private uint CreateNewProcess(bool attached, Scheduler wanted, uint newPID) { if (!attached) { try { try { if (Directory.Exists(wanted.BotPath) && File.Exists(wanted.BotPath + "\\GW2MinionLauncherDLL.dll")) SetDllDirectory(wanted.BotPath); Logger.LoggingObject.Log(Level.Verbose, "Launching instance for {0} with {1}.", LoginName, wanted.BotPath + "\\GW2MinionLauncherDLL.dll"); newPID = LaunchAccount(Config.Singleton.GeneralSettings.GW2Path, LoginName, Password, NoSound); } catch (AccessViolationException ex) { Logger.LoggingObject.Log(Level.Critical, ex.Message); } wanted.SetLastStartTime(DateTime.Now); wanted.SetShouldBeRunning(true); } catch (DllNotFoundException ex) { Logger.LoggingObject.Log(Level.Error, ex.Message); } catch (BadImageFormatException ex) { Logger.LoggingObject.Log(Level.Error, ex.Message); } } return newPID; }
private bool CheckIfProcessAlreadyExists(Process[] gw2, Scheduler wanted, bool attached, ref uint newPID) { foreach (Process p in gw2) { if (GetAccountName((uint) p.Id) == LoginName) { Logger.LoggingObject.Log(Level.Verbose, "Found wanted process for {0}, no need to launch.", LoginName); try { Logger.LoggingObject.Log(Level.Verbose, "Attaching to {0} with {1}.", LoginName, wanted.BotPath + "\\GW2MinionLauncherDLL.dll"); if (Directory.Exists(wanted.BotPath) && File.Exists(wanted.BotPath + "\\GW2MinionLauncherDLL.dll")) SetDllDirectory(wanted.BotPath); attached = Attach((uint) p.Id); } catch (AccessViolationException ex) { Logger.LoggingObject.Log(Level.Critical, ex.Message); } newPID = (uint) p.Id; wanted.SetLastStartTime(DateTime.Now); wanted.SetShouldBeRunning(true); } } return attached; }