// 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);
        }
Exemplo n.º 2
0
 internal static bool IsEqualOrSubpath(string path, string subpath)
 {
     if (!string.IsNullOrEmpty(path))
     {
         if (string.IsNullOrEmpty(subpath))
         {
             return(false);
         }
         int length = path.Length;
         if (path[length - 1] == '/')
         {
             length--;
         }
         int num2 = subpath.Length;
         if (subpath[num2 - 1] == '/')
         {
             num2--;
         }
         if (num2 < length)
         {
             return(false);
         }
         if (!StringUtil.EqualsIgnoreCase(path, 0, subpath, 0, length))
         {
             return(false);
         }
         if ((num2 > length) && (subpath[length] != '/'))
         {
             return(false);
         }
     }
     return(true);
 }
 internal FindFileData(ref UnsafeNativeMethods.WIN32_FIND_DATA wfd)
 {
     _fileAttributesData = new FileAttributesData(ref wfd);
     _fileNameLong       = wfd.cFileName;
     if (wfd.cAlternateFileName != null &&
         wfd.cAlternateFileName.Length > 0 &&
         !StringUtil.EqualsIgnoreCase(wfd.cFileName, wfd.cAlternateFileName))
     {
         _fileNameShort = wfd.cAlternateFileName;
     }
 }
Exemplo n.º 4
0
        private void PrependRelativePath(string relativePathLong, string relativePathShort)
        {
            this._fileNameLong = relativePathLong + this._fileNameLong;
            string str = string.IsNullOrEmpty(this._fileNameShort) ? this._fileNameLong : this._fileNameShort;

            this._fileNameShort = relativePathShort + str;
            if (StringUtil.EqualsIgnoreCase(this._fileNameShort, this._fileNameLong))
            {
                this._fileNameShort = null;
            }
        }
        private void PrependRelativePath(string relativePathLong, string relativePathShort)
        {
            _fileNameLong = relativePathLong + _fileNameLong;

            // if the short form is null or empty, prepend the short relative path to the long form
            string fileName = String.IsNullOrEmpty(_fileNameShort) ? _fileNameLong : _fileNameShort;

            _fileNameShort = relativePathShort + fileName;

            // if the short form is the same as the long form, set the short form to null
            if (StringUtil.EqualsIgnoreCase(_fileNameShort, _fileNameLong))
            {
                _fileNameShort = null;
            }
        }
Exemplo n.º 6
0
        //
        // NOTE: This function is also present in fx\src\configuration\system\configuration\urlpath.cs
        // Please propagate any changes to that file.
        //
        // Determine if subpath is a subpath of path.
        // For example, /myapp/foo.aspx is a subpath of /myapp
        // Account for optional trailing slashes.
        //
        internal static bool IsEqualOrSubpath(string path, string subpath)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(true);
            }

            if (String.IsNullOrEmpty(subpath))
            {
                return(false);
            }

            //
            // Compare up to but not including trailing slash
            //
            int lPath = path.Length;

            if (path[lPath - 1] == '/')
            {
                lPath -= 1;
            }

            int lSubpath = subpath.Length;

            if (subpath[lSubpath - 1] == '/')
            {
                lSubpath -= 1;
            }

            if (lSubpath < lPath)
            {
                return(false);
            }

            if (!StringUtil.EqualsIgnoreCase(path, 0, subpath, 0, lPath))
            {
                return(false);
            }

            // Check subpath that character following length of path is a slash
            if (lSubpath > lPath && subpath[lPath] != '/')
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
        // Disallow Apartment components in when ASPCOMPAT is off

        internal static void CheckThreadingModel(String progidDisplayName, Guid clsid)
        {
            if (IsInAspCompatMode)
            {
                return;
            }

            // try cache first
            CacheStoreProvider cacheInternal  = HttpRuntime.Cache.InternalCache;
            String             key            = CacheInternal.PrefixAspCompatThreading + progidDisplayName;
            String             threadingModel = (String)cacheInternal.Get(key);
            RegistryKey        regKey         = null;

            if (threadingModel == null)
            {
                try {
                    regKey = Registry.ClassesRoot.OpenSubKey("CLSID\\{" + clsid + "}\\InprocServer32");
                    if (regKey != null)
                    {
                        threadingModel = (String)regKey.GetValue("ThreadingModel");
                    }
                }
                catch {
                }
                finally {
                    if (regKey != null)
                    {
                        regKey.Close();
                    }
                }

                if (threadingModel == null)
                {
                    threadingModel = String.Empty;
                }

                cacheInternal.Insert(key, threadingModel, null);
            }

            if (StringUtil.EqualsIgnoreCase(threadingModel, "Apartment"))
            {
                throw new HttpException(
                          SR.GetString(SR.Apartment_component_not_allowed, progidDisplayName));
            }
        }
Exemplo n.º 8
0
 internal static void CheckThreadingModel(string progidDisplayName, Guid clsid)
 {
     if (!IsInAspCompatMode)
     {
         CacheInternal cacheInternal = HttpRuntime.CacheInternal;
         string        str           = "s" + progidDisplayName;
         string        str2          = (string)cacheInternal.Get(str);
         RegistryKey   key           = null;
         if (str2 == null)
         {
             try
             {
                 key = Registry.ClassesRoot.OpenSubKey(@"CLSID\{" + clsid + @"}\InprocServer32");
                 if (key != null)
                 {
                     str2 = (string)key.GetValue("ThreadingModel");
                 }
             }
             catch
             {
             }
             finally
             {
                 if (key != null)
                 {
                     key.Close();
                 }
             }
             if (str2 == null)
             {
                 str2 = string.Empty;
             }
             cacheInternal.UtcInsert(str, str2);
         }
         if (StringUtil.EqualsIgnoreCase(str2, "Apartment"))
         {
             throw new HttpException(System.Web.SR.GetString("Apartment_component_not_allowed", new object[] { progidDisplayName }));
         }
     }
 }
Exemplo n.º 9
0
 internal FindFileData(ref UnsafeNativeMethods.WIN32_FIND_DATA wfd)
 {
     this._fileAttributesData = new System.Web.Util.FileAttributesData(ref wfd);
     this._fileNameLong       = wfd.cFileName;
     if (((wfd.cAlternateFileName != null) && (wfd.cAlternateFileName.Length > 0)) && !StringUtil.EqualsIgnoreCase(wfd.cFileName, wfd.cAlternateFileName))
     {
         this._fileNameShort = wfd.cAlternateFileName;
     }
 }