void FirstCompile(string path) { Logger.Log("first compile: " + path); var dir = new DirectoryInfo(path); var list = dir.GetFiles("*.cs", SearchOption.AllDirectories).ToList(); foreach (var file in list) { string filePath = file.FullName; var project = CompilationManager.GetProjectFromFile(filePath); // skip because already compiled if (project == null) { var assembly = TryCompile(filePath); if (assembly != null) { RefreshAssembly(filePath, assembly); } else { Logger.Log("first compile error: " + file.FullName); } } } }
void FirstCompile(string path) { Logger.Log("first compile: " + path); var dir = new DirectoryInfo(path); var list = dir.GetFiles("*.cs", SearchOption.AllDirectories).ToList(); List <Tuple <string, Assembly> > assemblies = new(); foreach (var file in list) { string filePath = file.FullName; var project = CompilationManager.GetProjectFromFile(filePath); // skip because already compiled if (project == null) { var assembly = TryCompile(filePath); if (assembly != null) { assemblies.Add(new Tuple <string, Assembly>(filePath, assembly)); //RefreshAssembly(filePath, assembly); } else { Logger.Log("first compile error: " + file.FullName); Logger.Log(""); } } } assemblies.ForEach((tuple) => RefreshAssembly(tuple.Item1, tuple.Item2)); }
private Assembly TryCompile(string path) { try { return(CompilationManager.Compile(path)); } catch (Exception e) { Logger.LogError("compile error!"); Logger.PrintException(e); return(null); } }
internal void Init(string workDir) { FileStream logFileStream = new FileStream(Path.Combine(workDir, "patcher.log"), FileMode.Create, FileAccess.ReadWrite, FileShare.Read); var logFileWriter = new StreamWriter(logFileStream); Logger.WriteLine += (string str) => { logFileWriter.WriteLine(str); logFileWriter.Flush(); }; ExceptionHandler += (object sender, UnhandledExceptionEventArgs args) => { if (args != null) { Logger.PrintException(args.ExceptionObject as Exception); } }; ExceptionHandler += (object sender, UnhandledExceptionEventArgs args) => { string dir = Path.Combine(workDir, "ErrorLogs"); Directory.CreateDirectory(dir); DateTime date = DateTime.Now; File.Copy(logFileStream.Name, Path.Combine(dir, string.Format("ErrorLog_{0}_{1}_{2}_{3}_{4}.log", date.Year, date.Month, date.Day, date.Hour, date.Minute)), true); System.Windows.Forms.MessageBox.Show("ErrorLog Created", "Dynamic Patcher"); }; try { using StreamReader file = File.OpenText(Path.Combine(workDir, "dynamicpatcher.config.json")); using JsonTextReader reader = new JsonTextReader(file); var json = JObject.Load(reader); if (json["hide_console"].ToObject <bool>()) { FreeConsole(); Logger.WriteLine -= ConsoleWriteLine; } if (json["show_attach_window"].ToObject <bool>()) { System.Windows.Forms.MessageBox.Show("Attach Me", "Dynamic Patcher"); } if (json["try_catch_callable"].ToObject <bool>()) { HookInfo.TryCatchCallable = true; } Logger.Log("try-catch callable: " + HookInfo.TryCatchCallable); if (json["force_gc_collect"].ToObject <bool>()) { Task.Run(() => { while (true) { Logger.Log("Sleep 10s."); Thread.Sleep(TimeSpan.FromSeconds(10)); Logger.Log("GC collect."); GC.Collect(); GC.WaitForPendingFinalizers(); GC.WaitForFullGCComplete(); Logger.Log("GC collect finish."); } }); } CompilationManager = new CompilationManager(workDir); codeWatcher = new CodeWatcher(workDir); codeWatcher.FirstAction += FirstCompile; codeWatcher.OnCodeChanged += OnCodeChanged; } catch (Exception e) { Logger.PrintException(e); } }