private Image GetDefaultImage(Settings.AccountType type, Size sz) { var i = (int)type; if (defaultImage == null) { defaultImage = new Image[2]; } if (defaultImage[i] == null) { using (var icon = new Icon(type == Settings.AccountType.GuildWars1 ? Properties.Resources.Gw1 : Properties.Resources.Gw2, 48, 48)) { var image = defaultImage[i] = new Bitmap(sz.Width, sz.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (var g = Graphics.FromImage(image)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawIcon(icon, new Rectangle(0, 0, image.Width, image.Height)); } return(image); } } return(defaultImage[i]); }
public static IEnumerable <Settings.IAccount> GetAccounts(Settings.AccountType type) { foreach (var uid in Settings.Accounts.GetKeys()) { var a = Settings.Accounts[uid]; var account = a.Value; if (a.HasValue && account != null && a.Value.Type == type) { yield return(a.Value); } } }
/// <summary> /// Finds the process with the ID and attempts to kill the specified mutex type /// Specify a null username to run as an administrator /// </summary> /// <param name="pid"></param> /// <param name="username"></param> /// <param name="password">The password for the username or null to run as the current user</param> public static void KillMutexWindow(Settings.AccountType type, int pid, string username, System.Security.SecureString password) { string n; if (type == Settings.AccountType.GuildWars1) { n = "Guild Wars"; } else { n = "Guild Wars 2"; } var path = GetPath(); var p = new ProcessStartInfo(path, "-pu -handle -pid " + pid + " \"" + GetMutexName(type) + "\" " + (byte)Windows.Win32Handles.MatchMode.EndsWith); if (username != null) { p.UseShellExecute = false; if (password != null) { try { //other users will be using this Util.FileUtil.AllowFileAccess(path, System.Security.AccessControl.FileSystemRights.Modify); } catch (Exception ex) { Util.Logging.Log(ex); } p.UserName = username; p.LoadUserProfile = true; p.Password = password; p.WorkingDirectory = Path.GetPathRoot(path); //the user may not have access to default working directory } } else { p.UseShellExecute = true; p.Verb = "runas"; } using (var proc = Process.Start(p)) { proc.WaitForExit(); } }
public static string GetMutexName(Settings.AccountType type) { switch (type) { case Settings.AccountType.GuildWars1: return("AN-Mutex-Window-Guild Wars"); case Settings.AccountType.GuildWars2: return("AN-Mutex-Window-Guild Wars 2"); default: throw new NotSupportedException(); } }
public static bool KillMutexWindow(Settings.AccountType type, bool runAsAdmin) { return(Execute("-pu -handle -pid 0 \"" + GetMutexName(type) + "\" " + (byte)Windows.Win32Handles.MatchMode.EndsWith, runAsAdmin)); }
/// <summary> /// Scans entire system and attempts to kill the specified mutex type ("AN-Mutex-Window-Guild Wars 2" or "AN-Mutex-Window-Guild Wars") /// </summary> public static bool KillMutexWindow(Settings.AccountType type) { return(KillMutexWindow(type, true)); }
/// <summary> /// Finds all processes that match the name and attempts to kill the specified type of mutex /// Runs as an administrator /// </summary> /// <param name="name"></param> public static void KillMutexWindowByProcessName(Settings.AccountType type, string name) { Execute("-pu -handle -n \"" + name + "\" \"" + GetMutexName(type) + "\" " + (byte)Windows.Win32Handles.MatchMode.EndsWith, true); }
/// <summary> /// Finds all processes under the directory and attempts to kill the specified type of mutex /// Runs as an administrator /// </summary> /// <param name="gw2Path"></param> public static void KillMutexWindowByDirectory(Settings.AccountType type, string gw2Path) { Execute("-pu -handle -d \"" + gw2Path + "\" \"" + GetMutexName(type) + "\" " + (byte)Windows.Win32Handles.MatchMode.EndsWith, true); }