2022-10-23 12:43:35 +00:00
|
|
|
#include "system.hpp"
|
2024-07-20 12:45:01 +00:00
|
|
|
#include "core.hpp"
|
2022-10-23 12:43:35 +00:00
|
|
|
#include "path.hpp"
|
2022-10-24 16:45:01 +00:00
|
|
|
#include "progress_dialog.hpp"
|
2022-10-23 12:43:35 +00:00
|
|
|
#include "settings.hpp"
|
|
|
|
|
2022-10-24 16:45:01 +00:00
|
|
|
#include <QMessageBox>
|
2022-10-23 12:43:35 +00:00
|
|
|
|
2023-02-22 16:27:31 +00:00
|
|
|
bool isSystemInitialized()
|
2022-10-23 12:43:35 +00:00
|
|
|
{
|
2023-02-22 16:27:31 +00:00
|
|
|
return isSystemInitialized(readSystemDirectorySetting());
|
2023-02-16 18:47:18 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 16:27:31 +00:00
|
|
|
bool isSystemInitialized(const QString &path)
|
2023-02-16 18:47:18 +00:00
|
|
|
{
|
2024-07-20 12:45:01 +00:00
|
|
|
auto root = toPath(path);
|
|
|
|
std::filesystem::file_status status;
|
2022-10-23 12:43:35 +00:00
|
|
|
|
|
|
|
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
|
2022-10-23 12:43:35 +00:00
|
|
|
} catch (...) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-07-20 12:45:01 +00:00
|
|
|
|
|
|
|
return status.type() == std::filesystem::file_type::regular;
|
2022-10-23 12:43:35 +00:00
|
|
|
}
|
|
|
|
|
2024-07-20 12:45:01 +00:00
|
|
|
bool initSystem(const QString &path, const QString &firmware, QWidget *parent)
|
2023-02-16 18:47:18 +00:00
|
|
|
{
|
2023-02-22 16:27:31 +00:00
|
|
|
// 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();
|
2024-07-27 17:52:27 +00:00
|
|
|
Rust<RustError> error;
|
2024-07-21 10:18:19 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2023-02-22 16:27:31 +00:00
|
|
|
// Check result.
|
2024-07-20 12:45:01 +00:00
|
|
|
if (error) {
|
2024-07-21 10:18:19 +00:00
|
|
|
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
|
|
|
|
2022-10-23 12:43:35 +00:00
|
|
|
return true;
|
|
|
|
}
|