Exemple #1
0
 /// <summary>
 /// Verifies that the specified <see cref="FileRequestResult"/> can be used in the current virtual environment.
 /// </summary>
 /// <param name="fileRequestResult"></param>
 /// <returns></returns>
 private static FileRequestResult GetVerifiedRequestResult(FileRequestResult fileRequestResult)
 {
     if (File.Exists(fileRequestResult.Path))
     {
         // File exists, request is suposed to be valid.
         return(fileRequestResult);
     }
     // Path doesn't exist, determine whether it should be used anyway.
     if (fileRequestResult.Request.ResourceType == ResourceType.Library)
     {
         // Don't use: The target is a library unknown to the virtual environment.
         fileRequestResult.Path = fileRequestResult.Request.Path;
     }
     if (fileRequestResult.Request.CreationDisposition == FileCreationDisposition.OpenExisting)
     {
         // Don't use: The target won't be created, it's save to return original path.
         fileRequestResult.Path = fileRequestResult.Request.Path;
     }
     if (fileRequestResult.Request.CreationDisposition == FileCreationDisposition.Unspecified)
     {
         // Note: The following lines need to be reviewed!
         // In some cases the API hook handler receives this value for FileCreationDisposition,
         // which is (according to the documentation) invalid for any of the file management API functions.
         // The source and meaning of this value is unknown, the following is more or less a work-around.
         if (fileRequestResult.SystemFolder != VirtualFolder.Temporary)
         {
             fileRequestResult.Path = fileRequestResult.Request.Path;
         }
         // Else: the path leads to a temporary resource, which should always reside in the virtual environment.
     }
     return(fileRequestResult);
 }
 /// <summary>
 /// Returns the replacement path for the specified <paramref name="request"/>.
 /// The result is relative to the virtual file system's root directory.
 /// </summary>
 /// <param name="request">The <see cref="FileRequest"/> to redirect.</param>
 /// <param name="root"></param>
 /// <returns>The replacement path, used for redirection.</returns>
 public FileRequestResult Redirect(FileRequest request, string root)
 {
   var result = new FileRequestResult {Request = request};
   string systemFolder;
   if (request.Path.StartsWithAny(_systemVariables.Keys, out systemFolder, true))
   {
     result.SystemFolder = _systemVariables[systemFolder];
     result.Path = _systemVariables[systemFolder].ToPath() +
                             (request.Path.Length > systemFolder.Length
                                ? request.Path.Substring(systemFolder.Length + 1).ToLowerInvariant()
                                : "");
   }
   else
   {
     result.SystemFolder = VirtualFolder.Other;
     result.Path = RedirectToDefaultFolder(request.Path);
   }
   result.Path = Path.Combine(root, result.Path);
   return result;
 }
Exemple #3
0
        /// <summary>
        /// Returns the replacement path for the specified <paramref name="request"/>.
        /// The result is relative to the virtual file system's root directory.
        /// </summary>
        /// <param name="request">The <see cref="FileRequest"/> to redirect.</param>
        /// <param name="root"></param>
        /// <returns>The replacement path, used for redirection.</returns>
        public FileRequestResult Redirect(FileRequest request, string root)
        {
            var result = new FileRequestResult {
                Request = request
            };
            string systemFolder;

            if (request.Path.StartsWithAny(_systemVariables.Keys, out systemFolder, true))
            {
                result.SystemFolder = _systemVariables[systemFolder];
                result.Path         = _systemVariables[systemFolder].ToPath() +
                                      (request.Path.Length > systemFolder.Length
                                   ? request.Path.Substring(systemFolder.Length + 1).ToLowerInvariant()
                                   : "");
            }
            else
            {
                result.SystemFolder = VirtualFolder.Other;
                result.Path         = RedirectToDefaultFolder(request.Path);
            }
            result.Path = Path.Combine(root, result.Path);
            return(result);
        }
 /// <summary>
 /// Verifies that the specified <see cref="FileRequestResult"/> can be used in the current virtual environment.
 /// </summary>
 /// <param name="fileRequestResult"></param>
 /// <returns></returns>
 private static FileRequestResult GetVerifiedRequestResult(FileRequestResult fileRequestResult)
 {
   if (File.Exists(fileRequestResult.Path))
     // File exists, request is suposed to be valid.
     return fileRequestResult;
   // Path doesn't exist, determine whether it should be used anyway.
   if (fileRequestResult.Request.ResourceType == ResourceType.Library)
     // Don't use: The target is a library unknown to the virtual environment.
     fileRequestResult.Path = fileRequestResult.Request.Path;
   if (fileRequestResult.Request.CreationDisposition == FileCreationDisposition.OpenExisting)
     // Don't use: The target won't be created, it's save to return original path.
     fileRequestResult.Path = fileRequestResult.Request.Path;
   if (fileRequestResult.Request.CreationDisposition == FileCreationDisposition.Unspecified)
   {
     // Note: The following lines need to be reviewed!
     // In some cases the API hook handler receives this value for FileCreationDisposition,
     // which is (according to the documentation) invalid for any of the file management API functions.
     // The source and meaning of this value is unknown, the following is more or less a work-around.
     if (fileRequestResult.SystemFolder != VirtualFolder.Temporary)
       fileRequestResult.Path = fileRequestResult.Request.Path;
     // Else: the path leads to a temporary resource, which should always reside in the virtual environment.
   }
   return fileRequestResult;
 }