obliteration/gui/system.cpp

72 lines
1.8 KiB
C++
Raw Normal View History

#include "system.hpp"
2024-07-20 12:45:01 +00:00
#include "core.hpp"
#include "path.hpp"
2022-10-24 16:45:01 +00:00
#include "progress_dialog.hpp"
#include "settings.hpp"
2022-10-24 16:45:01 +00:00
#include <QMessageBox>
bool isSystemInitialized()
{
return isSystemInitialized(readSystemDirectorySetting());
}
bool isSystemInitialized(const QString &path)
{
2024-07-20 12:45:01 +00:00
auto root = toPath(path);
std::filesystem::file_status status;
try {
2024-07-14 19:52:33 +00:00
#ifdef _WIN32
2024-07-20 12:45:01 +00:00
status = std::filesystem::status(root / L"part" / L"md0.obp");
2024-07-14 19:52:33 +00:00
#else
2024-07-20 12:45:01 +00:00
status = std::filesystem::status(root / "part" / "md0.obp");
2024-07-14 19:52:33 +00:00
#endif
} catch (...) {
return false;
}
2024-07-20 12:45:01 +00:00
return status.type() == std::filesystem::file_type::regular;
}
2024-07-20 12:45:01 +00:00
bool initSystem(const QString &path, const QString &firmware, QWidget *parent)
{
// Setup progress dialog.
2024-07-20 12:45:01 +00:00
ProgressDialog progress("Initializing system", QString("Opening %1").arg(firmware), parent);
// Update firmware.
auto root = path.toStdString();
auto fw = firmware.toStdString();
Rust<RustError> error;
error = update_firmware(
2024-07-20 12:45:01 +00:00
root.c_str(),
fw.c_str(),
&progress, [](const char *status, std::uint64_t total, std::uint64_t written, void *cx) {
auto progress = reinterpret_cast<ProgressDialog *>(cx);
if (progress->statusText() != status) {
progress->setStatusText(status);
progress->setValue(0);
progress->setMaximum(total);
} else {
progress->setValue(written);
}
});
2023-02-07 21:37:15 +00:00
progress.complete();
2022-10-24 16:45:01 +00:00
// Check result.
2024-07-20 12:45:01 +00:00
if (error) {
QMessageBox::critical(
parent,
"Error",
QString("Failed to install %1 to %2: %3").arg(firmware).arg(path).arg(error_message(error)));
2022-10-24 16:45:01 +00:00
return false;
}
2024-07-20 12:45:01 +00:00
QMessageBox::information(parent, "Success", "Firmware installed successfully.");
2023-02-07 21:37:15 +00:00
return true;
}