internal PhysicalStoragePath(string path, FileSystem fileSystem) : base(fileSystem, path) { Debug.Assert( ReferenceEquals(fileSystem.PathInformation, PhysicalPathHelper.PhysicalPathInformation), $"When using the PhysicalStoragePath, your file system should be using the corresponding " + $"{nameof(PhysicalPathHelper.PhysicalPathInformation)}." ); var fullPath = GetFullPathOrThrow(path); var rootPath = Path.GetPathRoot(path); var pathWithoutTrailingSeparator = PathPolyfills.TrimEndingDirectorySeparator(path); var directoryPath = Path.GetDirectoryName(pathWithoutTrailingSeparator); var name = Path.GetFileName(pathWithoutTrailingSeparator); var nameWithoutExtension = GetNameWithoutExtension(name); var extension = PhysicalPathHelper.GetExtensionWithoutTrailingExtensionSeparator(pathWithoutTrailingSeparator); var isPathFullyQualified = PathPolyfills.IsPathFullyQualified(path); Kind = isPathFullyQualified ? PathKind.Absolute : PathKind.Relative; Name = name; NameWithoutExtension = nameWithoutExtension; Extension = string.IsNullOrEmpty(extension) ? null : extension; _rootLazy = new Lazy <StoragePath?>( () => string.IsNullOrEmpty(rootPath) ? null : fileSystem.GetPath(rootPath) ); _parentLazy = new Lazy <StoragePath?>( () => string.IsNullOrEmpty(directoryPath) ? null : fileSystem.GetPath(directoryPath) ); _fullPathLazy = new Lazy <StoragePath>( () => fileSystem.GetPath(fullPath) );
public override async Task <StorageFolderProperties> GetPropertiesAsync(CancellationToken cancellationToken = default) { var folder = await FsHelper.GetFolderAsync(_fullPath, cancellationToken).ConfigureAwait(false); var props = await folder.GetBasicPropertiesAsync().AsAwaitable(cancellationToken); var lastModified = props.DateModified == default ? (DateTimeOffset?)null : props.DateModified; return(new StorageFolderProperties( folder.Name, IOPath.GetFileNameWithoutExtension(folder.Name), PhysicalPathHelper.GetExtensionWithoutTrailingExtensionSeparator(folder.Name)?.ToNullIfEmpty(), folder.DateCreated, lastModified )); }
public override Task <StorageFolderProperties> GetPropertiesAsync(CancellationToken cancellationToken = default) { return(Task.Run(() => { EnsureExists(); // Attempting to get the real folder name can fail, e.g. the folder might have been deleted in between. // In such a case, simply return the last fetched name. It will happen rarely and is good enough // for such cases. cancellationToken.ThrowIfCancellationRequested(); var realFolderName = FsHelper.GetRealDirectoryName(_fullPath.ToString()) ?? Path.Name; var lastWriteTime = Directory.GetLastWriteTimeUtc(_fullPath.ToString()); return new StorageFolderProperties( realFolderName, IOPath.GetFileNameWithoutExtension(realFolderName), PhysicalPathHelper.GetExtensionWithoutTrailingExtensionSeparator(realFolderName)?.ToNullIfEmpty(), Directory.GetCreationTimeUtc(_fullPath.ToString()), lastWriteTime ); }, cancellationToken)); }