예제 #1
0
 public void AddDirEntry(ScsHashEntry entry)
 {
     if (_rootDirectory == null)
     {
         _rootDirectory = new ScsDirectory(entry, "");
     }
     else
     {
         _rootDirectory.AddDirEntry(entry);
     }
 }
예제 #2
0
 public void AddZipEntry(ScsZipEntry entry, string path)
 {
     if (_rootDirectory == null)
     {
         _rootDirectory = new ScsDirectory(this, "");
         _rootDirectory.AddZipEntry(entry, path);
     }
     else
     {
         _rootDirectory.AddZipEntry(entry, path);
     }
 }
예제 #3
0
        public void AddZipEntry(ScsZipEntry entry, string path)
        {
            if (entry == null || path == "")
            {
                return;
            }

            var slashIndex = path.IndexOf("/", StringComparison.Ordinal);

            if (slashIndex == -1) // no slash found => end of path = file location
            {
                var fileHash = entry.GetHash();
                var newPath  = Path.Combine(EntryPath, path);
                newPath = newPath.Replace('\\', '/');

                if (Files.ContainsKey(fileHash))
                {
                    // Log.Msg($"File '{filePath}' already exists => overwriting");
                    Files[fileHash] = new ScsFile(entry, newPath);
                }
                else
                {
                    Files.Add(fileHash, new ScsFile(entry, newPath));
                }

                return;
            }

            if (path.StartsWith("/"))
            {
                path = path.Substring(1);
            }

            var currentDir = path.Substring(0, slashIndex);
            var hashName   = Helper.CombinePath(EntryPath, currentDir);
            var hash       = CityHash.CityHash64(Encoding.UTF8.GetBytes(hashName), (ulong)hashName.Length);

            if (Directories.ContainsKey(hash))
            {
                Directories[hash].AddZipEntry(entry, path.Substring(slashIndex + 1));
            }
            else
            {
                var newPath = Path.Combine(EntryPath, currentDir);
                newPath = newPath.Replace('\\', '/');

                var dir = new ScsDirectory(_rfs, newPath);
                dir.AddZipEntry(entry, path.Substring(slashIndex + 1));

                Directories.Add(hash, dir);
            }
        }
예제 #4
0
        public void AddHashEntry(ScsHashEntry entry)
        {
            if (entry == null)
            {
                return;
            }

            var data     = entry.Read();
            var contents = Encoding.UTF8.GetString(data);

            if (entry.IsDirectory())
            {
                var lines = contents.Split('\n');
                foreach (var line in lines) // loop through file/dir list
                {
                    if (line.Equals(""))
                    {
                        continue;
                    }

                    if (line.StartsWith("*")) // dirs
                    {
                        var dirPath = Path.Combine(EntryPath, line.Substring(1));
                        dirPath = dirPath.Replace('\\', '/');

                        var nextEntry = (ScsHashEntry)entry.GetRootFile().GetEntry(dirPath);
                        var nextHash  = CityHash.CityHash64(Encoding.UTF8.GetBytes(dirPath), (ulong)dirPath.Length);

                        if (nextEntry == null)
                        {
                            Log.Msg($"Could not find hash for '{dirPath}'");
                            continue;
                        }

                        if (!Directories.ContainsKey(nextHash))
                        {
                            var dir = new ScsDirectory(_rfs, dirPath);
                            dir.AddHashEntry(nextEntry);
                            Directories.Add(nextHash, dir);
                        }
                        else
                        {
                            Directories[nextHash].AddHashEntry(nextEntry);
                        }
                    }
                    else // file
                    {
                        var filePath = Path.Combine(EntryPath, line);
                        filePath = filePath.Replace('\\', '/');

                        var nextHash  = CityHash.CityHash64(Encoding.UTF8.GetBytes(filePath), (ulong)filePath.Length);
                        var nextEntry = entry.GetRootFile().GetEntry(filePath);

                        if (nextEntry == null)
                        {
                            Log.Msg($"Could not find hash for '{filePath}'");
                            continue;
                        }

                        if (Files.ContainsKey(nextHash))
                        {
                            // Log.Msg($"File '{filePath}' already exists => overwriting");
                            Files[nextHash] = new ScsFile(nextEntry, filePath);
                        }
                        else
                        {
                            Files.Add(nextHash, new ScsFile(nextEntry, filePath));
                        }
                    }
                }
            }
        }