diff options
Diffstat (limited to 'platform/macos/export')
-rw-r--r-- | platform/macos/export/export_plugin.cpp | 149 | ||||
-rw-r--r-- | platform/macos/export/export_plugin.h | 2 | ||||
-rw-r--r-- | platform/macos/export/plist.cpp | 292 | ||||
-rw-r--r-- | platform/macos/export/plist.h | 25 |
4 files changed, 432 insertions, 36 deletions
diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index de6016cb9b..49c8c7758d 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -34,6 +34,7 @@ #include "lipo.h" #include "macho.h" +#include "core/io/image_loader.h" #include "core/string/translation.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" @@ -90,11 +91,14 @@ bool EditorExportPlatformMacOS::get_export_option_visibility(const EditorExportP return false; } } break; - case 2: { // "altool" + case 2: { // "notarytool" + // All options are visible. + } break; + case 3: { // "altool" // All options are visible. } break; default: { // disabled - if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/apple_team_id" || p_option == "notarization/api_uuid" || p_option == "notarization/api_key") { + if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/apple_team_id" || p_option == "notarization/api_uuid" || p_option == "notarization/api_key" || p_option == "notarization/api_key_id") { return false; } } break; @@ -116,7 +120,8 @@ void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "debug/export_console_script", PROPERTY_HINT_ENUM, "No,Debug Only,Debug and Release"), 1)); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.png,*.icns"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.icns,*.png,*.webp,*.svg"), "")); + 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::STRING, "application/bundle_identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/app_category", PROPERTY_HINT_ENUM, "Business,Developer-tools,Education,Entertainment,Finance,Games,Action-games,Adventure-games,Arcade-games,Board-games,Card-games,Casino-games,Dice-games,Educational-games,Family-games,Kids-games,Music-games,Puzzle-games,Racing-games,Role-playing-games,Simulation-games,Sports-games,Strategy-games,Trivia-games,Word-games,Graphics-design,Healthcare-fitness,Lifestyle,Medical,Music,News,Photography,Productivity,Reference,Social-networking,Sports,Travel,Utilities,Video,Weather"), "Games")); @@ -127,9 +132,9 @@ void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false)); #ifdef MACOS_ENABLED - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),PyOxidizer rcodesign,Xcode codesign"), 3, true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign,Xcode codesign"), 3, true)); #else - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),PyOxidizer rcodesign"), 1, true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign"), 1, true)); #endif // "codesign" only options: r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), "")); @@ -163,17 +168,18 @@ void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray())); #ifdef MACOS_ENABLED - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,PyOxidizer rcodesign,Xcode altool"), 0, true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign,Xcode notarytool,Xcode altool (deprecated)"), 0, true)); #else - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,PyOxidizer rcodesign"), 0, true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign"), 0, true)); #endif - // "altool" only options: + // "altool" and "notarytool" only options: r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_password", PROPERTY_HINT_PASSWORD, "Enable two-factor authentication and provide app-specific password"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide team ID if your Apple ID belongs to multiple teams"), "")); - // "altool" and "rcodesign" only options: - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_uuid", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect issuer ID"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect API key ID"), "")); + // "altool", "notarytool" and "rcodesign" only options: + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_uuid", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect issuer ID UUID"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_GLOBAL_FILE, "*.p8"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect API key ID"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the microphone"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); @@ -268,7 +274,7 @@ void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, memcpy(&p_dest.write[ofs], result.ptr(), res_size); } -void EditorExportPlatformMacOS::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) { +void EditorExportPlatformMacOS::_make_icon(const Ref<EditorExportPreset> &p_preset, const Ref<Image> &p_icon, Vector<uint8_t> &p_data) { Ref<ImageTexture> it = memnew(ImageTexture); Vector<uint8_t> data; @@ -302,7 +308,7 @@ void EditorExportPlatformMacOS::_make_icon(const Ref<Image> &p_icon, Vector<uint for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) { Ref<Image> copy = p_icon; // does this make sense? doesn't this just increase the reference count instead of making a copy? Do we even need a copy? copy->convert(Image::FORMAT_RGBA8); - copy->resize(icon_infos[i].size, icon_infos[i].size); + copy->resize(icon_infos[i].size, icon_infos[i].size, (Image::Interpolation)(p_preset->get("application/icon_interpolation").operator int())); if (icon_infos[i].is_png) { // Encode PNG icon. @@ -496,7 +502,12 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres args.push_back(p_preset->get("notarization/api_uuid")); args.push_back("--api-key"); - args.push_back(p_preset->get("notarization/api_key")); + args.push_back(p_preset->get("notarization/api_key_id")); + + if (!p_preset->get("notarization/api_key").operator String().is_empty()) { + args.push_back("--api-key-path"); + args.push_back(p_preset->get("notarization/api_key")); + } args.push_back(p_path); @@ -517,7 +528,7 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres } else { print_verbose("rcodesign (" + p_path + "):\n" + str); int next_nl = str.find("\n", rq_offset); - String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 14, -1) : str.substr(rq_offset + 14, next_nl - rq_offset - 14); + String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 23, -1) : str.substr(rq_offset + 23, next_nl - rq_offset - 23); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour.")); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:")); @@ -527,7 +538,91 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres } } break; #ifdef MACOS_ENABLED - case 2: { // "altool" + case 2: { // "notarytool" + print_verbose("using notarytool notarization..."); + + if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed.")); + return Error::FAILED; + } + + List<String> args; + + args.push_back("notarytool"); + args.push_back("submit"); + + args.push_back(p_path); + + if (p_preset->get("notarization/apple_id_name") == "" && p_preset->get("notarization/api_uuid") == "") { + add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified.")); + return Error::FAILED; + } + if (p_preset->get("notarization/apple_id_name") != "" && p_preset->get("notarization/api_uuid") != "") { + add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.")); + return Error::FAILED; + } + + if (p_preset->get("notarization/apple_id_name") != "") { + if (p_preset->get("notarization/apple_id_password") == "") { + add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified.")); + return Error::FAILED; + } + args.push_back("--apple-id"); + args.push_back(p_preset->get("notarization/apple_id_name")); + + args.push_back("--password"); + args.push_back(p_preset->get("notarization/apple_id_password")); + } else { + if (p_preset->get("notarization/api_key_id") == "") { + add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified.")); + return Error::FAILED; + } + args.push_back("--issuer"); + args.push_back(p_preset->get("notarization/api_uuid")); + + if (!p_preset->get("notarization/api_key").operator String().is_empty()) { + args.push_back("--key"); + args.push_back(p_preset->get("notarization/api_key")); + } + + args.push_back("--key-id"); + args.push_back(p_preset->get("notarization/api_key_id")); + } + + args.push_back("--no-progress"); + + if (p_preset->get("notarization/apple_team_id")) { + args.push_back("--team-id"); + args.push_back(p_preset->get("notarization/apple_team_id")); + } + + String str; + int exitcode = 0; + Error err = OS::get_singleton()->execute("xcrun", args, &str, &exitcode, true); + if (err != OK) { + add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable.")); + return err; + } + + int rq_offset = str.find("id:"); + if (exitcode != 0 || rq_offset == -1) { + print_line("notarytool (" + p_path + "):\n" + str); + add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details.")); + return Error::FAILED; + } else { + print_verbose("notarytool (" + p_path + "):\n" + str); + int next_nl = str.find("\n", rq_offset); + String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 4, -1) : str.substr(rq_offset + 4, next_nl - rq_offset - 4); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour.")); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:")); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request uuid> --issuer <api uuid> --key-id <api key id> --key <api key path>\" or"); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request uuid> --apple-id <your email> --password <app-specific pwd>>\""); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):")); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple <app path>\""); + } + } break; + case 3: { // "altool" print_verbose("using altool notarization..."); if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { @@ -571,7 +666,7 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres args.push_back(p_preset->get("notarization/api_uuid")); args.push_back("--apiKey"); - args.push_back(p_preset->get("notarization/api_key")); + args.push_back(p_preset->get("notarization/api_key_id")); } args.push_back("--type"); @@ -593,7 +688,7 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres return err; } - int rq_offset = str.find("RequestUUID"); + int rq_offset = str.find("RequestUUID:"); if (exitcode != 0 || rq_offset == -1) { print_line("xcrun altool (" + p_path + "):\n" + str); add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details.")); @@ -601,7 +696,7 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres } else { print_verbose("xcrun altool (" + p_path + "):\n" + str); int next_nl = str.find("\n", rq_offset); - String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 14, -1) : str.substr(rq_offset + 14, next_nl - rq_offset - 14); + String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 13, -1) : str.substr(rq_offset + 13, next_nl - rq_offset - 13); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour. When the process is completed, you'll receive an email.")); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:")); @@ -726,7 +821,7 @@ Error EditorExportPlatformMacOS::_code_sign(const Ref<EditorExportPreset> &p_pre String str; int exitcode = 0; - Error err = OS::get_singleton()->execute("codesign", args, &str, nullptr, true); + Error err = OS::get_singleton()->execute("codesign", args, &str, &exitcode, true); if (err != OK) { add_message(EXPORT_MESSAGE_WARNING, TTR("Code Signing"), TTR("Could not start codesign executable, make sure Xcode command line tools are installed.")); return err; @@ -1270,9 +1365,9 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p } else { Ref<Image> icon; icon.instantiate(); - icon->load(iconpath); - if (!icon->is_empty()) { - _make_icon(icon, data); + err = ImageLoader::load_image(iconpath, icon); + if (err == OK && !icon->is_empty()) { + _make_icon(p_preset, icon, data); } } } @@ -1817,7 +1912,7 @@ bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<Editor err += TTR("Notarization: Code signing is required for notarization.") + "\n"; valid = false; } - if (notary_tool == 2) { + if (notary_tool == 2 || notary_tool == 3) { if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { err += TTR("Notarization: Xcode command line tools are not installed.") + "\n"; valid = false; @@ -1832,11 +1927,11 @@ bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<Editor if (p_preset->get("notarization/apple_id_name") != "") { if (p_preset->get("notarization/apple_id_password") == "") { err += TTR("Notarization: Apple ID password not specified.") + "\n"; + valid = false; } - valid = false; } if (p_preset->get("notarization/api_uuid") != "") { - if (p_preset->get("notarization/api_key") == "") { + if (p_preset->get("notarization/api_key_id") == "") { err += TTR("Notarization: App Store Connect API key ID not specified.") + "\n"; valid = false; } @@ -1847,7 +1942,7 @@ bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<Editor err += TTR("Notarization: App Store Connect issuer ID name not specified.") + "\n"; valid = false; } - if (p_preset->get("notarization/api_key") == "") { + if (p_preset->get("notarization/api_key_id") == "") { err += TTR("Notarization: App Store Connect API key ID not specified.") + "\n"; valid = false; } diff --git a/platform/macos/export/export_plugin.h b/platform/macos/export/export_plugin.h index b6ad587caa..af7570c394 100644 --- a/platform/macos/export/export_plugin.h +++ b/platform/macos/export/export_plugin.h @@ -53,7 +53,7 @@ class EditorExportPlatformMacOS : public EditorExportPlatform { Ref<ImageTexture> logo; void _fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary); - void _make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data); + void _make_icon(const Ref<EditorExportPreset> &p_preset, const Ref<Image> &p_icon, Vector<uint8_t> &p_data); Error _notarize(const Ref<EditorExportPreset> &p_preset, const String &p_path); Error _code_sign(const Ref<EditorExportPreset> &p_preset, const String &p_path, const String &p_ent_path, bool p_warn = true); diff --git a/platform/macos/export/plist.cpp b/platform/macos/export/plist.cpp index cad014e65b..c88b6e1077 100644 --- a/platform/macos/export/plist.cpp +++ b/platform/macos/export/plist.cpp @@ -30,6 +30,119 @@ #include "plist.h" +PList::PLNodeType PListNode::get_type() const { + return data_type; +} + +Variant PListNode::get_value() const { + switch (data_type) { + case PList::PL_NODE_TYPE_NIL: { + return Variant(); + } break; + case PList::PL_NODE_TYPE_STRING: { + return String::utf8(data_string.get_data()); + } break; + case PList::PL_NODE_TYPE_ARRAY: { + Array arr; + for (const Ref<PListNode> &E : data_array) { + arr.push_back(E); + } + return arr; + } break; + case PList::PL_NODE_TYPE_DICT: { + Dictionary dict; + for (const KeyValue<String, Ref<PListNode>> &E : data_dict) { + dict[E.key] = E.value; + } + return dict; + } break; + case PList::PL_NODE_TYPE_BOOLEAN: { + return data_bool; + } break; + case PList::PL_NODE_TYPE_INTEGER: { + return data_int; + } break; + case PList::PL_NODE_TYPE_REAL: { + return data_real; + } break; + case PList::PL_NODE_TYPE_DATA: { + int strlen = data_string.length(); + + size_t arr_len = 0; + Vector<uint8_t> buf; + { + buf.resize(strlen / 4 * 3 + 1); + uint8_t *w = buf.ptrw(); + + ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &arr_len, (unsigned char *)data_string.get_data(), strlen) != OK, Vector<uint8_t>()); + } + buf.resize(arr_len); + return buf; + } break; + case PList::PL_NODE_TYPE_DATE: { + return String(data_string.get_data()); + } break; + } + return Variant(); +} + +Ref<PListNode> PListNode::new_node(const Variant &p_value) { + Ref<PListNode> node; + node.instantiate(); + + switch (p_value.get_type()) { + case Variant::NIL: { + node->data_type = PList::PL_NODE_TYPE_NIL; + } break; + case Variant::BOOL: { + node->data_type = PList::PL_NODE_TYPE_BOOLEAN; + node->data_bool = p_value; + } break; + case Variant::INT: { + node->data_type = PList::PL_NODE_TYPE_INTEGER; + node->data_int = p_value; + } break; + case Variant::FLOAT: { + node->data_type = PList::PL_NODE_TYPE_REAL; + node->data_real = p_value; + } break; + case Variant::STRING_NAME: + case Variant::STRING: { + node->data_type = PList::PL_NODE_TYPE_STRING; + node->data_string = p_value.operator String().utf8(); + } break; + case Variant::DICTIONARY: { + node->data_type = PList::PL_NODE_TYPE_DICT; + Dictionary dict = p_value; + const Variant *next = dict.next(nullptr); + while (next) { + Ref<PListNode> sub_node = dict[*next]; + ERR_FAIL_COND_V_MSG(sub_node.is_null(), Ref<PListNode>(), "Invalid dictionary element, should be PListNode."); + node->data_dict[*next] = sub_node; + next = dict.next(next); + } + } break; + case Variant::ARRAY: { + node->data_type = PList::PL_NODE_TYPE_ARRAY; + Array ar = p_value; + for (int i = 0; i < ar.size(); i++) { + Ref<PListNode> sub_node = ar[i]; + ERR_FAIL_COND_V_MSG(sub_node.is_null(), Ref<PListNode>(), "Invalid array element, should be PListNode."); + node->data_array.push_back(sub_node); + } + } break; + case Variant::PACKED_BYTE_ARRAY: { + node->data_type = PList::PL_NODE_TYPE_DATA; + PackedByteArray buf = p_value; + node->data_string = CryptoCore::b64_encode_str(buf.ptr(), buf.size()).utf8(); + } break; + default: { + ERR_FAIL_V_MSG(Ref<PListNode>(), "Unsupported data type."); + } break; + } + return node; +} + Ref<PListNode> PListNode::new_array() { Ref<PListNode> node = memnew(PListNode()); ERR_FAIL_COND_V(node.is_null(), Ref<PListNode>()); @@ -65,6 +178,7 @@ Ref<PListNode> PListNode::new_date(const String &p_string) { ERR_FAIL_COND_V(node.is_null(), Ref<PListNode>()); node->data_type = PList::PLNodeType::PL_NODE_TYPE_DATE; node->data_string = p_string.utf8(); + node->data_real = (double)Time::get_singleton()->get_unix_time_from_datetime_string(p_string) - 978307200.0; return node; } @@ -76,7 +190,7 @@ Ref<PListNode> PListNode::new_bool(bool p_bool) { return node; } -Ref<PListNode> PListNode::new_int(int32_t p_int) { +Ref<PListNode> PListNode::new_int(int64_t p_int) { Ref<PListNode> node = memnew(PListNode()); ERR_FAIL_COND_V(node.is_null(), Ref<PListNode>()); node->data_type = PList::PLNodeType::PL_NODE_TYPE_INTEGER; @@ -84,7 +198,7 @@ Ref<PListNode> PListNode::new_int(int32_t p_int) { return node; } -Ref<PListNode> PListNode::new_real(float p_real) { +Ref<PListNode> PListNode::new_real(double p_real) { Ref<PListNode> node = memnew(PListNode()); ERR_FAIL_COND_V(node.is_null(), Ref<PListNode>()); node->data_type = PList::PLNodeType::PL_NODE_TYPE_REAL; @@ -337,6 +451,168 @@ PList::PList(const String &p_string) { load_string(p_string); } +uint64_t PList::read_bplist_var_size_int(Ref<FileAccess> p_file, uint8_t p_size) { + uint64_t pos = p_file->get_position(); + uint64_t ret = 0; + switch (p_size) { + case 1: { + ret = p_file->get_8(); + } break; + case 2: { + ret = BSWAP16(p_file->get_16()); + } break; + case 3: { + ret = BSWAP32(p_file->get_32() & 0x00FFFFFF); + } break; + case 4: { + ret = BSWAP32(p_file->get_32()); + } break; + case 5: { + ret = BSWAP64(p_file->get_64() & 0x000000FFFFFFFFFF); + } break; + case 6: { + ret = BSWAP64(p_file->get_64() & 0x0000FFFFFFFFFFFF); + } break; + case 7: { + ret = BSWAP64(p_file->get_64() & 0x00FFFFFFFFFFFFFF); + } break; + case 8: { + ret = BSWAP64(p_file->get_64()); + } break; + default: { + ret = 0; + } + } + p_file->seek(pos + p_size); + + return ret; +} + +Ref<PListNode> PList::read_bplist_obj(Ref<FileAccess> p_file, uint64_t p_offset_idx) { + Ref<PListNode> node; + node.instantiate(); + + uint64_t ot_off = trailer.offset_table_start + p_offset_idx * trailer.offset_size; + p_file->seek(ot_off); + uint64_t marker_off = read_bplist_var_size_int(p_file, trailer.offset_size); + ERR_FAIL_COND_V_MSG(marker_off == 0, Ref<PListNode>(), "Invalid marker size."); + + p_file->seek(marker_off); + uint8_t marker = p_file->get_8(); + uint8_t marker_type = marker & 0xF0; + uint64_t marker_size = marker & 0x0F; + + switch (marker_type) { + case 0x00: { + if (marker_size == 0x00) { + node->data_type = PL_NODE_TYPE_NIL; + } else if (marker_size == 0x08) { + node->data_type = PL_NODE_TYPE_BOOLEAN; + node->data_bool = false; + } else if (marker_size == 0x09) { + node->data_type = PL_NODE_TYPE_BOOLEAN; + node->data_bool = true; + } else { + ERR_FAIL_V_MSG(Ref<PListNode>(), "Invalid nil/bool marker value."); + } + } break; + case 0x10: { + node->data_type = PL_NODE_TYPE_INTEGER; + node->data_int = static_cast<int64_t>(read_bplist_var_size_int(p_file, pow(2, marker_size))); + } break; + case 0x20: { + node->data_type = PL_NODE_TYPE_REAL; + node->data_int = static_cast<int64_t>(read_bplist_var_size_int(p_file, pow(2, marker_size))); + } break; + case 0x30: { + node->data_type = PL_NODE_TYPE_DATE; + node->data_int = BSWAP64(p_file->get_64()); + node->data_string = Time::get_singleton()->get_datetime_string_from_unix_time(node->data_real + 978307200.0).utf8(); + } break; + case 0x40: { + if (marker_size == 0x0F) { + uint8_t ext = p_file->get_8() & 0xF; + marker_size = read_bplist_var_size_int(p_file, pow(2, ext)); + } + node->data_type = PL_NODE_TYPE_DATA; + PackedByteArray buf; + buf.resize(marker_size + 1); + p_file->get_buffer(reinterpret_cast<uint8_t *>(buf.ptrw()), marker_size); + node->data_string = CryptoCore::b64_encode_str(buf.ptr(), buf.size()).utf8(); + } break; + case 0x50: { + if (marker_size == 0x0F) { + uint8_t ext = p_file->get_8() & 0xF; + marker_size = read_bplist_var_size_int(p_file, pow(2, ext)); + } + node->data_type = PL_NODE_TYPE_STRING; + node->data_string.resize(marker_size + 1); + p_file->get_buffer(reinterpret_cast<uint8_t *>(node->data_string.ptrw()), marker_size); + } break; + case 0x60: { + if (marker_size == 0x0F) { + uint8_t ext = p_file->get_8() & 0xF; + marker_size = read_bplist_var_size_int(p_file, pow(2, ext)); + } + Char16String cs16; + cs16.resize(marker_size + 1); + for (uint64_t i = 0; i < marker_size; i++) { + cs16[i] = BSWAP16(p_file->get_16()); + } + node->data_type = PL_NODE_TYPE_STRING; + node->data_string = String::utf16(cs16.ptr(), cs16.length()).utf8(); + } break; + case 0x80: { + node->data_type = PL_NODE_TYPE_INTEGER; + node->data_int = static_cast<int64_t>(read_bplist_var_size_int(p_file, marker_size + 1)); + } break; + case 0xA0: + case 0xC0: { + if (marker_size == 0x0F) { + uint8_t ext = p_file->get_8() & 0xF; + marker_size = read_bplist_var_size_int(p_file, pow(2, ext)); + } + uint64_t pos = p_file->get_position(); + + node->data_type = PL_NODE_TYPE_ARRAY; + for (uint64_t i = 0; i < marker_size; i++) { + p_file->seek(pos + trailer.ref_size * i); + uint64_t ref = read_bplist_var_size_int(p_file, trailer.ref_size); + + Ref<PListNode> element = read_bplist_obj(p_file, ref); + ERR_FAIL_COND_V(element.is_null(), Ref<PListNode>()); + node->data_array.push_back(element); + } + } break; + case 0xD0: { + if (marker_size == 0x0F) { + uint8_t ext = p_file->get_8() & 0xF; + marker_size = read_bplist_var_size_int(p_file, pow(2, ext)); + } + uint64_t pos = p_file->get_position(); + + node->data_type = PL_NODE_TYPE_DICT; + for (uint64_t i = 0; i < marker_size; i++) { + p_file->seek(pos + trailer.ref_size * i); + uint64_t key_ref = read_bplist_var_size_int(p_file, trailer.ref_size); + + p_file->seek(pos + trailer.ref_size * (i + marker_size)); + uint64_t obj_ref = read_bplist_var_size_int(p_file, trailer.ref_size); + + Ref<PListNode> element_key = read_bplist_obj(p_file, key_ref); + ERR_FAIL_COND_V(element_key.is_null() || element_key->data_type != PL_NODE_TYPE_STRING, Ref<PListNode>()); + Ref<PListNode> element = read_bplist_obj(p_file, obj_ref); + ERR_FAIL_COND_V(element.is_null(), Ref<PListNode>()); + node->data_dict[String::utf8(element_key->data_string.ptr(), element_key->data_string.length())] = element; + } + } break; + default: { + ERR_FAIL_V_MSG(Ref<PListNode>(), "Invalid marker type."); + } + } + return node; +} + bool PList::load_file(const String &p_filename) { root = Ref<PListNode>(); @@ -349,11 +625,19 @@ bool PList::load_file(const String &p_filename) { fb->get_buffer(magic, 8); if (String((const char *)magic, 8) == "bplist00") { - ERR_FAIL_V_MSG(false, "PList: Binary property lists are not supported."); + fb->seek_end(-26); + trailer.offset_size = fb->get_8(); + trailer.ref_size = fb->get_8(); + trailer.object_num = BSWAP64(fb->get_64()); + trailer.root_offset_idx = BSWAP64(fb->get_64()); + trailer.offset_table_start = BSWAP64(fb->get_64()); + root = read_bplist_obj(fb, trailer.root_offset_idx); + + return root.is_valid(); } else { // Load text plist. Error err; - Vector<uint8_t> array = FileAccess::get_file_as_array(p_filename, &err); + Vector<uint8_t> array = FileAccess::get_file_as_bytes(p_filename, &err); ERR_FAIL_COND_V(err != OK, false); String ret; diff --git a/platform/macos/export/plist.h b/platform/macos/export/plist.h index 97331a3629..d53e88832f 100644 --- a/platform/macos/export/plist.h +++ b/platform/macos/export/plist.h @@ -35,6 +35,7 @@ #include "core/crypto/crypto_core.h" #include "core/io/file_access.h" +#include "core/os/time.h" class PListNode; @@ -55,8 +56,20 @@ public: }; private: + struct PListTrailer { + uint8_t offset_size; + uint8_t ref_size; + uint64_t object_num; + uint64_t root_offset_idx; + uint64_t offset_table_start; + }; + + PListTrailer trailer; Ref<PListNode> root; + uint64_t read_bplist_var_size_int(Ref<FileAccess> p_file, uint8_t p_size); + Ref<PListNode> read_bplist_obj(Ref<FileAccess> p_file, uint64_t p_offset_idx); + public: PList(); PList(const String &p_string); @@ -82,19 +95,23 @@ public: Vector<Ref<PListNode>> data_array; HashMap<String, Ref<PListNode>> data_dict; union { - int32_t data_int; + int64_t data_int; bool data_bool; - float data_real; + double data_real; }; + PList::PLNodeType get_type() const; + Variant get_value() const; + + static Ref<PListNode> new_node(const Variant &p_value); static Ref<PListNode> new_array(); static Ref<PListNode> new_dict(); static Ref<PListNode> new_string(const String &p_string); static Ref<PListNode> new_data(const String &p_string); static Ref<PListNode> new_date(const String &p_string); static Ref<PListNode> new_bool(bool p_bool); - static Ref<PListNode> new_int(int32_t p_int); - static Ref<PListNode> new_real(float p_real); + static Ref<PListNode> new_int(int64_t p_int); + static Ref<PListNode> new_real(double p_real); bool push_subnode(const Ref<PListNode> &p_node, const String &p_key = ""); |