Exemple #1
0
 public void AddHashEntry(ScsHashEntry entry)
 {
     if (_rootDirectory == null)
     {
         _rootDirectory = new ScsDirectory(this, "");
         _rootDirectory.AddHashEntry(entry);
     }
     else
     {
         _rootDirectory.AddHashEntry(entry);
     }
 }
Exemple #2
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));
                        }
                    }
                }
            }
        }