private static int RunApplyModScript(ApplyScriptOptions opts) { if (!Directory.Exists(opts.InputDirectory)) { throw new Exception($"Non-existent input directory: {opts.InputDirectory}"); } if (!Directory.Exists(opts.OutputDirectory)) { Directory.CreateDirectory(opts.OutputDirectory); } if (string.IsNullOrEmpty(opts.ModScriptPath)) { throw new Exception("Missing modscript path!"); } var profile = ResolveProfile(opts.ProfileName); if (profile == null) { Console.WriteLine("ERROR: Unknown profile {0}", opts.ProfileName); Console.WriteLine("AVAILABLE PROFILES:"); foreach (var baseProfile in Profiles) { Console.WriteLine("\tNAME: {0}", baseProfile.GetName()); } return(1); } var database = new Database(new DatabaseOptions(profile.GetGame(), profile.GetDatabaseType())); var deserializer = new DatabaseDeserializer(database, opts.InputDirectory); var stopwatch = Stopwatch.StartNew(); var loadedDatabase = deserializer.Deserialize(); stopwatch.Stop(); Console.WriteLine("Loaded database from {2} in {0}ms ({1:f2}s)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f, opts.InputDirectory); stopwatch.Restart(); var modScriptParser = new ModScriptParser(opts.ModScriptPath); var cmdStopwatch = Stopwatch.StartNew(); var modScriptDatabase = new ModScriptDatabaseHelper(database); var commandCount = 0; foreach (var command in modScriptParser.Parse()) { #if !DEBUG try { #endif cmdStopwatch.Restart(); command.Execute(modScriptDatabase); commandCount++; //Console.WriteLine("Executed command in {1}ms: {0}", command.Line, cmdStopwatch.ElapsedMilliseconds); #if !DEBUG } catch (Exception e) { throw new ModScriptCommandExecutionException($"Failed to execute command: {command.Line}", e); } #endif } stopwatch.Stop(); var commandsPerSecond = commandCount / (stopwatch.ElapsedMilliseconds / 1000.0f); Console.WriteLine("Applied script from {2} in {0}ms ({1:f2}s) ({4} commands @ ~{3:f2} commands/sec)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f, opts.ModScriptPath, commandsPerSecond, commandCount); if (opts.MakeBackup) { stopwatch.Restart(); Console.WriteLine("Making backup"); Directory.Move(opts.InputDirectory, $"{opts.InputDirectory.TrimEnd('/', '\\')}_{DateTimeOffset.Now.ToUnixTimeSeconds()}"); Directory.CreateDirectory(opts.InputDirectory); stopwatch.Stop(); Console.WriteLine("Made backup in {0}ms ({1:f2}s)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f); } stopwatch.Restart(); new DatabaseSerializer(database, opts.InputDirectory).Serialize(loadedDatabase.Files); //deserializer.GenerateFiles(profile, args.OutputDirectory); stopwatch.Stop(); Console.WriteLine("Exported YML files to {2} in {0}ms ({1:f2}s)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f, opts.InputDirectory); if (opts.GenerateBins) { stopwatch.Restart(); deserializer.GenerateFiles(profile, opts.OutputDirectory); stopwatch.Stop(); Console.WriteLine("Exported VLT files to {2} in {0}ms ({1:f2}s)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f, opts.OutputDirectory); } return(0); }
private static void RunApplyModScript(ProgramArgs args, BaseProfile profile) { if (string.IsNullOrEmpty(args.ModScriptPath)) { throw new Exception("Missing modscript path!"); } var database = new Database(new DatabaseOptions(profile.GetGame(), profile.GetDatabaseType())); var deserializer = new DatabaseDeserializer(database, args.InputDirectory); Stopwatch stopwatch = Stopwatch.StartNew(); var loadedDatabase = deserializer.Deserialize(); stopwatch.Stop(); Console.WriteLine("Loaded database from {2} in {0}ms ({1:f2}s)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f, args.InputDirectory); stopwatch.Restart(); var modScriptParser = new ModScriptParser(args.ModScriptPath); var cmdStopwatch = Stopwatch.StartNew(); var modScriptDatabase = new ModScriptDatabaseHelper(database); int commandCount = 0; foreach (var command in modScriptParser.Parse()) { #if !DEBUG try { #endif cmdStopwatch.Restart(); command.Execute(modScriptDatabase); commandCount++; //Console.WriteLine("Executed command in {1}ms: {0}", command.Line, cmdStopwatch.ElapsedMilliseconds); #if !DEBUG } catch (Exception e) { throw new ModScriptCommandExecutionException($"Failed to execute command: {command.Line}", e); } #endif } stopwatch.Stop(); float commandsPerSecond = commandCount / (stopwatch.ElapsedMilliseconds / 1000.0f); Console.WriteLine("Applied script from {2} in {0}ms ({1:f2}s) ({4} commands @ ~{3:f2} commands/sec)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f, args.ModScriptPath, commandsPerSecond, commandCount); stopwatch.Restart(); Console.WriteLine("Making backup"); Directory.Move(args.InputDirectory, $"{args.InputDirectory.TrimEnd('/', '\\')}_{DateTimeOffset.Now.ToUnixTimeSeconds()}"); Directory.CreateDirectory(args.InputDirectory); stopwatch.Stop(); Console.WriteLine("Made backup in {0}ms ({1:f2}s)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f); stopwatch.Restart(); new DatabaseSerializer(database, args.InputDirectory).Serialize(loadedDatabase.Files); //deserializer.GenerateFiles(profile, args.OutputDirectory); stopwatch.Stop(); Console.WriteLine("Exported YML files to {2} in {0}ms ({1:f2}s)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f, args.InputDirectory); stopwatch.Restart(); deserializer.GenerateFiles(profile, args.OutputDirectory); stopwatch.Stop(); Console.WriteLine("Exported VLT files to {2} in {0}ms ({1:f2}s)", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedMilliseconds / 1000f, args.OutputDirectory); }