コード例 #1
0
        static IAsyncOperation CopyApk(IAsyncOperation signOp, string srcApk, string destApk)
        {
            var monitor = IdeApp.Workbench.ProgressMonitors.GetOutputProgressMonitor(
                GettextCatalog.GetString("Create Android Package"), MonoDevelop.Ide.Gui.Stock.RunProgramIcon, true, true);

            var chop = new ChainedAsyncOperationSequence(monitor,
                                                         new ChainedAsyncOperation()
            {
                TaskName     = "Waiting for package creation to complete",
                Skip         = () => signOp == null || signOp.IsCompleted ? "" : null,
                Create       = () => signOp,
                ErrorMessage = "Package creation failed"
            },
                                                         new ChainedAsyncOperation()
            {
                TaskName = "Moving package to final destination",
                Create   = () => {
                    File.Copy(srcApk, destApk, true);
                    return(Core.Execution.NullProcessAsyncOperation.Success);
                },
                ErrorMessage = "Error moving package to final destination"
            }
                                                         );

            chop.Completed += delegate {
                monitor.Dispose();
            };

            chop.Start();
            return(chop);
        }
コード例 #2
0
        public MonoDroidPublishOperation(IProgressMonitor monitor, AndroidSigningOptions signingOptions,
                                         string sourceApk, string destinationApk, IAsyncOperation packagingOperation, bool createNewKey, string dName, int keyValidity)
        {
            var toolbox          = MonoDroidFramework.Toolbox;
            var destApk          = (FilePath)destinationApk;
            var destUnalignedApk = ((FilePath)(destApk.FileNameWithoutExtension + "-unaligned.apk"));

            if (!destApk.ParentDirectory.IsNullOrEmpty)
            {
                destUnalignedApk = destApk.ParentDirectory.Combine(destUnalignedApk);
            }

            chop = new ChainedAsyncOperationSequence(monitor,
                                                     new ChainedAsyncOperation()
            {
                TaskName = GettextCatalog.GetString("Creating new keystore"),
                Skip     = () => !createNewKey ? "" : null,
                Create   = () => toolbox.Genkeypair(signingOptions, dName,
                                                    keyValidity, monitor.Log, monitor.Log),
                ErrorMessage = GettextCatalog.GetString("Failed to create a new keystore")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName     = GettextCatalog.GetString("Waiting for packaging to complete"),
                Skip         = () => (packagingOperation == null || packagingOperation.IsCompleted) ? "" : null,
                Create       = () => packagingOperation,
                ErrorMessage = GettextCatalog.GetString("Failed to create android package")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName = GettextCatalog.GetString("Signing package with custom key"),
                Create   = () => toolbox.SignPackage(signingOptions, sourceApk, destUnalignedApk,
                                                     monitor.Log, monitor.Log),
                ErrorMessage = GettextCatalog.GetString("Failed to sign package")
            },
                                                     new ChainedAsyncOperation()
            {
                Create = () => toolbox.AlignPackage(destUnalignedApk, destApk,
                                                    monitor.Log, monitor.Log),
                ErrorMessage = GettextCatalog.GetString("Failed to align package")
            },
                                                     new ChainedAsyncOperation()
            {
                Create = () => {
                    File.Delete(destUnalignedApk);
                    return(Core.Execution.NullProcessAsyncOperation.Success);
                },
                ErrorMessage = GettextCatalog.GetString("Failed to remove temp package file")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName = GettextCatalog.GetString("Package successfully signed"),
                Create   = () => Core.Execution.NullProcessAsyncOperation.Success
            }
                                                     );
        }
