static Jenkins96 HandleLine(string line, ParallelLoopState state, Jenkins96 hasher) { if (string.IsNullOrWhiteSpace(line)) { return(hasher); } if (line.IndexOfAny(pathInvalidChars) != -1) { return(hasher); } line = line.Replace('/', '\\'); //string extLower = Path.GetExtension(line).ToLower(); //if (extLower == ".mdx" || extLower == ".mdl") //{ // line = Path.ChangeExtension(line, ".m2"); // extLower = ".m2"; //} ulong hash = hasher.ComputeHash(line); if (!CheckName(hash, line)) { return(hasher); } processed[hash] = true; return(hasher); }
public static void LoadFilelist() { if (!Directory.Exists(Settings.ApplicationPath + @"\ListFiles\")) { Directory.CreateDirectory(Settings.ApplicationPath + @"\ListFiles\"); } if (File.Exists(Settings.ApplicationPath + @"\ListFiles\Listfile.txt")) { StreamReader sr = File.OpenText(Settings.ApplicationPath + @"\ListFiles\Listfile.txt"); string[] ListFile = sr.ReadToEnd().Split("\n"[0]); Debug.Log("FileList Lines : " + ListFile.Length); foreach (string item in ListFile) { if (item != null && item != "") { ulong hashUlong = Hasher.ComputeHash(item); if (MyRootData.ContainsKey(hashUlong)) { FileList.Add(item); FileListDictionary.Add(item, hashUlong); } } } } else { Debug.Log("Missing Listfile"); } }
public static void Validate(string filename) { if (Hashes.Contains(Jenkins96.ComputeHash(filename))) { Filenames.Enqueue(filename); } }
public IEnumerable <InstallEntry> GetEntries(ulong hash) { foreach (var entry in InstallData) { if (Hasher.ComputeHash(entry.Name) == hash) { yield return(entry); } } }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { worker.ReportProgress(0, "Loading listfile.."); var linelist = new List <string>(); if (!File.Exists("listfile.txt")) { worker.ReportProgress(20, "Downloading listfile.."); UpdateListfile(); } if (!File.Exists("definitions/Map.dbd")) { worker.ReportProgress(30, "Downloading database definitions.."); UpdateDefinition("Map"); } worker.ReportProgress(50, "Loading listfile from disk.."); var hasher = new Jenkins96(); foreach (var line in File.ReadAllLines("listfile.txt")) { if (CASC.FileExists(line)) { linelist.Add(line.ToLower()); filenameLookup.Add(hasher.ComputeHash(line), line); } } worker.ReportProgress(70, "Sorting listfile.."); linelist.Sort(); var lines = linelist.ToArray(); linelist = null; var unwantedExtensions = new List <string>(); for (var u = 0; u < 512; u++) { unwantedExtensions.Add("_" + u.ToString().PadLeft(3, '0') + ".wmo"); } var unwanted = unwantedExtensions.ToArray(); unwantedExtensions = null; for (var i = 0; i < lines.Count(); i++) { if (showWMO && lines[i].EndsWith(".wmo")) { if (!unwanted.Contains(lines[i].Substring(lines[i].Length - 8, 8)) && !lines[i].EndsWith("lod.wmo") && !lines[i].EndsWith("lod1.wmo") && !lines[i].EndsWith("lod2.wmo") && !lines[i].EndsWith("lod3.wmo")) { models.Add(lines[i]); } } if (showM2 && lines[i].EndsWith(".m2")) { models.Add(lines[i]); } if (lines[i].EndsWith(".blp")) { textures.Add(lines[i]); } if (i % 1000 == 0) { var progress = (i * 100) / lines.Count(); worker.ReportProgress(progress, "Filtering listfile.."); } } lines = null; }
static bool CheckName(Jenkins96 hasher, string name) { return(CheckName(hasher.ComputeHash(name), name)); }
public void Write() { foreach (var index in LocalIndices) { if (!index.Changed) { continue; } uint pC = 0; Jenkins96 hasher = new Jenkins96(); using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { bw.Write(index.HeaderHashSize); bw.Write((uint)0); // HeaderHash bw.Write(index._2); bw.Write(index.BucketIndex); bw.Write(index._4); bw.Write(index.EntrySizeBytes); bw.Write(index.EntryOffsetBytes); bw.Write(index.EntryKeyBytes); bw.Write(index.ArchiveFileHeaderBytes); bw.Write(index.ArchiveTotalSizeMaximum); bw.Write(new byte[8]); bw.Write((uint)index.Entries.Count * 18); bw.Write((uint)0); // EntriesHash // entries index.Entries.Sort(new HashComparer()); foreach (var entry in index.Entries) { bw.Write(entry.Key); bw.WriteUInt40BE(entry.ArchiveOffset); bw.Write(entry.Size); } // update EntriesHash bw.BaseStream.Position = 0x28; for (int i = 0; i < index.Entries.Count; i++) { byte[] entryhash = new byte[18]; bw.BaseStream.Read(entryhash, 0, entryhash.Length); hasher.ComputeHash(entryhash, out pC); } bw.BaseStream.Position = 0x24; bw.Write(pC); // update HeaderHash bw.BaseStream.Position = 8; byte[] headerhash = new byte[index.HeaderHashSize]; bw.BaseStream.Read(headerhash, 0, headerhash.Length); hasher.ComputeHash(headerhash, out pC, true); bw.BaseStream.Position = 4; bw.Write(pC); // minimum file length constraint if (bw.BaseStream.Length < CHUNK_SIZE) { bw.BaseStream.SetLength(CHUNK_SIZE); } // save file to output var bucket = index.BucketIndex.ToString("X2"); var version = long.Parse(Path.GetFileNameWithoutExtension(index.BaseFile).Substring(2), NumberStyles.HexNumber); string filename = bucket + version.ToString("X8") + ".idx"; var path = Path.Combine(CASContainer.Settings.OutputPath, Helper.GetCDNPath(filename.ToLowerInvariant(), "data")); using (var fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read)) { fs.Seek(0, SeekOrigin.End); ms.Position = 0; ms.CopyTo(fs); fs.Flush(); } index.Changed = false; } } }
public bool FileExists(string file) => FileExists(Hasher.ComputeHash(file));
public int GetFileDataIdByName(string name) { return(GetFileDataIdByHash(Hasher.ComputeHash(name))); }