project_settings.cpp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  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. String candidate = current_dir;
  397. bool found = false;
  398. Error err;
  399. while (true) {
  400. err = _load_settings_text_or_binary(current_dir.plus_file("project.godot"), current_dir.plus_file("project.binary"));
  401. if (err == OK) {
  402. // Optional, we don't mind if it fails.
  403. _load_settings_text(current_dir.plus_file("override.cfg"));
  404. candidate = current_dir;
  405. found = true;
  406. break;
  407. }
  408. if (p_upwards) {
  409. // Try to load settings ascending through parent directories
  410. d->change_dir("..");
  411. if (d->get_current_dir() == current_dir) {
  412. break; // not doing anything useful
  413. }
  414. current_dir = d->get_current_dir();
  415. } else {
  416. break;
  417. }
  418. }
  419. resource_path = candidate;
  420. resource_path = resource_path.replace("\\", "/"); // Windows path to Unix path just in case.
  421. memdelete(d);
  422. if (!found) {
  423. return err;
  424. }
  425. if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
  426. resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
  427. }
  428. return OK;
  429. }
  430. Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards) {
  431. Error err = _setup(p_path, p_main_pack, p_upwards);
  432. if (err == OK) {
  433. String custom_settings = GLOBAL_DEF("application/config/project_settings_override", "");
  434. if (custom_settings != "") {
  435. _load_settings_text(custom_settings);
  436. }
  437. }
  438. // Using GLOBAL_GET on every block for compressing can be slow, so assigning here.
  439. Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching");
  440. Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level");
  441. Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size");
  442. Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level");
  443. Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level");
  444. return err;
  445. }
  446. bool ProjectSettings::has_setting(String p_var) const {
  447. _THREAD_SAFE_METHOD_
  448. return props.has(p_var);
  449. }
  450. Error ProjectSettings::_load_settings_binary(const String &p_path) {
  451. Error err;
  452. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  453. if (err != OK) {
  454. return err;
  455. }
  456. uint8_t hdr[4];
  457. f->get_buffer(hdr, 4);
  458. if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
  459. memdelete(f);
  460. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
  461. }
  462. uint32_t count = f->get_32();
  463. for (uint32_t i = 0; i < count; i++) {
  464. uint32_t slen = f->get_32();
  465. CharString cs;
  466. cs.resize(slen + 1);
  467. cs[slen] = 0;
  468. f->get_buffer((uint8_t *)cs.ptr(), slen);
  469. String key;
  470. key.parse_utf8(cs.ptr());
  471. uint32_t vlen = f->get_32();
  472. Vector<uint8_t> d;
  473. d.resize(vlen);
  474. f->get_buffer(d.ptrw(), vlen);
  475. Variant value;
  476. err = decode_variant(value, d.ptr(), d.size(), nullptr, true);
  477. ERR_CONTINUE_MSG(err != OK, "Error decoding property: " + key + ".");
  478. set(key, value);
  479. }
  480. f->close();
  481. memdelete(f);
  482. return OK;
  483. }
  484. Error ProjectSettings::_load_settings_text(const String &p_path) {
  485. Error err;
  486. FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
  487. if (!f) {
  488. // FIXME: Above 'err' error code is ERR_FILE_CANT_OPEN if the file is missing
  489. // This needs to be streamlined if we want decent error reporting
  490. return ERR_FILE_NOT_FOUND;
  491. }
  492. VariantParser::StreamFile stream;
  493. stream.f = f;
  494. String assign;
  495. Variant value;
  496. VariantParser::Tag next_tag;
  497. int lines = 0;
  498. String error_text;
  499. String section;
  500. int config_version = 0;
  501. while (true) {
  502. assign = Variant();
  503. next_tag.fields.clear();
  504. next_tag.name = String();
  505. err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true);
  506. if (err == ERR_FILE_EOF) {
  507. memdelete(f);
  508. // If we're loading a project.godot from source code, we can operate some
  509. // ProjectSettings conversions if need be.
  510. _convert_to_last_version(config_version);
  511. last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
  512. return OK;
  513. } else if (err != OK) {
  514. ERR_PRINT("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
  515. memdelete(f);
  516. return err;
  517. }
  518. if (assign != String()) {
  519. if (section == String() && assign == "config_version") {
  520. config_version = value;
  521. if (config_version > CONFIG_VERSION) {
  522. memdelete(f);
  523. 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));
  524. }
  525. } else {
  526. if (section == String()) {
  527. set(assign, value);
  528. } else {
  529. set(section + "/" + assign, value);
  530. }
  531. }
  532. } else if (next_tag.name != String()) {
  533. section = next_tag.name;
  534. }
  535. }
  536. }
  537. Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) {
  538. // Attempt first to load the binary project.godot file.
  539. Error err = _load_settings_binary(p_bin_path);
  540. if (err == OK) {
  541. return OK;
  542. } else if (err != ERR_FILE_NOT_FOUND) {
  543. // If the file exists but can't be loaded, we want to know it.
  544. ERR_PRINT("Couldn't load file '" + p_bin_path + "', error code " + itos(err) + ".");
  545. return err;
  546. }
  547. // Fallback to text-based project.godot file if binary was not found.
  548. err = _load_settings_text(p_text_path);
  549. if (err == OK) {
  550. return OK;
  551. } else if (err != ERR_FILE_NOT_FOUND) {
  552. ERR_PRINT("Couldn't load file '" + p_text_path + "', error code " + itos(err) + ".");
  553. return err;
  554. }
  555. return err;
  556. }
  557. int ProjectSettings::get_order(const String &p_name) const {
  558. ERR_FAIL_COND_V_MSG(!props.has(p_name), -1, "Request for nonexistent project setting: " + p_name + ".");
  559. return props[p_name].order;
  560. }
  561. void ProjectSettings::set_order(const String &p_name, int p_order) {
  562. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  563. props[p_name].order = p_order;
  564. }
  565. void ProjectSettings::set_builtin_order(const String &p_name) {
  566. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  567. if (props[p_name].order >= NO_BUILTIN_ORDER_BASE) {
  568. props[p_name].order = last_builtin_order++;
  569. }
  570. }
  571. bool ProjectSettings::is_builtin_setting(const String &p_name) const {
  572. // Return true because a false negative is worse than a false positive.
  573. ERR_FAIL_COND_V_MSG(!props.has(p_name), true, "Request for nonexistent project setting: " + p_name + ".");
  574. return props[p_name].order < NO_BUILTIN_ORDER_BASE;
  575. }
  576. void ProjectSettings::clear(const String &p_name) {
  577. ERR_FAIL_COND_MSG(!props.has(p_name), "Request for nonexistent project setting: " + p_name + ".");
  578. props.erase(p_name);
  579. }
  580. Error ProjectSettings::save() {
  581. Error error = save_custom(get_resource_path().plus_file("project.godot"));
  582. if (error == OK) {
  583. last_save_time = FileAccess::get_modified_time(get_resource_path().plus_file("project.godot"));
  584. }
  585. return error;
  586. }
  587. Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  588. Error err;
  589. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  590. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + ".");
  591. uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
  592. file->store_buffer(hdr, 4);
  593. int count = 0;
  594. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  595. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  596. count++;
  597. }
  598. }
  599. if (p_custom_features != String()) {
  600. file->store_32(count + 1);
  601. //store how many properties are saved, add one for custom featuers, which must always go first
  602. String key = CoreStringNames::get_singleton()->_custom_features;
  603. file->store_32(key.length());
  604. file->store_string(key);
  605. int len;
  606. err = encode_variant(p_custom_features, nullptr, len, false);
  607. if (err != OK) {
  608. memdelete(file);
  609. ERR_FAIL_V(err);
  610. }
  611. Vector<uint8_t> buff;
  612. buff.resize(len);
  613. err = encode_variant(p_custom_features, buff.ptrw(), len, false);
  614. if (err != OK) {
  615. memdelete(file);
  616. ERR_FAIL_V(err);
  617. }
  618. file->store_32(len);
  619. file->store_buffer(buff.ptr(), buff.size());
  620. } else {
  621. file->store_32(count); //store how many properties are saved
  622. }
  623. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  624. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  625. String key = F->get();
  626. if (E->key() != "") {
  627. key = E->key() + "/" + key;
  628. }
  629. Variant value;
  630. if (p_custom.has(key)) {
  631. value = p_custom[key];
  632. } else {
  633. value = get(key);
  634. }
  635. file->store_32(key.length());
  636. file->store_string(key);
  637. int len;
  638. err = encode_variant(value, nullptr, len, true);
  639. if (err != OK) {
  640. memdelete(file);
  641. }
  642. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  643. Vector<uint8_t> buff;
  644. buff.resize(len);
  645. err = encode_variant(value, buff.ptrw(), len, true);
  646. if (err != OK) {
  647. memdelete(file);
  648. }
  649. ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
  650. file->store_32(len);
  651. file->store_buffer(buff.ptr(), buff.size());
  652. }
  653. }
  654. file->close();
  655. memdelete(file);
  656. return OK;
  657. }
  658. Error ProjectSettings::_save_settings_text(const String &p_file, const Map<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) {
  659. Error err;
  660. FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
  661. ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.godot - " + p_file + ".");
  662. file->store_line("; Engine configuration file.");
  663. file->store_line("; It's best edited using the editor UI and not directly,");
  664. file->store_line("; since the parameters that go here are not all obvious.");
  665. file->store_line(";");
  666. file->store_line("; Format:");
  667. file->store_line("; [section] ; section goes between []");
  668. file->store_line("; param=value ; assign values to parameters");
  669. file->store_line("");
  670. file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
  671. if (p_custom_features != String()) {
  672. file->store_string("custom_features=\"" + p_custom_features + "\"\n");
  673. }
  674. file->store_string("\n");
  675. for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
  676. if (E != props.front()) {
  677. file->store_string("\n");
  678. }
  679. if (E->key() != "") {
  680. file->store_string("[" + E->key() + "]\n\n");
  681. }
  682. for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
  683. String key = F->get();
  684. if (E->key() != "") {
  685. key = E->key() + "/" + key;
  686. }
  687. Variant value;
  688. if (p_custom.has(key)) {
  689. value = p_custom[key];
  690. } else {
  691. value = get(key);
  692. }
  693. String vstr;
  694. VariantWriter::write_to_string(value, vstr);
  695. file->store_string(F->get().property_name_encode() + "=" + vstr + "\n");
  696. }
  697. }
  698. file->close();
  699. memdelete(file);
  700. return OK;
  701. }
  702. Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
  703. return save_custom(p_file);
  704. }
  705. Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
  706. ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
  707. Set<_VCSort> vclist;
  708. if (p_merge_with_current) {
  709. for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
  710. const VariantContainer *v = &G->get();
  711. if (v->hide_from_editor) {
  712. continue;
  713. }
  714. if (p_custom.has(G->key())) {
  715. continue;
  716. }
  717. _VCSort vc;
  718. vc.name = G->key(); //*k;
  719. vc.order = v->order;
  720. vc.type = v->variant.get_type();
  721. vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
  722. if (v->variant == v->initial) {
  723. continue;
  724. }
  725. vclist.insert(vc);
  726. }
  727. }
  728. for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) {
  729. // Lookup global prop to store in the same order
  730. Map<StringName, VariantContainer>::Element *global_prop = props.find(E->key());
  731. _VCSort vc;
  732. vc.name = E->key();
  733. vc.order = global_prop ? global_prop->get().order : 0xFFFFFFF;
  734. vc.type = E->get().get_type();
  735. vc.flags = PROPERTY_USAGE_STORAGE;
  736. vclist.insert(vc);
  737. }
  738. Map<String, List<String>> props;
  739. for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
  740. String category = E->get().name;
  741. String name = E->get().name;
  742. int div = category.find("/");
  743. if (div < 0) {
  744. category = "";
  745. } else {
  746. category = category.substr(0, div);
  747. name = name.substr(div + 1, name.size());
  748. }
  749. props[category].push_back(name);
  750. }
  751. String custom_features;
  752. for (int i = 0; i < p_custom_features.size(); i++) {
  753. if (i > 0) {
  754. custom_features += ",";
  755. }
  756. String f = p_custom_features[i].strip_edges().replace("\"", "");
  757. custom_features += f;
  758. }
  759. if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) {
  760. return _save_settings_text(p_path, props, p_custom, custom_features);
  761. } else if (p_path.ends_with(".binary")) {
  762. return _save_settings_binary(p_path, props, p_custom, custom_features);
  763. } else {
  764. ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + ".");
  765. }
  766. }
  767. 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) {
  768. Variant ret;
  769. if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
  770. ProjectSettings::get_singleton()->set(p_var, p_default);
  771. }
  772. ret = ProjectSettings::get_singleton()->get(p_var);
  773. ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
  774. ProjectSettings::get_singleton()->set_builtin_order(p_var);
  775. ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
  776. ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
  777. ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
  778. return ret;
  779. }
  780. Vector<String> ProjectSettings::get_optimizer_presets() const {
  781. List<PropertyInfo> pi;
  782. ProjectSettings::get_singleton()->get_property_list(&pi);
  783. Vector<String> names;
  784. for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
  785. if (!E->get().name.begins_with("optimizer_presets/")) {
  786. continue;
  787. }
  788. names.push_back(E->get().name.get_slicec('/', 1));
  789. }
  790. names.sort();
  791. return names;
  792. }
  793. void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
  794. ERR_FAIL_COND(!p_info.has("name"));
  795. ERR_FAIL_COND(!p_info.has("type"));
  796. PropertyInfo pinfo;
  797. pinfo.name = p_info["name"];
  798. ERR_FAIL_COND(!props.has(pinfo.name));
  799. pinfo.type = Variant::Type(p_info["type"].operator int());
  800. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  801. if (p_info.has("hint")) {
  802. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  803. }
  804. if (p_info.has("hint_string")) {
  805. pinfo.hint_string = p_info["hint_string"];
  806. }
  807. set_custom_property_info(pinfo.name, pinfo);
  808. }
  809. void ProjectSettings::set_custom_property_info(const String &p_prop, const PropertyInfo &p_info) {
  810. ERR_FAIL_COND(!props.has(p_prop));
  811. custom_prop_info[p_prop] = p_info;
  812. custom_prop_info[p_prop].name = p_prop;
  813. }
  814. const Map<StringName, PropertyInfo> &ProjectSettings::get_custom_property_info() const {
  815. return custom_prop_info;
  816. }
  817. void ProjectSettings::set_disable_feature_overrides(bool p_disable) {
  818. disable_feature_overrides = p_disable;
  819. }
  820. bool ProjectSettings::is_using_datapack() const {
  821. return using_datapack;
  822. }
  823. bool ProjectSettings::property_can_revert(const String &p_name) {
  824. if (!props.has(p_name)) {
  825. return false;
  826. }
  827. return props[p_name].initial != props[p_name].variant;
  828. }
  829. Variant ProjectSettings::property_get_revert(const String &p_name) {
  830. if (!props.has(p_name)) {
  831. return Variant();
  832. }
  833. return props[p_name].initial;
  834. }
  835. void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
  836. set(p_setting, p_value);
  837. }
  838. Variant ProjectSettings::get_setting(const String &p_setting) const {
  839. return get(p_setting);
  840. }
  841. bool ProjectSettings::has_custom_feature(const String &p_feature) const {
  842. return custom_features.has(p_feature);
  843. }
  844. Map<StringName, ProjectSettings::AutoloadInfo> ProjectSettings::get_autoload_list() const {
  845. return autoloads;
  846. }
  847. void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
  848. ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
  849. autoloads[p_autoload.name] = p_autoload;
  850. }
  851. void ProjectSettings::remove_autoload(const StringName &p_autoload) {
  852. ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
  853. autoloads.erase(p_autoload);
  854. }
  855. bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
  856. return autoloads.has(p_autoload);
  857. }
  858. ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
  859. ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
  860. return autoloads[p_name];
  861. }
  862. void ProjectSettings::_bind_methods() {
  863. ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
  864. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
  865. ClassDB::bind_method(D_METHOD("get_setting", "name"), &ProjectSettings::get_setting);
  866. ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
  867. ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
  868. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);
  869. ClassDB::bind_method(D_METHOD("add_property_info", "hint"), &ProjectSettings::_add_property_info_bind);
  870. ClassDB::bind_method(D_METHOD("clear", "name"), &ProjectSettings::clear);
  871. ClassDB::bind_method(D_METHOD("localize_path", "path"), &ProjectSettings::localize_path);
  872. ClassDB::bind_method(D_METHOD("globalize_path", "path"), &ProjectSettings::globalize_path);
  873. ClassDB::bind_method(D_METHOD("save"), &ProjectSettings::save);
  874. ClassDB::bind_method(D_METHOD("load_resource_pack", "pack", "replace_files", "offset"), &ProjectSettings::_load_resource_pack, DEFVAL(true), DEFVAL(0));
  875. ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &ProjectSettings::property_can_revert);
  876. ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &ProjectSettings::property_get_revert);
  877. ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
  878. }
  879. void ProjectSettings::_add_builtin_input_map() {
  880. if (InputMap::get_singleton()) {
  881. OrderedHashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
  882. for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) {
  883. Array events;
  884. // Convert list of input events into array
  885. for (List<Ref<InputEvent>>::Element *I = E.get().front(); I; I = I->next()) {
  886. events.push_back(I->get());
  887. }
  888. Dictionary action;
  889. action["deadzone"] = Variant(0.5f);
  890. action["events"] = events;
  891. String action_name = "input/" + E.key();
  892. GLOBAL_DEF(action_name, action);
  893. input_presets.push_back(action_name);
  894. }
  895. }
  896. }
  897. ProjectSettings::ProjectSettings() {
  898. // Initialization of engine variables should be done in the setup() method,
  899. // so that the values can be overridden from project.godot or project.binary.
  900. singleton = this;
  901. GLOBAL_DEF_BASIC("application/config/name", "");
  902. GLOBAL_DEF_BASIC("application/config/description", "");
  903. custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
  904. GLOBAL_DEF_BASIC("application/run/main_scene", "");
  905. custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res");
  906. GLOBAL_DEF("application/run/disable_stdout", false);
  907. GLOBAL_DEF("application/run/disable_stderr", false);
  908. GLOBAL_DEF("application/config/use_custom_user_dir", false);
  909. GLOBAL_DEF("application/config/custom_user_dir_name", "");
  910. GLOBAL_DEF("application/config/project_settings_override", "");
  911. GLOBAL_DEF_BASIC("audio/buses/default_bus_layout", "res://default_bus_layout.tres");
  912. custom_prop_info["audio/buses/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres");
  913. PackedStringArray extensions = PackedStringArray();
  914. extensions.push_back("gd");
  915. if (Engine::get_singleton()->has_singleton("GodotSharp")) {
  916. extensions.push_back("cs");
  917. }
  918. extensions.push_back("shader");
  919. GLOBAL_DEF("editor/script/search_in_file_extensions", extensions);
  920. custom_prop_info["editor/script/search_in_file_extensions"] = PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions");
  921. GLOBAL_DEF("editor/script/templates_search_path", "res://script_templates");
  922. custom_prop_info["editor/script/templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR);
  923. _add_builtin_input_map();
  924. 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");
  925. 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");
  926. GLOBAL_DEF("physics/2d/run_on_thread", false);
  927. GLOBAL_DEF("physics/3d/run_on_thread", false);
  928. GLOBAL_DEF("debug/settings/profiler/max_functions", 16384);
  929. custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1");
  930. GLOBAL_DEF("compression/formats/zstd/long_distance_matching", Compression::zstd_long_distance_matching);
  931. custom_prop_info["compression/formats/zstd/long_distance_matching"] = PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching");
  932. GLOBAL_DEF("compression/formats/zstd/compression_level", Compression::zstd_level);
  933. custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1");
  934. GLOBAL_DEF("compression/formats/zstd/window_log_size", Compression::zstd_window_log_size);
  935. custom_prop_info["compression/formats/zstd/window_log_size"] = PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1");
  936. GLOBAL_DEF("compression/formats/zlib/compression_level", Compression::zlib_level);
  937. custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  938. GLOBAL_DEF("compression/formats/gzip/compression_level", Compression::gzip_level);
  939. custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
  940. }
  941. ProjectSettings::~ProjectSettings() {
  942. singleton = nullptr;
  943. }