public FileVaultAsset(string path, string name, VaultAssetType type, bool isSensitive) { Path = path; Name = name; Type = type; IsSensitive = isSensitive; }
public VaultAsset CreateAsset(VaultAssetType type, string name, bool isSensitive = false, bool forceCreate = false, bool forceOverwrite = false) { throw new NotImplementedException(); }
public VaultAsset CreateAsset(VaultAssetType type, string name, bool isSensitive = false, bool getOrCreate = false) { if (!TYPE_PATHS.ContainsKey(type)) { throw new NotSupportedException("unknown or unsupported asset type") .With(nameof(VaultAssetType), type); } var path = Path.Combine(RootPath, TYPE_PATHS[type], name); if (!File.Exists(path)) { // Make sure the asset root dir is there Directory.CreateDirectory(Path.GetDirectoryName(path)); // Create a placeholder file to reserve and represent the created file using (var fs = File.Create(path, 100, isSensitive ? FileOptions.Encrypted : FileOptions.None)) { } } else if (!getOrCreate) { throw new IOException("asset file already exists"); } return(new FileVaultAsset(path, name, type, isSensitive)); }
public static void CopyTo(IVaultProvider vp, VaultAssetType vat, string van, string target, FileMode mode) { var asset = vp.GetAsset(vat, van); using (Stream s = vp.LoadAsset(asset), fs = new FileStream(target, mode)) { s.CopyTo(fs); } }
public static void CopyTo(IVault vlt, VaultAssetType vat, string van, string target, FileMode mode) { var asset = vlt.GetAsset(vat, van); using (Stream s = vlt.LoadAsset(asset), fs = new FileStream(target, mode)) { s.CopyTo(fs); } }
public VaultAsset GetAsset(VaultAssetType type, string name) { var path = Path.Combine(RootPath, TYPE_PATHS[type], name); if (!File.Exists(path)) { throw new FileNotFoundException("asset file does not exist"); } return(new FileVaultAsset(path, name, type, File.GetAttributes(path).HasFlag(FileAttributes.Encrypted))); }