// Save the index to file, assuming it is loaded and sorted void CreateIndexFromPlaceInfos(ProgressReportDelegate pr, int nTask, int nTotal) { // initialize Writer using (FileStream fsIdx = File.Open(IndexFileName(), FileMode.Create, FileAccess.Write, FileShare.None)) using (BinaryWriter bwIdx = new BinaryWriter(fsIdx, System.Text.Encoding.Default)) { // write index entry count (total overall place infos) bwIdx.Write(this.m_indexedPlaces.Length); // iterate over PlaceInfos int nPlaceCount = m_indexedPlaces.Length; for (int i = 0; i < nPlaceCount; i++) { IndexedPlace ip = m_indexedPlaces[i]; bwIdx.Write(ip.indexEntry.fileNumber); bwIdx.Write(ip.indexEntry.seekOffset); if (i % 100 == 0) { // don't update progress too often as that slows down if (pr != null) { pr(ProgressPercent(nTask, nTotal, 0, nPlaceCount, i), "Writing index"); } } } } }
// add the places from a single wwp file to our places array // note that nNextEntry is passed by reference - the total count is accumulated here void AddSingleWwpPlaces(int nFileNbr, ref int nNextEntry) { // open reader using (BinaryReader brWwp = OpenWwpReader(nFileNbr)) { int nEntryCount = brWwp.ReadInt32(); // read number of entries for (int i = 0; i < nEntryCount; i++) { IndexedPlace ip = new IndexedPlace(); // allocate indexed place class to store entries ip.pn = new WorldWindPlacename(); ip.placeDescriptor = this.m_placeNameSet; // "inherit" placeNameSet ip.indexEntry.fileNumber = (System.Int16)nFileNbr; // remember file number ip.indexEntry.seekOffset = (int)brWwp.BaseStream.Position; // and location in file PlaceItem pi = ip; ReadPlaceName(brWwp, ref pi.pn, MetaDataAction.Skip); // skipping the metadata is faster this.m_indexedPlaces[nNextEntry++] = ip; // remember this indexed place } } }
// add the places from a single wwp file to our places array // note that nNextEntry is passed by reference - the total count is accumulated here void AddSingleWwpPlaces(int nFileNbr, ref int nNextEntry) { // open reader using( BinaryReader brWwp = OpenWwpReader(nFileNbr) ) { int nEntryCount = brWwp.ReadInt32(); // read number of entries for(int i=0; i < nEntryCount; i++) { IndexedPlace ip = new IndexedPlace(); // allocate indexed place class to store entries ip.pn = new WorldWindPlacename(); ip.placeDescriptor = this.m_placeNameSet; // "inherit" placeNameSet ip.indexEntry.fileNumber = (System.Int16)nFileNbr; // remember file number ip.indexEntry.seekOffset = (int)brWwp.BaseStream.Position; // and location in file PlaceItem pi = ip; ReadPlaceName(brWwp, ref pi.pn, MetaDataAction.Skip); // skipping the metadata is faster this.m_indexedPlaces[nNextEntry++] = ip; // remember this indexed place } } }