private static void PerformPluginReload(ref WorkerInterface workInterface, ref bool fullRestart) { Stream strScene; Stream strData; string tempDir = Path.Combine(Path.GetTempPath(), "Duality"); string tempScenePath = Path.Combine(tempDir, "ReloadPluginBackup" + Scene.FileExt); string tempDataPath = Path.Combine(tempDir, "ReloadPluginBackup.dat"); if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); } if (!workInterface.RecoverMode) { // No full restart scheduled? Well, check if it should be! if (!fullRestart) { fullRestart = workInterface.ReloadSched.Any(asmFile => asmFile.EndsWith(".editor.dll", StringComparison.InvariantCultureIgnoreCase) || !DualityApp.IsLeafPlugin(asmFile)); } if (fullRestart) { strScene = File.Create(tempScenePath); strData = File.Create(tempDataPath); } else { strScene = new MemoryStream(1024 * 1024 * 10); strData = new MemoryStream(512); } // Save current data Log.Editor.Write("Saving data..."); StreamWriter strDataWriter = new StreamWriter(strData); strDataWriter.WriteLine(Scene.CurrentPath); strDataWriter.Flush(); workInterface.MainForm.Invoke((Action) delegate() { // Save all data DualityEditorApp.SaveAllProjectData(); Scene.Current.Save(strScene); }); workInterface.Progress += 0.4f; Thread.Sleep(20); if (!fullRestart) { // Reload core plugins Log.Editor.Write("Reloading core plugins..."); Log.Editor.PushIndent(); int count = workInterface.ReloadSched.Count; while (workInterface.ReloadSched.Count > 0) { string curPath = workInterface.ReloadSched[0]; workInterface.MainForm.Invoke((Action <string>)DualityApp.ReloadPlugin, curPath); workInterface.Progress += 0.15f / (float)count; Thread.Sleep(20); string xmlDocFile = curPath.Replace(".dll", ".xml"); if (File.Exists(xmlDocFile)) { workInterface.MainForm.Invoke((Action <string>)HelpSystem.LoadXmlCodeDoc, xmlDocFile); } workInterface.ReloadSched.RemoveAt(0); workInterface.ReloadDone.Add(curPath); workInterface.Progress += 0.05f / (float)count; } Log.Editor.PopIndent(); strScene.Seek(0, SeekOrigin.Begin); strData.Seek(0, SeekOrigin.Begin); } else { strScene.Close(); strData.Close(); bool debug = System.Diagnostics.Debugger.IsAttached; // Close old form and wait for it to be closed workInterface.Shutdown = true; workInterface.MainForm.Invoke(new CloseMainFormDelegate(CloseMainForm), workInterface.MainForm); while (workInterface.MainForm.Visible) { Thread.Sleep(20); } Process newEditor = Process.Start(Application.ExecutablePath, "recover" + (debug ? " debug" : "")); return; } } else { strScene = File.OpenRead(tempScenePath); strData = File.OpenRead(tempDataPath); workInterface.Progress = 0.6f; } // Reload data Log.Editor.Write("Restoring data..."); StreamReader strDataReader = new StreamReader(strData); string scenePath = strDataReader.ReadLine(); workInterface.TempScene = Resource.Load <Scene>(strScene, scenePath); if (!workInterface.TempScene.IsRuntimeResource) { // Register the reloaded Scene in the ContentProvider, if it wasn't just a temporary one. ContentProvider.AddContent(scenePath, workInterface.TempScene); } strScene.Close(); strData.Close(); workInterface.Progress = 1.0f; workInterface.Finished = true; }