private void CreateNewMod() { newModDialog = new SaveFileDialog(); if (String.IsNullOrWhiteSpace(UserPreferences.Default.WorkingLocation)) { newModDialog.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); } else { newModDialog.InitialDirectory = UserPreferences.Default.WorkingLocation; } newModDialog.AddExtension = true; newModDialog.DefaultExt = ".mod"; newModDialog.FileName = "Mod Name"; newModDialog.Filter = "Mod File (*.mod)|*.mod"; newModDialog.Title = "Select a save location and name for the mod"; if (newModDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { if (CurrentMod != null) CloseMod(); // TODO: delete and remake the mod directory if it already exits to give the new mod a fresh start? Mod mod = new Mod(Path.GetFileNameWithoutExtension(newModDialog.FileName)); // setup the initial mod data mod.StorageLocation = Path.GetDirectoryName(newModDialog.FileName); mod.ModRootDirectory = mod.StorageLocation + "/" + mod.Name; mod.Raw = "name = \"" + mod.Name + "\"" + System.Environment.NewLine; mod.Raw += "path = \"mod/" + mod.Name + "\"" + System.Environment.NewLine; // Set the new mod as current SetCurrentMod(mod); } }
public static Mod LoadFromFile(String file) { if (!File.Exists(file)) return null; StreamReader stream = File.OpenText(file); String line; Mod mod = new Mod("Loaded Mod"); while ((line = stream.ReadLine()) != null) { mod.Raw += line + System.Environment.NewLine; if (line.Contains("=") && !line.StartsWith("#")) { KeyValuePair<String, String> data = Helpers.ReadStringData(line); switch (data.Key) { case "name": mod.Name = data.Value; mod.StorageLocation = System.IO.Path.GetDirectoryName(file); mod.ModRootDirectory = mod.StorageLocation + "/" + mod.Name; break; case "user_dir": mod.UserDirectory = data.Value; break; case "replace_path": mod.ReplacePaths.Add(data.Value); break; } } } // close the file stream stream.Close(); return mod; }
public void SetCurrentMod(Mod m) { if (m == null) { MessageBox.Show("Unable to load the specified mod.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); modClosedPanel.Visible = true; return; } // Set the mod CurrentMod = m; // Load the dynasties String dynastiesFolder = CurrentMod.ModRootDirectory + VanillaDynastiesPath; if(Directory.Exists(dynastiesFolder)) { // Go through each file and add it to the queue String[] files = Directory.GetFiles(dynastiesFolder); foreach (String filePath in files) { String file = Path.GetFileName(filePath); if (!CurrentMod.DynastyFiles.Contains(file)) { CurrentMod.DynastyFiles.Add(file); CurrentMod.DynastyFilesToLoad.Enqueue(filePath); } } // start loading the files if (CurrentMod.DynastyFilesToLoad.Count > 0) { StreamReader reader = new StreamReader(CurrentMod.DynastyFilesToLoad.Peek(), Encoding.Default, true); dynastyBackgroundWorker.RunWorkerAsync(reader); } } // Load the cultures String culturesFolder = CurrentMod.ModRootDirectory + VanillaCulturesPath; if (Directory.Exists(culturesFolder)) { // Go through each file and add it to the queue String[] files = Directory.GetFiles(culturesFolder); foreach (String filePath in files) { String file = Path.GetFileName(filePath); if (!CurrentMod.CultureFiles.Contains(file)) { CurrentMod.CultureFiles.Add(file); CurrentMod.CultureFilesToLoad.Enqueue(filePath); } } // start loading the files if (CurrentMod.CultureFilesToLoad.Count > 0) { StreamReader reader = new StreamReader(CurrentMod.CultureFilesToLoad.Peek(), Encoding.Default, true); cultureBackgroundWorker.RunWorkerAsync(reader); } } // Load characters String charactersFolder = CurrentMod.ModRootDirectory + VanillaCharactersPath; if (Directory.Exists(charactersFolder)) { // Go through each file and add it to the listview String[] files = Directory.GetFiles(charactersFolder); foreach (String filePath in files) { String file = Path.GetFileName(filePath); if (!CurrentMod.CharacterFiles.Contains(file)) { CurrentMod.CharacterFiles.Add(file); CurrentMod.CharacterFilesToLoad.Enqueue(filePath); } } // Start loading character files if (CurrentMod.CharacterFilesToLoad.Count > 0) { StreamReader reader = new StreamReader(CurrentMod.CharacterFilesToLoad.Peek(), Encoding.Default, true); characterBackgroundWorker.RunWorkerAsync(reader); } } UserPreferences.Default.LastMod = CurrentMod.StorageLocation + "/" + CurrentMod.Name + ".mod"; UserPreferences.Default.WorkingLocation = CurrentMod.StorageLocation; UserPreferences.Default.Save(); saveToolStripMenuItem.Enabled = true; closeModToolStripMenuItem.Enabled = true; closeWithoutSavingToolStripMenuItem.Enabled = true; // populate file tree PopulateTreeView(); // Hide the panel modClosedPanel.Visible = false; // Update title this.Text = DefaultWindowTitle + " - " + CurrentMod.Name; }