Example #1
0
        public void DownloadApk(
            string apkUrl,
            string packageName,
            bool isLaunchAfterInstall,
            bool isDeleteApk,
            string timestamp = "")
        {
            string str = Path.Combine(RegistryStrings.DataDir, "DownloadedApk");

            if (!Directory.Exists(str))
            {
                Directory.CreateDirectory(str);
            }
            string path2       = Regex.Replace(packageName + ".apk", "[\\x22\\\\\\/:*?|<>]", " ");
            string apkFilePath = Path.Combine(str, path2);

            Logger.Info("Downloading Apk file to: " + apkFilePath);
            this.ParentWindow.mWelcomeTab.mHomeAppManager.DownloadStarted(packageName);
            ClientStats.SendClientStatsAsync("download", "unknown", "app_install", packageName, "", "");
            this.mDownloadThread = new Thread((ThreadStart)(() =>
            {
                string apkUrl1 = apkUrl;
                if (DownloadInstallApk.IsContainsGoogleAdId(apkUrl1))
                {
                    apkUrl = this.AddGoogleAdidWithApk(apkUrl1);
                }
                apkUrl = BlueStacksUIUtils.GetFinalRedirectedUrl(apkUrl);
                if (string.IsNullOrEmpty(apkUrl))
                {
                    return;
                }
                this.mIsDownloading = true;
                this.mDownloader = new LegacyDownloader(3, apkUrl, apkFilePath);
                this.mDownloader.Download((LegacyDownloader.UpdateProgressCallback)(percent => this.ParentWindow.mWelcomeTab.mHomeAppManager.UpdateAppDownloadProgress(packageName, percent)), (LegacyDownloader.DownloadCompletedCallback)(filePath =>
                {
                    ClientStats.SendClientStatsAsync("download", "success", "app_install", packageName, "", "");
                    this.mIsDownloading = false;
                    this.ParentWindow.mWelcomeTab.mHomeAppManager.DownloadCompleted(packageName, filePath);
                    this.InstallApk(packageName, filePath, isLaunchAfterInstall, isDeleteApk, timestamp);
                    DownloadInstallApk.sDownloadedApkList.Add(packageName);
                }), (LegacyDownloader.ExceptionCallback)(ex =>
                {
                    ClientStats.SendClientStatsAsync("download", "fail", "app_install", packageName, "", "");
                    this.ParentWindow.mWelcomeTab.mHomeAppManager.DownloadFailed(packageName);
                    Logger.Error("Failed to download file: {0}. err: {1}", (object)apkFilePath, (object)ex.Message);
                }), (LegacyDownloader.ContentTypeCallback)null, (LegacyDownloader.SizeDownloadedCallback)null, (LegacyDownloader.PayloadInfoCallback)null);
            }))
            {
                IsBackground = true
            };
            this.mDownloadThread.Start();
        }