示例#1
0
 private static StorageFile OpenFile(string file, FileMode mode, FileAccess access)
 {
     return(FileHelper.GetFileForPathOrURI(file));
 }
示例#2
0
 public static void Replace(string sourceFileName, string destinationFileName, string destinationBackupFileName)
 {
     if (destinationFileName == null)
     {
         throw new ArgumentNullException();
     }
     if (!string.IsNullOrWhiteSpace(sourceFileName) && !string.IsNullOrWhiteSpace(destinationFileName))
     {
         if (!string.IsNullOrWhiteSpace(destinationBackupFileName))
         {
             try
             {
                 StorageFile fileForPathOrUri1 = FileHelper.GetFileForPathOrURI(sourceFileName);
                 string      fileName1         = Path.GetFileName(destinationFileName);
                 StorageFile fileForPathOrUri2;
                 if (fileName1.ToLower() == destinationFileName.ToLower())
                 {
                     if (Path.GetFileName(sourceFileName).ToLower() == fileName1.ToLower())
                     {
                         System.Diagnostics.Debug.WriteLine("File.Replace: Source and destination is the same file");
                         throw new IOException("Source and destination is the same file");
                     }
                     fileForPathOrUri2 = FileHelper.GetFileForPathOrURI(Path.Combine(Path.GetDirectoryName(fileForPathOrUri1.Path), fileName1));
                 }
                 else
                 {
                     fileForPathOrUri2 = FileHelper.GetFileForPathOrURI(destinationFileName);
                     if (fileForPathOrUri1.Equals((object)fileForPathOrUri2))
                     {
                         System.Diagnostics.Debug.WriteLine("File.Replace: Source and destination is the same file");
                         throw new IOException("Source and destination is the same file");
                     }
                 }
                 string fileName2 = Path.GetFileName(destinationBackupFileName);
                 if (fileName2.ToLower() == destinationBackupFileName.ToLower())
                 {
                     WindowsRuntimeSystemExtensions.AsTask(fileForPathOrUri2.RenameAsync(destinationBackupFileName)).Wait();
                 }
                 else
                 {
                     StorageFolder folderForPathOrUri = FileHelper.GetFolderForPathOrURI(destinationBackupFileName);
                     WindowsRuntimeSystemExtensions.AsTask(fileForPathOrUri2.MoveAsync((IStorageFolder)folderForPathOrUri, fileName2)).Wait();
                 }
                 if (fileName1.ToLower() == destinationFileName.ToLower())
                 {
                     WindowsRuntimeSystemExtensions.AsTask(fileForPathOrUri1.RenameAsync(destinationFileName)).Wait();
                     return;
                 }
                 else
                 {
                     StorageFolder folderForPathOrUri = FileHelper.GetFolderForPathOrURI(destinationFileName);
                     WindowsRuntimeSystemExtensions.AsTask(fileForPathOrUri1.MoveAsync((IStorageFolder)folderForPathOrUri, fileName1)).Wait();
                     return;
                 }
             }
             catch (Exception ex)
             {
                 throw File.GetRethrowException(ex);
             }
         }
     }
     throw new ArgumentException();
 }
示例#3
0
 public static Stream OpenFileForReading(string uri)
 {
     return(FileHelper.OpenFileForReading(FileHelper.GetFileForPathOrURI(uri)));
 }