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 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); }
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); } }
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); }
static void Main(string[] args) { // Language CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US"); if (args.Length == 0) { Console.WriteLine("Error: Not Enough Arguments!"); Console.WriteLine(" STSCTool {.bin/.txt}"); Console.ReadKey(true); return; } STSCMacros.Fill(); for (int i = 0; i < args.Length; ++i) { var file = new STSCFile(); if (Path.GetExtension(args[i]) == ".bin") { try { file.Load(args[i]); }catch (STSCDisassembleException e) { Console.WriteLine("Error: {0}.", e.Message); Console.WriteLine("This usually means the Script is corrupt or one or more STSCFile's definitions are incorrect."); Console.WriteLine("or the opcode being read is not yet implemented"); Console.WriteLine("Please check the output file for finding out what instruction went wrong."); Console.WriteLine("Disassembler must abort now!"); Console.ReadKey(true); } File.WriteAllLines(Path.ChangeExtension(args[i], ".txt"), STSCTextHandler.ConvertToText(file), Encoding.UTF8); } else { STSCTextHandler.ConvertToObject(file, File.ReadAllLines(args[i], Encoding.UTF8)); file.Save(Path.ChangeExtension(args[i], ".bin")); } } }
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)); } }