コード例 #3
0
        public MonoDroidUploadOperation(IProgressMonitor monitor, AndroidDevice device, FilePath packageFile, string packageName,
                                        IAsyncOperation signingOperation, bool replaceIfExists)
        {
            var         toolbox              = MonoDroidFramework.Toolbox;
            var         project              = DefaultUploadToDeviceHandler.GetActiveExecutableMonoDroidProject();
            var         conf                 = (MonoDroidProjectConfiguration)project.GetConfiguration(IdeApp.Workspace.ActiveConfiguration);
            int         apiLevel             = MonoDroidFramework.FrameworkVersionToApiLevel(project.TargetFramework.Id.Version);
            int         runtimeVersion       = MonoDroidFramework.GetRuntimeVersion();
            string      packagesListLocation = null;
            PackageList list                 = null;

            replaceIfExists = replaceIfExists || signingOperation != null;

            chop = new ChainedAsyncOperationSequence(monitor,
                                                     new ChainedAsyncOperation()
            {
                Skip         = () => MonoDroidFramework.DeviceManager.GetDeviceIsOnline(device.ID) ? "" : null,
                TaskName     = GettextCatalog.GetString("Waiting for device"),
                Create       = () => toolbox.WaitForDevice(device, monitor.Log, monitor.Log),
                Completed    = op => { DeviceNotFound = !op.Success; },
                ErrorMessage = GettextCatalog.GetString("Failed to get device")
            },
                                                     new ChainedAsyncOperation <AdbShellOperation> ()
            {
                TaskName  = GettextCatalog.GetString("Getting the package list location from device"),
                Create    = () => new AdbShellOperation(device, "ls /data/system/packages.xml"),
                Completed = op => {
                    string output = op.Output.Trim(new char [] { '\n', '\r' });
                    if (output == "/data/system/packages.xml")
                    {
                        packagesListLocation = output;
                    }
                    else
                    {
                        packagesListLocation = "/dbdata/system/packages.xml";
                    }
                }
            },
                                                     new ChainedAsyncOperation <AdbGetPackagesOperation> ()
            {
                TaskName     = GettextCatalog.GetString("Getting package list from device"),
                Create       = () => new AdbGetPackagesOperation(device, packagesListLocation),
                Completed    = op => list = op.PackageList,
                ErrorMessage = GettextCatalog.GetString("Failed to get package list")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName = GettextCatalog.GetString("Uninstalling old version of shared runtime package"),
                Skip     = () => !conf.AndroidUseSharedRuntime || list.GetOldRuntimesAndPlatforms(apiLevel, runtimeVersion).Count() == 0 ?
                           "" : null,
                Create = () => {                         // Cleanup task, no need to wait for it
                    foreach (InstalledPackage oldPackage in list.GetOldRuntimesAndPlatforms(apiLevel, runtimeVersion))
                    {
                        toolbox.Uninstall(device, oldPackage.Name, monitor.Log, monitor.Log);
                    }
                    return(Core.Execution.NullProcessAsyncOperation.Success);
                },
                ErrorMessage = GettextCatalog.GetString("Failed to uninstall package")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName = GettextCatalog.GetString("Installing shared runtime package on device"),
                Skip     = () => !conf.AndroidUseSharedRuntime || list.IsCurrentRuntimeInstalled(runtimeVersion) ?
                           "" : null,
                Create = () => {
                    var pkg = MonoDroidFramework.SharedRuntimePackage;
                    if (!File.Exists(pkg))
                    {
                        var msg = GettextCatalog.GetString("Could not find shared runtime package file");
                        monitor.ReportError(msg, null);
                        LoggingService.LogError("{0} '{1}'", msg, pkg);
                        return(null);
                    }
                    return(toolbox.Install(device, pkg, monitor.Log, monitor.Log));
                },
                ErrorMessage = GettextCatalog.GetString("Failed to install shared runtime package")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName = GettextCatalog.GetString("Installing the platform framework"),
                Skip     = () => !conf.AndroidUseSharedRuntime || list.IsCurrentPlatformInstalled(apiLevel, runtimeVersion) ?
                           "" : null,
                Create = () => {
                    var platformApk = MonoDroidFramework.GetPlatformPackage(apiLevel);
                    if (!File.Exists(platformApk))
                    {
                        var msg = GettextCatalog.GetString("Could not find platform package file");
                        monitor.ReportError(msg, null);
                        LoggingService.LogError("{0} '{1}'", msg, platformApk);
                        return(null);
                    }
                    return(toolbox.Install(device, platformApk, monitor.Log, monitor.Log));
                },
                ErrorMessage = GettextCatalog.GetString("Failed to install the platform framework")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName     = GettextCatalog.GetString("Uninstalling old version of package"),
                Skip         = () => (!replaceIfExists || !list.ContainsPackage(packageName))? "" : null,
                Create       = () => toolbox.Uninstall(device, packageName, monitor.Log, monitor.Log),
                ErrorMessage = GettextCatalog.GetString("Failed to uninstall package")
            },
                                                     new ChainedAsyncOperation()
            {
                TaskName     = GettextCatalog.GetString("Waiting for packaging signing to complete"),
                Skip         = () => (signingOperation == null || signingOperation.IsCompleted) ? "" : null,
                Create       = () => signingOperation,
                ErrorMessage = GettextCatalog.GetString("Package signing failed"),
            },
                                                     new ChainedAsyncOperation()
            {
                Skip = () => (list.ContainsPackage(packageName) && !replaceIfExists)
                                                ? GettextCatalog.GetString("Package is already up to date") : null,
                TaskName     = GettextCatalog.GetString("Installing package"),
                Create       = () => toolbox.Install(device, packageFile, monitor.Log, monitor.Log),
                ErrorMessage = GettextCatalog.GetString("Failed to install package")
            }
                                                     );
        }