public LocalizationFileObject(string pathToFile)
 {
     HeaderKeyToCommonValuesMap = new Dictionary <string, SortedSet <string> >();
     KeyValueToRecordMap        = new Dictionary <string, List <string> >();
     RecordList         = new List <List <string> >();
     HeaderValues       = DefaultHeaderColumns;
     LOCALIZATION_EXIST = File.Exists(pathToFile);
     if (LOCALIZATION_EXIST)
     {
         try
         {
             TraverseLocalizatonFile(pathToFile);
         }
         catch (Exception e)
         {
             XmlFileManager.WriteStringToLog("Localization parsing error: \n\n" + e.StackTrace);
             PARSING_ERROR = true;
         }
     }
     else
     {
         foreach (string header in DefaultHeaderColumns)
         {
             HeaderKeyToCommonValuesMap.Add(header, new SortedSet <string>());
         }
     }
 }
        public static void SaveAllGeneratedXmlToPath(MyStackPanel newObjectFormsPanel, string path, bool writeToLog = false)
        {
            string topTag    = "<" + Properties.Settings.Default.ModTagSetting + ">\n";
            string topTagEnd = "\n</" + Properties.Settings.Default.ModTagSetting + ">\n";

            foreach (Control nextChild in newObjectFormsPanel.Children)
            {
                //It is a top object in the view
                if (nextChild.GetType() == typeof(TreeViewItem))
                {
                    TreeViewItem          nextChildAsTree       = (TreeViewItem)nextChild;
                    XmlObjectsListWrapper xmlObjectsListWrapper = newObjectFormsPanel.StackPanelLoadedListWrappers.GetValueOrDefault(nextChildAsTree.Uid);
                    string parentPath = xmlObjectsListWrapper.XmlFile.ParentPath ?? "";
                    string xmlOut     = xmlObjectsListWrapper == null ? "" : GenerateXmlWithWrapper(nextChildAsTree, xmlObjectsListWrapper, true);
                    if (!String.IsNullOrEmpty(xmlOut))
                    {
                        XmlFileManager.WriteStringToFile(Path.Combine(path, parentPath), xmlObjectsListWrapper.XmlFile.FileName, topTag + xmlOut.TrimEnd() + topTagEnd, Properties.Settings.Default.DoLogTimestampOnSave);
                    }
                    if (writeToLog && !String.IsNullOrEmpty(xmlOut))
                    {
                        XmlFileManager.WriteStringToLog(xmlOut, true);
                    }
                }
            }
        }
        public static void CreateModInfoFile(string modTagDirectoryName)
        {
            string modDirectoryWithConfig = XmlFileManager.Get_ModDirectoryConfigPath(modTagDirectoryName);

            if (!Directory.Exists(modDirectoryWithConfig))
            {
                Directory.CreateDirectory(modDirectoryWithConfig);
            }
            string modInfoFilePath = Path.Combine(XmlFileManager.Get_ModDirectoryOutputPath(modTagDirectoryName), MOD_INFO_FILE_NAME);

            if (!File.Exists(modInfoFilePath))
            {
                File.Create(modInfoFilePath);
            }
        }
        public ModInfo(string modName)
        {
            string modInfoFilePath = Path.Combine(XmlFileManager.Get_ModDirectoryOutputPath(modName), MOD_INFO_FILE_NAME);

            if (File.Exists(modInfoFilePath))
            {
                bool didSucceed = LoadSettingsFromFile(modInfoFilePath);
                ModInfoExists = didSucceed;
                if (!didSucceed)
                {
                    ModInfoExists = false;
                    XmlFileManager.WriteStringToLog("Failed Loading mod info.");
                }
            }
        }
        private static string GenerateXmlWithWrapper(Control parentControl, XmlObjectsListWrapper xmlObjectsListWrapper, bool includeExistingData = false)
        {
            string       xmlOut = "";
            string       existingWrapperFileData = "";
            TreeViewItem nextChildAsTree         = (TreeViewItem)parentControl;

            //We have a target type tree view
            if (nextChildAsTree.Header.GetType() == typeof(string) && nextChildAsTree.Tag != null)
            {
                //The header is in the form nodename:targetattributename
                string[] treeTagSplit = nextChildAsTree.Header.ToString().Split(":");
                if (!treeTagSplit[0].Equals(IGNORE_STRING))
                {
                    xmlOut += GenerateAppendXmlForTargetObject(xmlObjectsListWrapper, nextChildAsTree, (XmlNode)nextChildAsTree.Tag, ((XmlNode)nextChildAsTree.Tag).Name);
                }
            }
            //We have a copied object creation tree view
            else if (nextChildAsTree.Header.GetType() == typeof(Button))
            {
                if (nextChildAsTree.Header is Button headerAsButton)
                {
                    xmlOut += GenerateObjectTreeXml(nextChildAsTree, xmlObjectsListWrapper, headerAsButton);
                }
            }
            //We have an empty object creation tree
            else
            {
                Button nextChildTreeButton = (Button)nextChildAsTree.Header;
                if (nextChildTreeButton != null)
                {
                    xmlOut += GenerateObjectTreeXml(nextChildAsTree, xmlObjectsListWrapper, nextChildTreeButton);
                }
            }
            string parentPath = xmlObjectsListWrapper.XmlFile.ParentPath ?? "";

            if (includeExistingData)
            {
                existingWrapperFileData = XmlFileManager.ReadExistingFile(Path.Combine(parentPath, xmlObjectsListWrapper.XmlFile.FileName), Properties.Settings.Default.ModTagSetting);
            }
            if (!String.IsNullOrEmpty(xmlOut) && !String.IsNullOrEmpty(existingWrapperFileData))
            {
                xmlOut += existingWrapperFileData;
            }
            return(xmlOut);
        }
        public bool LoadSettingsFromFile(string modInfoFilePath)
        {
            bool        didSucceed  = false;
            XmlDocument xmlDocument = new XmlDocument();

            try
            {
                xmlDocument.Load(modInfoFilePath);
                XmlNodeList allModInfoNodes = xmlDocument.GetElementsByTagName("ModInfo");
                XmlNode     firstChild      = allModInfoNodes.Item(0);
                if (firstChild != null)
                {
                    foreach (XmlNode nextNode in firstChild.ChildNodes)
                    {
                        if (nextNode.Name.Equals(MOD_INFO_NAME_TAG))
                        {
                            this.Name = nextNode.GetAvailableAttribute().Value;
                        }
                        else if (nextNode.Name.Equals(MOD_INFO_DESCRIPTION_TAG))
                        {
                            this.Description = nextNode.GetAvailableAttribute().Value;
                        }
                        else if (nextNode.Name.Equals(MOD_INFO_AUTHOR_TAG))
                        {
                            this.Author = nextNode.GetAvailableAttribute().Value;
                        }
                        else if (nextNode.Name.Equals(MOD_INFO_VERSION_TAG))
                        {
                            this.Version = nextNode.GetAvailableAttribute().Value;
                        }
                    }
                    didSucceed = true;
                }
            }
            catch (Exception e)
            {
                XmlFileManager.WriteStringToLog(e.Message);
            }
            return(didSucceed);
        }