示例#1
0
        public void DotNetCoreInstallSubroutine()
        {
            // Thread signal.
            bool complete = false;

            // Webclient
            WebClient webClient = new WebClient();

            // Remember the directory
            string dotNetInstallerDownloadLink = DotNetCore.GetDownloadLinkFromArch();

            string[] brokenUrlStrings            = dotNetInstallerDownloadLink.Split('/');
            string   dotNetInstallerFilename     = brokenUrlStrings[brokenUrlStrings.Length - 1];
            var      dotNetInstallerDownloadPath = Path.Combine(Program.InstallLocation, dotNetInstallerFilename);

            // Tell the user what's going to happen
            EasyLog(string.Format("Downloading {0} from {1}",
                                  dotNetInstallerFilename,
                                  dotNetInstallerDownloadLink
                                  ));

            // Start the stopwatch.
            _timeStarted = DateTime.Now;

            // Download Percent Changed Event - Update the progress bar
            webClient.DownloadProgressChanged += (senderChild, eChild) =>
            {
                OverallProgress.Maximum = int.Parse(eChild.TotalBytesToReceive.ToString());
                OverallProgress.Value   = int.Parse(eChild.BytesReceived.ToString());
                ProgressText.Text       = string.Format("Downloaded {0}/{1} MiB @ {2} KiB/s",
                                                        Math.Round(eChild.BytesReceived / Math.Pow(1024, 2), 2),
                                                        Math.Round(eChild.TotalBytesToReceive / Math.Pow(1024, 2), 2),
                                                        Math.Round(eChild.BytesReceived / (DateTime.Now - _timeStarted).TotalSeconds / Math.Pow(1024, 1), 2
                                                                   )
                                                        );
            };

            // Download Complete Event
            webClient.DownloadFileCompleted += (senderChild, eChild) =>
            {
                // Tell the user where the file was saved.
                EasyLog(string.Format("{0} was saved to {1}", dotNetInstallerFilename, dotNetInstallerDownloadPath));

                // TODO: INSTALL SILENTLY
                EasyLog("Installing Microsoft Dotnet Core Dependency...");
                var microsoftVisualCInstaller = Process.Start(dotNetInstallerDownloadPath, "/install /passive /norestart /q");
                microsoftVisualCInstaller.WaitForExit();

                // Change the thread signal.
                complete = true;
            };

            // Download the file asyncronously.
            webClient.DownloadFileAsync(new Uri(dotNetInstallerDownloadLink), dotNetInstallerDownloadPath);

            while (webClient.IsBusy || !complete)
            {
                Thread.Sleep(1);
            }
        }
 /// <summary>
 /// Create the service
 /// </summary>
 public void Create()
 {
     Process.Start(
         GetExecutablePath(),
         string.Format("install \"spectero.daemon\" \"{0}\" \"{1}\"",
                       DotNetCore.GetDotnetPath(),
                       GetBinaryExpectedPath()
                       )
         );
 }
示例#3
0
        /// <summary>
        /// The thread that will do most of the logic for the form.
        /// </summary>
        public void Worker()
        {
            // Store the download link in an easy to access variable
            _downloadLink = Program.ReleaseInformation["versions"][Program.Version]["download"].ToString();

            // Genereate an absolute installation path specifically so we can store the daemon here.
            _absoluteInstallationPath = Path.Combine(Program.InstallLocation, "Daemon");
            _installerPath            = Path.Combine(Program.InstallLocation, "Installer.exe");

            // Create the base path and absolute path.
            if (!Directory.Exists(Program.InstallLocation))
            {
                Directory.CreateDirectory(Program.InstallLocation);
            }
            if (!Directory.Exists(_absoluteInstallationPath))
            {
                Directory.CreateDirectory(_absoluteInstallationPath);
            }

            // Check if we're the SxS installer - if not, then copy.
            if (Assembly.GetExecutingAssembly().Location != _installerPath)
            {
                File.Copy(Assembly.GetExecutingAssembly().Location, _installerPath, true);
            }

            // Create shorthand variables to use rather than redundant functions.
            _zipFilename     = Program.Version + ".zip";
            _absoluteZipPath = Path.Combine(Program.InstallLocation, _zipFilename);

            // Download DNCRTs if it doesn't exist or if the old version is obsolete.
            if (!DotNetCore.Exists())
            {
                DotNetCoreInstallSubroutine();
            }
            else if (!DotNetCore.IsVersionCompatable())
            {
                DotNetCoreInstallSubroutine();
            }

            // Download the project files.
            SpecteroDownloaderSubworker();

            // Check service things.
            try
            {
                if (Program.CreateService)
                {
                    NonSuckingServiceManagerSubworker();
                    ServiceManager sm = new ServiceManager(nssmInstallPath);
                    if (sm.Exists())
                    {
                        EasyLog("Service already exists - will be updated.");
                        sm.Stop();
                        EasyLog("Stopped old service...");
                        // Update the service
                        sm.Delete();
                        EasyLog("The old spectero.daemon service has been deleted.");
                    }
                    // Create the service.
                    sm.Create();
                    EasyLog("Created widnows service: spectero.daemon.");
                    sm.Start();
                }
            }
            catch (Exception exception)
            {
                EasyLog("An exception occured while trying to create the service.\n" + exception);
            }

            // Try to add to path
            try
            {
                // Check to see if we should add to the path of the system.
                if (Program.AddToPath)
                {
                    AddToPath(Path.Combine(_absoluteInstallationPath, "latest\\cli\\Tooling"));
                }
            }
            catch (Exception exception)
            {
                EasyLog("An exception occured while adding to PATH.\n" + exception);
            }

            // Try to create a symbolic link.
            try
            {
                Program.CreateSymbolicLink(
                    Path.Combine(_absoluteInstallationPath, "latest"),
                    Path.Combine(_absoluteInstallationPath, Program.Version),
                    Program.SymbolicLink.Directory
                    );
            }
            catch (Exception exception)
            {
                EasyLog("An exception occured while creating a symbolic link.\n" + exception);
            }

            // Disable the cancel button.
            ExitButton.Enabled = false;

            // Modify registry
            EnableFirewallFormwarding();

            // Add the path to the installer to add/remove page in control panel.
            var winins = new WindowsInstaller();

            if (winins.Exists())
            {
                winins.CreateEntry(_installerPath);
            }

            // Install OpenVPN.
            InstallOpenVPN();

            // Set markers in registry
            CreateRegistryEntry();

            // Set the environment state
            SetASPEnvironment();

            // Mark as complete and enable the progress bar
            EasyLog("Installation is complete.");
            NextButton.Enabled = true;
        }