Esempio n. 1
0
        private static void CheckIfAlreadyRunning(bool hideMode)
        {
            if (!ProcessUtils.CheckAlreadyRunningAndTakeLock(Strings.GetPlayerLockName(MultiInstanceStrings.VmName, "bgp"), out Program.sFrontendLock))
            {
                return;
            }
            Logger.Info("Frontend already running");
            IntPtr zero = IntPtr.Zero;

            if (!hideMode)
            {
                IntPtr front = Program.BringToFront(MultiInstanceStrings.VmName);
                if (front != IntPtr.Zero)
                {
                    Logger.Info("Sending WM_USER_SHOW_WINDOW to Frontend handle {0}", (object)front);
                    InteropWindow.SendMessage(front, 1025U, IntPtr.Zero, IntPtr.Zero);
                }
                else
                {
                    Dictionary <string, string> data = new Dictionary <string, string>();
                    try
                    {
                        Logger.Info("ShowWindow result: " + HTTPUtils.SendRequestToEngine("showWindow", data, MultiInstanceStrings.VmName, 0, (Dictionary <string, string>)null, false, 1, 0, "", "bgp"));
                    }
                    catch (Exception ex)
                    {
                        Logger.Warning("Exception in ShowWindow request failed. Err: {0}", (object)ex.Message);
                    }
                }
            }
            Environment.Exit(0);
        }
