No longer create some temporary files. Everything else still needs to be set up to allow for this!

This commit is contained in:
CreepyCrafter24 2019-12-19 18:36:43 +01:00
parent 7d0c62cab7
commit 98c0035d18
3 changed files with 25 additions and 16 deletions

View File

@ -13,4 +13,6 @@
- info.xml
- Version
- Repos
- Local Repo
- Local Repo
- Install
- __ZIP_CONTENTS

View File

@ -14,15 +14,18 @@ namespace UpTool2
public partial class DownloadDialog : Form
{
bool close;
public DownloadDialog(string uri, string file)
WebClient client;
public byte[] result;
public DownloadDialog(string uri)
{
InitializeComponent();
try
{
WebClient client = new WebClient();
client.DownloadProgressChanged += progressChanged;
client.DownloadFileCompleted += done;
client.DownloadFileAsync(new Uri(uri), file);
client.DownloadDataCompleted += done;
//client.DownloadFileAsync(new Uri(uri), file);
client.DownloadDataAsync(new Uri(uri), client);
}
catch
{
@ -31,10 +34,11 @@ namespace UpTool2
}
}
private void done(object sender, AsyncCompletedEventArgs e)
private void done(object sender, DownloadDataCompletedEventArgs e)
{
DialogResult = DialogResult.OK;
close = true;
result = e.Result;
Close();
}

View File

@ -145,26 +145,29 @@ namespace UpTool2
XElement meta = XDocument.Load(metaXML).Element("meta");
if (Assembly.GetExecutingAssembly().GetName().Version < Version.Parse(meta.Element("Version").Value))
{
using (DownloadDialog dlg = new DownloadDialog(meta.Element("File").Value, dir + @"\update.tmp"))
byte[] dl;
using (DownloadDialog dlg = new DownloadDialog(meta.Element("File").Value))
{
if (dlg.ShowDialog() != DialogResult.OK)
throw new Exception("Failed to update");
dl = dlg.result;
}
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
{
string pkghash = BitConverter.ToString(sha256.ComputeHash(File.ReadAllBytes(dir + @"\update.tmp"))).Replace("-", string.Empty).ToUpper();
string pkghash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty).ToUpper();
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 (File.Exists(dir + @"\update.exe"))
File.Delete(dir + @"\update.exe");
if (Directory.Exists(dir + @"\update"))
Directory.Delete(dir + @"\update", true);
ZipFile.ExtractToDirectory(dir + @"\update.tmp", dir + @"\update");
File.Delete(dir + @"\update.tmp");
string[] array = Directory.GetFiles(dir + @"\update\Release");
for (int i = 0; i < array.Length; i++)
File.Copy(array[i], dir + @"\update.exe", true);
if (Directory.Exists(dir + @"\Install"))
Directory.Delete(dir + @"\Install", true);
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(dir + @"\Install\" + s.Name, true);
});
}
splash.Hide();
Process.Start(new ProcessStartInfo { FileName = "cmd.exe", Arguments = "/C timeout /t 2 & copy /b/v/y \"" + dir + @"\update.exe" + "\" \"" + Application.ExecutablePath + "\" & \"" + Application.ExecutablePath + "\"", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden });
return false;