internal static void DownloadNow(BlueStacksUpdateData bstUpdateData, bool hiddenMode)
 {
     new Thread((ThreadStart)(() =>
     {
         BlueStacksUpdater.IsDownloadingInHiddenMode = hiddenMode;
         BlueStacksUpdater.SUpdateState = BlueStacksUpdater.UpdateState.DOWNLOADING;
         if (System.IO.File.Exists(bstUpdateData.UpdateDownloadLocation))
         {
             BlueStacksUpdater.DownloadComplete();
         }
         else
         {
             BlueStacksUpdater.ParentWindow.Dispatcher.Invoke((Delegate)(() =>
             {
                 BlueStacksUIBinding.Bind(BlueStacksUpdater.ParentWindow.mTopBar.mPreferenceDropDownControl.mUpgradeBluestacksStatusTextBlock, "STRING_DOWNLOADING_UPDATE", "");
                 BlueStacksUpdater.ParentWindow.mTopBar.mPreferenceDropDownControl.mUpdateDownloadProgressPercentage.Visibility = Visibility.Visible;
                 BlueStacksUpdater.ParentWindow.mTopBar.mPreferenceDropDownControl.mUpdateDownloadProgressPercentage.Content = (object)"0%";
                 BlueStacksUpdater.sUpdateDownloadProgress = new UpdateDownloadProgress();
                 BlueStacksUpdater.sUpdateDownloadProgress.mUpdateDownloadProgressPercentage.Content = (object)"0%";
                 BlueStacksUpdater.sUpdateDownloadProgress.Owner = (Window)BlueStacksUpdater.ParentWindow;
                 if (hiddenMode)
                 {
                     return;
                 }
                 BlueStacksUpdater.sUpdateDownloadProgress.Show();
             }));
             BlueStacksUpdater.DownloadUpdate(bstUpdateData);
         }
     }))
     {
         IsBackground = true
     }.Start();
 }
 private static void DownloadUpdate(BlueStacksUpdateData bluestacksUpdateData)
 {
     BlueStacksUpdater.sDownloader = new Downloader();
     BlueStacksUpdater.sDownloader.DownloadException += new Downloader.DownloadExceptionEventHandler(BlueStacksUpdater.Downloader_DownloadException);
     BlueStacksUpdater.sDownloader.DownloadProgressPercentChanged += new Downloader.DownloadProgressPercentChangedEventHandler(BlueStacksUpdater.Downloader_DownloadProgressPercentChanged);
     BlueStacksUpdater.sDownloader.DownloadFileCompleted          += new Downloader.DownloadFileCompletedEventHandler(BlueStacksUpdater.Downloader_DownloadFileCompleted);
     BlueStacksUpdater.sDownloader.UnsupportedResume += new Downloader.UnsupportedResumeEventHandler(BlueStacksUpdater.Downloader_UnsupportedResume);
     BlueStacksUpdater.sDownloader.DownloadFile(bluestacksUpdateData.DownloadUrl, bluestacksUpdateData.UpdateDownloadLocation);
 }
        private static void CheckUpdateBackgroundWorker_RunWorkerCompleted(
            object sender,
            RunWorkerCompletedEventArgs e)
        {
            BlueStacks.Common.Tuple <BlueStacksUpdateData, bool> result = (BlueStacks.Common.Tuple <BlueStacksUpdateData, bool>)e.Result;
            BlueStacksUpdateData bstUpdateData = result.Item1;
            bool flag = result.Item2;

            if (bstUpdateData.IsUpdateAvailble)
            {
                BlueStacksUpdater.ParentWindow.mTopBar.mConfigButton.ImageName = "cfgmenu_update";
                BlueStacksUpdater.ParentWindow.mTopBar.mPreferenceDropDownControl.mUpgradeBluestacksStatus.Visibility = Visibility.Visible;
                BlueStacksUIBinding.Bind(BlueStacksUpdater.ParentWindow.mTopBar.mPreferenceDropDownControl.mUpgradeBluestacksStatusTextBlock, "STRING_DOWNLOAD_UPDATE", "");
                BlueStacksUpdater.ParentWindow.mTopBar.mPreferenceDropDownControl.mUpdateDownloadProgressPercentage.Visibility = Visibility.Collapsed;
                if (bstUpdateData.IsFullInstaller)
                {
                    if (!flag)
                    {
                        return;
                    }
                    if (bstUpdateData.UpdateType.Equals("hard", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Logger.Info("Forced full installer update, starting download.");
                        BlueStacksUpdater.DownloadNow(bstUpdateData, true);
                    }
                    else
                    {
                        if (!bstUpdateData.UpdateType.Equals("soft", StringComparison.InvariantCultureIgnoreCase) || string.Compare(bstUpdateData.EngineVersion.Trim(), RegistryManager.Instance.LastUpdateSkippedVersion.Trim(), StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            return;
                        }
                        ClientStats.SendBluestacksUpdaterUIStatsAsync(ClientStatsEvent.UpgradePopup, "");
                        UpdatePrompt updatePrompt1 = new UpdatePrompt(bstUpdateData);
                        updatePrompt1.Height = 215.0;
                        updatePrompt1.Width  = 400.0;
                        UpdatePrompt    updatePrompt2   = updatePrompt1;
                        ContainerWindow containerWindow = new ContainerWindow(BlueStacksUpdater.ParentWindow, (UserControl)updatePrompt2, (double)(int)updatePrompt2.Width, (double)(int)updatePrompt2.Height, false, true, false, -1.0, (Brush)null);
                    }
                }
                else
                {
                    Logger.Info("Only client installer update, starting download.");
                    BlueStacksUpdater.DownloadNow(bstUpdateData, true);
                }
            }
            else
            {
                BlueStacksUpdater.SUpdateState = BlueStacksUpdater.UpdateState.NO_UPDATE;
            }
        }
 internal UpdatePrompt(BlueStacksUpdateData bstUpdateData)
 {
     this.InitializeComponent();
     this.mBstUpdateData = bstUpdateData;
     if (string.IsNullOrEmpty(bstUpdateData.EngineVersion))
     {
         this.mLabelVersion.Content    = (object)"";
         this.mLabelVersion.Visibility = Visibility.Collapsed;
     }
     else
     {
         this.mLabelVersion.Content = (object)("v" + bstUpdateData.EngineVersion);
     }
     BlueStacksUIBinding.Bind(this.titleLabel, "STRING_BLUESTACKS_UPDATE_AVAILABLE");
     BlueStacksUIBinding.Bind(this.bodyLabel, "STRING_UPDATE_AVAILABLE");
     BlueStacksUIBinding.Bind((Button)this.mDownloadNewButton, "STRING_DOWNLOAD_UPDATE");
     this.mCloseBtn.Visibility            = Visibility.Visible;
     this.mDetailedChangeLogs.NavigateUri = new Uri(bstUpdateData.DetailedChangeLogsUrl);
     this.mDetailedChangeLogs.Inlines.Clear();
     this.mDetailedChangeLogs.Inlines.Add(LocaleStrings.GetLocalizedString("STRING_LEARN_WHATS_NEW", "Learn What's New"));
 }
 public static void SetupBlueStacksUpdater(MainWindow window, bool isStartup)
 {
     BlueStacksUpdater.ParentWindow = window;
     if (BlueStacksUpdater.sCheckUpdateBackgroundWorker == null)
     {
         BlueStacksUpdater.sCheckUpdateBackgroundWorker         = new BackgroundWorker();
         BlueStacksUpdater.sCheckUpdateBackgroundWorker.DoWork += (DoWorkEventHandler)((sender, e) =>
         {
             bool flag = (bool)e.Argument;
             BlueStacksUpdateData stacksUpdateData = BlueStacksUpdater.CheckForUpdate(!flag);
             BlueStacksUpdater.sBstUpdateData = stacksUpdateData;
             e.Result = (object)new BlueStacks.Common.Tuple <BlueStacksUpdateData, bool>(stacksUpdateData, flag);
         });
         BlueStacksUpdater.sCheckUpdateBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BlueStacksUpdater.CheckUpdateBackgroundWorker_RunWorkerCompleted);
     }
     if (!BlueStacksUpdater.sCheckUpdateBackgroundWorker.IsBusy)
     {
         BlueStacksUpdater.sCheckUpdateBackgroundWorker.RunWorkerAsync((object)isStartup);
     }
     else
     {
         Logger.Info("Not launching update checking thread, since already running");
     }
 }
        private static BlueStacksUpdateData CheckForUpdate(bool isManualCheck)
        {
            BlueStacksUpdateData stacksUpdateData = new BlueStacksUpdateData();

            try
            {
                string urlWithParams = WebHelper.GetUrlWithParams(WebHelper.GetServerHost() + "/check_upgrade", (string)null, (string)null, (string)null);
                Logger.Debug("The URL for checking upgrade: {0}", (object)urlWithParams);
                string osName;
                SystemUtils.GetOSInfo(out osName, out string _, out string _);
                string str = InstallerArchitectures.AMD64;
                if (!SystemUtils.IsOs64Bit())
                {
                    str = InstallerArchitectures.X86;
                }
                Dictionary <string, string> data = new Dictionary <string, string>()
                {
                    {
                        "installer_arch",
                        str
                    },
                    {
                        "os",
                        osName
                    },
                    {
                        "manual_check",
                        isManualCheck.ToString((IFormatProvider)CultureInfo.InvariantCulture)
                    }
                };
                string json = BstHttpClient.Post(urlWithParams, data, (Dictionary <string, string>)null, false, string.Empty, 5000, 1, 0, false, "bgp");
                Logger.Info("Response received for check for update: " + Environment.NewLine + json);
                JObject jobject = JObject.Parse(json);
                if (jobject["update_available"].ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase) && RegistryManager.Instance.FailedUpgradeVersion != jobject["update_details"][(object)"client_version"].ToString())
                {
                    stacksUpdateData.IsUpdateAvailble = true;
                    stacksUpdateData.UpdateType       = jobject["update_details"][(object)"upgrade_type"].ToString();
                    stacksUpdateData.IsFullInstaller  = jobject["update_details"][(object)"is_full_installer"].ToObject <bool>();
                    stacksUpdateData.Md5                   = jobject["update_details"][(object)"md5"].ToString();
                    stacksUpdateData.ClientVersion         = jobject["update_details"][(object)"client_version"].ToString();
                    stacksUpdateData.EngineVersion         = jobject["update_details"][(object)"engine_version"].ToString();
                    stacksUpdateData.DownloadUrl           = jobject["update_details"][(object)"download_url"].ToString();
                    stacksUpdateData.DetailedChangeLogsUrl = jobject["update_details"][(object)"detailed_changelogs_url"].ToString();
                    if (!Directory.Exists(RegistryManager.Instance.SetupFolder))
                    {
                        Directory.CreateDirectory(RegistryManager.Instance.SetupFolder);
                    }
                    stacksUpdateData.UpdateDownloadLocation       = !stacksUpdateData.IsFullInstaller ? Path.Combine(RegistryManager.Instance.SetupFolder, "BlueStacksInstaller_" + stacksUpdateData.ClientVersion + "_client.zip") : Path.Combine(RegistryManager.Instance.SetupFolder, "BlueStacksInstaller_" + stacksUpdateData.ClientVersion + "_full.exe");
                    RegistryManager.Instance.DownloadedUpdateFile = stacksUpdateData.UpdateDownloadLocation;
                    BlueStacksUpdater.sBstUpdateData = stacksUpdateData;
                    BlueStacksUpdater.SUpdateState   = BlueStacksUpdater.UpdateState.UPDATE_AVAILABLE;
                }
                return(stacksUpdateData);
            }
            catch (Exception ex)
            {
                Logger.Warning("Got error in checking for upgrade: {0}", (object)ex.ToString());
                return(new BlueStacksUpdateData()
                {
                    IsTryAgain = true
                });
            }
        }