// FindFile - given a file name, gets the file attributes and short form (8.3 format) of a file name.
        static internal int FindFile(string path, out FindFileData data)
        {
            IntPtr hFindFile;

            UnsafeNativeMethods.WIN32_FIND_DATA wfd;

            data = null;

            // Remove trailing slash if any, otherwise FindFirstFile won't work correctly
            path = FileUtil.RemoveTrailingDirectoryBackSlash(path);
#if DBG
            Debug.Assert(Path.GetDirectoryName(path) != null, "Path.GetDirectoryName(path) != null");
            Debug.Assert(Path.GetFileName(path) != null, "Path.GetFileName(path) != null");
#endif

            hFindFile = UnsafeNativeMethods.FindFirstFile(path, out wfd);
            int lastError = Marshal.GetLastWin32Error(); // FXCOP demands that this preceed the ==
            if (hFindFile == UnsafeNativeMethods.INVALID_HANDLE_VALUE)
            {
                return(HttpException.HResultFromLastError(lastError));
            }

            UnsafeNativeMethods.FindClose(hFindFile);

#if DBG
            string file = Path.GetFileName(path);
            file = file.TrimEnd(' ', '.');
            Debug.Assert(StringUtil.EqualsIgnoreCase(file, wfd.cFileName) ||
                         StringUtil.EqualsIgnoreCase(file, wfd.cAlternateFileName),
                         "Path to FindFile is not for a single file: " + path);
#endif

            data = new FindFileData(ref wfd);
            return(HResults.S_OK);
        }
 internal static int FindFile(string fullPath, string rootDirectoryPath, out FindFileData data)
 {
     int num = FindFile(fullPath, out data);
     if ((num == 0) && !string.IsNullOrEmpty(rootDirectoryPath))
     {
         rootDirectoryPath = FileUtil.RemoveTrailingDirectoryBackSlash(rootDirectoryPath);
         string str = string.Empty;
         string relativePathShort = string.Empty;
         for (string str3 = Path.GetDirectoryName(fullPath); ((str3 != null) && (str3.Length > (rootDirectoryPath.Length + 1))) && (str3.IndexOf(rootDirectoryPath, StringComparison.OrdinalIgnoreCase) == 0); str3 = Path.GetDirectoryName(str3))
         {
             UnsafeNativeMethods.WIN32_FIND_DATA win_find_data;
             IntPtr hndFindFile = UnsafeNativeMethods.FindFirstFile(str3, out win_find_data);
             int lastError = Marshal.GetLastWin32Error();
             if (hndFindFile == UnsafeNativeMethods.INVALID_HANDLE_VALUE)
             {
                 return HttpException.HResultFromLastError(lastError);
             }
             UnsafeNativeMethods.FindClose(hndFindFile);
             str = win_find_data.cFileName + Path.DirectorySeparatorChar + str;
             if (!string.IsNullOrEmpty(win_find_data.cAlternateFileName))
             {
                 relativePathShort = win_find_data.cAlternateFileName + Path.DirectorySeparatorChar + relativePathShort;
             }
             else
             {
                 relativePathShort = win_find_data.cFileName + Path.DirectorySeparatorChar + relativePathShort;
             }
         }
         if (!string.IsNullOrEmpty(str))
         {
             data.PrependRelativePath(str, relativePathShort);
         }
     }
     return num;
 }
 internal void MakeExist(FindFileData ffd, byte[] dacl)
 {
     this._fileNameLong = ffd.FileNameLong;
     this._fileNameShort = ffd.FileNameShort;
     this._fad = ffd.FileAttributesData;
     this._dacl = dacl;
     this._exists = true;
 }
 internal static int FindFile(string path, out FindFileData data)
 {
     UnsafeNativeMethods.WIN32_FIND_DATA win_find_data;
     data = null;
     path = FileUtil.RemoveTrailingDirectoryBackSlash(path);
     IntPtr hndFindFile = UnsafeNativeMethods.FindFirstFile(path, out win_find_data);
     int lastError = Marshal.GetLastWin32Error();
     if (hndFindFile == UnsafeNativeMethods.INVALID_HANDLE_VALUE)
     {
         return HttpException.HResultFromLastError(lastError);
     }
     UnsafeNativeMethods.FindClose(hndFindFile);
     data = new FindFileData(ref win_find_data);
     return 0;
 }
