Пример #1
0
        internal void InstallApk(string apkPath, bool addToChooseApkList = false)
        {
            Logger.Info("Console: Installing apk: {0}", (object)apkPath);
            string package = string.Empty;
            string appName = string.Empty;

            if (string.Equals(Path.GetExtension(apkPath), ".xapk", StringComparison.InvariantCultureIgnoreCase))
            {
                JToken infoFromXapk = Utils.ExtractInfoFromXapk(apkPath);
                if (infoFromXapk != null)
                {
                    package = infoFromXapk.GetValue("package_name");
                    appName = infoFromXapk.GetValue("name");
                    Logger.Debug("Package name from manifest.json.." + package);
                }
            }
            else
            {
                AppInfoExtractor apkInfo = AppInfoExtractor.GetApkInfo(apkPath);
                package = apkInfo.PackageName;
                appName = apkInfo.AppName;
            }
            ClientStats.SendMiscellaneousStatsAsync("open_apk", RegistryManager.Instance.UserGuid, "import_apk", package, RegistryManager.Instance.ClientVersion, RegistryManager.Instance.Version, RegistryManager.Instance.Oem, (string)null, (string)null, "Android");
            if (addToChooseApkList)
            {
                DownloadInstallApk.sApkInstalledFromChooser.Add(package);
            }
            if (!string.IsNullOrEmpty(package))
            {
                this.ParentWindow.Dispatcher.Invoke((Delegate)(() => this.ParentWindow.mWelcomeTab.mHomeAppManager.AddAppIcon(package, appName, string.Empty, this)));
            }
            this.InstallApk(package, apkPath, false, false, "");
        }
        internal static AppInfoExtractor GetApkInfo(string apkFile)
        {
            AppInfoExtractor appInfoExtractor = new AppInfoExtractor();

            try
            {
                string input = string.Empty;
                using (Process process = new Process())
                {
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.CreateNoWindow         = true;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.StandardOutputEncoding = Encoding.UTF8;
                    process.StartInfo.FileName  = Path.Combine(RegistryStrings.InstallDir, "hd-aapt.exe");
                    process.StartInfo.Arguments = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "dump badging \"{0}\"", (object)apkFile);
                    process.Start();
                    input = process.StandardOutput.ReadToEnd();
                    process.WaitForExit();
                }
                Match match1 = new Regex("package:\\sname='(.+?)'").Match(input);
                appInfoExtractor.PackageName = match1.Groups[1].Value;
                if (!string.IsNullOrEmpty(appInfoExtractor.PackageName))
                {
                    Match match2 = new Regex("application:\\slabel='(.+)'\\sicon='(.+?)'").Match(input);
                    appInfoExtractor.AppName = match2.Groups[1].Value;
                    appInfoExtractor.AppName = Regex.Replace(appInfoExtractor.AppName, "[\\x22\\\\\\/:*?|<>]", "");
                    match2.Groups[2].Value.Replace("/", "\\");
                    Match match3 = new Regex("launchable\\sactivity\\sname='(.+?)'").Match(input);
                    appInfoExtractor.ActivityName = match3.Groups[1].Value;
                }
            }
            catch
            {
                Logger.Error("Error getting file info");
            }
            return(appInfoExtractor);
        }