Пример #1
0
        public void ConvertXmlToExcel(DirectoryInfo lastPathToDataFiles, bool insertMod)
        {
            TranslationComponents transComp = GetTranslationComponents(lastPathToDataFiles, insertMod);

            var          eh  = new ExcelHelper();
            ExcelPackage pck = eh.CreateExcelDoc(_fiExcelFile);

            // structure of headers (columns) -> MOD | ID | English | lang1 | lang2, ...
            eh.CreateHeaderRow(pck, transComp.Headers);

            eh.WriteEntries(pck, transComp.AllModInfo);
            eh.SaveExcelDoc(pck);
        }
Пример #2
0
        private void openModFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string curPath = "";

            DirectoryInfo lastPath = ConfigHelper.GetLastPathOfDataFiles();

            if (lastPath != null)
            {
                curPath = lastPath.FullName;
            }

            if (string.IsNullOrEmpty(curPath) == false)
            {
                folderBrowserDialog1.SelectedPath = curPath;
            }
            folderBrowserDialog1.ShowNewFolderButton = true;


            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                m_tbModFolder.Text = folderBrowserDialog1.SelectedPath;
                try
                {
                    // start the process
                    TranslationComponents tc = TranslationManager.GetGridData(new DirectoryInfo(folderBrowserDialog1.SelectedPath));

                    if (tc == null)
                    {
                        MessageBox.Show("No 'stringtable.xml' files found.");
                        return;
                    }


                    _gridUiHelper = new GridUiHelper(this);
                    _gridUiHelper.ShowData(tc);

                    openModFolderToolStripMenuItem.Enabled = false;
                    saveToolStripMenuItem.Enabled          = true;
                    addLanguageToolStripMenuItem.Enabled   = true;
                    statisticsToolStripMenuItem.Enabled    = true;

                    ConfigHelper.SetLastPathOfDataFiles(new DirectoryInfo(folderBrowserDialog1.SelectedPath));
                }
                catch (DuplicateKeyException duplicateKeyException)
                {
                    MessageBox.Show(String.Format("Duplicate Key found.\nName: \"{0}\" \nFile: \"{1}\"", duplicateKeyException.KeyName, duplicateKeyException.FileName), "Duplicate Key Error");
                }
            }
        }
Пример #3
0
        private void openModFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string curPath = "";

            DirectoryInfo lastPath = ConfigHelper.GetLastPathOfDataFiles();

            if (lastPath != null)
            {
                curPath = lastPath.FullName;
            }

            if (string.IsNullOrEmpty(curPath) == false)
            {
                folderBrowserDialog1.SelectedPath = curPath;
            }
            folderBrowserDialog1.ShowNewFolderButton = true;


            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                m_tbModFolder.Text = folderBrowserDialog1.SelectedPath;
                try {
                    // start the process
                    TranslationComponents tc = TranslationManager.GetGridData(new DirectoryInfo(folderBrowserDialog1.SelectedPath));

                    if (tc == null)
                    {
                        MessageBox.Show(Resources.GridUI_No_stringtable_xml_files_found);
                        return;
                    }


                    _gridUiHelper = new GridUiHelper(this);
                    _gridUiHelper.ShowData(tc);

                    openModFolderToolStripMenuItem.Enabled = false;
                    saveToolStripMenuItem.Enabled          = true;
                    addLanguageToolStripMenuItem.Enabled   = true;
                    statisticsToolStripMenuItem.Enabled    = true;

                    ConfigHelper.SetLastPathOfDataFiles(new DirectoryInfo(folderBrowserDialog1.SelectedPath));
                } catch (DuplicateKeyException duplicateKeyException) {
                    MessageBox.Show(String.Format(Resources.GridUI_Duplicate_key_found, duplicateKeyException.KeyName, duplicateKeyException.FileName, duplicateKeyException.EntryName), Resources.GridUI_Duplicate_key_found_title);
                } catch (GenericXmlException xmlException) {
                    MessageBox.Show(String.Format(Resources.GridUI_Generic_xml_exception, xmlException.KeyName, xmlException.FileName, xmlException.EntryName), Resources.GridUI_Generic_xml_exception_title);
                }
            }
        }
