Пример #1
0
 private void WorkerThread()
 {
     try
     {
         bool uninstall;
         lock (CancelPendingLock)
         {
             uninstall = uninstallMode;
         }
         InstallWorker installWorker = new InstallWorker();
         if (uninstall)
         {
             installWorker.PerformUninstall(WorkerThreadComplete, WorkerThreadProgress, WorkerThreadAllowCancel, WorkerThreadCancelPending);
         }
         else
         {
             installWorker.PerformInstall(WorkerThreadComplete, WorkerThreadProgress, WorkerThreadAllowCancel, WorkerThreadCancelPending);
         }
     }
     catch (Exception e)
     {
         if (e is PythonPackageInstallException || e is PythonPackageUninstallException)
         {
             InstallLogger.Log(e.Message);
         }
         else
         {
             InstallLogger.Log(string.Format("Installation Error:\n{0}", e.ToString()));
         }
         WorkerThreadFailed();
     }
 }
Пример #2
0
        public static void InstallPythonPackage(string PythonPath, string PackagePath)
        {
            string packagePath = PackagePath;

            if (!File.Exists(packagePath))
            {
                packagePath = Path.Combine(Path.GetDirectoryName(WindowsHelpers.GetApplicationPath()), packagePath);
                if (!File.Exists(packagePath))
                {
                    throw new InvalidOperationException(string.Format("Python Package {0} not found", PackagePath));
                }
            }
            SilentProcess.StdoutDataCapture dataCapture = new SilentProcess.StdoutDataCapture();
            SilentProcess process = SilentProcess.StartConsoleProcessSilently(
                PythonPath,
                string.Format("-m pip install --no-index {0}", packagePath),
                dataCapture.DataReceivedHandler
                );

            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                InstallLogger.Log(dataCapture.GetData());
                throw new PythonPackageInstallException(string.Format("Install of package {0} failed", PackagePath));
            }
        }
Пример #3
0
        public static void UninstallPythonPackage(string PythonPath, string PackageName)
        {
            SilentProcess.StdoutDataCapture dataCapture = new SilentProcess.StdoutDataCapture();
            SilentProcess process = SilentProcess.StartConsoleProcessSilently(
                PythonPath,
                string.Format("-m pip uninstall -y {0}", PackageName),
                dataCapture.DataReceivedHandler
                );

            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                InstallLogger.Log(dataCapture.GetData());
                throw new PythonPackageUninstallException(string.Format("Uninstall of package {0} failed", PackageName));
            }
        }
Пример #4
0
        public static List <PythonVersion> GetInstalledPythonVersions()
        {
            List <PythonVersion>     PythonVersions         = new List <PythonVersion>();
            List <Tuple <int, int> > RegistryPythonVersions = EnumeratePythonVersionsInRegistry();
            string pyLauncherPath = GetFullPath("py.exe");

            if (pyLauncherPath != null)
            {
                PythonVersions.AddRange(EnumeratePythonVersionsUsingPyLauncher(pyLauncherPath));
            }
            foreach (Tuple <int, int> RegistryPyVersion in RegistryPythonVersions)
            {
                bool FoundVersion = false;
                foreach (PythonVersion PyVersion in PythonVersions)
                {
                    if ((PyVersion.Major == RegistryPyVersion.Item1) && (PyVersion.Minor == RegistryPyVersion.Item2))
                    {
                        FoundVersion = true;
                        break;
                    }
                }
                if (!FoundVersion)
                {
                    try
                    {
                        int Major;
                        int Minor;
                        int Bugfix;
                        GetPythonVersionFromPythonPath(FindPythonInRegistry(RegistryPyVersion.Item1, RegistryPyVersion.Item2, false), out Major, out Minor, out Bugfix);
                        PythonVersions.Add(new PythonVersion(Major, Minor, Bugfix));
                    }
                    catch (Exception e)
                    {
                        InstallLogger.Log(string.Format("Unable to detect bugfix number for Python version {0}.{1}:\n{2}", RegistryPyVersion.Item1, RegistryPyVersion.Item2, e.ToString()));
                    }
                }
            }
            foreach (PythonVersion pythonVersion in PythonVersions)
            {
                InstallLogger.Log(string.Format("Found Python {0}", pythonVersion));
            }
            return(PythonVersions);
        }
