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);
            }
        }
Example #2
0
 private async void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         WorkshopFiles = await LoadWorkshopItemsAsync(_profile.SOTF_Enabled);
         await LoadModsFromProfile();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, _globalizer.GetResourceString("ModDetails_Load_FailedTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Example #3
0
        private async Task <WorkshopFileList> LoadWorkshopItemsAsync(bool isSotF)
        {
            WorkshopFileDetailResponse localCache = 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);
            });

            return(WorkshopFileList.GetList(localCache));
        }
Example #4
0
        private async void WorkshopFilesWindow_Closed(object sender, EventArgs e)
        {
            _workshopFilesWindow = null;
            this.Activate();

            try
            {
                WorkshopFiles = await LoadWorkshopItemsAsync(_profile.SOTF_Enabled);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, _globalizer.GetResourceString("ModDetails_Load_FailedTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #5
0
        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);
            }
        }
Example #6
0
        public static ModDetailList GetModDetails(List <string> modIdList, string modsRootFolder, WorkshopFileList workshopFiles, PublishedFileDetailsResponse response)
        {
            var result = new ModDetailList();

            if (modIdList != null)
            {
                foreach (var modId in modIdList)
                {
                    var temp = workshopFiles?.FirstOrDefault(w => w.WorkshopId.Equals(modId));

                    result.Add(new ModDetail()
                    {
                        AppId       = temp?.AppId ?? string.Empty,
                        ModId       = modId,
                        TimeUpdated = -1,
                        Title       = temp?.Title ?? "Mod name not available",
                        IsValid     = false,
                    });
                }
            }

            if (response?.publishedfiledetails != null)
            {
                foreach (var item in result)
                {
                    var temp = response.publishedfiledetails.FirstOrDefault(w => w.publishedfileid.Equals(item.ModId));

                    if (temp != null)
                    {
                        item.AppId       = temp?.creator_app_id ?? string.Empty;
                        item.ModId       = temp?.publishedfileid ?? item.ModId;
                        item.TimeUpdated = temp?.time_updated ?? item.TimeUpdated;
                        item.Title       = temp?.title ?? item.Title;
                        item.IsValid     = temp?.creator_app_id != null;
                    }
                }
            }

            result.SetPublishedFileIndex();
            result.PopulateExtended(modsRootFolder);
            return(result);
        }