Added local packages and fixed bugs

This commit is contained in:
CreepyCrafter24 2019-09-29 16:19:57 +02:00
parent 64cefd87f3
commit 8f3075b2eb
10 changed files with 153 additions and 49 deletions

View File

@ -1,2 +1,3 @@
More Icons for Apps
More apps: Laptop Sim (when done)
Use local info when building GUI (Except name/description)

View File

@ -1,23 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="UpTool2.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="UpTool2.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
<userSettings>
<UpTool2.Properties.Settings>
<setting name="Repos" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>https://github.com/CreepyCrafter24/UpTool2/releases/download/Repo/Repo.xml</string>
</ArrayOfString>
</value>
</setting>
</UpTool2.Properties.Settings>
</userSettings>
</configuration>
</configuration>

View File

@ -31,6 +31,7 @@
this.components = new System.ComponentModel.Container();
this.sidebarPanel = new System.Windows.Forms.FlowLayoutPanel();
this.infoPanel = new System.Windows.Forms.Panel();
this.action_run = new System.Windows.Forms.Button();
this.action_remove = new System.Windows.Forms.Button();
this.action_update = new System.Windows.Forms.Button();
this.action_install = new System.Windows.Forms.Button();
@ -43,7 +44,8 @@
this.controls_settings = new System.Windows.Forms.Button();
this.controls_reload = new System.Windows.Forms.Button();
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.action_run = new System.Windows.Forms.Button();
this.controls_upload = new System.Windows.Forms.Button();
this.searchPackageDialog = new System.Windows.Forms.OpenFileDialog();
this.infoPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
this.splitContainer.Panel1.SuspendLayout();
@ -76,6 +78,17 @@
this.infoPanel.Size = new System.Drawing.Size(528, 450);
this.infoPanel.TabIndex = 1;
//
// action_run
//
this.action_run.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.action_run.Location = new System.Drawing.Point(421, 5);
this.action_run.Name = "action_run";
this.action_run.Size = new System.Drawing.Size(23, 23);
this.action_run.TabIndex = 5;
this.action_run.Text = "↗";
this.action_run.UseVisualStyleBackColor = true;
this.action_run.Click += new System.EventHandler(this.Action_run_Click);
//
// action_remove
//
this.action_remove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@ -151,6 +164,7 @@
//
// optionsPanel
//
this.optionsPanel.Controls.Add(this.controls_upload);
this.optionsPanel.Controls.Add(this.filterBox);
this.optionsPanel.Controls.Add(this.searchBox);
this.optionsPanel.Controls.Add(this.controls_settings);
@ -167,9 +181,9 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.filterBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.filterBox.FormattingEnabled = true;
this.filterBox.Location = new System.Drawing.Point(58, 7);
this.filterBox.Location = new System.Drawing.Point(58, 6);
this.filterBox.Name = "filterBox";
this.filterBox.Size = new System.Drawing.Size(207, 21);
this.filterBox.Size = new System.Drawing.Size(178, 21);
this.filterBox.TabIndex = 3;
this.filterBox.SelectedIndexChanged += new System.EventHandler(this.updateSidebarV);
//
@ -210,16 +224,20 @@
this.toolTip.ReshowDelay = 100;
this.toolTip.ShowAlways = true;
//
// action_run
// controls_upload
//
this.action_run.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.action_run.Location = new System.Drawing.Point(421, 5);
this.action_run.Name = "action_run";
this.action_run.Size = new System.Drawing.Size(23, 23);
this.action_run.TabIndex = 5;
this.action_run.Text = "↗";
this.action_run.UseVisualStyleBackColor = true;
this.action_run.Click += new System.EventHandler(this.Action_run_Click);
this.controls_upload.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.controls_upload.Location = new System.Drawing.Point(242, 5);
this.controls_upload.Name = "controls_upload";
this.controls_upload.Size = new System.Drawing.Size(23, 23);
this.controls_upload.TabIndex = 4;
this.controls_upload.Text = "↑";
this.controls_upload.UseVisualStyleBackColor = true;
this.controls_upload.Click += new System.EventHandler(this.controls_upload_Click);
//
// searchPackageDialog
//
this.searchPackageDialog.Filter = "Packages (*.zip)|*.zip";
//
// MainForm
//
@ -261,6 +279,8 @@
private System.Windows.Forms.ToolTip toolTip;
private System.Windows.Forms.ComboBox filterBox;
private System.Windows.Forms.Button action_run;
private System.Windows.Forms.Button controls_upload;
private System.Windows.Forms.OpenFileDialog searchPackageDialog;
}
}

