[qt] refactor: qt_common lib (#94)
This is part of a series of PRs made in preparation for the QML rewrite. this PR specifically moves a bunch of utility functions from main.cpp into qt_common, with the biggest benefit being that QML can reuse the exact same code through ctx passthrough. Also, QtCommon::Frontend is an abstraction layer over several previously Widgets-specific stuff like QMessageBox that gets used everywhere. The idea is that once QML is implemented, these functions can have a Quick version implemented for systems that don't work well with Widgets (sun) or for those on Plasma 6+ (reduces memory usage w/o Widgets linkage) although Quick from C++ is actually anal, but whatever. Other than that this should also just kinda reduce the size of main.cpp which is a 6000-line behemoth rn, and clangd straight up gives up with it for me (likely caused by the massive amount of headers, which this DOES reduce). In the future, I probably want to create a common strings lookup table that both Qt and QML can reference--though I'm not sure how much linguist likes that--which should give us a way to keep language consistent (use frozen-map). TODO: Docs for Qt stuff Co-authored-by: MaranBr <maranbr@outlook.com> Reviewed-on: #94 Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: Shinmegumi <shinmegumi@eden-emu.dev>
This commit is contained in:
parent
4c5d03f5de
commit
f4386423e8
111 changed files with 2235 additions and 1544 deletions
78
src/qt_common/qt_rom_util.cpp
Normal file
78
src/qt_common/qt_rom_util.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "qt_rom_util.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace QtCommon::ROM {
|
||||
|
||||
bool RomFSRawCopy(size_t total_size,
|
||||
size_t& read_size,
|
||||
QtProgressCallback callback,
|
||||
const FileSys::VirtualDir& src,
|
||||
const FileSys::VirtualDir& dest,
|
||||
bool full)
|
||||
{
|
||||
// TODO(crueter)
|
||||
// if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable())
|
||||
// return false;
|
||||
// if (dialog.wasCanceled())
|
||||
// return false;
|
||||
|
||||
// std::vector<u8> buffer(CopyBufferSize);
|
||||
// auto last_timestamp = std::chrono::steady_clock::now();
|
||||
|
||||
// const auto QtRawCopy = [&](const FileSys::VirtualFile& src_file,
|
||||
// const FileSys::VirtualFile& dest_file) {
|
||||
// if (src_file == nullptr || dest_file == nullptr) {
|
||||
// return false;
|
||||
// }
|
||||
// if (!dest_file->Resize(src_file->GetSize())) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// for (std::size_t i = 0; i < src_file->GetSize(); i += buffer.size()) {
|
||||
// if (dialog.wasCanceled()) {
|
||||
// dest_file->Resize(0);
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// using namespace std::literals::chrono_literals;
|
||||
// const auto new_timestamp = std::chrono::steady_clock::now();
|
||||
|
||||
// if ((new_timestamp - last_timestamp) > 33ms) {
|
||||
// last_timestamp = new_timestamp;
|
||||
// dialog.setValue(
|
||||
// static_cast<int>(std::min(read_size, total_size) * 100 / total_size));
|
||||
// QCoreApplication::processEvents();
|
||||
// }
|
||||
|
||||
// const auto read = src_file->Read(buffer.data(), buffer.size(), i);
|
||||
// dest_file->Write(buffer.data(), read, i);
|
||||
|
||||
// read_size += read;
|
||||
// }
|
||||
|
||||
// return true;
|
||||
// };
|
||||
|
||||
// if (full) {
|
||||
// for (const auto& file : src->GetFiles()) {
|
||||
// const auto out = VfsDirectoryCreateFileWrapper(dest, file->GetName());
|
||||
// if (!QtRawCopy(file, out))
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// for (const auto& dir : src->GetSubdirectories()) {
|
||||
// const auto out = dest->CreateSubdirectory(dir->GetName());
|
||||
// if (!RomFSRawCopy(total_size, read_size, dialog, dir, out, full))
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue