Пример #1
0
 public DeploymentOperations(bool localInstall = false)
 {
     GitHubOperations  = new GitHubOperations();
     ServiceOperations = new ServiceOperations();
     _localInstall     = localInstall;
     _logFilename      = Path.Combine(localInstall ? Directory.GetCurrentDirectory() : Path.GetTempPath(), "LMS.Setup.log");
     _setupFilename    = Path.Combine(localInstall ? Directory.GetCurrentDirectory() : Path.GetTempPath(), "LMS.Setup.exe");
 }
Пример #2
0
        private async Task UpdateRequired(Release latestRelease)
        {
            Log.Information("Update required!");

            Log.Information("Getting the download url.");
            string url = await GitHubOperations.GetDownloadUrlAsync(latestRelease);

            Log.Information("Download started. This could take some time...");
            IApiResponse <byte[]> response = await GitHubOperations.DownloadLatestRelease(url);

            Log.Information("Saving file to disk.");
            SaveLatestRelease(response);

            ServiceOperations.Stop();

            Log.Information("Installation started.");
            InstallLatestRelease();

            ServiceOperations.Start();
        }
Пример #3
0
        public async Task StartAsync()
        {
            Release latestRelease = null;

            SemVer.Version latestVersion;
            if (!_localInstall)
            {
                if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "LMS.Setup.exe")))
                {
                    Log.Debug("Setup file exists. let's go ahead and remove that.");
                    File.Delete("LMS.Setup.exe");
                }

                latestRelease = await GitHubOperations.GetLatestRelease();

                latestVersion = GitHubOperations.GetLatestVersion(latestRelease);
            }
            else
            {
                latestVersion = new SemVer.Version(FileVersionInfo.GetVersionInfo(_setupFilename).ProductVersion);
            }


            SemVer.Version currentVersion = GetCurrentInstalledVersion();

            Log.Information($"Installed: {currentVersion}    Available: {latestVersion}");

            if (currentVersion.CompareTo(latestVersion) < 0)
            {
                if (currentVersion.Equals(new SemVer.Version(1, 0, 0)))
                {
                    Log.Debug("New installation.");
                    if (_localInstall)
                    {
                        UpdateRequired();
                    }
                    else
                    {
                        await UpdateRequired(latestRelease);
                    }

                    return;
                }

                Log.Debug("Existing installation.");
                Uninstall();
                if (_localInstall)
                {
                    UpdateRequired();
                }
                else
                {
                    await UpdateRequired(latestRelease);
                }
                return;
            }

            if (currentVersion.CompareTo(latestVersion) > 0)
            {
                Log.Warning("The installed version is newer than what is currently available.");
                Log.Warning("I'm going to uninstall the program.");

                Uninstall();
                if (_localInstall)
                {
                    UpdateRequired();
                }
                else
                {
                    await UpdateRequired(latestRelease);
                }
                return;
            }

            if (currentVersion.CompareTo(latestVersion) == 0)
            {
                Log.Information("No update is required at this time.");
                Log.Information("Checking installation folder integrity.");
                if (File.Exists(Path.Combine(GetProgramFilesPath(), "License Monitoring System", "LMS.exe")))
                {
                    Log.Information("All looks good!");
                    return;
                }

                Log.Warning("Executable is missing from the installation folder.");
                Log.Warning("Attempting to reinstall the application.");

                Uninstall();
                if (_localInstall)
                {
                    UpdateRequired();
                }
                else
                {
                    await UpdateRequired(latestRelease);
                }
            }
        }