void OpenFile() { puts("Путь к файлу:"); scanf("%s", &path); if (file = fopen(path, "r")) { //Считаем количество строк в фале recordCount = GetRowsCount(file); //Инициализируем массив структур routeArray = new Route[recordCount]; printf("Файл '%s' загружен! Количество записей: %u.\n", path, recordCount); isLoaded = true; //Парсим строки файла в структуры char fcontent[BUFFER_SIZE]; char* line; int i = 0; while (fgets(fcontent, BUFFER_SIZE, file)) { line = strdup(fcontent); routeArray[i] = ParseRoute(line); free(line); i++; } Print(); } else { printf("Не удалось загрузить файл '%s'.\n", path); getch(); isLoaded = false; } }
LoadStatus_t GdbLoader::Load(void) { m_cOrdinal = 0; SetProgress(g_hExp, "Loading...", 0); size_t cOffset = sizeof(g_pGdbSignature); size_t cFileSize = (size_t)GetFileSize(); do { const size_t cEndOffset_tmp = __min(cOffset + sizeof(CGdbRecordHdr), cFileSize); const char * const pRecord_tmp = GetFilePart(cOffset, cEndOffset_tmp); if (pRecord_tmp == NULL) return lsFailed; const CGdbRecordHdr * const pHdr_tmp = reinterpret_cast<const CGdbRecordHdr *>(pRecord_tmp); size_t cNextOffset = __min(cOffset + sizeof(CGdbRecordHdr) + pHdr_tmp->dwLen, cFileSize); const char * const pRecord = GetFilePart (cOffset, cNextOffset); if (pRecord == NULL) return lsFailed; const CGdbRecordHdr * const pHdr = reinterpret_cast<const CGdbRecordHdr *>(pRecord); switch (pHdr->btType) { case 'D': { // GDB format version. const CGdbFormatVersion * const pVer = static_cast<const CGdbFormatVersion *>(pHdr); switch (pVer->wdVersion) { case 0x6B: case 0x6C: case 0x6D: // AddLog(g_hExp, "GDB Format version %d.", pVer->wdVersion - 0x6B + 1); break; default: // ReportText ("Format version: 0x%02X.", pVer->wdVersion); break; } m_b2ndVersion = pVer->wdVersion == 0x6C; m_b3rdVersion = pVer->wdVersion == 0x6D; if (pVer->wdVersion > 0x6D) AddLog(g_hExp, "File was created with an untested version of MapSource.", NULL); break; } case 'A': { // MapSource version. const CGdbMSVersion * const pVer = static_cast<const CGdbMSVersion *> (pHdr); const char * const pRecord = GetFilePart (cOffset, cNextOffset + 10); if (pRecord == NULL) return lsFailed; if (::_strnicmp (pRecord + (cNextOffset - cOffset), "MapSource", 10) == 0) cNextOffset += 10; break; } case 'W': { // Waypoint. const CGdbWaypointHdr * const pWP = static_cast<const CGdbWaypointHdr *> (pHdr); ParseWaypoint (pWP, cOffset, cNextOffset); break; } case 'T': { // Track. const CGdbTrackHdr * const pTrack = static_cast<const CGdbTrackHdr *> (pHdr); ParseTrack (pTrack, cOffset, cNextOffset, cFileSize, false); break; } case 'R': { // Route. const CGdbRouteHdr * const pRoute = static_cast<const CGdbRouteHdr *> (pHdr); ParseRoute (pRoute, cOffset, cNextOffset); break; } case 'L': { // Map reference. const CGdbMapHdr * const pMap = static_cast<const CGdbMapHdr *> (pHdr); break; } case 'V': { // Tail mark and map set info. break; } } cOffset = cNextOffset; SetProgress(g_hExp, NULL, ::MulDiv(100, cOffset, cFileSize)); } while (cOffset < cFileSize); return lsOK; }