Esempio n. 1
0
        public static bool ClearMutex(int ProID, string MutexName)
        {
            bool success = false;

            if (HandleManager.KillHandle(Process.GetProcessById(ProID), MutexName, false))
            {
                success = true;
            }


            return(success);
        }
Esempio n. 2
0
        /// <summary>
        /// Kills named mutex in active process.
        /// </summary>
        /// <param name="Proc">Full path to process file to unlock from</param>
        /// <param name="MutexName">Full name of mutex to be removed</param>
        /// <param name="excProcIDs">Process ID's to exclude</param>
        /// <returns></returns>
        public static bool ClearMutex(string ProcName, string MutexName, ref List <int> excProcIDs)
        {
            bool success = false;
            var  excList = excProcIDs == null ? new List <int>() : excProcIDs.ToList();

            //get list of currently running system processes
            Process[] processList = Process.GetProcesses();

            foreach (Process i in processList.Where(a => !excList.Contains(a.Id)).Where(a => a.ProcessName.Equals(ProcName, StringComparison.OrdinalIgnoreCase)))
            {
                if (HandleManager.KillHandle(i, MutexName, false))
                {
                    success = true;
                    excProcIDs.Add(i.Id);
                }
            }

            return(success);
        }
Esempio n. 3
0
        /// <summary>
        /// Clears file locks on the specified file, from specified process.
        /// </summary>
        /// <param name="Proc">Full path to process file to unlock from</param>
        /// <param name="File">Full path to file to be unlocked</param>
        /// <param name="excProcIDs">Process ID's to exclude</param>
        /// <returns></returns>
        public static bool ClearFileLock(string ProcName, string File, ref List <int> excProcIDs)
        {
            bool success = false;
            var  excList = excProcIDs == null ? new List <int>() : excProcIDs.ToList();

            //take off the drive portion due to limitation in how killhandle works for file name
            File = File.Substring(2);

            //get list of currently running system processes
            Process[] processList = Process.GetProcesses();

            foreach (Process i in processList.Where(a => !excList.Contains(a.Id)).Where(a => a.ProcessName.Equals(ProcName, StringComparison.OrdinalIgnoreCase)))
            {
                if (HandleManager.KillHandle(i, File, true))
                {
                    success = true;
                    excProcIDs.Add(i.Id);
                }
            }

            return(success);
        }
Esempio n. 4
0
        /// <summary>
        /// Clears file locks on the specified dat file, from specified process.
        /// </summary>
        /// <param name="Proc">Full path to process file to unlock from</param>
        /// <param name="Dat">Full path to dat file to be unlocked</param>
        /// <param name="excProcIDs">Process ID's to exclude</param>
        /// <returns></returns>
        public static bool ClearDatLock(string Proc, string Dat, ref List <int> excProcIDs)
        {
            bool success = false;
            var  excList = excProcIDs == null ? new List <int>() : excProcIDs.ToList();

            //take off the drive portion due to limitation in how killhandle works for file name
            Dat = Dat.Substring(2);

            //get list of currently running system processes
            Process[] processList = Process.GetProcesses();

            foreach (Process i in processList.Where(a => !excList.Contains(a.Id)).Where(a => a.ProcessName.Equals(Regex.Replace(Proc, @"\.exe(?=[^.]*$)", "", RegexOptions.IgnoreCase), StringComparison.OrdinalIgnoreCase)))
            {
                if (HandleManager.KillHandle(i, Dat, true))
                {
                    success = true;
                    excProcIDs.Add(i.Id);
                }
            }

            return(success);
        }
