fix: use correct suffix when decoding

This commit is contained in:
鲁树人 2024-11-26 06:51:21 +09:00
parent 8d3b6f5ca5
commit bd9a9285ae
2 changed files with 7 additions and 5 deletions

View File

@ -27,7 +27,7 @@ class KggTask {
void info(const wchar_t* msg) const { fwprintf(stderr, L"[INFO] %s (%s)\n", msg, kgg_path_.filename().c_str()); } void info(const wchar_t* msg) const { fwprintf(stderr, L"[INFO] %s (%s)\n", msg, kgg_path_.filename().c_str()); }
void info(const std::wstring& msg) const { info(msg.c_str()); } void info(const std::wstring& msg) const { info(msg.c_str()); }
void Execute(const Infra::kgm_ekey_db_t& ekey_db) const { void Execute(const Infra::kgm_ekey_db_t& ekey_db, const std::wstring_view suffix) const {
constexpr static std::array<uint8_t, 16> kMagicHeader{0x7C, 0xD5, 0x32, 0xEB, 0x86, 0x02, 0x7F, 0x4B, constexpr static std::array<uint8_t, 16> kMagicHeader{0x7C, 0xD5, 0x32, 0xEB, 0x86, 0x02, 0x7F, 0x4B,
0xA8, 0xAF, 0xA6, 0x8E, 0x0F, 0xFF, 0x99, 0x14}; 0xA8, 0xAF, 0xA6, 0x8E, 0x0F, 0xFF, 0x99, 0x14};
@ -70,7 +70,7 @@ class KggTask {
kgg_stream_in.read(magic.data(), 4); kgg_stream_in.read(magic.data(), 4);
qmc2->Decrypt(std::span(reinterpret_cast<uint8_t*>(magic.data()), 4), 0); qmc2->Decrypt(std::span(reinterpret_cast<uint8_t*>(magic.data()), 4), 0);
auto real_ext = DetectRealExt(magic); auto real_ext = DetectRealExt(magic);
auto out_path = out_dir_ / std::format(L"{}_kgg-dec.{}", kgg_path_.stem().wstring(), real_ext); auto out_path = out_dir_ / std::format(L"{}{}.{}", kgg_path_.stem().wstring(), suffix, real_ext);
if (exists(out_path)) { if (exists(out_path)) {
warning(std::format(L"output file already exists: {}", out_path.filename().wstring())); warning(std::format(L"output file already exists: {}", out_path.filename().wstring()));
@ -117,7 +117,8 @@ class KggTask {
class KggTaskQueue { class KggTaskQueue {
public: public:
explicit KggTaskQueue(Infra::kgm_ekey_db_t ekey_db) : ekey_db_(std::move(ekey_db)) {} explicit KggTaskQueue(Infra::kgm_ekey_db_t ekey_db, const std::wstring_view suffix)
: ekey_db_(std::move(ekey_db)), suffix_(suffix) {}
void Push(std::unique_ptr<KggTask> task) { void Push(std::unique_ptr<KggTask> task) {
std::lock_guard lock(mutex_); std::lock_guard lock(mutex_);
@ -160,12 +161,13 @@ class KggTaskQueue {
private: private:
bool thread_end_{false}; bool thread_end_{false};
Infra::kgm_ekey_db_t ekey_db_; Infra::kgm_ekey_db_t ekey_db_;
std::wstring suffix_;
void WorkerThreadBody() { void WorkerThreadBody() {
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
std::unique_ptr<KggTask> task{nullptr}; std::unique_ptr<KggTask> task{nullptr};
while ((task = Pop())) { while ((task = Pop())) {
task->Execute(ekey_db_); task->Execute(ekey_db_, suffix_);
} }
} }

View File

@ -103,7 +103,7 @@ int main() {
} }
#endif #endif
KggTaskQueue queue(ekey_db); KggTaskQueue queue(ekey_db, file_suffix);
auto thread_count = auto thread_count =
#ifndef NDEBUG #ifndef NDEBUG
1; 1;