Пример #1
0
        private void BatchExportTranslationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var sfd = new SaveFileDialog
            {
                Filter   = GenerateFilters(false),
                FileName = "Select a file type and folder to store all the text files and press Save",
                Title    = "Batch Export"
            };

            if (sfd.ShowDialog() == true)
            {
                // Path to the directory which will contain all the translation files
                string dir = Path.GetDirectoryName(sfd.FileName);
                // Gets the index of the filetype
                var index = sfd.FilterIndex - 1;
                foreach (var entry in ScriptArchive.FileEntries)
                {
                    var script = new STSCFile();
                    using (var stream = ScriptArchive.GetFileStream(entry.FileName))
                        script.Load(stream);
                    string filepath = Path.ChangeExtension(Path.Combine(dir, entry.FileName),
                                                           TranslationSTSCHandler.FileTypes[index].TypeExtension);
                    // Create the directory
                    Directory.CreateDirectory(Path.GetDirectoryName(filepath));
                    File.WriteAllText(filepath, TranslationSTSCHandler.ExportTranslation(index, script, ScriptDB, App.StringProcess), new UTF8Encoding(true));
                }
            }
        }
Пример #2
0
        private void BatchImportTranslationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            string tag = ((MenuItem)sender)?.Tag as string;
            var    sfd = new SaveFileDialog
            {
                Filter   = GenerateFilters(false),
                FileName = "Select a file type and the folder which contains the translation files (the folder containing the 1st, 2nd and 3rd folder) and press Save",
                Title    = "Batch Import"
            };

            if (sfd.ShowDialog() == true)
            {
                // Path to the directory which contains all the translation files
                string dir = Path.GetDirectoryName(sfd.FileName);
                // Gets the index of the filetype
                int index = sfd.FilterIndex - 1;
                foreach (var entry in ScriptArchive.FileEntries)
                {
                    var script = new STSCFile();
                    using (var stream = ScriptArchive.GetFileStream(entry.FileName))
                        script.Load(stream);
                    // Path to the script file
                    string filepath = Path.ChangeExtension(Path.Combine(dir, entry.FileName), TranslationSTSCHandler.FileTypes[index].TypeExtension);
                    // Skip script if file does not exist
                    if (!File.Exists(filepath))
                    {
                        continue;
                    }
                    // Import translation
                    try
                    {
                        string data = "";
                        using (var stream = File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                            using (StreamReader reader = new StreamReader(stream))
                                data = reader.ReadToEnd();
                        TranslationSTSCHandler.ImportTranslation(index, script, data, !tag.Contains("nokey"), App.StringProcess);
                        // Save the script back into the archive
                        using (var stream = new MemoryStream())
                        {
                            script.Save(stream);
                            ScriptArchive.ReplaceFile(entry.FileName, stream.ToArray());
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Failed to open file! Possible another program is using it.", "Import Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            // Reload the current script
            if (ScriptListBox.SelectedIndex == -1)
            {
                return;
            }
            LoadScript(ScriptArchive.FileEntries[ScriptListBox.SelectedIndex].FileName);
        }
Пример #3
0
        private void ImportTranslationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            string tag = ((MenuItem)sender)?.Tag as string;

            if (ScriptListBox.SelectedIndex == -1)
            {
                return;
            }
            var file = ScriptArchive.FileEntries[ScriptListBox.SelectedIndex];
            var ofd  = new OpenFileDialog
            {
                Filter = GenerateFilters(true)
            };

            if (ofd.ShowDialog() == true)
            {
                // Gets the index of the filetype
                int index = TranslationSTSCHandler.FileTypes.ToList().FindIndex(t => ofd.FileName.Contains(t.TypeExtension));
                // if importer is not found
                if (index == -1)
                {
                    MessageBox.Show("Could not detect the file type!", "Import Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                // TODO: Add key option
                // Import translation
                try
                {
                    string data = "";
                    using (var stream = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        using (StreamReader reader = new StreamReader(stream))
                            data = reader.ReadToEnd();
                    TranslationSTSCHandler.ImportTranslation(index, ScriptFile, data, !tag.Contains("nokey"), App.StringProcess);
                    // Save the script back into the archive
                    using (var stream = new MemoryStream())
                    {
                        ScriptFile.ConvertToDialogueCode();
                        ScriptFile.Save(stream);
                        ScriptArchive.ReplaceFile(file.FileName, stream.ToArray());
                    }
                    // Reload the current script
                    LoadScript(ScriptArchive.FileEntries[ScriptListBox.SelectedIndex].FileName);
                }
                catch
                {
                    MessageBox.Show("Failed to open file! Possible another program is using it.", "Import Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Пример #4
0
        private void ImportTranslationWorkbookMenuItem_Click(object sender, RoutedEventArgs e)
        {
            string tag = ((MenuItem)sender)?.Tag as string;
            var    sfd = new OpenFileDialog
            {
                Filter   = "Excel Workbook(*.xlsx)|*.xlsx",
                FileName = "Script.xlsx",
                Title    = "Import Excel Workbook"
            };

            if (sfd.ShowDialog() == true)
            {
                var workbook = Workbook.Load(sfd.FileName);

                foreach (var entry in ScriptArchive.FileEntries)
                {
                    var script = new STSCFile();
                    using (var stream = ScriptArchive.GetFileStream(entry.FileName))
                        script.Load(stream);

                    try
                    {
                        var worksheet = workbook.Worksheets.FirstOrDefault(t => entry.FileName.Contains(t.SheetName));
                        var lines     = TranslationXLSXFile.ImportWorksheet(worksheet);
                        TranslationSTSCHandler.ImportTranslation(lines, script, !tag.Contains("nokey"), App.StringProcess);
                        // Save the script back into the archive
                        using (var stream = new MemoryStream())
                        {
                            script.Save(stream);
                            ScriptArchive.ReplaceFile(entry.FileName, stream.ToArray());
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Failed to open file! Possible another program is using it.", "Import Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                // Reload the current script
                if (ScriptListBox.SelectedIndex == -1)
                {
                    return;
                }
                LoadScript(ScriptArchive.FileEntries[ScriptListBox.SelectedIndex].FileName);
            }
        }
Пример #5
0
        private void BatchImportTranslationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            string tag = ((MenuItem)sender)?.Tag as string;
            var    sfd = new SaveFileDialog
            {
                Filter   = GenerateFilters(false),
                FileName = "Select a file type and the folder which contains the translation files (the folder containing the 1st, 2nd and 3rd folder) and press Save",
                Title    = "Batch Import"
            };

            if (sfd.ShowDialog() == true)
            {
                // Path to the directory which contains all the translation files
                string dir = Path.GetDirectoryName(sfd.FileName);
                // Gets the index of the filetype
                int index = sfd.FilterIndex - 1;
                foreach (var entry in ScriptArchive.FileEntries)
                {
                    var script = new STSCFile();
                    using (var stream = ScriptArchive.GetFileStream(entry.FileName))
                        script.Load(stream);
                    // Path to the script file
                    string filepath = Path.ChangeExtension(Path.Combine(dir, entry.FileName), TranslationSTSCHandler.FileTypes[index].TypeExtension);
                    // Skip script if file does not exist
                    if (!File.Exists(filepath))
                    {
                        continue;
                    }
                    // Import translation
                    TranslationSTSCHandler.ImportTranslation(index, script, File.ReadAllText(filepath), !tag.Contains("nokey"));
                    // Save the script back into the archive
                    using (var stream = new MemoryStream())
                    {
                        script.Save(stream);
                        ScriptArchive.ReplaceFile(entry.FileName, stream.ToArray());
                    }
                }
            }
            // Reload the current script
            if (ScriptListBox.SelectedIndex == -1)
            {
                return;
            }
            LoadScript(ScriptArchive.FileEntries[ScriptListBox.SelectedIndex].FileName);
        }
Пример #6
0
        private void ExportTranslationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (ScriptListBox.SelectedIndex == -1)
            {
                return;
            }
            var file = ScriptArchive.FileEntries[ScriptListBox.SelectedIndex];
            var sfd  = new SaveFileDialog
            {
                Filter   = GenerateFilters(false),
                FileName = Path.GetFileNameWithoutExtension(file.FileName)
            };

            if (sfd.ShowDialog() == true)
            {
                // Gets the index of the filetype
                int index  = TranslationSTSCHandler.FileTypes.ToList().FindIndex(t => sfd.FileName.Contains(t.TypeExtension));
                var script = new STSCFile();
                using (var stream = ScriptArchive.GetFileStream(file.FileName))
                    script.Load(stream);
                File.WriteAllText(sfd.FileName, TranslationSTSCHandler.ExportTranslation(index, script, ScriptDB, App.StringProcess), new UTF8Encoding(true));
            }
        }
Пример #7
0
        private void ImportTranslationMenuItem_Click(object sender, RoutedEventArgs e)
        {
            string tag = ((MenuItem)sender)?.Tag as string;

            if (ScriptListBox.SelectedIndex == -1)
            {
                return;
            }
            var file = ScriptArchive.FileEntries[ScriptListBox.SelectedIndex];
            var ofd  = new OpenFileDialog
            {
                Filter = GenerateFilters(true)
            };

            if (ofd.ShowDialog() == true)
            {
                // Gets the index of the filetype
                int index = TranslationSTSCHandler.FileTypes.ToList().FindIndex(t => ofd.FileName.Contains(t.TypeExtension));
                // if importer is not found
                if (index == -1)
                {
                    MessageBox.Show("Could not detect the file type!", "Import Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                // TODO: Add key option
                // Import translation
                TranslationSTSCHandler.ImportTranslation(index, ScriptFile, File.ReadAllText(ofd.FileName), !tag.Contains("nokey"));
                // Save the script back into the archive
                using (var stream = new MemoryStream())
                {
                    ScriptFile.ConvertToDialogueCode();
                    ScriptFile.Save(stream);
                    ScriptArchive.ReplaceFile(file.FileName, stream.ToArray());
                }
            }
        }