diff --git a/ToDo.txt b/ToDo.txt index 31f5b2e..1b887ff 100644 --- a/ToDo.txt +++ b/ToDo.txt @@ -1,2 +1,3 @@ More Icons for Apps More apps: Laptop Sim (when done) +Use local info when building GUI (Except name/description) diff --git a/UpTool2/App.config b/UpTool2/App.config index b5c4218..82bc2e6 100644 --- a/UpTool2/App.config +++ b/UpTool2/App.config @@ -1,23 +1,22 @@ - + - -
+ +
- + - + https://github.com/CreepyCrafter24/UpTool2/releases/download/Repo/Repo.xml - \ No newline at end of file + diff --git a/UpTool2/MainForm.Designer.cs b/UpTool2/MainForm.Designer.cs index c52b834..0712fe7 100644 --- a/UpTool2/MainForm.Designer.cs +++ b/UpTool2/MainForm.Designer.cs @@ -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; } } diff --git a/UpTool2/MainForm.cs b/UpTool2/MainForm.cs index 48f4034..ee16cc4 100644 --- a/UpTool2/MainForm.cs +++ b/UpTool2/MainForm.cs @@ -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 apps = new Dictionary(); - 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 tmp_appslist = new List(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; diff --git a/UpTool2/MainForm.resx b/UpTool2/MainForm.resx index 8766f29..bee429b 100644 --- a/UpTool2/MainForm.resx +++ b/UpTool2/MainForm.resx @@ -120,4 +120,7 @@ 17, 17 + + 107, 17 + \ No newline at end of file diff --git a/UpTool2/Properties/Resources.Designer.cs b/UpTool2/Properties/Resources.Designer.cs index 8d08570..4419b52 100644 --- a/UpTool2/Properties/Resources.Designer.cs +++ b/UpTool2/Properties/Resources.Designer.cs @@ -59,5 +59,15 @@ namespace UpTool2.Properties { resourceCulture = value; } } + + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon C_64 { + get { + object obj = ResourceManager.GetObject("C_64", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } } } diff --git a/UpTool2/Properties/Resources.resx b/UpTool2/Properties/Resources.resx index 1af7de1..77de3d4 100644 --- a/UpTool2/Properties/Resources.resx +++ b/UpTool2/Properties/Resources.resx @@ -117,4 +117,8 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\C_64.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/UpTool2/Properties/Settings.Designer.cs b/UpTool2/Properties/Settings.Designer.cs index 925fc92..63acb13 100644 --- a/UpTool2/Properties/Settings.Designer.cs +++ b/UpTool2/Properties/Settings.Designer.cs @@ -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()))); diff --git a/UpTool2/Resources/C_64.ico b/UpTool2/Resources/C_64.ico new file mode 100644 index 0000000..8eeea9c Binary files /dev/null and b/UpTool2/Resources/C_64.ico differ diff --git a/UpTool2/UpTool2.csproj b/UpTool2/UpTool2.csproj index 39cba00..4ce3d7a 100644 --- a/UpTool2/UpTool2.csproj +++ b/UpTool2/UpTool2.csproj @@ -8,10 +8,11 @@ WinExe UpTool2 UpTool2 - v4.7.2 + v4.8 512 true true + AnyCPU @@ -36,6 +37,7 @@ UpTool2.Program + @@ -105,5 +107,8 @@ + + + \ No newline at end of file