public static FileInfo downloadUpdate(LocalIni local, ServerIni serv) { List <string> values = new List <string>(serv.zipFiles.Values); List <string> keys = new List <string>(serv.zipFiles.Keys); using (WebClient webClient = new WebClient()) { int i = 0; for (; i < values.Count; i++) { //try resume if (File.Exists(Util.getUpdateDirPath() + values[i]) && CheckSum.verifyMd5Hash(Util.getUpdateDirPath() + values[i], keys[i])) { continue; } //download File.WriteAllText(Util.getUpdateDirPath() + values[i], webClient.DownloadString(new Uri(Util.concutUrl(local.serverUri.ToString(), values[i]))), Encoding.Default); //check sum if (!CheckSum.verifyMd5Hash(Util.getUpdateDirPath() + values[i], keys[i]))//second attempt { File.WriteAllText(Util.getUpdateDirPath() + values[i], webClient.DownloadString(new Uri(Util.concutUrl(local.serverUri.ToString(), values[i]))), Encoding.Default); if (!CheckSum.verifyMd5Hash(Util.getUpdateDirPath() + values[i], keys[i])) { throw new Exception("file download error"); } } } } //combine files string updateFile = Util.getUpdateDirPath() + "update.zip"; File.Create(updateFile); foreach (string file in values) { string curFile = Util.getUpdateDirPath() + file; File.AppendAllText(updateFile, File.ReadAllText(curFile, Encoding.Default), Encoding.Default); File.Delete(curFile); } return(new FileInfo(updateFile)); }
public static ServerIni getServerIni(LocalIni local) { ServerIni ret = new ServerIni(); string[] versionIni = Util.readFileRemoteFile(local.serverUri); double d; Double.TryParse(versionIni[0], out d); //read version ret.version = d; for (int i = 1; i + 1 < versionIni.Length; i += 2) { Debug.Assert(i + 1 < versionIni.Length); ret.addIfNonFile(versionIni[i + 1], versionIni[i]); } return(ret); }
static void Main(string[] args) { try { local = getLocalIni(LOCAL_INI_NAME); serv = getServerIni(local); if (local.version < serv.version) { form = new updateForm(); form.ShowDialog(); } else { Process.Start(Path.Combine(Util.getModulePath().ToString(), EXEC_NAME)); } } catch (Exception) { Process.Start(Path.Combine(Util.getModulePath().ToString(), EXEC_NAME)); } }