comparison src/core/config.cc @ 135:0a458cb26ff4

filesystem: move to using std::filesystem after C++17 switch old compilers will croak compiling this, but it's not like we *really* need to support them (they probably croak compiling Qt as well)
author Paper <mrpapersonic@gmail.com>
date Thu, 09 Nov 2023 18:01:56 -0500
parents 275da698697d
children 6fdf0632c003
comparison
equal deleted inserted replaced
134:54c9d36207db 135:0a458cb26ff4
19 19
20 /* I'll use an INI-based config file instead of using an 20 /* I'll use an INI-based config file instead of using an
21 XML file like Taiga. */ 21 XML file like Taiga. */
22 22
23 int Config::Load() { 23 int Config::Load() {
24 Filesystem::Path cfg_path = Filesystem::GetConfigPath(); 24 std::filesystem::path cfg_path = Filesystem::GetConfigPath();
25 25
26 mINI::INIFile file(cfg_path.GetPath()); 26 mINI::INIFile file(cfg_path.string());
27 mINI::INIStructure ini; 27 mINI::INIStructure ini;
28 file.read(ini); 28 file.read(ini);
29 29
30 service = Translate::ToService(INI::GetIniValue<std::string>(ini, "General", "Service", "None")); 30 service = Translate::ToService(INI::GetIniValue<std::string>(ini, "General", "Service", "None"));
31 31
38 auth.anilist.auth_token = INI::GetIniValue<std::string>(ini, "Authentication/AniList", "Auth Token", ""); 38 auth.anilist.auth_token = INI::GetIniValue<std::string>(ini, "Authentication/AniList", "Auth Token", "");
39 auth.anilist.user_id = INI::GetIniValue<int>(ini, "Authentication/AniList", "User ID", 0); 39 auth.anilist.user_id = INI::GetIniValue<int>(ini, "Authentication/AniList", "User ID", 0);
40 40
41 torrents.feed_link = INI::GetIniValue<std::string>(ini, "Torrents", "RSS feed", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0"); 41 torrents.feed_link = INI::GetIniValue<std::string>(ini, "Torrents", "RSS feed", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0");
42 42
43 recognition.detect_media_players = INI::GetIniValue<bool>(ini, "Recognition", "Detect media players", true);
44
43 /* ew */ 45 /* ew */
44 locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniValue<std::string>(ini, "General", "Locale", "en_US")))); 46 locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniValue<std::string>(ini, "General", "Locale", "en_US"))));
45 47
46 theme.SetTheme(Translate::ToTheme(INI::GetIniValue<std::string>(ini, "Appearance", "Theme", "Default"))); 48 theme.SetTheme(Translate::ToTheme(INI::GetIniValue<std::string>(ini, "Appearance", "Theme", "Default")));
47 49
48 return 0; 50 return 0;
49 } 51 }
50 52
51 int Config::Save() const { 53 int Config::Save() const {
52 Filesystem::Path cfg_path = Filesystem::GetConfigPath(); 54 std::filesystem::path cfg_path = Filesystem::GetConfigPath();
53 if (!cfg_path.GetParent().Exists()) 55 Filesystem::CreateDirectories(cfg_path);
54 cfg_path.GetParent().CreateDirectories();
55 56
56 mINI::INIFile file(cfg_path.GetPath()); 57 mINI::INIFile file(cfg_path.string());
57 mINI::INIStructure ini; 58 mINI::INIStructure ini;
58 59
59 INI::SetIniValue(ini, "General", "Service", service); 60 INI::SetIniValue(ini, "General", "Service", service);
60 INI::SetIniValue(ini, "General", "Locale", locale.GetLocale().name()); 61 INI::SetIniValue(ini, "General", "Locale", locale.GetLocale().name());
61 62
71 INI::SetIniValue(ini, "Appearance", "Theme", theme.GetTheme()); 72 INI::SetIniValue(ini, "Appearance", "Theme", theme.GetTheme());
72 73
73 INI::SetIniValue(ini, "Torrents", "RSS feed", torrents.feed_link); 74 INI::SetIniValue(ini, "Torrents", "RSS feed", torrents.feed_link);
74 75
75 INI::SetIniValue(ini, "Recognition", "Detect media players", recognition.detect_media_players); 76 INI::SetIniValue(ini, "Recognition", "Detect media players", recognition.detect_media_players);
76 //ini["Recognition"]["Detect streaming media"] = Strings::ToUtf8String(recognition.detect_streaming_media);
77 77
78 file.write(ini); 78 file.write(ini);
79 79
80 return 0; 80 return 0;
81 } 81 }