public static ShowError ( |
||
e | ||
Résultat | void |
public void Save() { List <string> data = new List <string>(); try { FieldInfo[] fields = this.GetType().GetFields(); foreach (FieldInfo field in fields) { // Array Types if (field.GetValue(this).GetType() == typeof(bool[])) { bool[] bools = (bool[])field.GetValue(this); string boolString = field.Name + "="; for (int i = 0; i < bools.Length; i++) { boolString += bools[i] + ","; } data.Add(boolString.Substring(0, boolString.Length - 1)); } // List types else if (field.GetValue(this).GetType() == typeof(List <string>)) { List <string> strings = (List <String>)field.GetValue(this); string listString = field.Name + "="; foreach (string s in strings) { listString += "{" + s + "};"; } if (listString[listString.Length - 1] == ';') { listString = listString.Remove(listString.Length - 1); } data.Add(listString); } else // Basic Type { data.Add(field.Name + "=" + field.GetValue(this)); } } File.WriteAllLines(path, data); } catch (Exception e) { Utils.ShowError(e); } }
public static PatchInfo ReadPatch(string path) { PatchInfo info = new PatchInfo(); info.path = System.IO.Path.GetDirectoryName(path); if (File.Exists(path)) { string[] lines = File.ReadAllLines(path); foreach (string line in lines) { string[] s = line.Split('='); if (s.Length != 2) { continue; } // Name if (s[0].ToLower() == "name") { info.name = s[1]; } // Conflicts if (s[0].ToLower() == "conflicts") { info.conflicts.Add(s[1]); } // Requires if (s[0].ToLower() == "requires") { info.requires.Add(s[1]); } } } else { Utils.ShowError("Invalid Patch path\n\n" + path); return(null); } return(info); }
private void ExtractDRPG() { string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string zipPath = path + "\\DoomRPG.zip"; FastZip zip = new FastZip(); try { toolStripStatusLabel.Text = "Extracting DoomRPG.zip..."; toolStripProgressBar.Style = ProgressBarStyle.Marquee; Thread extractThread = new Thread(ExtractZip); extractThread.Start(); } catch (Exception e) { Utils.ShowError(e); } }
public static bool CheckForConflicts(List <PatchInfo> patches) { string error = string.Empty; bool hasError = false; for (int i = 0; i < patches.Count; i++) { if (!patches[i].Enabled) { continue; } for (int j = 0; j < patches.Count; j++) { if (!patches[j].Enabled) { continue; } for (int k = 0; k < patches[j].Conflicts.Count; k++) { if (patches[j].Conflicts[k].ToLower() == patches[i].Name.ToLower()) { error += "Patch " + patches[i].name + " conflicts with patch " + patches[j].name + "\n"; hasError = true; } } } } if (hasError) { Utils.ShowError(error.TrimEnd('\n'), "Patch Conflict"); return(false); } else { return(true); } }
private async void buttonCheckUpdates_Click(object sender, EventArgs e) { // Check the current branch if (currentBranch == string.Empty) { Utils.ShowError("No branch has been selected"); return; } // Save config SaveControls(); config.Save(); // Error Handling if (!CheckForErrors()) { return; } buttonCheckUpdates.Enabled = false; buttonLaunch.Enabled = false; await CheckForUpdates(); }
private async Task CheckForUpdates() { DialogResult result; // Save the config SaveControls(); config.Save(); // Wipe Warning if (!config.wipeWarning) { result = MessageBox.Show("This process will wipe whatever is in your selected Doom RPG folder. Are you sure you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); } else { result = DialogResult.Yes; } // Extra check to see if your selected Doom RPG path already has stuff in it if (CheckForMods()) { DialogResult createResult = MessageBox.Show("The Doom RPG folder contains other mod files. Would you like to create a subfolder for Doom RPG?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (createResult == DialogResult.Yes) { textBoxDRPGPath.Text += "\\DoomRPG"; config.DRPGPath += "\\DoomRPG"; } else { return; } } if (result == DialogResult.Yes) { config.wipeWarning = true; toolStripStatusLabel.ForeColor = Color.FromKnownColor(KnownColor.ControlText); toolStripStatusLabel.Text = "Checking for updates..."; toolStripProgressBar.Style = ProgressBarStyle.Marquee; try { string masterSHA = await GetMasterSHA(); string SHAPath = config.DRPGPath + "\\SHA-1"; // Does the SHA-1 of the current version match the remote branch? if (Directory.Exists(config.DRPGPath + "\\.git")) // Version is pulled from git, why bother updating with the launcher? { toolStripStatusLabel.Text = "This version of Doom RPG is managed by git"; toolStripProgressBar.Style = ProgressBarStyle.Continuous; buttonCheckUpdates.Enabled = true; buttonLaunch.Enabled = true; return; } else if (!Directory.Exists(config.DRPGPath)) // Directory wasn't found { toolStripStatusLabel.ForeColor = Color.Red; toolStripStatusLabel.Text = "Could not find Doom RPG directory, downloading latest version..."; } else if (File.Exists(SHAPath)) { string localSHA = File.ReadAllLines(SHAPath)[0]; // Not a match, need to grab the latest version if (masterSHA != localSHA || !File.Exists(SHAPath)) { toolStripStatusLabel.ForeColor = Color.Red; toolStripStatusLabel.Text = "Out-of-date, downloading latest version..."; } else // Up-to-date { toolStripStatusLabel.ForeColor = Color.Green; toolStripStatusLabel.Text = "Already up-to-date!"; toolStripProgressBar.Style = ProgressBarStyle.Continuous; buttonCheckUpdates.Enabled = true; buttonLaunch.Enabled = true; return; } } else // Could not find SHA-1, download a new copy { toolStripStatusLabel.ForeColor = Color.Red; toolStripStatusLabel.Text = "Could not find SHA-1, downloading latest version..."; } // Delete the old folder if (Directory.Exists(config.DRPGPath)) { Directory.Delete(config.DRPGPath, true); } await Task.Delay(1000 * 3); toolStripProgressBar.Style = ProgressBarStyle.Continuous; DownloadDRPG(); } catch (Exception e) { Utils.ShowError(e); } } else { buttonCheckUpdates.Enabled = true; buttonLaunch.Enabled = true; } }
public void Load() { try { if (File.Exists(path)) { FieldInfo[] fields = this.GetType().GetFields(); string[] lines = File.ReadAllLines(path); foreach (string option in lines) { string[] s = option.Split('='); if (s.Length != 2) { continue; } FieldInfo field = fields.FirstOrDefault(o => o.Name == s[0]); if (field != null) { // Basic Types if (field.GetValue(this).GetType() == typeof(bool)) { field.SetValue(this, bool.Parse(s[1])); } if (field.GetValue(this).GetType() == typeof(int)) { field.SetValue(this, int.Parse(s[1])); } if (field.GetValue(this).GetType() == typeof(float)) { field.SetValue(this, float.Parse(s[1])); } if (field.GetValue(this).GetType() == typeof(string)) { field.SetValue(this, s[1]); } // String List if (field.GetValue(this).GetType() == typeof(List <string>)) { List <string> listStrings = new List <string>(); string[] entries = s[1].Split(';'); if (entries.Length > 0 && entries[0] != string.Empty) { foreach (string entry in entries) { listStrings.Add(entry.Trim(new char[] { '{', '}' })); } } field.SetValue(this, listStrings); } // Enums if (field.GetValue(this).GetType() == typeof(IWAD)) { for (int i = 0; i < Enum.GetNames(typeof(IWAD)).Length; i++) { if (Enum.GetNames(typeof(IWAD))[i].Contains(s[1])) { field.SetValue(this, Enum.ToObject(typeof(IWAD), i)); } } } if (field.GetValue(this).GetType() == typeof(Difficulty)) { for (int i = 0; i < Enum.GetNames(typeof(Difficulty)).Length; i++) { if (Enum.GetNames(typeof(Difficulty))[i].Contains(s[1])) { field.SetValue(this, Enum.ToObject(typeof(Difficulty), i)); } } } if (field.GetValue(this).GetType() == typeof(DRLAClass)) { for (int i = 0; i < Enum.GetNames(typeof(DRLAClass)).Length; i++) { if (Enum.GetNames(typeof(DRLAClass))[i].Contains(s[1])) { field.SetValue(this, Enum.ToObject(typeof(DRLAClass), i)); } } } if (field.GetValue(this).GetType() == typeof(MultiplayerMode)) { for (int i = 0; i < Enum.GetNames(typeof(MultiplayerMode)).Length; i++) { if (Enum.GetNames(typeof(MultiplayerMode))[i].Contains(s[1])) { field.SetValue(this, Enum.ToObject(typeof(MultiplayerMode), i)); } } } if (field.GetValue(this).GetType() == typeof(ServerType)) { for (int i = 0; i < Enum.GetNames(typeof(ServerType)).Length; i++) { if (Enum.GetNames(typeof(ServerType))[i].Contains(s[1])) { field.SetValue(this, Enum.ToObject(typeof(ServerType), i)); } } } } } } else { Save(); } } catch (Exception e) { Utils.ShowError(e); } }