bool ProfileFileHasPassword(Path path) { ProfileMap map; return Profile::LoadFile(map, path, IgnoreError()) && map.Exists(ProfileKeys::Password); }
static void CheckGRecord(const TCHAR *path) { GRecord grecord; grecord.Initialize(); ok1(grecord.VerifyGRecordInFile(Path(path), IgnoreError())); }
static void CheckTextFile(Path path, const char *const* expect) { FileLineReaderA reader(path, IgnoreError()); ok1(!reader.error()); const char *line; while ((line = reader.ReadLine()) != NULL) { if (*line == 'G') break; ok1(*expect != NULL); if (StringIsEqual(*expect, "HFFTYFRTYPE:", 12)) { ok1(StringIsEqual(line, "HFFTYFRTYPE:", 12)); } else { if (strcmp(line, *expect)) { printf("# \"%s\" fails to match with \"%s\"\n", line, *expect); } ok1(strcmp(line, *expect) == 0); } ++expect; } ok1(*expect == NULL); }
unsigned FlarmNetReader::LoadFile(const TCHAR *path, FlarmNetDatabase &database) { FileLineReaderA file(path, IgnoreError()); if (file.error()) return 0; return LoadFile(file, database); }
unsigned TaskFileSeeYou::Count() { // Reset internal task name memory namesuffixes.clear(); // Open the CUP file FileLineReader reader(path, IgnoreError(), Charset::AUTO); if (reader.error()) return 0; unsigned count = 0; bool in_task_section = false; TCHAR *line; while ((line = reader.ReadLine()) != nullptr) { if (in_task_section) { // If the line starts with a string or "nothing" followed // by a comma it is a new task definition line if (line[0] == _T('\"') || line[0] == _T(',')) { // If we still have space in the task name list if (count < namesuffixes.capacity()) { // If the task doesn't have a name inside the file if (line[0] == _T(',')) namesuffixes.append(nullptr); else { // Ignore starting quote (") line++; // Save pointer to first character TCHAR *name = line; // Skip characters until next quote (") or end of string while (line[0] != _T('\"') && line[0] != _T('\0')) line++; // Replace quote (") by end of string (null) line[0] = _T('\0'); // Append task name to the list if (_tcslen(name) > 0) namesuffixes.append(_tcsdup(name)); else namesuffixes.append(nullptr); } } // Increase the task counter count++; } } else if (StringIsEqualIgnoreCase(line, _T("-----Related Tasks-----"))) { // Found the marker -> all following lines are task lines in_task_section = true; } } // Return number of tasks found in the CUP file return count; }
static void LoadChecklist() { nLists = 0; free(ChecklistText[0]); ChecklistText[0] = NULL; free(ChecklistTitle[0]); ChecklistTitle[0] = NULL; TLineReader *reader = OpenDataTextFile(_T(XCSCHKLIST), IgnoreError()); if (reader == NULL) return; StaticString<MAXDETAILS> Details; TCHAR Name[100]; bool inDetails = false; int i; Details.clear(); Name[0] = 0; TCHAR *TempString; while ((TempString = reader->ReadLine()) != NULL) { // Look for start if (TempString[0] == '[') { if (inDetails) { addChecklist(Name, Details); Details.clear(); Name[0] = 0; } // extract name for (i = 1; i < MAXTITLE; i++) { if (TempString[i] == ']') break; Name[i - 1] = TempString[i]; } Name[i - 1] = 0; inDetails = true; } else { // append text to details string Details.append(TempString); Details.push_back(_T('\n')); } } delete reader; if (inDetails) { addChecklist(Name, Details); } }
/** * Opens XCSoars own FLARM details file, parses it and * adds its entries as FlarmLookupItems * @see AddSecondaryItem */ static void LoadSecondary(FlarmNameDatabase &db) { LogFormat("OpenFLARMDetails"); TLineReader *reader = OpenDataTextFile(_T("xcsoar-flarm.txt"), IgnoreError()); if (reader != NULL) { LoadFlarmNameFile(*reader, db); delete reader; } }
/** * Loads the FLARMnet file */ static void LoadFLARMnet(FlarmNetDatabase &db) { NLineReader *reader = OpenDataTextFileA(_T("data.fln"), IgnoreError()); if (reader == NULL) return; unsigned num_records = FlarmNetReader::LoadFile(*reader, db); delete reader; if (num_records > 0) LogFormat("%u FLARMnet ids found", num_records); }
static void DrawFlights(Canvas &canvas, const PixelRect &rc) { FileLineReaderA file(Path("/mnt/onboard/XCSoarData/flights.log"), IgnoreError()); if (file.error()) return; FlightListRenderer renderer(normal_font, bold_font); FlightParser parser(file); FlightInfo flight; while (parser.Read(flight)) renderer.AddFlight(flight); renderer.Draw(canvas, rc); }
int main(int argc, char **argv) { plan_tests(51); const Path path(_T("output/test/test.igc")); File::Delete(path); Run(path); CheckTextFile(path, expect); GRecord grecord; grecord.Initialize(); ok1(grecord.VerifyGRecordInFile(path, IgnoreError())); return exit_status(); }
/** * 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 ManagedFileListWidget::LoadRepositoryFile() { #ifdef HAVE_DOWNLOAD_MANAGER mutex.Lock(); repository_modified = false; repository_failed = false; mutex.Unlock(); #endif repository.Clear(); const auto path = LocalPath(_T("repository")); FileLineReaderA reader(path, IgnoreError()); if (reader.error()) return; ParseFileRepository(repository, reader); }
bool ReadWaypointFile(struct zzip_dir *dir, const char *path, WaypointFileType file_type, Waypoints &way_points, WaypointFactory factory, OperationEnvironment &operation) { auto *reader = CreateWaypointReader(file_type, factory); if (reader == nullptr) return false; bool success = false; ZipLineReader line_reader(dir, path, IgnoreError(), Charset::AUTO); if (!line_reader.error()) { reader->Parse(way_points, line_reader, operation); success = true; } delete reader; return success; }
static void ReadIGCMetaData(Path path, IGCHeader &header, BrokenDate &date) { strcpy(header.manufacturer, "XXX"); strcpy(header.id, "000"); header.flight = 0; FileLineReaderA reader(path, IgnoreError()); if (reader.error()) { date = BrokenDate::TodayUTC(); return; } char *line = reader.ReadLine(); if (line != nullptr) IGCParseHeader(line, header); line = reader.ReadLine(); if (line == nullptr || !IGCParseDateRecord(line, date)) date = BrokenDate::TodayUTC(); }
static bool ReadWorldFile(struct zzip_dir *dir, const char *path, WorldFileData &data) { ZipLineReaderA reader(dir, path, IgnoreError()); return !reader.error() && ReadWorldFile(reader, data); }
OrderedTask* TaskFileSeeYou::GetTask(const TaskBehaviour &task_behaviour, const Waypoints *waypoints, unsigned index) const { // Create FileReader for reading the task FileLineReader reader(path, IgnoreError(), Charset::AUTO); if (reader.error()) return nullptr; // Read waypoints from the CUP file Waypoints file_waypoints; { const WaypointFactory factory(WaypointOrigin::NONE); WaypointReaderSeeYou waypoint_file(factory); NullOperationEnvironment operation; waypoint_file.Parse(file_waypoints, reader, operation); } file_waypoints.Optimise(); if (!reader.Rewind()) return nullptr; TCHAR *line = AdvanceReaderToTask(reader, index); if (line == nullptr) return nullptr; // Read waypoint list // e.g. "Club day 4 Racing task","085PRI","083BOJ","170D_K","065SKY","0844YY", "0844YY" // TASK NAME , TAKEOFF, START , TP1 , TP2 , FINISH , LANDING TCHAR waypoints_buffer[1024]; const TCHAR *wps[30]; size_t n_waypoints = ExtractParameters(line, waypoints_buffer, wps, 30, true, _T('"')); // Some versions of StrePla append a trailing ',' without a following // WP name resulting an empty last entry. Remove it from the results if (n_waypoints > 0 && wps[n_waypoints - 1][0] == _T('\0')) n_waypoints --; // At least taskname and takeoff, start, finish and landing points are needed if (n_waypoints < 5) return nullptr; // Remove taskname, start point and landing point from count n_waypoints -= 3; SeeYouTaskInformation task_info; SeeYouTurnpointInformation turnpoint_infos[30]; WaypointPtr waypoints_in_task[30]; ParseCUTaskDetails(reader, &task_info, turnpoint_infos); OrderedTask *task = new OrderedTask(task_behaviour); task->SetFactory(task_info.wp_dis ? TaskFactoryType::RACING : TaskFactoryType::AAT); AbstractTaskFactory& fact = task->GetFactory(); const TaskFactoryType factType = task->GetFactoryType(); OrderedTaskSettings beh = task->GetOrderedTaskSettings(); if (factType == TaskFactoryType::AAT) { beh.aat_min_time = task_info.task_time; } if (factType == TaskFactoryType::AAT || factType == TaskFactoryType::RACING) { beh.start_constraints.max_height = (unsigned)task_info.max_start_altitude; beh.start_constraints.max_height_ref = AltitudeReference::MSL; } task->SetOrderedTaskSettings(beh); // mark task waypoints. Skip takeoff and landing point for (unsigned i = 0; i < n_waypoints; i++) { auto file_wp = file_waypoints.LookupName(wps[i + 2]); if (file_wp == nullptr) return nullptr; // Try to find waypoint by name auto wp = waypoints->LookupName(file_wp->name); // If waypoint by name found and closer than 10m to the original if (wp != nullptr && wp->location.DistanceS(file_wp->location) <= fixed(10)) { // Use this waypoint for the task waypoints_in_task[i] = wp; continue; } // Try finding the closest waypoint to the original one wp = waypoints->GetNearest(file_wp->location, fixed(10)); // If closest waypoint found and closer than 10m to the original if (wp != nullptr && wp->location.DistanceS(file_wp->location) <= fixed(10)) { // Use this waypoint for the task waypoints_in_task[i] = wp; continue; } // Use the original waypoint waypoints_in_task[i] = file_wp; } //now create TPs and OZs for (unsigned i = 0; i < n_waypoints; i++) { ObservationZonePoint* oz = CreateOZ(turnpoint_infos[i], i, n_waypoints, waypoints_in_task, factType); assert(waypoints_in_task[i]); OrderedTaskPoint *pt = CreatePoint(i, n_waypoints, WaypointPtr(waypoints_in_task[i]), fact, oz, factType); if (pt != nullptr) fact.Append(*pt, false); delete pt; } return task; }