| 472 | } |
| 473 | |
| 474 | int clone(const Arguments& info) |
| 475 | { |
| 476 | if (info.outname.empty()) |
| 477 | { |
| 478 | std::cout << "You need to specify an output name" << std::endl; |
| 479 | return 1; |
| 480 | } |
| 481 | |
| 482 | ESMData data; |
| 483 | if (load(info, &data) != 0) |
| 484 | { |
| 485 | std::cout << "Failed to load, aborting." << std::endl; |
| 486 | return 1; |
| 487 | } |
| 488 | |
| 489 | size_t recordCount = data.mRecords.size(); |
| 490 | |
| 491 | int digitCount = 1; // For a nicer output |
| 492 | if (recordCount > 0) |
| 493 | digitCount = static_cast<int>(std::log10(recordCount)) + 1; |
| 494 | |
| 495 | std::cout << "Loaded " << recordCount << " records:\n\n"; |
| 496 | |
| 497 | int i = 0; |
| 498 | for (std::pair<int, int> stat : data.mRecordStats) |
| 499 | { |
| 500 | ESM::NAME name; |
| 501 | name = stat.first; |
| 502 | int amount = stat.second; |
| 503 | std::cout << std::setw(digitCount) << amount << " " << name.toStringView() << " "; |
| 504 | if (++i % 3 == 0) |
| 505 | std::cout << '\n'; |
| 506 | } |
| 507 | |
| 508 | if (i % 3 != 0) |
| 509 | std::cout << '\n'; |
| 510 | |
| 511 | std::cout << "\nSaving records to: " << Files::pathToUnicodeString(info.outname) << "...\n"; |
| 512 | |
| 513 | ESM::ESMWriter esm; |
| 514 | ToUTF8::Utf8Encoder encoder(ToUTF8::calculateEncoding(info.encoding)); |
| 515 | esm.setEncoder(&encoder); |
| 516 | esm.setHeader(data.mHeader); |
| 517 | esm.setVersion(ESM::VER_130); |
| 518 | esm.setRecordCount(static_cast<int>(recordCount)); |
| 519 | |
| 520 | std::fstream save(info.outname, std::fstream::out | std::fstream::binary); |
| 521 | esm.save(save); |
| 522 | |
| 523 | int saved = 0; |
| 524 | for (auto& record : data.mRecords) |
| 525 | { |
| 526 | if (i <= 0) |
| 527 | break; |
| 528 | |
| 529 | const ESM::NAME typeName = record->getType(); |
| 530 | |
| 531 | esm.startRecord(typeName, record->getFlags()); |
no test coverage detected