Exemplo n.º 1
0
        public static bool Exists(string path)
        {
            bool result;

            lock (VirtualFileSystem.syncVFS)
            {
                if (!VirtualFileSystem.Initialized)
                {
                    Log.Fatal("VirtualFileSystem: File system is not initialized.");
                    result = false;
                }
                else
                {
                    if (VirtualFileSystem.LoggingFileOperations)
                    {
                        Log.Info("Logging File Operations: VirtualDirectory.Exists( \"{0}\" )", path);
                    }
                    string realPathByVirtual = VirtualFileSystem.GetRealPathByVirtual(path);
                    if (Directory.Exists(realPathByVirtual))
                    {
                        result = true;
                    }
                    else if (VirtualDirectory.IsInArchive(path))
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public static bool IsInArchive(string path)
        {
            bool result;

            lock (VirtualFileSystem.syncVFS)
            {
                if (!VirtualFileSystem.Initialized)
                {
                    Log.Fatal("VirtualFileSystem: File system is not initialized.");
                    result = false;
                }
                else
                {
                    if (VirtualFileSystem.LoggingFileOperations)
                    {
                        Log.Info("Logging File Operations: VirtualFile.IsInArchive( \"{0}\" )", path);
                    }
                    path = VirtualFileSystem.NormalizePath(path);
                    path = VirtualFileSystem.RedirectFile(path, true);
                    string realPathByVirtual = VirtualFileSystem.GetRealPathByVirtual(path);
                    if (File.Exists(realPathByVirtual))
                    {
                        result = false;
                    }
                    else
                    {
                        ArchiveManager.FileInfo fileInfo;
                        result = ArchiveManager.Instance.GetFileInfo(path, out fileInfo);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        public static bool IsArchive(string path)
        {
            bool result;

            lock (VirtualFileSystem.syncVFS)
            {
                if (VirtualFileSystem.LoggingFileOperations)
                {
                    Log.Info("Logging File Operations: VirtualFile.IsArchive( \"{0}\" )", path);
                }
                path = VirtualFileSystem.NormalizePath(path);
                path = VirtualFileSystem.RedirectFile(path, true);
                string realPathByVirtual = VirtualFileSystem.GetRealPathByVirtual(path);
                result = (ArchiveManager.Instance.GetArchive(realPathByVirtual) != null);
            }
            return(result);
        }
Exemplo n.º 4
0
        public static long GetLength(string path)
        {
            long result;

            lock (VirtualFileSystem.syncVFS)
            {
                if (!VirtualFileSystem.Initialized)
                {
                    Log.Fatal("VirtualFileSystem: File system is not initialized.");
                    result = 0L;
                }
                else
                {
                    if (VirtualFileSystem.LoggingFileOperations)
                    {
                        Log.Info("Logging File Operations: VirtualFile.GetLength( \"{0}\" )", path);
                    }
                    path = VirtualFileSystem.NormalizePath(path);
                    path = VirtualFileSystem.RedirectFile(path, true);
                    string realPathByVirtual = VirtualFileSystem.GetRealPathByVirtual(path);
                    try
                    {
                        FileInfo fileInfo = new FileInfo(realPathByVirtual);
                        result = fileInfo.Length;
                        return(result);
                    }
                    catch (FileNotFoundException)
                    {
                    }
                    ArchiveManager.FileInfo fileInfo2;
                    if (!ArchiveManager.Instance.GetFileInfo(path, out fileInfo2))
                    {
                        throw new FileNotFoundException("File not found.", path);
                    }
                    result = fileInfo2.Length;
                }
            }
            return(result);
        }
Exemplo n.º 5
0
 public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption)
 {
     string[] result;
     lock (VirtualFileSystem.syncVFS)
     {
         if (!VirtualFileSystem.Initialized)
         {
             Log.Fatal("VirtualFileSystem: File system is not initialized.");
             result = null;
         }
         else
         {
             if (VirtualFileSystem.LoggingFileOperations)
             {
                 Log.Info("Logging File Operations: VirtualDirectory.GetFiles( \"{0}\", \"{1}\", \"{2}\" )", path, searchPattern, searchOption);
             }
             if (searchPattern.IndexOfAny(new char[]
             {
                 '\\',
                 '/',
                 '?'
             }) != -1)
             {
                 throw new ArgumentException("searchPattern: following characters: \\, /, ? is not supported.");
             }
             if (path.Contains(".."))
             {
                 throw new ArgumentException("path: \"..\" is not supported.");
             }
             if (searchPattern.Contains(".."))
             {
                 throw new ArgumentException("searchPattern: \"..\" is not supported.");
             }
             if (VirtualFileSystem.IsUserDirectoryPath(path))
             {
                 string   realPathByVirtual = VirtualFileSystem.GetRealPathByVirtual(path);
                 string[] array;
                 if (Directory.Exists(realPathByVirtual))
                 {
                     array = Directory.GetFiles(realPathByVirtual, searchPattern, searchOption);
                 }
                 else
                 {
                     array = new string[0];
                 }
                 int startIndex = VirtualFileSystem.UserDirectoryPath.Length + 1;
                 for (int i = 0; i < array.Length; i++)
                 {
                     array[i] = "user:" + array[i].Substring(startIndex);
                 }
                 Array.Sort <string>(array);
                 result = array;
             }
             else
             {
                 string   realPathByVirtual2 = VirtualFileSystem.GetRealPathByVirtual(path);
                 string[] array2;
                 if (Directory.Exists(realPathByVirtual2))
                 {
                     array2 = Directory.GetFiles(realPathByVirtual2, searchPattern, searchOption);
                 }
                 else
                 {
                     array2 = new string[0];
                 }
                 int startIndex2 = VirtualFileSystem.ResourceDirectoryPath.Length + 1;
                 for (int j = 0; j < array2.Length; j++)
                 {
                     array2[j] = array2[j].Substring(startIndex2);
                 }
                 List <string> list = new List <string>(64);
                 ArchiveManager.Instance.A(path, searchPattern, searchOption, list);
                 if (list.Count != 0)
                 {
                     string[] array3 = array2;
                     for (int k = 0; k < array3.Length; k++)
                     {
                         string item = array3[k];
                         list.Add(item);
                     }
                     list.Sort();
                     for (int l = list.Count - 1; l >= 1; l--)
                     {
                         if (string.Compare(list[l], list[l - 1], true) == 0)
                         {
                             list.RemoveAt(l);
                         }
                     }
                     array2 = list.ToArray();
                 }
                 else
                 {
                     Array.Sort <string>(array2);
                 }
                 result = array2;
             }
         }
     }
     return(result);
 }
Exemplo n.º 6
0
        public static VirtualFileStream Open(string path)
        {
            VirtualFileStream result;

            lock (VirtualFileSystem.syncVFS)
            {
                if (!VirtualFileSystem.Initialized)
                {
                    Log.Fatal("VirtualFileSystem: File system is not initialized.");
                    result = null;
                }
                else
                {
                    if (VirtualFileSystem.LoggingFileOperations)
                    {
                        Log.Info("Logging File Operations: VirtualFile.Open( \"{0}\" )", path);
                    }
                    path = VirtualFileSystem.NormalizePath(path);
                    path = VirtualFileSystem.RedirectFile(path, true);
                    bool cachingExtension = VirtualFileSystem.IsCachingExtension(path);
                    if (cachingExtension)
                    {
                        byte[] bytesCached = VirtualFileSystem.LoadCachedBytes(path);
                        if (bytesCached != null)
                        {
                            result = new MemoryVirtualFileStream(bytesCached);
                            return(result);
                        }
                    }

                    if (VirtualFileSystem.preloadItems.Count != 0)
                    {
                        string key = path.ToLower();
                        VirtualFileSystem.PreloadFileToMemoryItem preloadFileToMemoryItem;
                        if (VirtualFileSystem.preloadItems.TryGetValue(key, out preloadFileToMemoryItem) && preloadFileToMemoryItem.loaded)
                        {
                            result = new MemoryVirtualFileStream(preloadFileToMemoryItem.data);
                            return(result);
                        }
                    }
                    VirtualFileStream virtualFileStream = null;
                    string            realPathByVirtual = VirtualFileSystem.GetRealPathByVirtual(path);
                    try
                    {
                        if (PlatformInfo.Platform == PlatformInfo.PlanformType.Windows)
                        {
                            virtualFileStream = new WindowsVirtualFileStream(realPathByVirtual);
                        }
                        else if (PlatformInfo.Platform == PlatformInfo.PlanformType.MacOSX)
                        {
                            virtualFileStream = new MacOSXVirtualFileStream(realPathByVirtual);
                        }
                        else
                        {
                            virtualFileStream = new DefaultVirtualFileStream(realPathByVirtual);
                        }
                    }
                    catch (FileNotFoundException)
                    {
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    if (virtualFileStream == null)
                    {
                        virtualFileStream = ArchiveManager.Instance.FileOpen(path);
                        if (virtualFileStream == null)
                        {
                            throw new FileNotFoundException("File not found.", path);
                        }
                    }
                    if (cachingExtension)
                    {
                        byte[] array2 = new byte[virtualFileStream.Length];
                        if ((long)virtualFileStream.Read(array2, 0, (int)virtualFileStream.Length) == virtualFileStream.Length)
                        {
                            VirtualFileSystem.CacheBytes(path, array2);
                        }
                        virtualFileStream.Position = 0L;
                    }
                    result = virtualFileStream;
                }
            }
            return(result);
        }