private void ProcessStageModFiles(string[] files, string baseDirectory) { string[] xmlFiles = Utils.FindFilesByFilename(files, "kamimod.xml"); List <string> XmlModFiles = new List <string>(); List <StageModXML> XmlMods = new List <StageModXML>(); if (xmlFiles != null) { foreach (string xmlFile in xmlFiles) { if (Path.GetFileName(xmlFile) != "kamimod.xml") { continue; } StageModXML mod = Utils.DeserializeXML <StageModXML>(xmlFile); if (mod == null) { continue; } XmlMods.Add(mod); XmlModFiles.Add(xmlFile); } } if (XmlMods.Count > 0) { for (int i = 0; i < XmlMods.Count; ++i) { string oldBasePath = Path.GetDirectoryName(XmlModFiles[0]); string modFolderName = oldBasePath.Split(Path.DirectorySeparatorChar).Last(); if (modFolderName == "unzip") { modFolderName = XmlMods[i].DisplayName; } StageModXML xmlTest = Utils.OpenStageKamiModFile(modFolderName); if (xmlTest != null) { MessageBox.Show(String.Format("Mod already exists under the same folder name '{0}'. Skipping...", modFolderName)); return; } oldBasePath = oldBasePath + Path.DirectorySeparatorChar; string newBasePath = PathHelper.FolderStageMods + modFolderName + Path.DirectorySeparatorChar; Utils.CopyAllValidFilesBetweenDirectories(oldBasePath, newBasePath); LogHelper.Info(String.Format("KamiMod {0} imported successfully!", modFolderName)); RefreshRowData(); } } else { string baseDirectoryTopFolderExcluded = baseDirectory.Remove(baseDirectory.LastIndexOf(Path.DirectorySeparatorChar, baseDirectory.Length - 2)); string stageFolder = Utils.FindDirectoryInFiles(files, DB.StagesDB.StageNames, baseDirectoryTopFolderExcluded); //Check if all the folders are either empty, or don't exist if (stageFolder.Equals(String.Empty)) { MessageBox.Show("No valid mod files or directories found. Make sure that the mod files follow the Sm4shExplorer file tree, and have a root folder of 'melee' or 'end' that has a stage folder such as 'BattleField_f'"); LogHelper.Error("No valid mod files or directories found. Make sure that the mod files follow the Sm4shExplorer file tree, and have a root folder of 'melee' or 'end' that has a stage folder such as 'BattleField_f'"); return; } DB.Stage stage = null; string[] folderParts = stageFolder.Split(Path.DirectorySeparatorChar); string folder1 = folderParts[folderParts.Length - 2]; string folder2 = folderParts.Last(); if (folder1.Equals("melee")) { foreach (DB.Stage st in DB.StagesDB.Stages) { if (st.Type != DB.StageType.Melee) { continue; } if (!folder2.Equals(st.Label)) { continue; } stage = st; break; } } else if (folder1.Equals("end")) { foreach (DB.Stage st in DB.StagesDB.Stages) { if (st.Type != DB.StageType.End) { continue; } if (!folder2.Equals(st.Label)) { continue; } stage = st; break; } } if (stage == null) { MessageBox.Show("No 'end' or 'melee' folder found. Make sure that the mod files follow the Sm4shExplorer file tree, and have a root folder of 'melee' or 'end' that has a stage folder such as 'BattleField_f'"); LogHelper.Error("No 'end' or 'melee' folder found. Make sure that the mod files follow the Sm4shExplorer file tree, and have a root folder of 'melee' or 'end' that has a stage folder such as 'BattleField_f'"); return; } string name = baseDirectory.Split(Path.DirectorySeparatorChar).Last(); Forms.NewModNamePopup popup = new Forms.NewModNamePopup(); popup.nameText = name; bool nameValid = false; while (!nameValid) { popup.ShowDialog(); if (!popup.confirmPressed) { return; } popup.confirmPressed = false; name = popup.nameText; name = PathHelper.RemoveInvalidFilenameChars(name); if (name.Length < 1) { MessageBox.Show("Invalid mod name given. Please enter a new one."); continue; } StageModXML xmlTest = Utils.OpenStageKamiModFile(name); if (xmlTest != null) { MessageBox.Show("Mod already exists under the same folder name. Please enter a new one."); continue; } nameValid = true; } string newModDirectory = PathHelper.FolderStageMods + Path.DirectorySeparatorChar + name + Path.DirectorySeparatorChar; string[] Files_stage_10 = Utils.FindFilesByFilename(files, "stage_10"); string[] Files_stage_11 = Utils.FindFilesByFilename(files, "stage_11"); string[] Files_stage_12 = Utils.FindFilesByFilename(files, "stage_12"); string[] Files_stage_13 = Utils.FindFilesByFilename(files, "stage_13"); string[] Files_stage_30 = Utils.FindFilesByFilename(files, "stage_30"); string[] Files_stagen_10 = Utils.FindFilesByFilename(files, "stagen_10"); #region XML File Creation StageModXML xml = new StageModXML(); xml.DisplayName = name; xml.WifiSafe = true; //Assuming wifi-safe xml.IntendedStage = stage.ID; xml.stage_10 = Files_stage_10.Length > 0; xml.stage_11 = Files_stage_11.Length > 0; xml.stage_12 = Files_stage_12.Length > 0; xml.stage_13 = Files_stage_13.Length > 0; xml.stage_30 = Files_stage_30.Length > 0; xml.stagen_10 = Files_stagen_10.Length > 0; Utils.SerializeXMLToFile(xml, newModDirectory + "kamimod.xml"); #endregion Utils.CopyAllValidFilesBetweenDirectories(stageFolder, newModDirectory + "stage" + Path.DirectorySeparatorChar); if (xml.stage_10 || xml.stage_11 || xml.stage_12 || xml.stage_13 || xml.stage_30 || xml.stagen_10) { string baseChrPath = newModDirectory + "ui" + Path.DirectorySeparatorChar; Directory.CreateDirectory(baseChrPath); if (xml.stage_10) { File.Copy(Files_stage_10[0], baseChrPath + "stage_10_XX.nut"); } if (xml.stage_11) { File.Copy(Files_stage_11[0], baseChrPath + "stage_11_XX.nut"); } if (xml.stage_12) { File.Copy(Files_stage_12[0], baseChrPath + "stage_12_XX.nut"); } if (xml.stage_13) { File.Copy(Files_stage_13[0], baseChrPath + "stage_13_XX.nut"); } if (xml.stage_30) { File.Copy(Files_stage_30[0], baseChrPath + "stage_30_XX.nut"); } if (xml.stagen_10) { File.Copy(Files_stagen_10[0], baseChrPath + "stagen_10_XX.nut"); } } LogHelper.Info(String.Format("Mod {0} imported successfully!", name)); RefreshRowData(); } }
private void ProcessGeneralModFiles(string[] files, string baseDirectory) { string[] xmlFiles = Utils.FindFilesByFilename(files, "kamimod.xml"); List <string> XmlModFiles = new List <string>(); List <GeneralModXML> XmlMods = new List <GeneralModXML>(); if (xmlFiles != null) { foreach (string xmlFile in xmlFiles) { if (Path.GetFileName(xmlFile) != "kamimod.xml") { continue; } GeneralModXML mod = Utils.DeserializeXML <GeneralModXML>(xmlFile); if (mod == null) { continue; } XmlMods.Add(mod); XmlModFiles.Add(xmlFile); } } if (XmlMods.Count > 0) { for (int i = 0; i < XmlMods.Count; ++i) { string oldBasePath = Path.GetDirectoryName(XmlModFiles[0]); string modFolderName = oldBasePath.Split(Path.DirectorySeparatorChar).Last(); if (modFolderName == "unzip") { modFolderName = XmlMods[i].DisplayName; } GeneralModXML xmlTest = Utils.OpenGeneralKamiModFile(modFolderName); if (xmlTest != null) { MessageBox.Show(String.Format("Mod already exists under the same folder name '{0}'. Skipping...", modFolderName)); return; } oldBasePath = oldBasePath + Path.DirectorySeparatorChar; string newBasePath = PathHelper.FolderGeneralMods + modFolderName + Path.DirectorySeparatorChar; Utils.CopyAllValidFilesBetweenDirectories(oldBasePath, newBasePath); LogHelper.Info(String.Format("KamiMod {0} imported successfully!", modFolderName)); RefreshRowData(); } } else { string baseDirectoryTopFolderExcluded = baseDirectory.Remove(baseDirectory.LastIndexOf(Path.DirectorySeparatorChar, baseDirectory.Length - 2)); string data_Folder = Utils.FindDirectoryInFiles(files, "data", baseDirectoryTopFolderExcluded); string data_en_Folder = Utils.FindDirectoryInFiles(files, "data(us_en)", baseDirectoryTopFolderExcluded); string data_fr_Folder = Utils.FindDirectoryInFiles(files, "data(us_fr)", baseDirectoryTopFolderExcluded); string data_sp_Folder = Utils.FindDirectoryInFiles(files, "data(us_sp)", baseDirectoryTopFolderExcluded); //Check if all the folders are either empty, or don't exist if (data_Folder.Equals(String.Empty) && data_en_Folder.Equals(String.Empty) && data_fr_Folder.Equals(String.Empty) && data_sp_Folder.Equals(String.Empty)) { MessageBox.Show("No valid mod files or directories found. Make sure that the mod files follow the Sm4shExplorer file tree, and have a root folder of 'data', 'data(us_en)', 'data(us_fr)' and/or 'data(us_sp).'"); LogHelper.Error("No valid mod files or directories found. Make sure that the mod files follow the Sm4shExplorer file tree, and have a root folder of 'data', 'data(us_en)', 'data(us_fr)' and/or 'data(us_sp).'"); return; } string name = baseDirectory.Split(Path.DirectorySeparatorChar).Last(); Forms.NewModNamePopup popup = new Forms.NewModNamePopup(); popup.nameText = name; bool nameValid = false; while (!nameValid) { popup.ShowDialog(); if (!popup.confirmPressed) { return; } popup.confirmPressed = false; name = popup.nameText; name = PathHelper.RemoveInvalidFilenameChars(name); if (name.Length < 1) { MessageBox.Show("Invalid mod name given. Please enter a new one."); continue; } GeneralModXML xmlTest = Utils.OpenGeneralKamiModFile(name); if (xmlTest != null) { MessageBox.Show("Mod already exists under the same folder name. Please enter a new one."); continue; } nameValid = true; } string newModDirectory = PathHelper.FolderGeneralMods + Path.DirectorySeparatorChar + name + Path.DirectorySeparatorChar; #region XML File Creation GeneralModXML xml = new GeneralModXML(); xml.DisplayName = name; xml.WifiSafe = true; //Assuming wifi-safe Utils.SerializeXMLToFile(xml, newModDirectory + "kamimod.xml"); #endregion #region Mod Files if (!data_Folder.Equals(String.Empty)) { Utils.CopyAllValidFilesBetweenDirectories(data_Folder, newModDirectory + "data" + Path.DirectorySeparatorChar); } if (!data_en_Folder.Equals(String.Empty)) { Utils.CopyAllValidFilesBetweenDirectories(data_en_Folder, newModDirectory + "data(us_en)" + Path.DirectorySeparatorChar); } if (!data_fr_Folder.Equals(String.Empty)) { Utils.CopyAllValidFilesBetweenDirectories(data_fr_Folder, newModDirectory + "data(us_fr)" + Path.DirectorySeparatorChar); } if (!data_sp_Folder.Equals(String.Empty)) { Utils.CopyAllValidFilesBetweenDirectories(data_sp_Folder, newModDirectory + "data(us_sp)" + Path.DirectorySeparatorChar); } #endregion LogHelper.Info(String.Format("Mod {0} imported successfully!", name)); RefreshRowData(); } }
private void ProcessCharacterGeneralModFiles(string[] files, string baseDirectory) { string[] xmlFiles = Utils.FindFilesByFilename(files, "kamimod.xml"); List <string> XmlModFiles = new List <string>(); List <CharacterGeneralModXML> XmlMods = new List <CharacterGeneralModXML>(); if (xmlFiles != null) { foreach (string xmlFile in xmlFiles) { if (Path.GetFileName(xmlFile) != "kamimod.xml") { continue; } CharacterGeneralModXML mod = Utils.DeserializeXML <CharacterGeneralModXML>(xmlFile); if (mod == null) { continue; } XmlMods.Add(mod); XmlModFiles.Add(xmlFile); } } if (XmlMods.Count > 0) { for (int i = 0; i < XmlMods.Count; ++i) { string oldBasePath = Path.GetDirectoryName(XmlModFiles[0]); string modFolderName = oldBasePath.Split(Path.DirectorySeparatorChar).Last(); if (modFolderName == "unzip") { modFolderName = XmlMods[i].DisplayName; } CharacterGeneralModXML xmlTest = Utils.OpenCharacterGeneralKamiModFile(_CurrentFighter.name, modFolderName); if (xmlTest != null) { MessageBox.Show(String.Format("Mod already exists under the same folder name '{0}'. Skipping...", modFolderName)); return; } oldBasePath = oldBasePath + Path.DirectorySeparatorChar; string newBasePath = PathHelper.FolderCharGeneralMods + _CurrentFighter.name + Path.DirectorySeparatorChar + modFolderName + Path.DirectorySeparatorChar; Utils.CopyAllValidFilesBetweenDirectories(oldBasePath, newBasePath); LogHelper.Info(String.Format("KamiMod {0} imported successfully!", modFolderName)); RefreshRowData(); } } else { string baseDirectoryTopFolderExcluded = baseDirectory.Remove(baseDirectory.LastIndexOf(Path.DirectorySeparatorChar, baseDirectory.Length - 2)); string cameraFolder = Utils.FindDirectoryInFiles(files, "camera", baseDirectoryTopFolderExcluded); string modelFolder = Utils.FindDirectoryInFiles(files, "model", baseDirectoryTopFolderExcluded); string effectFolder = Utils.FindDirectoryInFiles(files, "effect", baseDirectoryTopFolderExcluded); string motionFolder = Utils.FindDirectoryInFiles(files, "motion", baseDirectoryTopFolderExcluded); string scriptFolder = Utils.FindDirectoryInFiles(files, "script", baseDirectoryTopFolderExcluded); string soundFolder = Utils.FindDirectoryInFiles(files, "sound", baseDirectoryTopFolderExcluded); if (string.IsNullOrEmpty(cameraFolder) && string.IsNullOrEmpty(modelFolder) && string.IsNullOrEmpty(effectFolder) && string.IsNullOrEmpty(motionFolder) && string.IsNullOrEmpty(scriptFolder) && string.IsNullOrEmpty(soundFolder)) { MessageBox.Show("No valid folder found. Make sure the directory or zip file contains one of the following folders: camera, model, effect, motion, script, sound"); LogHelper.Error("No valid folder found. Make sure the directory or zip file contains one of the following folders: camera, model, effect, motion, script, sound"); return; } string name = baseDirectory.Split(Path.DirectorySeparatorChar).Last(); Forms.NewModNamePopup popup = new Forms.NewModNamePopup(); popup.nameText = name; bool nameValid = false; while (!nameValid) { popup.ShowDialog(); if (!popup.confirmPressed) { return; } popup.confirmPressed = false; name = popup.nameText; name = PathHelper.RemoveInvalidFilenameChars(name); if (name.Length < 1) { MessageBox.Show("Invalid mod name given. Please enter a new one."); continue; } CharacterGeneralModXML xmlTest = Utils.OpenCharacterGeneralKamiModFile(_CurrentFighter.name, name); if (xmlTest != null) { MessageBox.Show("Mod already exists under the same folder name. Please enter a new one."); continue; } nameValid = true; } string newModDirectory = PathHelper.FolderCharGeneralMods + Path.DirectorySeparatorChar + _CurrentFighter.name + Path.DirectorySeparatorChar + name + Path.DirectorySeparatorChar; #region XML File Creation CharacterGeneralModXML xml = new CharacterGeneralModXML(); xml.DisplayName = name; xml.WifiSafe = true; //Assuming wifi-safe Utils.SerializeXMLToFile(xml, newModDirectory + "kamimod.xml"); #endregion #region Mod Files if (!cameraFolder.Equals(String.Empty)) { Utils.CopyAllValidFilesBetweenDirectories(cameraFolder, newModDirectory + "camera" + Path.DirectorySeparatorChar); } if (!modelFolder.Equals(String.Empty)) { Utils.CopyAllValidFilesBetweenDirectories(modelFolder, newModDirectory + "model" + Path.DirectorySeparatorChar); } if (!effectFolder.Equals(String.Empty)) { Utils.CopyAllValidFilesBetweenDirectories(effectFolder, newModDirectory + "effect" + Path.DirectorySeparatorChar); } if (!motionFolder.Equals(String.Empty)) { Utils.CopyAllValidFilesBetweenDirectories(motionFolder, newModDirectory + "motion" + Path.DirectorySeparatorChar); } if (!scriptFolder.Equals(String.Empty)) { Utils.CopyAllValidFilesBetweenDirectories(scriptFolder, newModDirectory + "script" + Path.DirectorySeparatorChar); } if (!soundFolder.Equals(String.Empty)) { Utils.CopyAllValidFilesBetweenDirectories(soundFolder, newModDirectory + "sound" + Path.DirectorySeparatorChar); } #endregion LogHelper.Info(String.Format("Mod {0} imported successfully!", name)); RefreshRowData(); } }