private static void DownloadFile(string address, string downloadPath, bool closeAndDeleteApplication) { // Start a new thread for the download part only. new Thread(() => { // WebClient is more high level than HttpClient using (WebClient webClient = new WebClient()) { ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; //webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); try { webClient.DownloadFileAsync(new Uri(address), downloadPath); while (webClient.IsBusy) { Application.DoEvents(); } closeAndDelete = closeAndDeleteApplication; } catch (Exception ex) { ThemedMessageBox.Show(ex.Message, "Download Error:"); } } }).Start(); }
//private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e) //{ // ThemedMessageBox.Show(e.ProgressPercentage + "%"); //} private static void Completed(object sender, AsyncCompletedEventArgs e) { if (closeAndDelete) { ThemedMessageBox.Show("Download completed!\nApplication will restart to take effect", "Good news!"); CleanupAndStartApp(); } }
public static DialogResult CheckForUpdates(bool silently) { // Checking version mentioned in "version" file on GitHub latestStringVersion = DownloadString(EXE_VERSION_TEXT_URL); int latestVersion; bool showMessageBox; string message; string title; DialogResult result; if (latestStringVersion.Length == 0) { showMessageBox = true; message = "There is no data in \"version\" file on GitHub!"; title = "Warning!"; result = DialogResult.Abort; goto SHOW_MESSAGEBOX; } try { latestVersion = Convert.ToInt32(latestStringVersion.Replace(".", "")); } catch (Exception ex) { showMessageBox = true; message = "There is something wrong with version number in \"version\" file on GitHub!\n" + ex.Message; title = "Warning!"; result = DialogResult.Abort; goto SHOW_MESSAGEBOX; } if (currentVersion < latestVersion) { return(ThemedDialogueBox.Show($"The new DoW Mod Manager v{latestStringVersion} is available. Do you wish to update now?", "New update available", exeORmods: "exe")); } else { showMessageBox = true; message = "You have the latest version!"; title = "Good news!"; result = DialogResult.Cancel; } SHOW_MESSAGEBOX: if (!silently) { if (showMessageBox) { ThemedMessageBox.Show(message, title); } } return(result); }
/// <summary> /// This method saves changes to the *.module file /// </summary> private void ButtonSaveFile_Click(object sender, EventArgs e) { string filePath = modManager.ModuleFilePaths[loadedModBox.SelectedIndex]; List <string> listOfMods = new List <string>(); using (StreamReader sr = new StreamReader(filePath)) { string line; // Populate the Required Mods List with entries from the .module file while ((line = sr.ReadLine()) != null && !line.Contains("RequiredMod")) { listOfMods.Add(line); } } string modString = ""; // Write more info into the list of mods for (int i = 0; i < modlist.Count; i++) { switch (modlist[i].State) { case ModState.Active: break; case ModState.Inactive: modString = "//"; break; case ModState.Pending: break; } modString = "RequiredMod." + (i + 1) + " = " + modlist[i].Name; listOfMods.Add(modString); } // Finally write the stuff using (StreamWriter sw = new StreamWriter(filePath)) { for (int i = 0; i < listOfMods.Count; i++) { sw.WriteLine(listOfMods[i]); } } // Update the Main Mod Manager List with possible new entries modManager.SetUpAllNecessaryMods(); // Update the Dropdown list with the new entries GetLoadableMods(); ReselectLastItems(); // Show a Succesprompt ThemedMessageBox.Show("Module file changes were successfully applied!", "Saving successful"); }
/// <summary> /// This function occurs when the delete button was pressed and removes a merge. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonDelete_Click(object sender, EventArgs e) { int selIndex = loadedModBox.SelectedIndex; string filePath = moduleList[selIndex].Parent.FilePath; lastDropDownItemIndex = selIndex; File.Delete(filePath); // Show a Succesprompt ThemedMessageBox.Show("Current merged module file was deleted and all changes were successfully reverted!", "Delete successful!"); }
private static string DownloadString(string address) { string str = ""; using (WebClient webClient = new WebClient()) { try { str = webClient.DownloadString(address); } catch (Exception ex) { ThemedMessageBox.Show(ex.Message, "Download Error:"); } } return(str); }
public MiniBrowser(string URL) { InitializeComponent(); webBrowser1.ScriptErrorsSuppressed = true; // Use the same icon as executable Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); pictureBox.Image = Icon.ToBitmap(); try { webBrowser1.Navigate(new Uri(URL)); } catch (Exception) { ThemedMessageBox.Show("Something wrong with this URL:\n" + URL); } }
/// <summary> /// This method will be called right after Constructor /// </summary> private void FontsManagerForm_Load(object sender, EventArgs e) { if (Directory.Exists(FONTS_DIRECTORY)) { openFileDialog1.InitialDirectory = FONTS_DIRECTORY; if (!File.Exists(backupFileNameWithPath)) { // First, we create an archive from a font folder and write it in DoW root directory ZipFile.CreateFromDirectory(FONTS_DIRECTORY, BACKUP_FILE_NAME); // Then we move backup file to a Font directory for convenience // DO NOT just create arhive in the same directory, because it will try to achive itself ;-) // (or use more complex ZipArchive class) File.Move(BACKUP_FILE_NAME, backupFileNameWithPath); } } else { ThemedMessageBox.Show("If you want to manage your fonts - install \"A Larger Fonts\" mod first!", "Suggestion:"); Close(); } }
// TODO: It looks very similar to CheckForUpdates() public static DialogResult CheckForNewModlist(bool silently) { // Checking version mentioned in "version" file on GitHub latestStringVersion = DownloadString(MODLIST_VERSION_TEXT_URL); int latestModlistVersion; bool showMessageBox; string message; string title; DialogResult result; if (latestStringVersion.Length == 0) { showMessageBox = true; message = "There is no data in \"version\" file on GitHub!"; title = "Warning!"; result = DialogResult.Abort; goto SHOW_MESSAGEBOX; } try { latestModlistVersion = Convert.ToInt32(latestStringVersion.Replace(".", "")); } catch (Exception ex) { showMessageBox = true; message = "There is something wrong with version number in \"version\" file on GitHub!\n" + ex.Message; title = "Warning!"; result = DialogResult.Abort; goto SHOW_MESSAGEBOX; } // Check for version string in Modlist file int modlistVersion = 0; using (StreamReader file = new StreamReader(currentDir + "\\" + ModDownloaderForm.MODLIST_FILE)) { string line; if ((line = file.ReadLine()) != null) { try { modlistVersion = Convert.ToInt32(line.Replace(".", "")); } catch (Exception ex) { showMessageBox = true; message = $"There is something wrong with version number in {ModDownloaderForm.MODLIST_FILE}\n" + ex.Message; title = "Warning!"; result = DialogResult.Abort; goto SHOW_MESSAGEBOX; } } } if (modlistVersion < latestModlistVersion) { return(ThemedDialogueBox.Show($"The new Modlist v{latestStringVersion} is available. Do you wish to update now?", "New update available", exeORmods: "mods")); } else { showMessageBox = true; message = "You have the latest version!"; title = "Good news!"; result = DialogResult.Cancel; } SHOW_MESSAGEBOX: if (!silently) { if (showMessageBox) { ThemedMessageBox.Show(message, title); } } return(result); }
/// <summary> /// This method saves changes to the *.module file /// </summary> private void ButtonSaveFile_Click(object sender, EventArgs e) { string filePath = modManager.ModuleFilePaths[loadedModBox.SelectedIndex]; List <string> listOfMods = new List <string>(); using (StreamReader sr = new StreamReader(filePath)) { string line; // Populate the Required Mods List with entries from the .module file while ((line = sr.ReadLine()) != null && !line.Contains("RequiredMod")) { listOfMods.Add(line); } } // Add base game modules since they can't be picked but need to be there. int startOffset = 0; if (usesW40kmodule) { listOfMods.Add("RequiredMod.1 = W40k"); startOffset++; } if (usesDXP2module) { listOfMods.Add("RequiredMod.2 = DXP2"); startOffset++; } // Add the disabled and activate mods now. string disablerString = string.Empty; string modString = string.Empty; for (int i = 0; i < modlist.Count; i++) { switch (modlist[i].State) { case ModState.Active: break; case ModState.Inactive: disablerString = "//"; break; case ModState.Missing: disablerString = "//"; break; } modString = disablerString + "RequiredMod." + (i + 1 + startOffset) + " = " + modlist[i].Name; listOfMods.Add(modString); } // Finally write the stuff if (!filePath.Contains(mergePostfix)) { filePath = filePath.Remove(filePath.Length - 7) + mergePostfix + ".module"; lastDropDownItemIndex = loadedModBox.Items.IndexOf(lastItem); } using (StreamWriter sw = new StreamWriter(filePath)) { for (int i = 0; i < listOfMods.Count; i++) { sw.WriteLine(listOfMods[i]); } } // Show a Succesprompt ThemedMessageBox.Show("New merged module file was created and the changes were successfully applied!\nYou can now select the new merged mod in the Mod Manager to play it.", "Saving successful!"); }
public static DialogResult CheckForUpdates(bool silently) { // That fixes problem in Windows 7 ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // Checking version mentioned in "version" file on GitHub latestStringVersion = DownloadString(EXE_VERSION_TEXT_URL); Version latestVersion; bool showMessageBox; string message; string title; DialogResult result; if (latestStringVersion.Length == 0) { showMessageBox = true; message = "There is no data in \"version\" file on GitHub!"; title = "Warning!"; result = DialogResult.Abort; goto SHOW_MESSAGEBOX; } try { latestVersion = new Version(latestStringVersion); } catch (Exception ex) { showMessageBox = true; message = "There is something wrong with version number in \"version\" file on GitHub!\n" + ex.Message; title = "Warning!"; result = DialogResult.Abort; goto SHOW_MESSAGEBOX; } if (currentVersion < latestVersion) { return(ThemedDialogueBox.Show($"The new DoW Mod Manager v{latestStringVersion} is available. Do you wish to update now?", "New update available", exeORmods: "exe")); } else { showMessageBox = true; message = "You have the latest version!"; title = "Good news!"; result = DialogResult.Cancel; } SHOW_MESSAGEBOX: if (!silently) { if (showMessageBox) { ThemedMessageBox.Show(message, title); } } return(result); }
private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { ThemedMessageBox.Show("1024x768 -> 1024\n1280x720 -> 800\n1366x768 -> 1024\n2560x1440 -> ?\n1920x1080 -> 1280\n4096x2160 -> ?", "Discovered screen withts"); }