public void LoadFile(string stxFilePath)
        {
            StxFile stx = new StxFile();

            stx.Load(stxFilePath);
            StxPath = stxFilePath;

            Strings = new ObservableCollection <string>(stx.StringTables[0].Strings);
            StringListBox.ItemsSource = Strings;
        }
Beispiel #2
0
 private void SettingEditorResetAllInputControls()
 {
     StxBoolean.Value  = false;
     StxDatetime.Value = DateTime.Today;
     StxFile.Clear();
     StxFolder.Clear();
     StxLongInteger.Clear();
     StxPassword.Clear();
     StxText.Clear();
     StxFont.Clear();
     StxColor.Clear();
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("STX Tool by CaptainSwag101\n" +
                              "Version 0.0.1, built on 2019-10-14\n");

            if (args.Length == 0)
            {
                Console.WriteLine("ERROR: No targets specified.");
                return;
            }

            foreach (string arg in args)
            {
                FileInfo info = new FileInfo(arg);
                if (!info.Exists)
                {
                    Console.WriteLine($"ERROR: File \"{arg}\" does not exist, skipping.");
                    continue;
                }

                if (info.Extension.ToLowerInvariant() == ".stx")
                {
                    // Convert STX to TXT
                    StxFile stx = new StxFile();
                    stx.Load(info.FullName);

                    using StreamWriter writer = new StreamWriter(info.FullName.Replace(info.Extension, "") + ".txt", false);
                    foreach (var tuple in stx.StringTables)
                    {
                        writer.WriteLine("{");

                        foreach (string str in tuple.Item1)
                        {
                            writer.WriteLine(str.Replace("\r", @"\r").Replace("\n", @"\n"));
                        }

                        writer.WriteLine("}");
                    }
                }
                else if (info.Extension.ToLowerInvariant() == ".txt")
                {
                    // Convert TXT to STX
                    StxFile stx = new StxFile();

                    using StreamReader reader = new StreamReader(info.FullName);
                    while (!reader.EndOfStream)
                    {
                        if (reader.ReadLine().StartsWith('{'))
                        {
                            List <string> table = new List <string>();

                            while (true)
                            {
                                string line = reader.ReadLine();
                                if (string.IsNullOrEmpty(line))
                                {
                                    continue;
                                }

                                if (line.StartsWith('}'))
                                {
                                    break;
                                }

                                table.Add(line.Replace(@"\n", "\n").Replace(@"\r", "\r"));
                            }

                            stx.StringTables.Add((table, 8));
                        }
                    }

                    stx.Save(info.FullName.Replace(info.Extension, "") + ".stx");
                }
                else
                {
                    Console.WriteLine($"ERROR: Invalid file extension \"{info.Extension}\".");
                    continue;
                }
            }
        }
Beispiel #4
0
        private void OpenScriptMenuItem_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "WRD script files (*.wrd)|*.wrd|All files (*.*)|*.*";
            if (!(openFileDialog.ShowDialog() ?? false))
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(openFileDialog.FileName))
            {
                MessageBox.Show("ERROR: Specified file name is empty or null.");
                return;
            }

            loadedWrd = new WrdFile();
            loadedWrd.Load(openFileDialog.FileName);
            loadedWrdLocation = openFileDialog.FileName;

            statusText.Text = $"Loaded WRD file: {new FileInfo(openFileDialog.FileName).Name}";

            // Clear the StackPanel of old entries
            wrdCommandTextBox.Text = string.Empty;

            // Generate a string for every command in the WRD
            StringBuilder sb = new StringBuilder();

            foreach (WrdCommand command in loadedWrd.Commands)
            {
                sb.Append(command.Opcode);
                sb.Append('|');
                sb.AppendJoin(", ", command.Arguments);
                sb.Append('\n');
            }
            wrdCommandTextBox.Text = sb.ToString();

            // Check if we need to prompt the user to open an external STX file for strings
            wrdStringsTextBox.Text = string.Empty;
            if (loadedWrd.UsesExternalStrings)
            {
                if (MessageBox.Show("The WRD file references external string data, load an STX file?", "Load external strings", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    OpenFileDialog openStxDialog = new OpenFileDialog();
                    openStxDialog.Filter = "STX text files (*.stx)|*.stx|All files (*.*)|*.*";

                    if (!(openStxDialog.ShowDialog() ?? false))
                    {
                        return;
                    }

                    if (string.IsNullOrWhiteSpace(openStxDialog.FileName))
                    {
                        MessageBox.Show("ERROR: Specified file name is empty or null.");
                        return;
                    }

                    StxFile stx = new StxFile();
                    stx.Load(openStxDialog.FileName);
                    loadedStxLocation = openStxDialog.FileName;

                    foreach (string str in stx.StringTables.First().Strings)
                    {
                        wrdStringsTextBox.Text += str.Replace("\n", "\\n").Replace("\r", "\\r") + '\n';
                    }
                }
            }
            else
            {
                foreach (string str in loadedWrd.InternalStrings)
                {
                    wrdStringsTextBox.Text += str.Replace("\n", "\\n").Replace("\r", "\\r") + '\n';
                }
            }
        }