/// <summary> /// Creates a fake Data Index Group and stores the computed checksum /// </summary> /// <param name="directory"></param> /// <param name="configContainer"></param> #pragma warning disable IDE0051 // Remove unused private members private void GenerateIndexGroup(string directory, Configs.ConfigContainer configContainer) #pragma warning restore IDE0051 // Remove unused private members { if (configContainer == null) { return; } // get the list of data archives var archives = configContainer.CDNConfig.GetValues("archives"); archives.Sort(new MD5HashComparer()); // populate the archive indicies and var temp = new List <IndexEntry>(DataIndices.Sum(x => x.Entries.Count())); foreach (var index in DataIndices) { if (index.IsLooseIndex) { continue; } ushort archiveIndex = (ushort)archives.IndexOf(index.Checksum.ToString()); foreach (var e in index.Entries) { e.IndexOrdinal = archiveIndex; temp.Add(e); } } // sort var comparer = new MD5HashComparer(); temp.Sort((x, y) => comparer.Compare(x.Key, y.Key)); // create a new IndexFile, add all entries and store the checksum in the CDN config var indexFile = new IndexFile(IndexType.Data | IndexType.Group); indexFile.LoadIndicies(temp); indexFile.Write(directory, configContainer); }
/// <summary> /// Sorts the CDN Config archive names /// </summary> private void SortEntries() { if (Type != ConfigType.CDNConfig) { return; } // archive collection - size collection string[,] entries = new string[, ] { { "patch-file-index", "patch-file-index-size" }, { "file-index", "file-index-size" }, { "patch-archives", "patch-archives-index-size" }, { "archives", "archives-index-size" }, }; var comparer = new MD5HashComparer(); for (int i = 0; i < entries.GetLength(0); i++) { if (_data.TryGetValue(entries[i, 0], out var values) && values.Count > 1) { if (!_data.TryGetValue(entries[i, 1], out var sizes)) { values.Sort(comparer); } else { // sizes and values must maintain same index var sort = values.Zip(sizes, (v, s) => (v, s)).OrderBy(x => x.v, comparer).ToArray(); for (int j = 0; j < sort.Length; j++) { values[j] = sort[j].v; sizes[j] = sort[j].s; } } } } }
public void AddNewHash(Combo.ComboInfo info, VersionInfo versionInfo, params ushort[] types) { MD5HashComparer comparer = new MD5HashComparer(); Dictionary <MD5Hash, ushort> addedHashes = new Dictionary <MD5Hash, ushort>(comparer); Dictionary <MD5Hash, ulong> hashGUIDs = new Dictionary <MD5Hash, ulong>(comparer); //var md5 = MD5.Create(); // key = content hash, value = type foreach (KeyValuePair <ulong, ApplicationPackageManifest.Types.PackageRecord> file in Files) { ushort fileType = teResourceGUID.Type(file.Key); //if (!types.Contains(fileType)) continue; if (fileType == 0x9C) { continue; // bundle } if (fileType == 0x77) { continue; // package indice } ContentManifestFile.HashData cmfRecord = CMFMap[file.Key]; if (!versionInfo.ContentHashes.Contains(cmfRecord.HashKey)) { if (fileType == 0x4 && teResourceGUID.Locale(file.Key) == 0xF) { continue; // ? } if (fileType == 0x4 && teResourceGUID.Locale(file.Key) == 0x1F) { continue; // ? } if (fileType == 0x4 && teResourceGUID.Locale(file.Key) == 0x2F) { continue; // ? } if (fileType == 0x4 && teResourceGUID.Locale(file.Key) == 0x3F) { continue; // ? } if (fileType == 0x4 && teResourceGUID.Locale(file.Key) == 0x4F) { continue; // ? } if (fileType == 0x4 && teResourceGUID.Locale(file.Key) == 0x5F) { continue; // ? } if (fileType == 0x4 && teResourceGUID.Platform(file.Key) == 0x8) { continue; // effect images } //string currentHash = file.Value.ContentHash.ToHexString(); addedHashes[cmfRecord.HashKey] = fileType; hashGUIDs[cmfRecord.HashKey] = file.Key; // todo //using (Stream stream = OpenFile(file.Value)) { // if (stream == null) continue; // var hash = md5.ComputeHash(stream).ToMD5(); // if (!comparer.Equals(hash, cmfRecord.HashKey)) { // // } //} } } foreach (KeyValuePair <MD5Hash, ushort> addedHash in addedHashes) { if (types.Contains(addedHash.Value)) { ulong guid = hashGUIDs[addedHash.Key]; //string name = teResourceGUID.AsString(guid); Combo.Find(info, guid); } } }