private void Run() { while (!inputEntries.IsCompleted) { RawEntry entry = null; try { entry = inputEntries.Take(); var parts = entry.AudioFile.Split('|'); byte[] hash; Stream str = null; try { str = File.OpenRead(@"..\DATA\AUDIO\" + parts[0]); // If it was a UTF file, grab the entry from it if (parts.Length > 1) { str = UTFReader.ReadEntry(str, parts[1]); } hash = AudioHasher.Hash(str, entry.Hack); Console.WriteLine($"Convert: {entry.AudioFile} -> {hash.DebugSubtitleKey()}"); } finally { str?.Dispose(); } outputEntries.Add(new HashedEntry(entry, hash)); } catch (FileSanityException e) { e.FileName = entry?.AudioFile; throw; } catch (InvalidOperationException) { //inputEntries got completed during Take() break; } } }
private void CreateCommodity(List <KeyValue> dataBlock, string outputPath, List <KeyDoubleValue> commodities) { string type = (from kvO in dataBlock where kvO.Key.Equals("category") select kvO.Value).FirstOrDefault(); if (type.Equals("commodity")) { string nickName = (from db in dataBlock where db.Key.Equals("nickname") select db.Value).FirstOrDefault().ToLower(); int nID = Convert.ToInt32((from cm in commodities where cm.Key.Equals(nickName) select cm.ValueA).FirstOrDefault()); if (nID > 0) { string nHex = nID.ToString("X"); int resNameID = Convert.ToInt32(nHex.Substring(1), 16); string name = (from rsrc in this.Dllstrings where rsrc.Id == resNameID && rsrc.Type == ResType.String select rsrc.Data).FirstOrDefault(); int iID = Convert.ToInt32((from cm in commodities where cm.Key.Equals(nickName) select cm.ValueB).FirstOrDefault()); string iHex = iID.ToString("X"); int resInfoID = Convert.ToInt32(iHex.Substring(1), 16); string infos = (from rsrc in this.DllXml where rsrc.Id == resInfoID && rsrc.Type == ResType.XML select rsrc.Data).FirstOrDefault(); if (!string.IsNullOrEmpty(infos)) { infos = infos.Substring(infos.IndexOf("|@") + 2); } string utfPath = (from db in dataBlock where db.Key.Equals("item_icon") select db.Value).FirstOrDefault(); string basePrice = (from db in dataBlock where db.Key.Equals("price") select db.Value).FirstOrDefault(); string utfFilePath = this.Path + @"Data\" + utfPath; string fileName = null; if (File.Exists(utfFilePath)) { using (UTFReader utfRdr = new UTFReader(utfFilePath)) { fileName = utfRdr.GetImage(outputPath, nickName); } } this.Commodities.Add(new Commodity(nickName, name, infos, fileName, Int32.Parse(basePrice))); } } }