WaypointFileType DetermineWaypointFileType(const TCHAR *path) { // If WinPilot waypoint file -> save type and return true if (MatchesExtension(path, _T(".dat")) || MatchesExtension(path, _T(".xcw"))) return WaypointFileType::WINPILOT; // If SeeYou waypoint file -> save type and return true if (MatchesExtension(path, _T(".cup"))) return WaypointFileType::SEEYOU; // If Zander waypoint file -> save type and return true if (MatchesExtension(path, _T(".wpz"))) return WaypointFileType::ZANDER; // If FS waypoint file -> save type and return true if (MatchesExtension(path, _T(".wpt"))) { std::unique_ptr<TLineReader> reader(OpenTextFile(path)); if (reader && WaypointReaderFS::VerifyFormat(*reader)) return WaypointFileType::FS; reader.reset(OpenTextFile(path)); if (reader && WaypointReaderOzi::VerifyFormat(*reader)) return WaypointFileType::OZI_EXPLORER; reader.reset(OpenTextFile(path)); if (reader && WaypointReaderCompeGPS::VerifyFormat(*reader)) return WaypointFileType::COMPE_GPS; } return WaypointFileType::UNKNOWN; }
bool WaypointGlue::IsWritable(int file_number) { TCHAR file[MAX_PATH]; if (!GetPath(file_number, file)) return false; return (MatchesExtension(file, _T(".dat")) || MatchesExtension(file, _T(".xcw"))); }
DebugReplay * CreateDebugReplay(Args &args) { if (!args.IsEmpty() && MatchesExtension(args.PeekNext(), ".igc")) { const char *input_file = args.ExpectNext(); FileLineReaderA *reader = new FileLineReaderA(input_file); if (reader->error()) { delete reader; fprintf(stderr, "Failed to open %s\n", input_file); return NULL; } return new DebugReplayIGC(reader); } const tstring driver_name = args.ExpectNextT(); const struct DeviceRegister *driver = FindDriverByName(driver_name.c_str()); if (driver == NULL) { _ftprintf(stderr, _T("No such driver: %s\n"), driver_name.c_str()); return NULL; } const char *input_file = args.ExpectNext(); FileLineReaderA *reader = new FileLineReaderA(input_file); if (reader->error()) { delete reader; fprintf(stderr, "Failed to open %s\n", input_file); return NULL; } return new DebugReplayNMEA(reader, driver); }
bool DeleteOldIGCFile(const NMEA_INFO &gps_info, TCHAR *pathname) { HANDLE hFind; // file handle WIN32_FIND_DATA FindFileData; TCHAR oldestname[MAX_PATH]; TCHAR searchpath[MAX_PATH]; TCHAR fullname[MAX_PATH]; _stprintf(searchpath, TEXT("%s*"),pathname); hFind = FindFirstFile(searchpath, &FindFileData); // find the first file if(hFind == INVALID_HANDLE_VALUE) { return false; } if(!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { if (MatchesExtension(FindFileData.cFileName, TEXT(".igc")) || MatchesExtension(FindFileData.cFileName, TEXT(".IGC"))) { // do something... _tcscpy(oldestname, FindFileData.cFileName); } else { return false; } } bool bSearch = true; while(bSearch) { // until we finds an entry if(FindNextFile(hFind,&FindFileData)) { if(!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (MatchesExtension(FindFileData.cFileName, TEXT(".igc")) || (MatchesExtension(FindFileData.cFileName, TEXT(".IGC"))))) { if (LogFileIsOlder(gps_info,oldestname,FindFileData.cFileName)) { _tcscpy(oldestname, FindFileData.cFileName); // we have a new oldest name } } } else { bSearch = false; } } FindClose(hFind); // closing file handle // now, delete the file... _stprintf(fullname, TEXT("%s%s"),pathname,oldestname); DeleteFile(fullname); return true; // did delete one }
WayPointFile* WayPointFile::create(const TCHAR* filename, int the_filenum) { bool compressed = false; // If filename is empty -> clear and return false if (string_is_empty(filename)) { return NULL; } // check existence of file if (!File::Exists(filename)) { ZipSource zip(filename); if (zip.error()) { // File does not exist, fail return NULL; } else { // File does exist inside map file -> save compressed flag compressed = true; } } // If WinPilot waypoint file -> save type and return true if (MatchesExtension(filename, _T(".dat")) || MatchesExtension(filename, _T(".xcw"))) { return new WayPointFileWinPilot(filename, the_filenum, compressed); } // If SeeYou waypoint file -> save type and return true if (MatchesExtension(filename, _T(".cup"))) { return new WayPointFileSeeYou(filename, the_filenum, compressed); } // If Zander waypoint file -> save type and return true if (MatchesExtension(filename, _T(".wpz"))) { return new WayPointFileZander(filename, the_filenum, compressed); } // unknown return NULL; }
TaskFile* TaskFile::Create(const TCHAR* path) { // If filename is empty or file does not exist if (StringIsEmpty(path) || !File::Exists(path)) return NULL; // If XCSoar task file -> return new TaskFileXCSoar if (MatchesExtension(path, _T(".tsk"))) return new TaskFileXCSoar(path); // If SeeYou task file -> return new TaskFileSeeYou if (MatchesExtension(path, _T(".cup"))) return new TaskFileSeeYou(path); // If IGC file -> return new TaskFileIGC if (MatchesExtension(path, _T(".igc"))) return new TaskFileIGC(path); // unknown task file type return NULL; }
DebugReplay * CreateDebugReplay(Args &args) { DebugReplay *replay; if (!args.IsEmpty() && MatchesExtension(args.PeekNext(), ".igc")) { replay = DebugReplayIGC::Create(args.ExpectNext()); } else { const auto driver_name = args.ExpectNextT(); const auto input_file = args.ExpectNext(); replay = DebugReplayNMEA::Create(input_file, driver_name); } return replay; }
bool Replay::Start(const TCHAR *_path) { assert(_path != NULL); /* make sure the old AbstractReplay instance has cleaned up before creating a new one */ Stop(); _tcscpy(path, _path); if (StringIsEmpty(path)) { replay = new DemoReplayGlue(task_manager); } else if (MatchesExtension(path, _T(".igc"))) { auto reader = new FileLineReaderA(path); if (reader->error()) { delete reader; return false; } replay = new IgcReplay(reader); cli = new CatmullRomInterpolator(fixed(0.98)); cli->Reset(); } else { auto reader = new FileLineReaderA(path); if (reader->error()) { delete reader; return false; } replay = new NmeaReplay(reader, CommonInterface::GetSystemSettings().devices[0]); } if (logger != NULL) logger->ClearBuffer(); virtual_time = fixed(-1); fast_forward = fixed(-1); next_data.Reset(); Timer::Schedule(100); return true; }
void Replay::SetFilename(const TCHAR *name) { if (!name || StringIsEmpty(name)) { mode = MODE_DEMO; return; } Stop(); if (MatchesExtension(name, _T(".igc"))) { mode = MODE_IGC; igc_replay.SetFilename(name); } else { mode = MODE_NMEA; nmea_replay.SetFilename(name); } }