Пример #5
0
 private void WorkerThreadFailed()
 {
     InstallLogger.Log("Installation Failed.");
     Dispatcher.BeginInvoke(new Action(delegate()
     {
         ExitCode    = 1;
         InstallDone = true;
         InstallProgress.IsIndeterminate = false;
         InstallProgress.Value           = 0;
         if (PassiveMode)
         {
             CloseWindow();
         }
         else
         {
             MessageBox.Show("Installation Failed.", "Installation Error", MessageBoxButton.OK, MessageBoxImage.Error);
             CancelButton.IsEnabled = true;
         }
     }));
 }
Пример #6
0
        public static List <PythonPackage> GetInstalledPythonPackages(string PythonPath)
        {
            List <PythonPackage> PythonPackages = new List <PythonPackage>();

            SilentProcess.StdoutDataCapture dataCapture = new SilentProcess.StdoutDataCapture();
            SilentProcess process = SilentProcess.StartConsoleProcessSilently(PythonPath, "-m pip list --format=\"json\" --no-index", dataCapture.DataReceivedHandler);

            process.WaitForExit();
            bool TryLegacy = true;

            if (process.ExitCode == 0)
            {
                try
                {
                    PythonPackages = ParseJsonPipList(SanitizePipOutput(dataCapture.GetData()));
                    TryLegacy      = false;
                }
                catch (Exception e)
                {
                    InstallLogger.Log("Error occurred while trying to parse pip JSON:");
                    InstallLogger.Log(e.ToString());
                    InstallLogger.Log("Falling back to legacy mode");
                }
            }
            if (TryLegacy)
            {
                //
                // Older versions of pip don't support the --format flag, parse the legacy format
                //
                dataCapture = new SilentProcess.StdoutDataCapture();
                process     = SilentProcess.StartConsoleProcessSilently(PythonPath, "-m pip list --no-index", dataCapture.DataReceivedHandler);
                process.WaitForExit();
                if (process.ExitCode == 0)
                {
                    PythonPackages = ParseLegacyPipList(SanitizePipOutput(dataCapture.GetData()));
                }
            }
            return(PythonPackages);
        }
Пример #7
0
        private void CheckForVendorCustomizedEdkRepoAlreadyInstalled(bool Passive)
        {
            RegistryKey VendorUninstallKey;

            if (FoundVendorCustomizedEdkRepoAlreadyInstalled(out VendorUninstallKey))
            {
                string ProductName     = InstallerStrings.ProductName;
                string DisplayName     = VendorUninstallKey.GetValue("DisplayName").ToString();
                string UninstallString = string.Format("{0} /Passive", VendorUninstallKey.GetValue("UninstallString"));
                if (Passive)
                {
                    InstallLogger.Log(string.Format("{0} is a third party version of {1}. {0} is already installed.", DisplayName, ProductName));
                    InstallLogger.Log(string.Format("To install this version of {1}, {0} must be uninstalled first.", DisplayName, ProductName));
                    SilentProcess p = SilentProcess.StartConsoleProcessSilently("cmd.exe", string.Format("/S /C \"{0}\"", UninstallString));
                    p.WaitForExit();
                    Thread.Sleep(4000);
                }
                else
                {
                    MessageBoxResult Uninstall = MessageBox.Show(
                        string.Format("{0} is a third party version of {1}, {0} is already installed. To install this version of {1}, {0} must be uninstalled first.\r\n\r\nUninstall {0} now?", DisplayName, ProductName),
                        InstallerStrings.InstallerName,
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Exclamation,
                        MessageBoxResult.No
                        );
                    if (Uninstall == MessageBoxResult.Yes)
                    {
                        SilentProcess p = SilentProcess.StartConsoleProcessSilently("cmd.exe", string.Format("/S /C \"{0}\"", UninstallString));
                        p.WaitForExit();
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        Application.Current.Shutdown(0);
                    }
                }
            }
        }
