project_settings.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. /*************************************************************************/
  2. /* project_settings.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "project_settings.h"
  31. #include "core/core_bind.h"
  32. #include "core/core_string_names.h"
  33. #include "core/input/input_map.h"
  34. #include "core/io/dir_access.h"
  35. #include "core/io/file_access.h"
  36. #include "core/io/file_access_network.h"
  37. #include "core/io/file_access_pack.h"
  38. #include "core/io/marshalls.h"
  39. #include "core/os/keyboard.h"
  40. #include "core/os/os.h"
  41. #include "core/variant/variant_parser.h"
  42. #include <zlib.h>
  43. ProjectSettings *ProjectSettings::singleton = nullptr;
  44. ProjectSettings *ProjectSettings::get_singleton() {
  45. return singleton;
  46. }
  47. String ProjectSettings::get_resource_path() const {
  48. return resource_path;
  49. }
  50. const String ProjectSettings::IMPORTED_FILES_PATH("res://.godot/imported");
  51. String ProjectSettings::localize_path(const String &p_path) const {
  52. if (resource_path == "") {
  53. return p_path; //not initialized yet
  54. }
  55. if (p_path.begins_with("res://") || p_path.begins_with("user://") ||
  56. (p_path.is_absolute_path() && !p_path.begins_with(resource_path))) {
  57. return p_path.simplify_path();
  58. }
  59. DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  60. String path = p_path.replace("\\", "/").simplify_path();
  61. if (dir->change_dir(path) == OK) {
  62. String cwd = dir->get_current_dir();
  63. cwd = cwd.replace("\\", "/");
  64. memdelete(dir);
  65. // Ensure that we end with a '/'.
  66. // This is important to ensure that we do not wrongly localize the resource path
  67. // in an absolute path that just happens to contain this string but points to a
  68. // different folder (e.g. "/my/project" as resource_path would be contained in
  69. // "/my/project_data", even though the latter is not part of res://.
  70. // `plus_file("")` is an easy way to ensure we have a trailing '/'.
  71. const String res_path = resource_path.plus_file("");
  72. // DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/',
  73. // so we must make sure we have it as well in order to compare with 'res_path'.
  74. cwd = cwd.plus_file("");
  75. if (!cwd.begins_with(res_path)) {
  76. return p_path;
  77. }
  78. return cwd.replace_first(res_path, "res://");
  79. } else {
  80. memdelete(dir);
  81. int sep = path.rfind("/");
  82. if (sep == -1) {
  83. return "res://" + path;
  84. }
  85. String parent = path.substr(0, sep);
  86. String plocal = localize_path(parent);
  87. if (plocal == "") {
  88. return "";
  89. }
  90. // Only strip the starting '/' from 'path' if its parent ('plocal') ends with '/'
  91. if (plocal[plocal.length() - 1] == '/') {
  92. sep += 1;
  93. }
  94. return plocal + path.substr(sep, path.size() - sep);
  95. }
  96. }
  97. void ProjectSettings::set_initial_value(const String &p_name, const Variant &p_value) {
  98. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  99. props[p_name].initial = p_value;
  100. }
  101. void ProjectSettings::set_restart_if_changed(const String &p_name, bool p_restart) {
  102. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  103. props[p_name].restart_if_changed = p_restart;
  104. }
  105. void ProjectSettings::set_as_basic(const String &p_name, bool p_basic) {
  106. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  107. props[p_name].basic = p_basic;
  108. }
  109. void ProjectSettings::set_ignore_value_in_docs(const String &p_name, bool p_ignore) {
  110. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  111. #ifdef DEBUG_METHODS_ENABLED
  112. props[p_name].ignore_value_in_docs = p_ignore;
  113. #endif
  114. }
  115. bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const {
  116. ERR_FAIL_COND_V_MSG(!props.has(p_name), false, "Request for nonexistent project setting: " + p_name + ".");
  117. #ifdef DEBUG_METHODS_ENABLED
  118. return props[p_name].ignore_value_in_docs;
  119. #else
  120. return false;
  121. #endif
  122. }
  123. String ProjectSettings::globalize_path(const String &p_path) const {
  124. if (p_path.begins_with("res://")) {
  125. if (resource_path != "") {
  126. return p_path.replace("res:/", resource_path);
  127. }
  128. return p_path.replace("res://", "");
  129. } else if (p_path.begins_with("user://")) {
  130. String data_dir = OS::get_singleton()->get_user_data_dir();
  131. if (data_dir != "") {
  132. return p_path.replace("user:/", data_dir);
  133. }
  134. return p_path.replace("user://", "");
  135. }
  136. return p_path;
  137. }
  138. bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
  139. _THREAD_SAFE_METHOD_
  140. if (p_value.get_type() == Variant::NIL) {
  141. props.erase(p_name);
  142. if (p_name.operator String().begins_with("autoload/")) {
  143. String node_name = p_name.operator String().split("/")[1];
  144. if (autoloads.has(node_name)) {
  145. remove_autoload(node_name);
  146. }
  147. }
  148. } else {
  149. if (p_name == CoreStringNames::get_singleton()->_custom_features) {
  150. Vector<String> custom_feature_array = String(p_value).split(",");
  151. for (int i = 0; i < custom_feature_array.size(); i++) {
  152. custom_features.insert(custom_feature_array[i]);
  153. }
  154. return true;
  155. }
  156. if (!disable_feature_overrides) {
  157. int dot = p_name.operator String().find(".");
  158. if (dot != -1) {
  159. Vector<String> s = p_name.operator String().split(".");
  160. bool override_valid = false;
  161. for (int i = 1; i < s.size(); i++) {
  162. String feature = s[i].strip_edges();
  163. if (OS::get_singleton()->has_feature(feature) || custom_features.has(feature)) {
  164. override_valid = true;
  165. break;
  166. }
  167. }
  168. if (override_valid) {
  169. feature_overrides[s[0]] = p_name;
  170. }
  171. }
  172. }
  173. if (props.has(p_name)) {
  174. if (!props[p_name].overridden) {
  175. props[p_name].variant = p_value;
  176. }
  177. } else {
  178. props[p_name] = VariantContainer(p_value, last_order++);
  179. }
  180. if (p_name.operator String().begins_with("autoload/")) {
  181. String node_name = p_name.operator String().split("/")[1];
  182. AutoloadInfo autoload;
  183. autoload.name = node_name;
  184. String path = p_value;
  185. if (path.begins_with("*")) {
  186. autoload.is_singleton = true;
  187. autoload.path = path.substr(1);
  188. } else {
  189. autoload.path = path;
  190. }
  191. add_autoload(autoload);
  192. }
  193. }
  194. return true;
  195. }
  196. bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
  197. _THREAD_SAFE_METHOD_
  198. StringName name = p_name;
  199. if (!disable_feature_overrides && feature_overrides.has(name)) {
  200. name = feature_overrides[name];
  201. }
  202. if (!props.has(name)) {
  203. WARN_PRINT("Property not found: " + String(name));
  204. return false;
  205. }
  206. r_ret = props[name].variant;
  207. return true;
  208. }
  209. struct _VCSort {
  210. String name;
  211. Variant::Type type;
  212. int order;
  213. int flags;
  214. bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; }
  215. };
  216. void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  217. _THREAD_SAFE_METHOD_
  218. Set<_VCSort> vclist;
  219. for (Map<StringName, VariantContainer>::Element *E = props.front(); E; E = E->next()) {
  220. const VariantContainer *v = &E->get();
  221. if (v->hide_from_editor) {
  222. continue;
  223. }
  224. _VCSort vc;
  225. vc.name = E->key();
  226. vc.order = v->order;
  227. vc.type = v->variant.get_type();
  228. if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload")) {
  229. vc.flags = PROPERTY_USAGE_STORAGE;
  230. } else {
  231. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  232. }
  233. if (v->basic) {
  234. vc.flags |= PROPERTY_USAGE_EDITOR_BASIC_SETTING;
  235. }
  236. if (v->restart_if_changed) {
  237. vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  238. }
  239. vclist.insert(vc);
  240. }
  241. for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
  242. String prop_info_name = E->get().name;
  243. int dot = prop_info_name.find(".");
  244. if (dot != -1 && !custom_prop_info.has(prop_info_name)) {
  245. prop_info_name = prop_info_name.substr(0, dot);
  246. }
  247. if (custom_prop_info.has(prop_info_name)) {
  248. PropertyInfo pi = custom_prop_info[prop_info_name];
  249. pi.name = E->get().name;
  250. pi.usage = E->get().flags;
  251. p_list->push_back(pi);
  252. } else {
  253. p_list->push_back(PropertyInfo(E->get().type, E->get().name, PROPERTY_HINT_NONE, "", E->get().flags));
  254. }
  255. }
  256. }
  257. bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files, int p_offset) {
  258. if (PackedData::get_singleton()->is_disabled()) {
  259. return false;
  260. }
  261. bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files, p_offset) == OK;
  262. if (!ok) {
  263. return false;
  264. }
  265. //if data.pck is found, all directory access will be from here
  266. DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
  267. using_datapack = true;
  268. return true;
  269. }
  270. void ProjectSettings::_convert_to_last_version(int p_from_version) {
  271. if (p_from_version <= 3) {
  272. // Converts the actions from array to dictionary (array of events to dictionary with deadzone + events)
  273. for (Map<StringName, ProjectSettings::VariantContainer>::Element *E = props.front(); E; E = E->next()) {
  274. Variant value = E->get().variant;
  275. if (String(E->key()).begins_with("input/") && value.get_type() == Variant::ARRAY) {
  276. Array array = value;
  277. Dictionary action;
  278. action["deadzone"] = Variant(0.5f);
  279. action["events"] = array;
  280. E->get().variant = action;
  281. }
  282. }
  283. }
  284. }
  285. /*
  286. * This method is responsible for loading a project.godot file and/or data file
  287. * using the following merit order:
  288. * - If using NetworkClient, try to lookup project file or fail.
  289. * - If --main-pack was passed by the user (`p_main_pack`), load it or fail.
  290. * - Search for project PCKs automatically. For each step we try loading a potential
  291. * PCK, and if it doesn't work, we proceed to the next step. If any step succeeds,
  292. * we try loading the project settings, and abort if it fails. Steps:
  293. * o Bundled PCK in the executable.
  294. * o [macOS only] PCK with same basename as the binary in the .app resource dir.
  295. * o PCK with same basename as the binary in the binary's directory. We handle both
  296. * changing the extension to '.pck' (e.g. 'win_game.exe' -> 'win_game.pck') and
  297. * appending '.pck' to the binary name (e.g. 'linux_game' -> 'linux_game.pck').
  298. * o PCK with the same basename as the binary in the current working directory.
  299. * Same as above for the two possible PCK file names.
  300. * - On relevant platforms (Android/iOS), lookup project file in OS resource path.
  301. * If found, load it or fail.
  302. * - Lookup project file in passed `p_path` (--path passed by the user), i.e. we
  303. * are running from source code.
  304. * If not found and `p_upwards` is true (--upwards passed by the user), look for
  305. * project files in parent folders up to the system root (used to run a game
  306. * from command line while in a subfolder).
  307. * If a project file is found, load it or fail.
  308. * If nothing was found, error out.
  309. */
  310. Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, bool p_upwards) {
  311. // If looking for files in a network client, use it directly
  312. if (FileAccessNetworkClient::get_singleton()) {
  313. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  314. if (err == OK) {
  315. // Optional, we don't mind if it fails
  316. _load_settings_text("res://override.cfg");
  317. }
  318. return err;
  319. }
  320. // Attempt with a user-defined main pack first
  321. if (p_main_pack != "") {
  322. bool ok = _load_resource_pack(p_main_pack);
  323. ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, "Cannot open resource pack '" + p_main_pack + "'.");
  324. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  325. if (err == OK) {
  326. // Load override from location of the main pack
  327. // Optional, we don't mind if it fails
  328. _load_settings_text(p_main_pack.get_base_dir().plus_file("override.cfg"));
  329. }
  330. return err;
  331. }
  332. String exec_path = OS::get_singleton()->get_executable_path();
  333. if (exec_path != "") {
  334. // We do several tests sequentially until one succeeds to find a PCK,
  335. // and if so, we attempt loading it at the end.
  336. // Attempt with PCK bundled into executable.
  337. bool found = _load_resource_pack(exec_path);
  338. // Attempt with exec_name.pck.
  339. // (This is the usual case when distributing a Godot game.)
  340. String exec_dir = exec_path.get_base_dir();
  341. String exec_filename = exec_path.get_file();
  342. String exec_basename = exec_filename.get_basename();
  343. // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
  344. // or the exec path's basename + '.pck' (Windows).
  345. // We need to test both possibilities as extensions for Linux binaries are optional
  346. // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
  347. #ifdef OSX_ENABLED
  348. if (!found) {
  349. // Attempt to load PCK from macOS .app bundle resources.
  350. found = _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_basename + ".pck")) || _load_resource_pack(OS::get_singleton()->get_bundle_resource_dir().plus_file(exec_filename + ".pck"));
  351. }
  352. #endif
  353. if (!found) {
  354. // Try to load data pack at the location of the executable.
  355. // As mentioned above, we have two potential names to attempt.
  356. found = _load_resource_pack(exec_dir.plus_file(exec_basename + ".pck")) || _load_resource_pack(exec_dir.plus_file(exec_filename + ".pck"));
  357. }
  358. if (!found) {
  359. // If we couldn't find them next to the executable, we attempt
  360. // the current working directory. Same story, two tests.
  361. found = _load_resource_pack(exec_basename + ".pck") || _load_resource_pack(exec_filename + ".pck");
  362. }
  363. // If we opened our package, try and load our project.
  364. if (found) {
  365. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  366. if (err == OK) {
  367. // Load override from location of the executable.
  368. // Optional, we don't mind if it fails.
  369. _load_settings_text(exec_path.get_base_dir().plus_file("override.cfg"));
  370. }
  371. return err;
  372. }
  373. }
  374. // Try to use the filesystem for files, according to OS.
  375. // (Only Android -when reading from pck- and iOS use this.)
  376. if (OS::get_singleton()->get_resource_dir() != "") {
  377. // OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
  378. // If the OS would rather use a specific location, then it will not be empty.
  379. resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
  380. if (resource_path != "" && resource_path[resource_path.length() - 1] == '/') {
  381. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  382. }
  383. Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
  384. if (err == OK) {
  385. // Optional, we don't mind if it fails.
  386. _load_settings_text("res://override.cfg");
  387. }
  388. return err;
  389. }
  390. // Nothing was found, try to find a project file in provided path (`p_path`)
  391. // or, if requested (`p_upwards`) in parent directories.
  392. DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  393. ERR_FAIL_COND_V_MSG(!d, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_path + "'.");
  394. d->change_dir(p_path);
  395. String current_dir = d->get_current_dir();
  396. bool found = false;
  397. Error err;
  398. while (true) {
  399. // Set the resource path early so things can be resolved when loading.
  400. resource_path = current_dir;
  401. resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case.
  402. err = _load_settings_text_or_binary(current_dir.plus_file("project.godot"), current_dir.plus_file("project.binary"));
  403. if (err == OK) {
  404. // Optional, we don't mind if it fails.
  405. _load_settings_text(current_dir.plus_file("override.cfg"));
  406. found = true;
  407. break;
  408. }
  409. if (p_upwards) {
  410. // Try to load settings ascending through parent directories
  411. d->change_dir("..");
  412. if (d->get_current_dir() == current_dir) {
  413. break; // not doing anything useful
  414. }
  415. current_dir = d->get_current_dir();
  416. } else {
  417. break;
  418. }
  419. }
  420. memdelete(d);
  421. if (!found) {
  422. return err;
  423. }
  424. if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
  425. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  426. }
  427. return OK;
  428. }
  429. Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards) {
  430. Error err = _setup(p_path, p_main_pack, p_upwards);
  431. if (err == OK) {
  432. String custom_settings = GLOBAL_DEF("application/config/project_settings_override", "");
  433. if (custom_settings != "") {
  434. _load_settings_text(custom_settings);
  435. }
  436. }
  437. // Using GLOBAL_GET on every block for compressing can be slow, so assigning here.
  438. Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching");
  439. Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level");
  440. Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size");
  441. Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level");
  442. Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level");
  443. return err;
  444. }
  445. bool ProjectSettings::has_setting(String p_var) const {
  446. _THREAD_SAFE_METHOD_
  447. return props.has(p_var);
  448. }
  449. Error ProjectSettings::_load_settings_binary(const String &p_path) {
  450. Error err;
  451. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  452. if (err != OK) {
  453. return err;
  454. }
  455. uint8_t hdr[4];
  456. f->get_buffer(hdr, 4);
  457. if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
  458. memdelete(f);
  459. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
  460. }
  461. uint32_t count = f->get_32();
  462. for (uint32_t i = 0; i < count; i++) {
  463. uint32_t slen = f->get_32();
  464. CharString cs;
  465. cs.resize(slen + 1);
  466. cs[slen] = 0;
  467. f->get_buffer((uint8_t *)cs.ptr(), slen);
  468. String key;
  469. key.parse_utf8(cs.ptr());
  470. uint32_t vlen = f->get_32();
  471. Vector<uint8_t> d;
  472. d.resize(vlen);
  473. f->get_buffer(d.ptrw(), vlen);
  474. Variant value;
  475. err = decode_variant(value, d.ptr(), d.size(), nullptr, true);
  476. ERR_CONTINUE_MSG(err != OK, "Error decoding property: " + key + ".");
  477. set(key, value);
  478. }
  479. f->close();
  480. memdelete(f);
  481. return OK;
  482. }
  483. Error ProjectSettings::_load_settings_text(const String &p_path) {
  484. Error err;
  485. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  486. if (!f) {
  487. // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
  488. // This needs to be streamlined if we want decent error reporting
  489. return ERR_FILE_NOT_FOUND;
  490. }
  491. VariantParser::StreamFile stream;
  492. stream.f = f;
  493. String assign;
  494. Variant value;
  495. VariantParser::Tag next_tag;
  496. int lines = 0;
  497. String error_text;
  498. String section;
  499. int config_version = 0;
  500. while (true) {
  501. assign = Variant();
  502. next_tag.fields.clear();
  503. next_tag.name = String();
  504. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
  505. if (err == ERR_FILE_EOF) {
  506. memdelete(f);
  507. // If we're loading a project.godot from source code, we can operate some
  508. // ProjectSettings conversions if need be.
  509. _convert_to_last_version(config_version);
  510. last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
  511. return OK;
  512. } else if (err != OK) {
  513. ERR_PRINT("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
  514. memdelete(f);
  515. return err;
  516. }
  517. if (assign != String()) {
  518. if (section == String() && assign == "config_version") {
  519. config_version = value;
  520. if (config_version > CONFIG_VERSION) {
  521. memdelete(f);
  522. ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, vformat("Can't open project at '%s', its `config_version` (%d) is from a more recent and incompatible version of the engine. Expected config version: %d.", p_path, config_version, CONFIG_VERSION));
  523. }
  524. } else {
  525. if (section == String()) {
  526. set(assign, value);
  527. } else {
  528. set(section + "/" + assign, value);
  529. }
  530. }
  531. } else if (next_tag.name != String()) {
  532. section = next_tag.name;
  533. }
  534. }
  535. }
  536. Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
  537. // Attempt first to load the binary project.godot file.
  538. Error err = _load_settings_binary(p_bin_path);
  539. if (err == OK) {
  540. return OK;
  541. } else if (err != ERR_FILE_NOT_FOUND) {
  542. // If the file exists but can't be loaded, we want to know it.
  543. ERR_PRINT("Couldn't load file '" + p_bin_path + "', error code " + itos(err) + ".");
  544. }
  545. // Fallback to text-based project.godot file if binary was not found.
  546. err = _load_settings_text(p_text_path);
  547. if (err == OK) {
  548. return OK;
  549. } else if (err != ERR_FILE_NOT_FOUND) {
  550. ERR_PRINT("Couldn't load file '" + p_text_path + "', error code " + itos(err) + ".");
  551. }
  552. return err;
  553. }
  554. int ProjectSettings::get_order(const String &p_name) const {
  555. ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, "Request for nonexistent project setting: " + p_name + ".");
  556. return props[p_name].order;
  557. }
  558. void ProjectSettings::set_order(const String &p_name, int p_order) {
  559. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  560. props[p_name].order = p_order;
  561. }
  562. void ProjectSettings::set_builtin_order(const String &p_name) {
  563. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  564. if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
  565. props[p_name].order = last_builtin_order++;
  566. }
  567. }
  568. bool ProjectSettings::is_builtin_setting(const String &p_name) const {
  569. // Return true because a false negative is worse than a false positive.
  570. ERR_FAIL_COND_V_MSG(!props.has(p_name), true, "Request for nonexistent project setting: " + p_name + ".");
  571. return props[p_name].order < NO_BUILTIN_ORDER_BASE;
  572. }
  573. void ProjectSettings::clear(const String &p_name) {
  574. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  575. props.erase(p_name);
  576. }
  577. Error ProjectSettings::save() {
  578. Error error = save_custom(get_resource_path().plus_file("project.godot"));
  579. if (error == OK) {
  580. last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
  581. }
  582. return error;
  583. }
  584. Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  585. Error err;
  586. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  587. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + ".");
  588. uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
  589. file->store_buffer(hdr, 4);
  590. int count = 0;
  591. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  592. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  593. count++;
  594. }
  595. }
  596. if (p_custom_features != String()) {
  597. file->store_32(count + 1);
  598. //store how many properties are saved, add one for custom featuers, which must always go first
  599. String key = CoreStringNames::get_singleton()->_custom_features;
  600. file->store_pascal_string(key);
  601. int len;
  602. err = encode_variant(p_custom_features, nullptr, len, false);
  603. if (err != OK) {
  604. memdelete(file);
  605. ERR_FAIL_V(err);
  606. }
  607. Vector<uint8_t> buff;
  608. buff.resize(len);
  609. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  610. if (err != OK) {
  611. memdelete(file);
  612. ERR_FAIL_V(err);
  613. }
  614. file->store_32(len);
  615. file->store_buffer(buff.ptr(), buff.size());
  616. } else {
  617. file->store_32(count); //store how many properties are saved
  618. }
  619. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  620. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  621. String key = F->get();
  622. if (E->key() != "") {
  623. key = E->key() + "/" + key;
  624. }
  625. Variant value;
  626. if (p_custom.has(key)) {
  627. value = p_custom[key];
  628. } else {
  629. value = get(key);
  630. }
  631. file->store_pascal_string(key);
  632. int len;
  633. err = encode_variant(value, nullptr, len, true);
  634. if (err != OK) {
  635. memdelete(file);
  636. }
  637. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  638. Vector<uint8_t> buff;
  639. buff.resize(len);
  640. err = encode_variant(value, buff.ptrw(), len, true);
  641. if (err != OK) {
  642. memdelete(file);
  643. }
  644. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  645. file->store_32(len);
  646. file->store_buffer(buff.ptr(), buff.size());
  647. }
  648. }
  649. file->close();
  650. memdelete(file);
  651. return OK;
  652. }
  653. Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  654. Error err;
  655. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  656. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.godot - " + p_file + ".");
  657. file->store_line("; Engine configuration file.");
  658. file->store_line("; It's best edited using the editor UI and not directly,");
  659. file->store_line("; since the parameters that go here are not all obvious.");
  660. file->store_line(";");
  661. file->store_line("; Format:");
  662. file->store_line("; [section] ; section goes between []");
  663. file->store_line("; param=value ; assign values to parameters");
  664. file->store_line("");
  665. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  666. if (p_custom_features != String()) {
  667. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  668. }
  669. file->store_string("\n");
  670. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  671. if (E != props.front()) {
  672. file->store_string("\n");
  673. }
  674. if (E->key() != "") {
  675. file->store_string("[" + E->key() + "]\n\n");
  676. }
  677. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  678. String key = F->get();
  679. if (E->key() != "") {
  680. key = E->key() + "/" + key;
  681. }
  682. Variant value;
  683. if (p_custom.has(key)) {
  684. value = p_custom[key];
  685. } else {
  686. value = get(key);
  687. }
  688. String vstr;
  689. VariantWriter::write_to_string(value, vstr);
  690. file->store_string(F->get().property_name_encode() + "=" + vstr + "\n");
  691. }
  692. }
  693. file->close();
  694. memdelete(file);
  695. return OK;
  696. }
  697. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  698. return save_custom(p_file);
  699. }
  700. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  701. ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  702. Set<_VCSort> vclist;
  703. if (p_merge_with_current) {
  704. for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
  705. const VariantContainer *v = &G->get();
  706. if (v->hide_from_editor) {
  707. continue;
  708. }
  709. if (p_custom.has(G->key())) {
  710. continue;
  711. }
  712. _VCSort vc;
  713. vc.name = G->key(); //*k;
  714. vc.order = v->order;
  715. vc.type = v->variant.get_type();
  716. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  717. if (v->variant == v->initial) {
  718. continue;
  719. }
  720. vclist.insert(vc);
  721. }
  722. }
  723. for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) {
  724. // Lookup global prop to store in the same order
  725. Map<StringName, VariantContainer>::Element *global_prop = props.find(E->key());
  726. _VCSort vc;
  727. vc.name = E->key();
  728. vc.order = global_prop ? global_prop->get().order : 0xFFFFFFF;
  729. vc.type = E->get().get_type();
  730. vc.flags = PROPERTY_USAGE_STORAGE;
  731. vclist.insert(vc);
  732. }
  733. Map<String, List<String>> props;
  734. for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
  735. String category = E->get().name;
  736. String name = E->get().name;
  737. int div = category.find("/");
  738. if (div < 0) {
  739. category = "";
  740. } else {
  741. category = category.substr(0, div);
  742. name = name.substr(div + 1, name.size());
  743. }
  744. props[category].push_back(name);
  745. }
  746. String custom_features;
  747. for (int i = 0; i < p_custom_features.size(); i++) {
  748. if (i > 0) {
  749. custom_features += ",";
  750. }
  751. String f = p_custom_features[i].strip_edges().replace("\"", "");
  752. custom_features += f;
  753. }
  754. if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) {
  755. return _save_settings_text(p_path, props, p_custom, custom_features);
  756. } else if (p_path.ends_with(".binary")) {
  757. return _save_settings_binary(p_path, props, p_custom, custom_features);
  758. } else {
  759. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + ".");
  760. }
  761. }
  762. Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic) {
  763. Variant ret;
  764. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  765. ProjectSettings::get_singleton()->set(p_var, p_default);
  766. }
  767. ret = ProjectSettings::get_singleton()->get(p_var);
  768. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  769. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  770. ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
  771. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  772. ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
  773. return ret;
  774. }
  775. Vector<String> ProjectSettings::get_optimizer_presets() const {
  776. List<PropertyInfo> pi;
  777. ProjectSettings::get_singleton()->get_property_list(&pi);
  778. Vector<String> names;
  779. for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
  780. if (!E->get().name.begins_with("optimizer_presets/")) {
  781. continue;
  782. }
  783. names.push_back(E->get().name.get_slicec('/', 1));
  784. }
  785. names.sort();
  786. return names;
  787. }
  788. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  789. ERR_FAIL_COND(!p_info.has("name"));
  790. ERR_FAIL_COND(!p_info.has("type"));
  791. PropertyInfo pinfo;
  792. pinfo.name = p_info["name"];
  793. ERR_FAIL_COND(!props.has(pinfo.name));
  794. pinfo.type = Variant::Type(p_info["type"].operator int());
  795. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  796. if (p_info.has("hint")) {
  797. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  798. }
  799. if (p_info.has("hint_string")) {
  800. pinfo.hint_string = p_info["hint_string"];
  801. }
  802. set_custom_property_info(pinfo.name, pinfo);
  803. }
  804. void ProjectSettings::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) {
  805. ERR_FAIL_COND(!props.has(p_prop));
  806. custom_prop_info[p_prop] = p_info;
  807. custom_prop_info[p_prop].name = p_prop;
  808. }
  809. const Map<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  810. return custom_prop_info;
  811. }
  812. void ProjectSettings::set_disable_feature_overrides(bool p_disable) {
  813. disable_feature_overrides = p_disable;
  814. }
  815. bool ProjectSettings::is_using_datapack() const {
  816. return using_datapack;
  817. }
  818. bool ProjectSettings::property_can_revert(const String &p_name) {
  819. if (!props.has(p_name)) {
  820. return false;
  821. }
  822. return props[p_name].initial != props[p_name].variant;
  823. }
  824. Variant ProjectSettings::property_get_revert(const String &p_name) {
  825. if (!props.has(p_name)) {
  826. return Variant();
  827. }
  828. return props[p_name].initial;
  829. }
  830. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  831. set(p_setting, p_value);
  832. }
  833. Variant ProjectSettings::get_setting(const String &p_setting) const {
  834. return get(p_setting);
  835. }
  836. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  837. return custom_features.has(p_feature);
  838. }
  839. Map<StringName, ProjectSettings::AutoloadInfo> ProjectSettings::get_autoload_list() const {
  840. return autoloads;
  841. }
  842. void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
  843. ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
  844. autoloads[p_autoload.name] = p_autoload;
  845. }
  846. void ProjectSettings::remove_autoload(const StringName &p_autoload) {
  847. ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
  848. autoloads.erase(p_autoload);
  849. }
  850. bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
  851. return autoloads.has(p_autoload);
  852. }
  853. ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
  854. ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
  855. return autoloads[p_name];
  856. }
  857. void ProjectSettings::_bind_methods() {
  858. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  859. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  860. ClassDB::bind_method(D_METHOD("get_setting", "name"), &ProjectSettings::get_setting);
  861. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  862. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  863. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  864. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  865. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  866. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  867. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  868. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  869. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::_load_resource_pack, DEFVAL(true), DEFVAL(0));
  870. ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ProjectSettings::property_can_revert);
  871. ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &ProjectSettings::property_get_revert);
  872. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  873. }
  874. void ProjectSettings::_add_builtin_input_map() {
  875. if (InputMap::get_singleton()) {
  876. OrderedHashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
  877. for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) {
  878. Array events;
  879. // Convert list of input events into array
  880. for (List<Ref<InputEvent>>::Element *I = E.get().front(); I; I = I->next()) {
  881. events.push_back(I->get());
  882. }
  883. Dictionary action;
  884. action["deadzone"] = Variant(0.5f);
  885. action["events"] = events;
  886. String action_name = "input/" + E.key();
  887. GLOBAL_DEF(action_name, action);
  888. input_presets.push_back(action_name);
  889. }
  890. }
  891. }
  892. ProjectSettings::ProjectSettings() {
  893. // Initialization of engine variables should be done in the setup() method,
  894. // so that the values can be overridden from project.godot or project.binary.
  895. singleton = this;
  896. GLOBAL_DEF_BASIC("application/config/name", "");
  897. GLOBAL_DEF_BASIC("application/config/description", "");
  898. custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
  899. GLOBAL_DEF_BASIC("application/run/main_scene", "");
  900. custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res");
  901. GLOBAL_DEF("application/run/disable_stdout", false);
  902. GLOBAL_DEF("application/run/disable_stderr", false);
  903. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  904. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  905. GLOBAL_DEF("application/config/project_settings_override", "");
  906. GLOBAL_DEF_BASIC("audio/buses/default_bus_layout", "res://default_bus_layout.tres");
  907. custom_prop_info["audio/buses/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres");
  908. PackedStringArray extensions = PackedStringArray();
  909. extensions.push_back("gd");
  910. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  911. extensions.push_back("cs");
  912. }
  913. extensions.push_back("gdshader");
  914. GLOBAL_DEF("editor/run/main_run_args", "");
  915. GLOBAL_DEF("editor/script/search_in_file_extensions", extensions);
  916. custom_prop_info["editor/script/search_in_file_extensions"] = PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions");
  917. GLOBAL_DEF("editor/script/templates_search_path", "res://script_templates");
  918. custom_prop_info["editor/script/templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR);
  919. _add_builtin_input_map();
  920. // Keep the enum values in sync with the `DisplayServer::ScreenOrientation` enum.
  921. custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::INT, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor");
  922. custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
  923. GLOBAL_DEF("physics/2d/run_on_thread", false);
  924. GLOBAL_DEF("physics/3d/run_on_thread", false);
  925. GLOBAL_DEF("debug/settings/profiler/max_functions", 16384);
  926. custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1");
  927. GLOBAL_DEF("compression/formats/zstd/long_distance_matching", Compression::zstd_long_distance_matching);
  928. custom_prop_info["compression/formats/zstd/long_distance_matching"] = PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching");
  929. GLOBAL_DEF("compression/formats/zstd/compression_level", Compression::zstd_level);
  930. custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1");
  931. GLOBAL_DEF("compression/formats/zstd/window_log_size", Compression::zstd_window_log_size);
  932. custom_prop_info["compression/formats/zstd/window_log_size"] = PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1");
  933. GLOBAL_DEF("compression/formats/zlib/compression_level", Compression::zlib_level);
  934. custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  935. GLOBAL_DEF("compression/formats/gzip/compression_level", Compression::gzip_level);
  936. custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  937. }
  938. ProjectSettings::~ProjectSettings() {
  939. singleton = nullptr;
  940. }