Пример #1
0
        public static TarDirectory ReadFromFileOrCache(string file)
        {
            string key = file.Replace('\\', '/');

            if (!cache.TryGetValue(key, out var value))
            {
                value = new TarDirectory(file, "");
                value.lazyLoadArchive = file;
                cache.Add(key, value);
            }
            return(value);
        }
Пример #2
0
        private static IEnumerable <TarDirectory> EnumerateAllChildrenRecursive(TarDirectory of)
        {
            foreach (TarDirectory dir in of.subDirectories)
            {
                yield return(dir);

                foreach (TarDirectory item in EnumerateAllChildrenRecursive(dir))
                {
                    yield return(item);
                }
            }
        }
Пример #3
0
 private static IEnumerable <TarFile> EnumerateAllFilesRecursive(TarDirectory of)
 {
     foreach (TarFile file in of.files)
     {
         yield return(file);
     }
     foreach (TarDirectory subDirectory in of.subDirectories)
     {
         foreach (TarFile item in EnumerateAllFilesRecursive(subDirectory))
         {
             yield return(item);
         }
     }
 }
Пример #4
0
        public static VirtualDirectory GetDirectory(string filesystemPath)
        {
            if (Path.GetExtension(filesystemPath) == ".tar")
            {
                return(TarDirectory.ReadFromFileOrCache(filesystemPath));
            }
            string text = filesystemPath + ".tar";

            if (File.Exists(text))
            {
                return(TarDirectory.ReadFromFileOrCache(text));
            }
            return(new FilesystemDirectory(filesystemPath));
        }
Пример #5
0
        public static List <VirtualDirectory> GetDirectories(string filesystemPath, string searchPattern, SearchOption searchOption, bool allowArchiveAndRealFolderDuplicates = false)
        {
            List <VirtualDirectory> list = new List <VirtualDirectory>();

            string[] directories = Directory.GetDirectories(filesystemPath, searchPattern, searchOption);
            foreach (string text in directories)
            {
                string text2 = text + ".tar";
                if (!allowArchiveAndRealFolderDuplicates && File.Exists(text2))
                {
                    list.Add(TarDirectory.ReadFromFileOrCache(text2));
                }
                else
                {
                    list.Add(new FilesystemDirectory(text));
                }
            }
            directories = Directory.GetFiles(filesystemPath, searchPattern, searchOption);
            foreach (string text3 in directories)
            {
                if (Path.GetExtension(text3) != ".tar")
                {
                    continue;
                }
                if (!allowArchiveAndRealFolderDuplicates)
                {
                    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text3);
                    bool   flag = false;
                    foreach (VirtualDirectory item in list)
                    {
                        if (item.Name == fileNameWithoutExtension)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (flag)
                    {
                        continue;
                    }
                }
                list.Add(TarDirectory.ReadFromFileOrCache(text3));
            }
            return(list);
        }
Пример #6
0
        private static void ParseTAR(TarDirectory root, TarInputStream input, string fullPath)
        {
            Dictionary <string, byte[]> dictionary = new Dictionary <string, byte[]>();
            List <TarEntry>             list       = new List <TarEntry>();
            List <TarDirectory>         list2      = new List <TarDirectory>();

            byte[] buffer = new byte[16384];
            try
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    TarEntry nextEntry;
                    while ((nextEntry = input.GetNextEntry()) != null)
                    {
                        ReadTarEntryData(input, memoryStream, buffer);
                        dictionary.Add(nextEntry.Name, memoryStream.ToArray());
                        list.Add(nextEntry);
                        memoryStream.Position = 0L;
                        memoryStream.SetLength(0L);
                    }
                }
                list2.Add(root);
                foreach (TarEntry item in list.Where((TarEntry e) => e.IsDirectory && !string.IsNullOrEmpty(e.Name)))
                {
                    string str = FormatFolderPath(item.Name);
                    list2.Add(new TarDirectory(fullPath + "/" + str, str));
                }
                foreach (TarEntry item2 in list.Where((TarEntry e) => !e.IsDirectory))
                {
                    string       b            = FormatFolderPath(Path.GetDirectoryName(item2.Name));
                    TarDirectory tarDirectory = null;
                    foreach (TarDirectory item3 in list2)
                    {
                        if (item3.inArchiveFullPath == b)
                        {
                            tarDirectory = item3;
                            break;
                        }
                    }
                    tarDirectory.files.Add(new TarFile(dictionary[item2.Name], fullPath + "/" + item2.Name, Path.GetFileName(item2.Name)));
                }
                foreach (TarDirectory item4 in list2)
                {
                    if (string.IsNullOrEmpty(item4.inArchiveFullPath))
                    {
                        continue;
                    }
                    string       b2            = FormatFolderPath(Path.GetDirectoryName(item4.inArchiveFullPath));
                    TarDirectory tarDirectory2 = null;
                    foreach (TarDirectory item5 in list2)
                    {
                        if (item5.inArchiveFullPath == b2)
                        {
                            tarDirectory2 = item5;
                            break;
                        }
                    }
                    tarDirectory2.subDirectories.Add(item4);
                }
            }
            finally
            {
                input.Close();
            }
        }
Пример #7
0
 public static void ClearAllCache()
 {
     TarDirectory.ClearCache();
 }