bool WaypointGlue::LoadWaypoints(Waypoints &way_points, const RasterTerrain *terrain, OperationEnvironment &operation) { LogFormat("ReadWaypoints"); operation.SetText(_("Loading Waypoints...")); bool found = false; // Delete old waypoints way_points.Clear(); TCHAR path[MAX_PATH]; LoadWaypointFile(way_points, LocalPath(path, _T("user.cup")), WaypointFileType::SEEYOU, WaypointOrigin::USER, terrain, operation); // ### FIRST FILE ### if (Profile::GetPath(ProfileKeys::WaypointFile, path)) found |= LoadWaypointFile(way_points, path, WaypointOrigin::PRIMARY, terrain, operation); // ### SECOND FILE ### if (Profile::GetPath(ProfileKeys::AdditionalWaypointFile, path)) found |= LoadWaypointFile(way_points, path, WaypointOrigin::ADDITIONAL, terrain, operation); // ### WATCHED WAYPOINT/THIRD FILE ### if (Profile::GetPath(ProfileKeys::WatchedWaypointFile, path)) found |= LoadWaypointFile(way_points, path, WaypointOrigin::WATCHED, terrain, operation); // ### MAP/FOURTH FILE ### // If no waypoint file found yet if (!found) { auto dir = OpenMapFile(); if (dir != nullptr) { found |= LoadWaypointFile(way_points, dir, "waypoints.xcw", WaypointFileType::WINPILOT, WaypointOrigin::MAP, terrain, operation); found |= LoadWaypointFile(way_points, dir, "waypoints.cup", WaypointFileType::SEEYOU, WaypointOrigin::MAP, terrain, operation); zzip_dir_close(dir); } } // Optimise the waypoint list after attaching new waypoints way_points.Optimise(); // Return whether waypoints have been loaded into the waypoint list return found; }
void ChooseMapFile ( HWND hWnd ) { OPENFILENAME OpenFileName; char Directory[255], MapFileName[255]; memset(&MapFileName, 0, sizeof(MapFileName)); memset(&OpenFileName, 0, sizeof(OpenFileName)); GetCurrentDirectory( 255, Directory ); GetMapDirectory( Directory ); OpenFileName.lStructSize = sizeof( OpenFileName ); OpenFileName.hwndOwner = hWnd; OpenFileName.lpstrFilter = "Map file(*.map;*.cod)\0*.map;*.cod\0All files (*.*)\0*.*\0"; OpenFileName.lpstrFile = MapFileName; OpenFileName.lpstrInitialDir = Directory; OpenFileName.nMaxFile = MAX_PATH; OpenFileName.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; if (GetOpenFileName (&OpenFileName)) { GetCurrentDirectory( 255, Directory ); SetMapDirectory( Directory ); ResetMappings (); if (!OpenMapFile(MapFileName)) { DisplayError("Failed to process %s",MapFileName); ResetMappings (); } } }
static std::unique_ptr<NLineReader> OpenMapTextFileA(const char *in_map_file) try { assert(in_map_file != nullptr); auto archive = OpenMapFile(); if (!archive) return nullptr; return std::make_unique<ZipLineReaderA>(archive->get(), in_map_file); } catch (const std::runtime_error &e) { LogError(e); return nullptr; }
/** * Load topography from the map file (ZIP), load the other files from * the same ZIP file. */ static bool LoadConfiguredTopographyZip(TopographyStore &store, OperationEnvironment &operation) try { auto archive = OpenMapFile(); if (!archive) return false; ZipLineReaderA reader(archive->get(), "topology.tpl"); store.Load(operation, reader, nullptr, archive->get()); return true; } catch (...) { LogError(std::current_exception(), "No topography in map file"); return false; }
/** * Load topography from the map file (ZIP), load the other files from * the same ZIP file. */ static bool LoadConfiguredTopographyZip(TopographyStore &store, OperationEnvironment &operation) { auto dir = OpenMapFile(); if (dir == nullptr) return false; ZipLineReaderA reader(dir, "topology.tpl", IgnoreError()); if (reader.error()) { zzip_dir_close(dir); LogFormat(_T("No topography in map file")); return false; } store.Load(operation, reader, nullptr, dir); zzip_dir_close(dir); return true; }
void ReadAirspace(Airspaces &airspaces, RasterTerrain *terrain, const AtmosphericPressure &press, OperationEnvironment &operation) { LogFormat("ReadAirspace"); operation.SetText(_("Loading Airspace File...")); bool airspace_ok = false; AirspaceParser parser(airspaces); // Read the airspace filenames from the registry auto path = Profile::GetPath(ProfileKeys::AirspaceFile); if (!path.IsNull()) airspace_ok |= ParseAirspaceFile(parser, path, operation); path = Profile::GetPath(ProfileKeys::AdditionalAirspaceFile); if (!path.IsNull()) airspace_ok |= ParseAirspaceFile(parser, path, operation); auto archive = OpenMapFile(); if (archive) airspace_ok |= ParseAirspaceFile(parser, archive->get(), "airspace.txt", operation); if (airspace_ok) { airspaces.Optimise(); airspaces.SetFlightLevels(press); if (terrain != NULL) airspaces.SetGroundLevels(*terrain); } else // there was a problem airspaces.Clear(); }
static TLineReader * OpenMapTextFile(const char *in_map_file, Charset cs) { assert(in_map_file != nullptr); auto dir = OpenMapFile(); if (dir == nullptr) return nullptr; Error error; ZipLineReader *reader = new ZipLineReader(dir, in_map_file, error, cs); zzip_dir_close(dir); if (reader == nullptr) { LogError(error); return nullptr; } if (reader->error()) { delete reader; return nullptr; } return reader; }
void CAL_SetupMapFile() { Sint16 i; bstone::FileStream handle; Sint32 pos; char fname[13]; mapfiletype header; maptype* map_header; // // load maphead.ext (offsets and tileinfo for map file) // strcpy(fname, mheadname); strcat(fname, extension); handle.open(fname); if (!handle.is_open()) CA_CannotOpen(fname); handle.read(&header.RLEWtag, sizeof(header.RLEWtag)); handle.read(&header.headeroffsets, sizeof(header.headeroffsets)); rlew_tag = header.RLEWtag; // // open the data file // OpenMapFile(); // // load all map header // for (i = 0; i < NUMMAPS; ++i) { pos = header.headeroffsets[i]; if (pos < 0) continue; mapheaderseg[i] = new maptype(); map_header = mapheaderseg[i]; maphandle.set_position(pos); maphandle.read( &map_header->planestart, sizeof(map_header->planestart)); maphandle.read( &map_header->planelength, sizeof(map_header->planelength)); maphandle.read( &map_header->width, sizeof(map_header->width)); maphandle.read( &map_header->height, sizeof(map_header->height)); maphandle.read( &map_header->name, sizeof(map_header->name)); } // // allocate space for 3 64*64 planes // for (i = 0; i < MAPPLANES; ++i) mapsegs[i] = new Uint16[64 * 64]; #if FORCE_FILE_CLOSE CloseMapFile(); #endif }