} //partial enum, actual set is huge, google SYSTEM_INFORMATION_CLASS #endregion #region Functions /// <summary> /// Clears file locks on the GW_DAT file located at basePath. /// </summary> /// <param name="basePath">Full patch to gw.dat file</param> /// <returns></returns> public static bool ClearDatLock(string basePath) { bool success = false; //take off the drive portion due to limitation in how killhandle works for file name string root = Directory.GetDirectoryRoot(basePath).Substring(0, 2); basePath = basePath.Replace(root, string.Empty); string fileToUnlock = basePath + "\\" + Program.GW_DAT; //get list of currently running system processes Process[] processList = Process.GetProcesses(); foreach (Process i in processList) { //filter for guild wars ones if (i.ProcessName.Equals(Program.GW_PROCESS_NAME, StringComparison.OrdinalIgnoreCase)) { if (HandleManager.KillHandle(i, fileToUnlock, true)) { success = true; } } } return(success); }
public static bool LaunchGame(string gwPath, string gwArgs) { //check if the install exists if (!File.Exists(gwPath)) { MessageBox.Show("The path: " + gwPath + " does not exist!"); return(false); } else { bool forced = false; //bool forced = forceUnlockCheckBox.CheckBoxControl.Checked; if (forced) { HandleManager.ClearDatLock(Directory.GetParent(gwPath).FullName); } //attempt to launch var started = LaunchGame(gwPath, gwArgs, forced); if (started) { //give time for gw to read path before it gets changed again. System.Threading.Thread.Sleep(Program.settings.RegistryCooldown); } return(started); } }
public static bool LaunchGame(string gwPath, string args, bool forced) { bool success = false; if (!forced) { //check to see if this copy is already started if (IsCopyRunning(gwPath)) { MessageBox.Show(gwPath + " is already running, please launch a different copy.", Program.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return(success); } } do { Process gw = new Process(); gw.StartInfo.FileName = gwPath; gw.StartInfo.Arguments = args; gw.StartInfo.WorkingDirectory = Directory.GetParent(gwPath).FullName; gw.StartInfo.UseShellExecute = true; gw.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; try { //set new gw path RegistryManager.SetGWRegPath(gwPath); //clear mutex to allow for another gw launch HandleManager.ClearMutex(); //attempt to start gw process gw.Start(); Thread.Sleep(10000); success = true; } catch (Exception e) { success = false; gw.Kill(); Thread.Sleep(3000); //MessageBox.Show("Error launching: " + gwPath + "!\n" + e.Message, // Program.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } }while (!success); return(success); }
/// <summary> /// Kills GW mutex is active processes. /// </summary> /// <returns></returns> public static bool ClearMutex() { bool success = false; //get list of currently running system processes ICollection <Process> processList = Process.GetProcesses().Where(x => x.ProcessName.Equals(Program.GW_PROCESS_NAME, StringComparison.OrdinalIgnoreCase)).ToList(); foreach (Process i in processList) { //filter for guild wars ones if (HandleManager.KillHandle(i, Program.MUTEX_MATCH_STRING, false)) { success = true; } } return(success); }