public void Load() { // Parse Manifests string[] modFolders = Directory.GetDirectories(mModsDirectoryPath); if (modFolders == null) { return; } foreach (string modPath in modFolders) { string formatted = JsonHelper.NormalizeSystemPath(modPath); Module module = new Module(formatted); module.InitializeFromManifest(); mModules.Add(module.Name, module); } foreach (Module module in mModules.Values) { module.LoadFiles(); } foreach (Module module in mModules.Values) { module.PostLoadFixup(); } }
private void SearchForFileType(string directory, string fileType, List <string> luaFilesFound) { if (!Directory.Exists(directory)) { return; } string[] directories = Directory.GetDirectories(directory); if (directories == null) { return; } foreach (string d in directories) { string[] files = Directory.GetFiles(d, fileType); if (files != null) { foreach (string f in files) { string formatted = JsonHelper.NormalizeSystemPath(f); luaFilesFound.Add(formatted); } SearchForFileType(d, fileType, luaFilesFound); } } }
private void ParseLinkedFiles(string jsonString) { string directory = Directory; Regex matcher = new Regex("file\\([\\S]+\\)"); foreach (Match match in matcher.Matches(jsonString)) { string matchValue = match.Value; // Sigh, special case these because they're more like folders instead of files if (matchValue != "file(animations)" && matchValue != "file(effects)") { string linkedFile = JsonHelper.GetFileFromFileJson(match.Value, directory); linkedFile = JsonHelper.NormalizeSystemPath(linkedFile); if (!System.IO.File.Exists(linkedFile) && !System.IO.Directory.Exists(linkedFile)) { AddError("Links to non-existent file " + linkedFile); continue; } if (LinkedFileData.ContainsKey(linkedFile)) { continue; } FileData linkedFileData = GetFileDataFactory(linkedFile); if (linkedFileData != null) { LinkedFileData.Add(linkedFile, linkedFileData); linkedFileData.ReferencedByFileData[GetAliasOrFlatName()] = this; } } } }
public GameMasterNode(string module, string filePath) { mModule = module; mPath = filePath; mDirectory = JsonHelper.NormalizeSystemPath(System.IO.Path.GetDirectoryName(mPath)); mFileName = System.IO.Path.GetFileNameWithoutExtension(mPath); kNodeIndex++; }
public QubicleFileData(string path) : base(path) { mDirectory = JsonHelper.NormalizeSystemPath(System.IO.Path.GetDirectoryName(Path)); if (System.IO.Path.GetExtension(path).Equals(".qmo")) { mIsQb = false; } }
public MainForm(string path) { if (path != null) { path = path.Trim(); kModsDirectoryPath = JsonHelper.NormalizeSystemPath(path); } InitializeComponent(); }
public ModuleDataManager(string modsDirectoryPath) { if (sInstance != null) { sInstance.Dispose(); sInstance = null; } mModsDirectoryPath = JsonHelper.NormalizeSystemPath(modsDirectoryPath); sInstance = this; }
private void saveEffectsFileDialog_FileOk(object sender, CancelEventArgs e) { string directory = System.IO.Path.GetFullPath(saveEffectsFileDialog.FileName); using (StreamWriter wr = new StreamWriter(directory, false, new UTF8Encoding(false))) { wr.Write("{\n\n}"); } mNewFilePath = JsonHelper.NormalizeSystemPath(directory); Reload(); }
// Get last directory/file name in a path string public static string GetLastStringInPath(string path) { if (path != null && path.Contains(Path.DirectorySeparatorChar) || path.Contains(Path.AltDirectorySeparatorChar)) { string formatted = JsonHelper.NormalizeSystemPath(path); string[] dirs = formatted.Split(Path.AltDirectorySeparatorChar); path = dirs.Last <string>(); } return(path); }
private void chooseModDirectory() { var dialog = new FolderSelectDialog() { DirectoryPath = kModsDirectoryPath ?? Environment.CurrentDirectory, Title = "Stonehearth Mods Root Directory" }; DialogResult result = DialogResult.Abort; do { result = dialog.ShowDialog(); if (result == DialogResult.OK) { string newPath = dialog.DirectoryPath; if (this.checkModsFolder(ref newPath)) { kModsDirectoryPath = JsonHelper.NormalizeSystemPath(newPath); Properties.Settings.Default["ModsDirectory"] = kModsDirectoryPath; Properties.Settings.Default.Save(); return; } else if (Directory.Exists(newPath)) { // If the directory does exist, but doesn't seem to be valid, make it a user chocie if (MessageBox.Show("The chosen directory does not appear to be a valid mods directory. Choose it anyway?", "Possibly invalid mods directory", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { return; } } else { if (MessageBox.Show("Invalid mods directory chosen. Try again?", "Invalid directory", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No) { return; } } } else { if (MessageBox.Show("No mods directory selected. Try again?", "No directory selected.", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } } }while (true); // repeat until we've got a proper directory or the user aborts }
public MainForm(string path, string steamUploadsPath) { InitializeComponent(); if (path != null) { path = path.Trim(); kModsDirectoryPath = JsonHelper.NormalizeSystemPath(path); } if (steamUploadsPath != null) { steamUploadsPath = steamUploadsPath.Trim(); kSteamUploadsDirectoryPath = JsonHelper.NormalizeSystemPath(steamUploadsPath); } }
public void Load() { ParseGenericEncounterScripts(MainForm.kModsDirectoryPath + "/stonehearth/services/server/game_master/controllers"); // get the game master index location foreach (Module module in ModuleDataManager.GetInstance().GetAllModules()) { ModuleFile gmIndex = module.GetAliasFile("data:gm_index"); if (gmIndex != null) { string folder = JsonHelper.NormalizeSystemPath(System.IO.Path.GetDirectoryName(gmIndex.ResolvedPath)); ParseEncounterScripts(module.Name, folder); ParseNodeGraph(module.Name, folder); } } }
public ModuleDataManager(string modsDirectoryPath, string extraModsDirectoryPath) { if (sInstance != null) { sInstance.Dispose(); sInstance = null; } mModsDirectoryPath = JsonHelper.NormalizeSystemPath(modsDirectoryPath); sInstance = this; // The additional mods directory path can be empty if modder develops inside the mods folder if (extraModsDirectoryPath != string.Empty) { mSteamUploadsDirectoryPath = JsonHelper.NormalizeSystemPath(extraModsDirectoryPath); } }
public void Load() { // Parse Manifests string[] modFolders = Directory.GetDirectories(mModsDirectoryPath); if (modFolders == null) { return; } foreach (string modPath in modFolders) { string formatted = JsonHelper.NormalizeSystemPath(modPath); if (!mModules.Keys.Contains(formatted)) { Module module = new Module(formatted); module.InitializeFromManifest(); mModules.Add(module.Name, module); } } // Append modules from the additional folder (e.g. steam_uploads) at the end of the list if (SteamUploadsDirectoryPathExists()) { string[] customModsFolders = Directory.GetDirectories(mSteamUploadsDirectoryPath); foreach (string customModPath in customModsFolders) { string formatted = JsonHelper.NormalizeSystemPath(customModPath); if (!mModules.Keys.Contains(formatted)) { Module module = new Module(formatted); module.InitializeFromManifest(); mModules.Add(module.Name, module); } } } foreach (Module module in mModules.Values) { module.LoadFiles(); } foreach (Module module in mModules.Values) { module.PostLoadFixup(); } }
public void newFileButton_Click(object sender, EventArgs e) { if (mSelectedNode != null) { string path = mSelectedNode.Tag != null?JsonHelper.NormalizeSystemPath(mSelectedNode.Tag.ToString()) : null; if (path != null) { saveEffectsFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(path); } } else { saveEffectsFileDialog.InitialDirectory = System.IO.Path.GetFullPath(ModuleDataManager.GetInstance().ModsDirectoryPath); } saveEffectsFileDialog.ShowDialog(); saveEffectsFileDialog.RestoreDirectory = true; }
private void saveNewEncounterNodeDialog_FileOk(object sender, CancelEventArgs e) { string filePath = saveNewEncounterNodeDialog.FileName; if (filePath == null) { return; } filePath = JsonHelper.NormalizeSystemPath(filePath); GameMasterNode existingNode = GameMasterDataManager.GetInstance().GetGameMasterNode(filePath); if (existingNode != null) { MessageBox.Show("Cannot override an existing node. Either edit that node or create a new name."); return; } GameMasterDataManager.GetInstance().AddNewGenericScriptNode(this, mSelectedNewScriptNode, filePath); }
public void Load() { ParseGenericEncounterScripts(MainForm.kModsDirectoryPath + "/stonehearth/services/server/game_master/controllers"); var defaultSchemaPath = Application.StartupPath + "/schemas/encounters/encounter.json"; using (StreamReader sr = new StreamReader(defaultSchemaPath, System.Text.Encoding.UTF8)) { mDefaultSchema = JsonSchemaTools.ParseSchema(sr.ReadToEnd(), defaultSchemaPath); } // get the game master index location foreach (Module module in ModuleDataManager.GetInstance().GetAllModules()) { ModuleFile gmIndex = module.GetAliasFile("data:gm_index"); if (gmIndex != null) { string folder = JsonHelper.NormalizeSystemPath(System.IO.Path.GetDirectoryName(gmIndex.ResolvedPath)); ParseEncounterScripts(module.Name, folder); ParseNodeGraph(module.Name, folder); } } }
// Adds all files and directories in path to tree node root private void AppendTreeNodes(TreeNode root, string rootPath) { string[] filePaths = Directory.GetFiles(rootPath); string[] folderPaths = Directory.GetDirectories(rootPath); foreach (string filePath in filePaths) { if (root.Tag == null) { root.Tag = JsonHelper.NormalizeSystemPath(filePath); } TreeNode node = new TreeNode(System.IO.Path.GetFileName(filePath)); node.Tag = JsonHelper.NormalizeSystemPath(filePath); root.Nodes.Add(node); } foreach (string folderPath in folderPaths) { TreeNode subRoot = new TreeNode(System.IO.Path.GetFileName(folderPath)); subRoot.Tag = JsonHelper.NormalizeSystemPath(folderPath); AppendTreeNodes(subRoot, folderPath); root.Nodes.Add(subRoot); } }
public Dictionary <string, JsonFileData> GetIconicJsons(bool baseModsOnly = false) { Dictionary <string, JsonFileData> entityJsonFiles = GetJsonsOfType(JSONTYPE.ENTITY, baseModsOnly); Dictionary <string, JsonFileData> iconicJsonFiles = new Dictionary <string, JsonFileData>(); foreach (KeyValuePair <string, JsonFileData> entry in entityJsonFiles) { JsonFileData jsonFileData = entry.Value; JToken iconicForm = jsonFileData.Json.SelectToken("components.stonehearth:entity_forms.iconic_form"); if (iconicForm != null) { string iconicFilePath = JsonHelper.GetFileFromFileJson(iconicForm.ToString(), jsonFileData.Directory); iconicFilePath = JsonHelper.NormalizeSystemPath(iconicFilePath); JsonFileData iconicFileData = (JsonFileData)jsonFileData.OpenedFiles.Find(e => e is JsonFileData && e.Path == iconicFilePath); if (iconicFileData != null) { iconicJsonFiles.Add(iconicFilePath, iconicFileData); } } } return(iconicJsonFiles); }
public static string GetFileFromFileJson(string fileJson, string parentPath) { parentPath = JsonHelper.NormalizeSystemPath(parentPath); string fullPath = string.Empty; bool startedWithFile = false; if (fileJson.StartsWith("file(")) { string temp = fileJson.Substring(5); fullPath = temp.Substring(0, temp.Length - 1); startedWithFile = true; } else { fullPath = fileJson; } if (fullPath.IndexOf("../") >= 0) { // If there's a relative directory int index = fullPath.IndexOf("../"); char[] delimeter = "/".ToCharArray(); string[] splitParentPath = parentPath.Split(delimeter); int parentPathCount = splitParentPath.Length + 1; while (index >= 0) { parentPathCount--; fullPath = fullPath.Substring(index + 3); index = fullPath.IndexOf("../"); } splitParentPath = parentPath.Split(delimeter, parentPathCount); splitParentPath[splitParentPath.Length - 1] = ""; parentPath = string.Join("/", splitParentPath); parentPath = parentPath.Substring(0, parentPath.Length - 1); } else if (fileJson.IndexOf('.') < 0) { string folderName = fullPath.Substring(fullPath.LastIndexOf('/') + 1); fullPath = fullPath + "/" + folderName + ".json"; } if (fullPath.StartsWith("/")) { if (startedWithFile) { string mod = parentPath.Replace(MainForm.kModsDirectoryPath + '/', ""); int firstSlash = mod.IndexOf('/'); if (firstSlash >= 0) { mod = mod.Substring(0, firstSlash); } fullPath = ModuleDataManager.GetInstance().ModsDirectoryPath + '/' + mod + fullPath; } else { fullPath = ModuleDataManager.GetInstance().ModsDirectoryPath + fullPath; } } else { fullPath = parentPath + "/" + fullPath; } return(fullPath); }
public JsonFileData(string path) : base(path) { mDirectory = JsonHelper.NormalizeSystemPath(System.IO.Path.GetDirectoryName(Path)); }
private void ParseJsonSpecificData() { string directory = Directory; switch (mJsonType) { case JSONTYPE.ENTITY: JToken entityFormsComponent = mJson.SelectToken("components.stonehearth:entity_forms"); if (entityFormsComponent != null) { // Look for stonehearth:entity_forms JToken ghostForm = entityFormsComponent["ghost_form"]; if (ghostForm != null) { string ghostFilePath = JsonHelper.GetFileFromFileJson(ghostForm.ToString(), directory); ghostFilePath = JsonHelper.NormalizeSystemPath(ghostFilePath); JsonFileData ghost = new JsonFileData(ghostFilePath); ghost.Load(); ghost.AddMixin("stonehearth:mixins:placed_object"); OpenedFiles.Add(ghost); ghost.PostLoad(); } JToken iconicForm = entityFormsComponent["iconic_form"]; if (iconicForm != null) { string iconicFilePath = JsonHelper.GetFileFromFileJson(iconicForm.ToString(), directory); iconicFilePath = JsonHelper.NormalizeSystemPath(iconicFilePath); JsonFileData iconic = new JsonFileData(iconicFilePath); iconic.Load(); OpenedFiles.Add(iconic); } CheckForNoNetWorth(); } else { if (GetModuleFile() != null && mJson.SelectToken("components.item") != null) { CheckForNoNetWorth(); } } break; case JSONTYPE.JOB: // Parse crafter stuff JToken crafter = mJson["crafter"]; if (crafter != null) { // This is a crafter, load its recipes string recipeListLocation = crafter["recipe_list"].ToString(); recipeListLocation = JsonHelper.GetFileFromFileJson(recipeListLocation, directory); JsonFileData recipes = new JsonFileData(recipeListLocation); recipes.Load(); foreach (FileData recipe in recipes.LinkedFileData.Values) { recipes.RelatedFiles.Add(recipe); } OpenedFiles.Add(recipes); recipes.ReferencedByFileData[GetAliasOrFlatName()] = this; } JObject jobEquipment = mJson["equipment"] as JObject; if (jobEquipment != null) { foreach (JToken equippedItem in jobEquipment.Children()) { string equipmentJson = equippedItem.Last.ToString(); FileData fileData = null; if (equipmentJson.IndexOf(':') >= 0) { foreach (ModuleFile alias in LinkedAliases) { if (alias.FullAlias.Equals(equipmentJson)) { fileData = alias.FileData; } } } else { equipmentJson = JsonHelper.GetFileFromFileJson(equipmentJson, directory); LinkedFileData.TryGetValue(equipmentJson, out fileData); } JsonFileData jsonFileData = fileData as JsonFileData; if (jsonFileData != null) { JToken equipment_piece = jsonFileData.mJson.SelectToken("components.stonehearth:equipment_piece"); if (equipment_piece != null) { JToken ilevel = equipment_piece["ilevel"]; if (ilevel != null && ilevel.Value <int>() > 0) { JToken noDrop = equipment_piece["no_drop"]; if (noDrop == null || !noDrop.Value <bool>()) { AddError("Equipment piece " + equipmentJson + " is not set to no_drop=true even through it is a job equipment!"); } } } } } } ////AlterJobExperience(); break; case JSONTYPE.RECIPE: JToken portrait = mJson["portrait"]; if (portrait != null) { string portraitImageLocation = portrait.ToString(); portraitImageLocation = JsonHelper.GetFileFromFileJson(portraitImageLocation, directory); ImageFileData image = new ImageFileData(portraitImageLocation); LinkedFileData.Add(portraitImageLocation, image); } break; case JSONTYPE.AI_PACK: JArray actions = mJson["actions"] as JArray; if (actions != null) { foreach (JToken action in actions) { string fullAlias = action.ToString(); ModuleFile linkedAlias = ModuleDataManager.GetInstance().GetModuleFile(fullAlias); if (linkedAlias == null) { AddError("links to alias " + fullAlias + " which does not exist!"); } } } break; case JSONTYPE.MONSTER_TUNING: JToken experience = mJson.SelectToken("attributes.exp_reward"); if (experience != null) { //Console.WriteLine(GetAliasOrFlatName() + "\t" + experience.ToString()); } break; } CheckDisplayName(); if (Json != null && Json.SelectToken("components.effect_list.effects") != null) { AddError("effect_list component is using 'effects' to specify a list of effects. This is bad because these effects will not restart after save load. You should put all the effects into a single file and reference that file as 'default'"); } FixUpAllCombatData(); }
private void selectJsonFileDialog_FileOk(object sender, CancelEventArgs e) { string filePath = selectJsonFileDialog.FileName; if (filePath == null) { return; } filePath = JsonHelper.NormalizeSystemPath(filePath); NewAliasParameters parameters = selectJsonFileDialog.Tag as NewAliasParameters; Module selectedMod = parameters.SelectedMod; string manifestEntryType = parameters.ManifestEntryType; if (!filePath.Contains(selectedMod.Path)) { MessageBox.Show("The file must be under the directory " + selectedMod.Path); return; } mLastModuleLocations[selectedMod.Name] = filePath; string shortPath = filePath.Replace(selectedMod.Path + "/", ""); string[] pathSplit = shortPath.Split('/'); string samplePath = string.Empty; for (int i = 1; i < (pathSplit.Length - 1); ++i) { if (string.IsNullOrEmpty(samplePath)) { samplePath = pathSplit[i]; } else { samplePath = samplePath + ':' + pathSplit[i]; } } if (pathSplit.Length > 2) { // Make the file path not contain the .json part if it doesn't have to string fileName = pathSplit[pathSplit.Length - 1]; string extension = System.IO.Path.GetExtension(fileName); if (extension == ".json") { string folder = pathSplit[pathSplit.Length - 2]; if (folder.Equals(System.IO.Path.GetFileNameWithoutExtension(fileName))) { shortPath = shortPath.Replace("/" + fileName, ""); } } else if (extension == ".lua") { string nameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileName); if (nameWithoutExtension.EndsWith("_action")) { nameWithoutExtension = nameWithoutExtension.Substring(0, nameWithoutExtension.Length - 7); samplePath = samplePath + ':' + nameWithoutExtension; } } } NewAliasCallback callback = new NewAliasCallback(this, selectedMod, shortPath, manifestEntryType); InputDialog dialog = new InputDialog("Add New Alias", "Type the name of the alias for " + filePath, samplePath, "Add!"); dialog.SetCallback(callback); dialog.ShowDialog(); }
public bool OnAccept(string newBaseModsPath, string newSteamUploadsPath) { bool modsPathAccepted = false; // First check that the mods directory is valid (we require it) var check = form.checkModsFolder(ref newBaseModsPath); if (check == ModFolderCheckResult.ZIPPED) { if (UnzipMods(newBaseModsPath)) { check = ModFolderCheckResult.VALID; } } if (check == ModFolderCheckResult.VALID) { kModsDirectoryPath = JsonHelper.NormalizeSystemPath(newBaseModsPath); Properties.Settings.Default["ModsDirectory"] = kModsDirectoryPath; Properties.Settings.Default.Save(); modsPathAccepted = true; } else if (Directory.Exists(newBaseModsPath)) { // If the directory does exist, but doesn't seem to be valid, make it a user choice if (MessageBox.Show("The chosen directory does not appear to be a valid mods directory. It should contain the uncompressed stonehearth mod. Choose it anyway?", "Possibly invalid mods directory", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { kModsDirectoryPath = JsonHelper.NormalizeSystemPath(newBaseModsPath); Properties.Settings.Default["ModsDirectory"] = kModsDirectoryPath; modsPathAccepted = true; } } else { if (MessageBox.Show("Invalid mods directory chosen. Try again?", "Invalid directory", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No) { modsPathAccepted = false; } } // Check the steam_uploads directory (can be empty if the user is developing in the mods folder) var check2 = form.checkModsFolder(ref newSteamUploadsPath); if (check2 == ModFolderCheckResult.ZIPPED) { if (UnzipMods(newSteamUploadsPath)) { check2 = ModFolderCheckResult.VALID; } } if (check2 == ModFolderCheckResult.VALID) { kSteamUploadsDirectoryPath = JsonHelper.NormalizeSystemPath(newSteamUploadsPath); Properties.Settings.Default["SteamUploadsDirectory"] = kSteamUploadsDirectoryPath; Properties.Settings.Default.Save(); } else if (Directory.Exists(newSteamUploadsPath)) { // If the directory does exist, but doesn't seem to be valid, make it a user choice if (MessageBox.Show("The chosen directory does not appear to be a valid mods directory. Choose it anyway?", "Possibly invalid additional mods directory", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { kSteamUploadsDirectoryPath = JsonHelper.NormalizeSystemPath(newSteamUploadsPath); Properties.Settings.Default["SteamUploadsDirectory"] = kSteamUploadsDirectoryPath; } } else if (newSteamUploadsPath == string.Empty) { // Accept cleaning the additional path to not show the mods in there kSteamUploadsDirectoryPath = JsonHelper.NormalizeSystemPath(newSteamUploadsPath); Properties.Settings.Default["SteamUploadsDirectory"] = kSteamUploadsDirectoryPath; } return(modsPathAccepted); }
private bool chooseModDirectory() { var dialog = new FolderSelectDialog() { DirectoryPath = kModsDirectoryPath ?? Environment.CurrentDirectory, Title = "Stonehearth Mods Root Directory" }; DialogResult result = DialogResult.Abort; do { result = dialog.ShowDialog(); if (result == DialogResult.OK) { string newPath = dialog.DirectoryPath; var check = this.checkModsFolder(ref newPath); if (check == ModFolderCheckResult.ZIPPED) { if (MessageBox.Show("The chosen directory appears to have compressed mods. To use it, the mods must be uncompressed. Would you like to do that?", "Compressed mods directory", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { var splash = new LoadingSplash(); splash.Show(); Application.DoEvents(); // Hacky, but whatever. foreach (var path in Directory.EnumerateFiles(newPath)) { if (path.EndsWith(".smod") && !Directory.Exists(path.Substring(0, path.Length - 5))) { System.IO.Compression.ZipFile.ExtractToDirectory(path, newPath); } } splash.Hide(); splash.Dispose(); check = ModFolderCheckResult.VALID; } } if (check == ModFolderCheckResult.VALID) { kModsDirectoryPath = JsonHelper.NormalizeSystemPath(newPath); Properties.Settings.Default["ModsDirectory"] = kModsDirectoryPath; Properties.Settings.Default.Save(); return(true); } else if (Directory.Exists(newPath)) { // If the directory does exist, but doesn't seem to be valid, make it a user choice if (MessageBox.Show("The chosen directory does not appear to be a valid mods directory. Choose it anyway?", "Possibly invalid mods directory", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { kModsDirectoryPath = JsonHelper.NormalizeSystemPath(newPath); Properties.Settings.Default["ModsDirectory"] = kModsDirectoryPath; return(true); } } else { if (MessageBox.Show("Invalid mods directory chosen. Try again?", "Invalid directory", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No) { return(false); } } } else { if (MessageBox.Show("No mods directory selected. Try again?", "No directory selected.", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return(false); } } }while (true); // repeat until we've got a proper directory or the user aborts }
// Add tree nodes in the specified folder (inside mods folder) private void AddTreeNodesByFolder(List <TreeNode> treeNodes, string folderName) { string[] modFolders = Directory.GetDirectories(mModsDirectoryPath); if (modFolders == null) { return; } // check all the mod folders foreach (string modPath in modFolders) { string modName = System.IO.Path.GetFileName(modPath); TreeNode modNode = new TreeNode(modName); bool hasChildren = false; string searchDirectoryPath = JsonHelper.NormalizeSystemPath(modPath) + folderName; if (Directory.Exists(searchDirectoryPath)) { // check all the folders foreach (string folderPath in Directory.EnumerateDirectories(searchDirectoryPath)) { hasChildren = true; string rootFolderName = System.IO.Path.GetFileName(folderPath); TreeNode root = new TreeNode(rootFolderName); modNode.Nodes.Add(root); // Add effect folder node under mod name node AppendTreeNodes(root, folderPath); // Append tree nodes from nested folders and files root.ExpandAll(); // Expand the top level } } if (hasChildren) { treeNodes.Add(modNode); modNode.ExpandAll(); } } // Repeat but for steam uploads directory if (SteamUploadsDirectoryPathExists()) { string[] moreModFolders = Directory.GetDirectories(mSteamUploadsDirectoryPath); if (moreModFolders == null) { return; } // check all the mod folders foreach (string modPath in moreModFolders) { string modName = System.IO.Path.GetFileName(modPath); TreeNode modNode = new TreeNode(modName); bool hasChildren = false; string searchDirectoryPath = JsonHelper.NormalizeSystemPath(modPath) + folderName; if (Directory.Exists(searchDirectoryPath)) { // check all the folders foreach (string folderPath in Directory.EnumerateDirectories(searchDirectoryPath)) { hasChildren = true; string rootFolderName = System.IO.Path.GetFileName(folderPath); TreeNode root = new TreeNode(rootFolderName); modNode.Nodes.Add(root); // Add effect folder node under mod name node AppendTreeNodes(root, folderPath); // Append tree nodes from nested folders and files root.ExpandAll(); // Expand the top level } } if (hasChildren) { treeNodes.Add(modNode); modNode.ExpandAll(); } } } }
public static string GetFileFromFileJson(string fileJson, string parentPath) { parentPath = JsonHelper.NormalizeSystemPath(parentPath); string fullPath = string.Empty; bool startedWithFile = false; if (fileJson.StartsWith("file(")) { string temp = fileJson.Substring(5); fullPath = temp.Substring(0, temp.Length - 1); startedWithFile = true; } else { fullPath = fileJson; } if (fullPath.IndexOf("../") >= 0) { // If there's a relative directory int index = fullPath.IndexOf("../"); char[] delimeter = "/".ToCharArray(); string[] splitParentPath = parentPath.Split(delimeter); int parentPathCount = splitParentPath.Length + 1; while (index >= 0) { parentPathCount--; fullPath = fullPath.Substring(index + 3); index = fullPath.IndexOf("../"); } splitParentPath = parentPath.Split(delimeter, parentPathCount); splitParentPath[splitParentPath.Length - 1] = ""; parentPath = string.Join("/", splitParentPath); parentPath = parentPath.Substring(0, parentPath.Length - 1); } else if (fileJson.IndexOf('.') < 0) { string folderName = fullPath.Substring(fullPath.LastIndexOf('/') + 1); fullPath = fullPath + "/" + folderName + ".json"; } if (fullPath.StartsWith("/")) { if (startedWithFile) { // We don't know where the mod is, so replace both directories just in case string mod = ModuleDataManager.GetInstance().TryReplaceModsDirectory(parentPath, "", "/"); mod = ModuleDataManager.GetInstance().TryReplaceSteamUploadsDirectory(mod, "", "/"); int firstSlash = mod.IndexOf('/'); if (firstSlash >= 0) { mod = mod.Substring(0, firstSlash); } fullPath = ModuleDataManager.GetInstance().GetParentDirectoryByModName(mod) + '/' + mod + fullPath; } else { // This is likely a recipe or similar. Assume the first word is the mod namespace string mod = fullPath; mod = mod.Substring(1); // Remove the first slash int firstSlash = mod.IndexOf('/'); mod = mod.Substring(0, firstSlash); fullPath = ModuleDataManager.GetInstance().GetParentDirectoryByModName(mod) + fullPath; } } else { fullPath = parentPath + "/" + fullPath; } return(fullPath); }