Mercurial > minori
annotate src/core/config.cc @ 118:39521c47c7a3
*: another huge megacommit, SORRY
The torrents page works a lot better now
Added the edit option to the anime list right click menu
Vectorized currently playing files
Available player and extensions are now loaded at runtime
from files in (dotpath)/players.json and (dotpath)/extensions.json
These paths are not permanent and will likely be moved to
(dotpath)/recognition
...
...
...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 07 Nov 2023 23:40:54 -0500 |
parents | 254b1d2b7096 |
children | 275da698697d |
rev | line source |
---|---|
9 | 1 /** |
2 * config.cpp: | |
3 * parses the config... lol | |
4 **/ | |
5 #include "core/config.h" | |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
6 #include "core/strings.h" |
9 | 7 #include "core/anime.h" |
102 | 8 #include "core/ini.h" |
9 | 9 #include "core/filesystem.h" |
10 #include "core/json.h" | |
90
c4bb49c2f6eb
config: improve handling of vars
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
11 #include "gui/translate/anime.h" |
c4bb49c2f6eb
config: improve handling of vars
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
12 #include "gui/translate/config.h" |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
13 #include <algorithm> |
9 | 14 #include <cstdlib> |
15 #include <cstring> | |
16 #include <filesystem> | |
17 #include <fstream> | |
18 #include <limits.h> | |
19 | |
20 int Config::Load() { | |
61
327568ad9be9
core/fs: finish class-ification of paths
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
21 Filesystem::Path cfg_path = Filesystem::GetConfigPath(); |
102 | 22 |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
23 mINI::INIFile file(cfg_path.GetPath()); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
24 mINI::INIStructure ini; |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
25 file.read(ini); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
26 |
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
27 service = Translate::ToService(INI::GetIniString(ini, "General", "Service", "None")); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
28 /* ew */ |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
29 locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniString(ini, "General", "Locale", "en_US")))); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
30 |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
31 anime_list.language = Translate::ToLanguage(INI::GetIniString(ini, "Anime List", "Title language", "Romaji")); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
32 anime_list.display_aired_episodes = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Display only aired episodes", ""), true); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
33 anime_list.display_available_episodes = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Display only available episodes in library", ""), true); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
34 anime_list.highlight_anime_if_available = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Highlight anime if available", ""), true); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
35 anime_list.highlighted_anime_above_others = Strings::ToBool(INI::GetIniString(ini, "Anime List", "Display highlighted anime above others", ""), false); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
36 |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
37 anilist.auth_token = INI::GetIniString(ini, "AniList", "Auth Token", ""); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
38 anilist.user_id = Strings::ToInt(INI::GetIniString(ini, "AniList", "User ID", ""), 0); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
39 |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
116
diff
changeset
|
40 torrents.feed_link = INI::GetIniString(ini, "Torrents", "RSS feed", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0"); |
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
41 |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
42 theme.SetTheme(Translate::ToTheme(INI::GetIniString(ini, "Appearance", "Theme", "Default"))); |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
43 |
9 | 44 return 0; |
45 } | |
46 | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
116
diff
changeset
|
47 int Config::Save() const { |
61
327568ad9be9
core/fs: finish class-ification of paths
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
48 Filesystem::Path cfg_path = Filesystem::GetConfigPath(); |
327568ad9be9
core/fs: finish class-ification of paths
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
49 if (!cfg_path.GetParent().Exists()) |
327568ad9be9
core/fs: finish class-ification of paths
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
50 cfg_path.GetParent().CreateDirectories(); |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
51 |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
52 mINI::INIFile file(cfg_path.GetPath()); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
53 mINI::INIStructure ini; |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
54 |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
55 ini["General"]["Service"] = Translate::ToString(service); |
108 | 56 ini["General"]["Locale"] = Strings::ToUtf8String(locale.GetLocale().name()); |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
57 ini["Anime List"]["Title language"] = Translate::ToString(anime_list.language); |
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
58 ini["Anime List"]["Display only aired episodes"] = Strings::ToUtf8String(anime_list.display_aired_episodes); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
59 ini["Anime List"]["Display only available episodes in library"] = Strings::ToUtf8String(anime_list.display_available_episodes); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
60 ini["Anime List"]["Highlight anime if available"] = Strings::ToUtf8String(anime_list.highlight_anime_if_available); |
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
61 ini["Anime List"]["Display highlighted anime above others"] = Strings::ToUtf8String(anime_list.highlighted_anime_above_others); |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
62 ini["AniList"]["Auth Token"] = anilist.auth_token; |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
63 ini["AniList"]["User ID"] = std::to_string(anilist.user_id); |
102 | 64 ini["Appearance"]["Theme"] = Translate::ToString(theme.GetTheme()); |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
116
diff
changeset
|
65 ini["Torrents"]["RSS feed"] = torrents.feed_link; |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
66 |
102 | 67 file.write(ini); |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
68 |
9 | 69 return 0; |
70 } |