void clsAppSettings::CheckIfFirstRun() { readWriteMutex->lockInline(); bool bFirstRun = userSettings->value("IsFirstRun").toBool(); if(!bFirstRun) { userSettings->setValue("IsFirstRun",true); WriteDefaultSettings(); } userSettings->sync(); readWriteMutex->unlockInline(); }
int main(int argc, char **argv) { FILE *fpin; AppData *ad; if (argc < 2 || argc > 4) { fprintf(stderr, "gpxrewrite - Part of %s\n", PACKAGE_STRING); fprintf(stderr, "Error: Incorrect arguments\n"); fprintf(stderr, " gpxrewrite settings.ini (reads file from stdin, writes to stdout)\n"); fprintf(stderr, " gpxrewrite settings.ini gpxfile.gpx (writes to stdout)\n"); fprintf(stderr, " gpxrewrite settings.ini gpxfile.gpx output.gpx\n"); exit(1); } DEBUG("Get memory"); ad = getMemory(sizeof(AppData)); DEBUG("Write default settings"); WriteDefaultSettings(&(ad->settings)); DEBUG("Read settings file"); ReadSettings(&(ad->settings), argv[1]); if (argc >= 3) { DEBUG("Opening input file"); fpin = fopen(argv[2], "r"); if (! fpin) { fprintf(stderr, "Error opening input file: %s\n", argv[2]); exit(3); } } else { DEBUG("Using stdin"); fpin = stdin; } if (argc >= 4) { DEBUG("Opening output file"); ad->fpout = fopen(argv[3], "w"); if (! ad->fpout) { fprintf(stderr, "Error opening output file: %s\n", argv[3]); exit(4); } } else { DEBUG("Using stdout"); ad->fpout = stdout; } DEBUG("Writing XML header"); fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ad->fpout); DEBUG("Parsing XML"); ParseXML(fpin, &WaypointHandler, &NonWaypointHandler, (void *) ad); DEBUG("Writing trailing newline"); fputs(GetXMLNewline(), ad->fpout); if (fpin != stdin) { DEBUG("Closing input file"); fclose(fpin); } if (ad->fpout != stdout) { DEBUG("Closing output file"); fclose(ad->fpout); } DEBUG("Freeing settings"); FreeSettings(&(ad->settings)); DEBUG("Freeing memory"); freeMemory((void **) &ad); return 0; }