You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

explorist_ini.cc 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "defs.h"
  2. #include "inifile.h"
  3. #include "explorist_ini.h"
  4. static inifile_t* inifile;
  5. static const char myname[] = "explorist";
  6. const char*
  7. explorist_read_value(const char* section, const char* key)
  8. {
  9. return inifile_readstr(inifile, section, key);
  10. }
  11. static mag_info*
  12. explorist_ini_try(const char* path)
  13. {
  14. mag_info* info = NULL;
  15. char* inipath;
  16. char* s;
  17. xasprintf(&inipath, "%s/%s", path, "APP/Atlas.ini");
  18. inifile = inifile_init(inipath, myname);
  19. if (!inifile) {
  20. xfree(inipath);
  21. return NULL;
  22. }
  23. info = (mag_info*) xmalloc(sizeof(mag_info));
  24. info->geo_path = NULL;
  25. info->track_path = NULL;
  26. info->waypoint_path = NULL;
  27. s = xstrdup(inifile_readstr(inifile, "UGDS", "WpFolder"));
  28. if (s) {
  29. s = gstrsub(s, "\\", "/");
  30. xasprintf(&info->waypoint_path, "%s/%s", path, s);
  31. }
  32. s = xstrdup(inifile_readstr(inifile, "UGDS", "GcFolder"));
  33. if (s) {
  34. s = gstrsub(s, "\\", "/");
  35. xasprintf(&info->geo_path, "%s/%s", path, s);
  36. }
  37. s = xstrdup(inifile_readstr(inifile, "UGDS", "TrkFolder"));
  38. if (s) {
  39. s = gstrsub(s, "\\", "/");
  40. xasprintf(&info->track_path, "%s/%s", path, s);
  41. }
  42. inifile_done(inifile);
  43. xfree(inipath);
  44. return info;
  45. }
  46. mag_info*
  47. explorist_ini_get(const char** dirlist)
  48. {
  49. mag_info* r = NULL;
  50. while (dirlist && *dirlist) {
  51. r = explorist_ini_try(*dirlist);
  52. if (r) {
  53. return r;
  54. }
  55. }
  56. return r;
  57. }
  58. void
  59. explorist_ini_done(mag_info* info)
  60. {
  61. xfree(info->geo_path);
  62. xfree(info->track_path);
  63. xfree(info->waypoint_path);
  64. xfree(info);
  65. }