public static void Main(string[] args) { if (Environment.CurrentDirectory != Application.StartupPath) { Environment.CurrentDirectory = Application.StartupPath; } Console.WriteLine("Creating loader."); m_RunMutex = new Mutex(true, "NZB-O-Matic Mutex"); if (!m_RunMutex.WaitOne(0, false)) { Console.WriteLine("Instance of NZB-O-Matic already running!"); CopyData cd = new CopyData(); cd.Channels.Add("NZBImport"); foreach (string str in args) { if (str.EndsWith(".nzb")) { cd.Channels["NZBImport"].Send(str); } } cd.Channels.Remove("NZBImport"); return; } do { try { //reset variables m_Update = false; m_Restart = false; //setup appdomain AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationName = "NZB-O-MaticPlus"; setup.ApplicationBase = Environment.CurrentDirectory; setup.ShadowCopyDirectories = Environment.CurrentDirectory; setup.ShadowCopyFiles = "true"; //create appdomain m_AppDomain = AppDomain.CreateDomain("Engine Domain", null, setup); //create remoteloader in appdomain m_RemoteLoader = (RemoteLoader)m_AppDomain.CreateInstanceFromAndUnwrap(System.IO.Path.GetFileName(Application.ExecutablePath), "Loader.RemoteLoader"); //load assembly in to remoteloader m_RemoteLoader.LoadAssembly("Engine"); //create instance of engine in remoteloader m_RemoteLoader.Create(); //get name and version from engine m_Name = m_RemoteLoader.Name; m_Version = m_RemoteLoader.Version; //start engine in remoteloader m_RemoteLoader.Start(args); //get variables after engine exits m_Restart = m_RemoteLoader.Restart; m_Update = m_RemoteLoader.Update; } catch (Exception e) { Console.WriteLine(e); } if (m_Update) { frmUpdate m_UpdateForm = new frmUpdate(); Application.Run(m_UpdateForm); m_UpdateForm.Dispose(); } } while(m_Restart); Console.WriteLine("Exiting program."); }
public static void Main(string[] args) { if(Environment.CurrentDirectory != Application.StartupPath) Environment.CurrentDirectory = Application.StartupPath; Console.WriteLine("Creating loader."); m_RunMutex = new Mutex(true, "NZB-O-Matic Mutex"); if(!m_RunMutex.WaitOne(0, false)) { Console.WriteLine("Instance of NZB-O-Matic already running!"); CopyData cd = new CopyData(); cd.Channels.Add("NZBImport"); foreach(string str in args) if(str.EndsWith(".nzb")) cd.Channels["NZBImport"].Send(str); cd.Channels.Remove("NZBImport"); return; } do { try { //reset variables m_Update = false; m_Restart = false; //setup appdomain AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationName = "NZB-O-MaticPlus"; setup.ApplicationBase = Environment.CurrentDirectory; setup.ShadowCopyDirectories = Environment.CurrentDirectory; setup.ShadowCopyFiles = "true"; //create appdomain m_AppDomain = AppDomain.CreateDomain("Engine Domain", null, setup); //create remoteloader in appdomain m_RemoteLoader = (RemoteLoader)m_AppDomain.CreateInstanceFromAndUnwrap(System.IO.Path.GetFileName(Application.ExecutablePath), "Loader.RemoteLoader"); //load assembly in to remoteloader m_RemoteLoader.LoadAssembly("Engine"); //create instance of engine in remoteloader m_RemoteLoader.Create(); //get name and version from engine m_Name = m_RemoteLoader.Name; m_Version = m_RemoteLoader.Version; //start engine in remoteloader m_RemoteLoader.Start(args); //get variables after engine exits m_Restart = m_RemoteLoader.Restart; m_Update = m_RemoteLoader.Update; } catch(Exception e) { Console.WriteLine(e); } if(m_Update) { frmUpdate m_UpdateForm = new frmUpdate(); Application.Run(m_UpdateForm); m_UpdateForm.Dispose(); } } while(m_Restart); Console.WriteLine("Exiting program."); }