GetFileFromPathAsync() 공개 정적인 메소드

public static GetFileFromPathAsync ( [ path ) : IAsyncOperation
path [
리턴 IAsyncOperation
예제 #1
0
        public async Task <IStorageFile> CopyTo(IStorageFolder folderdestination, string filenamewithextension, NameCollisionOption option)
        {
            if (await Exists())
            {
                var file = await UWPFile.GetFileFromPathAsync(FullPath);

                var folder = await UWPFolders.GetFolderFromPathAsync(folderdestination.FullPath);

                switch (option)
                {
                case NameCollisionOption.GenerateUniqueName:
                    await file.CopyAsync(folder, filenamewithextension, Windows.Storage.NameCollisionOption.GenerateUniqueName);

                    break;

                case NameCollisionOption.ReplaceExisting:
                    await file.CopyAsync(folder, filenamewithextension, Windows.Storage.NameCollisionOption.ReplaceExisting);

                    break;

                case NameCollisionOption.FailIfExists:
                    await file.CopyAsync(folder, filenamewithextension, Windows.Storage.NameCollisionOption.FailIfExists);

                    break;
                }
            }
            return(null);
        }
예제 #2
0
        public async Task <bool> Delete()
        {
            if (await Exists())
            {
                var file = await UWPFile.GetFileFromPathAsync(FullPath);

                await file.DeleteAsync();

                return(true);
            }
            return(false);
        }
예제 #3
0
        public static async Task <StorageFile> GetFileFromPath(string path)
        {
            var file = await UWPFile.GetFileFromPathAsync(path);

            return(new StorageFile
            {
                Attributes = (System.IO.FileAttributes)((int)file.Attributes),
                DateCreated = file.DateCreated.DateTime,
                DisplayName = file.DisplayName,
                DisplayType = file.DisplayType,
                FullPath = file.Path,
                Name = file.Name
            });
        }
예제 #4
0
        public async Task <Stream> Open(FileAccessMode mode)
        {
            if (await Exists())
            {
                var file = await UWPFile.GetFileFromPathAsync(FullPath);

                switch (mode)
                {
                case FileAccessMode.Read:
                    return(await file.OpenStreamForReadAsync());

                case FileAccessMode.Write:
                    return(await file.OpenStreamForWriteAsync());
                }
                return(null);
            }
            else
            {
                throw new FileNotFoundException("El archivo que tratas de copiar no existe, path: " + FullPath + ", name: " + Name);
            }
        }
예제 #5
0
        private static async Task <StorageFile> GetFileFromApplicationUri(CancellationToken ct, Uri uri)
        {
            if (uri.Scheme != "ms-appx")
            {
                throw new InvalidOperationException("Uri is not using the ms-appx scheme");
            }

            var path = uri.PathAndQuery.TrimStart(new char[] { '/' });

            var directoryName = global::System.IO.Path.GetDirectoryName(path);
            var fileName      = global::System.IO.Path.GetFileNameWithoutExtension(path);
            var fileExtension = global::System.IO.Path.GetExtension(path);

            var resourcePathname = NSBundle.MainBundle.PathForResource(global::System.IO.Path.Combine(directoryName, fileName), fileExtension.Substring(1));

            if (resourcePathname != null)
            {
                return(await StorageFile.GetFileFromPathAsync(resourcePathname));
            }
            else
            {
                throw new FileNotFoundException($"The file [{path}] cannot be found in the bundle");
            }
        }
예제 #6
0
        public IAsyncOperation <global::Windows.Storage.IStorageItem> GetItemAsync(string name) =>
        AsyncOperation.FromTask(async ct =>
        {
            await TryInitializeStorage();

            var itemPath = global::System.IO.Path.Combine(Path, name);

            var fileExists      = File.Exists(itemPath);
            var directoryExists = Directory.Exists(itemPath);

            if (!fileExists && !directoryExists)
            {
                throw new FileNotFoundException(itemPath);
            }

            if (fileExists)
            {
                return((IStorageItem)await StorageFile.GetFileFromPathAsync(itemPath));
            }
            else
            {
                return((IStorageItem)await StorageFolder.GetFolderFromPathAsync(itemPath));
            }
        });
예제 #7
0
        private static async Task <StorageFile> GetFileFromApplicationUriAsyncTask(CancellationToken ct, Uri uri)
        {
            if (uri.Scheme != "ms-appx")
            {
                throw new InvalidOperationException("Uri is not using the ms-appx scheme");
            }

            var path = AndroidResourceNameEncoder.EncodeResourcePath(uri.PathAndQuery.TrimStart(new char[] { '/' }));

            // Read the contents of our asset
            var assets          = global::Android.App.Application.Context.Assets;
            var outputCachePath = global::System.IO.Path.Combine(Android.App.Application.Context.CacheDir.AbsolutePath, path);

            if (typeof(StorageFile).Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                typeof(StorageFile).Log().Debug($"GetFileFromApplicationUriAsyncTask path:{path} outputCachePath:{outputCachePath}");
            }

            // Ensure only one generation of the cached file can occur at a time.
            // The copy of tha android asset should not be necessary, but requires a significant
            // refactoring of the StorageFile class to make non-local provides opaque.
            // This will need to be revisited once we add support for other providers.
            using var gate = await _assetGate.LockForAsset(ct, path);

            if (!File.Exists(outputCachePath))
            {
                Directory.CreateDirectory(global::System.IO.Path.GetDirectoryName(outputCachePath));

                using var input  = assets.Open(path);
                using var output = File.OpenWrite(outputCachePath);

                await input.CopyToAsync(output);
            }

            return(await StorageFile.GetFileFromPathAsync(outputCachePath));
        }
예제 #8
0
 /// <summary>
 /// WARNING This method should not be used because it doesn't match the StorageFile API
 /// </summary>
 public IAsyncOperation <StorageFile> SafeGetFileAsync(string path) =>
 AsyncOperation.FromTask(async ct =>
 {
     return(await StorageFile.GetFileFromPathAsync(global::System.IO.Path.Combine(Path, path)));
 });
예제 #9
0
        private async Task <bool> Exists()
        {
            var file = await UWPFile.GetFileFromPathAsync(FullPath);

            return(file != null);
        }