Пример #8
0
        private static List <PythonPackage> ParseJsonPipList(string PipJsonList)
        {
            List <PythonPackage> PythonPackages = new List <PythonPackage>();
            JSONNode             json           = JSON.Parse(PipJsonList);

            if (json == null)
            {
                throw new ArgumentException("Pip list JSON failed to parse.");
            }
            if (!json.IsArray)
            {
                throw new ArgumentException(string.Format("Pip list root JSON type is not list type"));
            }
            JSONArray array = json.AsArray;

            foreach (JSONNode node in array)
            {
                if (!node.IsObject)
                {
                    InstallLogger.Log(string.Format("Found unexpected json node {0}", node.Value));
                    continue;
                }
                Dictionary <string, JSONNode> jsonObject = node.Linq.ToDictionary(x => x.Key, x => x.Value);
                if (!jsonObject.ContainsKey("name") ||
                    !jsonObject.ContainsKey("version"))
                {
                    InstallLogger.Log(string.Format("Found unexpected json node {0}", node.Value));
                    continue;
                }
                string        versionString = jsonObject["version"].Value;
                PythonVersion version       = new PythonVersion(0, 0, 0);
                string        pattern       = @"(\d+)\.(\d+)\.(\d+)";
                Match         match         = Regex.Match(versionString, pattern);
                if (match.Success)
                {
                    version = new PythonVersion(Int32.Parse(match.Groups[1].Value), Int32.Parse(match.Groups[2].Value), Int32.Parse(match.Groups[3].Value));
                }
                else
                {
                    pattern = @"(\d+)\.(\d+)";
                    match   = Regex.Match(versionString, pattern);
                    if (match.Success)
                    {
                        version = new PythonVersion(Int32.Parse(match.Groups[1].Value), Int32.Parse(match.Groups[2].Value), 0);
                    }
                    else
                    {
                        pattern = @"(\d+)";
                        match   = Regex.Match(versionString, pattern);
                        if (match.Success)
                        {
                            version = new PythonVersion(Int32.Parse(match.Groups[1].Value), 0, 0);
                        }
                    }
                }
                PythonPackage package = new PythonPackage();
                package.Name    = jsonObject["name"].Value;
                package.Version = version;
                PythonPackages.Add(package);
            }

            return(PythonPackages);
        }
Пример #9
0
        //
        // Note: If one creates a custom version of EdkRepo using this mechanism,
        // be sure to make a new ProductCode and add it to InstallerStrings.KnownVendorCustomizerProductCodes
        //
        private void LoadVendorCustomizer(bool Passive)
        {
            string   path             = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            Assembly VendorPlugin     = null;
            string   VendorPluginPath = string.Empty;

            foreach (string file in Directory.GetFiles(path))
            {
                if (Path.GetFileName(file).Equals("TianoCore.EdkRepoInstaller.VendorCustomizer.dll",
                                                  StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        VendorPlugin     = Assembly.LoadFile(file);
                        VendorPluginPath = file;
                    }
                    catch (Exception e)
                    {
                        VendorPlugin = null;
                        InstallLogger.Log(string.Format("Unable to load vendor customizer: {0}\r\n{1}", file, e.ToString()));
                        if (!Passive)
                        {
                            MessageBox.Show(
                                string.Format("Unable to load vendor customizer: {0}\r\n{1}", file, e.ToString()),
                                InstallerStrings.InstallerName,
                                MessageBoxButton.OK,
                                MessageBoxImage.Error
                                );
                        }
                        Application.Current.Shutdown(1);
                    }
                    break;
                }
            }
            if (VendorPlugin != null)
            {
                try
                {
                    bool ObjectCreated = false;
                    foreach (Type t in VendorPlugin.GetExportedTypes())
                    {
                        IEnumerable <object> attributes = t.GetCustomAttributes(true);
                        foreach (object attribute in attributes)
                        {
                            if (attribute.GetType().Name == "EdkRepoInstallerVendorCustomizerAttribute")
                            {
                                VendorCustomizer.VendorCustomizerObject = Activator.CreateInstance(t);
                                ObjectCreated = true;
                                if (string.IsNullOrEmpty(VendorPluginPath))
                                {
                                    throw new ArgumentException("VendorPluginPath is empty");
                                }
                                VendorCustomizer.VendorPluginPath = VendorPluginPath;
                                break;
                            }
                        }
                        if (ObjectCreated)
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    VendorPlugin = null;
                    InstallLogger.Log(string.Format("Unable to load vendor customizer\r\n{0}", e.ToString()));
                    if (!Passive)
                    {
                        MessageBox.Show(
                            string.Format("Unable to load vendor customizer\r\n{0}", e.ToString()),
                            InstallerStrings.InstallerName,
                            MessageBoxButton.OK,
                            MessageBoxImage.Error
                            );
                    }
                    Application.Current.Shutdown(1);
                }
            }
        }