22#include "filesystem.hpp"
24#include "sdl_prefs.hpp"
25#include "sdl_common_utils.hpp"
27#include <winpr/path.h>
28#include <winpr/config.h>
29#include <winpr/json.h>
31#include <freerdp/version.h>
32#include <freerdp/settings.h>
33#include <freerdp/utils/helpers.h>
35SdlPref::WINPR_JSONPtr SdlPref::get(
bool systemConfigOnly)
const
37 auto config = get_pref_file(systemConfigOnly);
41WINPR_JSON* SdlPref::get_item(
const std::string& key,
bool systemConfigOnly)
const
44 if (systemConfigOnly || !is_user_config_enabled())
45 return get_item(_system_config, key);
48 auto res = get_item(_config, key);
52 res = get_item(_system_config, key);
56WINPR_JSON* SdlPref::get_item(
const WINPR_JSONPtr& config,
const std::string& key)
const
63bool SdlPref::get_bool(
const WINPR_JSONPtr& config,
const std::string& key,
bool fallback)
const
65 auto item = get_item(config, key);
71bool SdlPref::is_user_config_enabled()
const
73 auto& config = _system_config;
76 return get_bool(config,
"isUserConfigEnabled",
true);
79bool SdlPref::is_commandline_override_allowed()
const
81 auto& config = _system_config;
84 return get_bool(config,
"allowCommandlineToOverride",
true);
87std::string SdlPref::item_to_str(WINPR_JSON* item,
const std::string& fallback)
97std::string SdlPref::get_string(
const std::string& key,
const std::string& fallback,
98 bool systemConfigOnly)
const
100 auto item = get_item(key, systemConfigOnly);
101 return item_to_str(item, fallback);
104bool SdlPref::get_bool(
const std::string& key,
bool fallback,
bool systemConfigOnly)
const
106 auto item = get_item(key, systemConfigOnly);
112int64_t SdlPref::get_int(
const std::string& key, int64_t fallback,
bool systemConfigOnly)
const
114 auto item = get_item(key, systemConfigOnly);
118 return static_cast<int64_t
>(val);
121std::vector<std::string> SdlPref::get_array(
const std::string& key,
122 const std::vector<std::string>& fallback,
123 bool systemConfigOnly)
const
125 auto item = get_item(key, systemConfigOnly);
129 std::vector<std::string> values;
133 values.push_back(item_to_str(cur));
139void SdlPref::print_config_file_help(
int version)
141#if defined(WITH_WINPR_JSON)
142 const std::string url =
"https://wiki.libsdl.org/SDL" + std::to_string(version);
143 std::cout <<
"GLOBAL CONFIGURATION FILE" << std::endl;
144 std::cout << std::endl;
145 std::cout <<
" The SDL client supports some system defined configuration options."
147 std::cout <<
" Settings are stored in JSON format" << std::endl;
148 std::cout <<
" The location is a system configuration file. Location for current machine is "
149 << SdlPref::instance()->get_pref_file(
true) << std::endl;
150 std::cout << std::endl;
151 std::cout <<
" The following configuration options are supported:" << std::endl;
152 std::cout << std::endl;
153 std::cout <<
" isUserConfigEnabled" << std::endl;
154 std::cout <<
" Allows to enable/disable user specific configuration files." << std::endl;
155 std::cout <<
" Default enabled" << std::endl;
156 std::cout << std::endl;
157 std::cout <<
" allowCommandlineToOverride" << std::endl;
159 <<
" Allows command line options to override values from the configuration files."
161 std::cout <<
" Default enabled" << std::endl;
162 std::cout << std::endl;
163 std::cout <<
" All options of the following user configuration file are also supported here."
165 std::cout << std::endl;
167 std::cout <<
"CONFIGURATION FILE" << std::endl;
168 std::cout << std::endl;
169 std::cout <<
" The SDL client supports some user defined configuration options." << std::endl;
170 std::cout <<
" Settings are stored in JSON format" << std::endl;
171 std::cout <<
" The location is a per user file. Location for current user is "
172 << SdlPref::instance()->get_pref_file() << std::endl;
174 <<
" The XDG_CONFIG_HOME environment variable can be used to override the base directory."
176 std::cout << std::endl;
177 std::cout <<
" The following configuration options are supported:" << std::endl;
178 std::cout << std::endl;
179 std::cout <<
" SDL_KeyModMask" << std::endl;
180 std::cout <<
" Defines the key combination required for SDL client shortcuts."
182 std::cout <<
" Default KMOD_RSHIFT" << std::endl;
183 std::cout <<
" An array of SDL_Keymod strings as defined at "
185 << url <<
"/SDL_Keymod" << std::endl;
186 std::cout << std::endl;
187 std::cout <<
" SDL_Fullscreen" << std::endl;
188 std::cout <<
" Toggles client fullscreen state." << std::endl;
189 std::cout <<
" Default SDL_SCANCODE_RETURN." << std::endl;
190 std::cout <<
" A string as "
192 << url <<
"/SDLScancodeLookup" << std::endl;
193 std::cout << std::endl;
194 std::cout <<
" SDL_Minimize" << std::endl;
195 std::cout <<
" Minimizes client windows." << std::endl;
196 std::cout <<
" Default SDL_SCANCODE_M." << std::endl;
197 std::cout <<
" A string as "
199 << url <<
"/SDLScancodeLookup" << std::endl;
200 std::cout << std::endl;
201 std::cout <<
" SDL_Resizeable" << std::endl;
202 std::cout <<
" Toggles local window resizeable state." << std::endl;
203 std::cout <<
" Default SDL_SCANCODE_R." << std::endl;
204 std::cout <<
" A string as "
206 << url <<
"/SDLScancodeLookup" << std::endl;
207 std::cout << std::endl;
208 std::cout <<
" SDL_Grab" << std::endl;
209 std::cout <<
" Toggles keyboard and mouse grab state." << std::endl;
210 std::cout <<
" Default SDL_SCANCODE_G." << std::endl;
211 std::cout <<
" A string as "
213 << url <<
"/SDLScancodeLookup" << std::endl;
214 std::cout << std::endl;
215 std::cout <<
" SDL_Disconnect" << std::endl;
216 std::cout <<
" Disconnects from the RDP session." << std::endl;
217 std::cout <<
" Default SDL_SCANCODE_D." << std::endl;
218 std::cout <<
" A string as defined at " << url <<
"/SDLScancodeLookup" << std::endl;
221 std::cout << std::endl;
222 std::cout <<
" SDL_ConnectionDialog" << std::endl;
223 std::cout <<
" Shows the connection dialog with progress and errors." << std::endl;
224 std::cout <<
" Default true. +/-sdl-connection-dialog overrides it unless "
225 "allowCommandlineToOverride is disabled."
232SdlPref::SdlPref(std::string file)
233 : _name(std::move(file)), _system_name(get_default_file(true)), _config(get(false)),
234 _system_config(get(true))
238std::string SdlPref::get_default_file(
bool systemConfigOnly)
240 CStringPtr name(freerdp_GetConfigFilePath(systemConfigOnly,
"sdl-freerdp.json"), free);
241 fs::path config{ name.get() };
242 return config.string();
245std::shared_ptr<SdlPref> SdlPref::instance(
const std::string& name)
247 static std::shared_ptr<SdlPref> _instance;
248 if (!_instance || (_instance->get_pref_file() != name))
249 _instance.reset(
new SdlPref(name));
253std::string SdlPref::get_pref_file(
bool systemConfigOnly)
const
255 if (systemConfigOnly)
WINPR_ATTR_NODISCARD WINPR_API BOOL WINPR_JSON_IsBool(const WINPR_JSON *item)
Check if JSON item is of type BOOL.
WINPR_ATTR_NODISCARD WINPR_API BOOL WINPR_JSON_IsNumber(const WINPR_JSON *item)
Check if JSON item is of type Number.
WINPR_ATTR_NODISCARD WINPR_API size_t WINPR_JSON_GetArraySize(const WINPR_JSON *array)
Get the number of arrayitems from an array.
WINPR_ATTR_NODISCARD WINPR_API BOOL WINPR_JSON_IsTrue(const WINPR_JSON *item)
Check if JSON item is BOOL value True.
WINPR_API WINPR_JSON * WINPR_JSON_ParseFromFile(const char *filename)
Parse a JSON string read from a file filename.
WINPR_ATTR_NODISCARD WINPR_API WINPR_JSON * WINPR_JSON_GetObjectItemCaseSensitive(const WINPR_JSON *object, const char *string)
Same as WINPR_JSON_GetObjectItem but with case sensitive matching.
WINPR_ATTR_NODISCARD WINPR_API BOOL WINPR_JSON_IsString(const WINPR_JSON *item)
Check if JSON item is of type String.
WINPR_ATTR_NODISCARD WINPR_API WINPR_JSON * WINPR_JSON_GetArrayItem(const WINPR_JSON *array, size_t index)
Return a pointer to an item in the array.
WINPR_ATTR_NODISCARD WINPR_API double WINPR_JSON_GetNumberValue(const WINPR_JSON *item)
Return the Number value of a JSON item.
WINPR_ATTR_NODISCARD WINPR_API BOOL WINPR_JSON_IsArray(const WINPR_JSON *item)
Check if JSON item is of type Array.
WINPR_API void WINPR_JSON_Delete(WINPR_JSON *item)
Delete a WinPR JSON wrapper object.
WINPR_ATTR_NODISCARD WINPR_API const char * WINPR_JSON_GetStringValue(WINPR_JSON *item)
Return the String value of a JSON item.