1
0
mirror of synced 2024-09-24 03:28:24 +02:00

sys: Load Tips from a local file instead of querying an API (#797)

* store tips locally

* C++ random implementation

* show one different tip per day

* fix json conversion to string

* put tips.json in builtin romfs
This commit is contained in:
iTrooz_ 2022-10-27 13:21:54 +02:00 committed by GitHub
parent e567061e3c
commit 24c0cc10a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 15 deletions

View File

@ -45,18 +45,6 @@ namespace hex::init {
return true;
}
static bool downloadInformation() {
hex::Net net;
auto tip = net.getString(ImHexApiURL + "/tip"s, 200).get();
if (tip.code != 200)
return false;
ImHexApi::System::impl::addInitArgument("tip-of-the-day", tip.body);
return true;
}
bool createDirectories() {
bool result = true;
@ -319,7 +307,6 @@ namespace hex::init {
{ "Loading settings", loadSettings, false },
{ "Loading plugins", loadPlugins, false },
{ "Checking for updates", checkForUpdates, true },
{ "Downloading information", downloadInformation, true },
{ "Loading fonts", loadFonts, true },
};
}

View File

@ -0,0 +1,23 @@
[
{
"name" : "ImHex",
"tips" : [
"Try pressing CTRL + Shift + P to open the command palette!",
"The data processor allows pre-processing of the binary input data before it's displayed without modifying the original data.",
"Take a closer look at the Splash screen :)",
"Check out the WerWolv/ImHex-Patterns repository for pre-made patterns and more!",
"ImHex can be easily extended with plugins through its API."
]
},
{
"name" : "Reverse Engineering",
"tips" : [
"Reverse Engineering a foreign file format becomes a lot easier if you know some values that should be stored in there.",
"Ghidra, binwalk, Unicorn, x86dbg, DetectItEasy, Dependencies and CheatEngine are other fantastic and free reverse engineering tools!",
"ALWAYS read the documentation if there is one. It will save you a lot of time.",
"Tools are what you make of them, practice makes perfect.",
"Looking for patterns and repeating structures in binary data is always a good start.",
"The entropy graph is an easy way to quickly figure out where interesting data is stored and if the data is encrypted or compressed."
]
}
]

View File

@ -22,6 +22,7 @@
#include <string>
#include <list>
#include <unordered_set>
#include <random>
namespace hex::plugin::builtin {
@ -549,8 +550,17 @@ namespace hex::plugin::builtin {
}
}
if (ImHexApi::System::getInitArguments().contains("tip-of-the-day")) {
s_tipOfTheDay = ImHexApi::System::getInitArguments()["tip-of-the-day"];
auto tipsData = romfs::get("tips.json");
if(tipsData.valid()){
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());
auto chosenCategory = tipsCategories[random()%tipsCategories.size()]["tips"];
auto chosenTip = chosenCategory[random()%chosenCategory.size()];
s_tipOfTheDay = chosenTip.get<std::string>();
bool showTipOfTheDay = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", 1);
if (showTipOfTheDay)