No longer create some temporary files. Everything else still needs to be set up to allow for this!
This commit is contained in:
parent
7d0c62cab7
commit
98c0035d18
@ -13,4 +13,6 @@
|
|||||||
- info.xml
|
- info.xml
|
||||||
- Version
|
- Version
|
||||||
- Repos
|
- Repos
|
||||||
- Local Repo
|
- Local Repo
|
||||||
|
- Install
|
||||||
|
- __ZIP_CONTENTS
|
@ -14,15 +14,18 @@ namespace UpTool2
|
|||||||
public partial class DownloadDialog : Form
|
public partial class DownloadDialog : Form
|
||||||
{
|
{
|
||||||
bool close;
|
bool close;
|
||||||
public DownloadDialog(string uri, string file)
|
WebClient client;
|
||||||
|
public byte[] result;
|
||||||
|
public DownloadDialog(string uri)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WebClient client = new WebClient();
|
WebClient client = new WebClient();
|
||||||
client.DownloadProgressChanged += progressChanged;
|
client.DownloadProgressChanged += progressChanged;
|
||||||
client.DownloadFileCompleted += done;
|
client.DownloadDataCompleted += done;
|
||||||
client.DownloadFileAsync(new Uri(uri), file);
|
//client.DownloadFileAsync(new Uri(uri), file);
|
||||||
|
client.DownloadDataAsync(new Uri(uri), client);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -31,10 +34,11 @@ namespace UpTool2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void done(object sender, AsyncCompletedEventArgs e)
|
private void done(object sender, DownloadDataCompletedEventArgs e)
|
||||||
{
|
{
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
close = true;
|
close = true;
|
||||||
|
result = e.Result;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,26 +145,29 @@ namespace UpTool2
|
|||||||
XElement meta = XDocument.Load(metaXML).Element("meta");
|
XElement meta = XDocument.Load(metaXML).Element("meta");
|
||||||
if (Assembly.GetExecutingAssembly().GetName().Version < Version.Parse(meta.Element("Version").Value))
|
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)
|
if (dlg.ShowDialog() != DialogResult.OK)
|
||||||
throw new Exception("Failed to update");
|
throw new Exception("Failed to update");
|
||||||
|
dl = dlg.result;
|
||||||
}
|
}
|
||||||
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
|
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())
|
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());
|
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"))
|
if (Directory.Exists(dir + @"\Install"))
|
||||||
File.Delete(dir + @"\update.exe");
|
Directory.Delete(dir + @"\Install", true);
|
||||||
if (Directory.Exists(dir + @"\update"))
|
using (MemoryStream ms = new MemoryStream(dl))
|
||||||
Directory.Delete(dir + @"\update", true);
|
using (ZipArchive ar = new ZipArchive(ms))
|
||||||
ZipFile.ExtractToDirectory(dir + @"\update.tmp", dir + @"\update");
|
{
|
||||||
File.Delete(dir + @"\update.tmp");
|
ar.Entries.Where(s => !string.IsNullOrEmpty(s.Name)).ToList().ForEach(s =>
|
||||||
string[] array = Directory.GetFiles(dir + @"\update\Release");
|
{
|
||||||
for (int i = 0; i < array.Length; i++)
|
s.ExtractToFile(dir + @"\Install\" + s.Name, true);
|
||||||
File.Copy(array[i], dir + @"\update.exe", true);
|
});
|
||||||
|
}
|
||||||
splash.Hide();
|
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 });
|
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;
|
return false;
|
||||||
|
Reference in New Issue
Block a user