| 483 | } |
| 484 | |
| 485 | LSError FileBankManager::Create(const char* tgt, const char* src, bool compress, bool optimize, const char* logFile, |
| 486 | const char** doNotCompress, const QFProperty* properties, int nProperties) |
| 487 | { |
| 488 | newestFile = 0; |
| 489 | size = 0; |
| 490 | |
| 491 | files.Resize(0); |
| 492 | files.Realloc(1024); |
| 493 | RString folder = src; |
| 494 | RString target = tgt; |
| 495 | ScanDir(folder, ""); |
| 496 | |
| 497 | if (logFile) |
| 498 | { |
| 499 | ParseMasks(logFile); |
| 500 | } |
| 501 | SortAndRemove(logFile != nullptr); |
| 502 | // repack only if destination is older than all sources |
| 503 | |
| 504 | if (!optimize) |
| 505 | { |
| 506 | Fail("Obsolete: Optimized format should be used"); |
| 507 | } |
| 508 | |
| 509 | int destTime = FileTime(target); |
| 510 | if (destTime >= newestFile) |
| 511 | { |
| 512 | LOG_DEBUG(Core, "{} skipped - no changes detected.\n", (const char*)folder); |
| 513 | return LSOK; |
| 514 | } |
| 515 | |
| 516 | const char* action = "Repacking"; |
| 517 | if (compress) |
| 518 | { |
| 519 | action = "Compressing"; |
| 520 | } |
| 521 | else if (optimize) |
| 522 | { |
| 523 | action = "Optimizing"; |
| 524 | } |
| 525 | LOG_DEBUG(Core, "{}: {} {} files ({} KB).\n", (const char*)folder, action, files.Size(), (size + 1023) / 1024); |
| 526 | |
| 527 | if (!compress) |
| 528 | { |
| 529 | // save headers |
| 530 | SOFStream out; |
| 531 | out.open(target); |
| 532 | out.setbuffer(1024 * 1024); |
| 533 | SaveProperties(out, properties, nProperties); |
| 534 | SaveHeadersOpt(out); |
| 535 | for (int i = 0; i < files.Size(); i++) |
| 536 | { |
| 537 | FileInfoExt& file = files[i]; |
| 538 | RString inFilename = folder + RString(DIR_STR) + HostPathFromBankEntryName(file.name); |
| 539 | QIFStream in; |
| 540 | in.open(inFilename); |
| 541 | out.write(in.act(), in.rest()); |
| 542 | } |