public static Package Load(IEnvironment environment, UriString packageFeed) { Package package = null; var filename = packageFeed.Filename.ToNPath(); if (!filename.IsInitialized || filename.IsRoot) { return(package); } var key = filename.FileNameWithoutExtension + "_updatelastCheckTime"; var now = DateTimeOffset.Now; NPath feed = environment.UserCachePath.Combine(packageFeed.Filename); if (!feed.FileExists() || now.Date > environment.UserSettings.Get <DateTimeOffset>(key).Date) { feed = new DownloadTask(TaskManager.Instance.Token, environment.FileSystem, packageFeed, environment.UserCachePath) .Catch(ex => { LogHelper.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed, ex.GetType().ToString(), ex.GetExceptionMessageShort()); return(true); }) .RunSynchronously(); if (feed.IsInitialized) { environment.UserSettings.Set <DateTimeOffset>(key, now); } } if (!feed.IsInitialized) { // try from assembly resources feed = AssemblyResources.ToFile(ResourceType.Platform, packageFeed.Filename, environment.UserCachePath, environment); } if (feed.IsInitialized) { try { package = feed.ReadAllText().FromJson <Package>(true, false); } catch (Exception ex) { LogHelper.Error(ex); } } return(package); }
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 void CheckForUpdates(IApplicationManager manager) { var download = new DownloadTask(manager.TaskManager.Token, manager.Environment.FileSystem, UpdateFeedUrl, manager.Environment.UserCachePath) .Catch(ex => { LogHelper.Warning(@"Error downloading update check:{0} ""{1}""", UpdateFeedUrl, ex.GetExceptionMessageShort()); return(true); }); download.OnEnd += (thisTask, result, success, exception) => { if (success) { try { Package package = result.ReadAllText().FromJson <Package>(lowerCase: true, onlyPublic: false); TheVersion current = TheVersion.Parse(ApplicationInfo.Version); TheVersion newVersion = package.Version; var versionToSkip = manager.UserSettings.Get <TheVersion>(Constants.SkipVersionKey); if (versionToSkip == newVersion) { LogHelper.Info("Skipping GitHub for Unity update v" + newVersion); return; } if (newVersion <= current) { LogHelper.Trace("Skipping GitHub for Unity update v" + newVersion + ", we already have it"); return; } manager.TaskManager.RunInUI(() => { NotifyOfNewUpdate(manager, current, package); }); } catch (Exception ex) { LogHelper.GetLogger <UpdateCheckWindow>().Error(ex); } } }; download.Start(); }
public void QueueDownload(UriString url, NPath targetDirectory, string filename = null, int retryCount = 0) { var download = new DownloadTask(Token, fileSystem, url, targetDirectory, filename, retryCount); download.OnStart += t => OnDownloadStart?.Invoke(((DownloadTask)t).Url); download.OnEnd += (t, res, s, ex) => { if (s) { OnDownloadComplete?.Invoke(((DownloadTask)t).Url, res); } else { OnDownloadFailed?.Invoke(((DownloadTask)t).Url, ex); } }; // queue after hooking up events so OnDownload* gets called first Queue(download); }
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); }