/// <summary> /// Common handler for handling descriptive exceptions. /// </summary> /// <param name="ex">The received descriptive exception.</param> public static void Handle(DescriptiveException ex) { MessageIcon icon; string title; switch (ex.Type) { case DescriptiveType.Information: icon = MessageIcon.Information; title = "Information"; break; case DescriptiveType.Warning: icon = MessageIcon.Warning; title = "Warning"; break; case DescriptiveType.Error: icon = MessageIcon.Error; title = "Error"; break; default: icon = MessageIcon.None; title = string.Empty; break; } SPiApp2.Controls.Console.WriteLine(ex.Message); AppDialogMessage.Show(ex.Message, title, MessageButtons.OK, icon); }
public virtual bool Save() { try { _Save(); return(true); } catch (Exception ex) { Debug.WriteLine(ex.Message); AppDialogMessage.Show("An error occured while saving the asset.", "Asset save error", MessageButtons.OK, MessageIcon.Error); } return(false); }
public bool Load() { try { Debug.Assert(stream == null); _Load(); return(true); } catch (Exception ex) { Debug.WriteLine(ex.Message); SPiApp2.Controls.Console.WriteLine(ex.Message); AppDialogMessage.Show("An error occured while loading the asset.", "Asset load error", MessageButtons.OK, MessageIcon.Error); } return(false); }
/// <summary> /// Opens explorer to the specified path; if the file has been specified it will also select the file. /// </summary> /// <param name="directory">The path to directory in which the file resides.</param> /// <param name="filename">The name of the file to browse for.</param> public static void Browse(string directory, string filename = null) { char sep = Path.DirectorySeparatorChar; string path = string.Format("{0}{1}{2}", directory, sep, filename); if (!Directory.Exists(directory)) { AppDialogMessage.Show(string.Format("Directory at '{0}' could not be located.", directory), "Missing directory", MessageButtons.OK, MessageIcon.Warning); } else if (!string.IsNullOrEmpty(filename) && !File.Exists(path)) { AppDialogMessage.Show(string.Format("File at '{0}' could not be located.", path), "Missing file", MessageButtons.OK, MessageIcon.Warning); } else { Explorer(path); } }
/// <summary> /// Opens the text file if an editor is set. Otherwise it is displayed in explorer. /// </summary> /// <param name="directory">The path to the directory in which the file resides.</param> /// <param name="filename">The name of the file to open.</param> public static void OpenTextFile(string directory, string filename) { string path = string.Format("{0}{1}{2}", directory, Path.DirectorySeparatorChar, filename); if (!Directory.Exists(directory)) { AppDialogMessage.Show(string.Format("Directory at '{0}' could not be located.", directory), "Missing directory", MessageButtons.OK, MessageIcon.Warning); } else if (string.IsNullOrEmpty(filename) || !File.Exists(path)) { AppDialogMessage.Show(string.Format("File at '{0}' could not be located.", path), "Missing file", MessageButtons.OK, MessageIcon.Warning); } else { if (GetTextEditor(out string editor, out string arguments)) { ProcessStartInfo info = new ProcessStartInfo(); info.FileName = editor; info.WorkingDirectory = directory; info.UseShellExecute = true; if (!string.IsNullOrEmpty(arguments)) { info.Arguments = string.Format("{0} {1}", arguments, Utility.EscapeSmart(filename)); } else { info.Arguments = filename; } Process.Start(info); } else { Explorer(directory, filename); } } }
/// <summary> /// Checks if the code is allowed to write the template files to their destination. /// </summary> /// <remarks> /// Writing is allowed when: /// - The destination files do not exist; /// - The destination files do exist but the user allows overwriting. /// </remarks> /// <param name="info">The source/destination path of files to copy.</param> /// <returns>true if copying of the template files is allowed; otherwise, false.</returns> private bool AllowFileWriting(Dictionary <string, string> info) { bool filesExist = false; bool overwrite = false; // Check if one or more template files already exist foreach (KeyValuePair <string, string> pair in info) { if (File.Exists(pair.Value)) { Debug.WriteLine(string.Format("File '{0}' already exists.", pair.Value)); MessageResult result = AppDialogMessage.Show("One or more files of the template already exist. Do you want to overwrite them?", "Overwrite?", MessageButtons.YesNo, MessageIcon.Question); filesExist = true; overwrite = (result == MessageResult.Yes); break; } } return(!filesExist || (filesExist && overwrite)); }
/// <summary> /// Launches an executable file. /// </summary> /// <param name="exePath">The absolute or relative path to the executable.</param> /// <param name="workingDirectory">The working directory to used by the executable.</param> /// <param name="arguments">The arguments to pass to the application.</param> public static void Launch(string exePath, string workingDirectory, string arguments = null) { if (!Directory.Exists(workingDirectory)) { AppDialogMessage.Show(string.Format("Could not locate directory at path '{0}'.", workingDirectory), "Missing directory", MessageButtons.OK, MessageIcon.Error); } else { if (!File.Exists(exePath)) { string altPath = string.Format("{0}{1}{2}", workingDirectory, Path.DirectorySeparatorChar, exePath); if (!File.Exists(altPath)) { AppDialogMessage.Show(string.Format("Could not locate executable file at '{0}' or '{1}'.", exePath, altPath), "Missing executable", MessageButtons.OK, MessageIcon.Error); } else { exePath = altPath; } } ProcessStartInfo info = new ProcessStartInfo(); info.UseShellExecute = true; info.FileName = exePath; info.WorkingDirectory = workingDirectory; if (!string.IsNullOrEmpty(arguments)) { info.Arguments = arguments; } Process.Start(info); } }
public static void RunSelectedMod() { // First save the settings UserData.Instance.Save(); ModSettings settings = ModSettings.Instance; // Check to see if the settings file exists if (!settings.Exists()) { AppDialogMessage dialog = new AppDialogMessage("No settings file has been found. Is this a SINGLEPLAYER mod?", "Singleplayer mod?", MessageButtons.YesNo, MessageIcon.Question); bool?result = dialog.ShowDialog(); if (result == null || result.HasValue == false || result.Value != true) { // ABORT! return; } if (dialog.Result == MessageResult.Yes) { settings.ModType = "Singleplayer"; } else { settings.ModType = "Multiplayer"; } settings.Save(); } string installPath = Preferences.InstallPath; string optional = string.Empty; // Enable developer if (UserData.ModDeveloper) { optional = string.Format("{0} +set developer 1", optional); } // Enable developer_scipt if (UserData.ModDeveloperScript) { optional = string.Format("{0} +set developer_script 1", optional); } // Enable cheats if (UserData.ModCheats) { optional = string.Format("{0} +set thereisacow 1337", optional); } // Enable custom command line options if (UserData.ModCustom) { optional = string.Format("{0} {1}", optional, UserData.ModOptions); } SPiApp2.Components.Application.Launch( string.Format("{0}{1}bin{1}mod_run.bat", Environment.CurrentDirectory, System.IO.Path.DirectorySeparatorChar), installPath, string.Format("\"{0}\" {1} \"{2}\" {3} \"{4}\"", installPath, UserData.SelectedMod, Preferences.Executable, GetMultiplayerSign(), optional) ); }
/// <summary> /// Validate the text lines of a zone file. /// </summary> /// <param name="data">The zone file's lines of text.</param> /// <returns>true if valid; otherwise, false.</returns> public static bool Validate(string[] lines) { int numLine = 0; foreach (string line in lines) { numLine++; // Empty lines and comments are allowed, therefor check these first if (string.IsNullOrWhiteSpace(line) || line.StartsWith("//")) { continue; } string[] tokens = line.Split(','); if (tokens.Length < 2) { AppDialogMessage.Show(string.Format("Invalid number of tokens on line {0} of the zone file.", numLine), "Invalid zone file", MessageButtons.OK, MessageIcon.Error); return(false); } for (int i = 0; i < tokens.Length; i++) { tokens[i] = tokens[i].Trim(); if (string.IsNullOrWhiteSpace(tokens[i])) { AppDialogMessage.Show(string.Format("One of more fields at line {0} are empty.", numLine), "Invalid field", MessageButtons.OK, MessageIcon.Warning); } } string keyword = tokens[0]; bool resolved = false; switch (keyword) { // ignore,<zone_file> // include,<zone_file> // [cod4]\zone_source\<zone_file>.csv case "ignore": case "include": resolved = Validate_ExternalZone(ref tokens); break; // rawfile,<rawfile_name> // [cod4]\raw\<rawfile_name> case "rawfile": resolved = Validate_RawFile(ref tokens); break; // menufile,<menufile_name> // [cod4]\raw\<menufile_name> case "menufile": resolved = Validate_MenuFile(ref tokens); break; // localize,<localized_file> // [cod4]\raw\<language>\localizedstrings\<localized_file>.str case "localize": resolved = Validate_Localize(ref tokens); break; // xanim,<xanim_name> // [cod4]\raw\xanims\<xanim_name> case "xanim": resolved = Validate_Animation(ref tokens); break; // xmodel,<xmodel_name> // [cod4]\raw\xmodels\<xmodel_name> case "xmodel": resolved = Validate_Model(ref tokens); break; // weapon,<weapon_file> // [cod4]\raw\weapons\<weapon_file> case "weapon": resolved = Validate_Weapon(ref tokens); break; // col_map_**,<bsp_file> // [cod4]\raw\<bsp_file> case "col_map_sp": case "col_map_mp": resolved = Validate_CollisionMap(ref tokens); break; // fx,<filename> // [cod4]\raw\fx\<filename>.efx case "fx": resolved = Validate_Effect(ref tokens); break; // sound,<soundalias_name>,<map_name>,<modifier> // [cod4]\raw\soundaliases\<soundalias_name>.csv case "sound": resolved = Validate_Sound(ref tokens); break; // material,<material_name> // [cod4]\raw\materials\<material_name> case "material": resolved = Validate_Material(ref tokens); break; // ui_map,<filename> // [cod4]\raw\<filename> case "ui_map": resolved = Validate_InterfaceMap(ref tokens); break; // impactfx,<map_name> // [cod4]\raw\fx\maps\<map_name>\iw_impacts.csv case "impactfx": resolved = Validate_ImpactEffects(ref tokens); break; default: AppDialogMessage.Show(string.Format("Unknown keyword '{0}' found. Skipping validation of line {1}.", tokens[0], numLine), "Unknown keyword", MessageButtons.OK, MessageIcon.Warning); continue; } if (!resolved) { AppDialogMessage.Show(string.Format("Could not resolve {0} at line {1}.", keyword, numLine), "Unresolved zone file", MessageButtons.OK, MessageIcon.Warning); } } return(true); }