Пример #4
0
        private TranslationComponents GetTranslationComponents(DirectoryInfo lastPathToDataFiles, bool insertMod)
        {
            List <FileInfo> allStringtableFiles = FileSystemHelper.GetFilesByNameInDirectory(lastPathToDataFiles, STRINGTABLE_NAME, SearchOption.AllDirectories).ToList();

            if (allStringtableFiles.Any() == false)
            {
                return(null);
            }

            var xh = new XmlHelper();
            TranslationComponents transComp = xh.ParseXmlFiles(allStringtableFiles);

            transComp.Headers = PrepareHeaders(transComp.Headers, insertMod);

            TranslationComponents = transComp;
            return(TranslationComponents);
        }
Пример #5
0
        private void PrepareTabControl(TranslationComponents tc)
        {
            foreach (ModInfoContainer modInfoContainer in tc.AllModInfo)
            {
                var tabPage = new TabPage(modInfoContainer.Name);
                tabPage.Name       = modInfoContainer.Name;
                tabPage.AutoScroll = true;

                _gridUi.tabControl1.TabPages.Add(tabPage);
            }

            foreach (TabPage tabPage in _gridUi.tabControl1.TabPages)
            {
                DataGridView gridView = CreateGridViewAndFillWithData(tc, tabPage.Text);

                tabPage.Controls.Add(gridView);
            }
        }
Пример #6
0
        public TranslationComponents ParseXmlFiles(List <FileInfo> allStringTablePaths)
        {
            var lstXDocuments = new List <XDocument>();

            var lstHeader = new List <string>();

            var allModInfos = new List <ModInfoContainer>();

            var transComp = new TranslationComponents();

            foreach (FileInfo currentFile in allStringTablePaths)
            {
                var modInfo = new ModInfoContainer();
                modInfo.FileInfoStringTable = currentFile;
                modInfo.Name = currentFile.Directory.Name;


                XDocument xdoc = XDocument.Load(currentFile.FullName);
                lstXDocuments.Add(xdoc);

                IEnumerable <XElement> keys = xdoc.Descendants().Where(x => x.Name == KEY_NAME);

                var dicKeyWithTranslations = new Dictionary <string, Dictionary <string, string> >();

                // all keys
                foreach (XElement key in keys)
                {
                    string currentKeyId = key.Attribute(ID_NAME).Value;

                    var dicTranslations = new Dictionary <string, string>();

                    // all languages of a key
                    foreach (XElement language in key.Descendants())
                    {
                        string languageName = language.Name.ToString();

                        if (dicTranslations.ContainsKey(languageName))
                        {
                            throw new DuplicateKeyException(languageName, currentFile.FullName);
                        }

                        dicTranslations.Add(languageName, language.Value);

                        // save all the languages
                        if (lstHeader.Contains(languageName) == false)
                        {
                            lstHeader.Add(languageName);
                        }
                    }

                    if (dicKeyWithTranslations.ContainsKey(currentKeyId))
                    {
                        throw new DuplicateKeyException(currentKeyId, currentFile.FullName);
                    }
                    dicKeyWithTranslations.Add(currentKeyId, dicTranslations);
                }


                modInfo.Values = dicKeyWithTranslations;
                allModInfos.Add(modInfo);
            }

            transComp.AllModInfo = allModInfos;
            transComp.Headers    = lstHeader;

            return(transComp);
        }
Пример #7
0
 public void ShowData(TranslationComponents tc)
 {
     _tc = tc;
     PrepareTabControl(tc);
 }
