private static string GetScaledPath(string path, HashSet <string> assets, ResolutionScale?scaleOverride) { if (!string.IsNullOrEmpty(path)) { var directory = Path.GetDirectoryName(path); var filename = Path.GetFileNameWithoutExtension(path); var extension = Path.GetExtension(path); var resolutionScale = scaleOverride == null ? (int)DisplayInformation.GetForCurrentView().ResolutionScale : (int)scaleOverride; for (var i = KnownScales.Length - 1; i >= 0; i--) { var probeScale = KnownScales[i]; if (resolutionScale >= probeScale) { var filePath = Path.Combine(directory, $"{filename}.scale-{probeScale}{extension}"); if (assets.Contains(filePath)) { return(!string.IsNullOrEmpty(UNO_BOOTSTRAP_APP_BASE) ? $"{UNO_BOOTSTRAP_APP_BASE}/{filePath}" : filePath); } } } return(!string.IsNullOrEmpty(UNO_BOOTSTRAP_APP_BASE) ? $"{UNO_BOOTSTRAP_APP_BASE}/{path}" : path); } return(path); }
public override async Task <StorageFolder> CreateFolderAsync(string folderName, CreationCollisionOption option, CancellationToken token) { await TryInitializeStorage(); var path = IOPath.Combine(Path, folderName); switch (option) { case CreationCollisionOption.ReplaceExisting: if (Directory.Exists(path)) { Directory.Delete(path, true); } if (File.Exists(path)) { throw new UnauthorizedAccessException("There is already a file with the same name."); } break; case CreationCollisionOption.FailIfExists: if (Directory.Exists(path) || File.Exists(path)) { throw new UnauthorizedAccessException("There is already an item with the same name."); } break; case CreationCollisionOption.OpenIfExists: if (Directory.Exists(path)) { return(new StorageFolder(folderName, path)); } if (File.Exists(path)) { throw new UnauthorizedAccessException("There is already a file with the same name."); } break; case CreationCollisionOption.GenerateUniqueName: var availableName = await FindAvailableNumberedFolderNameAsync(folderName); path = IOPath.Combine(Path, availableName); break; default: throw new NotSupportedException("Unsupported value of CreationCollisionOption"); } var directory = Directory.CreateDirectory(path); return(new StorageFolder(directory.Name, path)); }
public NativeStorageFolder(NativeStorageItemInfo info, StorageFolder?parent) : base(SystemPath.Combine(parent?.Path ?? string.Empty, info.Name ?? string.Empty)) { if (info is null) { throw new ArgumentNullException(nameof(info)); } _id = info.Id; _name = info.Name ?? string.Empty; _parent = parent; }
public NativeStorageFile(NativeStorageItemInfo nativeStorageItem, StorageFolder?parent) : base(SystemPath.Combine(parent?.Path ?? string.Empty, nativeStorageItem.Name ?? string.Empty)) { if (parent != null && !(parent.Implementation is StorageFolder.NativeStorageFolder)) { throw new ArgumentException("Parent folder of a native file must be a native folder", nameof(parent)); } _id = nativeStorageItem.Id; _fileName = nativeStorageItem.Name ?? string.Empty; _parent = parent; }
public override async Task <StorageFile> CreateFileAsync(string desiredName, CreationCollisionOption options, CancellationToken cancellationToken) { await TryInitializeStorage(); var path = IOPath.Combine(Path, desiredName); var actualName = desiredName; switch (options) { case CreationCollisionOption.FailIfExists: if (Directory.Exists(path) || File.Exists(path)) { throw new UnauthorizedAccessException("There is already an item with the same name."); } break; case CreationCollisionOption.GenerateUniqueName: actualName = await FindAvailableNumberedFileNameAsync(desiredName); break; case CreationCollisionOption.OpenIfExists: if (Directory.Exists(path)) { throw new UnauthorizedAccessException("There is already a folder with the same name."); } break; case CreationCollisionOption.ReplaceExisting: if (Directory.Exists(path)) { throw new UnauthorizedAccessException("There is already a folder with the same name."); } if (File.Exists(path)) { File.Delete(path); } break; default: throw new ArgumentOutOfRangeException(nameof(options)); } var actualPath = IOPath.Combine(Path, actualName); if (!File.Exists(actualPath)) { File.Create(actualPath).Close(); } return(await StorageFile.GetFileFromPathAsync(IOPath.Combine(Path, actualName))); }
public override async Task <StorageFile> GetFileAsync(string name, CancellationToken token) { await TryInitializeStorage(); var filePath = IOPath.Combine(Path, name); if (!File.Exists(filePath)) { throw new FileNotFoundException(filePath); } return(StorageFile.GetFileFromPath(filePath)); }
public override async Task <StorageFolder> GetFolderAsync(string name, CancellationToken token) { await TryInitializeStorage(); var itemPath = IOPath.Combine(Path, name); var directoryExists = Directory.Exists(itemPath); if (!directoryExists) { throw new FileNotFoundException(itemPath); } return(await GetFolderFromPathAsync(itemPath)); }
public override async Task <IStorageItem?> TryGetItemAsync(string name, CancellationToken token) { await TryInitializeStorage(); var itemPath = IOPath.Combine(Path, name); if (File.Exists(itemPath)) { return(await StorageFile.GetFileFromPathAsync(itemPath)); } if (Directory.Exists(itemPath)) { return(await GetFolderFromPathAsync(itemPath)); } return(null); }
public override async Task <StorageFolder> GetFolderAsync(string name, CancellationToken token) { await TryInitializeStorage(); var itemPath = IOPath.Combine(Path, name); if (File.Exists(itemPath)) { throw new ArgumentException($"The item with name '{name}' is a file.", nameof(name)); } if (!Directory.Exists(itemPath)) { throw new FileNotFoundException($"There is no file with name '{name}'."); } return(await GetFolderFromPathAsync(itemPath)); }
private static string GetScaledPath(string path, HashSet <string> assets, ResolutionScale?scaleOverride) { if (!string.IsNullOrEmpty(path)) { var directory = Path.GetDirectoryName(path); var filename = Path.GetFileNameWithoutExtension(path); var extension = Path.GetExtension(path); var resolutionScale = scaleOverride == null ? (int)DisplayInformation.GetForCurrentView().ResolutionScale : (int)scaleOverride; // On Windows, the minimum scale is 100%, however, on Wasm, we can have lower scales. // This condition is to allow Wasm to use the .scale-100 image when the scale is < 100% if (resolutionScale < 100) { resolutionScale = 100; } for (var i = KnownScales.Length - 1; i >= 0; i--) { var probeScale = KnownScales[i]; if (resolutionScale >= probeScale) { var filePath = Path.Combine(directory, $"{filename}.scale-{probeScale}{extension}"); if (assets.Contains(filePath)) { return(AssetsPathBuilder.BuildAssetUri(filePath)); } } } return(AssetsPathBuilder.BuildAssetUri(path)); } return(path); }
public override async Task <StorageFile> CreateFileAsync(string desiredName, CreationCollisionOption options, CancellationToken cancellationToken) { await TryInitializeStorage(); var actualName = desiredName; if (File.Exists(IOPath.Combine(Path, desiredName))) { switch (options) { case CreationCollisionOption.FailIfExists: throw new Exception("Cannot create a file when that file already exists."); case CreationCollisionOption.OpenIfExists: break; case CreationCollisionOption.ReplaceExisting: File.Create(IOPath.Combine(Path, desiredName)).Close(); break; case CreationCollisionOption.GenerateUniqueName: actualName = await FindAvailableNumberedFileNameAsync(desiredName); var path = IOPath.Combine(Path, actualName); File.Create(path).Close(); break; default: throw new ArgumentOutOfRangeException(nameof(options)); } } else { File.Create(IOPath.Combine(Path, desiredName)).Close(); } return(await StorageFile.GetFileFromPathAsync(IOPath.Combine(Path, actualName))); }