Пример #1
0
        /// <summary>
        /// Processes a script file
        /// </summary>
        /// <param name="filePath"></param>
        static void ProcessScript(string filePath)
        {
            using (var reader = new BinaryReader(File.OpenRead(filePath)))
            {
                using (var script = ScriptBase.LoadScript(reader, HashTables))
                {
                    PrintVerbose(string.Format(": Processing {0} script.", script.Game));
                    var outputPath = Path.Combine(ProcessDirectory, script.Game, script.FilePath);
                    Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                    PrintVerbose(string.Format(": Outputting to {0}", outputPath));

                    if (Options.Disassemble)
                    {
                        PrintVerbose(": Disassembling script..");
                        File.WriteAllText(outputPath + ".script_asm" + Path.GetExtension(outputPath), script.Disassemble());
                    }

                    PrintVerbose(": Decompiling script..");
                    File.WriteAllText(outputPath + ".decompiled.gsc" + Path.GetExtension(outputPath), script.Decompile());
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Handles loading the script files
        /// </summary>
        private void LoadScriptFiles(string[] files)
        {
            ClearScripts();
            SetProgressCount(files.Length);

            foreach (var file in files)
            {
                SetProgressMessage("Loading " + file);
                LogIt("Loading " + file);
                // Wrap in a Try/Catch because we need control of it after
                var reader = new BinaryReader(new MemoryStream(File.ReadAllBytes(file)));

                try
                {
                    ScriptFiles.Add(ScriptBase.LoadScript(reader, HashTables));
                }
                catch (Exception e)
                {
                    reader?.Dispose();
                    LogIt("Failed to load " + file);
                    LogIt(e);
                    continue;
                }

                if (!IncrementProgress())
                {
                    // Ensure we clear whatever we have loaded
                    LogIt("Operation cancelled");
                    ClearScripts();
                    return;
                }
            }

            // Set the item source for UI
            Dispatcher.BeginInvoke(new Action(() => ScriptList.ItemsSource = ScriptFiles));
        }