Пример #8
0
        private DataGridView CreateGridViewAndFillWithData(TranslationComponents tc, string currentModule)
        {
            var gridView = new DataGridView();

            gridView.Dock = DockStyle.Fill;

            gridView.EditMode = DataGridViewEditMode.EditOnKeystroke;


            gridView.CellValueChanged       += gridView_CellValueChanged;
            gridView.CellBeginEdit          += gridView_CellBeginEdit;
            gridView.KeyUp                  += gridView_KeyUp;
            gridView.KeyDown                += gridView_KeyDown;
            gridView.UserDeletedRow         += gridView_UserDeletedRow;
            gridView.ColumnHeaderMouseClick += gridView_ColumnHeaderMouseClick;

            foreach (string header in tc.Headers)
            {
                var dgvc = new DataGridViewTextBoxColumn();
                dgvc.HeaderText = header;
                dgvc.SortMode   = DataGridViewColumnSortMode.NotSortable;
                dgvc.Resizable  = DataGridViewTriState.True;
                gridView.Columns.Add(dgvc);
            }

            ModInfoContainer modInfoContainer = tc.AllModInfo.FirstOrDefault(mi => mi.Name == currentModule);

            if (modInfoContainer != null)
            {
                foreach (var translationsWithKey in modInfoContainer.Values)
                {
                    var row = new DataGridViewRow();
                    row.CreateCells(gridView);

                    int index = 1;

                    row.Cells[0].Value = translationsWithKey.Key;


                    foreach (string header in tc.Headers)
                    {
                        if (header == TranslationManager.COLUMN_IDNAME || header == TranslationManager.COLUMN_MODNAME)
                        {
                            continue;
                        }

                        if (header == "English")
                        {
                            row.Cells[index].Style.BackColor = Color.FromKnownColor(COLOR_BASELANGUAGE);
                        }

                        if (!translationsWithKey.Value.ContainsKey(header))
                        {
                            row.Cells[index].Style.BackColor = Color.FromKnownColor(COLOR_EMPTYCELL);
                            AddMissingTranslationToStatistics(tc.Statistics, header, currentModule);
                        }
                        else
                        {
                            string trans = translationsWithKey.Value[header];
                            row.Cells[index].Value          = trans;
                            row.Cells[index].Style.WrapMode = DataGridViewTriState.True;
                        }

                        index += 1;
                    }

                    gridView.Rows.Add(row);
                }
            }


            gridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            //gridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            return(gridView);
        }
Пример #9
0
        public TranslationComponents ParseXmlFiles(List <FileInfo> allStringTablePaths)
        {
            var lstHeader = new System.Collections.Concurrent.ConcurrentBag <string>();

            var allModInfos = new System.Collections.Concurrent.ConcurrentBag <ModInfoContainer>();

            var transComp = new TranslationComponents();

            Parallel.ForEach(allStringTablePaths, (currentFile) => {
                var modInfo = new ModInfoContainer {
                    FileInfoStringTable = currentFile,
                    Name = currentFile.Directory.Name
                };

                XDocument xdoc;

                try {
                    xdoc = XDocument.Load(currentFile.FullName);
                } catch (XmlException xmlException) {
                    throw new GenericXmlException("", currentFile.FullName, xmlException.Message);
                }

                IEnumerable <XElement> keys = xdoc.Descendants().Where(x => x.Name == KEY_NAME);

                var dicKeyWithTranslations = new Dictionary <string, Dictionary <string, string> >();

                // all keys
                foreach (XElement key in keys)
                {
                    string currentKeyId = key.Attribute(ID_NAME).Value;

                    var dicTranslations = new Dictionary <string, string>();

                    // all languages of a key
                    foreach (XElement language in key.Descendants())
                    {
                        string languageName = language.Name.ToString();

                        if (dicTranslations.ContainsKey(languageName))
                        {
                            throw new DuplicateKeyException(languageName, currentFile.FullName, currentKeyId);
                        }

                        dicTranslations.Add(languageName, language.Value);

                        // save all the languages
                        if (lstHeader.Contains(languageName) == false)
                        {
                            lstHeader.Add(languageName);
                        }
                    }

                    if (dicKeyWithTranslations.ContainsKey(currentKeyId))
                    {
                        throw new DuplicateKeyException(currentKeyId, currentFile.FullName, currentKeyId);
                    }
                    dicKeyWithTranslations.Add(currentKeyId, dicTranslations);
                }


                modInfo.Values = dicKeyWithTranslations;
                allModInfos.Add(modInfo);
            });

            transComp.AllModInfo = allModInfos.OrderBy(mic => mic.Name).ToList();
            transComp.Headers    = lstHeader.OrderBy(h => h).ToList();

            return(transComp);
        }