mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
feat: Added system to handle version migrations
This commit is contained in:
@@ -31,7 +31,7 @@ namespace hex::plugin::builtin {
|
||||
std::ignore = args;
|
||||
|
||||
hex::log::print(std::string(romfs::get("logo.ans").string()),
|
||||
ImHexApi::System::getImHexVersion(),
|
||||
ImHexApi::System::getImHexVersion().get(),
|
||||
ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash(),
|
||||
__DATE__, __TIME__,
|
||||
ImHexApi::System::isPortableVersion() ? "Portable" : "Installed");
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace hex::plugin::builtin {
|
||||
nlohmann::json result;
|
||||
|
||||
result["build"] = {
|
||||
{ "version", ImHexApi::System::getImHexVersion() },
|
||||
{ "version", ImHexApi::System::getImHexVersion().get() },
|
||||
{ "commit", ImHexApi::System::getCommitHash(true) },
|
||||
{ "branch", ImHexApi::System::getCommitBranch() }
|
||||
};
|
||||
|
||||
@@ -226,11 +226,15 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
|
||||
EventWindowInitialized::subscribe([] {
|
||||
if (ContentRegistry::Settings::read<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.prev_launch_version", "") == "") {
|
||||
const auto currVersion = ImHexApi::System::getImHexVersion();
|
||||
const auto prevLaunchVersion = ContentRegistry::Settings::read<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.prev_launch_version", "");
|
||||
if (prevLaunchVersion == "") {
|
||||
EventFirstLaunch::post();
|
||||
}
|
||||
|
||||
ContentRegistry::Settings::write<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.prev_launch_version", ImHexApi::System::getImHexVersion());
|
||||
EventImHexUpdated::post(SemanticVersion(prevLaunchVersion), currVersion);
|
||||
|
||||
ContentRegistry::Settings::write<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.prev_launch_version", currVersion.get(false));
|
||||
});
|
||||
|
||||
EventWindowDeinitializing::subscribe([](GLFWwindow *window) {
|
||||
|
||||
@@ -39,9 +39,7 @@ namespace hex::plugin::builtin {
|
||||
return false;
|
||||
|
||||
// Convert the current version string to a format that can be compared to the latest release
|
||||
auto versionString = ImHexApi::System::getImHexVersion();
|
||||
size_t versionLength = std::min(versionString.find_first_of('-'), versionString.length());
|
||||
auto currVersion = "v" + versionString.substr(0, versionLength);
|
||||
auto currVersion = "v" + ImHexApi::System::getImHexVersion().get(false);
|
||||
|
||||
// Get the latest release version string
|
||||
auto latestVersion = releases["tag_name"].get<std::string_view>();
|
||||
@@ -59,7 +57,7 @@ namespace hex::plugin::builtin {
|
||||
ContentRegistry::Settings::write<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.uuid", uuid);
|
||||
}
|
||||
|
||||
TaskManager::createBackgroundTask("hex.builtin.task.sending_statistics"_lang, [uuid, versionString](auto&) {
|
||||
TaskManager::createBackgroundTask("hex.builtin.task.sending_statistics"_lang, [uuid](auto&) {
|
||||
// To avoid potentially flooding our database with lots of dead users
|
||||
// from people just visiting the website, don't send telemetry data from
|
||||
// the web version
|
||||
@@ -71,7 +69,7 @@ namespace hex::plugin::builtin {
|
||||
nlohmann::json telemetry = {
|
||||
{ "uuid", uuid },
|
||||
{ "format_version", "1" },
|
||||
{ "imhex_version", versionString },
|
||||
{ "imhex_version", ImHexApi::System::getImHexVersion().get(false) },
|
||||
{ "imhex_commit", fmt::format("{}@{}", ImHexApi::System::getCommitHash(true), ImHexApi::System::getCommitBranch()) },
|
||||
{ "install_type", ImHexApi::System::isPortableVersion() ? "Portable" : "Installed" },
|
||||
{ "os", ImHexApi::System::getOSName() },
|
||||
|
||||
@@ -298,7 +298,7 @@ namespace hex::plugin::builtin {
|
||||
ImGui::TextUnformatted("hex.builtin.oobe.server_contact.data_collected.version"_lang);
|
||||
ImGui::TableNextColumn();
|
||||
ImGuiExt::TextFormattedWrapped("{}\n{}@{}\n{}",
|
||||
ImHexApi::System::getImHexVersion(),
|
||||
ImHexApi::System::getImHexVersion().get(),
|
||||
ImHexApi::System::getCommitHash(true),
|
||||
ImHexApi::System::getCommitBranch(),
|
||||
ImHexApi::System::isPortableVersion() ? "Portable" : "Installed"
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
{
|
||||
const auto metadataContent = hex::format("{}\n{}", MetadataHeaderMagic, ImHexApi::System::getImHexVersion());
|
||||
const auto metadataContent = hex::format("{}\n{}", MetadataHeaderMagic, ImHexApi::System::getImHexVersion().get(false));
|
||||
tar.writeString(MetadataPath, metadataContent);
|
||||
}
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace hex::plugin::builtin {
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
// Draw basic information about ImHex and its version
|
||||
ImGuiExt::TextFormatted("ImHex Hex Editor v{} by WerWolv", ImHexApi::System::getImHexVersion());
|
||||
ImGuiExt::TextFormatted("ImHex Hex Editor v{} by WerWolv", ImHexApi::System::getImHexVersion().get());
|
||||
ImGui::Indent(25_scaled);
|
||||
ImGuiExt::TextFormatted("Powered by Dear ImGui v{}", ImGui::GetVersion());
|
||||
ImGui::Unindent(25_scaled);
|
||||
@@ -582,9 +582,9 @@ namespace hex::plugin::builtin {
|
||||
static ReleaseNotes notes;
|
||||
|
||||
// Set up the request to get the release notes the first time the page is opened
|
||||
const static auto ImHexVersionString = ImHexApi::System::getImHexVersion(false);
|
||||
const static auto ImHexVersion = ImHexApi::System::getImHexVersion();
|
||||
AT_FIRST_TIME {
|
||||
static HttpRequest request("GET", GitHubApiURL + std::string("/releases/") + (ImHexVersionString.ends_with(".WIP") ? "latest" : ( "tags/v" + ImHexVersionString)));
|
||||
static HttpRequest request("GET", GitHubApiURL + std::string("/releases/") + (ImHexVersion.nightly() ? "latest" : ( "tags/v" + ImHexVersion.get(false))));
|
||||
|
||||
m_releaseNoteRequest = request.execute();
|
||||
};
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace hex::plugin::builtin {
|
||||
// Force update all installed items after an update so that there's no old and incompatible versions around anymore
|
||||
{
|
||||
const auto prevUpdateVersion = ContentRegistry::Settings::read<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.prev_launch_version", "");
|
||||
if (prevUpdateVersion != ImHexApi::System::getImHexVersion()) {
|
||||
if (SemanticVersion(prevUpdateVersion) != ImHexApi::System::getImHexVersion()) {
|
||||
updateAll();
|
||||
}
|
||||
}
|
||||
@@ -359,7 +359,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
TaskManager::doLater([] {
|
||||
ContentRegistry::Settings::write<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.prev_launch_version", ImHexApi::System::getImHexVersion());
|
||||
ContentRegistry::Settings::write<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.prev_launch_version", ImHexApi::System::getImHexVersion().get(false));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user