コード例 #1
0
        public void InjectTransifexFile()
        {
            // parcours les fichier puis essaye de retrouver la partie correspondante dans le fichier de traduction
            if (!File.Exists(this.TransifexFilePath))
            {
                throw new InvalidOperationException("No transifex file");
            }

            var type = DemocracyStringHandling.DetectFileType(this.TransifexFilePath);

            if (type == FileType.MainSentences)
            {
                InjectMain();
            }
            else if (type == FileType.Mods)
            {
                var transifexFileParser = new IniParser.FileIniDataParser();
                var transifexInidata    = transifexFileParser.ReadFile(this.TransifexFilePath, Encoding.UTF8);

                var modPath = transifexInidata.Sections.Where(s => s.SectionName.Contains("Mod__")).First().SectionName.Replace("Mod__", "");
                InjectMod(modPath);
            }
            else
            {
                //throw new InvalidOperationException("File not currently supported");
            }
        }
コード例 #2
0
        private async void buttonApply_Click(object sender, EventArgs e)
        {
            if (comboBoxLanguages.SelectedItem is Language)
            {
                if (!Directory.Exists(this.labelGameSourcePath.Text))
                {
                    MessageBox.Show("Please select a valid game path...", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                // Test if restore original files needed
                IsFirstLaunch();

                // if force download redownload
                if (this.checkBoxForceDl.Checked)
                {
                    var previousText = this.labelProgression.Text;
                    this.labelProgression.Text = "Loading transifex translations files...";
                    this.buttonApply.Visible   = false;
                    await this.DownloadTranslationFile(this.CurrentTranslationInfo.LanguageCode, this.CurrentTranslationInfo.Total_segments);

                    this.labelProgression.Text = previousText;
                    this.buttonApply.Visible   = true;
                    this.progressBarDownlodResources.Visible = false;
                }

                try
                {
                    // list all file from lang cache folder
                    var langCode = ((Language)comboBoxLanguages.SelectedItem).Code;

                    var files = Directory.EnumerateFiles(@"cache\{0}\".FormatWith(langCode), "*.ini");

                    var gameInjector = new DemocracyStringHandling(null, null, this.labelGameSourcePath.Text, this.checkBoxRemoveSC.Checked);

                    // For each file extract and inject
                    foreach (var file in files)
                    {
                        gameInjector.TransifexFilePath = file;
                        gameInjector.InjectTransifexFile();
                    }

                    // Copy additional files if french
                    if (langCode == "fr")
                    {
                        File.Copy(@"Resources\fr\partynames.txt", Path.Combine(this.labelGameSourcePath.Text, "partynames.txt"), overwrite: true);
                        File.Copy(@"Resources\fr\quotes.csv", Path.Combine(this.labelGameSourcePath.Text, "quotes.csv"), overwrite: true);
                    }

                    var dialogResult = MessageBox.Show("Game is now translated in {0}\r\nLaunch game ?".FormatWith(((Language)comboBoxLanguages.SelectedItem).Name), "Translation successful...", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                    {
                        var exePath          = this.labelGameSourcePath.Text.Replace("\\data", "") + "\\Democracy3.exe";
                        ProcessStartInfo psi = new ProcessStartInfo();
                        psi.FileName         = exePath;
                        psi.WorkingDirectory = System.IO.Path.GetDirectoryName(psi.FileName);
                        System.Diagnostics.Process.Start(psi);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }