public static BoolWithMessage DeleteTextureFiles(TextureMetaData metaData) { if (metaData == null) { return(BoolWithMessage.False($"meta data is null")); } if (metaData.FilePaths?.Count == 0) { return(BoolWithMessage.False($"List of files to delete is unknown for {metaData.Name}.")); } try { BoolWithMessage result = FileUtils.DeleteFiles(metaData.FilePaths); if (result.Result == false) { return(result); } // lastly delete entry from list of installed textures InstalledTexturesMetaData currentlyInstalledTextures = MetaDataManager.LoadTextureMetaData(); currentlyInstalledTextures.Remove(metaData); MetaDataManager.SaveTextureMetaData(currentlyInstalledTextures); return(BoolWithMessage.True($"{metaData.Name} has been deleted!")); } catch (Exception e) { return(BoolWithMessage.False($"Failed to delete files: {e.Message}")); } }
internal static TextureMetaData GetTextureMetaDataByName(string assetName, InstalledTexturesMetaData installedTextures) { if (installedTextures == null) { installedTextures = LoadTextureMetaData(); } return(installedTextures.InstalledTextures.Where(t => t.AssetName == assetName).FirstOrDefault()); }
/// <summary> /// Reads installed_textures.json meta data and initializes <see cref="InstalledTextures"/> with results /// </summary> private void InitInstalledTextures() { InstalledTexturesMetaData installedMetaData = MetaDataManager.LoadTextureMetaData(); List <InstalledTextureItemViewModel> textures = new List <InstalledTextureItemViewModel>(); foreach (TextureMetaData item in installedMetaData.InstalledTextures) { textures.Add(new InstalledTextureItemViewModel(item)); } InstalledTextures = textures.OrderBy(t => t.TextureName).ToList(); }
public void RefreshFilteredAssetList(bool checkForFileChanges = false) { List <AssetCategory> categories = GetSelectedCategories(); List <AssetViewModel> newList = new List <AssetViewModel>(); foreach (AssetCategory cat in categories) { newList.AddRange(GetAssetsByCategory(cat)); } RefreshAuthorList(); if (AuthorToFilterBy.Author != defaultAuthorValue) { newList = newList.Where(a => a.Author == AuthorToFilterBy.Author).ToList(); } if (SelectedInstallStatus != defaultInstallStatusValue) { // read currently installed textures/map from files into memory so checking each asset is quicker InstalledTexturesMetaData installedTextures = MetaDataManager.LoadTextureMetaData(); List <MapMetaData> installedMaps = MetaDataManager.GetAllMetaDataForMaps(); switch (SelectedInstallStatus) { case "Installed": newList = newList.Where(a => IsAssetInstalled(a, installedMaps, installedTextures)).ToList(); break; case "Not Installed": newList = newList.Where(a => IsAssetInstalled(a, installedMaps, installedTextures) == false).ToList(); break; default: break; } } FilteredAssetList = newList; if (FilteredAssetList.Count == 0 && GetSelectedCategories().Count() == 0) { UserMessage = "Check categories to view the list of downloadable assets ..."; } }
internal static void SaveTextureMetaData(InstalledTexturesMetaData metaData) { if (metaData == null) { return; } try { CreateMetaDataFolder(); string jsonToSave = JsonConvert.SerializeObject(metaData, Formatting.Indented); File.WriteAllText(PathToInstalledTextureFile, jsonToSave); } catch (Exception e) { Logger.Error(e, "failed to save texture meta data"); return; } }
internal static void SaveTextureMetaData(TextureMetaData metaData) { if (metaData == null) { return; } try { CreateMetaDataFolder(); InstalledTexturesMetaData currentlyInstalled = LoadTextureMetaData(); currentlyInstalled.Replace(metaData); SaveTextureMetaData(currentlyInstalled); } catch (Exception e) { Logger.Error(e, "failed to save texture meta data"); return; } }
private bool IsAssetInstalled(AssetViewModel asset, List <MapMetaData> mapMetaData, InstalledTexturesMetaData installedTextures) { if (asset.AssetCategory == AssetCategory.Maps.Value) { if (mapMetaData == null) { mapMetaData = MetaDataManager.GetAllMetaDataForMaps(); } return(mapMetaData.Any(m => m.AssetName == asset.Asset.ID)); } else { return(MetaDataManager.GetTextureMetaDataByName(asset.Asset.ID, installedTextures) != null); } }