export_plugin.cpp 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*************************************************************************/
  2. /* export_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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 "export_plugin.h"
  31. #include "core/config/project_settings.h"
  32. #include "editor/editor_node.h"
  33. Error EditorExportPlatformLinuxBSD::_export_debug_script(const Ref<EditorExportPreset> &p_preset, const String &p_app_name, const String &p_pkg_name, const String &p_path) {
  34. FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE);
  35. ERR_FAIL_COND_V(!f, ERR_CANT_CREATE);
  36. f->store_line("#!/bin/sh");
  37. f->store_line("echo -ne '\\033c\\033]0;" + p_app_name + "\\a'");
  38. f->store_line("base_path=\"$(dirname \"$(realpath \"$0\")\")\"");
  39. f->store_line("\"$base_path/" + p_pkg_name + "\" \"$@\"");
  40. return OK;
  41. }
  42. Error EditorExportPlatformLinuxBSD::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
  43. Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, p_path, p_flags);
  44. if (err != OK) {
  45. return err;
  46. }
  47. String app_name;
  48. if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
  49. app_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
  50. } else {
  51. app_name = "Unnamed";
  52. }
  53. app_name = OS::get_singleton()->get_safe_dir_name(app_name);
  54. // Save console script.
  55. if (err == OK) {
  56. int con_scr = p_preset->get("debug/export_console_script");
  57. if ((con_scr == 1 && p_debug) || (con_scr == 2)) {
  58. String scr_path = p_path.get_basename() + ".sh";
  59. err = _export_debug_script(p_preset, app_name, p_path.get_file(), scr_path);
  60. FileAccess::set_unix_permissions(scr_path, 0755);
  61. }
  62. }
  63. return err;
  64. }