/// <summary> /// Loads a vault file /// </summary> /// <param name="vaultName">Name of the vault</param> public LoadVaultResult LoadVault(string vaultName) { var result = new LoadVaultResult(); // Get the filename result.Filename = GamePathResolver.GetVaultFile(vaultName); // Check the cache try { result.Vault = this.userContext.Vaults[result.Filename]; } catch (KeyNotFoundException) { // We need to load the vault. if (!File.Exists(result.Filename)) { // the file does not exist so create a new vault. result.Vault = this.CreateVault(vaultName, result.Filename); result.VaultLoaded = true; } else { result.Vault = new PlayerCollection(vaultName, result.Filename); result.Vault.IsVault = true; try { PlayerCollectionProvider.LoadFile(result.Vault); result.VaultLoaded = true; } catch (ArgumentException argumentException) { result.ArgumentException = argumentException; } } // Add the vault to the cache, but only if we create it or it successfully loads. if (result.VaultLoaded) { this.userContext.Vaults.Add(result.Filename, result.Vault); } } return(result); }
/// <summary> /// Loads a vault file /// </summary> /// <param name="vaultName">Name of the vault</param> public LoadVaultResult LoadVault(string vaultName) { var result = new LoadVaultResult(); // Get the filename result.Filename = GamePathResolver.GetVaultFile(vaultName); // Check the cache var resultVault = this.userContext.Vaults.GetOrAddAtomic(result.Filename, k => { PlayerCollection pc; // We need to load the vault. if (!File.Exists(k)) { // the file does not exist so create a new vault. pc = this.CreateVault(vaultName, k); pc.VaultLoaded = true; } else { pc = new PlayerCollection(vaultName, k); pc.IsVault = true; try { PlayerCollectionProvider.LoadFile(pc); pc.VaultLoaded = true; } catch (ArgumentException argumentException) { pc.ArgumentException = argumentException; } } return(pc); }); result.Vault = resultVault; result.VaultLoaded = resultVault.VaultLoaded; result.ArgumentException = resultVault.ArgumentException; return(result); }