static public bool BatchExportLocalization(SingleLanguageDB db,
                                            string refPath, string refFileFormatString, string overrideRefPattern,
                                            string outPath, string outFileFormatString, int splitLine = 0)
 {
     return(BatchExportLocalization(db, refPath, LocalizationFileFormat.GetFileFormat(refFileFormatString),
                                    overrideRefPattern, outPath, LocalizationFileFormat.GetFileFormat(outFileFormatString), splitLine));
 }
 private void FormMain_Load(object sender, EventArgs e)
 {
     foreach (TabPage tab in tabControlMain.TabPages)
     {
         foreach (Control c in tab.Controls)
         {
             if ((string)c.Tag == "FileFormat" && c is ComboBox)
             {
                 ComboBox cmb = (ComboBox)c;
                 cmb.DataSource = LocalizationFileFormat.GetAllFileFormats();
             }
         }
     }
     updateTextBoxFromSettings();
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="db"></param>
        /// <param name="path"></param>
        /// <param name="fileFormat"></param>
        /// <param name="overridePattern"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        static public int BatchImportToSingleLanguageDB(SingleLanguageDB db, string path, LocalizationFileFormat fileFormat,
                                                        string overridePattern = null, LocalizationDB.ImportMode mode = LocalizationDB.ImportMode.kReplace)
        {
            if (!Directory.Exists(path))
            {
                return(0);
            }

            string pattern    = overridePattern != null ? overridePattern : fileFormat.GetLocalizationFileInstance().DefaultNamePattern();
            int    totalCount = 0;

            foreach (var filename in Directory.EnumerateFiles(path, pattern))
            {
                ILocalizationFile file = fileFormat.GetLocalizationFileInstance();
                file.Read(filename);
                totalCount += ImportToSingleLanguageDBFromFile(db, file, mode);
            }
            return(totalCount);
        }
 static public int BatchImportToSingleLanguageDB(SingleLanguageDB db, string path, string fileFormatString,
                                                 string overridePattern = null, LocalizationDB.ImportMode mode = LocalizationDB.ImportMode.kReplace)
 {
     return(BatchImportToSingleLanguageDB(db, path, LocalizationFileFormat.GetFileFormat(fileFormatString), overridePattern, mode));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="db"></param>
        /// <param name="refPath"></param>
        /// <param name="refFileFormat"></param>
        /// <param name="overrideRefPattern"></param>
        /// <param name="outPath"></param>
        /// <param name="outFileFormat"></param>
        /// <param name="splitLine"></param>
        /// <returns></returns>
        static public bool BatchExportLocalization(SingleLanguageDB db,
                                                   string refPath, LocalizationFileFormat refFileFormat, string overrideRefPattern,
                                                   string outPath, LocalizationFileFormat outFileFormat, int splitLine = 0)
        {
            if (!Directory.Exists(refPath))
            {
                return(false);
            }

            string refpattern = overrideRefPattern != null ? overrideRefPattern : refFileFormat.GetLocalizationFileInstance().DefaultNamePattern();

            foreach (var filename in Directory.EnumerateFiles(refPath, refpattern))
            {
                ILocalizationFile reffile = refFileFormat.GetLocalizationFileInstance();
                reffile.Read(filename);

                ILocalizationFile outfile = outFileFormat.GetLocalizationFileInstance();
                if (!outfile.CanWrite())
                {
                    continue;
                }
                if (!ExportLocalization(db, reffile, outfile))
                {
                    continue;
                }
                string newName = Path.GetFileNameWithoutExtension(filename);
                Directory.CreateDirectory(outPath);
                if (splitLine <= 0)
                {
                    outfile.Write(outPath + "\\" + newName + "." + outfile.DefaultExtension());
                }
                else
                {
                    int count = outfile.CountLines();
                    if (count > 0)
                    {
                        ILocalizationFile splitFile = outFileFormat.GetLocalizationFileInstance();
                        splitFile.GenHeader("english");
                        int contentCount = 0;
                        int fileCount    = 1;
                        for (int i = outfile.HeaderLines(); i < count; ++i)
                        {
                            if (contentCount >= splitLine)
                            {
                                splitFile.Write(outPath + "\\" + newName + "-" + fileCount.ToString() + "." + splitFile.DefaultExtension());
                                fileCount++;
                                contentCount = 0;
                                if (i != count - 1)
                                {
                                    splitFile = outFileFormat.GetLocalizationFileInstance();
                                    splitFile.GenHeader("english");
                                }
                            }
                            if (outfile.IsLineLocalizationData(i))
                            {
                                string tag  = "";
                                int    ver  = 0;
                                string data = "";
                                string rest = "";
                                outfile.GetData(i, ref tag, ref ver, ref data, ref rest);
                                splitFile.AppendLine(tag, ver, data, rest);
                                contentCount++;
                            }
                            else
                            {
                                string data = "";
                                outfile.GetNonLocalizationData(i, ref data);
                                splitFile.AppendLine(null, 0, data, null);
                            }
                        }
                        splitFile.Write(outPath + "\\" + newName + "-" + fileCount.ToString() + "." + splitFile.DefaultExtension());
                    }
                }
            }
            return(true);
        }