Esempio n. 5
0
 static async Task launchgw2(int?accnr = null, int delay = 0)
 {
     try
     {
         if (delay > 0)
         {
             await Task.Delay(delay);
         }
         ProcessStartInfo gw2proinfo = new ProcessStartInfo();
         gw2proinfo.FileName         = Globals.exepath + Globals.exename;
         gw2proinfo.Arguments        = Globals.args.Print(accnr);
         gw2proinfo.WorkingDirectory = Globals.exepath;
         Process gw2pro = new Process {
             StartInfo = gw2proinfo
         };
         if (accnr != null)
         {
             Globals.LinkedAccs.Add(new ProAccBinding(gw2pro, Globals.selected_accs[(int)accnr]));
             GFXManager.UseGFX(Globals.selected_accs[(int)accnr].Configpath);
         }
         else
         {
             MainWindow.Account undefacc = new MainWindow.Account {
                 Email = "-", Nick = "Acc Nr" + Globals.LinkedAccs.Count
             };
             Globals.LinkedAccs.Add(new ProAccBinding(gw2pro, undefacc));
         }
         try
         {
             gw2pro.Start();
         }
         catch (Exception err) // logged
         {
             Log.Error($"Unable to launch GW2. Process info: (Filename:{gw2pro.StartInfo.FileName}|Working Directory:{gw2pro.StartInfo.WorkingDirectory}). Arguments not logged for security reasons.", err);
             MessageBox.Show($"Guild Wars 2 does not seem to be working. Maybe the path is wrong?\nMore technical information:\n{err}");
             throw;
         }
         var mutexName       = "AN-Mutex-Window-Guild Wars 2";
         var exProcIDsString =
             nomutexpros == null
             ? string.Empty
             : string.Join(",", nomutexpros.Select(id => id.ToString().ToArray()));
         var processStartInfoString = $"(Proc:{Globals.exename}|Mutex name:{mutexName}|excProcIDs:{exProcIDsString})";
         try
         {
             HandleManager.ClearMutex(Globals.exename, mutexName, ref nomutexpros);
         }
         catch (Exception err) // logged
         {
             Log.Error($"Unable to clear Mutex. {processStartInfoString}", err);
             MessageBox.Show($"Something went wrong while we tried to trick GW2 into allowing a second instance. Bummer.\nMore technical information:\n{err}");
             throw;
         }
         try
         {
             gw2pro.WaitForInputIdle(10000);
         }
         catch (Exception err) // logged
         {
             Log.Error($"Error while waiting for idle input from GW2 process.", err);
             MessageBox.Show($"Guild Wars 2 seems to be stuck. Are you on a very old computer?\nMore technical information:\n{err}");
             throw;
         }
         string processMD5String = null;
         try
         {
             processMD5String = procMD5(gw2pro);
         }
         catch (Exception e) // logged
         {
             Log.Error($"Unable to get process MD5. Process Start Info: {processStartInfoString}", e);
             MessageBox.Show($"Something went wrong trying to get more info from the GW2 process. What is happening, dude?\nMore technical information:\n{e}");
             throw;
         }
         try
         {
             //Register the new client to prevent problems.
             updateRegClients(procMD5(gw2pro));
         }
         catch (Exception err) // logged
         {
             Log.Error($"Unable to register the new client. Process MD5: {processMD5String}", err);
             MessageBox.Show($"Something went sideways while we were trying to prevent future issues. Isn't that ironic?\nMore technical information:\n{err}");
             throw;
         }
         Thread.Sleep(3000);
         if (Properties.Settings.Default.use_reshade)
         {
             var reshadeUnlockerProcess   = GetReshadeUnlockerProcess();
             var reshadeUnlockerStartInfo = $"(Filename:{reshadeUnlockerProcess.FileName}|Working Directory:{reshadeUnlockerProcess.WorkingDirectory})";
             try
             {
                 Process.Start(reshadeUnlockerProcess);
             }
             catch (Exception err) // logged
             {
                 Log.Error($"Unable to register the new client. Process MD5: {processMD5String}", err);
                 MessageBox.Show($"Reshade Unlocker does not seem to be working. Maybe the path is wrong?\nMore technical information:\n{err}");
                 throw;
             }
         }
     }
     catch // logged
     {
         MessageBox.Show("Something went wrong trying to launch Gw2. See log file for more information.");
     }
 }
Esempio n. 6
0
        static void launchgw2(int?accnr = null)
        {
            try
            {
                ProcessStartInfo gw2proinfo = new ProcessStartInfo();
                gw2proinfo.FileName         = Globals.exepath + Globals.exename;
                gw2proinfo.Arguments        = Globals.args.Print(accnr);
                gw2proinfo.WorkingDirectory = Globals.exepath;
                Process gw2pro = new Process {
                    StartInfo = gw2proinfo
                };
                if (accnr != null)
                {
                    Globals.LinkedAccs.Add(new ProAccBinding(gw2pro, Globals.selected_accs[(int)accnr]));
                    GFXManager.UseGFX(Globals.selected_accs[(int)accnr].Configpath);
                }
                else
                {
                    MainWindow.Account undefacc = new MainWindow.Account {
                        Email = "-", Nick = "Acc Nr" + Globals.LinkedAccs.Count
                    };
                    Globals.LinkedAccs.Add(new ProAccBinding(gw2pro, undefacc));
                }

                try
                {
                    gw2pro.Start();
                }
                catch (Exception err)
                {
                    System.Windows.MessageBox.Show("Could not launch Gw2. Invalid path?\n" + err.Message);
                }
                try
                {
                    HandleManager.ClearMutex(Globals.exename, "AN-Mutex-Window-Guild Wars 2", ref nomutexpros);
                    gw2pro.WaitForInputIdle(10000);
                    //Thread.Sleep(1000);
                    //Register the new client to prevent problems.
                    updateRegClients(procMD5(gw2pro));
                    Thread.Sleep(3000);
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message);
                }

                if (Properties.Settings.Default.use_reshade)
                {
                    try
                    {
                        ProcessStartInfo unlockerpro = new ProcessStartInfo();
                        unlockerpro.FileName         = Globals.unlockerpath;
                        unlockerpro.WorkingDirectory = Path.GetDirectoryName(Globals.unlockerpath);
                        Process.Start(unlockerpro);
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show("Could not launch ReshadeUnlocker. Invalid path?\n" + err.Message);
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }