| 423 | } |
| 424 | |
| 425 | Error PckCreator::_create_after_process() { |
| 426 | ERR_FAIL_COND_V_MSG(files_to_pck.is_empty(), ERR_INVALID_DATA, "No files to write to PCK!"); |
| 427 | Ref<EditorProgressGDDC> pr = EditorProgressGDDC::create(nullptr, "re_write_pck", "Writing PCK archive...", (int)files_to_pck.size(), true); |
| 428 | cancelled = false; |
| 429 | broken_cnt = 0; |
| 430 | f = nullptr; |
| 431 | encryption_error = OK; |
| 432 | files_start = 0; |
| 433 | file_base = 0; |
| 434 | key = GDRESettings::get_singleton()->get_encryption_key(); |
| 435 | uint64_t start_time = OS::get_singleton()->get_ticks_msec(); |
| 436 | |
| 437 | auto temp_path = pck_path; |
| 438 | if (embed && get_exe_to_embed().is_empty()) { |
| 439 | error_string = "No executable to embed!"; |
| 440 | return ERR_FILE_NOT_FOUND; |
| 441 | } |
| 442 | |
| 443 | // create a tmp file if the pck file already exists |
| 444 | if (FileAccess::exists(pck_path) || exe_to_embed.simplify_path() == pck_path.simplify_path()) { |
| 445 | temp_path = pck_path + ".tmp"; |
| 446 | } |
| 447 | |
| 448 | f = FileAccess::open(temp_path, FileAccess::WRITE); |
| 449 | if (f.is_null()) { |
| 450 | error_string = ("Error opening PCK file: ") + temp_path; |
| 451 | return ERR_FILE_CANT_WRITE; |
| 452 | } |
| 453 | uint64_t embedded_start = 0; |
| 454 | uint64_t embedded_size = 0; |
| 455 | |
| 456 | GDREPackedSource::EXEPCKInfo exe_pck_info; |
| 457 | uint64_t absolute_exe_end = 0; |
| 458 | if (embed) { |
| 459 | // append to exe |
| 460 | |
| 461 | Ref<FileAccess> fs = FileAccess::open(exe_to_embed, FileAccess::READ); |
| 462 | if (fs.is_null()) { |
| 463 | error_string = ("Error opening executable file: ") + exe_to_embed; |
| 464 | return ERR_FILE_CANT_READ; |
| 465 | } |
| 466 | pr->step("Exec...", 0, true); |
| 467 | |
| 468 | fs->seek_end(); |
| 469 | absolute_exe_end = fs->get_position(); |
| 470 | uint64_t exe_end; |
| 471 | if (GDREPackedSource::get_exe_embedded_pck_info(exe_to_embed, exe_pck_info)) { |
| 472 | exe_end = exe_pck_info.pck_embed_off; |
| 473 | } else { |
| 474 | exe_end = absolute_exe_end; |
| 475 | } |
| 476 | fs->seek(0); |
| 477 | // copy executable data |
| 478 | for (uint64_t i = 0; i < exe_end; i++) { |
| 479 | f->store_8(fs->get_8()); |
| 480 | } |
| 481 | |
| 482 | embedded_start = f->get_position(); |
no test coverage detected