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));
                }
            }
        }
 private void SaveButton_Click(object sender, RoutedEventArgs e)
 {
     // Save the current script
     SaveScript();
     // Saves all the files onto disk
     ScriptArchive.Save(App.ScriptPath);
 }
        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);
        }
 public void SaveScript()
 {
     if (ScriptFile != null)
     {
         using (var stream = new MemoryStream())
         {
             // Builds the script file and saves it to the stream
             ScriptFile.Save(stream);
             // Replaces the file that was in the archive with the newly built script
             ScriptArchive.ReplaceFile(_config.LastOpenedScript, stream.ToArray());
         }
         ScriptEdited = false;
     }
 }
        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);
                }
            }
        }
 public void LoadScript(string scriptName, bool save = true)
 {
     if (ScriptEdited && save)
     {
         SaveScript();
     }
     // Load script file
     ScriptFile = new STSCFileDialogue(ScriptDB, App.WorkingGame);
     ScriptFile.Load(ScriptArchive.GetFileStream(scriptName));
     // Write the script path to the config
     _config.LastOpenedScript = scriptName;
     // Mark script as not edited
     ScriptEdited = false;
     // Update the title to reflect the new loaded file
     UpdateTitle();
 }
        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);
            }
        }
示例#8
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);
        }
        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));
            }
        }
示例#10
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());
                }
            }
        }