Пример #1
0
        private GitInstallationState CheckForGitUpdates(GitInstallationState state)
        {
            if (state.IsCustomGitPath)
            {
                return(state);
            }

            if (state.GitInstallationPath != installDetails.GitInstallationPath)
            {
                return(state);
            }

            state.GitPackage = DugiteReleaseManifest.Load(installDetails.GitManifest, GitInstallDetails.GitPackageFeed, environment);
            if (state.GitPackage == null)
            {
                return(state);
            }

            state.GitIsValid = state.GitVersion >= state.GitPackage.Version;
            if (!state.GitIsValid)
            {
                Logger.Trace($"{installDetails.GitExecutablePath} is out of date");
            }

            return(state);
        }
        public static DugiteReleaseManifest Load(ITaskManager taskManager, SPath localCacheFile,
                                                 UriString packageFeed, IGitEnvironment environment,
                                                 bool alwaysDownload = false)
        {
            DugiteReleaseManifest package = null;
            var filename = localCacheFile.FileName;
            var cacheDir = localCacheFile.Parent;
            var key      = localCacheFile.FileNameWithoutExtension + "_updatelastCheckTime";
            var now      = DateTimeOffset.Now;

            if (!localCacheFile.FileExists() ||
                (alwaysDownload || now.Date > environment.UserSettings.Get <DateTimeOffset>(key).Date))
            {
                var result = new DownloadTask(taskManager, packageFeed,
                                              localCacheFile.Parent, filename)
                             .Catch(ex => {
                    Logger.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed,
                                   ex.GetType().ToString(), ex.GetExceptionMessageShort());
                    return(true);
                }).RunSynchronously();
                localCacheFile = result.ToSPath();
                if (localCacheFile.IsInitialized && !alwaysDownload)
                {
                    environment.UserSettings.Set <DateTimeOffset>(key, now);
                }
            }

            if (!localCacheFile.IsInitialized)
            {
                // try from assembly resources
                localCacheFile = AssemblyResources.ToFile(ResourceType.Platform, filename, cacheDir, environment);
            }

            if (localCacheFile.IsInitialized)
            {
                try
                {
                    package = Load(taskManager, localCacheFile, cacheDir, environment);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
            }
            return(package);
        }
        public static DugiteReleaseManifest Load(NPath localCacheFile, UriString packageFeed, IEnvironment environment)
        {
            DugiteReleaseManifest package = null;
            //NPath localCacheFeed = environment.UserCachePath.Combine("embedded-git.json");
            var filename = localCacheFile.FileName;
            var key      = localCacheFile.FileNameWithoutExtension + "_updatelastCheckTime";
            var now      = DateTimeOffset.Now;

            if (!localCacheFile.FileExists() || now.Date > environment.UserSettings.Get <DateTimeOffset>(key).Date)
            {
                localCacheFile = new DownloadTask(TaskManager.Instance.Token, environment.FileSystem, packageFeed, environment.UserCachePath, filename)
                                 .Catch(ex => {
                    LogHelper.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed, ex.GetType().ToString(), ex.GetExceptionMessageShort());
                    return(true);
                })
                                 .RunSynchronously();

                if (localCacheFile.IsInitialized)
                {
                    environment.UserSettings.Set <DateTimeOffset>(key, now);
                }
            }

            if (!localCacheFile.IsInitialized)
            {
                // try from assembly resources
                localCacheFile = AssemblyResources.ToFile(ResourceType.Platform, packageFeed.Filename, environment.UserCachePath, environment);
            }

            if (localCacheFile.IsInitialized)
            {
                try
                {
                    package = Load(localCacheFile, environment);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
            }
            return(package);
        }