Example #5
0
        internal static int FindFile(string path, out FindFileData data)
        {
            UnsafeNativeMethods.WIN32_FIND_DATA win_find_data;
            data = null;
            path = FileUtil.RemoveTrailingDirectoryBackSlash(path);
            IntPtr hndFindFile = UnsafeNativeMethods.FindFirstFile(path, out win_find_data);
            int    lastError   = Marshal.GetLastWin32Error();

            if (hndFindFile == UnsafeNativeMethods.INVALID_HANDLE_VALUE)
            {
                return(HttpException.HResultFromLastError(lastError));
            }
            UnsafeNativeMethods.FindClose(hndFindFile);
            data = new FindFileData(ref win_find_data);
            return(0);
        }
Example #6
0
        internal static int FindFile(string fullPath, string rootDirectoryPath, out FindFileData data)
        {
            int num = FindFile(fullPath, out data);

            if ((num == 0) && !string.IsNullOrEmpty(rootDirectoryPath))
            {
                rootDirectoryPath = FileUtil.RemoveTrailingDirectoryBackSlash(rootDirectoryPath);
                string str = string.Empty;
                string relativePathShort = string.Empty;
                for (string str3 = Path.GetDirectoryName(fullPath); ((str3 != null) && (str3.Length > (rootDirectoryPath.Length + 1))) && (str3.IndexOf(rootDirectoryPath, StringComparison.OrdinalIgnoreCase) == 0); str3 = Path.GetDirectoryName(str3))
                {
                    UnsafeNativeMethods.WIN32_FIND_DATA win_find_data;
                    IntPtr hndFindFile = UnsafeNativeMethods.FindFirstFile(str3, out win_find_data);
                    int    lastError   = Marshal.GetLastWin32Error();
                    if (hndFindFile == UnsafeNativeMethods.INVALID_HANDLE_VALUE)
                    {
                        return(HttpException.HResultFromLastError(lastError));
                    }
                    UnsafeNativeMethods.FindClose(hndFindFile);
                    str = win_find_data.cFileName + Path.DirectorySeparatorChar + str;
                    if (!string.IsNullOrEmpty(win_find_data.cAlternateFileName))
                    {
                        relativePathShort = win_find_data.cAlternateFileName + Path.DirectorySeparatorChar + relativePathShort;
                    }
                    else
                    {
                        relativePathShort = win_find_data.cFileName + Path.DirectorySeparatorChar + relativePathShort;
                    }
                }
                if (!string.IsNullOrEmpty(str))
                {
                    data.PrependRelativePath(str, relativePathShort);
                }
            }
            return(num);
        }
