private async Task LoadWorkshopItems(bool loadFromCacheFile) { var cursor = this.Cursor; try { Application.Current.Dispatcher.Invoke(() => this.Cursor = System.Windows.Input.Cursors.Wait); await Task.Delay(500); WorkshopFileDetailResponse localCache = null; WorkshopFileDetailResponse steamCache = null; await Task.Run(() => { var file = Path.Combine(Config.Default.DataDir, _isSotF ? Config.Default.WorkshopCacheFile_SotF : Config.Default.WorkshopCacheFile); // try to load the cache file. localCache = WorkshopFileDetailResponse.Load(file); if (loadFromCacheFile) { steamCache = localCache; // check if the cache is old if (localCache != null && localCache.cached.AddHours(Config.Default.WorkshopCache_ExpiredHours) < DateTime.UtcNow) { // cache is considered old, clear cache variable so it will reload from internet steamCache = null; } } // check if the cache exists if (steamCache == null) { steamCache = SteamUtils.GetSteamModDetails(_isSotF ? Config.Default.AppId_SotF : Config.Default.AppId); if (steamCache != null) { steamCache.Save(file); } else { MessageBox.Show(_globalizer.GetResourceString("WorkshopFiles_Refresh_FailedLabel"), _globalizer.GetResourceString("WorkshopFiles_Refresh_FailedTitle"), MessageBoxButton.OK, MessageBoxImage.Error); steamCache = localCache; } } }); WorkshopFiles = WorkshopFileList.GetList(steamCache); } finally { Application.Current.Dispatcher.Invoke(() => this.Cursor = cursor); } }
private async Task LoadWorkshopItems(bool loadFromCacheFile) { var cursor = this.Cursor; try { Application.Current.Dispatcher.Invoke(() => this.Cursor = System.Windows.Input.Cursors.Wait); await Task.Delay(500); WorkshopFileDetailResponse cache = null; await Task.Run(() => { var file = Path.Combine(Config.Default.DataDir, _isSotF ? Config.Default.WorkshopCacheFile_SotF : Config.Default.WorkshopCacheFile); if (loadFromCacheFile) { // try to load the cache file. cache = WorkshopFileDetailResponse.Load(file); // check if the cache is old if (cache != null && cache.cached.AddHours(Config.Default.WorkshopCache_ExpiredHours) < DateTime.UtcNow) { // cache is considered old, clear cache variable so it will reload from internet cache = null; } } // check if the cache exists if (cache == null) { cache = SteamUtils.GetSteamModDetails(_isSotF ? Config.Default.AppId_SotF : Config.Default.AppId); if (cache != null) { cache.Save(file); } } }); WorkshopFiles = WorkshopFileList.GetList(cache); } finally { Application.Current.Dispatcher.Invoke(() => this.Cursor = cursor); } }