private static void ShowFetchedMsg(AnnouncementMessage m, string vmName) { Logger.Info("ShowFetchedMsg called for: " + m.Action); switch (m.Action) { case "Download and Execute": CustomAlert.ShowCloudAnnouncement(m.ImagePath, m.Title, m.Msg, false, (MouseButtonEventHandler)((o, e) => { CloudAnnouncement.UpdateClickStats(vmName); new Thread((ThreadStart)(() => { Random random = new Random(); m.FileName += " "; string str1 = m.FileName.Substring(0, m.FileName.IndexOf(' ')); string str2 = m.FileName.Substring(m.FileName.IndexOf(' ') + 1); string str3 = Path.Combine(CloudAnnouncement.Dir, string.Format("{0}_{1}", (object)random.Next(), (object)str1)); try { new WebClient().DownloadFile(m.ActionURL, str3); Thread.Sleep(2000); Process process = new Process(); process.StartInfo.UseShellExecute = true; process.StartInfo.CreateNoWindow = true; if ((str3.ToLowerInvariant().EndsWith(".msi") || str3.ToLowerInvariant().EndsWith(".exe")) && !BlueStacksUtils.IsSignedByBlueStacks(str3)) { Logger.Info("Not executing unsigned binary " + str3); } else { if (str3.ToLowerInvariant().EndsWith(".msi")) { process.StartInfo.FileName = "msiexec"; str2 = string.Format("/i {0} {1}", (object)str3, (object)str2); process.StartInfo.Arguments = str2; } else { process.StartInfo.FileName = str3; process.StartInfo.Arguments = str2; } Logger.Info("Starting process: {0} {1}", (object)process.StartInfo.FileName, (object)str2); process.Start(); } } catch (Exception ex) { Logger.Error("Failed to download and execute. err: " + ex.ToString()); } })) { IsBackground = true }.Start(); }), vmName); break; case "None": CustomAlert.ShowCloudAnnouncement(m.ImagePath, m.Title, m.Msg, false, (MouseButtonEventHandler)null, vmName); break; case "Silent Install": Logger.Info("Got update request. Initializing silent install..."); new Thread((ThreadStart)(() => { Random random = new Random(); m.FileName += " "; string str1 = m.FileName.Substring(0, m.FileName.IndexOf(' ')); string str2 = m.FileName.Substring(m.FileName.IndexOf(' ') + 1); string str3 = Path.Combine(CloudAnnouncement.Dir, string.Format("{0}_{1}", (object)random.Next(), (object)str1)); try { new WebClient().DownloadFile(m.ActionURL, str3); Thread.Sleep(2000); Process process = new Process(); process.StartInfo.UseShellExecute = true; process.StartInfo.CreateNoWindow = true; if ((str3.ToLowerInvariant().EndsWith(".msi") || str3.ToLowerInvariant().EndsWith(".exe")) && !BlueStacksUtils.IsSignedByBlueStacks(str3)) { Logger.Info("Not executing unsigned binary " + str3); } else { if (str3.ToLowerInvariant().EndsWith(".msi")) { process.StartInfo.FileName = "msiexec"; str2 = string.Format("/i {0} {1}", (object)str3, (object)str2); process.StartInfo.Arguments = str2; } else { Logger.Info("Creating file: " + str3 + ".config"); try { System.IO.File.WriteAllText(str3 + ".config", CloudAnnouncement.configString); } catch (Exception ex) { Logger.Error("Exception in create config file: " + ex.ToString()); } process.StartInfo.FileName = str3; process.StartInfo.Arguments = str2; } Logger.Info("Starting process: {0} {1}", (object)process.StartInfo.FileName, (object)str2); process.Start(); } } catch (Exception ex) { Logger.Error("Silent install failed."); Logger.Error("Failed to download and execute. err: " + ex.ToString()); } })) { IsBackground = true }.Start(); break; case "Silent LogCollect": if (!string.Equals(CloudAnnouncement.sOemForSilentLogCollect, "bgp", StringComparison.InvariantCultureIgnoreCase)) { Logger.Info("This is not the OEM for silent log collection. OEM to launch: " + CloudAnnouncement.sOemForSilentLogCollect); CloudAnnouncement.StartSilentLogCollectorForCustomOEM(CloudAnnouncement.sOemForSilentLogCollect); break; } Logger.Info("Starting silent log collection"); new Thread((ThreadStart)(() => { try { string fileName = Path.Combine(HDAgent.s_InstallDir, "HD-LogCollector.exe"); if (CloudAnnouncement.sIsSilentLogCollectForAllOems) { Process.Start(fileName, "-silent -logAllOems"); } else { Process.Start(fileName, "-silent"); } } catch (Exception ex) { Logger.Error("Exception in starting HD-logCollector.exe: " + ex.ToString()); } })) { IsBackground = true }.Start(); break; case "Start Android App": CustomAlert.ShowCloudAnnouncement(m.ImagePath, m.Title, m.Msg, false, (MouseButtonEventHandler)((o, e) => { CloudAnnouncement.UpdateClickStats(vmName); try { string fileName = HDAgent.s_InstallDir + "\\HD-RunApp.exe"; string[] strArray = m.FileName.Split(' '); Logger.Info("Broadcast: Starting RunApp: {0} with args: -p {1} -a {2} -nl -vmname:{3}", (object)fileName, (object)strArray[0], (object)strArray[1], (object)vmName); Process.Start(fileName, string.Format("-p {0} -a {1} -nl -vmname:{2}", (object)strArray[0], (object)strArray[1], (object)vmName)); } catch (Exception ex) { Logger.Error("Failed to start android app: {0}. Error: {1}", (object)m.FileName, (object)ex.ToString()); } }), vmName); break; case "Web URL": NotificationManager.Instance.AddNewNotification(m.ImagePath, m.AnnouncementID, m.Title, m.Msg, m.ActionURL); CustomAlert.ShowCloudAnnouncement(m.ImagePath, m.Title, m.Msg, false, (MouseButtonEventHandler)((o, e) => { Logger.Info("Announcement msg clicked. Opening url: " + m.ActionURL); Process.Start(m.ActionURL); CloudAnnouncement.UpdateClickStats(vmName); }), vmName); break; case "Web URL GM": NotificationManager.Instance.AddNewNotification(m.ImagePath, m.AnnouncementID, m.Title, m.Msg, m.ActionURL); CustomAlert.ShowCloudAnnouncement(m.ImagePath, m.Title, m.Msg, false, (MouseButtonEventHandler)((o, e) => { Logger.Info("Announcement msg clicked. Opening tab: " + m.ActionURL); Dictionary <string, string> data = new Dictionary <string, string>(); if (System.IO.File.Exists(m.ImagePath)) { data.Add("image", m.ImagePath); } data.Add("url", m.ActionURL); data.Add("name", m.Title); if (!Utils.IsUIProcessAlive(vmName, "bgp")) { Logger.Info("Frontend not running"); CloudAnnouncement.WaitUntilClientServerReady(vmName); } Logger.Info("Will open tab for url: " + m.ActionURL); HTTPUtils.SendRequestToClient("launchWebTab", data, vmName, 0, (Dictionary <string, string>)null, false, 1, 0, "bgp"); }), vmName); break; default: Logger.Error("Announcement: Invalid msg type rcvd: " + m.Action); break; } }
private static void PerformGrmActionsWorker_DoWork( DoWorkEventArgs e, List <GrmAction> actions, string package, MainWindow ParentWindow) { try { ParentWindow.Dispatcher.Invoke((Delegate)(() => { ParentWindow.mFrontendGrid.Visibility = Visibility.Hidden; ParentWindow.mExitProgressGrid.ProgressText = LocaleStrings.GetLocalizedString("STRING_PERFORMING_ACTIONS", ""); ParentWindow.mExitProgressGrid.Visibility = Visibility.Visible; })); try { ClientStats.SendMiscellaneousStatsAsync("grm_action_clicked", RegistryManager.Instance.UserGuid, string.Join(",", actions.Select <GrmAction, string>((Func <GrmAction, string>)(_ => _.ActionType.ToString((IFormatProvider)CultureInfo.InvariantCulture))).ToArray <string>()), RegistryManager.Instance.ClientVersion, RegistryManager.Instance.Version, "bgp", package, (string)null, (string)null, "Android"); } catch (Exception ex) { Logger.Error("Exception while sending misc stat for grm. " + ex?.ToString()); } e.Result = (object)false; foreach (GrmAction action1 in actions) { GrmActionType grmActionType = EnumHelper.Parse <GrmActionType>(action1.ActionType, GrmActionType.NoAction); bool? nullable1 = new bool?(false); EngineState engineState; switch (grmActionType) { case GrmActionType.UpdateRam: int num1 = int.Parse(action1.ActionDictionary["actionValue"], (IFormatProvider)CultureInfo.InvariantCulture); int num2 = 4096; int result; if (int.TryParse(PhysicalRamEvaluator.RAM, out result)) { num2 = (int)((double)result * 0.5); } string currentEngine1 = RegistryManager.Instance.CurrentEngine; engineState = EngineState.raw; string str1 = engineState.ToString(); if (currentEngine1 == str1 && num2 >= 3072) { num2 = 3072; } if (num2 < num1) { num1 = num2; } RegistryManager.Instance.Guest[ParentWindow.mVmName].Memory = num1; nullable1 = new bool?(true); break; case GrmActionType.UserBrowser: ParentWindow.Utils.HandleGenericActionFromDictionary(action1.ActionDictionary, "grm", ""); nullable1 = new bool?(false); break; case GrmActionType.DownloadFileAndExecute: Random random = new Random(); string str2 = action1.ActionDictionary["fileName"] + " "; string str3 = str2.Substring(0, str2.IndexOf(' ')); string str4 = str2.Substring(str2.IndexOf(' ') + 1); string str5 = Path.Combine(RegistryStrings.PromotionDirectory, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}_{1}", (object)random.Next(), (object)str3)); try { using (WebClient webClient = new WebClient()) webClient.DownloadFile(action1.ActionDictionary["url"], str5); Thread.Sleep(2000); using (Process process = new Process()) { process.StartInfo.UseShellExecute = true; process.StartInfo.CreateNoWindow = true; if ((str5.ToUpperInvariant().EndsWith(".msi", StringComparison.InvariantCultureIgnoreCase) || str5.ToUpperInvariant().EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) && !BlueStacksUtils.IsSignedByBlueStacks(str5)) { Logger.Info("Not executing unsigned binary " + str5); GrmHandler.GrmExceptionMessageBox(ParentWindow); return; } if (str5.ToUpperInvariant().EndsWith(".msi", StringComparison.InvariantCultureIgnoreCase)) { process.StartInfo.FileName = "msiexec"; str4 = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "/i {0} {1}", (object)str5, (object)str4); process.StartInfo.Arguments = str4; } else { process.StartInfo.FileName = str5; process.StartInfo.Arguments = str4; } Logger.Info("Starting process: {0} {1}", (object)process.StartInfo.FileName, (object)str4); process.Start(); } } catch (Exception ex) { GrmHandler.GrmExceptionMessageBox(ParentWindow); Logger.Error("Failed to download and execute. err: " + ex?.ToString()); } nullable1 = new bool?(false); break; case GrmActionType.NoAction: nullable1 = new bool?(false); break; case GrmActionType.ContinueAnyway: ParentWindow.Dispatcher.Invoke((Delegate)(() => { ParentWindow.mFrontendGrid.Visibility = Visibility.Visible; ParentWindow.mExitProgressGrid.Visibility = Visibility.Hidden; if (GrmHandler.sDictAppRuleSet[ParentWindow.mVmName][package].MessageWindow.DontShowOption) { GrmHandler.DonotShowCheckboxHandling(ParentWindow, package); GrmHandler.RefreshGrmIndication(package, ParentWindow.mVmName); GrmHandler.SendUpdateGrmPackagesToAndroid(ParentWindow.mVmName); GrmHandler.SendUpdateGrmPackagesToBrowser(ParentWindow.mVmName); } ParentWindow.mWelcomeTab.mHomeAppManager.OpenApp(package, false); })); nullable1 = new bool?(); break; case GrmActionType.GlMode: string action2 = action1.ActionDictionary["actionValue"]; int glRenderMode = RegistryManager.Instance.Guest[ParentWindow.mVmName].GlRenderMode; int glMode1 = RegistryManager.Instance.Guest[ParentWindow.mVmName].GlMode; GlMode glMode2 = GlMode.PGA_GL; if (glRenderMode == 1 && glMode1 == 1) { glMode2 = GlMode.PGA_GL; } else if (glRenderMode == 1 && glMode1 == 2) { glMode2 = GlMode.AGA_GL; } else { switch (glMode1) { case 1: glMode2 = GlMode.PGA_DX; break; case 2: glMode2 = GlMode.AGA_DX; break; } } List <string> list1 = ((IEnumerable <string>)action2.Split(',')).Select <string, string>((Func <string, string>)(_ => _.Trim())).ToList <string>(); if (list1.Contains <string>(glMode2.ToString(), (IEqualityComparer <string>)StringComparer.InvariantCultureIgnoreCase)) { nullable1 = new bool?(false); break; } string str6 = list1.RandomElement <string>(); string str7 = ""; int num3; string str8; if (string.Compare(str6.Split('_')[1].Trim(), "GL", StringComparison.OrdinalIgnoreCase) == 0) { num3 = 1; str8 = str7 + "1"; } else { num3 = 4; str8 = str7 + "4"; } int num4; string args; if (string.Compare(str6.Split('_')[0].Trim(), "PGA", StringComparison.OrdinalIgnoreCase) == 0) { num4 = 1; args = str8 + " 1"; } else { num4 = 2; args = str8 + " 2"; } if (RunCommand.RunCmd(Path.Combine(RegistryStrings.InstallDir, "HD-GlCheck"), args, true, true, false, 0).ExitCode == 0) { RegistryManager.Instance.Guest[ParentWindow.mVmName].GlRenderMode = num3; Utils.UpdateValueInBootParams("GlMode", num4.ToString((IFormatProvider)CultureInfo.InvariantCulture), ParentWindow.mVmName, true, "bgp"); RegistryManager.Instance.Guest[ParentWindow.mVmName].GlMode = num4; } else { GrmHandler.GrmExceptionMessageBox(ParentWindow); Logger.Info("GL check execution for the required combination failed."); } nullable1 = new bool?(true); break; case GrmActionType.DeviceProfile: string strA = action1.ActionDictionary["pCode"]; string empty = string.Empty; string str9; if (string.Compare(strA, "custom", StringComparison.OrdinalIgnoreCase) == 0) { str9 = "{" + string.Format((IFormatProvider)CultureInfo.InvariantCulture, "\"createcustomprofile\":\"{0}\",", (object)"true") + string.Format((IFormatProvider)CultureInfo.InvariantCulture, "\"model\":\"{0}\",", (object)action1.ActionDictionary["model"]) + string.Format((IFormatProvider)CultureInfo.InvariantCulture, "\"brand\":\"{0}\",", (object)action1.ActionDictionary["brand"]) + string.Format((IFormatProvider)CultureInfo.InvariantCulture, "\"manufacturer\":\"{0}\"", (object)action1.ActionDictionary["manufacturer"]) + "}"; } else { List <string> list2 = ((IEnumerable <string>)strA.Split(',')).Select <string, string>((Func <string, string>)(_ => _.Trim())).ToList <string>(); string valueInBootParams = Utils.GetValueInBootParams("pcode", ParentWindow.mVmName, "", "bgp"); if (!list2.Contains(valueInBootParams)) { strA = list2.RandomElement <string>(); str9 = "{" + string.Format((IFormatProvider)CultureInfo.InvariantCulture, "\"createcustomprofile\":\"{0}\",", (object)"false") + string.Format((IFormatProvider)CultureInfo.InvariantCulture, "\"pcode\":\"{0}\"", (object)strA) + "}"; } else { break; } } if (string.Equals(VmCmdHandler.RunCommand(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0} {1}", (object)"changeDeviceProfile", (object)str9), ParentWindow.mVmName, "bgp"), "ok", StringComparison.InvariantCulture)) { Utils.UpdateValueInBootParams("pcode", strA, ParentWindow.mVmName, false, "bgp"); if (PackageActivityNames.ThirdParty.AllCallOfDutyPackageNames.Contains(package)) { HTTPUtils.SendRequestToAgentAsync("clearAppData", new Dictionary <string, string>() { { nameof(package), package } }, ParentWindow.mVmName, 0, (Dictionary <string, string>)null, false, 1, 0, "bgp"); } } else { GrmHandler.GrmExceptionMessageBox(ParentWindow); Logger.Error("Setting device profile for the required combination failed."); } nullable1 = new bool?(false); break; case GrmActionType.BootParam: Utils.UpdateValueInBootParams(action1.ActionDictionary["param"].Trim(), action1.ActionDictionary["actionValue"].Trim(), ParentWindow.mVmName, true, "bgp"); nullable1 = new bool?(true); break; case GrmActionType.DPI: string action3 = action1.ActionDictionary["actionValue"]; Utils.SetDPIInBootParameters(RegistryManager.Instance.Guest[ParentWindow.mVmName].BootParameters, action3, ParentWindow.mVmName, "bgp"); nullable1 = new bool?(true); break; case GrmActionType.CpuCores: int num5 = int.Parse(action1.ActionDictionary["actionValue"], (IFormatProvider)CultureInfo.InvariantCulture); string currentEngine2 = RegistryManager.Instance.CurrentEngine; engineState = EngineState.raw; string str10 = engineState.ToString(); if (currentEngine2 != str10) { RegistryManager.Instance.Guest[ParentWindow.mVmName].VCPUs = num5 > 8 ? 8 : num5; } nullable1 = new bool?(true); break; case GrmActionType.Resolution: List <string> list3 = ((IEnumerable <string>)action1.ActionDictionary["actionValue"].Split(',')).Select <string, string>((Func <string, string>)(_ => _.Replace(" ", string.Empty))).ToList <string>(); string str11 = RegistryManager.Instance.Guest[ParentWindow.mVmName].GuestWidth.ToString((IFormatProvider)CultureInfo.InvariantCulture) + "x" + RegistryManager.Instance.Guest[ParentWindow.mVmName].GuestHeight.ToString((IFormatProvider)CultureInfo.InvariantCulture); if (!list3.Contains <string>(str11, (IEqualityComparer <string>)StringComparer.InvariantCultureIgnoreCase)) { string str12 = list3.RandomElement <string>(); RegistryManager.Instance.Guest[ParentWindow.mVmName].GuestWidth = int.Parse(str12.Split('x')[0].Trim(), (IFormatProvider)CultureInfo.InvariantCulture); RegistryManager.Instance.Guest[ParentWindow.mVmName].GuestHeight = int.Parse(str12.Split('x')[1].Trim(), (IFormatProvider)CultureInfo.InvariantCulture); nullable1 = new bool?(true); break; } break; case GrmActionType.RestartBluestacks: nullable1 = new bool?(true); break; case GrmActionType.RestartMachine: Process.Start("shutdown.exe", "-r -t 0"); break; case GrmActionType.Fps: int newFps = int.Parse(action1.ActionDictionary["actionValue"], (IFormatProvider)CultureInfo.InvariantCulture); RegistryManager.Instance.Guest[ParentWindow.mVmName].FPS = newFps; Utils.UpdateValueInBootParams("fps", newFps.ToString((IFormatProvider)CultureInfo.InvariantCulture), ParentWindow.mVmName, true, "bgp"); Utils.SendChangeFPSToInstanceASync(ParentWindow.mVmName, newFps, "bgp"); nullable1 = new bool?(false); break; case GrmActionType.EditRegistry: string action4 = action1.ActionDictionary["location"]; if (string.Compare(action4, "registryManager", StringComparison.OrdinalIgnoreCase) == 0) { PropertyInfo property = typeof(RegistryManager).GetProperty(action1.ActionDictionary["propertyName"]); object obj = Convert.ChangeType((object)action1.ActionDictionary["propertyValue"], Type.GetTypeCode(property.PropertyType), (IFormatProvider)CultureInfo.InvariantCulture); property.SetValue((object)RegistryManager.Instance, obj, (object[])null); } else if (string.Compare(action4, "instanceManager", StringComparison.OrdinalIgnoreCase) == 0) { PropertyInfo property = typeof(InstanceRegistry).GetProperty(action1.ActionDictionary["propertyName"]); object obj = Convert.ChangeType((object)action1.ActionDictionary["propertyValue"], Type.GetTypeCode(property.PropertyType), (IFormatProvider)CultureInfo.InvariantCulture); property.SetValue((object)RegistryManager.Instance.Guest[ParentWindow.mVmName], obj, (object[])null); } else { string registryPath = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Software\\BlueStacks{0}\\{1}", (object)BlueStacks.Common.Strings.GetOemTag(), (object)action1.ActionDictionary["propertyPath"].Replace("vmName", ParentWindow.mVmName)); object obj = (object)null; RegistryValueKind type = EnumHelper.Parse <RegistryValueKind>(action1.ActionDictionary["propertyRegistryKind"], RegistryValueKind.String); switch (type) { case RegistryValueKind.String: obj = (object)action1.ActionDictionary["propertyValue"]; break; case RegistryValueKind.DWord: obj = (object)int.Parse(action1.ActionDictionary["propertyValue"], (IFormatProvider)CultureInfo.InvariantCulture); break; } RegistryUtils.SetRegistryValue(registryPath, action1.ActionDictionary["propertyName"], obj, type, RegistryKeyKind.HKEY_LOCAL_MACHINE); } nullable1 = new bool?(false); break; case GrmActionType.ClearAppData: HTTPUtils.SendRequestToAgentAsync("clearAppData", new Dictionary <string, string>() { { nameof(package), package } }, ParentWindow.mVmName, 0, (Dictionary <string, string>)null, false, 1, 0, "bgp"); break; } bool?nullable2 = nullable1; bool flag = true; if (nullable2.GetValueOrDefault() == flag & nullable2.HasValue) { e.Result = (object)true; } else if (!nullable1.HasValue) { e.Result = (object)null; } } Thread.Sleep(1000); } catch (Exception ex) { Logger.Error("Exception in performing grm actions, ex: " + ex.ToString()); ClientStats.SendMiscellaneousStatsAsync("grm_action_error", RegistryManager.Instance.UserGuid, GrmHandler.sDictAppRuleSet[ParentWindow.mVmName][package].RuleId, RegistryManager.Instance.ClientVersion, RegistryManager.Instance.Version, "bgp", package, ex.Message, (string)null, "Android"); GrmHandler.GrmExceptionMessageBox(ParentWindow); e.Result = (object)null; } }