Improve code
This commit is contained in:
parent
c87a3790ce
commit
af1f9fbfea
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||
</startup>
|
||||
</configuration>
|
||||
</configuration>
|
|
@ -1,115 +0,0 @@
|
|||
using Microsoft.VisualBasic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace UpTool2
|
||||
{
|
||||
static class AppInstall
|
||||
{
|
||||
public static void Install(App appI)
|
||||
{
|
||||
string app = "";
|
||||
string tmp = "";
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
app = appI.appPath;
|
||||
tmp = GlobalVariables.dir + @"\tmp";
|
||||
if (Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
Directory.CreateDirectory(tmp);
|
||||
if (Directory.Exists(app))
|
||||
Directory.Delete(app, true);
|
||||
Directory.CreateDirectory(app);
|
||||
DownloadDialog dlg = new DownloadDialog(appI.file);
|
||||
if (dlg.ShowDialog() != DialogResult.OK)
|
||||
throw new Exception("Download failed");
|
||||
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
|
||||
{
|
||||
string pkghash = BitConverter.ToString(sha256.ComputeHash(dlg.result)).Replace("-", string.Empty).ToUpper();
|
||||
if (pkghash != appI.hash.ToUpper())
|
||||
throw new Exception("The hash is not equal to the one stored in the repo:\r\nPackage: " + pkghash + "\r\nOnline: " + appI.hash.ToUpper());
|
||||
}
|
||||
File.WriteAllBytes(app + @"\package.zip", dlg.result);
|
||||
completeInstall(appI);
|
||||
#if !DEBUG
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (Directory.Exists(app))
|
||||
Directory.Delete(app, true);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
#endif
|
||||
if (tmp != "" && Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
#if !DEBUG
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void installZip(string zipPath, App meta)
|
||||
{
|
||||
string app = "";
|
||||
string tmp = "";
|
||||
try
|
||||
{
|
||||
app = meta.appPath;
|
||||
Directory.CreateDirectory(app);
|
||||
tmp = GlobalVariables.dir + @"\tmp";
|
||||
if (Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
Directory.CreateDirectory(tmp);
|
||||
File.Copy(zipPath, app + @"\package.zip");
|
||||
completeInstall(meta);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (Directory.Exists(app))
|
||||
Directory.Delete(app, true);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tmp != "" && Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
}
|
||||
}
|
||||
|
||||
static void completeInstall(App app) => completeInstall(app.appPath, app.name, app.description, app.version, app.mainFile);
|
||||
|
||||
static void completeInstall(string appPath, string name, string description, Version version, string mainFile)
|
||||
{
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
string tmp = GlobalVariables.dir + @"\tmp";
|
||||
ZipFile.ExtractToDirectory(appPath + @"\package.zip", tmp);
|
||||
Directory.Move(tmp + @"\Data", appPath + @"\app");
|
||||
if (mainFile == null)
|
||||
new XElement("app", new XElement("Name", name), new XElement("Description", description), new XElement("Version", version)).Save(appPath + @"\info.xml");
|
||||
else
|
||||
new XElement("app", new XElement("Name", name), new XElement("Description", description), new XElement("Version", version), new XElement("MainFile", mainFile)).Save(appPath + @"\info.xml");
|
||||
Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C \"" + tmp + "\\Install.bat\"", WorkingDirectory = appPath + @"\app", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }).WaitForExit();
|
||||
if (GlobalVariables.relE)
|
||||
GlobalVariables.reloadElements.Invoke();
|
||||
#if !DEBUG
|
||||
}
|
||||
catch { throw; }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,8 +4,11 @@ using System.Drawing;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using UpTool2.Tool;
|
||||
using static System.Environment;
|
||||
using Version = System.Version;
|
||||
|
||||
namespace UpTool2
|
||||
namespace UpTool2.Data
|
||||
{
|
||||
public struct App : IEquatable<App>
|
||||
{
|
||||
|
@ -39,7 +42,7 @@ namespace UpTool2
|
|||
public Status status
|
||||
{
|
||||
get {
|
||||
string xml = GlobalVariables.getInfoPath(ID);
|
||||
string xml = PathTool.getInfoPath(ID);
|
||||
if (File.Exists(xml))
|
||||
{
|
||||
if (Version.TryParse(XDocument.Load(xml).Element("app").Element("Version").Value, out Version ver) && ver >= version)
|
||||
|
@ -53,13 +56,31 @@ namespace UpTool2
|
|||
}
|
||||
|
||||
public override bool Equals(object obj) => obj is App app && Equals(app);
|
||||
|
||||
public bool Equals(App other) => ID.Equals(other.ID);
|
||||
|
||||
public override int GetHashCode() => 1213502048 + EqualityComparer<Guid>.Default.GetHashCode(ID);
|
||||
public override string ToString() => "Name: " + name + "\r\nDescription:\r\n" + string.Join("\r\n", description.Split('\n').Select(s => { if (s.EndsWith("\r")) s.Remove(s.Length - 1, 1); return "> " + s; })) + "\r\nVersion: " + version + "\r\nFile: " + file + "\r\nLocal: " + local.ToString() + "\r\nHash: " + hash + "\r\nID: " + ID.ToString() + "\r\nColor: " + color.ToKnownColor().ToString() + "\r\nRunnable: " + runnable + "\r\nMainFile: " + mainFile + "\r\nStatus: " + status.ToString() + "\r\nObject Hash Code: " + GetHashCode();
|
||||
|
||||
public override string ToString() => $@"Name: {name}
|
||||
Description:
|
||||
{string.Join(NewLine, description.Split('\n').Select(s => { if (s.EndsWith("\r")) s.Remove(s.Length - 1, 1); return "> " + s; }))}
|
||||
Version: {version}
|
||||
File: {file}
|
||||
Local: {local.ToString()}
|
||||
Hash: {hash}
|
||||
ID: {ID.ToString()}
|
||||
Color: {color.ToKnownColor().ToString()}
|
||||
Runnable: {runnable}
|
||||
MainFile: {mainFile}
|
||||
Status: {status.ToString()}
|
||||
Object Hash Code: {GetHashCode()}";
|
||||
|
||||
public static bool operator ==(App left, App right) => left.Equals(right);
|
||||
|
||||
public static bool operator !=(App left, App right) => !(left == right);
|
||||
public string appPath => GlobalVariables.getAppPath(this);
|
||||
public string dataPath => GlobalVariables.getDataPath(this);
|
||||
public string infoPath => GlobalVariables.getInfoPath(this);
|
||||
|
||||
public string appPath => PathTool.getAppPath(this.ID);
|
||||
public string dataPath => PathTool.getDataPath(this.ID);
|
||||
public string infoPath => PathTool.getInfoPath(this.ID);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace UpTool2
|
||||
namespace UpTool2.Data
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
|
@ -8,4 +8,4 @@
|
|||
Local = 8,
|
||||
All = 15
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,23 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UpTool2.Data;
|
||||
|
||||
namespace UpTool2
|
||||
{
|
||||
static partial class GlobalVariables
|
||||
{
|
||||
public static Dictionary<Guid, App> apps = new Dictionary<Guid, App>();
|
||||
public static string dir => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\UpTool2";
|
||||
public static string appsPath => dir + @"\Apps";
|
||||
public static string getAppPath(App app) => getAppPath(app.ID);
|
||||
public static string getDataPath(App app) => getDataPath(app.ID);
|
||||
public static string getInfoPath(App app) => getInfoPath(app.ID);
|
||||
public static string getAppPath(Guid app) => appsPath + @"\" + app.ToString();
|
||||
public static string getDataPath(Guid app) => getAppPath(app) + @"\app";
|
||||
public static string getInfoPath(Guid app) => getAppPath(app) + "\\info.xml";
|
||||
public static bool relE = true;
|
||||
public static Action reloadElements;
|
||||
public static Version minimumVer => Version.Parse("0.0.0.0");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,9 +8,14 @@ using System.IO.Compression;
|
|||
using Microsoft.VisualBasic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using UpTool2.Tool;
|
||||
using UpTool2.Data;
|
||||
|
||||
#if DEBUG
|
||||
|
||||
using System.Threading;
|
||||
using System.Linq;
|
||||
|
||||
#endif
|
||||
|
||||
namespace UpTool2
|
||||
|
@ -23,7 +28,7 @@ namespace UpTool2
|
|||
try
|
||||
{
|
||||
#endif
|
||||
AppInstall.Install((App)action_install.Tag);
|
||||
AppInstall.Install((App)action_install.Tag);
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e1)
|
||||
|
@ -34,17 +39,18 @@ namespace UpTool2
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void Action_remove_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
string app = GlobalVariables.dir + @"\Apps\" + ((App)action_remove.Tag).ID.ToString();
|
||||
string tmp = GlobalVariables.dir + @"\tmp";
|
||||
string app = ((App)action_remove.Tag).appPath;
|
||||
string tmp = PathTool.tempPath;
|
||||
if (Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
Directory.CreateDirectory(tmp);
|
||||
ZipFile.ExtractToDirectory(app + @"\package.zip", tmp);
|
||||
Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C \"" + tmp + "\\Remove.bat\"", WorkingDirectory = app + @"\app" }).WaitForExit();
|
||||
ZipFile.ExtractToDirectory(Path.Combine(app, "package.zip"), tmp);
|
||||
Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = $"/C \"{Path.Combine(tmp, "Remove.bat")}\"", WorkingDirectory = Path.Combine(app, "app") }).WaitForExit();
|
||||
Directory.Delete(tmp, true);
|
||||
Directory.Delete(app, true);
|
||||
if (GlobalVariables.relE)
|
||||
|
@ -57,20 +63,21 @@ namespace UpTool2
|
|||
MessageBox.Show(e1.ToString(), "Removal failed");
|
||||
}
|
||||
}
|
||||
|
||||
private void controls_upload_Click(object sender, EventArgs e)
|
||||
{
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
if (searchPackageDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
Guid ID = Guid.NewGuid();
|
||||
while (GlobalVariables.apps.ContainsKey(ID) || Directory.Exists(GlobalVariables.getAppPath(ID)))
|
||||
ID = Guid.NewGuid();
|
||||
App appI = new App(Interaction.InputBox("Name:"), "Locally installed package, removal only", GlobalVariables.minimumVer, "", true, "", ID, Color.Red, Resources.C_64.ToBitmap(), false, "");
|
||||
AppInstall.installZip(searchPackageDialog.FileName, appI);
|
||||
}
|
||||
if (searchPackageDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
Guid ID = Guid.NewGuid();
|
||||
while (GlobalVariables.apps.ContainsKey(ID) || Directory.Exists(PathTool.getAppPath(ID)))
|
||||
ID = Guid.NewGuid();
|
||||
App appI = new App(Interaction.InputBox("Name:"), "Locally installed package, removal only", GlobalVariables.minimumVer, "", true, "", ID, Color.Red, Resources.C_64.ToBitmap(), false, "");
|
||||
AppInstall.installZip(searchPackageDialog.FileName, appI);
|
||||
}
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e1)
|
||||
|
@ -81,7 +88,8 @@ namespace UpTool2
|
|||
}
|
||||
#endif
|
||||
}
|
||||
void reloadElements()
|
||||
|
||||
private void reloadElements()
|
||||
{
|
||||
//remove
|
||||
toolTip.RemoveAll();
|
||||
|
@ -134,22 +142,24 @@ namespace UpTool2
|
|||
sidebarPanel.Controls.Add(sidebarIcon);
|
||||
}
|
||||
updateSidebarV(null, null);
|
||||
Text = "UpTool2 " + ((availableUpdates == 0) ? "(All up-to-date)" : "(" + availableUpdates.ToString() + " Updates)");
|
||||
Text = $"UpTool2 {((availableUpdates == 0) ? "(All up-to-date)" : $"({availableUpdates.ToString()} Updates)")}";
|
||||
}
|
||||
|
||||
private void Action_run_Click(object sender, EventArgs e)
|
||||
{
|
||||
Console.WriteLine(new string('-', 10));
|
||||
Console.WriteLine(GlobalVariables.getDataPath((App)action_run.Tag));
|
||||
Console.WriteLine(((App)action_run.Tag).dataPath);
|
||||
Console.WriteLine("\\");
|
||||
Console.WriteLine(((App)action_run.Tag).mainFile);
|
||||
Console.WriteLine(GlobalVariables.getDataPath((App)action_run.Tag));
|
||||
Console.WriteLine(((App)action_run.Tag).dataPath);
|
||||
_ = Process.Start(
|
||||
new ProcessStartInfo
|
||||
{
|
||||
FileName = GlobalVariables.getDataPath((App)action_run.Tag) + "\\" + ((App)action_run.Tag).mainFile,
|
||||
WorkingDirectory = GlobalVariables.getDataPath((App)action_run.Tag)
|
||||
FileName = Path.Combine(((App)action_run.Tag).dataPath, ((App)action_run.Tag).mainFile),
|
||||
WorkingDirectory = ((App)action_run.Tag).dataPath
|
||||
});
|
||||
}
|
||||
|
||||
private void Action_update_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
|
@ -165,13 +175,16 @@ namespace UpTool2
|
|||
reloadElements();
|
||||
GlobalVariables.relE = true;
|
||||
}
|
||||
|
||||
private void Controls_reload_Click(object sender, EventArgs e)
|
||||
{
|
||||
RepoManagement.fetchRepos();
|
||||
reloadElements();
|
||||
}
|
||||
|
||||
private void Controls_settings_Click(object sender, EventArgs e) => new SettingsForms().ShowDialog();
|
||||
void clearSelection()
|
||||
|
||||
private void clearSelection()
|
||||
{
|
||||
action_install.Enabled = false;
|
||||
action_remove.Enabled = false;
|
||||
|
@ -180,6 +193,7 @@ namespace UpTool2
|
|||
infoPanel_Title.Text = "";
|
||||
infoPanel_Description.Text = "";
|
||||
}
|
||||
|
||||
private void updateSidebarV(object sender, EventArgs e)
|
||||
{
|
||||
#if DEBUG
|
||||
|
@ -188,7 +202,8 @@ namespace UpTool2
|
|||
searchBox.Text = "!DEBUG:PRINT";
|
||||
string _tmp_file = Path.GetTempFileName();
|
||||
File.WriteAllText(_tmp_file, string.Join("\r\n\r\n", GlobalVariables.apps.Values.Select(app => app.ToString()).Concat(new string[] { "Assembly version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString() }).ToArray()));
|
||||
new Thread(() => {
|
||||
new Thread(() =>
|
||||
{
|
||||
Process.Start("notepad", _tmp_file).WaitForExit();
|
||||
File.Delete(_tmp_file);
|
||||
}).Start();
|
||||
|
@ -196,18 +211,19 @@ namespace UpTool2
|
|||
else
|
||||
{
|
||||
#endif
|
||||
Enum.TryParse(filterBox.SelectedValue.ToString(), out Status status);
|
||||
for (int i = 0; i < sidebarPanel.Controls.Count; i++)
|
||||
{
|
||||
Panel sidebarIcon = (Panel)sidebarPanel.Controls[i];
|
||||
App app = (App)sidebarIcon.Tag;
|
||||
sidebarIcon.Visible = app.name.Contains(searchBox.Text) && ((int)app.status & (int)(Program.online ? status : Status.Installed)) != 0;
|
||||
}
|
||||
clearSelection();
|
||||
Enum.TryParse(filterBox.SelectedValue.ToString(), out Status status);
|
||||
for (int i = 0; i < sidebarPanel.Controls.Count; i++)
|
||||
{
|
||||
Panel sidebarIcon = (Panel)sidebarPanel.Controls[i];
|
||||
App app = (App)sidebarIcon.Tag;
|
||||
sidebarIcon.Visible = app.name.Contains(searchBox.Text) && ((int)app.status & (int)(Program.online ? status : Status.Installed)) != 0;
|
||||
}
|
||||
clearSelection();
|
||||
#if DEBUG
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
GlobalVariables.reloadElements = reloadElements;
|
||||
|
@ -223,16 +239,17 @@ namespace UpTool2
|
|||
filterBox.SelectedIndex = 2;
|
||||
}
|
||||
reloadElements();
|
||||
if (!Directory.Exists(GlobalVariables.appsPath))
|
||||
Directory.CreateDirectory(GlobalVariables.appsPath);
|
||||
if (!Directory.Exists(PathTool.appsPath))
|
||||
Directory.CreateDirectory(PathTool.appsPath);
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
Program.splash.Hide();
|
||||
BringToFront();
|
||||
}
|
||||
|
||||
struct _IMAGE_FILE_HEADER
|
||||
private struct _IMAGE_FILE_HEADER
|
||||
{
|
||||
public ushort Machine;
|
||||
public ushort NumberOfSections;
|
||||
|
@ -243,7 +260,7 @@ namespace UpTool2
|
|||
public ushort Characteristics;
|
||||
}
|
||||
|
||||
static DateTime GetBuildDateTime(Assembly assembly)
|
||||
private static DateTime GetBuildDateTime(Assembly assembly)
|
||||
{
|
||||
var path = assembly.GetName().CodeBase;
|
||||
if (File.Exists(path))
|
||||
|
@ -275,7 +292,10 @@ namespace UpTool2
|
|||
private void MainForm_HelpRequested(object sender, HelpEventArgs hlpevent)
|
||||
{
|
||||
DateTime buildTime = GetBuildDateTime(Assembly.GetExecutingAssembly());
|
||||
MessageBox.Show("UpTool2 by CC24\r\nVersion: " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + "\r\nBuild Date: " + buildTime.ToString("dd.MM.yyyy"), "UpTool2");
|
||||
_ = MessageBox.Show($@"UpTool2 by CC24
|
||||
Version: {Assembly.GetExecutingAssembly().GetName().Version.ToString()}
|
||||
Build Date: {buildTime.ToString("dd.MM.yyyy")}", "UpTool2");
|
||||
hlpevent.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
@ -9,20 +12,20 @@ using System.Security.Cryptography;
|
|||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.IO.Compression;
|
||||
using System.Xml.Linq;
|
||||
using UpTool2.Tool;
|
||||
using Shortcut = UpTool2.Tool.Shortcut;
|
||||
|
||||
namespace UpTool2
|
||||
{
|
||||
static class Program
|
||||
internal static class Program
|
||||
{
|
||||
public static Form splash;
|
||||
public static bool online;
|
||||
|
||||
[STAThread]
|
||||
static void Main()
|
||||
private static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
@ -52,26 +55,31 @@ namespace UpTool2
|
|||
#endif
|
||||
hasHandle = true;
|
||||
}
|
||||
string xml = GlobalVariables.dir + @"\info.xml";
|
||||
FixXML(xml);
|
||||
string metaXML = XDocument.Load(xml).Element("meta").Element("UpdateSource").Value;
|
||||
FixXML(PathTool.infoXML);
|
||||
string metaXML = XDocument.Load(PathTool.infoXML).Element("meta").Element("UpdateSource").Value;
|
||||
online = Ping(metaXML);
|
||||
|
||||
#if !DEBUG
|
||||
if (Application.ExecutablePath != GlobalVariables.dir + @"\Install\UpTool2.exe")
|
||||
if (Application.ExecutablePath != PathTool.GetProgPath("Install", "UpTool2.exe"))
|
||||
{
|
||||
if ((!online) || MessageBox.Show("Thank you for downloading UpTool2.\r\nTo prevent inconsistent behavior you will need to install this before running.\r\nFiles will be placed in %appdata%\\UpTool2 and %appdata%\\Microsoft\\Windows\\Start Menu\\Programs\r\nDo you want to continue?", "UpTool2", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
if ((!online))
|
||||
throw new WebException("Could fetch Metadata (are you online?)");
|
||||
if (MessageBox.Show(@"Thank you for downloading UpTool2.
|
||||
To prevent inconsistent behavior you will need to install this before running.
|
||||
Files will be placed in %appdata%\UpTool2 and %appdata%\Microsoft\Windows\Start Menu\Programs
|
||||
Do you want to continue?", "UpTool2", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
throw new Exception("Exiting...");
|
||||
MessageBox.Show("Installing an Update. Please restart from your start menu!");
|
||||
installUpdate(XDocument.Load(metaXML).Element("meta"));
|
||||
Shortcut.Make(GlobalVariables.dir + @"\Install\UpTool2.exe", Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\UpTool2.lnk");
|
||||
Shortcut.Make(PathTool.GetProgPath("Install", "UpTool2.exe"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk"));
|
||||
mutex.ReleaseMutex();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\UpTool2.lnk"))
|
||||
Shortcut.Make(GlobalVariables.dir + @"\Install\UpTool2.exe", Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\\UpTool2.lnk");
|
||||
if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk")))
|
||||
Shortcut.Make(PathTool.GetProgPath("Install", "UpTool2.exe"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk"));
|
||||
#endif
|
||||
if (!Directory.Exists(GlobalVariables.dir + @"\Apps"))
|
||||
Directory.CreateDirectory(GlobalVariables.dir + @"\Apps");
|
||||
if (!Directory.Exists(PathTool.GetProgPath("Apps")))
|
||||
Directory.CreateDirectory(PathTool.GetProgPath("Apps"));
|
||||
if (!online || UpdateCheck(metaXML))
|
||||
Application.Run(new MainForm());
|
||||
#if !DEBUG
|
||||
|
@ -89,7 +97,7 @@ namespace UpTool2
|
|||
}
|
||||
}
|
||||
|
||||
static void ShowSplash()
|
||||
private static void ShowSplash()
|
||||
{
|
||||
splash = new Form
|
||||
{
|
||||
|
@ -119,7 +127,7 @@ namespace UpTool2
|
|||
splash.BringToFront();
|
||||
}
|
||||
|
||||
static void FixXML(string xml, bool throwOnError = false)
|
||||
public static void FixXML(string xml, bool throwOnError = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -136,7 +144,7 @@ namespace UpTool2
|
|||
if (meta.Element("Repos") == null)
|
||||
meta.Add(new XElement("Repos"));
|
||||
if (meta.Element("Repos").Elements("Repo").Count() == 0)
|
||||
meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"), new XElement("Link", "https://raw.githubusercontent.com/JFronny/UpTool2/master/Repo.xml")));
|
||||
meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"), new XElement("Link", "https://gist.githubusercontent.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4/raw/Meta.xml")));
|
||||
meta.Element("Repos").Elements("Repo").Select(s => s.Element("Link"))
|
||||
.Where(s => new string[] { null, "https://github.com/JFronny/UpTool2/releases/download/Repo/Repo.xml",
|
||||
"https://raw.githubusercontent.com/JFronny/UpTool2/master/Repo.xml"}.Contains(s.Value))
|
||||
|
@ -157,7 +165,7 @@ namespace UpTool2
|
|||
}
|
||||
}
|
||||
|
||||
static bool UpdateCheck(string metaXML)
|
||||
private static bool UpdateCheck(string metaXML)
|
||||
{
|
||||
XElement meta = XDocument.Load(metaXML).Element("meta");
|
||||
if (Assembly.GetExecutingAssembly().GetName().Version < Version.Parse(meta.Element("Version").Value))
|
||||
|
@ -168,7 +176,7 @@ namespace UpTool2
|
|||
return true;
|
||||
}
|
||||
|
||||
static void installUpdate(XElement meta)
|
||||
private static void installUpdate(XElement meta)
|
||||
{
|
||||
byte[] dl;
|
||||
using (DownloadDialog dlg = new DownloadDialog(meta.Element("File").Value))
|
||||
|
@ -183,19 +191,20 @@ namespace UpTool2
|
|||
if (pkghash != meta.Element("Hash").Value.ToUpper())
|
||||
throw new Exception("The hash is not equal to the one stored in the repo:\r\nPackage: " + pkghash + "\r\nOnline: " + meta.Element("Hash").Value.ToUpper());
|
||||
}
|
||||
if (Directory.Exists(GlobalVariables.dir + @"\Install\tmp"))
|
||||
Directory.Delete(GlobalVariables.dir + @"\Install\tmp", true);
|
||||
Directory.CreateDirectory(GlobalVariables.dir + @"\Install\tmp");
|
||||
|
||||
if (Directory.Exists(PathTool.GetProgPath("Install", "tmp")))
|
||||
Directory.Delete(PathTool.GetProgPath("Install", "tmp"), true);
|
||||
Directory.CreateDirectory(PathTool.GetProgPath("Install", "tmp"));
|
||||
using (MemoryStream ms = new MemoryStream(dl))
|
||||
using (ZipArchive ar = new ZipArchive(ms))
|
||||
{
|
||||
ar.Entries.Where(s => !string.IsNullOrEmpty(s.Name)).ToList().ForEach(s =>
|
||||
{
|
||||
s.ExtractToFile(GlobalVariables.dir + @"\Install\tmp\" + s.Name, true);
|
||||
s.ExtractToFile(PathTool.GetProgPath("Install", "tmp", s.Name), true);
|
||||
});
|
||||
}
|
||||
splash.Hide();
|
||||
Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = @"/C timeout /t 2 & xcopy /s /e /y tmp\* .", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = GlobalVariables.dir + @"\Install" });
|
||||
Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = @"/C timeout /t 2 & xcopy /s /e /y tmp\* .", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = PathTool.GetProgPath("Install") });
|
||||
}
|
||||
|
||||
public static bool Ping(string url)
|
||||
|
@ -206,11 +215,8 @@ namespace UpTool2
|
|||
request.Timeout = 3000;
|
||||
request.AllowAutoRedirect = false;
|
||||
request.Method = "HEAD";
|
||||
|
||||
using (var response = request.GetResponse())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
using var response = request.GetResponse();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -218,4 +224,4 @@ namespace UpTool2
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
@ -33,4 +32,4 @@ using System.Runtime.InteropServices;
|
|||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyFileVersion("1.0.1.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.1.0")]
|
|
@ -1,160 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using UpTool2.Properties;
|
||||
|
||||
namespace UpTool2
|
||||
{
|
||||
static class RepoManagement
|
||||
{
|
||||
public static void fetchRepos()
|
||||
{
|
||||
string xml = GlobalVariables.dir + @"\info.xml";
|
||||
XElement meta = XDocument.Load(xml).Element("meta");
|
||||
List<XElement> tmp_apps_list = new List<XElement>();
|
||||
if (meta.Element("Repos") == null)
|
||||
meta.Add(new XElement("Repos"));
|
||||
if (meta.Element("Repos").Elements("Repo").Count() == 0)
|
||||
meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"), new XElement("Link", "https://github.com/JFronny/UpTool2/releases/download/Repo/Repo.xml")));
|
||||
List<string> repArr = meta.Element("Repos").Elements("Repo").Select(s => s.Element("Link").Value).Distinct().ToList();
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
int i = 0;
|
||||
while (i < repArr.Count)
|
||||
{
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
XDocument repo = XDocument.Load(repArr[i]);
|
||||
repArr.AddRange(repo.Element("repo").Elements("repolink").Select(s => s.Value).Where(s => !repArr.Contains(s)));
|
||||
XElement[] tmp_apparray = repo.Element("repo").Elements("app").Where(app => tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value).Count() == 0 ||
|
||||
tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value)
|
||||
.Where(a => a.Element("Version").getVer() >= app.Element("Version").getVer()).Count() == 0).ToArray()
|
||||
.Concat(repo.Element("repo").Elements("applink").Select(s => XDocument.Load(s.Value).Element("app"))).ToArray();
|
||||
for (int i1 = 0; i1 < tmp_apparray.Length; i1++)
|
||||
{
|
||||
XElement app = tmp_apparray[i1];
|
||||
//"Sanity check"
|
||||
int.Parse(app.Element("Version").Value);
|
||||
Guid.Parse(app.Element("ID").Value);
|
||||
//Create XElement
|
||||
tmp_apps_list.Add(new XElement("App",
|
||||
new XElement("Name", app.Element("Name").Value),
|
||||
new XElement("Description", app.Element("Description").Value),
|
||||
new XElement("Version", app.Element("Version").Value),
|
||||
new XElement("ID", app.Element("ID").Value),
|
||||
new XElement("File", app.Element("File").Value),
|
||||
new XElement("Hash", app.Element("Hash").Value)
|
||||
));
|
||||
if (app.Element("MainFile") != null)
|
||||
tmp_apps_list.Last().Add(new XElement("MainFile", app.Element("MainFile").Value));
|
||||
if (app.Element("Icon") != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
//Scale Image and save as Base64
|
||||
Image src = Image.FromStream(client.OpenRead(app.Element("Icon").Value));
|
||||
Bitmap dest = new Bitmap(70, 70);
|
||||
dest.SetResolution(src.HorizontalResolution, src.VerticalResolution);
|
||||
using (Graphics g = Graphics.FromImage(dest))
|
||||
{
|
||||
g.CompositingMode = CompositingMode.SourceCopy;
|
||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
using (var wrapMode = new ImageAttributes())
|
||||
{
|
||||
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
|
||||
g.DrawImage(src, new Rectangle(0, 0, 70, 70), 0, 0, src.Width, src.Height, GraphicsUnit.Pixel, wrapMode);
|
||||
}
|
||||
}
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
dest.Save(ms, ImageFormat.Png);
|
||||
tmp_apps_list.Last().Add(new XElement("Icon", Convert.ToBase64String(ms.ToArray())));
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
if (tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value).Count() > 1)
|
||||
tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value).Reverse().Skip(1).ToList().ForEach(a => tmp_apps_list.Remove(a));
|
||||
}
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "Failed to load repo: " + repArr[i]);
|
||||
}
|
||||
#endif
|
||||
i++;
|
||||
}
|
||||
}
|
||||
tmp_apps_list.Sort((x, y) => x.Element("Name").Value.CompareTo(y.Element("Name").Value));
|
||||
if (meta.Element("LocalRepo") == null)
|
||||
meta.Add(new XElement("LocalRepo"));
|
||||
XElement repos = meta.Element("LocalRepo");
|
||||
repos.RemoveNodes();
|
||||
tmp_apps_list.ForEach(app => repos.Add(app));
|
||||
meta.Save(xml);
|
||||
}
|
||||
|
||||
static Version getVer(this XElement el) => int.TryParse(el.Value, out int i) ? new Version(0, 0, 0, i) : Version.Parse(el.Value);
|
||||
|
||||
public static void getReposFromDisk()
|
||||
{
|
||||
GlobalVariables.apps.Clear();
|
||||
string xml = GlobalVariables.dir + @"\info.xml";
|
||||
XDocument.Load(xml).Element("meta").Element("LocalRepo").Elements().ToList().ForEach(app =>
|
||||
{
|
||||
Guid id = Guid.Parse(app.Element("ID").Value);
|
||||
string locInPath = GlobalVariables.getInfoPath(id);
|
||||
XElement locIn = File.Exists(locInPath) ? XDocument.Load(locInPath).Element("app") : app;
|
||||
if (int.TryParse(app.Element("Version").Value, out int iputareallylongnameheresoiwillnotuseitlaterbyaccident))
|
||||
app.Element("Version").Value = GlobalVariables.minimumVer.ToString();
|
||||
GlobalVariables.apps.Add(id, new App(
|
||||
name: locIn.Element("Name").Value,
|
||||
description: locIn.Element("Description").Value,
|
||||
version: Version.Parse(app.Element("Version").Value),
|
||||
file: app.Element("File").Value,
|
||||
local: false,
|
||||
hash: app.Element("Hash").Value,
|
||||
iD: id,
|
||||
color: Color.White,
|
||||
icon: app.Element("Icon") == null ? Resources.C_64.ToBitmap() : (Bitmap)new ImageConverter().ConvertFrom(Convert.FromBase64String(app.Element("Icon").Value)),
|
||||
runnable: locIn.Element("MainFile") != null || app.Element("MainFile") != null,
|
||||
mainFile: locIn.Element("MainFile") == null ? (app.Element("MainFile") == null ? "" : app.Element("MainFile").Value) : locIn.Element("MainFile").Value
|
||||
));
|
||||
#if DEBUG
|
||||
Console.WriteLine(locIn.Element("MainFile") == null ? "NULL" : locIn.Element("MainFile").Value);
|
||||
Console.WriteLine(GlobalVariables.apps[id].mainFile);
|
||||
#endif
|
||||
});
|
||||
Directory.GetDirectories(GlobalVariables.dir + @"\Apps\").Where(s => !GlobalVariables.apps.ContainsKey(Guid.Parse(Path.GetFileName(s)))).ToList().ForEach(s =>
|
||||
{
|
||||
Guid tmp = Guid.Parse(Path.GetFileName(s));
|
||||
try
|
||||
{
|
||||
XElement data = XDocument.Load(GlobalVariables.getInfoPath(tmp)).Element("app");
|
||||
GlobalVariables.apps.Add(tmp, new App("(local) " + data.Element("Name").Value, data.Element("Description").Value, GlobalVariables.minimumVer, "", true, "", tmp, Color.Red, Resources.C_64.ToBitmap(), data.Element("MainFile") != null, data.Element("MainFile") == null ? "" : data.Element("MainFile").Value));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (MessageBox.Show("An error occured while loading this local repo:\r\n" + e.Message + "\r\nDo you want to exit? Otherwise the folder will be deleted, possibly causeing problems later.", "", MessageBoxButtons.YesNo) == DialogResult.No)
|
||||
Directory.Delete(GlobalVariables.getAppPath(tmp), true);
|
||||
else
|
||||
Environment.Exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using UpTool2.Tool;
|
||||
|
||||
namespace UpTool2
|
||||
{
|
||||
public partial class SettingsForms : Form
|
||||
{
|
||||
string dir => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\UpTool2";
|
||||
string xml => dir + @"\info.xml";
|
||||
XDocument doc;
|
||||
XElement meta;
|
||||
XElement repos;
|
||||
private XDocument doc;
|
||||
private XElement meta;
|
||||
private XElement repos;
|
||||
|
||||
public SettingsForms()
|
||||
{
|
||||
InitializeComponent();
|
||||
doc = XDocument.Load(xml);
|
||||
Program.FixXML(PathTool.infoXML);
|
||||
doc = XDocument.Load(PathTool.infoXML);
|
||||
meta = doc.Element("meta");
|
||||
if (meta.Element("Repos") == null)
|
||||
meta.Add(new XElement("Repos"));
|
||||
if (meta.Element("Repos").Elements("Repo").Count() == 0)
|
||||
meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"), new XElement("Link", "https://github.com/JFronny/UpTool2/releases/download/Repo/Repo.xml")));
|
||||
repos = meta.Element("Repos");
|
||||
foreach (XElement repo in repos.Elements("Repo"))
|
||||
{
|
||||
|
@ -44,7 +34,7 @@ namespace UpTool2
|
|||
repos.Add(new XElement("Repo", new XElement("Name", (string)sourceGrid.Rows[y].Cells[0].Value), new XElement("Link", (string)sourceGrid.Rows[y].Cells[1].Value)));
|
||||
}
|
||||
}
|
||||
doc.Save(xml);
|
||||
doc.Save(PathTool.infoXML);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
113
UpTool2/Tool/AppInstall.cs
Normal file
113
UpTool2/Tool/AppInstall.cs
Normal file
|
@ -0,0 +1,113 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using UpTool2.Data;
|
||||
|
||||
namespace UpTool2.Tool
|
||||
{
|
||||
internal static class AppInstall
|
||||
{
|
||||
public static void Install(App appI)
|
||||
{
|
||||
string app = "";
|
||||
string tmp = "";
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
app = appI.appPath;
|
||||
tmp = PathTool.tempPath;
|
||||
if (Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
Directory.CreateDirectory(tmp);
|
||||
if (Directory.Exists(app))
|
||||
Directory.Delete(app, true);
|
||||
Directory.CreateDirectory(app);
|
||||
using DownloadDialog dlg = new DownloadDialog(appI.file);
|
||||
if (dlg.ShowDialog() != DialogResult.OK)
|
||||
throw new Exception("Download failed");
|
||||
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
|
||||
{
|
||||
string pkghash = BitConverter.ToString(sha256.ComputeHash(dlg.result)).Replace("-", string.Empty).ToUpper();
|
||||
if (pkghash != appI.hash.ToUpper())
|
||||
throw new Exception($@"The hash is not equal to the one stored in the repo:
|
||||
Package: {pkghash}
|
||||
Online: {appI.hash.ToUpper()}");
|
||||
}
|
||||
File.WriteAllBytes(Path.Combine(app, "package.zip"), dlg.result);
|
||||
completeInstall(appI);
|
||||
#if !DEBUG
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (Directory.Exists(app))
|
||||
Directory.Delete(app, true);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
#endif
|
||||
if (tmp != "" && Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
#if !DEBUG
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void installZip(string zipPath, App meta)
|
||||
{
|
||||
string app = "";
|
||||
string tmp = "";
|
||||
try
|
||||
{
|
||||
app = meta.appPath;
|
||||
Directory.CreateDirectory(app);
|
||||
tmp = PathTool.tempPath;
|
||||
if (Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
Directory.CreateDirectory(tmp);
|
||||
File.Copy(zipPath, Path.Combine(app + "package.zip"));
|
||||
completeInstall(meta);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (Directory.Exists(app))
|
||||
Directory.Delete(app, true);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tmp != "" && Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
}
|
||||
}
|
||||
|
||||
private static void completeInstall(App app) => completeInstall(app.appPath, app.name, app.description, app.version, app.mainFile);
|
||||
|
||||
private static void completeInstall(string appPath, string name, string description, Version version, string mainFile)
|
||||
{
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
string tmp = PathTool.tempPath;
|
||||
ZipFile.ExtractToDirectory(Path.Combine(appPath + "package.zip"), tmp);
|
||||
Directory.Move(Path.Combine(tmp + "Data"), Path.Combine(appPath + "app"));
|
||||
XElement el = new XElement("app", new XElement("Name", name), new XElement("Description", description), new XElement("Version", version));
|
||||
if (mainFile != null)
|
||||
el.Add(new XElement(new XElement("MainFile", mainFile)));
|
||||
el.Save(Path.Combine(appPath, "info.xml"));
|
||||
Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = $"/C \"{Path.Combine(tmp, "Install.bat")}\"", WorkingDirectory = Path.Combine(appPath, "app"), CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }).WaitForExit();
|
||||
if (GlobalVariables.relE)
|
||||
GlobalVariables.reloadElements.Invoke();
|
||||
#if !DEBUG
|
||||
}
|
||||
catch { throw; }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace UpTool2
|
||||
namespace UpTool2.Tool
|
||||
{
|
||||
partial class DownloadDialog
|
||||
{
|
||||
|
@ -16,6 +16,7 @@
|
|||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
client.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
|
@ -1,30 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace UpTool2
|
||||
namespace UpTool2.Tool
|
||||
{
|
||||
public partial class DownloadDialog : Form
|
||||
{
|
||||
bool close;
|
||||
WebClient client;
|
||||
private bool close;
|
||||
private readonly WebClient client;
|
||||
public byte[] result;
|
||||
|
||||
public DownloadDialog(string uri)
|
||||
{
|
||||
InitializeComponent();
|
||||
try
|
||||
{
|
||||
WebClient client = new WebClient();
|
||||
client = new WebClient();
|
||||
client.DownloadProgressChanged += progressChanged;
|
||||
client.DownloadDataCompleted += done;
|
||||
//client.DownloadFileAsync(new Uri(uri), file);
|
||||
client.DownloadDataAsync(new Uri(uri), client);
|
||||
}
|
||||
catch
|
||||
|
@ -46,4 +39,4 @@ namespace UpTool2
|
|||
|
||||
private void DownloadDialog_FormClosing(object sender, FormClosingEventArgs e) => e.Cancel = !close;
|
||||
}
|
||||
}
|
||||
}
|
22
UpTool2/Tool/PathTool.cs
Normal file
22
UpTool2/Tool/PathTool.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace UpTool2.Tool
|
||||
{
|
||||
internal static class PathTool
|
||||
{
|
||||
public static string GetProgPath(params string[] segments) => Path.Combine(new[] { dir }.Concat(segments).ToArray());
|
||||
|
||||
public static string dir => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UpTool2");
|
||||
public static string tempPath => GetProgPath("tmp");
|
||||
public static string appsPath => GetProgPath("Apps");
|
||||
public static string infoXML => GetProgPath("info.xml");
|
||||
|
||||
public static string getAppPath(Guid app) => Path.Combine(appsPath, app.ToString());
|
||||
|
||||
public static string getDataPath(Guid app) => Path.Combine(getAppPath(app) + @"app");
|
||||
|
||||
public static string getInfoPath(Guid app) => Path.Combine(getAppPath(app), "info.xml");
|
||||
}
|
||||
}
|
159
UpTool2/Tool/RepoManagement.cs
Normal file
159
UpTool2/Tool/RepoManagement.cs
Normal file
|
@ -0,0 +1,159 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using UpTool2.Data;
|
||||
using UpTool2.Properties;
|
||||
|
||||
namespace UpTool2.Tool
|
||||
{
|
||||
internal static class RepoManagement
|
||||
{
|
||||
public static void fetchRepos()
|
||||
{
|
||||
Program.FixXML(PathTool.infoXML);
|
||||
XElement meta = XDocument.Load(PathTool.infoXML).Element("meta");
|
||||
List<XElement> tmp_apps_list = new List<XElement>();
|
||||
List<string> repArr = meta.Element("Repos").Elements("Repo").Select(s => s.Element("Link").Value).Distinct().ToList();
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
int i = 0;
|
||||
while (i < repArr.Count)
|
||||
{
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
XDocument repo = XDocument.Load(repArr[i]);
|
||||
repArr.AddRange(repo.Element("repo").Elements("repolink").Select(s => s.Value).Where(s => !repArr.Contains(s)));
|
||||
XElement[] tmp_apparray = repo.Element("repo").Elements("app").Where(app => tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value).Count() == 0 ||
|
||||
tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value)
|
||||
.Where(a => a.Element("Version").getVer() >= app.Element("Version").getVer()).Count() == 0).ToArray()
|
||||
.Concat(repo.Element("repo").Elements("applink").Select(s => XDocument.Load(s.Value).Element("app"))).ToArray();
|
||||
for (int i1 = 0; i1 < tmp_apparray.Length; i1++)
|
||||
{
|
||||
XElement app = tmp_apparray[i1];
|
||||
//"Sanity check"
|
||||
int.Parse(app.Element("Version").Value);
|
||||
Guid.Parse(app.Element("ID").Value);
|
||||
//Create XElement
|
||||
tmp_apps_list.Add(new XElement("App",
|
||||
new XElement("Name", app.Element("Name").Value),
|
||||
new XElement("Description", app.Element("Description").Value),
|
||||
new XElement("Version", app.Element("Version").Value),
|
||||
new XElement("ID", app.Element("ID").Value),
|
||||
new XElement("File", app.Element("File").Value),
|
||||
new XElement("Hash", app.Element("Hash").Value)
|
||||
));
|
||||
if (app.Element("MainFile") != null)
|
||||
tmp_apps_list.Last().Add(new XElement("MainFile", app.Element("MainFile").Value));
|
||||
if (app.Element("Icon") != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
//Scale Image and save as Base64
|
||||
Image src = Image.FromStream(client.OpenRead(app.Element("Icon").Value));
|
||||
Bitmap dest = new Bitmap(70, 70);
|
||||
dest.SetResolution(src.HorizontalResolution, src.VerticalResolution);
|
||||
using (Graphics g = Graphics.FromImage(dest))
|
||||
{
|
||||
g.CompositingMode = CompositingMode.SourceCopy;
|
||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
using (var wrapMode = new ImageAttributes())
|
||||
{
|
||||
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
|
||||
g.DrawImage(src, new Rectangle(0, 0, 70, 70), 0, 0, src.Width, src.Height, GraphicsUnit.Pixel, wrapMode);
|
||||
}
|
||||
}
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
dest.Save(ms, ImageFormat.Png);
|
||||
tmp_apps_list.Last().Add(new XElement("Icon", Convert.ToBase64String(ms.ToArray())));
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
if (tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value).Count() > 1)
|
||||
tmp_apps_list.Where(a => a.Element("ID").Value == app.Element("ID").Value).Reverse().Skip(1).ToList().ForEach(a => tmp_apps_list.Remove(a));
|
||||
}
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "Failed to load repo: " + repArr[i]);
|
||||
}
|
||||
#endif
|
||||
i++;
|
||||
}
|
||||
}
|
||||
tmp_apps_list.Sort((x, y) => x.Element("Name").Value.CompareTo(y.Element("Name").Value));
|
||||
if (meta.Element("LocalRepo") == null)
|
||||
meta.Add(new XElement("LocalRepo"));
|
||||
XElement repos = meta.Element("LocalRepo");
|
||||
repos.RemoveNodes();
|
||||
tmp_apps_list.ForEach(app => repos.Add(app));
|
||||
meta.Save(PathTool.infoXML);
|
||||
}
|
||||
|
||||
private static Version getVer(this XElement el) => int.TryParse(el.Value, out int i) ? new Version(0, 0, 0, i) : Version.Parse(el.Value);
|
||||
|
||||
public static void getReposFromDisk()
|
||||
{
|
||||
GlobalVariables.apps.Clear();
|
||||
string xml = PathTool.infoXML;
|
||||
XDocument.Load(xml).Element("meta").Element("LocalRepo").Elements().ToList().ForEach(app =>
|
||||
{
|
||||
Guid id = Guid.Parse(app.Element("ID").Value);
|
||||
string locInPath = PathTool.getInfoPath(id);
|
||||
XElement locIn = File.Exists(locInPath) ? XDocument.Load(locInPath).Element("app") : app;
|
||||
if (int.TryParse(app.Element("Version").Value, out _))
|
||||
app.Element("Version").Value = GlobalVariables.minimumVer.ToString();
|
||||
GlobalVariables.apps.Add(id, new App(
|
||||
name: locIn.Element("Name").Value,
|
||||
description: locIn.Element("Description").Value,
|
||||
version: Version.Parse(app.Element("Version").Value),
|
||||
file: app.Element("File").Value,
|
||||
local: false,
|
||||
hash: app.Element("Hash").Value,
|
||||
iD: id,
|
||||
color: Color.White,
|
||||
icon: app.Element("Icon") == null ? Resources.C_64.ToBitmap() : (Bitmap)new ImageConverter().ConvertFrom(Convert.FromBase64String(app.Element("Icon").Value)),
|
||||
runnable: locIn.Element("MainFile") != null || app.Element("MainFile") != null,
|
||||
mainFile: locIn.Element("MainFile") == null ? app.Element("MainFile") == null ? "" : app.Element("MainFile").Value : locIn.Element("MainFile").Value
|
||||
));
|
||||
#if DEBUG
|
||||
Console.WriteLine(locIn.Element("MainFile") == null ? "NULL" : locIn.Element("MainFile").Value);
|
||||
Console.WriteLine(GlobalVariables.apps[id].mainFile);
|
||||
#endif
|
||||
});
|
||||
Directory.GetDirectories(PathTool.appsPath).Where(s => !GlobalVariables.apps.ContainsKey(Guid.Parse(Path.GetFileName(s)))).ToList().ForEach(s =>
|
||||
{
|
||||
Guid tmp = Guid.Parse(Path.GetFileName(s));
|
||||
try
|
||||
{
|
||||
XElement data = XDocument.Load(PathTool.getInfoPath(tmp)).Element("app");
|
||||
GlobalVariables.apps.Add(tmp, new App("(local) " + data.Element("Name").Value, data.Element("Description").Value, GlobalVariables.minimumVer, "", true, "", tmp, Color.Red, Resources.C_64.ToBitmap(), data.Element("MainFile") != null, data.Element("MainFile") == null ? "" : data.Element("MainFile").Value));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (MessageBox.Show($@"An error occured while loading this local repo:
|
||||
{e.Message}
|
||||
Do you want to exit? Otherwise the folder will be deleted, possibly causeing problems later.", "", MessageBoxButtons.YesNo) == DialogResult.No)
|
||||
Directory.Delete(PathTool.getAppPath(tmp), true);
|
||||
else
|
||||
Environment.Exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,14 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace UpTool2
|
||||
namespace UpTool2.Tool
|
||||
{
|
||||
static class Shortcut
|
||||
internal static class Shortcut
|
||||
{
|
||||
static Type m_type = Type.GetTypeFromProgID("WScript.Shell");
|
||||
static object m_shell = Activator.CreateInstance(m_type);
|
||||
private static Type m_type = Type.GetTypeFromProgID("WScript.Shell");
|
||||
private static object m_shell = Activator.CreateInstance(m_type);
|
||||
|
||||
public static void Make(string target, string fileName)
|
||||
{
|
||||
IWshShortcut shortcut = (IWshShortcut)m_type.InvokeMember("CreateShortcut", BindingFlags.InvokeMethod, null, m_shell, new object[] { fileName });
|
||||
|
@ -20,26 +21,36 @@ namespace UpTool2
|
|||
{
|
||||
[DispId(0)]
|
||||
string FullName { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0)] get; }
|
||||
|
||||
[DispId(0x3e8)]
|
||||
string Arguments { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3e8)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3e8)] set; }
|
||||
|
||||
[DispId(0x3e9)]
|
||||
string Description { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3e9)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3e9)] set; }
|
||||
|
||||
[DispId(0x3ea)]
|
||||
string Hotkey { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3ea)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3ea)] set; }
|
||||
|
||||
[DispId(0x3eb)]
|
||||
string IconLocation { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3eb)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3eb)] set; }
|
||||
|
||||
[DispId(0x3ec)]
|
||||
string RelativePath { [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3ec)] set; }
|
||||
|
||||
[DispId(0x3ed)]
|
||||
string TargetPath { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3ed)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3ed)] set; }
|
||||
|
||||
[DispId(0x3ee)]
|
||||
int WindowStyle { [DispId(0x3ee)] get; [param: In] [DispId(0x3ee)] set; }
|
||||
|
||||
[DispId(0x3ef)]
|
||||
string WorkingDirectory { [return: MarshalAs(UnmanagedType.BStr)] [DispId(0x3ef)] get; [param: In, MarshalAs(UnmanagedType.BStr)] [DispId(0x3ef)] set; }
|
||||
[TypeLibFunc((short)0x40), DispId(0x7d0)]
|
||||
|
||||
[TypeLibFunc(0x40), DispId(0x7d0)]
|
||||
void Load([In, MarshalAs(UnmanagedType.BStr)] string PathLink);
|
||||
|
||||
[DispId(0x7d1)]
|
||||
void Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
<RootNamespace>UpTool2</RootNamespace>
|
||||
<AssemblyName>UpTool2</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>false</Deterministic>
|
||||
|
@ -53,12 +54,12 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App.cs" />
|
||||
<Compile Include="AppInstall.cs" />
|
||||
<Compile Include="DownloadDialog.cs">
|
||||
<Compile Include="DataStructures\App.cs" />
|
||||
<Compile Include="Tool\AppInstall.cs" />
|
||||
<Compile Include="Tool\DownloadDialog.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DownloadDialog.Designer.cs">
|
||||
<Compile Include="Tool\DownloadDialog.Designer.cs">
|
||||
<DependentUpon>DownloadDialog.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="GlobalVariables.cs" />
|
||||
|
@ -70,16 +71,17 @@
|
|||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RepoManagement.cs" />
|
||||
<Compile Include="Shortcut.cs" />
|
||||
<Compile Include="Tool\PathTool.cs" />
|
||||
<Compile Include="Tool\RepoManagement.cs" />
|
||||
<Compile Include="Tool\Shortcut.cs" />
|
||||
<Compile Include="SourcesForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SourcesForm.Designer.cs">
|
||||
<DependentUpon>SourcesForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Status.cs" />
|
||||
<EmbeddedResource Include="DownloadDialog.resx">
|
||||
<Compile Include="DataStructures\Status.cs" />
|
||||
<EmbeddedResource Include="Tool\DownloadDialog.resx">
|
||||
<DependentUpon>DownloadDialog.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="MainForm.resx">
|
||||
|
|
Reference in New Issue
Block a user