View File

@ -10,13 +10,14 @@ using System.Diagnostics;
using System.IO.Compression;
using System.Security.Cryptography;
using System.Linq;
using Microsoft.VisualBasic;
namespace UpTool2
{
public partial class MainForm : Form
{
Dictionary<Guid, App> apps = new Dictionary<Guid, App>();
enum Status { Not_Installed = 1, Updatable = 2, Installed = 4, All = 7 }
enum Status { Not_Installed = 1, Updatable = 2, Installed = 4, Local = 8, All = 15 }
string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\UpTool2";
public MainForm()
{
@ -49,6 +50,7 @@ namespace UpTool2
//add
toolTip.SetToolTip(controls_settings, "Settings");
toolTip.SetToolTip(controls_reload, "Refresh repositories");
toolTip.SetToolTip(controls_upload, "Install package from disk");
toolTip.SetToolTip(filterBox, "Filter");
toolTip.SetToolTip(action_install, "Install");
toolTip.SetToolTip(action_remove, "Remove");
@ -78,13 +80,8 @@ namespace UpTool2
if (runnable)
mainFile = el.Element("MainFile").Value;
Color color = ColorTranslator.FromHtml(el.Element("Color").Value);
string tmp_imageurl;
if (el.Element("Icon") == null)
tmp_imageurl = "https://raw.githubusercontent.com/CreepyCrafter24/CC-Clicker/master/C_64.ico";
else
tmp_imageurl = el.Element("Icon").Value;
Image icon = Image.FromStream(client.OpenRead(tmp_imageurl));
apps[ID] = new App(name, description, version, file, hash, ID, color, icon, runnable, mainFile);
Image icon = el.Element("Icon") == null ? Resources.C_64.ToBitmap() : Image.FromStream(client.OpenRead(el.Element("Icon").Value));
apps[ID] = new App(name, description, version, file, false, hash, ID, color, icon, runnable, mainFile);
}
}
#if !DEBUG
@ -95,6 +92,16 @@ namespace UpTool2
}
#endif
}
string[] localApps = Directory.GetDirectories(dir + @"\Apps\");
for (int i = 0; i < localApps.Length; i++)
{
Guid tmp = Guid.Parse(Path.GetFileName(localApps[i]));
if (!apps.ContainsKey(tmp))
{
XElement data = XDocument.Load(dir + @"\Apps\" + tmp.ToString() + @"\info.xml").Element("app");
apps.Add(tmp, new App("(local) " + data.Element("Name").Value, data.Element("Description").Value, -1, "", true, "", tmp, Color.Red, Resources.C_64.ToBitmap(), data.Element("MainFile") != null, data.Element("MainFile") == null ? "" : data.Element("MainFile").Value));
}
}
List<App> tmp_appslist = new List<App>(apps.Values);
tmp_appslist.Sort((x, y) => x.name.CompareTo(y.name));
foreach ((App app, Panel sidebarIcon) in from App app in tmp_appslist let sidebarIcon = new Panel() select (app, sidebarIcon))
@ -106,21 +113,21 @@ namespace UpTool2
sidebarIcon.BackgroundImageLayout = ImageLayout.Stretch;
sidebarIcon.Click += (object sender, EventArgs e) => {
infoPanel_Title.Text = app.name;
infoPanel_Title.ForeColor = app.local ? Color.Red : Color.Black;
infoPanel_Description.Text = app.description;
action_install.Tag = app;
action_install.Enabled = !Directory.Exists(dir + @"\Apps\" + app.ID.ToString());
action_install.Enabled = !(app.local || Directory.Exists(dir + @"\Apps\" + app.ID.ToString()));
action_remove.Tag = app;
action_remove.Enabled = Directory.Exists(dir + @"\Apps\" + app.ID.ToString());
action_update.Tag = app;
string xml = dir + @"\Apps\" + app.ID.ToString() + @"\info.xml";
action_update.Enabled = File.Exists(xml) && int.Parse(XDocument.Load(xml).Element("app").Element("Version").Value) < app.version;
action_update.Enabled = (!app.local) && File.Exists(xml) && int.Parse(XDocument.Load(xml).Element("app").Element("Version").Value) < app.version;
action_run.Tag = app;
action_run.Enabled = app.runnable && Directory.Exists(dir + @"\Apps\" + app.ID.ToString());
action_run.Enabled = (!app.local) && app.runnable && Directory.Exists(dir + @"\Apps\" + app.ID.ToString());
};
toolTip.SetToolTip(sidebarIcon, app.name);
sidebarPanel.Controls.Add(sidebarIcon);
}
client.Dispose();
updateSidebarV(null, null);
}
@ -180,8 +187,10 @@ namespace UpTool2
{
string app = "";
string tmp = "";
#if !DEBUG
try
{
#endif
App appI = (App)action_install.Tag;
app = dir + @"\Apps\" + appI.ID.ToString();
tmp = dir + @"\tmp";
@ -191,34 +200,83 @@ namespace UpTool2
if (Directory.Exists(app))
Directory.Delete(app, true);
Directory.CreateDirectory(app);
//using (var client = new WebClient())
//{
// client.DownloadFile(appI.file, app + @"\package.zip");
//}
if (new DownloadDialog(appI.file, app + @"\package.zip").ShowDialog() != DialogResult.OK)
throw new Exception("Download failed");
SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider();
if (BitConverter.ToString(sha256.ComputeHash(File.ReadAllBytes(app + @"\package.zip"))).Replace("-", string.Empty).ToUpper() != appI.hash)
throw new Exception("The hash is not equal to the one stored in the repo");
sha256.Dispose();
ZipFile.ExtractToDirectory(app + @"\package.zip", tmp);
Directory.Move(tmp + @"\Data", app + @"\app");
Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C \"" + tmp + "\\Install.bat\"", WorkingDirectory = app + @"\app" }).WaitForExit();
new XElement("app", new XElement("Version", appI.version)).Save(app + @"\info.xml");
Directory.Delete(tmp, true);
if (relE)
reloadElements();
completeInstall(app, appI);
#if !DEBUG
}
catch (Exception e1)
{
if (!relE)
throw;
if (Directory.Exists(tmp))
Directory.Delete(tmp, true);
if (Directory.Exists(app))
Directory.Delete(app, true);
MessageBox.Show(e1.ToString(), "Install failed");
}
#endif
Directory.Delete(tmp, true);
}
private void controls_upload_Click(object sender, EventArgs e)
{
string app = "";
string tmp = "";
#if !DEBUG
try
{
#endif
if (searchPackageDialog.ShowDialog() == DialogResult.OK)
{
Guid ID = Guid.NewGuid();
app = dir + @"\Apps\" + ID.ToString();
while (Directory.Exists(app))
{
ID = Guid.NewGuid();
app = dir + @"\Apps\" + ID.ToString();
}
App appI = new App(Interaction.InputBox("Name:"), "Locally installed package, removal only", -1, "", true, "", ID, Color.Red, Resources.C_64.ToBitmap(), false, "");
Directory.CreateDirectory(app);
tmp = dir + @"\tmp";
if (Directory.Exists(tmp))
Directory.Delete(tmp, true);
Directory.CreateDirectory(tmp);
File.Copy(searchPackageDialog.FileName, app + @"\package.zip");
completeInstall(app, appI);
}
#if !DEBUG
}
catch (Exception e1)
{
if (!relE)
throw;
if (Directory.Exists(app))
Directory.Delete(app, true);
MessageBox.Show(e1.ToString(), "Install failed");
}
#endif
Directory.Delete(tmp, true);
}
void completeInstall(string app, App appI)
{
try
{
string tmp = dir + @"\tmp";
ZipFile.ExtractToDirectory(app + @"\package.zip", tmp);
Directory.Move(tmp + @"\Data", app + @"\app");
if (appI.runnable)
new XElement("app", new XElement("Name", appI.name), new XElement("Description", appI.description), new XElement("Version", appI.version), new XElement("MainFile", appI.mainFile)).Save(app + @"\info.xml");
else
new XElement("app", new XElement("Name", appI.name), new XElement("Description", appI.description), new XElement("Version", appI.version)).Save(app + @"\info.xml");
Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C \"" + tmp + "\\Install.bat\"", WorkingDirectory = app + @"\app" }).WaitForExit();
if (relE)
reloadElements();
}
catch { throw; }
}
void clearSelection()
@ -238,7 +296,7 @@ namespace UpTool2
{
Panel sidebarIcon = (Panel)sidebarPanel.Controls[i];
App app = (App)sidebarIcon.Tag;
sidebarIcon.Visible = app.name.Contains(searchBox.Text) && ((int)app.status & (int)status) == (int)app.status;
sidebarIcon.Visible = app.name.Contains(searchBox.Text) && ((int)app.status & (int)status) != 0;
}
clearSelection();
}
@ -249,6 +307,7 @@ namespace UpTool2
public string description;
public int version;
public string file;
public bool local;
public string hash;
public Guid ID;
public Color color;
@ -256,12 +315,13 @@ namespace UpTool2
public bool runnable;
public string mainFile;
public App(string name, string description, int version, string file, string hash, Guid iD, Color color, Image icon, bool runnable, string mainFile)
public App(string name, string description, int version, string file, bool local, string hash, Guid iD, Color color, Image icon, bool runnable, string mainFile)
{
this.name = name ?? throw new ArgumentNullException(nameof(name));
this.description = description ?? throw new ArgumentNullException(nameof(description));
this.version = version;
this.file = file ?? throw new ArgumentNullException(nameof(file));
this.local = local;
this.hash = hash ?? throw new ArgumentNullException(nameof(hash));
ID = iD;
this.color = color;
@ -280,7 +340,9 @@ namespace UpTool2
if (int.Parse(XDocument.Load(xml).Element("app").Element("Version").Value) < version)
return Status.Updatable;
else
return Status.Installed;
{
return local ? Status.Installed | Status.Local : Status.Installed;
}
}
else
return Status.Not_Installed;

View File

@ -120,4 +120,7 @@
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="searchPackageDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>107, 17</value>
</metadata>
</root>

View File

@ -59,5 +59,15 @@ namespace UpTool2.Properties {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon C_64 {
get {
object obj = ResourceManager.GetObject("C_64", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
}
}

View File

@ -117,4 +117,8 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="C_64" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\C_64.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -12,7 +12,7 @@ namespace UpTool2.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.2.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

BIN
UpTool2/Resources/C_64.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -8,10 +8,11 @@
<OutputType>WinExe</OutputType>
<RootNamespace>UpTool2</RootNamespace>
<AssemblyName>UpTool2</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -36,6 +37,7 @@
<StartupObject>UpTool2.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression.FileSystem" />
@ -105,5 +107,8 @@
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\C_64.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>