[iOS Export] Check directory content before deleting old export leftovers.

This commit is contained in:
bruvzg 2024-03-22 10:40:36 +02:00
parent fe01776f05
commit b3043674f6
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
2 changed files with 63 additions and 6 deletions

View File

@ -29,6 +29,9 @@
<member name="application/code_sign_identity_release" type="String" setter="" getter="">
The "Full Name", "Common Name" or SHA-1 hash of the signing identity used for release export.
</member>
<member name="application/delete_old_export_files_unconditionally" type="bool" setter="" getter="">
If [code]true[/code], existing "project name" and "project name.xcodeproj" in the export destination directory will be unconditionally deleted during export.
</member>
<member name="application/export_method_debug" type="int" setter="" getter="">
Application distribution target (debug export).
</member>

View File

@ -170,6 +170,7 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options)
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "application/icon_interpolation", PROPERTY_HINT_ENUM, "Nearest neighbor,Bilinear,Cubic,Trilinear,Lanczos"), 4));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/export_project_only"), false));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "application/delete_old_export_files_unconditionally"), false));
Vector<PluginConfigIOS> found_plugins = get_plugins();
for (int i = 0; i < found_plugins.size(); i++) {
@ -1627,19 +1628,72 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres
}
{
bool delete_old = p_preset->get("application/delete_old_export_files_unconditionally");
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
if (da.is_valid()) {
String current_dir = da->get_current_dir();
// remove leftovers from last export so they don't interfere
// in case some files are no longer needed
// Remove leftovers from last export so they don't interfere in case some files are no longer needed.
if (da->change_dir(binary_dir + ".xcodeproj") == OK) {
da->erase_contents_recursive();
}
if (da->change_dir(binary_dir) == OK) {
da->erase_contents_recursive();
// Check directory content before deleting.
int expected_files = 0;
int total_files = 0;
if (!delete_old) {
da->list_dir_begin();
for (String n = da->get_next(); !n.is_empty(); n = da->get_next()) {
if (!n.begins_with(".")) { // Ignore ".", ".." and hidden files.
if (da->current_is_dir()) {
if (n == "xcshareddata" || n == "project.xcworkspace") {
expected_files++;
}
} else {
if (n == "project.pbxproj") {
expected_files++;
}
}
total_files++;
}
}
da->list_dir_end();
}
if ((total_files == 0) || (expected_files >= Math::floor(total_files * 0.8))) {
da->erase_contents_recursive();
} else {
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Unexpected files found in the export destination directory \"%s.xcodeproj\", delete it manually or select another destination."), binary_dir));
return ERR_CANT_CREATE;
}
}
da->change_dir(current_dir);
if (da->change_dir(binary_dir) == OK) {
// Check directory content before deleting.
int expected_files = 0;
int total_files = 0;
if (!delete_old) {
da->list_dir_begin();
for (String n = da->get_next(); !n.is_empty(); n = da->get_next()) {
if (!n.begins_with(".")) { // Ignore ".", ".." and hidden files.
if (da->current_is_dir()) {
if (n == "dylibs" || n == "Images.xcassets" || n.ends_with(".lproj") || n == "godot-publish-dotnet" || n.ends_with(".xcframework") || n.ends_with(".framework")) {
expected_files++;
}
} else {
if (n == binary_name + "-Info.plist" || n == binary_name + ".entitlements" || n == "Launch Screen.storyboard" || n == "export_options.plist" || n.begins_with("dummy.") || n.ends_with(".gdip")) {
expected_files++;
}
}
total_files++;
}
}
da->list_dir_end();
}
if ((total_files == 0) || (expected_files >= Math::floor(total_files * 0.8))) {
da->erase_contents_recursive();
} else {
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Unexpected files found in the export destination directory \"%s\", delete it manually or select another destination."), binary_dir));
return ERR_CANT_CREATE;
}
}
da->change_dir(current_dir);
if (!da->dir_exists(binary_dir)) {