GpgFrontend Project A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.

GlobalSettingStation.h
1
29 #ifndef GPGFRONTEND_GLOBALSETTINGSTATION_H
30 #define GPGFRONTEND_GLOBALSETTINGSTATION_H
31
32 #include <filesystem>
33
34 #include "GpgFrontendBuildInstallInfo.h"
35 #include "core/GpgFrontendCore.h"
36 #include "core/GpgFunctionObject.h"
37
38 namespace GpgFrontend {
39
44 class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
45 : public SingletonFunctionObject<GlobalSettingStation> {
46 public:
51 explicit GlobalSettingStation(
52 int channel = SingletonFunctionObject::GetDefaultChannel()) noexcept;
53
58 ~GlobalSettingStation() noexcept override;
59
65 libconfig::Setting &GetUISettings() noexcept;
66
72 template <typename T>
73 T LookupSettings(std::string path, T default_value) noexcept {
74 T value = default_value;
75 try {
76 value = static_cast<T>(GetUISettings().lookup(path));
77 } catch (...) {
78 SPDLOG_WARN("setting not found: {}", path);
79 }
80 return value;
81 }
82
88 [[nodiscard]] std::filesystem::path GetAppDir() const { return app_path_; }
89
90 [[nodiscard]] std::filesystem::path GetAppDataPath() const {
91 return app_data_path_;
92 }
93
99 [[nodiscard]] std::filesystem::path GetLogDir() const {
100 return app_log_path_;
101 }
102
108 [[nodiscard]] std::filesystem::path GetStandaloneDatabaseDir() const {
109 auto db_path = app_configure_path_ / "db";
110 if (!std::filesystem::exists(db_path)) {
111 std::filesystem::create_directory(db_path);
112 }
113 return db_path;
114 }
115
116 [[nodiscard]] std::filesystem::path GetAppConfigPath() const {
117 return app_configure_path_;
118 }
119
125 [[nodiscard]] std::filesystem::path GetStandaloneGpgBinDir() const {
126 return app_resource_path_ / "gpg1.4" / "gpg";
127 }
128
134 [[nodiscard]] std::filesystem::path GetLocaleDir() const {
135 return app_locale_path_;
136 }
137
143 [[nodiscard]] std::filesystem::path GetResourceDir() const {
144 return app_resource_path_;
145 }
146
152 [[nodiscard]] std::filesystem::path GetCertsDir() const {
153 return app_resource_path_ / "certs";
154 }
155
156 [[nodiscard]] std::string GetLogFilesSize() const;
157
158 [[nodiscard]] std::string GetDataObjectsFilesSize() const;
159
160 void ClearAllLogFiles() const;
161
162 void ClearAllDataObjects() const;
163
168 void SyncSettings() noexcept;
169
170 private:
171 std::filesystem::path app_path_ = QCoreApplication::applicationDirPath()
172 .toStdString();
173 std::filesystem::path app_data_path_ =
174 QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
175 .toStdString();
176 std::filesystem::path app_log_path_ =
177 app_data_path_ / "logs";
178 std::filesystem::path app_data_objs_path_ =
179 app_data_path_ / "data_objs";
180
181 #ifdef LINUX_INSTALL_BUILD
182 std::filesystem::path app_resource_path_ =
183 std::filesystem::path(APP_LOCALSTATE_PATH) /
184 "gpgfrontend";
185 #else
186 std::filesystem::path app_resource_path_ =
187 RESOURCE_DIR_BOOST_PATH(app_path_);
188 #endif
189
190 #ifdef LINUX_INSTALL_BUILD
191 std::filesystem::path app_locale_path_ =
192 std::string(APP_LOCALE_PATH);
193 #else
194 std::filesystem::path app_locale_path_ =
195 app_resource_path_ / "locales";
196 #endif
197
198 std::filesystem::path app_configure_path_ =
199 QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)
200 .toStdString();
201 std::filesystem::path ui_config_dir_path_ =
202 app_configure_path_ / "conf";
203 std::filesystem::path ui_config_path_ =
204 ui_config_dir_path_ / "main.cfg";
205
206 libconfig::Config ui_cfg_;
207
212 void init_app_secure_key();
213
218 int64_t get_files_size_at_path(std::filesystem::path path,
219 std::string filename_pattern) const;
220
225 std::string get_human_readable_size(int64_t size) const;
226
231 void delete_all_files(std::filesystem::path path,
232 std::string filename_pattern) const;
233 };
234 } // namespace GpgFrontend
235
236 #endif // GPGFRONTEND_GLOBALSETTINGSTATION_H
GpgFrontend::GlobalSettingStation
Definition: GlobalSettingStation.h:45
GpgFrontend::GlobalSettingStation::GetLocaleDir
std::filesystem::path GetLocaleDir() const
Get the Locale Dir object.
Definition: GlobalSettingStation.h:134
GpgFrontend::GlobalSettingStation::ui_cfg_
libconfig::Config ui_cfg_
UI Configure File.
Definition: GlobalSettingStation.h:206
GpgFrontend::GlobalSettingStation::GetCertsDir
std::filesystem::path GetCertsDir() const
Get the Certs Dir object.
Definition: GlobalSettingStation.h:152
GpgFrontend::GlobalSettingStation::GetLogDir
std::filesystem::path GetLogDir() const
Get the Log Dir object.
Definition: GlobalSettingStation.h:99
GpgFrontend::GlobalSettingStation::GetStandaloneGpgBinDir
std::filesystem::path GetStandaloneGpgBinDir() const
Get the Standalone Gpg Bin Dir object.
Definition: GlobalSettingStation.h:125
GpgFrontend::GlobalSettingStation::GetAppDir
std::filesystem::path GetAppDir() const
Get the App Dir object.
Definition: GlobalSettingStation.h:88
GpgFrontend::GlobalSettingStation::GetStandaloneDatabaseDir
std::filesystem::path GetStandaloneDatabaseDir() const
Get the Standalone Database Dir object.
Definition: GlobalSettingStation.h:108
GpgFrontend::GlobalSettingStation::~GlobalSettingStation
~GlobalSettingStation() noexcept override
Destroy the Global Setting Station object.
GpgFrontend::GlobalSettingStation::GetResourceDir
std::filesystem::path GetResourceDir() const
Get the Resource Dir object.
Definition: GlobalSettingStation.h:143
GpgFrontend::SingletonFunctionObject
Definition: GpgFunctionObject.h:150
GpgFrontend::SingletonFunctionObject::GetDefaultChannel
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.h:251
GpgFrontend
Definition: CoreCommonUtil.cpp:31