Example #7
0
    // FindFile - takes a full-path and a root-directory-path, and is used to get the
    // short form (8.3 format) of the relative-path.  A FindFileData structure is returned
    // with FileNameLong and FileNameShort relative to the specified root-directory-path.
    //
    // For example, if full-path is "c:\vdir\subdirectory\t.aspx" and root-directory-path 
    // is "c:\vdir", then the relative-path will be "subdirectory\t.aspx" and it's short 
    // form will be something like "subdir~1\t~1.ASP".
    //
    // This is used by FileChangesMonitor to support the ability to monitor all files and 
    // directories at any depth beneath the application root directory. 
    internal static int FindFile(string fullPath, string rootDirectoryPath, out FindFileData data) {

        int hr = FindFileData.FindFile(fullPath, out data);
        if (hr != HResults.S_OK || String.IsNullOrEmpty(rootDirectoryPath)) {
            return hr;
        }
        
#if DBG
        // The trailing slash should have been removed already, unless the root is "c:\"
        Debug.Assert(rootDirectoryPath.Length < 4 || rootDirectoryPath[rootDirectoryPath.Length-1] != '\\', "Trailing slash unexpected: " + rootDirectoryPath);
#endif
        
        // remove it just in case
        rootDirectoryPath = FileUtil.RemoveTrailingDirectoryBackSlash(rootDirectoryPath);
       
#if DBG 
        Debug.Assert(fullPath.IndexOf(rootDirectoryPath, StringComparison.OrdinalIgnoreCase) == 0, 
                     "fullPath (" + fullPath + ") is not within rootDirectoryPath (" + rootDirectoryPath + ")");
#endif
        
        // crawl backwards along the subdirectories of fullPath until we get to the specified rootDirectoryPath
        string relativePathLong = String.Empty;
        string relativePathShort = String.Empty;
        string currentParentDir = Path.GetDirectoryName(fullPath);
        while (currentParentDir != null 
               && currentParentDir.Length > rootDirectoryPath.Length+1 
               && currentParentDir.IndexOf(rootDirectoryPath, StringComparison.OrdinalIgnoreCase) == 0) {
            
            UnsafeNativeMethods.WIN32_FIND_DATA fd;
            IntPtr hFindFile = UnsafeNativeMethods.FindFirstFile(currentParentDir, out fd);
            int lastError = Marshal.GetLastWin32Error(); // FXCOP demands that this preceed the == 
            if (hFindFile == UnsafeNativeMethods.INVALID_HANDLE_VALUE) {
                return HttpException.HResultFromLastError(lastError);
            }
            UnsafeNativeMethods.FindClose(hFindFile);
            
#if DBG
            Debug.Assert(!String.IsNullOrEmpty(fd.cFileName), "!String.IsNullOrEmpty(fd.cFileName)");
#endif

            // build the long and short versions of the relative path
            relativePathLong = fd.cFileName + Path.DirectorySeparatorChar + relativePathLong;
            if (!String.IsNullOrEmpty(fd.cAlternateFileName)) {
                relativePathShort = fd.cAlternateFileName + Path.DirectorySeparatorChar + relativePathShort;
            }
            else {
                relativePathShort = fd.cFileName + Path.DirectorySeparatorChar + relativePathShort;
            }

            currentParentDir = Path.GetDirectoryName(currentParentDir);
        }

        if (!String.IsNullOrEmpty(relativePathLong)) {
            data.PrependRelativePath(relativePathLong, relativePathShort);
        }

#if DBG
        Debug.Trace("FindFile", "fullPath=" + fullPath + ", rootDirectoryPath=" + rootDirectoryPath);
        Debug.Trace("FindFile", "relativePathLong=" + relativePathLong + ", relativePathShort=" + relativePathShort);
        string fileNameShort = data.FileNameShort == null ? "<null>" : data.FileNameShort;
        Debug.Trace("FindFile", "FileNameLong=" + data.FileNameLong + ", FileNameShrot=" + fileNameShort);
#endif
        
        return hr;
    }
