Beispiel #1
0
        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            if (!Directory.Exists(PackagePath))
            {
                MessageBox.Show("Specified path doesn't exist! Please select again!",
                                "Path doesn't exist",
                                MessageBoxButton.OK,
                                MessageBoxImage.Stop);
                return;
            }

            switch (PackageName)
            {
            case EnvironmentChecker.VcpkgName:
                if (!EnvironmentChecker.CheckVcpkg(PackagePath))
                {
                    MessageBox.Show("vcpkg doesn't exist in specified path! Please select again or press 'Download' to download it !",
                                    "vcpkg doesn't exist",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Stop);
                    return;
                }
                Properties.Settings.Default.vcpkg_path = PackagePath;
                DialogResult = true;
                Close();
                break;
            }
        }
Beispiel #2
0
        private void Download_Click(object sender, RoutedEventArgs e)
        {
            switch (PackageName)
            {
            case EnvironmentChecker.GitName:
                Process.Start("https://git-scm.com/download/win");
                break;

            case EnvironmentChecker.VcpkgName:
                if (!Directory.Exists(PackagePath))
                {
                    MessageBox.Show("Specified path is invalid or missing! Please select path to download vcpkg!",
                                    "Select vcpkg download path",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Stop);
                    return;
                }

                var clone = Process.Start("git", "clone https://github.com/Microsoft/vcpkg.git " + PackagePath);
                clone.WaitForExit();
                switch (clone.ExitCode)
                {
                case 0:
                    if (!EnvironmentChecker.CheckVcpkg(PackagePath))
                    {
                        MessageBox.Show("vcpkg dosen't exist in clone directory! Please check you git configuration",
                                        "vcpkg is not donwloaded",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Stop);
                        return;
                    }
                    Properties.Settings.Default.vcpkg_path = PackagePath;
                    DialogResult = true;
                    Close();
                    break;

                case 128:
                    MessageBox.Show("Downloading is terminated because the specified directory is not empty. Please select a null folder to use vcpkg!",
                                    "Specified directory is not empty",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Stop);
                    return;

                default:
                    MessageBox.Show($"Git exited with code {clone.ExitCode}!",
                                    "Unknown Error",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Stop);
                    return;
                }
                break;
            }
        }
Beispiel #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            Window dummy; // Prevent application exit when FindpackageDialog is closed
            var    settings = Vcpkg.Properties.Settings.Default;

#if DEBUG
            settings.Reset();
#endif

            // Check if Git is installed
            var gitPath = EnvironmentChecker.GetGit();
            if (string.IsNullOrEmpty(gitPath))
            {
                dummy = new Window();
                if (!new FindPackageDialog(EnvironmentChecker.GitName).ShowDialog() ?? false)
                {
                    Environment.Exit(1);
                }
            }

            // Check if Vcpkg is downloaded
            var getVcpkg = string.IsNullOrEmpty(settings.vcpkg_path);
            if (!getVcpkg && !EnvironmentChecker.CheckVcpkg(settings.vcpkg_path))
            {
                getVcpkg = true;
            }

            if (getVcpkg)
            {
                var vcpkgPath = EnvironmentChecker.GetVcpkg();
                if (string.IsNullOrEmpty(vcpkgPath))
                {
                    dummy = new Window();
                    if (!new FindPackageDialog(EnvironmentChecker.VcpkgName).ShowDialog() ?? false)
                    {
                        Environment.Exit(1);
                    }
                    vcpkgPath = Vcpkg.Properties.Settings.Default.vcpkg_path;
                }
                else
                {
                    Vcpkg.Properties.Settings.Default.vcpkg_path = vcpkgPath;
                }
            }

            // Check if Vcpkg is updated and compiled
            bool compile = false;
            var  git     = new Process();
            git.StartInfo.FileName               = "git";
            git.StartInfo.WorkingDirectory       = settings.vcpkg_path;
            git.StartInfo.UseShellExecute        = false;
            git.StartInfo.CreateNoWindow         = true;
            git.StartInfo.RedirectStandardOutput = true;

            git.StartInfo.Arguments = "status";
            git.Start(); git.WaitForExit();
            var output = git.StandardOutput.ReadToEnd();
            if (output.IndexOf("branch is behind") >= 0)
            {
                if (MessageBox.Show("Your vcpkg repository in not up-to-date, would you like to update and recompile vcpkg?",
                                    "Update vcpkg",
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    git.StartInfo.Arguments = "pull";
                    git.Start(); git.WaitForExit();
                    compile = true;
                }
            }

            if (!compile && !EnvironmentChecker.CheckVcpkgCompiled(settings.vcpkg_path))
            {
                MessageBox.Show("Your vcpkg is not initialized. Compiling is going to be executed.",
                                "Initialize vcpkg",
                                MessageBoxButton.OK,
                                MessageBoxImage.Information);
                compile = true;
            }

            while (compile)
            {
                // Parsed from boostrap.bat
                var pspath     = Path.Combine(settings.vcpkg_path, "scripts\\bootstrap.ps1");
                var initialize = Process.Start("powershell.exe", "-NoProfile -ExecutionPolicy Bypass \"& {& '" + pspath + "'}\"");
                initialize.WaitForExit();

                if (!EnvironmentChecker.CheckVcpkgCompiled(settings.vcpkg_path))
                {
                    if (MessageBox.Show("vcpkg is not initialized successfully. Would you like to retry? If not, then this application will be terminated.",
                                        "Initialize unsuccessfully",
                                        MessageBoxButton.YesNo,
                                        MessageBoxImage.Warning) == MessageBoxResult.No)
                    {
                        compile = false;
                    }
                }
                else
                {
                    compile = false;
                }
            }

            // Set default values
            Properties.Add(nameof(VcpkgRootPath), Vcpkg.Properties.Settings.Default.vcpkg_path);
            Properties.Add(nameof(Triplet), DefaultTriplet);
            Properties.Add(nameof(DebugVcpkg), false);
            Properties.Add(nameof(DryRun), false);
        }