private StarDict(StarDictInfo info, IDictIdx index, string fileName, Encoding encoding) { this.encoding = encoding ?? Encoding.UTF8; this.info = info; this.index = index; this.database = fileName.EndsWith("dz") ? DictZip.OpenRead(fileName) : (IDictDb) new TxtDictDb(fileName); }
public StarDictIdx(StarDictInfo info, Encoding enc = null) { this.encoding = enc ?? Encoding.UTF8; this.offsetSize = info.PointerSize; var fname = info.BaseName + ".idx"; if (File.Exists(fname)) { this.table = new TxtHeteroIdxTable(fname, this.MeasureEntryLength); } else { this.table = new StrHeteroIdxTable(fname + ".gz", this.MeasureEntryLength); } // create and populate the index of index this.indexIndex = new int[info.NumberOfEntries + 1]; for (int cnt = 1, offset = 0; cnt < info.NumberOfEntries; ++cnt) { this.indexIndex[cnt] = offset = this.table.FindNext(offset); } this.indexIndex[info.NumberOfEntries] = info.IndexFileSize; // last sentry }
public static StarDict TryOpen(string baseFileName, Encoding encoding = null) { var info = new StarDictInfo(baseFileName + ".ifo"); if (!info.IsValid) { return(null); } var idx = new StarDictIdx(info); return(new StarDict( info, idx, baseFileName + (File.Exists(baseFileName + ".dict") ? ".dict" : ".dict.dz"), encoding)); }