Example #8
0
    // FindFile - given a file name, gets the file attributes and short form (8.3 format) of a file name.
    static internal int FindFile(string path, out FindFileData data) {
        IntPtr hFindFile;
        UnsafeNativeMethods.WIN32_FIND_DATA wfd;

        data = null;

        // Remove trailing slash if any, otherwise FindFirstFile won't work correctly
        path = FileUtil.RemoveTrailingDirectoryBackSlash(path);
#if DBG
        Debug.Assert(Path.GetDirectoryName(path) != null, "Path.GetDirectoryName(path) != null");
        Debug.Assert(Path.GetFileName(path) != null, "Path.GetFileName(path) != null");
#endif

        hFindFile = UnsafeNativeMethods.FindFirstFile(path, out wfd);
        int lastError = Marshal.GetLastWin32Error(); // FXCOP demands that this preceed the == 
        if (hFindFile == UnsafeNativeMethods.INVALID_HANDLE_VALUE) {
            return HttpException.HResultFromLastError(lastError);
        }

        UnsafeNativeMethods.FindClose(hFindFile);

#if DBG
        string file = Path.GetFileName(path);
        file = file.TrimEnd(' ', '.');
        Debug.Assert(StringUtil.EqualsIgnoreCase(file, wfd.cFileName) ||
                     StringUtil.EqualsIgnoreCase(file, wfd.cAlternateFileName),
                     "Path to FindFile is not for a single file: " + path);
#endif

        data = new FindFileData(ref wfd);
        return HResults.S_OK;
    }
    internal MapPathBasedVirtualFile(string virtualPath, string physicalPath,
        FindFileData ffd) : base(virtualPath) {

        _physicalPath = physicalPath;
        _ffd = ffd;
    }
        // FindFile - takes a full-path and a root-directory-path, and is used to get the
        // short form (8.3 format) of the relative-path.  A FindFileData structure is returned
        // with FileNameLong and FileNameShort relative to the specified root-directory-path.
        //
        // For example, if full-path is "c:\vdir\subdirectory\t.aspx" and root-directory-path
        // is "c:\vdir", then the relative-path will be "subdirectory\t.aspx" and it's short
        // form will be something like "subdir~1\t~1.ASP".
        //
        // This is used by FileChangesMonitor to support the ability to monitor all files and
        // directories at any depth beneath the application root directory.
        internal static int FindFile(string fullPath, string rootDirectoryPath, out FindFileData data)
        {
            int hr = FindFileData.FindFile(fullPath, out data);

            if (hr != HResults.S_OK || String.IsNullOrEmpty(rootDirectoryPath))
            {
                return(hr);
            }

#if DBG
            // The trailing slash should have been removed already, unless the root is "c:\"
            Debug.Assert(rootDirectoryPath.Length < 4 || rootDirectoryPath[rootDirectoryPath.Length - 1] != '\\', "Trailing slash unexpected: " + rootDirectoryPath);
#endif

            // remove it just in case
            rootDirectoryPath = FileUtil.RemoveTrailingDirectoryBackSlash(rootDirectoryPath);

#if DBG
            Debug.Assert(fullPath.IndexOf(rootDirectoryPath, StringComparison.OrdinalIgnoreCase) == 0,
                         "fullPath (" + fullPath + ") is not within rootDirectoryPath (" + rootDirectoryPath + ")");
#endif

            // crawl backwards along the subdirectories of fullPath until we get to the specified rootDirectoryPath
            string relativePathLong  = String.Empty;
            string relativePathShort = String.Empty;
            string currentParentDir  = Path.GetDirectoryName(fullPath);
            while (currentParentDir != null &&
                   currentParentDir.Length > rootDirectoryPath.Length + 1 &&
                   currentParentDir.IndexOf(rootDirectoryPath, StringComparison.OrdinalIgnoreCase) == 0)
            {
                UnsafeNativeMethods.WIN32_FIND_DATA fd;
                IntPtr hFindFile = UnsafeNativeMethods.FindFirstFile(currentParentDir, out fd);
                int    lastError = Marshal.GetLastWin32Error(); // FXCOP demands that this preceed the ==
                if (hFindFile == UnsafeNativeMethods.INVALID_HANDLE_VALUE)
                {
                    return(HttpException.HResultFromLastError(lastError));
                }
                UnsafeNativeMethods.FindClose(hFindFile);

#if DBG
                Debug.Assert(!String.IsNullOrEmpty(fd.cFileName), "!String.IsNullOrEmpty(fd.cFileName)");
#endif

                // build the long and short versions of the relative path
                relativePathLong = fd.cFileName + Path.DirectorySeparatorChar + relativePathLong;
                if (!String.IsNullOrEmpty(fd.cAlternateFileName))
                {
                    relativePathShort = fd.cAlternateFileName + Path.DirectorySeparatorChar + relativePathShort;
                }
                else
                {
                    relativePathShort = fd.cFileName + Path.DirectorySeparatorChar + relativePathShort;
                }

                currentParentDir = Path.GetDirectoryName(currentParentDir);
            }

            if (!String.IsNullOrEmpty(relativePathLong))
            {
                data.PrependRelativePath(relativePathLong, relativePathShort);
            }

#if DBG
            Debug.Trace("FindFile", "fullPath=" + fullPath + ", rootDirectoryPath=" + rootDirectoryPath);
            Debug.Trace("FindFile", "relativePathLong=" + relativePathLong + ", relativePathShort=" + relativePathShort);
            string fileNameShort = data.FileNameShort == null ? "<null>" : data.FileNameShort;
            Debug.Trace("FindFile", "FileNameLong=" + data.FileNameLong + ", FileNameShrot=" + fileNameShort);
#endif

            return(hr);
        }