private static string GetAppDependencyPackageFileName(
            string packageFileName, 
            AppDependency depend, 
            IAppManifestInfo info)
        {
            var path1 = Path.Combine(Path.GetDirectoryName(packageFileName), "Dependencies");
            var str = Path.Combine(path1, info.ProcessorArchitecture);
            var strArray = new[]
                               {
                                   Path.GetDirectoryName(packageFileName), str, path1, Constants.WindowsPhoneApp81SDKRoot
                               };
            foreach (var directory in strArray)
            {
                var requirementInDirectory = FindMatchinDependencyRequirementInDirectory(
                    packageFileName, 
                    directory, 
                    depend);
                if (!string.IsNullOrEmpty(requirementInDirectory))
                {
                    return requirementInDirectory;
                }
            }

            return null;
        }
Exemplo n.º 2
0
        private static string GetAppDependencyPackageFileName(
            string packageFileName,
            AppDependency depend,
            IAppManifestInfo info)
        {
            var path1    = Path.Combine(Path.GetDirectoryName(packageFileName), "Dependencies");
            var str      = Path.Combine(path1, info.ProcessorArchitecture);
            var strArray = new[]
            {
                Path.GetDirectoryName(packageFileName), str, path1, Constants.WindowsPhoneApp81SDKRoot
            };

            foreach (var directory in strArray)
            {
                var requirementInDirectory = FindMatchinDependencyRequirementInDirectory(
                    packageFileName,
                    directory,
                    depend);
                if (!string.IsNullOrEmpty(requirementInDirectory))
                {
                    return(requirementInDirectory);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
 public static void InstallApplication(
     DeviceInfo deviceInfo, 
     IAppManifestInfo manifestInfo, 
     DeploymentOptions deploymentOptions, 
     string packageFile)
 {
     DeployApplication(DeployAppMode.Install, deviceInfo, manifestInfo, deploymentOptions, packageFile);
 }
Exemplo n.º 4
0
 public static void InstallApplication(
     DeviceInfo deviceInfo,
     IAppManifestInfo manifestInfo,
     DeploymentOptions deploymentOptions,
     string packageFile)
 {
     DeployApplication(DeployAppMode.Install, deviceInfo, manifestInfo, deploymentOptions, packageFile);
 }
Exemplo n.º 5
0
        public void Deploy(string appPath)
        {
            this.appManifestInfo = Utils.ReadAppManifestInfoFromPackage(appPath);

            GlobalOptions.LaunchAfterInstall = true;
            Utils.InstallApplication(this.deviceInfo, this.appManifestInfo, DeploymentOptions.None, appPath);

            Logger.Info("Successfully deployed using Microsoft.Phone.Tools.Deploy");
        }
Exemplo n.º 6
0
        internal static bool IsMdilFirst(TypeOfApp appType, IAppManifestInfo manifestInfo)
        {
            switch (appType)
            {
            case TypeOfApp.XAP:
                return(manifestInfo.PlatformVersion.Major == 8 && manifestInfo.PlatformVersion.Minor >= 1);

            case TypeOfApp.APPX:
            case TypeOfApp.APPXBUNDLE:
                return(true);

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 7
0
        internal static void ApplySideloadFlags(IAppManifestInfo manifestInfo, ref DeploymentOptions deploymentOptions)
        {
            if (manifestInfo.PackageType == PackageType.Main || manifestInfo.PackageType == PackageType.Bundle ||
                manifestInfo.PackageType == PackageType.UnknownAppx)
            {
                deploymentOptions |= DeploymentOptions.Sideload;
            }
            else
            {
                if (manifestInfo.PackageType != PackageType.Framework)
                {
                    return;
                }

                deploymentOptions &= ~DeploymentOptions.Sideload;
            }
        }
Exemplo n.º 8
0
        internal static string GenerateNDeployMdil(
            string packageFile,
            IRemoteApplication app,
            TypeOfApp appType,
            IAppManifestInfo appManifest)
        {
            var generateMdil = (IGenerateMDIL) new MDILGeneratorFromPackage(packageFile, appType, appManifest);

            generateMdil.GenerateMDILTask();
            if (app != null)
            {
                try
                {
                    app.UpdateInstalledFilesInfo(
                        generateMdil.MSILFileList.ToArray(),
                        generateMdil.RelativeMSILFileList.ToArray());
                    var num = app.UpdateInstalledFiles(
                        generateMdil.MDILFileList.ToArray(),
                        generateMdil.RelativeMDILFileList.ToArray());
                    if (num != 0)
                    {
                        throw new Exception(
                                  string.Format(Resources.MDILDeploymentFailure, num));
                    }
                }
                finally
                {
                    generateMdil.Cleanup();
                }
            }
            else
            {
                generateMdil.Cleanup();
            }

            return(generateMdil.RepackedPackage);
        }
Exemplo n.º 9
0
        internal static bool IsTargetApplicableforMdilGeneration(
            ConnectableDevice connectableDevice,
            Version deviceVersion,
            IAppManifestInfo info,
            string appFile)
        {
            switch (info.PackageType)
            {
            case PackageType.UnknownAppx:
                return(IsXapApplicableForMdilGeneration(connectableDevice, deviceVersion, info.IsNative, appFile));

            case PackageType.Main:
            case PackageType.Resource:
            case PackageType.Bundle:
                return(IsAppxApplicableForMdilGeneration(connectableDevice, deviceVersion));

            case PackageType.Framework:
                return(false);

            default:
                throw new NotImplementedException(
                          "MDIL generation applicability cannot be determined for unexpected file type.");
            }
        }
Exemplo n.º 10
0
        private static void DeployApplication(
            DeployAppMode mode, 
            DeviceInfo deviceInfo, 
            IAppManifestInfo manifestInfo, 
            DeploymentOptions deploymentOptions, 
            string packageFile, 
            bool disconnect = true)
        {
            if (PackageType.Framework != manifestInfo.PackageType && WinTrust.VerifyEmbeddedSignature(packageFile))
            {
                throw new Exception(
                    string.Format(
                        CultureInfo.CurrentUICulture, 
                        Resources.InvalidPackaging, 
                        new object[0]));
            }

            var connectableDevice =
                new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID).GetConnectableDevice(
                    deviceInfo.DeviceId);
            var device = connectableDevice.Connect(true);
            var systemInfo = device.GetSystemInfo();
            var deviceVersion = new Version(systemInfo.OSMajor, systemInfo.OSMinor);
            if (manifestInfo.PlatformVersion.CompareTo(deviceVersion) > 0)
            {
                device.Disconnect();
                throw new Exception(
                    string.Format(
                        CultureInfo.CurrentUICulture, 
                        Resources.XapNotSupportedOnDevice, 
                        new object[0]));
            }

            var flag = IsTargetApplicableforMdilGeneration(
                connectableDevice, 
                deviceVersion, 
                manifestInfo, 
                packageFile);
            ApplySideloadFlags(manifestInfo, ref deploymentOptions);
            if (mode == DeployAppMode.Install)
            {
                if (device.IsApplicationInstalled(manifestInfo.ProductId))
                {
                    if (manifestInfo.PackageType == PackageType.Framework)
                    {
                        return;
                    }

                    device.GetApplication(manifestInfo.ProductId).Uninstall();
                }

                foreach (var str in DependencyFinder.GetAppDependencyPackages(packageFile))
                {
                    var manifestInfo1 = ReadAppManifestInfoFromPackage(str);
                    DeployApplication(
                        DeployAppMode.Install, 
                        deviceInfo, 
                        manifestInfo1, 
                        DeploymentOptions.OptOutSD, 
                        str, 
                        false);
                }
            }

            var app = (IRemoteApplication)null;
            if (mode == DeployAppMode.Update)
            {
                app = device.GetApplication(manifestInfo.ProductId);
            }

            var typeOfApp = DetermineAppType(packageFile);
            var applicationGenre = ((int)deploymentOptions).ToString(CultureInfo.InvariantCulture);
            var iconPath = ((int)manifestInfo.PackageType).ToString(CultureInfo.InvariantCulture);
            switch (mode)
            {
                case DeployAppMode.Install:
                    break;
                case DeployAppMode.Update:
                    break;
            }

            var path = (string)null;
            try
            {
                if (IsMdilFirst(typeOfApp, manifestInfo))
                {
                    if (flag)
                    {
                        path = GenerateNDeployMdil(packageFile, null, typeOfApp, manifestInfo);
                        packageFile = path;
                    }

                    switch (mode)
                    {
                        case DeployAppMode.Install:
                            app = device.InstallApplication(
                                manifestInfo.ProductId, 
                                manifestInfo.ProductId, 
                                applicationGenre, 
                                iconPath, 
                                packageFile);
                            break;
                        case DeployAppMode.Update:
                            app.UpdateApplication(applicationGenre, iconPath, packageFile);
                            break;
                    }
                }
                else
                {
                    switch (mode)
                    {
                        case DeployAppMode.Install:
                            app = device.InstallApplication(
                                manifestInfo.ProductId, 
                                manifestInfo.ProductId, 
                                applicationGenre, 
                                iconPath, 
                                packageFile);
                            break;
                        case DeployAppMode.Update:
                            app.UpdateApplication(applicationGenre, iconPath, packageFile);
                            break;
                    }

                    if (flag)
                    {
                        path = GenerateNDeployMdil(packageFile, app, typeOfApp, manifestInfo);
                    }
                }
            }
            finally
            {
                if (!GlobalOptions.LeaveBehindOptimized && !string.IsNullOrWhiteSpace(path) && File.Exists(path))
                {
                    File.Delete(path);
                }
            }

            if (GlobalOptions.LaunchAfterInstall && app != null)
            {
                app.Launch();
            }

            if (!disconnect)
            {
                return;
            }

            device.Disconnect();
        }
Exemplo n.º 11
0
 internal static bool IsTargetApplicableforMdilGeneration(
     ConnectableDevice connectableDevice, 
     Version deviceVersion, 
     IAppManifestInfo info, 
     string appFile)
 {
     switch (info.PackageType)
     {
         case PackageType.UnknownAppx:
             return IsXapApplicableForMdilGeneration(connectableDevice, deviceVersion, info.IsNative, appFile);
         case PackageType.Main:
         case PackageType.Resource:
         case PackageType.Bundle:
             return IsAppxApplicableForMdilGeneration(connectableDevice, deviceVersion);
         case PackageType.Framework:
             return false;
         default:
             throw new NotImplementedException(
                 "MDIL generation applicability cannot be determined for unexpected file type.");
     }
 }
Exemplo n.º 12
0
 internal static bool IsMdilFirst(TypeOfApp appType, IAppManifestInfo manifestInfo)
 {
     switch (appType)
     {
         case TypeOfApp.XAP:
             return manifestInfo.PlatformVersion.Major == 8 && manifestInfo.PlatformVersion.Minor >= 1;
         case TypeOfApp.APPX:
         case TypeOfApp.APPXBUNDLE:
             return true;
         default:
             throw new NotImplementedException();
     }
 }
Exemplo n.º 13
0
        internal static string GenerateNDeployMdil(
            string packageFile, 
            IRemoteApplication app, 
            TypeOfApp appType, 
            IAppManifestInfo appManifest)
        {
            var generateMdil = (IGenerateMDIL)new MDILGeneratorFromPackage(packageFile, appType, appManifest);
            generateMdil.GenerateMDILTask();
            if (app != null)
            {
                try
                {
                    app.UpdateInstalledFilesInfo(
                        generateMdil.MSILFileList.ToArray(), 
                        generateMdil.RelativeMSILFileList.ToArray());
                    var num = app.UpdateInstalledFiles(
                        generateMdil.MDILFileList.ToArray(), 
                        generateMdil.RelativeMDILFileList.ToArray());
                    if (num != 0)
                    {
                        throw new Exception(
                            string.Format(Resources.MDILDeploymentFailure, num));
                    }
                }
                finally
                {
                    generateMdil.Cleanup();
                }
            }
            else
            {
                generateMdil.Cleanup();
            }

            return generateMdil.RepackedPackage;
        }
Exemplo n.º 14
0
        internal static void ApplySideloadFlags(IAppManifestInfo manifestInfo, ref DeploymentOptions deploymentOptions)
        {
            if (manifestInfo.PackageType == PackageType.Main || manifestInfo.PackageType == PackageType.Bundle
                || manifestInfo.PackageType == PackageType.UnknownAppx)
            {
                deploymentOptions |= DeploymentOptions.Sideload;
            }
            else
            {
                if (manifestInfo.PackageType != PackageType.Framework)
                {
                    return;
                }

                deploymentOptions &= ~DeploymentOptions.Sideload;
            }
        }
Exemplo n.º 15
0
        private static void DeployApplication(
            DeployAppMode mode,
            DeviceInfo deviceInfo,
            IAppManifestInfo manifestInfo,
            DeploymentOptions deploymentOptions,
            string packageFile,
            bool disconnect = true)
        {
            if (PackageType.Framework != manifestInfo.PackageType && WinTrust.VerifyEmbeddedSignature(packageFile))
            {
                throw new Exception(
                          string.Format(
                              CultureInfo.CurrentUICulture,
                              Resources.InvalidPackaging,
                              new object[0]));
            }

            var connectableDevice =
                new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID).GetConnectableDevice(
                    deviceInfo.DeviceId);
            var device        = connectableDevice.Connect(true);
            var systemInfo    = device.GetSystemInfo();
            var deviceVersion = new Version(systemInfo.OSMajor, systemInfo.OSMinor);

            if (manifestInfo.PlatformVersion.CompareTo(deviceVersion) > 0)
            {
                device.Disconnect();
                throw new Exception(
                          string.Format(
                              CultureInfo.CurrentUICulture,
                              Resources.XapNotSupportedOnDevice,
                              new object[0]));
            }

            var flag = IsTargetApplicableforMdilGeneration(
                connectableDevice,
                deviceVersion,
                manifestInfo,
                packageFile);

            ApplySideloadFlags(manifestInfo, ref deploymentOptions);
            if (mode == DeployAppMode.Install)
            {
                if (device.IsApplicationInstalled(manifestInfo.ProductId))
                {
                    if (manifestInfo.PackageType == PackageType.Framework)
                    {
                        return;
                    }

                    device.GetApplication(manifestInfo.ProductId).Uninstall();
                }

                foreach (var str in DependencyFinder.GetAppDependencyPackages(packageFile))
                {
                    var manifestInfo1 = ReadAppManifestInfoFromPackage(str);
                    DeployApplication(
                        DeployAppMode.Install,
                        deviceInfo,
                        manifestInfo1,
                        DeploymentOptions.OptOutSD,
                        str,
                        false);
                }
            }

            var app = (IRemoteApplication)null;

            if (mode == DeployAppMode.Update)
            {
                app = device.GetApplication(manifestInfo.ProductId);
            }

            var typeOfApp        = DetermineAppType(packageFile);
            var applicationGenre = ((int)deploymentOptions).ToString(CultureInfo.InvariantCulture);
            var iconPath         = ((int)manifestInfo.PackageType).ToString(CultureInfo.InvariantCulture);

            switch (mode)
            {
            case DeployAppMode.Install:
                break;

            case DeployAppMode.Update:
                break;
            }

            var path = (string)null;

            try
            {
                if (IsMdilFirst(typeOfApp, manifestInfo))
                {
                    if (flag)
                    {
                        path        = GenerateNDeployMdil(packageFile, null, typeOfApp, manifestInfo);
                        packageFile = path;
                    }

                    switch (mode)
                    {
                    case DeployAppMode.Install:
                        app = device.InstallApplication(
                            manifestInfo.ProductId,
                            manifestInfo.ProductId,
                            applicationGenre,
                            iconPath,
                            packageFile);
                        break;

                    case DeployAppMode.Update:
                        app.UpdateApplication(applicationGenre, iconPath, packageFile);
                        break;
                    }
                }
                else
                {
                    switch (mode)
                    {
                    case DeployAppMode.Install:
                        app = device.InstallApplication(
                            manifestInfo.ProductId,
                            manifestInfo.ProductId,
                            applicationGenre,
                            iconPath,
                            packageFile);
                        break;

                    case DeployAppMode.Update:
                        app.UpdateApplication(applicationGenre, iconPath, packageFile);
                        break;
                    }

                    if (flag)
                    {
                        path = GenerateNDeployMdil(packageFile, app, typeOfApp, manifestInfo);
                    }
                }
            }
            finally
            {
                if (!GlobalOptions.LeaveBehindOptimized && !string.IsNullOrWhiteSpace(path) && File.Exists(path))
                {
                    File.Delete(path);
                }
            }

            if (GlobalOptions.LaunchAfterInstall && app != null)
            {
                app.Launch();
            }

            if (!disconnect)
            {
                return;
            }

            device.Disconnect();
        }
Exemplo n.º 16
0
        /// <summary>
        /// Starts the controller.
        /// </summary>
        public void Start()
        {
            if (!string.IsNullOrEmpty(this.address) && !string.IsNullOrEmpty(this.port))
            {
                return;
            }

            Device device = this.FindDevice();

            if (device == null)
            {
                throw new WindowsPhoneDriverException(string.Format(CultureInfo.InvariantCulture, "Found no matching devices for name '{0}'", this.deviceName));
            }
            else
            {
                this.SendStatusUpdate("Connecting to device {0}.", device.Name);

                List <string> fileNames = new List <string>();
                if (!this.appPath.Equals(string.Empty))
                {
                    this.assemblyDirectory = Path.GetDirectoryName(this.appPath);
                    fileNames.Add(Path.GetFileName(this.appPath));
                }
                else
                {
                    this.assemblyDirectory = Path.GetDirectoryName(this.GetType().Assembly.Location);
                    fileNames.Add("WindowsPhoneDriverBrowser.xap");
                }
                string path = GetPackagePath(this.assemblyDirectory, fileNames);

                this.SendStatusUpdate("path: " + path);
                ApplicationArchiveInfo appInfo = ApplicationArchiveInfo.ReadApplicationInfo(path);

                Guid   applicationId = appInfo.ApplicationId.Value;
                string iconPath      = appInfo.ExtractIconFile();

                bool isConnectedToDevice = false;
                try
                {
                    device.Connect();
                    isConnectedToDevice = device.IsConnected();
                }
                catch (SmartDeviceException ex)
                {
                    this.SendStatusUpdate("WARNING! Exception encountered when connecting to device. HRESULT: {0:X}, message: {1}", ex.HResult, ex.Message);
                    System.Threading.Thread.Sleep(500);
                }

                if (!isConnectedToDevice)
                {
                    // TODO: Create connection mitigation routine.
                    this.SendStatusUpdate("WARNING! Was unable to connect to device!");
                }
                else
                {
                    if (path.EndsWith("xap"))
                    {
                        if (device.IsApplicationInstalled(applicationId))
                        {
                            this.SendStatusUpdate("Application already installed. Uninstalling..");
                            device.GetApplication(applicationId).Uninstall();
                        }
                        this.SendStatusUpdate("Installing application {0}.", path);
                        this.browserApplication = device.InstallApplication(applicationId, applicationId, "WindowsPhoneDriverBrowser", iconPath, path);
                    }
                    else
                    {
                        if (device.IsApplicationInstalled(applicationId))
                        {
                            this.SendStatusUpdate("Application already installed. Uninstalling..");
                            device.GetApplication(applicationId).Uninstall();
                        }
                        this.SendStatusUpdate("Installing application {0}.", path);
                        IAppManifestInfo  manifestInfo      = Utils.ReadAppManifestInfoFromPackage(this.appPath);
                        DeploymentOptions deploymentOptions = DeploymentOptions.None;
                        var devices    = Utils.GetDevices();
                        var utilDevice = devices.FirstOrDefault(d => d.ToString() == "Device");
                        Utils.InstallApplication(utilDevice, manifestInfo, deploymentOptions, this.appPath);
                    }
                }

                File.Delete(iconPath);
            }
        }