Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/windows/export/export_plugin.cpp
10278 views
1
/**************************************************************************/
2
/* export_plugin.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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
31
#include "export_plugin.h"
32
33
#include "logo_svg.gen.h"
34
#include "run_icon_svg.gen.h"
35
#include "template_modifier.h"
36
37
#include "core/config/project_settings.h"
38
#include "core/io/image_loader.h"
39
#include "editor/editor_node.h"
40
#include "editor/editor_string_names.h"
41
#include "editor/export/editor_export.h"
42
#include "editor/file_system/editor_paths.h"
43
#include "editor/themes/editor_scale.h"
44
45
#include "modules/svg/image_loader_svg.h"
46
47
#ifdef WINDOWS_ENABLED
48
#include "shlobj.h"
49
50
// Converts long path to Windows UNC format.
51
static String fix_path(const String &p_path) {
52
String path = p_path;
53
if (p_path.is_relative_path()) {
54
Char16String current_dir_name;
55
size_t str_len = GetCurrentDirectoryW(0, nullptr);
56
current_dir_name.resize_uninitialized(str_len + 1);
57
GetCurrentDirectoryW(current_dir_name.size(), (LPWSTR)current_dir_name.ptrw());
58
path = String::utf16((const char16_t *)current_dir_name.get_data()).trim_prefix(R"(\\?\)").replace_char('\\', '/').path_join(path);
59
}
60
path = path.simplify_path();
61
path = path.replace_char('/', '\\');
62
if (path.size() >= MAX_PATH && !path.is_network_share_path() && !path.begins_with(R"(\\?\)")) {
63
path = R"(\\?\)" + path;
64
}
65
return path;
66
}
67
68
#endif
69
70
Error EditorExportPlatformWindows::_process_icon(const Ref<EditorExportPreset> &p_preset, const String &p_src_path, const String &p_dst_path) {
71
static const uint8_t icon_size[] = { 16, 32, 48, 64, 128, 0 /*256*/ };
72
73
struct IconData {
74
Vector<uint8_t> data;
75
uint8_t pal_colors = 0;
76
uint16_t planes = 0;
77
uint16_t bpp = 32;
78
};
79
80
HashMap<uint8_t, IconData> images;
81
Error err;
82
83
if (p_src_path.get_extension() == "ico") {
84
Ref<FileAccess> f = FileAccess::open(p_src_path, FileAccess::READ, &err);
85
if (err != OK) {
86
return err;
87
}
88
89
// Read ICONDIR.
90
f->get_16(); // Reserved.
91
uint16_t icon_type = f->get_16(); // Image type: 1 - ICO.
92
uint16_t icon_count = f->get_16(); // Number of images.
93
ERR_FAIL_COND_V(icon_type != 1, ERR_CANT_OPEN);
94
95
for (uint16_t i = 0; i < icon_count; i++) {
96
// Read ICONDIRENTRY.
97
uint16_t w = f->get_8(); // Width in pixels.
98
uint16_t h = f->get_8(); // Height in pixels.
99
uint8_t pal_colors = f->get_8(); // Number of colors in the palette (0 - no palette).
100
f->get_8(); // Reserved.
101
uint16_t planes = f->get_16(); // Number of color planes.
102
uint16_t bpp = f->get_16(); // Bits per pixel.
103
uint32_t img_size = f->get_32(); // Image data size in bytes.
104
uint32_t img_offset = f->get_32(); // Image data offset.
105
if (w != h) {
106
continue;
107
}
108
109
// Read image data.
110
uint64_t prev_offset = f->get_position();
111
images[w].pal_colors = pal_colors;
112
images[w].planes = planes;
113
images[w].bpp = bpp;
114
images[w].data.resize(img_size);
115
f->seek(img_offset);
116
f->get_buffer(images[w].data.ptrw(), img_size);
117
f->seek(prev_offset);
118
}
119
} else {
120
Ref<Image> src_image = _load_icon_or_splash_image(p_src_path, &err);
121
ERR_FAIL_COND_V(err != OK || src_image.is_null() || src_image->is_empty(), ERR_CANT_OPEN);
122
123
for (size_t i = 0; i < std::size(icon_size); ++i) {
124
int size = (icon_size[i] == 0) ? 256 : icon_size[i];
125
126
Ref<Image> res_image = src_image->duplicate();
127
ERR_FAIL_COND_V(res_image.is_null() || res_image->is_empty(), ERR_CANT_OPEN);
128
res_image->resize(size, size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int()));
129
images[icon_size[i]].data = res_image->save_png_to_buffer();
130
}
131
}
132
133
uint16_t valid_icon_count = 0;
134
for (size_t i = 0; i < std::size(icon_size); ++i) {
135
if (images.has(icon_size[i])) {
136
valid_icon_count++;
137
} else {
138
int size = (icon_size[i] == 0) ? 256 : icon_size[i];
139
add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Icon size \"%d\" is missing."), size));
140
}
141
}
142
ERR_FAIL_COND_V(valid_icon_count == 0, ERR_CANT_OPEN);
143
144
Ref<FileAccess> fw = FileAccess::open(p_dst_path, FileAccess::WRITE, &err);
145
if (err != OK) {
146
return err;
147
}
148
149
// Write ICONDIR.
150
fw->store_16(0); // Reserved.
151
fw->store_16(1); // Image type: 1 - ICO.
152
fw->store_16(valid_icon_count); // Number of images.
153
154
// Write ICONDIRENTRY.
155
uint32_t img_offset = 6 + 16 * valid_icon_count;
156
for (size_t i = 0; i < std::size(icon_size); ++i) {
157
if (images.has(icon_size[i])) {
158
const IconData &di = images[icon_size[i]];
159
fw->store_8(icon_size[i]); // Width in pixels.
160
fw->store_8(icon_size[i]); // Height in pixels.
161
fw->store_8(di.pal_colors); // Number of colors in the palette (0 - no palette).
162
fw->store_8(0); // Reserved.
163
fw->store_16(di.planes); // Number of color planes.
164
fw->store_16(di.bpp); // Bits per pixel.
165
fw->store_32(di.data.size()); // Image data size in bytes.
166
fw->store_32(img_offset); // Image data offset.
167
168
img_offset += di.data.size();
169
}
170
}
171
172
// Write image data.
173
for (size_t i = 0; i < std::size(icon_size); ++i) {
174
if (images.has(icon_size[i])) {
175
const IconData &di = images[icon_size[i]];
176
fw->store_buffer(di.data.ptr(), di.data.size());
177
}
178
}
179
return OK;
180
}
181
182
Error EditorExportPlatformWindows::sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) {
183
if (p_preset->get("codesign/enable")) {
184
return _code_sign(p_preset, p_path);
185
} else {
186
return OK;
187
}
188
}
189
190
Error EditorExportPlatformWindows::modify_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) {
191
if (p_preset->get("application/modify_resources")) {
192
_add_data(p_preset, p_path, false);
193
String wrapper_path = p_path.get_basename() + ".console.exe";
194
if (FileAccess::exists(wrapper_path)) {
195
_add_data(p_preset, wrapper_path, true);
196
}
197
}
198
return OK;
199
}
200
201
Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, BitField<EditorExportPlatform::DebugFlags> p_flags) {
202
String custom_debug = p_preset->get("custom_template/debug");
203
String custom_release = p_preset->get("custom_template/release");
204
String arch = p_preset->get("binary_format/architecture");
205
206
String template_path = p_debug ? custom_debug : custom_release;
207
template_path = template_path.strip_edges();
208
if (template_path.is_empty()) {
209
template_path = find_export_template(get_template_file_name(p_debug ? "debug" : "release", arch));
210
} else {
211
String exe_arch = _get_exe_arch(template_path);
212
if (arch != exe_arch) {
213
add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Mismatching custom export template executable architecture: found \"%s\", expected \"%s\"."), exe_arch, arch));
214
return ERR_CANT_CREATE;
215
}
216
}
217
218
bool export_as_zip = p_path.ends_with("zip");
219
bool embedded = p_preset->get("binary_format/embed_pck");
220
221
String pkg_name;
222
if (String(get_project_setting(p_preset, "application/config/name")) != "") {
223
pkg_name = String(get_project_setting(p_preset, "application/config/name"));
224
} else {
225
pkg_name = "Unnamed";
226
}
227
228
pkg_name = OS::get_singleton()->get_safe_dir_name(pkg_name);
229
230
// Setup temp folder.
231
String path = p_path;
232
String tmp_dir_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);
233
Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_dir_path);
234
if (export_as_zip) {
235
if (tmp_app_dir.is_null()) {
236
add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not create and open the directory: \"%s\""), tmp_dir_path));
237
return ERR_CANT_CREATE;
238
}
239
if (DirAccess::exists(tmp_dir_path)) {
240
if (tmp_app_dir->change_dir(tmp_dir_path) == OK) {
241
tmp_app_dir->erase_contents_recursive();
242
}
243
}
244
tmp_app_dir->make_dir_recursive(tmp_dir_path);
245
path = tmp_dir_path.path_join(p_path.get_file().get_basename() + ".exe");
246
}
247
248
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
249
int export_angle = p_preset->get("application/export_angle");
250
bool include_angle_libs = false;
251
if (export_angle == 0) {
252
include_angle_libs = (String(get_project_setting(p_preset, "rendering/gl_compatibility/driver.windows")) == "opengl3_angle") && (String(get_project_setting(p_preset, "rendering/renderer/rendering_method")) == "gl_compatibility");
253
} else if (export_angle == 1) {
254
include_angle_libs = true;
255
}
256
if (include_angle_libs) {
257
if (da->file_exists(template_path.get_base_dir().path_join("libEGL." + arch + ".dll"))) {
258
da->copy(template_path.get_base_dir().path_join("libEGL." + arch + ".dll"), path.get_base_dir().path_join("libEGL.dll"), get_chmod_flags());
259
}
260
if (da->file_exists(template_path.get_base_dir().path_join("libGLESv2." + arch + ".dll"))) {
261
da->copy(template_path.get_base_dir().path_join("libGLESv2." + arch + ".dll"), path.get_base_dir().path_join("libGLESv2.dll"), get_chmod_flags());
262
}
263
}
264
if (da->file_exists(template_path.get_base_dir().path_join("accesskit." + arch + ".dll"))) {
265
da->copy(template_path.get_base_dir().path_join("accesskit." + arch + ".dll"), path.get_base_dir().path_join("accesskit." + arch + ".dll"), get_chmod_flags());
266
}
267
268
int export_d3d12 = p_preset->get("application/export_d3d12");
269
bool agility_sdk_multiarch = p_preset->get("application/d3d12_agility_sdk_multiarch");
270
bool include_d3d12_extra_libs = false;
271
if (export_d3d12 == 0) {
272
include_d3d12_extra_libs = (String(get_project_setting(p_preset, "rendering/rendering_device/driver.windows")) == "d3d12") && (String(get_project_setting(p_preset, "rendering/renderer/rendering_method")) != "gl_compatibility");
273
} else if (export_d3d12 == 1) {
274
include_d3d12_extra_libs = true;
275
}
276
if (include_d3d12_extra_libs) {
277
if (da->file_exists(template_path.get_base_dir().path_join("D3D12Core." + arch + ".dll"))) {
278
if (agility_sdk_multiarch) {
279
da->make_dir_recursive(path.get_base_dir().path_join(arch));
280
da->copy(template_path.get_base_dir().path_join("D3D12Core." + arch + ".dll"), path.get_base_dir().path_join(arch).path_join("D3D12Core.dll"), get_chmod_flags());
281
} else {
282
da->copy(template_path.get_base_dir().path_join("D3D12Core." + arch + ".dll"), path.get_base_dir().path_join("D3D12Core.dll"), get_chmod_flags());
283
}
284
}
285
if (da->file_exists(template_path.get_base_dir().path_join("d3d12SDKLayers." + arch + ".dll"))) {
286
if (agility_sdk_multiarch) {
287
da->make_dir_recursive(path.get_base_dir().path_join(arch));
288
da->copy(template_path.get_base_dir().path_join("d3d12SDKLayers." + arch + ".dll"), path.get_base_dir().path_join(arch).path_join("d3d12SDKLayers.dll"), get_chmod_flags());
289
} else {
290
da->copy(template_path.get_base_dir().path_join("d3d12SDKLayers." + arch + ".dll"), path.get_base_dir().path_join("d3d12SDKLayers.dll"), get_chmod_flags());
291
}
292
}
293
if (da->file_exists(template_path.get_base_dir().path_join("WinPixEventRuntime." + arch + ".dll"))) {
294
da->copy(template_path.get_base_dir().path_join("WinPixEventRuntime." + arch + ".dll"), path.get_base_dir().path_join("WinPixEventRuntime.dll"), get_chmod_flags());
295
}
296
}
297
298
// Export project.
299
String pck_path = path;
300
if (embedded) {
301
pck_path = pck_path.get_basename() + ".tmp";
302
}
303
304
Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, pck_path, p_flags);
305
if (err != OK) {
306
// Message is supplied by the subroutine method.
307
return err;
308
}
309
310
if (p_preset->get("codesign/enable")) {
311
_code_sign(p_preset, pck_path);
312
String wrapper_path = path.get_basename() + ".console.exe";
313
if (FileAccess::exists(wrapper_path)) {
314
_code_sign(p_preset, wrapper_path);
315
}
316
}
317
318
if (embedded) {
319
Ref<DirAccess> tmp_dir = DirAccess::create_for_path(path.get_base_dir());
320
err = tmp_dir->rename(pck_path, path);
321
if (err != OK) {
322
add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to rename temporary file \"%s\"."), pck_path));
323
}
324
}
325
326
// ZIP project.
327
if (export_as_zip) {
328
if (FileAccess::exists(p_path)) {
329
OS::get_singleton()->move_to_trash(p_path);
330
}
331
332
Ref<FileAccess> io_fa_dst;
333
zlib_filefunc_def io_dst = zipio_create_io(&io_fa_dst);
334
zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, nullptr, &io_dst);
335
336
zip_folder_recursive(zip, tmp_dir_path, "", pkg_name);
337
338
zipClose(zip, nullptr);
339
340
if (tmp_app_dir->change_dir(tmp_dir_path) == OK) {
341
tmp_app_dir->erase_contents_recursive();
342
tmp_app_dir->change_dir("..");
343
tmp_app_dir->remove(pkg_name);
344
}
345
#ifdef WINDOWS_ENABLED
346
} else {
347
// Update Windows icon cache.
348
String w_path = fix_path(path);
349
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, (LPCWSTR)w_path.utf16().get_data(), nullptr);
350
351
String wrapper_path = path.get_basename() + ".console.exe";
352
if (FileAccess::exists(wrapper_path)) {
353
String w_wrapper_path = fix_path(wrapper_path);
354
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, (LPCWSTR)w_wrapper_path.utf16().get_data(), nullptr);
355
}
356
357
w_path = fix_path(path.get_base_dir());
358
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, (LPCWSTR)w_path.utf16().get_data(), nullptr);
359
360
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
361
#endif
362
}
363
364
return err;
365
}
366
367
String EditorExportPlatformWindows::get_template_file_name(const String &p_target, const String &p_arch) const {
368
return "windows_" + p_target + "_" + p_arch + ".exe";
369
}
370
371
List<String> EditorExportPlatformWindows::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
372
List<String> list;
373
list.push_back("exe");
374
list.push_back("zip");
375
return list;
376
}
377
378
String EditorExportPlatformWindows::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {
379
if (p_preset) {
380
if (p_name == "application/icon") {
381
String icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/icon"));
382
if (!icon_path.is_empty() && !FileAccess::exists(icon_path)) {
383
return TTR("Invalid icon path.");
384
}
385
} else if (p_name == "application/file_version") {
386
String file_version = p_preset->get("application/file_version");
387
if (!file_version.is_empty()) {
388
PackedStringArray version_array = file_version.split(".", false);
389
if (version_array.size() != 4 || !version_array[0].is_valid_int() ||
390
!version_array[1].is_valid_int() || !version_array[2].is_valid_int() ||
391
!version_array[3].is_valid_int() || file_version.contains_char('-')) {
392
return TTR("Invalid file version.");
393
}
394
}
395
} else if (p_name == "application/product_version") {
396
String product_version = p_preset->get("application/product_version");
397
if (!product_version.is_empty()) {
398
PackedStringArray version_array = product_version.split(".", false);
399
if (version_array.size() != 4 || !version_array[0].is_valid_int() ||
400
!version_array[1].is_valid_int() || !version_array[2].is_valid_int() ||
401
!version_array[3].is_valid_int() || product_version.contains_char('-')) {
402
return TTR("Invalid product version.");
403
}
404
}
405
}
406
}
407
return EditorExportPlatformPC::get_export_option_warning(p_preset, p_name);
408
}
409
410
bool EditorExportPlatformWindows::get_export_option_visibility(const EditorExportPreset *p_preset, const String &p_option) const {
411
if (p_preset == nullptr) {
412
return true;
413
}
414
415
// This option is not supported by "osslsigncode", used on non-Windows host.
416
if (!OS::get_singleton()->has_feature("windows") && p_option == "codesign/identity_type") {
417
return false;
418
}
419
420
bool advanced_options_enabled = p_preset->are_advanced_options_enabled();
421
422
// Hide codesign.
423
bool codesign = p_preset->get("codesign/enable");
424
if (!codesign && p_option != "codesign/enable" && p_option.begins_with("codesign/")) {
425
return false;
426
}
427
428
// Hide resources.
429
bool mod_res = p_preset->get("application/modify_resources");
430
if (!mod_res && p_option != "application/modify_resources" && p_option != "application/export_angle" && p_option != "application/export_d3d12" && p_option != "application/d3d12_agility_sdk_multiarch" && p_option.begins_with("application/")) {
431
return false;
432
}
433
434
// Hide SSH options.
435
bool ssh = p_preset->get("ssh_remote_deploy/enabled");
436
if (!ssh && p_option != "ssh_remote_deploy/enabled" && p_option.begins_with("ssh_remote_deploy/")) {
437
return false;
438
}
439
440
if (p_option == "dotnet/embed_build_outputs" ||
441
p_option == "custom_template/debug" ||
442
p_option == "custom_template/release" ||
443
p_option == "application/d3d12_agility_sdk_multiarch" ||
444
p_option == "application/export_angle" ||
445
p_option == "application/export_d3d12" ||
446
p_option == "application/icon_interpolation") {
447
return advanced_options_enabled;
448
}
449
return true;
450
}
451
452
void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_options) const {
453
EditorExportPlatformPC::get_export_options(r_options);
454
455
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "binary_format/architecture", PROPERTY_HINT_ENUM, "x86_64,x86_32,arm64"), "x86_64"));
456
457
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/enable"), false, true));
458
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/identity_type", PROPERTY_HINT_ENUM, "Select automatically,Use PKCS12 file (specify *.PFX/*.P12 file),Use certificate store (specify SHA-1 hash)", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), 0));
459
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_GLOBAL_FILE, "*.pfx,*.p12", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
460
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/password", PROPERTY_HINT_PASSWORD, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SECRET), ""));
461
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true));
462
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/timestamp_server_url"), ""));
463
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/digest_algorithm", PROPERTY_HINT_ENUM, "SHA1,SHA256"), 1));
464
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/description"), ""));
465
r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
466
467
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/modify_resources"), true, true));
468
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.ico,*.png,*.webp,*.svg"), "", false, true));
469
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/console_wrapper_icon", PROPERTY_HINT_FILE, "*.ico,*.png,*.webp,*.svg"), ""));
470
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
471
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
472
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "Leave empty to use project version"), ""));
473
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/company_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Company Name"), ""));
474
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/product_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
475
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_description"), ""));
476
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
477
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/trademarks"), ""));
478
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_angle", PROPERTY_HINT_ENUM, "Auto,Yes,No"), 0, true));
479
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/export_d3d12", PROPERTY_HINT_ENUM, "Auto,Yes,No"), 0, true));
480
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/d3d12_agility_sdk_multiarch"), true, true));
481
482
String run_script = "Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}'\n"
483
"$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}'\n"
484
"$trigger = New-ScheduledTaskTrigger -Once -At 00:00\n"
485
"$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries\n"
486
"$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings\n"
487
"Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true\n"
488
"Start-ScheduledTask -TaskName godot_remote_debug\n"
489
"while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 }\n"
490
"Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue";
491
492
String cleanup_script = "Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue\n"
493
"Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue\n"
494
"Remove-Item -Recurse -Force '{temp_dir}'";
495
496
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "ssh_remote_deploy/enabled"), false, true));
497
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/host"), "user@host_ip"));
498
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/port"), "22"));
499
500
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_ssh", PROPERTY_HINT_MULTILINE_TEXT), ""));
501
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/extra_args_scp", PROPERTY_HINT_MULTILINE_TEXT), ""));
502
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/run_script", PROPERTY_HINT_MULTILINE_TEXT), run_script));
503
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "ssh_remote_deploy/cleanup_script", PROPERTY_HINT_MULTILINE_TEXT), cleanup_script));
504
}
505
506
Error EditorExportPlatformWindows::_add_data(const Ref<EditorExportPreset> &p_preset, const String &p_path, bool p_console_icon) {
507
String icon_path;
508
if (p_preset->get("application/icon") != "") {
509
icon_path = p_preset->get("application/icon");
510
} else if (get_project_setting(p_preset, "application/config/windows_native_icon") != "") {
511
icon_path = get_project_setting(p_preset, "application/config/windows_native_icon");
512
} else {
513
icon_path = get_project_setting(p_preset, "application/config/icon");
514
}
515
icon_path = ProjectSettings::get_singleton()->globalize_path(icon_path);
516
517
if (p_console_icon) {
518
String console_icon_path = ProjectSettings::get_singleton()->globalize_path(p_preset->get("application/console_wrapper_icon"));
519
if (!console_icon_path.is_empty() && FileAccess::exists(console_icon_path)) {
520
icon_path = console_icon_path;
521
}
522
}
523
524
String tmp_icon_path = EditorPaths::get_singleton()->get_temp_dir().path_join("_tmp.ico");
525
if (!icon_path.is_empty()) {
526
if (_process_icon(p_preset, icon_path, tmp_icon_path) != OK) {
527
add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Invalid icon file \"%s\"."), icon_path));
528
icon_path = String();
529
}
530
}
531
532
TemplateModifier::modify(p_preset, p_path, tmp_icon_path);
533
534
if (FileAccess::exists(tmp_icon_path)) {
535
DirAccess::remove_file_or_error(tmp_icon_path);
536
}
537
538
return OK;
539
}
540
541
Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path) {
542
List<String> args;
543
544
#ifdef WINDOWS_ENABLED
545
String signtool_path = EDITOR_GET("export/windows/signtool");
546
if (!signtool_path.is_empty() && !FileAccess::exists(signtool_path)) {
547
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Could not find signtool executable at \"%s\"."), signtool_path));
548
return ERR_FILE_NOT_FOUND;
549
}
550
if (signtool_path.is_empty()) {
551
signtool_path = "signtool"; // try to run signtool from PATH
552
}
553
#else
554
String signtool_path = EDITOR_GET("export/windows/osslsigncode");
555
if (!signtool_path.is_empty() && !FileAccess::exists(signtool_path)) {
556
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Could not find osslsigncode executable at \"%s\"."), signtool_path));
557
return ERR_FILE_NOT_FOUND;
558
}
559
if (signtool_path.is_empty()) {
560
signtool_path = "osslsigncode"; // try to run signtool from PATH
561
}
562
#endif
563
564
args.push_back("sign");
565
566
//identity
567
#ifdef WINDOWS_ENABLED
568
int id_type = p_preset->get_or_env("codesign/identity_type", ENV_WIN_CODESIGN_ID_TYPE);
569
if (id_type == 0) { //auto select
570
args.push_back("/a");
571
} else if (id_type == 1) { //pkcs12
572
if (p_preset->get_or_env("codesign/identity", ENV_WIN_CODESIGN_ID) != "") {
573
args.push_back("/f");
574
args.push_back(p_preset->get_or_env("codesign/identity", ENV_WIN_CODESIGN_ID));
575
} else {
576
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
577
return FAILED;
578
}
579
} else if (id_type == 2) { //Windows certificate store
580
if (p_preset->get_or_env("codesign/identity", ENV_WIN_CODESIGN_ID) != "") {
581
args.push_back("/sha1");
582
args.push_back(p_preset->get_or_env("codesign/identity", ENV_WIN_CODESIGN_ID));
583
} else {
584
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
585
return FAILED;
586
}
587
} else {
588
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Invalid identity type."));
589
return FAILED;
590
}
591
#else
592
int id_type = 1;
593
if (p_preset->get_or_env("codesign/identity", ENV_WIN_CODESIGN_ID) != "") {
594
args.push_back("-pkcs12");
595
args.push_back(p_preset->get_or_env("codesign/identity", ENV_WIN_CODESIGN_ID));
596
} else {
597
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("No identity found."));
598
return FAILED;
599
}
600
#endif
601
602
//password
603
if ((id_type == 1) && (p_preset->get_or_env("codesign/password", ENV_WIN_CODESIGN_PASS) != "")) {
604
#ifdef WINDOWS_ENABLED
605
args.push_back("/p");
606
#else
607
args.push_back("-pass");
608
#endif
609
args.push_back(p_preset->get_or_env("codesign/password", ENV_WIN_CODESIGN_PASS));
610
}
611
612
//timestamp
613
if (p_preset->get("codesign/timestamp")) {
614
if (p_preset->get("codesign/timestamp_server") != "") {
615
#ifdef WINDOWS_ENABLED
616
args.push_back("/tr");
617
args.push_back(p_preset->get("codesign/timestamp_server_url"));
618
args.push_back("/td");
619
if ((int)p_preset->get("codesign/digest_algorithm") == 0) {
620
args.push_back("sha1");
621
} else {
622
args.push_back("sha256");
623
}
624
#else
625
args.push_back("-ts");
626
args.push_back(p_preset->get("codesign/timestamp_server_url"));
627
#endif
628
} else {
629
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Invalid timestamp server."));
630
return FAILED;
631
}
632
}
633
634
//digest
635
#ifdef WINDOWS_ENABLED
636
args.push_back("/fd");
637
#else
638
args.push_back("-h");
639
#endif
640
if ((int)p_preset->get("codesign/digest_algorithm") == 0) {
641
args.push_back("sha1");
642
} else {
643
args.push_back("sha256");
644
}
645
646
//description
647
if (p_preset->get("codesign/description") != "") {
648
#ifdef WINDOWS_ENABLED
649
args.push_back("/d");
650
#else
651
args.push_back("-n");
652
#endif
653
args.push_back(p_preset->get("codesign/description"));
654
}
655
656
//user options
657
PackedStringArray user_args = p_preset->get("codesign/custom_options");
658
for (int i = 0; i < user_args.size(); i++) {
659
String user_arg = user_args[i].strip_edges();
660
if (!user_arg.is_empty()) {
661
args.push_back(user_arg);
662
}
663
}
664
665
#ifndef WINDOWS_ENABLED
666
args.push_back("-in");
667
#endif
668
args.push_back(p_path);
669
#ifndef WINDOWS_ENABLED
670
args.push_back("-out");
671
args.push_back(p_path + "_signed");
672
#endif
673
674
String str;
675
Error err = OS::get_singleton()->execute(signtool_path, args, &str, nullptr, true);
676
if (err != OK || str.contains("not found") || str.contains("not recognized")) {
677
#ifdef WINDOWS_ENABLED
678
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start signtool executable. Configure signtool path in the Editor Settings (Export > Windows > signtool), or disable \"Codesign\" in the export preset."));
679
#else
680
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start osslsigncode executable. Configure signtool path in the Editor Settings (Export > Windows > osslsigncode), or disable \"Codesign\" in the export preset."));
681
#endif
682
return err;
683
}
684
685
print_line("codesign (" + p_path + "): " + str);
686
#ifndef WINDOWS_ENABLED
687
if (str.contains("SignTool Error")) {
688
#else
689
if (str.contains("Failed")) {
690
#endif
691
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Signtool failed to sign executable: %s."), str));
692
return FAILED;
693
}
694
695
#ifndef WINDOWS_ENABLED
696
Ref<DirAccess> tmp_dir = DirAccess::create_for_path(p_path.get_base_dir());
697
698
err = tmp_dir->remove(p_path);
699
if (err != OK) {
700
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Failed to remove temporary file \"%s\"."), p_path));
701
return err;
702
}
703
704
err = tmp_dir->rename(p_path + "_signed", p_path);
705
if (err != OK) {
706
add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), vformat(TTR("Failed to rename temporary file \"%s\"."), p_path + "_signed"));
707
return err;
708
}
709
#endif
710
711
return OK;
712
}
713
714
bool EditorExportPlatformWindows::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates, bool p_debug) const {
715
String err;
716
bool valid = EditorExportPlatformPC::has_valid_export_configuration(p_preset, err, r_missing_templates, p_debug);
717
718
String custom_debug = p_preset->get("custom_template/debug").operator String().strip_edges();
719
String custom_release = p_preset->get("custom_template/release").operator String().strip_edges();
720
String arch = p_preset->get("binary_format/architecture");
721
722
if (!custom_debug.is_empty() && FileAccess::exists(custom_debug)) {
723
String exe_arch = _get_exe_arch(custom_debug);
724
if (arch != exe_arch) {
725
err += vformat(TTR("Mismatching custom debug export template executable architecture: found \"%s\", expected \"%s\"."), exe_arch, arch) + "\n";
726
}
727
}
728
if (!custom_release.is_empty() && FileAccess::exists(custom_release)) {
729
String exe_arch = _get_exe_arch(custom_release);
730
if (arch != exe_arch) {
731
err += vformat(TTR("Mismatching custom release export template executable architecture: found \"%s\", expected \"%s\"."), exe_arch, arch) + "\n";
732
}
733
}
734
735
if (!err.is_empty()) {
736
r_error = err;
737
}
738
739
return valid;
740
}
741
742
bool EditorExportPlatformWindows::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
743
String err;
744
bool valid = true;
745
746
List<ExportOption> options;
747
get_export_options(&options);
748
for (const EditorExportPlatform::ExportOption &E : options) {
749
if (get_export_option_visibility(p_preset.ptr(), E.option.name)) {
750
String warn = get_export_option_warning(p_preset.ptr(), E.option.name);
751
if (!warn.is_empty()) {
752
err += warn + "\n";
753
if (E.required) {
754
valid = false;
755
}
756
}
757
}
758
}
759
760
if (!err.is_empty()) {
761
r_error = err;
762
}
763
764
return valid;
765
}
766
767
String EditorExportPlatformWindows::_get_exe_arch(const String &p_path) const {
768
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
769
if (f.is_null()) {
770
return "invalid";
771
}
772
773
// Jump to the PE header and check the magic number.
774
{
775
f->seek(0x3c);
776
uint32_t pe_pos = f->get_32();
777
778
f->seek(pe_pos);
779
uint32_t magic = f->get_32();
780
if (magic != 0x00004550) {
781
return "invalid";
782
}
783
}
784
785
// Process header.
786
uint16_t machine = f->get_16();
787
f->close();
788
789
switch (machine) {
790
case 0x014c:
791
return "x86_32";
792
case 0x8664:
793
return "x86_64";
794
case 0x01c0:
795
case 0x01c4:
796
return "arm32";
797
case 0xaa64:
798
return "arm64";
799
default:
800
return "unknown";
801
}
802
}
803
804
Error EditorExportPlatformWindows::fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) {
805
// Patch the header of the "pck" section in the PE file so that it corresponds to the embedded data
806
807
if (p_embedded_size + p_embedded_start >= 0x100000000) { // Check for total executable size
808
add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Windows executables cannot be >= 4 GiB."));
809
return ERR_INVALID_DATA;
810
}
811
812
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ_WRITE);
813
if (f.is_null()) {
814
add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), vformat(TTR("Failed to open executable file \"%s\"."), p_path));
815
return ERR_CANT_OPEN;
816
}
817
818
// Jump to the PE header and check the magic number
819
{
820
f->seek(0x3c);
821
uint32_t pe_pos = f->get_32();
822
823
f->seek(pe_pos);
824
uint32_t magic = f->get_32();
825
if (magic != 0x00004550) {
826
add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable file header corrupted."));
827
return ERR_FILE_CORRUPT;
828
}
829
}
830
831
// Process header
832
833
int num_sections;
834
{
835
int64_t header_pos = f->get_position();
836
837
f->seek(header_pos + 2);
838
num_sections = f->get_16();
839
f->seek(header_pos + 16);
840
uint16_t opt_header_size = f->get_16();
841
842
// Skip rest of header + optional header to go to the section headers
843
f->seek(f->get_position() + 2 + opt_header_size);
844
}
845
846
// Search for the "pck" section
847
848
int64_t section_table_pos = f->get_position();
849
850
bool found = false;
851
for (int i = 0; i < num_sections; ++i) {
852
int64_t section_header_pos = section_table_pos + i * 40;
853
f->seek(section_header_pos);
854
855
uint8_t section_name[9];
856
f->get_buffer(section_name, 8);
857
section_name[8] = '\0';
858
859
if (strcmp((char *)section_name, "pck") == 0) {
860
// "pck" section found, let's patch!
861
862
// Set virtual size to a little to avoid it taking memory (zero would give issues)
863
f->seek(section_header_pos + 8);
864
f->store_32(8);
865
866
f->seek(section_header_pos + 16);
867
f->store_32(p_embedded_size);
868
f->seek(section_header_pos + 20);
869
f->store_32(p_embedded_start);
870
871
found = true;
872
break;
873
}
874
}
875
876
if (!found) {
877
add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("Executable \"pck\" section not found."));
878
return ERR_FILE_CORRUPT;
879
}
880
return OK;
881
}
882
883
Ref<Texture2D> EditorExportPlatformWindows::get_run_icon() const {
884
return run_icon;
885
}
886
887
bool EditorExportPlatformWindows::poll_export() {
888
Ref<EditorExportPreset> preset;
889
890
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
891
Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
892
if (ep->is_runnable() && ep->get_platform() == this) {
893
preset = ep;
894
break;
895
}
896
}
897
898
int prev = menu_options;
899
menu_options = (preset.is_valid() && preset->get("ssh_remote_deploy/enabled").operator bool());
900
if (ssh_pid != 0 || !cleanup_commands.is_empty()) {
901
if (menu_options == 0) {
902
cleanup();
903
} else {
904
menu_options += 1;
905
}
906
}
907
return menu_options != prev;
908
}
909
910
Ref<Texture2D> EditorExportPlatformWindows::get_option_icon(int p_index) const {
911
if (p_index == 1) {
912
return stop_icon;
913
} else {
914
return EditorExportPlatform::get_option_icon(p_index);
915
}
916
}
917
918
int EditorExportPlatformWindows::get_options_count() const {
919
return menu_options;
920
}
921
922
String EditorExportPlatformWindows::get_option_label(int p_index) const {
923
return (p_index) ? TTR("Stop and uninstall") : TTR("Run on remote Windows system");
924
}
925
926
String EditorExportPlatformWindows::get_option_tooltip(int p_index) const {
927
return (p_index) ? TTR("Stop and uninstall running project from the remote system") : TTR("Run exported project on remote Windows system");
928
}
929
930
void EditorExportPlatformWindows::cleanup() {
931
if (ssh_pid != 0 && OS::get_singleton()->is_process_running(ssh_pid)) {
932
print_line("Terminating connection...");
933
OS::get_singleton()->kill(ssh_pid);
934
OS::get_singleton()->delay_usec(1000);
935
}
936
937
if (!cleanup_commands.is_empty()) {
938
print_line("Stopping and deleting previous version...");
939
for (const SSHCleanupCommand &cmd : cleanup_commands) {
940
if (cmd.wait) {
941
ssh_run_on_remote(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
942
} else {
943
ssh_run_on_remote_no_wait(cmd.host, cmd.port, cmd.ssh_args, cmd.cmd_args);
944
}
945
}
946
}
947
ssh_pid = 0;
948
cleanup_commands.clear();
949
}
950
951
Error EditorExportPlatformWindows::run(const Ref<EditorExportPreset> &p_preset, int p_device, BitField<EditorExportPlatform::DebugFlags> p_debug_flags) {
952
cleanup();
953
if (p_device) { // Stop command, cleanup only.
954
return OK;
955
}
956
957
EditorProgress ep("run", TTR("Running..."), 5);
958
959
const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("windows");
960
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
961
if (!da->dir_exists(dest)) {
962
Error err = da->make_dir_recursive(dest);
963
if (err != OK) {
964
EditorNode::get_singleton()->show_warning(TTR("Could not create temp directory:") + "\n" + dest);
965
return err;
966
}
967
}
968
969
String host = p_preset->get("ssh_remote_deploy/host").operator String();
970
String port = p_preset->get("ssh_remote_deploy/port").operator String();
971
if (port.is_empty()) {
972
port = "22";
973
}
974
Vector<String> extra_args_ssh = p_preset->get("ssh_remote_deploy/extra_args_ssh").operator String().split(" ", false);
975
Vector<String> extra_args_scp = p_preset->get("ssh_remote_deploy/extra_args_scp").operator String().split(" ", false);
976
977
const String basepath = dest.path_join("tmp_windows_export");
978
979
#define CLEANUP_AND_RETURN(m_err) \
980
{ \
981
if (da->file_exists(basepath + ".zip")) { \
982
da->remove(basepath + ".zip"); \
983
} \
984
if (da->file_exists(basepath + "_start.ps1")) { \
985
da->remove(basepath + "_start.ps1"); \
986
} \
987
if (da->file_exists(basepath + "_clean.ps1")) { \
988
da->remove(basepath + "_clean.ps1"); \
989
} \
990
return m_err; \
991
} \
992
((void)0)
993
994
if (ep.step(TTR("Exporting project..."), 1)) {
995
return ERR_SKIP;
996
}
997
Error err = export_project(p_preset, true, basepath + ".zip", p_debug_flags);
998
if (err != OK) {
999
DirAccess::remove_file_or_error(basepath + ".zip");
1000
return err;
1001
}
1002
1003
String cmd_args;
1004
{
1005
Vector<String> cmd_args_list = gen_export_flags(p_debug_flags);
1006
for (int i = 0; i < cmd_args_list.size(); i++) {
1007
if (i != 0) {
1008
cmd_args += " ";
1009
}
1010
cmd_args += cmd_args_list[i];
1011
}
1012
}
1013
1014
const bool use_remote = p_debug_flags.has_flag(DEBUG_FLAG_REMOTE_DEBUG) || p_debug_flags.has_flag(DEBUG_FLAG_DUMB_CLIENT);
1015
int dbg_port = EDITOR_GET("network/debug/remote_port");
1016
1017
print_line("Creating temporary directory...");
1018
ep.step(TTR("Creating temporary directory..."), 2);
1019
String temp_dir;
1020
#ifndef WINDOWS_ENABLED
1021
err = ssh_run_on_remote(host, port, extra_args_ssh, "powershell -command \\\"\\$tmp = Join-Path \\$Env:Temp \\$(New-Guid); New-Item -Type Directory -Path \\$tmp | Out-Null; Write-Output \\$tmp\\\"", &temp_dir);
1022
#else
1023
err = ssh_run_on_remote(host, port, extra_args_ssh, "powershell -command \"$tmp = Join-Path $Env:Temp $(New-Guid); New-Item -Type Directory -Path $tmp ^| Out-Null; Write-Output $tmp\"", &temp_dir);
1024
#endif
1025
if (err != OK || temp_dir.is_empty()) {
1026
CLEANUP_AND_RETURN(err);
1027
}
1028
1029
print_line("Uploading archive...");
1030
ep.step(TTR("Uploading archive..."), 3);
1031
err = ssh_push_to_remote(host, port, extra_args_scp, basepath + ".zip", temp_dir);
1032
if (err != OK) {
1033
CLEANUP_AND_RETURN(err);
1034
}
1035
1036
if (cmd_args.is_empty()) {
1037
cmd_args = " ";
1038
}
1039
1040
{
1041
String run_script = p_preset->get("ssh_remote_deploy/run_script");
1042
run_script = run_script.replace("{temp_dir}", temp_dir);
1043
run_script = run_script.replace("{archive_name}", basepath.get_file() + ".zip");
1044
run_script = run_script.replace("{exe_name}", basepath.get_file() + ".exe");
1045
run_script = run_script.replace("{cmd_args}", cmd_args);
1046
1047
Ref<FileAccess> f = FileAccess::open(basepath + "_start.ps1", FileAccess::WRITE);
1048
if (f.is_null()) {
1049
CLEANUP_AND_RETURN(err);
1050
}
1051
1052
f->store_string(run_script);
1053
}
1054
1055
{
1056
String clean_script = p_preset->get("ssh_remote_deploy/cleanup_script");
1057
clean_script = clean_script.replace("{temp_dir}", temp_dir);
1058
clean_script = clean_script.replace("{archive_name}", basepath.get_file() + ".zip");
1059
clean_script = clean_script.replace("{exe_name}", basepath.get_file() + ".exe");
1060
clean_script = clean_script.replace("{cmd_args}", cmd_args);
1061
1062
Ref<FileAccess> f = FileAccess::open(basepath + "_clean.ps1", FileAccess::WRITE);
1063
if (f.is_null()) {
1064
CLEANUP_AND_RETURN(err);
1065
}
1066
1067
f->store_string(clean_script);
1068
}
1069
1070
print_line("Uploading scripts...");
1071
ep.step(TTR("Uploading scripts..."), 4);
1072
err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_start.ps1", temp_dir);
1073
if (err != OK) {
1074
CLEANUP_AND_RETURN(err);
1075
}
1076
err = ssh_push_to_remote(host, port, extra_args_scp, basepath + "_clean.ps1", temp_dir);
1077
if (err != OK) {
1078
CLEANUP_AND_RETURN(err);
1079
}
1080
1081
print_line("Starting project...");
1082
ep.step(TTR("Starting project..."), 5);
1083
err = ssh_run_on_remote_no_wait(host, port, extra_args_ssh, vformat("powershell -file \"%s\\%s\"", temp_dir, basepath.get_file() + "_start.ps1"), &ssh_pid, (use_remote) ? dbg_port : -1);
1084
if (err != OK) {
1085
CLEANUP_AND_RETURN(err);
1086
}
1087
1088
cleanup_commands.clear();
1089
cleanup_commands.push_back(SSHCleanupCommand(host, port, extra_args_ssh, vformat("powershell -file \"%s\\%s\"", temp_dir, basepath.get_file() + "_clean.ps1")));
1090
1091
print_line("Project started.");
1092
1093
CLEANUP_AND_RETURN(OK);
1094
#undef CLEANUP_AND_RETURN
1095
}
1096
1097
EditorExportPlatformWindows::EditorExportPlatformWindows() {
1098
if (EditorNode::get_singleton()) {
1099
Ref<Image> img = memnew(Image);
1100
const bool upsample = !Math::is_equal_approx(Math::round(EDSCALE), EDSCALE);
1101
1102
ImageLoaderSVG::create_image_from_string(img, _windows_logo_svg, EDSCALE, upsample, false);
1103
set_logo(ImageTexture::create_from_image(img));
1104
1105
ImageLoaderSVG::create_image_from_string(img, _windows_run_icon_svg, EDSCALE, upsample, false);
1106
run_icon = ImageTexture::create_from_image(img);
1107
1108
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
1109
if (theme.is_valid()) {
1110
stop_icon = theme->get_icon(SNAME("Stop"), EditorStringName(EditorIcons));
1111
} else {
1112
stop_icon.instantiate();
1113
}
1114
}
1115
}
1116
1117