Esempio n. 2
0
        private static void CheckIfAlreadyRunning()
        {
            if (!ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_Log_Collector_Lockbgp", out App.sLogCollectorLock))
            {
                return;
            }
            bool flag = false;

            Logger.Info("LogCollector already running.");
            if (App.sOpt.Boot || App.sOpt.Apk || (App.sOpt.D || App.sOpt.Thin) || (App.sOpt.Silent || App.sOpt.Hidden))
            {
                flag = true;
            }
            if (!flag)
            {
                IntPtr window = InteropWindow.FindWindow((string)null, LocaleStrings.GetLocalizedString("STRING_BST_SUPPORT_UTILITY", ""));
                if (window != IntPtr.Zero)
                {
                    InteropWindow.SetForegroundWindow(window);
                }
                else
                {
                    CustomMessageWindow customMessageWindow = new CustomMessageWindow();
                    customMessageWindow.TitleTextBlock.Text = LocaleStrings.GetLocalizedString("STRING_BST_SUPPORT_UTILITY", "");
                    customMessageWindow.BodyTextBlock.Text  = LocaleStrings.GetLocalizedString("STRING_LOGCOLLECTOR_RUNNING", "");
                    customMessageWindow.AddButton(ButtonColors.Blue, LocaleStrings.GetLocalizedString("STRING_OK", ""), (EventHandler)null, (string)null, false, (object)null, true);
                    customMessageWindow.ShowDialog();
                }
            }
            App.KillApplication();
        }
 private static void CheckIfAlreadyRunning()
 {
     if (!ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_Uninstaller_Lockbgp", out App.sBlueStacksUninstallerLock))
     {
         return;
     }
     App.ExitApplication();
 }
Esempio n. 4
0
 private static void CheckIfAlreadyRunning()
 {
     if (!ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_Downloader_Lockbgp", out App.sDataManagerLock))
     {
         return;
     }
     Logger.Info(Process.GetCurrentProcess().ProcessName + " already running");
     App.ExitApplication();
 }
Esempio n. 5
0
 private static void CheckIfAlreadyRunning()
 {
     if (!ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_DiskCompactor_Lockbgp", out App.sDiskCompactionToolLock))
     {
         return;
     }
     Utils.BringToFront("Disk cleanup");
     Logger.Warning("Instance already running, exiting");
     App.ExitApplication(0);
 }
Esempio n. 6
0
 public static void Main(string[] args)
 {
     BlueStacks.ComRegistrar.ComRegistrar.Init();
     BlueStacks.ComRegistrar.ComRegistrar.sOpt.Parse(args);
     if (args.Length != 1 || !BlueStacks.ComRegistrar.ComRegistrar.sOpt.reg && !BlueStacks.ComRegistrar.ComRegistrar.sOpt.unreg)
     {
         Logger.Error("No/invalid arguments given. Exiting");
         Environment.Exit(2);
     }
     if (!SystemUtils.IsAdministrator())
     {
         Logger.Fatal("Not admin, exiting");
         Environment.Exit(4);
     }
     if (ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_UnRegRegCom_Lockbgp", out BlueStacks.ComRegistrar.ComRegistrar.sLock))
     {
         Logger.Info("Another instance of ComRegistrar is already running");
         Environment.Exit(1);
     }
     if (args.Length != 0)
     {
         Logger.Info("args: {0}", (object)string.Join(" ", args));
     }
     if (BlueStacks.ComRegistrar.ComRegistrar.sOpt.reg)
     {
         Logger.Info("Validating oleaut registries");
         if (FixUpOle.FixOle((string)null))
         {
             Logger.Info("Oleaut Validation successful");
         }
         else
         {
             Logger.Info("Oleaut Validation failed, continuing anyway");
         }
     }
     if (BlueStacks.ComRegistrar.ComRegistrar.sOpt.reg)
     {
         ulong num = RegisterProxyStub.DllRegisterServer();
         if (num != 0UL)
         {
             MultiInstanceUtils.SetDeviceCapsRegistry(string.Format("Registration error: {0}", (object)num), EngineState.legacy.ToString());
             Logger.Fatal("Unable to register BstkProxyStub.dll, Error: {0}", (object)num);
             Environment.Exit(10);
         }
     }
     else if (BlueStacks.ComRegistrar.ComRegistrar.sOpt.unreg)
     {
         Logger.Info("Unregistering components");
         long num = (long)RegisterProxyStub.DllUnregisterServer();
     }
     Environment.Exit(0);
 }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            Logger.InitUserLog();
            if (ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_MULTI_INS_Frontend_Lockbgp", out Mutex _))
            {
                Logger.Info("Process already running, exiting");
                Environment.Exit(-17);
            }
            IEnumerable <ICommandFactory> availableCommands = BlueStacks.VmManager.VmManager.GetAvailableCommands();

            if (args.Length == 0)
            {
                BlueStacks.VmManager.VmManager.PrintUsage(availableCommands);
                Environment.Exit(-6);
            }
            ICommand command  = new CommandParser(availableCommands).ParseCommand(args);
            int      exitCode = command.Execute();

            Logger.Info("Command Execute returns: " + exitCode.ToString());
            if (exitCode < 0)
            {
                switch (exitCode)
                {
                case -15:
                    Environment.Exit(-15);
                    break;

                case -11:
                    Environment.Exit(-11);
                    break;

                case -10:
                    Environment.Exit(-10);
                    break;

                case -7:
                    Environment.Exit(-7);
                    break;

                case -1:
                    Environment.Exit(-1);
                    break;

                default:
                    command.Undo();
                    break;
                }
            }
            Logger.Info("Exiting process with result {0}", (object)exitCode);
            Environment.Exit(exitCode);
        }
Esempio n. 8
0
        private static void HandleAlreadyRunning()
        {
            Logger.Info("Agent already running");
            if (!ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_HDAgent_Lockbgp", out HDAgent.s_HDAgentLock))
            {
                return;
            }
            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("visible", "true");
            string vmName = "";

            HTTPUtils.SendRequestToAgent("sysTrayVisibility", data, vmName, 0, (Dictionary <string, string>)null, false, 1, 0, "bgp", true);
            Environment.Exit(1);
        }
        private static void Main(string[] args)
        {
            Mutex lck  = (Mutex)null;
            bool  flag = false;

            Strings.CurrentDefaultVmName = "Android";
            int num1 = ProcessUtils.CheckAlreadyRunningAndTakeLock(Strings.GetPlayerLockName(Strings.CurrentDefaultVmName, "bgp"), out lck) ? 1 : 0;

            lck?.Close();
            if (num1 == 0 && BlueStacks.GuestCommandRunner.GuestCommandRunner.LaunchBlueStacks())
            {
                flag = true;
                Console.WriteLine("Successfully Launched AppPlayer");
            }
            lck?.Close();
            if (!BlueStacks.GuestCommandRunner.GuestCommandRunner.CheckIfGuestStarted())
            {
                Environment.Exit(-1);
            }
            AdbCommandRunner adbCommandRunner = new AdbCommandRunner(Strings.CurrentDefaultVmName);

            for (int index = 0; index < VMCommand.COMMAND.Length; ++index)
            {
                if (!string.IsNullOrEmpty(VMCommand.COMMAND[index]) && string.Compare(VmCmdHandler.RunCommand(VMCommand.COMMAND[index], Strings.CurrentDefaultVmName, "bgp"), "ok", true) != 0)
                {
                    if (Oem.Instance.IsHideMessageBoxIconInTaskBar)
                    {
                        int num2 = (int)MessageBox.Show((IWin32Window) new Form(), "Error, Something went wrong!");
                    }
                    else
                    {
                        int num3 = (int)MessageBox.Show("Error, Something went wrong!");
                    }
                    adbCommandRunner.Dispose();
                    Environment.Exit(-1);
                }
            }
            adbCommandRunner.Dispose();
            Thread.Sleep(2000);
            BlueStacks.GuestCommandRunner.GuestCommandRunner.StopZygote();
            BlueStacks.GuestCommandRunner.GuestCommandRunner.StartZygote();
            if (!flag)
            {
                return;
            }
            BlueStacks.GuestCommandRunner.GuestCommandRunner.ExitBlueStacks();
        }
Esempio n. 10
0
 private static void Main(string[] args)
 {
     Logger.InitLog((string)null, "Agent", true);
     HDAgent.InitExceptionHandlers();
     ProcessUtils.LogProcessContextDetails();
     if (ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_HDAgent_Lockbgp", out HDAgent.s_HDAgentLock))
     {
         HDAgent.HandleAlreadyRunning();
     }
     NotificationWindow.Init();
     NotificationPopup.SettingsImageClickedHandle(new EventHandler(HTTPHandler.SettingsImageMouseUp), (object)null);
     HDAgent.sPowerValues.Add("4", "Entering Suspend");
     HDAgent.sPowerValues.Add("7", "Resume from Suspend");
     HDAgent.sPowerValues.Add("10", "Power Status Change");
     HDAgent.sPowerValues.Add("18", "Resume Automatic");
     HDAgent.InitPowerEvents();
     MemoryManager.TrimMemory(true);
     HDAgent.s_InstallDir = RegistryStrings.InstallDir;
     Directory.SetCurrentDirectory(HDAgent.s_InstallDir);
     Logger.Info("HDAgent: CurrentDirectory: {0}", (object)Directory.GetCurrentDirectory());
     LocaleStrings.InitLocalization((string)null, "Android", false);
     ServicePointManager.DefaultConnectionLimit = 10;
     ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(HDAgent.ValidateRemoteCertificate);
     Application.EnableVisualStyles();
     new Thread(new ThreadStart(HDAgent.SetupHTTPServer))
     {
         IsBackground = true
     }.Start();
     try
     {
         EventLog eventLog1 = new EventLog("Application");
         eventLog1.EntryWritten       += new EntryWrittenEventHandler(HDAgent.EventLogWritten);
         eventLog1.EnableRaisingEvents = true;
         EventLog eventLog2 = new EventLog("System");
         eventLog2.EntryWritten       += new EntryWrittenEventHandler(HDAgent.EventLogWritten);
         eventLog2.EnableRaisingEvents = true;
     }
     catch (Exception ex)
     {
         Logger.Warning("Got excecption while hooking to event log ex:{0}", (object)ex.ToString());
     }
     Stats.SendMiscellaneousStatsAsyncForDMM(Stats.DMMEvent.agent_launched.ToString(), RegistryManager.Instance.AgentServerPort.ToString(), (string)null, (string)null, (string)null, "Android", 0);
     Application.Run((ApplicationContext) new HDAgent());
     Logger.Info("Exiting HDAgent PID {0}", (object)Process.GetCurrentProcess().Id);
 }
Esempio n. 11
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 HandleAlreadyRunning()
 {
     if (!ProcessUtils.CheckAlreadyRunningAndTakeLock(BlueStacks.Common.Strings.GetHDXapkInstallerLockName(BlueStacks.Common.Strings.CurrentDefaultVmName), out HDXapkInstaller.sHDXapkInstallerLock))
     {
         return;
     }
     Logger.Warning("XapkInstaller already running");
     if (Oem.Instance.IsMessageBoxToBeDisplayed)
     {
         string          localizedString = LocaleStrings.GetLocalizedString("STRING_BLUESTACKS_XAPK_HANDLER_TITLE", "");
         HDXapkInstaller hdXapkInstaller = new HDXapkInstaller((string)null, "");
         hdXapkInstaller.Show();
         int num = (int)MessageBox.Show((IWin32Window)hdXapkInstaller, LocaleStrings.GetLocalizedString("STRING_APKINSTALLER_ALREADY_RUNNING", ""), localizedString, MessageBoxButtons.OK, MessageBoxIcon.Hand);
         hdXapkInstaller.Close();
     }
     if (Features.IsFeatureEnabled(8589934592UL))
     {
         HDXapkInstaller.StartLogCollection(2, "PROCESS_ALREADY_RUNNING", "");
     }
     Environment.Exit(2);
 }
Esempio n. 13
0
 internal static bool TakeLock(string lockBane)
 {
     return(ProcessUtils.CheckAlreadyRunningAndTakeLock(lockBane, out Mutex _));
 }
        public static int Main(string[] args)
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            Logger.InitUserLog();
            BlueStacks.QuitMultiInstall.QuitMultiInstall.InitExceptionHandlers();
            ServiceController runningSvc = (ServiceController)null;

            if (ProcessUtils.CheckAlreadyRunningAndTakeLock("Global\\BlueStacks_HDQuitMultiInstall_Lockbgp", out BlueStacks.QuitMultiInstall.QuitMultiInstall.s_HDQuitMultiInstaceLock))
            {
                Logger.Info("QuitMultiInstall already running, returning");
                return(0);
            }
            if (args.Length != 0 && args[0] == "-in")
            {
                Logger.Info("quit multi install started with arg : -in...checking for another running version of parent proccess");
                string[] strArray = new string[9]
                {
                    "HD-Agent",
                    "HD-ApkHandler",
                    "HD-Adb",
                    "HD-RunApp",
                    "HD-Updater",
                    "HD-Player",
                    "BlueStacks",
                    "BstkSVC",
                    "HD-XapkHandler"
                };
                bool flag = false;
                foreach (string procName in strArray)
                {
                    if (Utils.IsRunningInstanceClashWithAnotherInstance(procName))
                    {
                        flag = true;
                        break;
                    }
                }
                if (Utils.IsRunningInstanceClashWithService(BlueStacks.QuitMultiInstall.QuitMultiInstall.BlueStacksServicePlusPrefixes, out runningSvc))
                {
                    flag = true;
                }
                if (!flag)
                {
                    return(0);
                }
                string str1 = LocaleStrings.GetLocalizedString("STRING_ANOTHER_BLUESTACKS_INSTANCE_RUNNING_PROMPT_TEXT1", "");
                string str2 = LocaleStrings.GetLocalizedString("STRING_ANOTHER_BLUESTACKS_INSTANCE_RUNNING_PROMPT_TEXT2", "");
                if ("bgp".Equals("dmm") && RegistryManager.Instance.UserSelectedLocale.Equals("ja-JP", StringComparison.InvariantCultureIgnoreCase))
                {
                    str1 = "同時に起動できないプログラムが既に動いています。";
                    str2 = "既に動いているプログラムを閉じて続行しますか?";
                }
                if (MessageBox.Show(str1 + Environment.NewLine + str2, string.Format("{0} Warning", (object)Strings.ProductDisplayName), MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
                {
                    return(-1);
                }
            }
            BlueStacks.QuitMultiInstall.QuitMultiInstall.QuitPreviousInstance();
            if (runningSvc != null)
            {
                BlueStacks.QuitMultiInstall.QuitMultiInstall.StopService(runningSvc);
            }
            ComRegistration.Register();
            return(0);
        }
Esempio n. 15
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();
                            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());
                }
            }
        }