2022-02-01 18:09:40 +01:00
|
|
|
#include <hex.hpp>
|
2023-06-20 11:55:56 +02:00
|
|
|
#include <hex/helpers/http_requests.hpp>
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/api/event.hpp>
|
|
|
|
#include <hex/api/content_registry.hpp>
|
|
|
|
#include <hex/api/localization.hpp>
|
2022-02-01 23:33:42 +01:00
|
|
|
#include <hex/api/plugin_manager.hpp>
|
2022-12-29 19:26:00 +01:00
|
|
|
#include <hex/api/theme_manager.hpp>
|
2023-05-11 18:44:50 +02:00
|
|
|
#include <hex/api/layout_manager.hpp>
|
2023-08-06 21:33:15 +02:00
|
|
|
#include <hex/api/achievement_manager.hpp>
|
2023-06-20 11:55:56 +02:00
|
|
|
#include <hex/api_urls.hpp>
|
2022-02-01 23:33:42 +01:00
|
|
|
#include <hex/ui/view.hpp>
|
2022-03-04 11:36:37 +01:00
|
|
|
#include <hex/helpers/fs.hpp>
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2022-02-01 23:33:42 +01:00
|
|
|
|
2022-08-08 21:23:52 +02:00
|
|
|
#include <hex/api/project_file_manager.hpp>
|
2022-02-01 18:09:40 +01:00
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
|
|
|
|
2022-02-01 23:33:42 +01:00
|
|
|
#include <nlohmann/json.hpp>
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <romfs/romfs.hpp>
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
#include <wolv/io/file.hpp>
|
|
|
|
#include <wolv/io/fs.hpp>
|
|
|
|
|
2022-07-26 14:59:08 +02:00
|
|
|
#include <fonts/codicons_font.h>
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-06-20 11:55:56 +02:00
|
|
|
#include <content/popups/popup_telemetry_request.hpp>
|
2023-05-27 16:59:30 +02:00
|
|
|
#include <content/recent.hpp>
|
2023-04-08 00:58:53 +02:00
|
|
|
|
2022-08-24 00:18:10 +02:00
|
|
|
#include <string>
|
2022-10-27 13:21:54 +02:00
|
|
|
#include <random>
|
2022-02-01 18:09:40 +01:00
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
2022-07-06 10:21:02 +02:00
|
|
|
static ImGui::Texture s_bannerTexture, s_backdropTexture;
|
2022-02-01 18:09:40 +01:00
|
|
|
|
|
|
|
static std::string s_tipOfTheDay;
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
class PopupRestoreBackup : public Popup<PopupRestoreBackup> {
|
2023-05-22 13:24:48 +02:00
|
|
|
private:
|
|
|
|
std::fs::path m_logFilePath;
|
|
|
|
std::function<void()> m_restoreCallback;
|
|
|
|
std::function<void()> m_deleteCallback;
|
2023-06-20 11:55:56 +02:00
|
|
|
bool m_reportError = true;
|
2023-04-08 00:58:53 +02:00
|
|
|
public:
|
2023-11-04 22:10:34 +01:00
|
|
|
PopupRestoreBackup(std::fs::path logFilePath, const std::function<void()> &restoreCallback, const std::function<void()> &deleteCallback)
|
2023-05-22 13:24:48 +02:00
|
|
|
: Popup("hex.builtin.popup.safety_backup.title"),
|
2023-11-04 22:10:34 +01:00
|
|
|
m_logFilePath(std::move(logFilePath)),
|
2023-05-22 13:24:48 +02:00
|
|
|
m_restoreCallback(restoreCallback),
|
2023-06-20 11:55:56 +02:00
|
|
|
m_deleteCallback(deleteCallback) {
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
this->m_reportError = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.upload_crash_logs", true);
|
2023-06-20 11:55:56 +02:00
|
|
|
}
|
2023-04-08 00:58:53 +02:00
|
|
|
|
|
|
|
void drawContent() override {
|
2023-04-16 21:34:29 +02:00
|
|
|
ImGui::TextUnformatted("hex.builtin.popup.safety_backup.desc"_lang);
|
2023-05-22 13:24:48 +02:00
|
|
|
if (!this->m_logFilePath.empty()) {
|
2023-06-20 11:55:56 +02:00
|
|
|
ImGui::NewLine();
|
2023-05-22 13:24:48 +02:00
|
|
|
ImGui::TextUnformatted("hex.builtin.popup.safety_backup.log_file"_lang);
|
2023-06-20 11:55:56 +02:00
|
|
|
ImGui::SameLine(0, 2_scaled);
|
2023-05-22 13:24:48 +02:00
|
|
|
if (ImGui::Hyperlink(this->m_logFilePath.filename().string().c_str())) {
|
|
|
|
fs::openFolderWithSelectionExternal(this->m_logFilePath);
|
|
|
|
}
|
2023-06-20 11:55:56 +02:00
|
|
|
|
|
|
|
ImGui::Checkbox("hex.builtin.popup.safety_backup.report_error"_lang, &this->m_reportError);
|
2023-05-22 13:24:48 +02:00
|
|
|
ImGui::NewLine();
|
|
|
|
}
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
auto width = ImGui::GetWindowWidth();
|
|
|
|
ImGui::SetCursorPosX(width / 9);
|
2023-04-16 21:34:29 +02:00
|
|
|
if (ImGui::Button("hex.builtin.popup.safety_backup.restore"_lang, ImVec2(width / 3, 0))) {
|
2023-05-22 13:24:48 +02:00
|
|
|
this->m_restoreCallback();
|
|
|
|
this->m_deleteCallback();
|
2023-04-08 00:58:53 +02:00
|
|
|
|
2023-06-20 11:55:56 +02:00
|
|
|
if (this->m_reportError) {
|
|
|
|
wolv::io::File logFile(this->m_logFilePath, wolv::io::File::Mode::Read);
|
|
|
|
if (logFile.isValid()) {
|
|
|
|
// Read current log file data
|
|
|
|
auto data = logFile.readString();
|
|
|
|
|
|
|
|
// Anonymize the log file
|
|
|
|
{
|
|
|
|
for (u32 pathType = 0; pathType < u32(fs::ImHexPath::END); pathType++) {
|
|
|
|
for (auto &folder : fs::getDefaultPaths(static_cast<fs::ImHexPath>(pathType))) {
|
|
|
|
auto parent = wolv::util::toUTF8String(folder.parent_path());
|
|
|
|
data = wolv::util::replaceStrings(data, parent, "<*****>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TaskManager::createBackgroundTask("Upload Crash report", [path = this->m_logFilePath, data](auto&){
|
|
|
|
HttpRequest request("POST", ImHexApiURL + std::string("/crash_upload"));
|
|
|
|
request.uploadFile(std::vector<u8>(data.begin(), data.end()), "file", path.filename()).wait();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.upload_crash_logs", this->m_reportError);
|
2023-06-20 11:55:56 +02:00
|
|
|
|
2023-04-17 17:02:10 +02:00
|
|
|
this->close();
|
2023-04-08 00:58:53 +02:00
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetCursorPosX(width / 9 * 5);
|
2023-04-16 21:34:29 +02:00
|
|
|
if (ImGui::Button("hex.builtin.popup.safety_backup.delete"_lang, ImVec2(width / 3, 0))) {
|
2023-05-22 13:24:48 +02:00
|
|
|
this->m_deleteCallback();
|
2023-04-08 00:58:53 +02:00
|
|
|
|
2023-04-17 17:02:10 +02:00
|
|
|
this->close();
|
2023-04-08 00:58:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class PopupTipOfTheDay : public Popup<PopupTipOfTheDay> {
|
|
|
|
public:
|
|
|
|
PopupTipOfTheDay() : Popup("hex.builtin.popup.tip_of_the_day.title", true, false) { }
|
|
|
|
|
|
|
|
void drawContent() override {
|
|
|
|
ImGui::Header("hex.builtin.welcome.tip_of_the_day"_lang, true);
|
|
|
|
|
|
|
|
ImGui::TextFormattedWrapped("{}", s_tipOfTheDay.c_str());
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
static bool dontShowAgain = false;
|
|
|
|
if (ImGui::Checkbox("hex.builtin.common.dont_show_again"_lang, &dontShowAgain)) {
|
|
|
|
ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", !dontShowAgain);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine((ImGui::GetMainViewport()->Size / 3 - ImGui::CalcTextSize("hex.builtin.common.close"_lang) - ImGui::GetStyle().FramePadding).x);
|
|
|
|
|
|
|
|
if (ImGui::Button("hex.builtin.common.close"_lang))
|
|
|
|
Popup::close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-07 07:16:38 +02:00
|
|
|
static void loadDefaultLayout() {
|
2023-05-11 18:44:50 +02:00
|
|
|
LayoutManager::loadString(std::string(romfs::get("layouts/default.hexlyt").string()));
|
2022-02-01 23:33:42 +01:00
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-07-06 10:21:02 +02:00
|
|
|
static bool isAnyViewOpen() {
|
2023-03-21 15:33:43 +01:00
|
|
|
const auto &views = ContentRegistry::Views::impl::getEntries();
|
2022-07-06 10:21:02 +02:00
|
|
|
return std::any_of(views.begin(), views.end(),
|
2023-04-08 12:08:45 +02:00
|
|
|
[](const auto &entry) {
|
2022-07-06 10:21:02 +02:00
|
|
|
return entry.second->getWindowOpenState();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
static void drawWelcomeScreenContent() {
|
|
|
|
const auto availableSpace = ImGui::GetContentRegionAvail();
|
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
ImGui::Image(s_bannerTexture, s_bannerTexture.getSize() / (2 * (1.0F / ImHexApi::System::getGlobalScale())));
|
2022-02-01 18:09:40 +01:00
|
|
|
|
|
|
|
ImGui::Indent();
|
|
|
|
if (ImGui::BeginTable("Welcome Left", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, 0))) {
|
|
|
|
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 3);
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
2023-11-04 22:10:34 +01:00
|
|
|
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + std::min<float>(450_scaled, availableSpace.x / 2 - 50_scaled));
|
2022-02-01 18:09:40 +01:00
|
|
|
ImGui::TextFormattedWrapped("A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM.");
|
2023-05-20 21:20:32 +02:00
|
|
|
ImGui::PopTextWrapPos();
|
2022-02-01 18:09:40 +01:00
|
|
|
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 6);
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
|
2022-02-02 00:36:09 +01:00
|
|
|
ImGui::UnderlinedText("hex.builtin.welcome.header.start"_lang);
|
2022-02-01 18:09:40 +01:00
|
|
|
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5_scaled);
|
|
|
|
{
|
2022-10-21 12:01:28 +02:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_NEW_FILE, "hex.builtin.welcome.start.create_file"_lang)) {
|
|
|
|
auto newProvider = hex::ImHexApi::Provider::createProvider("hex.builtin.provider.mem_file", true);
|
|
|
|
if (newProvider != nullptr && !newProvider->open())
|
|
|
|
hex::ImHexApi::Provider::remove(newProvider);
|
|
|
|
else
|
|
|
|
EventManager::post<EventProviderOpened>(newProvider);
|
|
|
|
}
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_GO_TO_FILE, "hex.builtin.welcome.start.open_file"_lang))
|
2022-02-01 18:09:40 +01:00
|
|
|
EventManager::post<RequestOpenWindow>("Open File");
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_NOTEBOOK, "hex.builtin.welcome.start.open_project"_lang))
|
2022-02-01 18:09:40 +01:00
|
|
|
EventManager::post<RequestOpenWindow>("Open Project");
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_TELESCOPE, "hex.builtin.welcome.start.open_other"_lang))
|
|
|
|
ImGui::OpenPopup("hex.builtin.welcome.start.popup.open_other"_lang);
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SetNextWindowPos(ImGui::GetWindowPos() + ImGui::GetCursorPos());
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::BeginPopup("hex.builtin.welcome.start.popup.open_other"_lang)) {
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
for (const auto &unlocalizedProviderName : ContentRegistry::Provider::impl::getEntries()) {
|
2022-02-01 18:09:40 +01:00
|
|
|
if (ImGui::Hyperlink(LangEntry(unlocalizedProviderName))) {
|
2022-08-12 15:11:27 +02:00
|
|
|
ImHexApi::Provider::createProvider(unlocalizedProviderName);
|
2022-02-01 18:09:40 +01:00
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
2023-10-04 12:00:32 +02:00
|
|
|
// Draw recent entries
|
2023-11-02 08:54:02 +01:00
|
|
|
ImGui::Dummy({});
|
2023-05-27 16:59:30 +02:00
|
|
|
recent::draw();
|
2022-02-01 18:09:40 +01:00
|
|
|
|
|
|
|
if (ImHexApi::System::getInitArguments().contains("update-available")) {
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
|
|
|
ImGui::TableNextColumn();
|
2022-02-02 00:36:09 +01:00
|
|
|
ImGui::UnderlinedText("hex.builtin.welcome.header.update"_lang);
|
2022-02-01 18:09:40 +01:00
|
|
|
{
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::DescriptionButton("hex.builtin.welcome.update.title"_lang, hex::format("hex.builtin.welcome.update.desc"_lang, ImHexApi::System::getInitArguments()["update-available"]).c_str(), ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
|
2023-10-21 20:40:24 +02:00
|
|
|
ImHexApi::System::updateImHex(ImHexApi::System::UpdateType::Stable);
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 6);
|
|
|
|
ImGui::TableNextColumn();
|
2022-02-02 00:36:09 +01:00
|
|
|
ImGui::UnderlinedText("hex.builtin.welcome.header.help"_lang);
|
2022-02-01 18:09:40 +01:00
|
|
|
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5_scaled);
|
2023-07-22 18:38:14 +02:00
|
|
|
ImGui::Dummy({0, 0});
|
2022-02-01 18:09:40 +01:00
|
|
|
{
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::IconHyperlink(ICON_VS_GITHUB, "hex.builtin.welcome.help.repo"_lang)) hex::openWebpage("hex.builtin.welcome.help.repo.link"_lang);
|
|
|
|
if (ImGui::IconHyperlink(ICON_VS_ORGANIZATION, "hex.builtin.welcome.help.gethelp"_lang)) hex::openWebpage("hex.builtin.welcome.help.gethelp.link"_lang);
|
|
|
|
if (ImGui::IconHyperlink(ICON_VS_COMMENT_DISCUSSION, "hex.builtin.welcome.help.discord"_lang)) hex::openWebpage("hex.builtin.welcome.help.discord.link"_lang);
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
|
|
|
ImGui::TableNextColumn();
|
2022-02-02 00:36:09 +01:00
|
|
|
ImGui::UnderlinedText("hex.builtin.welcome.header.plugins"_lang);
|
2022-02-01 18:09:40 +01:00
|
|
|
{
|
|
|
|
const auto &plugins = PluginManager::getPlugins();
|
|
|
|
|
|
|
|
if (!plugins.empty()) {
|
|
|
|
if (ImGui::BeginTable("plugins", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY | ImGuiTableFlags_SizingFixedFit, ImVec2((ImGui::GetContentRegionAvail().x * 5) / 6, ImGui::GetTextLineHeightWithSpacing() * 5))) {
|
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2022-02-02 00:36:09 +01:00
|
|
|
ImGui::TableSetupColumn("hex.builtin.welcome.plugins.plugin"_lang, ImGuiTableColumnFlags_WidthStretch, 0.2);
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.welcome.plugins.author"_lang, ImGuiTableColumnFlags_WidthStretch, 0.2);
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.welcome.plugins.desc"_lang, ImGuiTableColumnFlags_WidthStretch, 0.6);
|
2022-02-01 18:09:40 +01:00
|
|
|
ImGui::TableSetupColumn("##loaded", ImGuiTableColumnFlags_WidthFixed, ImGui::GetTextLineHeight());
|
|
|
|
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
ImGuiListClipper clipper;
|
|
|
|
clipper.Begin(plugins.size());
|
|
|
|
|
|
|
|
while (clipper.Step()) {
|
2022-03-27 00:01:28 +01:00
|
|
|
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
2022-02-01 18:09:40 +01:00
|
|
|
const auto &plugin = plugins[i];
|
|
|
|
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(plugin.getPluginName().c_str());
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(plugin.getPluginAuthor().c_str());
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(plugin.getPluginDescription().c_str());
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::TextUnformatted(plugin.isLoaded() ? ICON_VS_CHECK : ICON_VS_CLOSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clipper.End();
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::BeginTable("Welcome Right", 1, ImGuiTableFlags_NoBordersInBody, ImVec2(availableSpace.x / 2, 0))) {
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
|
|
|
ImGui::TableNextColumn();
|
2022-02-02 00:36:09 +01:00
|
|
|
ImGui::UnderlinedText("hex.builtin.welcome.header.customize"_lang);
|
2022-02-01 18:09:40 +01:00
|
|
|
{
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::DescriptionButton("hex.builtin.welcome.customize.settings.title"_lang, "hex.builtin.welcome.customize.settings.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
|
2022-02-01 18:09:40 +01:00
|
|
|
EventManager::post<RequestOpenWindow>("Settings");
|
|
|
|
}
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
|
|
|
ImGui::TableNextColumn();
|
2022-02-02 00:36:09 +01:00
|
|
|
ImGui::UnderlinedText("hex.builtin.welcome.header.learn"_lang);
|
2022-02-01 18:09:40 +01:00
|
|
|
{
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::DescriptionButton("hex.builtin.welcome.learn.latest.title"_lang, "hex.builtin.welcome.learn.latest.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
|
|
|
|
hex::openWebpage("hex.builtin.welcome.learn.latest.link"_lang);
|
2023-08-06 21:33:15 +02:00
|
|
|
if (ImGui::DescriptionButton("hex.builtin.welcome.learn.imhex.title"_lang, "hex.builtin.welcome.learn.imhex.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0))) {
|
|
|
|
AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.docs.name");
|
|
|
|
hex::openWebpage("hex.builtin.welcome.learn.imhex.link"_lang);
|
|
|
|
}
|
2022-02-02 00:36:09 +01:00
|
|
|
if (ImGui::DescriptionButton("hex.builtin.welcome.learn.pattern.title"_lang, "hex.builtin.welcome.learn.pattern.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
|
|
|
|
hex::openWebpage("hex.builtin.welcome.learn.pattern.link"_lang);
|
|
|
|
if (ImGui::DescriptionButton("hex.builtin.welcome.learn.plugins.title"_lang, "hex.builtin.welcome.learn.plugins.desc"_lang, ImVec2(ImGui::GetContentRegionAvail().x * 0.8F, 0)))
|
|
|
|
hex::openWebpage("hex.builtin.welcome.learn.plugins.link"_lang);
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
auto extraWelcomeScreenEntries = ContentRegistry::Interface::impl::getWelcomeScreenEntries();
|
2022-02-01 18:09:40 +01:00
|
|
|
if (!extraWelcomeScreenEntries.empty()) {
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 5);
|
|
|
|
ImGui::TableNextColumn();
|
2022-02-02 00:36:09 +01:00
|
|
|
ImGui::UnderlinedText("hex.builtin.welcome.header.various"_lang);
|
2022-02-01 18:09:40 +01:00
|
|
|
{
|
|
|
|
for (const auto &callback : extraWelcomeScreenEntries)
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
2022-08-10 10:28:40 +02:00
|
|
|
|
2023-05-11 12:00:45 +02:00
|
|
|
ImGui::SetCursorPos(ImVec2(ImGui::GetContentRegionAvail().x + ImGui::GetStyle().FramePadding.x, ImGui::GetStyle().FramePadding.y * 2 - 1));
|
|
|
|
if (ImGui::DimmedIconButton(ICON_VS_CLOSE, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed))) {
|
2022-08-10 10:28:40 +02:00
|
|
|
auto provider = ImHexApi::Provider::createProvider("hex.builtin.provider.null");
|
|
|
|
if (provider != nullptr)
|
2022-09-04 11:16:20 +02:00
|
|
|
if (provider->open())
|
|
|
|
EventManager::post<EventProviderOpened>(provider);
|
2022-08-10 10:28:40 +02:00
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void drawWelcomeScreen() {
|
2022-02-06 21:39:10 +01:00
|
|
|
if (ImGui::Begin("ImHexDockSpace")) {
|
2022-02-01 18:09:40 +01:00
|
|
|
if (!ImHexApi::Provider::isValid()) {
|
2023-05-22 10:37:30 +02:00
|
|
|
static std::array<char, 256> title;
|
|
|
|
ImFormatString(title.data(), title.size(), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("ImHexMainDock"));
|
2023-11-02 08:54:02 +01:00
|
|
|
if (ImGui::Begin(title.data(), nullptr, ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoBringToFrontOnFocus)) {
|
|
|
|
ImGui::Dummy({});
|
2023-11-05 21:17:37 +01:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, scaled({ 10, 10 }));
|
2023-05-22 10:37:30 +02:00
|
|
|
|
2023-11-05 21:17:37 +01:00
|
|
|
ImGui::SetNextWindowScroll({ 0.0F, -1.0F });
|
2023-11-02 08:54:02 +01:00
|
|
|
ImGui::SetNextWindowSize(ImGui::GetContentRegionAvail() + scaled({ 0, 10 }));
|
2023-11-05 21:17:37 +01:00
|
|
|
ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos() - ImVec2(0, ImGui::GetStyle().FramePadding.y + 2_scaled));
|
2023-11-02 09:34:03 +01:00
|
|
|
if (ImGui::Begin("Welcome Screen", nullptr, ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) {
|
2022-02-01 18:09:40 +01:00
|
|
|
drawWelcomeScreenContent();
|
|
|
|
}
|
2023-11-02 08:54:02 +01:00
|
|
|
ImGui::End();
|
2022-02-01 18:09:40 +01:00
|
|
|
ImGui::PopStyleVar();
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
2023-05-05 22:02:18 +02:00
|
|
|
/**
|
2023-11-04 22:10:34 +01:00
|
|
|
* @brief Draw some default background if there are no views available in the current layout
|
2023-05-05 22:02:18 +02:00
|
|
|
*/
|
2022-07-06 10:21:02 +02:00
|
|
|
static void drawNoViewsBackground() {
|
|
|
|
if (ImGui::Begin("ImHexDockSpace")) {
|
2023-11-04 22:10:34 +01:00
|
|
|
static std::array<char, 256> title;
|
|
|
|
ImFormatString(title.data(), title.size(), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("ImHexMainDock"));
|
|
|
|
if (ImGui::Begin(title.data())) {
|
2023-11-07 16:40:37 +01:00
|
|
|
ImGui::Dummy({});
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, scaled({ 10, 10 }));
|
2023-11-02 08:54:02 +01:00
|
|
|
|
2023-11-07 16:40:37 +01:00
|
|
|
ImGui::SetNextWindowScroll({ 0.0F, -1.0F });
|
|
|
|
ImGui::SetNextWindowSize(ImGui::GetContentRegionAvail() + scaled({ 0, 10 }));
|
|
|
|
ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos() - ImVec2(0, ImGui::GetStyle().FramePadding.y + 2_scaled));
|
|
|
|
if (ImGui::Begin("Welcome Screen", nullptr, ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) {
|
2022-07-06 10:21:02 +02:00
|
|
|
auto imageSize = scaled(ImVec2(350, 350));
|
2023-05-05 22:00:17 +02:00
|
|
|
auto imagePos = (ImGui::GetContentRegionAvail() - imageSize) / 2;
|
2022-07-06 10:21:02 +02:00
|
|
|
|
2023-05-05 22:00:17 +02:00
|
|
|
ImGui::SetCursorPos(imagePos);
|
2022-07-06 10:21:02 +02:00
|
|
|
ImGui::Image(s_backdropTexture, imageSize);
|
2023-05-05 22:00:17 +02:00
|
|
|
|
|
|
|
auto loadDefaultText = "hex.builtin.layouts.none.restore_default"_lang;
|
|
|
|
auto textSize = ImGui::CalcTextSize(loadDefaultText);
|
|
|
|
|
2023-05-11 18:44:10 +02:00
|
|
|
auto textPos = ImVec2(
|
2023-05-05 22:00:17 +02:00
|
|
|
(ImGui::GetContentRegionAvail().x - textSize.x) / 2,
|
|
|
|
imagePos.y + imageSize.y
|
2023-05-11 18:44:10 +02:00
|
|
|
);
|
2023-05-05 22:00:17 +02:00
|
|
|
|
|
|
|
ImGui::SetCursorPos(textPos);
|
|
|
|
if (ImGui::DimmedButton(loadDefaultText)){
|
|
|
|
loadDefaultLayout();
|
|
|
|
}
|
2022-07-06 10:21:02 +02:00
|
|
|
}
|
2023-11-07 16:40:37 +01:00
|
|
|
|
2023-11-02 08:54:02 +01:00
|
|
|
ImGui::End();
|
2022-07-06 10:21:02 +02:00
|
|
|
ImGui::PopStyleVar();
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2023-05-05 22:02:18 +02:00
|
|
|
/**
|
|
|
|
* @brief Registers the event handlers related to the welcome screen
|
|
|
|
* should only be called once, at startup
|
|
|
|
*/
|
2022-02-01 18:09:40 +01:00
|
|
|
void createWelcomeScreen() {
|
2023-05-27 16:59:30 +02:00
|
|
|
recent::registerEventHandlers();
|
|
|
|
recent::updateRecentEntries();
|
2022-08-14 10:07:45 +02:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
(void)EventManager::subscribe<EventFrameBegin>(drawWelcomeScreen);
|
2023-05-05 22:02:18 +02:00
|
|
|
|
|
|
|
// Sets a background when they are no views
|
2022-09-05 14:16:31 +02:00
|
|
|
(void)EventManager::subscribe<EventFrameBegin>([]{
|
|
|
|
if (ImHexApi::Provider::isValid() && !isAnyViewOpen())
|
|
|
|
drawNoViewsBackground();
|
|
|
|
});
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-11-10 20:47:08 +01:00
|
|
|
(void)EventManager::subscribe<EventSettingsChanged>([] {
|
2022-02-01 18:09:40 +01:00
|
|
|
{
|
2023-10-21 23:07:33 +02:00
|
|
|
auto theme = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", ThemeManager::NativeTheme).get<std::string>();
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-03-23 20:35:16 +01:00
|
|
|
if (theme != ThemeManager::NativeTheme) {
|
2023-03-21 15:33:43 +01:00
|
|
|
static std::string lastTheme;
|
2022-02-19 00:35:07 +01:00
|
|
|
|
2023-03-21 15:33:43 +01:00
|
|
|
if (theme != lastTheme) {
|
|
|
|
EventManager::post<RequestChangeTheme>(theme);
|
|
|
|
lastTheme = theme;
|
2022-02-19 00:35:07 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-10-21 23:07:33 +02:00
|
|
|
auto language = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.language", "en-US").get<std::string>();
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-07-09 20:24:56 +02:00
|
|
|
if (language != LangEntry::getSelectedLanguage())
|
|
|
|
LangEntry::loadLanguage(language);
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-10-21 23:07:33 +02:00
|
|
|
auto targetFps = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.fps", 14).get<int>();
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-11-04 22:10:34 +01:00
|
|
|
ImHexApi::System::setTargetFPS(static_cast<float>(targetFps));
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-12-29 19:26:00 +01:00
|
|
|
(void)EventManager::subscribe<RequestChangeTheme>([](const std::string &theme) {
|
2022-09-18 20:38:45 +02:00
|
|
|
auto changeTexture = [&](const std::string &path) {
|
2023-08-26 23:43:35 +02:00
|
|
|
return ImGui::Texture(romfs::get(path).span());
|
2022-02-19 00:35:07 +01:00
|
|
|
};
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-03-23 20:35:16 +01:00
|
|
|
ThemeManager::changeTheme(theme);
|
2023-07-04 08:42:33 +02:00
|
|
|
s_bannerTexture = changeTexture(hex::format("assets/{}/banner.png", ThemeManager::getImageTheme()));
|
|
|
|
s_backdropTexture = changeTexture(hex::format("assets/{}/backdrop.png", ThemeManager::getImageTheme()));
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
if (!s_bannerTexture.isValid()) {
|
2022-02-01 18:09:40 +01:00
|
|
|
log::error("Failed to load banner texture!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-07-05 12:10:54 +02:00
|
|
|
EventManager::subscribe<EventProviderCreated>([](auto) {
|
2022-07-07 07:16:38 +02:00
|
|
|
if (!isAnyViewOpen())
|
|
|
|
loadDefaultLayout();
|
2022-02-01 18:09:40 +01:00
|
|
|
});
|
|
|
|
|
2022-10-29 23:43:40 +02:00
|
|
|
EventManager::subscribe<EventWindowInitialized>([] {
|
2023-10-04 12:00:32 +02:00
|
|
|
// Documentation of the value above the setting definition
|
2023-06-20 11:55:56 +02:00
|
|
|
auto allowServerContact = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 2);
|
|
|
|
if (allowServerContact == 2) {
|
|
|
|
ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 0);
|
2023-10-04 12:00:32 +02:00
|
|
|
|
|
|
|
// Open the telemetry popup but only on desktop versions
|
|
|
|
#if !defined(OS_WEB)
|
|
|
|
PopupTelemetryRequest::open();
|
|
|
|
#endif
|
2022-10-29 23:43:40 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
// Clear project context if we go back to the welcome screen
|
2023-11-10 20:47:08 +01:00
|
|
|
EventManager::subscribe<EventProviderChanged>([](const hex::prv::Provider *oldProvider, const hex::prv::Provider *newProvider) {
|
2023-01-07 17:31:22 +01:00
|
|
|
hex::unused(oldProvider);
|
|
|
|
if (newProvider == nullptr) {
|
|
|
|
ProjectFile::clearPath();
|
|
|
|
EventManager::post<RequestUpdateWindowTitle>();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-14 10:07:45 +02:00
|
|
|
|
2023-05-27 16:59:30 +02:00
|
|
|
recent::drawFileMenuItem();
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
// Check for crash backup
|
2023-05-22 13:24:48 +02:00
|
|
|
constexpr static auto CrashFileName = "crash.json";
|
|
|
|
constexpr static auto BackupFileName = "crash_backup.hexproj";
|
|
|
|
bool hasCrashed = false;
|
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Config)) {
|
2023-05-22 13:24:48 +02:00
|
|
|
if (auto crashFilePath = std::fs::path(path) / CrashFileName; wolv::io::fs::exists(crashFilePath)) {
|
|
|
|
hasCrashed = true;
|
|
|
|
|
|
|
|
log::info("Found crash.json file at {}", wolv::util::toUTF8String(crashFilePath));
|
|
|
|
wolv::io::File crashFile(crashFilePath, wolv::io::File::Mode::Read);
|
2023-05-28 11:35:51 +02:00
|
|
|
nlohmann::json crashFileData;
|
|
|
|
try {
|
|
|
|
crashFileData = nlohmann::json::parse(crashFile.readString());
|
|
|
|
} catch (nlohmann::json::exception &e) {
|
|
|
|
log::error("Failed to parse crash.json file: {}", e.what());
|
|
|
|
crashFile.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-05-22 13:24:48 +02:00
|
|
|
bool hasProject = !crashFileData.value("project", "").empty();
|
|
|
|
|
|
|
|
auto backupFilePath = path / BackupFileName;
|
|
|
|
bool hasBackupFile = wolv::io::fs::exists(backupFilePath);
|
2023-06-20 11:55:56 +02:00
|
|
|
|
2023-05-22 13:24:48 +02:00
|
|
|
PopupRestoreBackup::open(
|
2023-10-04 12:00:32 +02:00
|
|
|
// Path of log file
|
2023-05-22 13:24:48 +02:00
|
|
|
crashFileData.value("logFile", ""),
|
2023-10-04 12:00:32 +02:00
|
|
|
|
|
|
|
// Restore callback
|
|
|
|
[=] {
|
2023-05-22 13:24:48 +02:00
|
|
|
if (hasBackupFile) {
|
|
|
|
ProjectFile::load(backupFilePath);
|
|
|
|
if (hasProject) {
|
|
|
|
ProjectFile::setPath(crashFileData["project"].get<std::string>());
|
|
|
|
} else {
|
|
|
|
ProjectFile::setPath("");
|
|
|
|
}
|
|
|
|
EventManager::post<RequestUpdateWindowTitle>();
|
|
|
|
}else{
|
|
|
|
if (hasProject) {
|
|
|
|
ProjectFile::setPath(crashFileData["project"].get<std::string>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-10-04 12:00:32 +02:00
|
|
|
|
|
|
|
// Delete callback (also executed after restore)
|
|
|
|
[crashFilePath, backupFilePath] {
|
2023-05-22 13:24:48 +02:00
|
|
|
wolv::io::fs::remove(crashFilePath);
|
|
|
|
wolv::io::fs::remove(backupFilePath);
|
|
|
|
}
|
|
|
|
);
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-08 00:58:53 +02:00
|
|
|
// Tip of the day
|
2022-10-27 13:21:54 +02:00
|
|
|
auto tipsData = romfs::get("tips.json");
|
2023-05-22 13:24:48 +02:00
|
|
|
if (!hasCrashed && tipsData.valid()) {
|
2022-10-27 13:21:54 +02:00
|
|
|
auto tipsCategories = nlohmann::json::parse(tipsData.string());
|
|
|
|
|
|
|
|
auto now = std::chrono::system_clock::now();
|
|
|
|
auto days_since_epoch = std::chrono::duration_cast<std::chrono::days>(now.time_since_epoch());
|
|
|
|
std::mt19937 random(days_since_epoch.count());
|
|
|
|
|
2023-05-16 11:33:00 +02:00
|
|
|
auto chosenCategory = tipsCategories[random()%tipsCategories.size()].at("tips");
|
2022-10-27 13:21:54 +02:00
|
|
|
auto chosenTip = chosenCategory[random()%chosenCategory.size()];
|
|
|
|
s_tipOfTheDay = chosenTip.get<std::string>();
|
2022-02-01 18:09:40 +01:00
|
|
|
|
2023-10-21 23:07:33 +02:00
|
|
|
bool showTipOfTheDay = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", true);
|
2022-02-01 18:09:40 +01:00
|
|
|
if (showTipOfTheDay)
|
2023-04-08 00:58:53 +02:00
|
|
|
PopupTipOfTheDay::open();
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
2023-08-06 21:33:15 +02:00
|
|
|
|
|
|
|
if (hasCrashed) {
|
2023-11-08 21:40:27 +01:00
|
|
|
TaskManager::doLater([]{
|
|
|
|
AchievementManager::unlockAchievement("hex.builtin.achievement.starting_out", "hex.builtin.achievement.starting_out.crash.name");
|
|
|
|
});
|
2023-08-06 21:33:15 +02:00
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
}
|
|
|
|
|
2022-02-19 00:35:07 +01:00
|
|
|
}
|