private async Task QOL_PLUGIN_CHECK() { //Can't really do a check if a game instance is already running. if (ACTIVE_SESSIONS.Count > 0) { return; } string x86Path = Path.Combine(plugins_x86, "multitool_qol.dll"); string x64Path = Path.Combine(plugins_x64, "multitool_qol.dll"); if ((File.Exists(x64Path) && File.Exists(x86Path)) && CalculateMD5(x86Path) == MainPage.onlineJson.QOL_HASH[0].ToLower() && CalculateMD5(x64Path) == MainPage.onlineJson.QOL_HASH[1].ToLower()) { return; } else { _progressControl = new ProgressControl(); ProgressGrid.Visibility = Visibility.Visible; MainGrid.Visibility = Visibility.Collapsed; ProgressPanel.Children.Add(_progressControl); System.Net.WebClient client = new System.Net.WebClient(); try { ProgressControl.updateProgressLabel("Downloading multitool_qol"); if (!Directory.Exists(@".\modpolice")) { Directory.CreateDirectory(@".\modpolice"); } if (File.Exists(@".\modpolice\" + MainPage.onlineJson.QOL_ARCHIVE)) { File.Delete(@".\modpolice\" + MainPage.onlineJson.QOL_ARCHIVE); } if (File.Exists(@".\modpolice\bin\plugins\multitool_qol.dll")) { File.Delete(@".\modpolice\bin\plugins\multitool_qol.dll"); } if (File.Exists(@".\modpolice\bin64\plugins\multitool_qol.dll")) { File.Delete(@".\modpolice\bin64\plugins\multitool_qol.dll"); } await Task.Delay(500); client.DownloadFile(String.Format("http://tonic.pw/files/bnsmultitool/{0}", MainPage.onlineJson.QOL_ARCHIVE), @".\modpolice\" + MainPage.onlineJson.QOL_ARCHIVE); ProgressControl.updateProgressLabel("Decompressing"); Modpolice.ExtractZipFileToDirectory(@".\modpolice\" + MainPage.onlineJson.QOL_ARCHIVE, @".\modpolice", true); await Task.Delay(500); ProgressControl.updateProgressLabel("Installing"); if (File.Exists(x86Path)) { File.Delete(x86Path); } if (File.Exists(x64Path)) { File.Delete(x64Path); } File.Move(@".\modpolice\bin\plugins\multitool_qol.dll", x86Path); File.Move(@".\modpolice\bin64\plugins\multitool_qol.dll", x64Path); ProgressControl.updateProgressLabel("Verifying anti-virus didn't clap it"); await Task.Delay(3000); if (!File.Exists(x86Path) || !File.Exists(x64Path)) { ProgressControl.updateProgressLabel(String.Format("multitool_qol.dll missing {0} {1}", !File.Exists(x86Path) ? "x86 " : "", !File.Exists(x64Path) ? "x64" : "")); await Task.Delay(5000); } } catch (Exception ex) { Debug.WriteLine("{0}", ex.Message); ProgressControl.updateProgressLabel(ex.Message); await Task.Delay(5000); } finally { client.Dispose(); } ProgressGrid.Visibility = Visibility.Hidden; MainGrid.Visibility = Visibility.Visible; ProgressPanel.Children.Clear(); _progressControl = null; } }
private async void installLoginHelperClick(object sender, RoutedEventArgs e) { _progressControl = new ProgressControl(); ProgressGrid.Visibility = Visibility.Visible; MainGrid.Visibility = Visibility.Collapsed; ProgressPanel.Children.Add(_progressControl); string pluginName = "loginhelper"; if (((Button)sender).Name.Contains("CHARSELECT")) { pluginName = "charselect"; } await Task.Run(async() => { try { if (!Directory.Exists("modpolice")) { Directory.CreateDirectory("modpolice"); } ProgressControl.updateProgressLabel("Logging into Mega anonymously..."); var client = new MegaApiClient(); await client.LoginAnonymousAsync(); if (!Directory.Exists("modpolice")) { Directory.CreateDirectory("modpolice"); } ProgressControl.updateProgressLabel("Retrieving file list..."); IEnumerable <INode> nodes = await client.GetNodesFromLinkAsync(new Uri("https://mega.nz/folder/4EUF2IhL#Ci1Y-sbbyw7nwwMGvHV2_w")); INode currentNode = null; IProgress <double> progress = new Progress <double>(x => ProgressControl.updateProgressLabel(String.Format("Downloading: {0} ({1}%)", currentNode.Name, Math.Round(x)))); //Find our latest nodes for download INode loginhelper_node = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains(pluginName)).OrderByDescending(t => t.ModificationDate).FirstOrDefault(); if (loginhelper_node == null) { ProgressControl.errorSadPeepo(Visibility.Visible); ProgressControl.updateProgressLabel("Something went wrong getting the node"); await Task.Delay(7000); return; } if (File.Exists(@"modpolice\" + loginhelper_node.Name)) { File.Delete(@"modpolice\" + loginhelper_node.Name); } currentNode = loginhelper_node; await client.DownloadFileAsync(currentNode, @"modpolice\" + loginhelper_node.Name, progress); ProgressControl.updateProgressLabel("Unzipping: " + loginhelper_node.Name); await Task.Delay(750); Modpolice.ExtractZipFileToDirectory(@".\modpolice\" + loginhelper_node.Name, @".\modpolice", true); ProgressControl.updateProgressLabel("Installing " + pluginName + " x86"); await Task.Delay(750); if (!Directory.Exists(plugins_x86)) { Directory.CreateDirectory(plugins_x86); } ProgressControl.updateProgressLabel("Installing " + pluginName + " x86"); if (File.Exists(Path.Combine(plugins_x86, pluginName + ".dll"))) { File.Delete(Path.Combine(plugins_x86, pluginName + ".dll")); } File.Move(@".\modpolice\bin\plugins\" + pluginName + ".dll", Path.Combine(plugins_x86, pluginName + ".dll")); ProgressControl.updateProgressLabel("Installing " + pluginName + " x64"); await Task.Delay(750); if (!Directory.Exists(plugins_x64)) { Directory.CreateDirectory(plugins_x64); } ProgressControl.updateProgressLabel("Installing " + pluginName + " x64"); if (File.Exists(Path.Combine(plugins_x64, pluginName + ".dll"))) { File.Delete(Path.Combine(plugins_x64, pluginName + ".dll")); } File.Move(@".\modpolice\bin64\plugins\" + pluginName + ".dll", Path.Combine(plugins_x64, pluginName + ".dll")); if (pluginName == "loginhelper") { ProgressControl.updateProgressLabel("Searching for use-ingame-login.xml"); await Task.Delay(750); if (!File.Exists(login_xml)) { ProgressControl.updateProgressLabel("patches.xml not found, installing..."); if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "BnS", "patches"))) { Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "BnS", "patches")); } File.WriteAllText(login_xml, Properties.Resources.use_ingame_login); } } ProgressControl.updateProgressLabel("All done, just tidying up."); await client.LogoutAsync(); } catch (Exception ex) { ProgressControl.errorSadPeepo(Visibility.Visible); ProgressControl.updateProgressLabel(ex.Message); await Task.Delay(7000); } }); ProgressGrid.Visibility = Visibility.Hidden; MainGrid.Visibility = Visibility.Visible; ProgressPanel.Children.Clear(); _progressControl = null; //Check if loginhelper is installed loginHelper_installed = (File.Exists(Path.Combine(plugins_x86, pluginName + ".dll")) && File.Exists(Path.Combine(plugins_x64, pluginName + ".dll"))); charselect_installed = (File.Exists(Path.Combine(plugins_x86, "charselect.dll")) && File.Exists(Path.Combine(plugins_x64, "charselect.dll"))); await Task.Run(async() => await checkOnlineVersion()); }
private async void installAdditional(object sender, RoutedEventArgs e) { string pluginName; switch (((Button)sender).Name) { case "simplemodeInstall": pluginName = "simplemodetrainingroom"; break; case "lessloadingInstall": pluginName = "lessloadingscreens"; break; default: pluginName = "highpriority"; break; } toggleControl = false; _progressControl = new ProgressControl(); ProgressGrid.Visibility = Visibility.Visible; MainGrid.Visibility = Visibility.Collapsed; ProgressPanel.Children.Add(_progressControl); try { if (!Directory.Exists("modpolice")) { Directory.CreateDirectory("modpolice"); } ProgressControl.updateProgressLabel("Logging into Mega"); var client = new MegaApiClient(); await client.LoginAnonymousAsync(); ProgressControl.updateProgressLabel("Retrieving file list..."); IEnumerable <INode> nodes = await client.GetNodesFromLinkAsync(new Uri("https://mega.nz/folder/WXhzUZ7Y#XzlqkPa8DU4X8xrILQDdZA")); INode currentNode = null; IProgress <double> progress = new Progress <double>(x => ProgressControl.updateProgressLabel(String.Format("Downloading: {0} ({1}%)", currentNode.Name, Math.Round(x)))); INode pluginNode = nodes.Where(x => x.Type == NodeType.File && x.Name.Contains(pluginName)).OrderByDescending(t => t.ModificationDate).FirstOrDefault(); if (pluginNode == null) { ProgressControl.errorSadPeepo(Visibility.Visible); ProgressControl.updateProgressLabel("Something went wrong getting the node"); await Task.Delay(5000); toggleControl = true; return; } if (File.Exists(@"modpolice\" + pluginNode.Name)) { File.Delete(@"modpolice\" + pluginNode.Name); } currentNode = pluginNode; await client.DownloadFileAsync(currentNode, @"modpolice\" + pluginNode.Name, progress); ProgressControl.updateProgressLabel("Unzipping: " + pluginNode.Name); await Task.Delay(750); Modpolice.ExtractZipFileToDirectory(@".\modpolice\" + pluginNode.Name, @".\modpolice", true); ProgressControl.updateProgressLabel("Installing " + pluginName + " x86"); await Task.Delay(750); if (!Directory.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86)) { Directory.CreateDirectory(SystemConfig.SYS.BNS_DIR + plugins_x86); } //Delete the current plugin dll if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + pluginName + ".dll")) { File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x86 + pluginName + ".dll"); } //Make sure there isn't a plugin dll that is in an off state if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x86 + pluginName + ".dll.off")) { File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x86 + pluginName + ".dll.off"); } File.Move(@".\modpolice\bin\plugins\" + pluginName + ".dll", SystemConfig.SYS.BNS_DIR + plugins_x86 + pluginName + ".dll"); ProgressControl.updateProgressLabel("Installing " + pluginName + " x64"); await Task.Delay(750); if (!Directory.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64)) { Directory.CreateDirectory(SystemConfig.SYS.BNS_DIR + plugins_x64); } //Delete the current plugin dll if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + pluginName + ".dll")) { File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x64 + pluginName + ".dll"); } //Make sure there isn't a plugin dll that is in an off state if (File.Exists(SystemConfig.SYS.BNS_DIR + plugins_x64 + pluginName + ".dll.off")) { File.Delete(SystemConfig.SYS.BNS_DIR + plugins_x64 + pluginName + ".dll.off"); } File.Move(@".\modpolice\bin64\plugins\" + pluginName + ".dll", SystemConfig.SYS.BNS_DIR + plugins_x64 + pluginName + ".dll"); ProgressControl.updateProgressLabel("All done"); await Task.Delay(750); await client.LogoutAsync(); } catch (Exception ex) { ProgressControl.errorSadPeepo(Visibility.Visible); ProgressControl.updateProgressLabel(ex.Message); await Task.Delay(7000); } try { ProgressGrid.Visibility = Visibility.Hidden; MainGrid.Visibility = Visibility.Visible; ProgressPanel.Children.Clear(); _progressControl = null; toggleControl = true; if (pluginName == "simplemodetrainingroom") { simplemodeTraining = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "simplemodetrainingroom.dll"); Dispatchers.toggleIsChecked(simplemodeToggle, true); Dispatchers.labelContent(SimplemodeCurrentLbl, String.Format("Current: {0}", (simplemodeTraining != null) ? simplemodeTraining.modificationTime.ToString("MM-dd-yy") : "Not Installed")); } else if (pluginName == "lessloadingscreens") { lessLoadingScreen = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "lessloadingscreens.dll"); Dispatchers.toggleIsChecked(lessloadingToggle, true); Dispatchers.labelContent(lessloadingCurrentLbl, String.Format("Current: {0}", (lessLoadingScreen != null) ? lessLoadingScreen.modificationTime.ToString("MM-dd-yy") : "Not Installed")); } else { highpriorityplugin = new pluginFileInfo(SystemConfig.SYS.BNS_DIR + plugins_x86 + "highpriority.dll"); Dispatchers.toggleIsChecked(HighpriorityToggle, true); Dispatchers.labelContent(HighpriorityCurrentLbl, String.Format("Current: {0}", (highpriorityplugin != null) ? highpriorityplugin.modificationTime.ToString("MM-dd-yy") : "Not Installed")); } Dispatchers.btnIsEnabled((Button)sender, false); } catch (Exception) { //F**K ASS C**T } }