private void _BeginDownload(UpdateInfoObject updateInfoObject) { _webClient = new WebClientWithTimeout(); _webClient.DownloadFileCompleted += _DownloadFileCompletedHandler; _webClient.DownloadProgressChanged += _DownloadFileProgressChangedHandler; _webClient.DownloadFileAsync(new Uri(updateInfoObject.Link), _updatePath, updateInfoObject); _RaiseBeginDownload(); }
public void DoModNetJob() { File.Delete("ModManager.dat"); if (!Directory.Exists("modules")) { Directory.CreateDirectory("modules"); } if (!Directory.Exists("scripts")) { Directory.CreateDirectory("scripts"); } String[] GlobalFiles = new string[] { "dinput8.dll", "global.ini" }; String[] ModNetReloadedFiles = new string[] { "7z.dll", "PocoFoundation.dll", "PocoNet.dll", "ModLoader.asi" }; String[] ModNetLegacyFiles = new string[] { "modules/udpcrc.soapbox.module", "modules/udpcrypt1.soapbox.module", "modules/udpcrypt2.soapbox.module", "modules/xmppsubject.soapbox.module", "scripts/global.ini", "lightfx.dll", "ModManager.asi", "global.ini" }; String[] RemoveAllFiles = GlobalFiles.Concat(ModNetReloadedFiles).Concat(ModNetLegacyFiles).ToArray(); foreach (string file in RemoveAllFiles) { if (File.Exists(file)) { try { File.Delete(file); } catch { MessageBox.Show($"File {file} cannot be deleted.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } actionText.Text = "Detecting ModNetSupport for " + serverText.SelectedItem.ToString(); String jsonModNet = ModNetReloaded.ModNetSupported(serverText.SelectedValue.ToString()); if (jsonModNet != String.Empty) { actionText.Text = "ModNetReloaded support detected, downloading required files..."; string[] newFiles = GlobalFiles.Concat(ModNetReloadedFiles).ToArray(); try { try { if (File.Exists("lightfx.dll")) { File.Delete("lightfx.dll"); } } catch { } WebClientWithTimeout newModNetFilesDownload = new WebClientWithTimeout(); foreach (string file in newFiles) { actionText.Text = "Fetching ModNetReloaded Files: " + file; Application.DoEvents(); newModNetFilesDownload.DownloadFile("https://cdn.soapboxrace.world/modules/" + file, file); } try { newModNetFilesDownload.DownloadFile("https://launcher.worldunited.gg/legacy/global.ini", "global.ini"); } catch { } SimpleJSON.JSONNode MainJson = SimpleJSON.JSON.Parse(jsonModNet); Uri newIndexFile = new Uri(MainJson["basePath"] + "/index.json"); String jsonindex = new WebClientWithTimeout().DownloadString(newIndexFile); SimpleJSON.JSONNode IndexJson = SimpleJSON.JSON.Parse(jsonindex); CountFilesTotal = IndexJson["entries"].Count; String path = Path.Combine("MODS", MDFive.HashPassword(MainJson["serverID"]).ToLower()); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (JSONNode modfile in IndexJson["entries"]) { if (SHA.HashFile(path + "/" + modfile["Name"]).ToLower() != modfile["Checksum"]) { WebClientWithTimeout client2 = new WebClientWithTimeout(); client2.DownloadFileAsync(new Uri(MainJson["basePath"] + "/" + modfile["Name"]), path + "/" + modfile["Name"]); client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client2.DownloadFileCompleted += (test, stuff) => { if (SHA.HashFile(path + "/" + modfile["Name"]).ToLower() == modfile["Checksum"]) { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } else { File.Delete(path + "/" + modfile["Name"]); Console.WriteLine(modfile["Name"] + " must be removed."); DoModNetJob(); } }; } else { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { string[] newFiles = GlobalFiles.Concat(ModNetLegacyFiles).ToArray(); WebClientWithTimeout newModNetFilesDownload = new WebClientWithTimeout(); foreach (string file in newFiles) { actionText.Text = "Fetching LegacyModnet Files: " + file; Application.DoEvents(); newModNetFilesDownload.DownloadFile("http://launcher.worldunited.gg/legacy/" + file, file); } if (result["modsUrl"] != null) { actionText.Text = "Electron support detected, checking mods..."; Uri newIndexFile = new Uri(result["modsUrl"] + "/index.json"); String jsonindex = new WebClientWithTimeout().DownloadString(newIndexFile); SimpleJSON.JSONNode IndexJson = SimpleJSON.JSON.Parse(jsonindex); CountFilesTotal = IndexJson.Count; String electronpath = (new Uri(serverText.SelectedValue.ToString()).Host).Replace(".", "-"); String path = Path.Combine("MODS", electronpath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.WriteAllText(path + ".json", jsonindex); using (var fs = new FileStream("ModManager.dat", FileMode.Create)) using (var bw = new BinaryWriter(fs)) { bw.Write(CountFilesTotal); foreach (JSONNode file in IndexJson) { var originalPath = Path.Combine(file["file"]).Replace("/", "\\").ToUpper(); var modPath = Path.Combine(path, file["file"]).Replace("/", "\\").ToUpper(); bw.Write(originalPath.Length); bw.Write(originalPath.ToCharArray()); bw.Write(modPath.Length); bw.Write(modPath.ToCharArray()); } } foreach (JSONNode modfile in IndexJson) { String directorycreate = Path.GetDirectoryName(path + "/" + modfile["file"]); Directory.CreateDirectory(directorycreate); if (ElectronModNet.calculateHash(path + "/" + modfile["file"]) != modfile["hash"]) { WebClientWithTimeout client2 = new WebClientWithTimeout(); client2.DownloadFileAsync(new Uri(result["modsUrl"] + "/" + modfile["file"]), path + "/" + modfile["file"]); client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client2.DownloadFileCompleted += (test, stuff) => { if (ElectronModNet.calculateHash(path + "/" + modfile["file"]) == modfile["hash"]) { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } else { File.Delete(path + "/" + modfile["file"]); Console.WriteLine(modfile["file"] + " must be removed."); DoModNetJob(); } }; } else { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } } } else if ((bool)result["rwacallow"] == true) { actionText.Text = "RWAC support detected, checking mods..."; String rwacpath = MDFive.HashPassword(new Uri(serverText.SelectedValue.ToString()).Host); String path = Path.Combine("MODS", rwacpath); Uri rwac_wev2 = new Uri(result["homePageUrl"] + "/rwac/fileschecker_sbrw.xml"); String getcontent = new WebClient().DownloadString(rwac_wev2); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(getcontent); var nodes = xmlDoc.SelectNodes("rwac/files/file"); CountFilesTotal = nodes.Count; //ModManager.dat using (var fs = new FileStream("ModManager.dat", FileMode.Create)) using (var bw = new BinaryWriter(fs)) { bw.Write(nodes.Count); foreach (XmlNode files in nodes) { string realfilepath = Path.Combine(files.Attributes["path"].Value, files.Attributes["name"].Value); String directorycreate = Path.GetDirectoryName(path + "/" + realfilepath); var originalPath = Path.Combine(realfilepath).Replace("/", "\\").ToUpper(); var modPath = Path.Combine(path, realfilepath).Replace("/", "\\").ToUpper(); bw.Write(originalPath.Length); bw.Write(originalPath.ToCharArray()); bw.Write(modPath.Length); bw.Write(modPath.ToCharArray()); Directory.CreateDirectory(directorycreate); if (files.Attributes["download"].Value != String.Empty) { if (MDFive.HashFile(path + "/" + realfilepath).ToLower() != files.InnerText) { WebClientWithTimeout client2 = new WebClientWithTimeout(); client2.DownloadFileAsync(new Uri(files.Attributes["download"].Value), path + "/" + realfilepath); client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client2.DownloadFileCompleted += (test, stuff) => { if (MDFive.HashFile(path + "/" + realfilepath).ToLower() == files.InnerText) { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } else { File.Delete(path + "/" + realfilepath); Console.WriteLine(realfilepath + " must be removed."); DoModNetJob(); } }; } else { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } } else { CountFiles++; if (CountFiles == CountFilesTotal) { launchGame(); } } } } } else { actionText.Text = "Deprecated modnet detected. Aborting..."; launchGame(); } } }