Exemple #1
0
        private static void CheckIfAlreadyRunning()
        {
            try
            {
                if (ProcessUtils.IsAlreadyRunning("Global\\BlueStacks_DiskCompactor_Lockbgp"))
                {
                    Logger.Info("Disk compaction is running in background");
                    foreach (string str in GetProcessExecutionPath.GetApplicationPath(Process.GetProcessesByName("DiskCompactionTool")))
                    {
                        if (str.Equals(Path.Combine(RegistryStrings.InstallDir, "DiskCompactionTool.exe"), StringComparison.InvariantCultureIgnoreCase))
                        {
                            CustomMessageWindow customMessageWindow = new CustomMessageWindow()
                            {
                                ImageName = "ProductLogo"
                            };
                            customMessageWindow.TitleTextBlock.Text = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}", (object)LocaleStrings.GetLocalizedString("STRING_EXIT_BLUESTACKS_DUE_TO_DISK_COMPACTION_HEADING", ""));
                            customMessageWindow.BodyTextBlock.Text  = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}", (object)LocaleStrings.GetLocalizedString("STRING_EXIT_BLUESTACKS_DUE_TO_DISK_COMPACTION_MESSAGE", ""));
                            customMessageWindow.AddButton(ButtonColors.Blue, "STRING_OK", (EventHandler)null, (string)null, false, (object)null, true);
                            customMessageWindow.CloseButtonHandle((Predicate <object>)null, (object)null);
                            customMessageWindow.ShowDialog();
                            Logger.Info("Disk compaction running for this instance. Exiting this instance");
                            App.ExitApplication();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to check if disk compaction is running: " + ex.Message);
            }
            string runningProcName;

            if (ProcessUtils.IsAnyInstallerProcesRunning(out runningProcName) && !string.IsNullOrEmpty(runningProcName))
            {
                Logger.Info(runningProcName + " process is running. Exiting BlueStacks MultiInstance Manager");
                Environment.Exit(-1);
            }
            if (!ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_MultiInstanceManager_Lockbgp", out App.sMultiInstanceManagerLock))
            {
                return;
            }
            Utils.BringToFront("BlueStacks Multi-Instance Manager");
            App.ExitApplication();
        }
        private static void CheckIfAlreadyRunning()
        {
            try
            {
                if (ProcessUtils.IsAlreadyRunning("Global\\BlueStacks_DiskCompactor_Lockbgp"))
                {
                    Logger.Info("Disk compaction is running in background");
                    foreach (string str in GetProcessExecutionPath.GetApplicationPath(Process.GetProcessesByName("DiskCompactionTool")))
                    {
                        if (str.Equals(Path.Combine(RegistryStrings.InstallDir, "DiskCompactionTool.exe"), StringComparison.InvariantCultureIgnoreCase))
                        {
                            CustomMessageWindow customMessageWindow = new CustomMessageWindow();
                            customMessageWindow.ImageName           = "ProductLogo";
                            customMessageWindow.TitleTextBlock.Text = LocaleStrings.GetLocalizedString("STRING_EXIT_BLUESTACKS_DUE_TO_DISK_COMPACTION_HEADING", "");
                            customMessageWindow.BodyTextBlock.Text  = LocaleStrings.GetLocalizedString("STRING_EXIT_BLUESTACKS_DUE_TO_DISK_COMPACTION_MESSAGE", "");
                            customMessageWindow.AddButton(ButtonColors.Blue, "STRING_OK", (EventHandler)null, (string)null, false, (object)null, true);
                            customMessageWindow.CloseButtonHandle((Predicate <object>)null, (object)null);
                            customMessageWindow.ShowDialog();
                            Logger.Info("Disk compaction running for this instance. Exiting this instance");
                            App.ExitApplication();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to check if disk compaction is running: " + ex.Message);
            }
            string runningProcName;

            if (!Opt.Instance.force && ProcessUtils.IsAnyInstallerProcesRunning(out runningProcName) && !string.IsNullOrEmpty(runningProcName))
            {
                Logger.Info(runningProcName + " process is running. Exiting BlueStacks");
                App.ExitApplication();
            }
            if (ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_BlueStacksUI_Lockbgp", out App.mBluestacksUILock))
            {
                try
                {
                    Logger.Info("Relaunching client for vm : " + Opt.Instance.vmname);
                    Dictionary <string, string> data = new Dictionary <string, string>()
                    {
                        {
                            "vmname",
                            Opt.Instance.vmname
                        },
                        {
                            "hidden",
                            Opt.Instance.h.ToString((IFormatProvider)CultureInfo.InvariantCulture)
                        }
                    };
                    if (Opt.Instance.launchedFromSysTray)
                    {
                        data.Add("all", "True");
                    }
                    if (!string.IsNullOrEmpty(Opt.Instance.Json))
                    {
                        data.Add("json", Opt.Instance.Json);
                        Logger.Debug("OpenPackage result: " + HTTPUtils.SendRequestToClient("openPackage", data, Opt.Instance.vmname, 0, (Dictionary <string, string>)null, false, 1, 0, "bgp"));
                    }
                    else
                    {
                        Logger.Debug("ShowWindow result: " + HTTPUtils.SendRequestToClient("showWindow", data, Opt.Instance.vmname, 0, (Dictionary <string, string>)null, false, 1, 0, "bgp"));
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex.ToString());
                }
                Logger.Info("BlueStacksUI already running. Exiting this instance");
                App.ExitApplication();
            }
            else
            {
                try
                {
                    Logger.Debug("Checking for existing process not exited");
                    List <Process> list = ((IEnumerable <Process>)Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName)).ToList <Process>();
                    if (!ProcessUtils.IsLockInUse("Global\\BlueStacks_BlueStacksUI_Closing_Lockbgp"))
                    {
                        return;
                    }
                    foreach (Process process in list)
                    {
                        if (process.Id != Process.GetCurrentProcess().Id)
                        {
                            process.Kill();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Warning("Ignoring error closing previous instances" + ex.ToString());
                }
            }
        }