Example #1
0
 public override IAsyncAction RenameAsync(string desiredName, NameCollisionOption option)
 {
     return(AsyncInfo.Run(async(cancellationToken) =>
     {
         string destination = IO.Path.Combine(IO.Path.GetDirectoryName(Path), desiredName);
         var destFile = new NativeStorageFile(destination, desiredName, DateTime.Now);
         if (!IsAlternateStream)
         {
             if (!await Task.Run(() => NativeFileOperationsHelper.MoveFileFromApp(Path, destination)))
             {
                 throw new Win32Exception(Marshal.GetLastWin32Error());
             }
         }
         else
         {
             destFile.CreateFile();
             using (var inStream = await this.OpenStreamForReadAsync())
                 using (var outStream = await destFile.OpenStreamForWriteAsync())
                 {
                     await inStream.CopyToAsync(outStream);
                     await outStream.FlushAsync();
                 }
             await DeleteAsync();
         }
     }));
 }
Example #2
0
 public override IAsyncOperation <BaseStorageFile> CopyAsync(IStorageFolder destinationFolder, string desiredNewName, NameCollisionOption option)
 {
     return(AsyncInfo.Run <BaseStorageFile>(async(cancellationToken) =>
     {
         if (string.IsNullOrEmpty(destinationFolder.Path))
         {
             throw new NotSupportedException();
         }
         var destination = IO.Path.Combine(destinationFolder.Path, desiredNewName);
         var destFile = new NativeStorageFile(destination, desiredNewName, DateTime.Now);
         if (!IsAlternateStream)
         {
             if (!await Task.Run(() => NativeFileOperationsHelper.CopyFileFromApp(Path, destination, option != NameCollisionOption.ReplaceExisting)))
             {
                 throw new Win32Exception(Marshal.GetLastWin32Error());
             }
         }
         else
         {
             destFile.CreateFile();
             using (var inStream = await this.OpenStreamForReadAsync())
                 using (var outStream = await destFile.OpenStreamForWriteAsync())
                 {
                     await inStream.CopyToAsync(outStream);
                     await outStream.FlushAsync();
                 }
         }
         return destFile;
     }));
 }
Example #3
0
 public static IAsyncOperation <BaseStorageFile> FromPathAsync(string path)
 {
     return(AsyncInfo.Run <BaseStorageFile>(async(cancellationToken) =>
     {
         if (NativeStorageFile.IsNativePath(path))
         {
             if (CheckAccess(path))
             {
                 var name = IO.Path.GetFileName(path);
                 return new NativeStorageFile(path, name.Substring(name.LastIndexOf(":") + 1), DateTime.Now);
             }
         }
         return null;
     }));
 }