astandardpaths.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. *openPilot Log - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020 Felix Turowsky
  4. *
  5. *This program is free software: you can redistribute it and/or modify
  6. *it under the terms of the GNU General Public License as published by
  7. *the Free Software Foundation, either version 3 of the License, or
  8. *(at your option) any later version.
  9. *
  10. *This program is distributed in the hope that it will be useful,
  11. *but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. *GNU General Public License for more details.
  14. *
  15. *You should have received a copy of the GNU General Public License
  16. *along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #include "src/classes/astandardpaths.h"
  19. QMap<AStandardPaths::Directories, QDir> AStandardPaths::directories;
  20. bool AStandardPaths::setup()
  21. {
  22. auto data_location = QStandardPaths::AppDataLocation;
  23. directories = {
  24. {Database, QDir(QStandardPaths::writableLocation(data_location))},
  25. {Templates, QDir(QStandardPaths::writableLocation(data_location)
  26. + QStringLiteral("/templates"))},
  27. {Backup, QDir(QStandardPaths::writableLocation(data_location)
  28. + QStringLiteral("/backup"))}
  29. };
  30. if (scan_directories())
  31. return true;
  32. return false;
  33. }
  34. const QDir& AStandardPaths::directory(Directories location)
  35. {
  36. return directories[location];
  37. }
  38. const QMap<AStandardPaths::Directories, QDir>& AStandardPaths::allDirectories()
  39. {
  40. return directories;
  41. }
  42. bool AStandardPaths::scan_directories()
  43. {
  44. for(const auto& dir : directories){
  45. if(!dir.exists()) {
  46. DEB << dir << "Does not exist. Creating:" << dir.absolutePath();
  47. if (!dir.mkpath(dir.absolutePath()))
  48. return false;
  49. }
  50. }
  51. return true;
  52. }