public void LoadStartingDirectory(ComboBox searchTreeLoadedFilesComboBox, ComboBox newObjectViewLoadedFilesComboBox, ComboBox currentModLoadedFilesCenterViewComboBox, ComboBox loadedModsSearchViewComboBox, ComboBox CurrentGameFilesCenterViewComboBox) { Directory.CreateDirectory(XmlFileManager.LoadedFilesPath); Directory.CreateDirectory(Path.Combine(XmlFileManager.LoadedFilesPath, XmlFileManager.Xui_Folder_Name)); Directory.CreateDirectory(Path.Combine(XmlFileManager.LoadedFilesPath, XmlFileManager.Xui_Menu_Folder_Name)); //Check normal files string[] files = Directory.GetFiles(XmlFileManager.LoadedFilesPath, "*.xml"); LoadFilesPathWrappers(files, searchTreeLoadedFilesComboBox, newObjectViewLoadedFilesComboBox, CurrentGameFilesCenterViewComboBox); //Check for Xui files string[] xuiFiles = Directory.GetFiles(Path.Combine(XmlFileManager.LoadedFilesPath, XmlFileManager.Xui_Folder_Name)); if (xuiFiles.Length > 0) { LoadFilesPathWrappers(xuiFiles, searchTreeLoadedFilesComboBox, newObjectViewLoadedFilesComboBox, CurrentGameFilesCenterViewComboBox); } //Check for Xui menu files string[] xuiMenuFiles = Directory.GetFiles(Path.Combine(XmlFileManager.LoadedFilesPath, XmlFileManager.Xui_Menu_Folder_Name)); if (xuiMenuFiles.Length > 0) { LoadFilesPathWrappers(xuiMenuFiles, searchTreeLoadedFilesComboBox, newObjectViewLoadedFilesComboBox, CurrentGameFilesCenterViewComboBox); } List <string> allCustomTagDirectories = XmlFileManager.GetCustomModFoldersInOutput(); loadedModsSearchViewComboBox.AddUniqueValueTo(""); foreach (string nextModTag in allCustomTagDirectories) { loadedModsSearchViewComboBox.AddUniqueValueTo(nextModTag); LoadCustomTagWrappers(nextModTag, currentModLoadedFilesCenterViewComboBox); } }
public void LoadDirectoryViewControl(ComboBox loadedModsSearchViewComboBox, ComboBox loadedModsCenterViewComboBox, ComboBox currentModFilesCenterViewComboBox) { CommonOpenFileDialog openFileDialog = new CommonOpenFileDialog { IsFolderPicker = true }; if (openFileDialog.ShowDialog() == CommonFileDialogResult.Ok) { string fullSelectedPath = openFileDialog.FileName; string currentModName = Path.GetFileName(openFileDialog.FileName); bool hasXmlFiles = XmlFileManager.CheckLoadedModFolderForXmlFiles(fullSelectedPath); if (hasXmlFiles && !fullSelectedPath.ToLower().Contains("config")) { currentModFilesCenterViewComboBox.SetComboBox(new List <string>()); Properties.Settings.Default.ModTagSetting = currentModName; Properties.Settings.Default.Save(); loadedModsSearchViewComboBox.SelectedItem = currentModName; //Copy the files to the output path at Output/Mods/ModName string appOutputPath = Path.Combine(XmlFileManager.AllModsOutputPath, "Mods", currentModName); bool overwriteLocalAppFiles = false; if (Directory.Exists(appOutputPath)) { MessageBoxResult messageBoxResult = MessageBox.Show( "The mod is already loaded. Do you want to OVERWRITE the local, application files?\n\n" + "WARNING: This feature does not merge the files! If you have changes in the files, they will be overwritten.", "Overwrite Application Mod Files", MessageBoxButton.YesNo, MessageBoxImage.Question); switch (messageBoxResult) { case MessageBoxResult.Yes: overwriteLocalAppFiles = true; break; } } XmlFileManager.CopyAllFilesToPath(fullSelectedPath, appOutputPath, overwriteLocalAppFiles); loadedModsCenterViewComboBox.AddUniqueValueTo(currentModName); loadedModsSearchViewComboBox.AddUniqueValueTo(currentModName); LoadCustomTagWrappers(currentModName, currentModFilesCenterViewComboBox); } else if (fullSelectedPath.ToLower().Contains("config")) { MessageBox.Show( "The was an error loading the mod at " + openFileDialog.FileName + ". If you selected the Config folder, please try again and select the ModFolder", "Error Loading Directory", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show( "The was an error loading the mod at " + openFileDialog.FileName + ". There was no xml found in the Config folder of the mod. Please check the folder for xml files.", "Missing XML Files!", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void SetCustomTagWrapper(string[] modOutputFiles, string nextModTag, ComboBox currentModLoadedFilesCenterViewComboBox) { foreach (string nextModFile in modOutputFiles) { string newOutputLocation = Path.Combine(XmlFileManager.LoadedFilesPath, nextModTag); XmlObjectsListWrapper wrapper = LoadWrapperFromFile(nextModFile); if (wrapper != null) { string wrapperDictionaryKey = nextModTag + "_" + wrapper.GenerateDictionaryKey(); UpdateWrapperInDictionary(wrapperDictionaryKey, wrapper); if (nextModTag.Equals(Properties.Settings.Default.ModTagSetting)) { currentModLoadedFilesCenterViewComboBox.AddUniqueValueTo(wrapperDictionaryKey); } if (!Directory.Exists(newOutputLocation)) { Directory.CreateDirectory(newOutputLocation); } string parentPath = wrapper.XmlFile.ParentPath ?? ""; if (!File.Exists(Path.Combine(newOutputLocation, parentPath, wrapper.XmlFile.FileName))) { Directory.CreateDirectory(Path.Combine(newOutputLocation, parentPath)); File.Copy(nextModFile, Path.Combine(newOutputLocation, parentPath, wrapper.XmlFile.FileName)); } } } }
private void AddWrapperDataToUIAndCopyFiles(string nextFileName, List <string> unloadedFiles, ComboBox searchTreeLoadedFilesComboBox, ComboBox newObjectViewLoadedFilesComboBox, ComboBox currentGameFilesCenterViewComboBox) { XmlObjectsListWrapper wrapper = LoadWrapperFromFile(nextFileName); string parentPath = wrapper.XmlFile.ParentPath ?? ""; string loadedFilePathToFile = Path.Combine(XmlFileManager.LoadedFilesPath, parentPath, wrapper.XmlFile.FileName); if (wrapper == null) { unloadedFiles.Add(nextFileName); } else if (File.Exists(loadedFilePathToFile)) { OverwriteFilePrompt(loadedFilePathToFile, nextFileName); } else { File.Copy(nextFileName, Path.Combine(XmlFileManager.LoadedFilesPath, parentPath, wrapper.XmlFile.FileName)); } if (wrapper != null) { string wrapperDictionaryKey = wrapper.GenerateDictionaryKey(); UpdateWrapperInDictionary(wrapperDictionaryKey, wrapper); searchTreeLoadedFilesComboBox.AddUniqueValueTo(wrapperDictionaryKey); newObjectViewLoadedFilesComboBox.AddUniqueValueTo(wrapperDictionaryKey); currentGameFilesCenterViewComboBox.AddUniqueValueTo(wrapperDictionaryKey); } }
private void AddModAttributesFromWrappers(List <XmlObjectsListWrapper> xmlWrappersForGameKeys, ComboBox newCommonValuesBox) { //Go through all mod files foreach (XmlObjectsListWrapper xmlObjectsListWrapper in xmlWrappersForGameKeys) { if (xmlObjectsListWrapper != null) { foreach (string tagNameKey in xmlObjectsListWrapper.ObjectNameToAttributeValuesMapNoXpath.Keys) { //Get the next top tag attribute mao Dictionary <string, List <string> > attributeDictinaryForItems = xmlObjectsListWrapper.ObjectNameToAttributeValuesMapNoXpath.GetValueOrDefault(tagNameKey); if (attributeDictinaryForItems != null) { //Get the first key in the attribute dictinary because we only want the first attribute //Probably a better way than a loop and break foreach (string key in attributeDictinaryForItems.Keys) { List <string> commonAttributes = attributeDictinaryForItems.GetValueOrDefault(key); if (commonAttributes != null) { newCommonValuesBox.AddUniqueValueTo(commonAttributes); //We only want the name, or key attribute. Essentially the first attribute in the wrapper dictionary. break; } } } //We only want the first tag found. break; } } } }
public static void AddUniqueValueTo(this ComboBox boxToAddTo, List <string> valuesToAdd) { if (boxToAddTo.ItemsSource == null) { ObservableCollection <string> allItems = new ObservableCollection <string>(valuesToAdd); boxToAddTo.ItemsSource = allItems; return; } else if (boxToAddTo.ItemsSource.GetType() == typeof(ObservableCollection <string>)) { foreach (string value in valuesToAdd) { boxToAddTo.AddUniqueValueTo(value); } } }
private void LoadFilesPathWrappers(string[] files, ComboBox searchTreeLoadedFilesComboBox, ComboBox newObjectViewLoadedFilesComboBox, ComboBox currentGameFilesCenterViewComboBox) { foreach (string file in files) { XmlObjectsListWrapper wrapper = LoadWrapperFromFile(file); string parentPath = wrapper.XmlFile.ParentPath ?? ""; if (wrapper != null && !File.Exists(Path.Combine(XmlFileManager.LoadedFilesPath, parentPath, wrapper.XmlFile.FileName))) { File.Copy(file, Path.Combine(XmlFileManager.LoadedFilesPath, parentPath, wrapper.XmlFile.FileName)); } if (wrapper != null) { string wrapperDictionaryKey = wrapper.GenerateDictionaryKey(); UpdateWrapperInDictionary(wrapperDictionaryKey, wrapper); searchTreeLoadedFilesComboBox.AddUniqueValueTo(wrapperDictionaryKey); newObjectViewLoadedFilesComboBox.AddUniqueValueTo(wrapperDictionaryKey); currentGameFilesCenterViewComboBox.AddUniqueValueTo(wrapperDictionaryKey); } } }