project_settings.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  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/file_access_network.h"
  35. #include "core/io/file_access_pack.h"
  36. #include "core/io/marshalls.h"
  37. #include "core/os/dir_access.h"
  38. #include "core/os/file_access.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_abs_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_32(key.length());
  601. file->store_string(key);
  602. int len;
  603. err = encode_variant(p_custom_features, nullptr, len, false);
  604. if (err != OK) {
  605. memdelete(file);
  606. ERR_FAIL_V(err);
  607. }
  608. Vector<uint8_t> buff;
  609. buff.resize(len);
  610. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  611. if (err != OK) {
  612. memdelete(file);
  613. ERR_FAIL_V(err);
  614. }
  615. file->store_32(len);
  616. file->store_buffer(buff.ptr(), buff.size());
  617. } else {
  618. file->store_32(count); //store how many properties are saved
  619. }
  620. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  621. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  622. String key = F->get();
  623. if (E->key() != "") {
  624. key = E->key() + "/" + key;
  625. }
  626. Variant value;
  627. if (p_custom.has(key)) {
  628. value = p_custom[key];
  629. } else {
  630. value = get(key);
  631. }
  632. file->store_32(key.length());
  633. file->store_string(key);
  634. int len;
  635. err = encode_variant(value, nullptr, len, true);
  636. if (err != OK) {
  637. memdelete(file);
  638. }
  639. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  640. Vector<uint8_t> buff;
  641. buff.resize(len);
  642. err = encode_variant(value, buff.ptrw(), len, true);
  643. if (err != OK) {
  644. memdelete(file);
  645. }
  646. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  647. file->store_32(len);
  648. file->store_buffer(buff.ptr(), buff.size());
  649. }
  650. }
  651. file->close();
  652. memdelete(file);
  653. return OK;
  654. }
  655. Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  656. Error err;
  657. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  658. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.godot - " + p_file + ".");
  659. file->store_line("; Engine configuration file.");
  660. file->store_line("; It's best edited using the editor UI and not directly,");
  661. file->store_line("; since the parameters that go here are not all obvious.");
  662. file->store_line(";");
  663. file->store_line("; Format:");
  664. file->store_line("; [section] ; section goes between []");
  665. file->store_line("; param=value ; assign values to parameters");
  666. file->store_line("");
  667. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  668. if (p_custom_features != String()) {
  669. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  670. }
  671. file->store_string("\n");
  672. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  673. if (E != props.front()) {
  674. file->store_string("\n");
  675. }
  676. if (E->key() != "") {
  677. file->store_string("[" + E->key() + "]\n\n");
  678. }
  679. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  680. String key = F->get();
  681. if (E->key() != "") {
  682. key = E->key() + "/" + key;
  683. }
  684. Variant value;
  685. if (p_custom.has(key)) {
  686. value = p_custom[key];
  687. } else {
  688. value = get(key);
  689. }
  690. String vstr;
  691. VariantWriter::write_to_string(value, vstr);
  692. file->store_string(F->get().property_name_encode() + "=" + vstr + "\n");
  693. }
  694. }
  695. file->close();
  696. memdelete(file);
  697. return OK;
  698. }
  699. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  700. return save_custom(p_file);
  701. }
  702. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  703. ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  704. Set<_VCSort> vclist;
  705. if (p_merge_with_current) {
  706. for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
  707. const VariantContainer *v = &G->get();
  708. if (v->hide_from_editor) {
  709. continue;
  710. }
  711. if (p_custom.has(G->key())) {
  712. continue;
  713. }
  714. _VCSort vc;
  715. vc.name = G->key(); //*k;
  716. vc.order = v->order;
  717. vc.type = v->variant.get_type();
  718. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  719. if (v->variant == v->initial) {
  720. continue;
  721. }
  722. vclist.insert(vc);
  723. }
  724. }
  725. for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) {
  726. // Lookup global prop to store in the same order
  727. Map<StringName, VariantContainer>::Element *global_prop = props.find(E->key());
  728. _VCSort vc;
  729. vc.name = E->key();
  730. vc.order = global_prop ? global_prop->get().order : 0xFFFFFFF;
  731. vc.type = E->get().get_type();
  732. vc.flags = PROPERTY_USAGE_STORAGE;
  733. vclist.insert(vc);
  734. }
  735. Map<String, List<String>> props;
  736. for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
  737. String category = E->get().name;
  738. String name = E->get().name;
  739. int div = category.find("/");
  740. if (div < 0) {
  741. category = "";
  742. } else {
  743. category = category.substr(0, div);
  744. name = name.substr(div + 1, name.size());
  745. }
  746. props[category].push_back(name);
  747. }
  748. String custom_features;
  749. for (int i = 0; i < p_custom_features.size(); i++) {
  750. if (i > 0) {
  751. custom_features += ",";
  752. }
  753. String f = p_custom_features[i].strip_edges().replace("\"", "");
  754. custom_features += f;
  755. }
  756. if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) {
  757. return _save_settings_text(p_path, props, p_custom, custom_features);
  758. } else if (p_path.ends_with(".binary")) {
  759. return _save_settings_binary(p_path, props, p_custom, custom_features);
  760. } else {
  761. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + ".");
  762. }
  763. }
  764. 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) {
  765. Variant ret;
  766. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  767. ProjectSettings::get_singleton()->set(p_var, p_default);
  768. }
  769. ret = ProjectSettings::get_singleton()->get(p_var);
  770. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  771. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  772. ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
  773. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  774. ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
  775. return ret;
  776. }
  777. Vector<String> ProjectSettings::get_optimizer_presets() const {
  778. List<PropertyInfo> pi;
  779. ProjectSettings::get_singleton()->get_property_list(&pi);
  780. Vector<String> names;
  781. for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
  782. if (!E->get().name.begins_with("optimizer_presets/")) {
  783. continue;
  784. }
  785. names.push_back(E->get().name.get_slicec('/', 1));
  786. }
  787. names.sort();
  788. return names;
  789. }
  790. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  791. ERR_FAIL_COND(!p_info.has("name"));
  792. ERR_FAIL_COND(!p_info.has("type"));
  793. PropertyInfo pinfo;
  794. pinfo.name = p_info["name"];
  795. ERR_FAIL_COND(!props.has(pinfo.name));
  796. pinfo.type = Variant::Type(p_info["type"].operator int());
  797. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  798. if (p_info.has("hint")) {
  799. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  800. }
  801. if (p_info.has("hint_string")) {
  802. pinfo.hint_string = p_info["hint_string"];
  803. }
  804. set_custom_property_info(pinfo.name, pinfo);
  805. }
  806. void ProjectSettings::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) {
  807. ERR_FAIL_COND(!props.has(p_prop));
  808. custom_prop_info[p_prop] = p_info;
  809. custom_prop_info[p_prop].name = p_prop;
  810. }
  811. const Map<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  812. return custom_prop_info;
  813. }
  814. void ProjectSettings::set_disable_feature_overrides(bool p_disable) {
  815. disable_feature_overrides = p_disable;
  816. }
  817. bool ProjectSettings::is_using_datapack() const {
  818. return using_datapack;
  819. }
  820. bool ProjectSettings::property_can_revert(const String &p_name) {
  821. if (!props.has(p_name)) {
  822. return false;
  823. }
  824. return props[p_name].initial != props[p_name].variant;
  825. }
  826. Variant ProjectSettings::property_get_revert(const String &p_name) {
  827. if (!props.has(p_name)) {
  828. return Variant();
  829. }
  830. return props[p_name].initial;
  831. }
  832. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  833. set(p_setting, p_value);
  834. }
  835. Variant ProjectSettings::get_setting(const String &p_setting) const {
  836. return get(p_setting);
  837. }
  838. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  839. return custom_features.has(p_feature);
  840. }
  841. Map<StringName, ProjectSettings::AutoloadInfo> ProjectSettings::get_autoload_list() const {
  842. return autoloads;
  843. }
  844. void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
  845. ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
  846. autoloads[p_autoload.name] = p_autoload;
  847. }
  848. void ProjectSettings::remove_autoload(const StringName &p_autoload) {
  849. ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
  850. autoloads.erase(p_autoload);
  851. }
  852. bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
  853. return autoloads.has(p_autoload);
  854. }
  855. ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
  856. ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
  857. return autoloads[p_name];
  858. }
  859. void ProjectSettings::_bind_methods() {
  860. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  861. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  862. ClassDB::bind_method(D_METHOD("get_setting", "name"), &ProjectSettings::get_setting);
  863. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  864. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  865. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  866. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  867. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  868. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  869. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  870. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  871. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::_load_resource_pack, DEFVAL(true), DEFVAL(0));
  872. ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ProjectSettings::property_can_revert);
  873. ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &ProjectSettings::property_get_revert);
  874. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  875. }
  876. void ProjectSettings::_add_builtin_input_map() {
  877. if (InputMap::get_singleton()) {
  878. OrderedHashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
  879. for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) {
  880. Array events;
  881. // Convert list of input events into array
  882. for (List<Ref<InputEvent>>::Element *I = E.get().front(); I; I = I->next()) {
  883. events.push_back(I->get());
  884. }
  885. Dictionary action;
  886. action["deadzone"] = Variant(0.5f);
  887. action["events"] = events;
  888. String action_name = "input/" + E.key();
  889. GLOBAL_DEF(action_name, action);
  890. input_presets.push_back(action_name);
  891. }
  892. }
  893. }
  894. ProjectSettings::ProjectSettings() {
  895. // Initialization of engine variables should be done in the setup() method,
  896. // so that the values can be overridden from project.godot or project.binary.
  897. singleton = this;
  898. GLOBAL_DEF_BASIC("application/config/name", "");
  899. GLOBAL_DEF_BASIC("application/config/description", "");
  900. custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
  901. GLOBAL_DEF_BASIC("application/run/main_scene", "");
  902. custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res");
  903. GLOBAL_DEF("application/run/disable_stdout", false);
  904. GLOBAL_DEF("application/run/disable_stderr", false);
  905. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  906. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  907. GLOBAL_DEF("application/config/project_settings_override", "");
  908. GLOBAL_DEF_BASIC("audio/buses/default_bus_layout", "res://default_bus_layout.tres");
  909. custom_prop_info["audio/buses/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres");
  910. PackedStringArray extensions = PackedStringArray();
  911. extensions.push_back("gd");
  912. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  913. extensions.push_back("cs");
  914. }
  915. extensions.push_back("shader");
  916. GLOBAL_DEF("editor/run/main_run_args", "");
  917. GLOBAL_DEF("editor/script/search_in_file_extensions", extensions);
  918. custom_prop_info["editor/script/search_in_file_extensions"] = PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions");
  919. GLOBAL_DEF("editor/script/templates_search_path", "res://script_templates");
  920. custom_prop_info["editor/script/templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR);
  921. _add_builtin_input_map();
  922. custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::STRING, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");
  923. 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");
  924. GLOBAL_DEF("physics/2d/run_on_thread", false);
  925. GLOBAL_DEF("physics/3d/run_on_thread", false);
  926. GLOBAL_DEF("debug/settings/profiler/max_functions", 16384);
  927. custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1");
  928. GLOBAL_DEF("compression/formats/zstd/long_distance_matching", Compression::zstd_long_distance_matching);
  929. custom_prop_info["compression/formats/zstd/long_distance_matching"] = PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching");
  930. GLOBAL_DEF("compression/formats/zstd/compression_level", Compression::zstd_level);
  931. custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1");
  932. GLOBAL_DEF("compression/formats/zstd/window_log_size", Compression::zstd_window_log_size);
  933. custom_prop_info["compression/formats/zstd/window_log_size"] = PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1");
  934. GLOBAL_DEF("compression/formats/zlib/compression_level", Compression::zlib_level);
  935. custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  936. GLOBAL_DEF("compression/formats/gzip/compression_level", Compression::gzip_level);
  937. custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  938. }
  939. ProjectSettings::~ProjectSettings() {
  940. singleton = nullptr;
  941. }