2022-03-04 19:06:29 +01:00
# include "content/views/view_about.hpp"
2022-02-01 18:09:40 +01:00
# include <hex/api/content_registry.hpp>
2020-11-14 21:16:03 +01:00
2021-09-06 20:35:38 +02:00
# include <hex/helpers/fmt.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/utils.hpp>
2021-09-06 20:35:38 +02:00
2022-01-22 23:11:28 +01:00
# include <romfs/romfs.hpp>
2021-12-07 22:47:41 +01:00
namespace hex : : plugin : : builtin {
2020-11-14 21:16:03 +01:00
2022-03-04 19:06:29 +01:00
ViewAbout : : ViewAbout ( ) : View ( " hex.builtin.view.help.about.name " ) {
2022-01-23 02:28:38 +01:00
ContentRegistry : : Interface : : addMenuItem ( " hex.builtin.menu.help " , 1000 , [ & , this ] {
if ( ImGui : : MenuItem ( " hex.builtin.view.help.about.name " _lang , " " ) ) {
2022-08-17 16:15:36 +02:00
TaskManager : : doLater ( [ ] { ImGui : : OpenPopup ( View : : toWindowName ( " hex.builtin.view.help.about.name " ) . c_str ( ) ) ; } ) ;
2022-02-01 22:09:44 +01:00
this - > m_aboutWindowOpen = true ;
2022-01-23 02:28:38 +01:00
this - > getWindowOpenState ( ) = true ;
}
if ( ImGui : : MenuItem ( " hex.builtin.view.help.documentation " _lang , " " ) ) {
hex : : openWebpage ( " https://imhex.werwolv.net/docs " ) ;
}
} ) ;
2020-11-14 21:16:03 +01:00
}
2022-03-04 19:06:29 +01:00
static void link ( const std : : string & name , const std : : string & author , const std : : string & url ) {
if ( ImGui : : BulletHyperlink ( name . c_str ( ) ) )
2022-01-23 20:46:19 +01:00
hex : : openWebpage ( url ) ;
2022-03-04 19:06:29 +01:00
if ( ImGui : : IsItemHovered ( ) ) {
ImGui : : BeginTooltip ( ) ;
ImGui : : TextFormatted ( " {} " , url ) ;
ImGui : : EndTooltip ( ) ;
}
if ( ! author . empty ( ) ) {
ImGui : : SameLine ( 0 , 0 ) ;
ImGui : : TextFormatted ( " by {} " , author ) ;
}
2020-11-30 21:44:40 +01:00
}
2022-03-04 19:06:29 +01:00
void ViewAbout : : drawAboutMainPage ( ) {
2022-01-23 20:46:19 +01:00
if ( ImGui : : BeginTable ( " about_table " , 2 , ImGuiTableFlags_SizingFixedFit ) ) {
ImGui : : TableNextRow ( ) ;
ImGui : : TableNextColumn ( ) ;
2022-09-18 20:38:45 +02:00
if ( ! this - > m_logoTexture . isValid ( ) ) {
2022-02-01 22:09:44 +01:00
auto logo = romfs : : get ( " logo.png " ) ;
2022-09-18 20:38:45 +02:00
this - > m_logoTexture = ImGui : : Texture ( reinterpret_cast < const ImU8 * > ( logo . data ( ) ) , logo . size ( ) ) ;
2022-01-23 20:46:19 +01:00
}
2022-09-18 20:38:45 +02:00
ImGui : : Image ( this - > m_logoTexture , scaled ( { 64 , 64 } ) ) ;
2022-01-23 20:46:19 +01:00
ImGui : : TableNextColumn ( ) ;
2021-08-25 19:54:59 +02:00
2022-01-23 20:46:19 +01:00
ImGui : : TextFormatted ( " ImHex Hex Editor v{} by WerWolv - " ICON_FA_CODE_BRANCH , IMHEX_VERSION ) ;
2021-12-12 13:35:07 +01:00
2022-01-24 20:53:17 +01:00
# if defined(GIT_BRANCH) && defined(GIT_COMMIT_HASH)
ImGui : : SameLine ( ) ;
if ( ImGui : : Hyperlink ( hex : : format ( " {0}@{1} " , GIT_BRANCH , GIT_COMMIT_HASH ) . c_str ( ) ) )
hex : : openWebpage ( " https://github.com/WerWolv/ImHex/commit/ " GIT_COMMIT_HASH ) ;
# endif
2022-01-23 20:46:19 +01:00
ImGui : : TextUnformatted ( " hex.builtin.view.help.about.translator " _lang ) ;
2022-01-24 20:53:17 +01:00
ImGui : : TextUnformatted ( " hex.builtin.view.help.about.source " _lang ) ;
ImGui : : SameLine ( ) ;
2022-01-23 20:46:19 +01:00
if ( ImGui : : Hyperlink ( " WerWolv/ImHex " ) )
hex : : openWebpage ( " https://github.com/WerWolv/ImHex " ) ;
ImGui : : EndTable ( ) ;
}
2020-11-30 21:44:40 +01:00
ImGui : : NewLine ( ) ;
2021-12-12 13:35:07 +01:00
ImGui : : TextUnformatted ( " hex.builtin.view.help.about.donations " _lang ) ;
ImGui : : Separator ( ) ;
2020-11-14 21:16:03 +01:00
2022-01-24 20:53:17 +01:00
constexpr const char * Links [ ] = { " https://werwolv.net/donate " , " https://www.patreon.com/werwolv " , " https://github.com/sponsors/WerWolv " } ;
2021-12-12 13:35:07 +01:00
2022-01-15 14:14:53 +01:00
ImGui : : TextFormattedWrapped ( " {} " , static_cast < const char * > ( " hex.builtin.view.help.about.thanks " _lang ) ) ;
2021-12-12 13:35:07 +01:00
ImGui : : NewLine ( ) ;
2021-01-23 00:46:50 +01:00
2021-12-12 13:35:07 +01:00
for ( auto & link : Links ) {
if ( ImGui : : Hyperlink ( link ) )
hex : : openWebpage ( link ) ;
}
}
2021-01-23 00:46:50 +01:00
2022-03-04 19:06:29 +01:00
void ViewAbout : : drawContributorPage ( ) {
ImGui : : TextFormattedWrapped ( " These amazing people have contributed to ImHex in the past. If you'd like to become part of them, please submit a PR to the GitHub Repository! " ) ;
ImGui : : NewLine ( ) ;
link ( " Mary for porting ImHex to MacOS " , " " , " https://github.com/Thog " ) ;
link ( " Roblabla for adding the MSI Windows installer " , " " , " https://github.com/roblabla " ) ;
link ( " jam1garner for adding support for Rust plugins " , " " , " https://github.com/jam1garner " ) ;
ImGui : : NewLine ( ) ;
link ( " All other amazing contributors " , " " , " https://github.com/WerWolv/ImHex/graphs/contributors/ " ) ;
2021-12-12 13:35:07 +01:00
}
2021-01-23 00:46:50 +01:00
2022-03-04 19:06:29 +01:00
void ViewAbout : : drawLibraryCreditsPage ( ) {
2021-12-12 13:35:07 +01:00
ImGui : : PushStyleColor ( ImGuiCol_ChildBg , ImVec4 ( 0.2F , 0.2F , 0.2F , 0.3F ) ) ;
2021-01-23 00:46:50 +01:00
2022-03-04 19:06:29 +01:00
link ( " ImGui " , " ocornut " , " https://github.com/ocornut/imgui/ " ) ;
link ( " imgui_club " , " ocornut " , " https://github.com/ocornut/imgui_club/ " ) ;
link ( " imnodes " , " Nelarius " , " https://github.com/Nelarius/imnodes/ " ) ;
link ( " ImGuiColorTextEdit " , " BalazsJako " , " https://github.com/BalazsJako/ImGuiColorTextEdit/ " ) ;
link ( " ImPlot " , " epezent " , " https://github.com/epezent/implot/ " ) ;
ImGui : : NewLine ( ) ;
link ( " capstone " , " aquynh " , " https://github.com/aquynh/capstone/ " ) ;
link ( " JSON for Modern C++ " , " nlohmann " , " https://github.com/nlohmann/json/ " ) ;
link ( " YARA " , " VirusTotal " , " https://github.com/VirusTotal/yara/ " ) ;
link ( " Native File Dialog Extended " , " btzy and mlabbe " , " https://github.com/btzy/nativefiledialog-extended/ " ) ;
link ( " libromfs " , " WerWolv " , " https://github.com/WerWolv/libromfs/ " ) ;
link ( " microtar " , " rxi " , " https://github.com/rxi/microtar/ " ) ;
link ( " xdgpp " , " danyspin97 " , " https://sr.ht/~danyspin97/xdgpp/ " ) ;
link ( " FreeType " , " David Turner " , " https://gitlab.freedesktop.org/freetype/freetype/ " ) ;
link ( " Mbed TLS " , " ARM " , " https://github.com/ARMmbed/mbedtls/ " ) ;
link ( " libcurl " , " Daniel Stenberg " , " https://curl.se/ " ) ;
link ( " libfmt " , " vitaut " , " https://fmt.dev/ " ) ;
2021-12-12 13:35:07 +01:00
ImGui : : NewLine ( ) ;
2022-03-04 19:06:29 +01:00
link ( " GNU libmagic " , " " , " https://www.darwinsys.com/file/ " ) ;
link ( " GLFW3 " , " " , " https://github.com/glfw/glfw/ " ) ;
link ( " LLVM " , " " , " https://github.com/llvm/llvm-project/ " ) ;
link ( " Python 3 " , " " , " https://github.com/python/cpython/ " ) ;
2021-01-23 00:46:50 +01:00
2021-12-12 13:35:07 +01:00
ImGui : : PopStyleColor ( ) ;
2022-03-04 19:06:29 +01:00
ImGui : : NewLine ( ) ;
2021-12-12 13:35:07 +01:00
}
2021-01-23 00:46:50 +01:00
2022-03-04 19:06:29 +01:00
void ViewAbout : : drawPathsPage ( ) {
2021-12-12 13:35:07 +01:00
if ( ImGui : : BeginTable ( " ##imhex_paths " , 2 , ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit ) ) {
ImGui : : TableSetupScrollFreeze ( 0 , 1 ) ;
ImGui : : TableSetupColumn ( " Type " ) ;
ImGui : : TableSetupColumn ( " Paths " ) ;
2022-09-12 21:28:02 +02:00
constexpr static std : : array < std : : pair < const char * , fs : : ImHexPath > , 8 > PathTypes = {
2022-03-04 11:36:37 +01:00
{ { " Resources " , fs : : ImHexPath : : Resources } ,
{ " Config " , fs : : ImHexPath : : Config } ,
{ " Magic " , fs : : ImHexPath : : Magic } ,
{ " Patterns " , fs : : ImHexPath : : Patterns } ,
{ " Patterns Includes " , fs : : ImHexPath : : PatternsInclude } ,
{ " Plugins " , fs : : ImHexPath : : Plugins } ,
{ " Python Scripts " , fs : : ImHexPath : : Python } ,
{ " Yara Patterns " , fs : : ImHexPath : : Yara } }
2022-01-24 20:53:17 +01:00
} ;
2021-12-12 13:35:07 +01:00
ImGui : : TableHeadersRow ( ) ;
for ( const auto & [ name , type ] : PathTypes ) {
ImGui : : TableNextRow ( ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : TextUnformatted ( name ) ;
ImGui : : TableNextColumn ( ) ;
2022-10-13 08:07:46 +02:00
for ( auto & path : fs : : getDefaultPaths ( type , true ) ) {
if ( fs : : isDirectory ( path ) ) {
ImGui : : TextUnformatted ( hex : : toUTF8String ( path ) . c_str ( ) ) ;
} else {
ImGui : : TextFormattedColored ( ImGui : : GetCustomColorVec4 ( ImGuiCustomCol_ToolbarRed ) , hex : : toUTF8String ( path ) . c_str ( ) ) ;
}
}
2021-01-23 00:46:50 +01:00
}
2021-12-12 13:35:07 +01:00
ImGui : : EndTable ( ) ;
}
}
2022-03-04 19:06:29 +01:00
void ViewAbout : : drawLicensePage ( ) {
2022-01-22 23:11:28 +01:00
ImGui : : TextFormattedWrapped ( " {} " , romfs : : get ( " LICENSE " ) . string ( ) ) ;
}
2022-03-04 19:06:29 +01:00
void ViewAbout : : drawAboutPopup ( ) {
2022-01-11 23:48:18 +01:00
ImGui : : SetNextWindowSize ( scaled ( ImVec2 ( 600 , 350 ) ) , ImGuiCond_Always ) ;
2021-12-12 13:35:07 +01:00
if ( ImGui : : BeginPopupModal ( View : : toWindowName ( " hex.builtin.view.help.about.name " ) . c_str ( ) , & this - > m_aboutWindowOpen , ImGuiWindowFlags_NoResize ) ) {
2021-01-14 17:01:44 +01:00
if ( ImGui : : IsKeyDown ( ImGui : : GetKeyIndex ( ImGuiKey_Escape ) ) )
ImGui : : CloseCurrentPopup ( ) ;
2021-12-12 13:35:07 +01:00
if ( ImGui : : BeginTabBar ( " about_tab_bar " ) ) {
if ( ImGui : : BeginTabItem ( " ImHex " ) ) {
2022-01-24 00:45:46 +01:00
if ( ImGui : : BeginChild ( 1 ) ) {
this - > drawAboutMainPage ( ) ;
}
ImGui : : EndChild ( ) ;
2021-12-12 13:35:07 +01:00
ImGui : : EndTabItem ( ) ;
2021-05-23 23:35:04 +02:00
}
2021-12-12 13:35:07 +01:00
if ( ImGui : : BeginTabItem ( " hex.builtin.view.help.about.contributor " _lang ) ) {
ImGui : : NewLine ( ) ;
2022-01-24 00:45:46 +01:00
if ( ImGui : : BeginChild ( 1 ) ) {
this - > drawContributorPage ( ) ;
}
ImGui : : EndChild ( ) ;
2021-12-12 13:35:07 +01:00
ImGui : : EndTabItem ( ) ;
}
2021-05-23 23:35:04 +02:00
2021-12-12 13:35:07 +01:00
if ( ImGui : : BeginTabItem ( " hex.builtin.view.help.about.libs " _lang ) ) {
ImGui : : NewLine ( ) ;
2022-01-24 00:45:46 +01:00
if ( ImGui : : BeginChild ( 1 ) ) {
this - > drawLibraryCreditsPage ( ) ;
}
ImGui : : EndChild ( ) ;
2021-12-12 13:35:07 +01:00
ImGui : : EndTabItem ( ) ;
}
2020-11-14 21:16:03 +01:00
2021-12-12 13:35:07 +01:00
if ( ImGui : : BeginTabItem ( " hex.builtin.view.help.about.paths " _lang ) ) {
ImGui : : NewLine ( ) ;
2022-01-24 00:45:46 +01:00
if ( ImGui : : BeginChild ( 1 ) ) {
this - > drawPathsPage ( ) ;
}
ImGui : : EndChild ( ) ;
2021-12-12 13:35:07 +01:00
ImGui : : EndTabItem ( ) ;
}
2020-11-30 21:44:40 +01:00
2022-01-22 23:11:28 +01:00
if ( ImGui : : BeginTabItem ( " hex.builtin.view.help.about.license " _lang ) ) {
ImGui : : NewLine ( ) ;
2022-01-24 00:45:46 +01:00
if ( ImGui : : BeginChild ( 1 ) ) {
this - > drawLicensePage ( ) ;
}
ImGui : : EndChild ( ) ;
2022-01-22 23:11:28 +01:00
ImGui : : EndTabItem ( ) ;
}
2021-12-12 13:35:07 +01:00
ImGui : : EndTabBar ( ) ;
}
2020-11-30 21:44:40 +01:00
2021-12-12 13:35:07 +01:00
ImGui : : EndPopup ( ) ;
2020-11-14 21:16:03 +01:00
}
}
2022-03-04 19:06:29 +01:00
void ViewAbout : : drawContent ( ) {
2021-12-12 13:35:07 +01:00
if ( ! this - > m_aboutWindowOpen )
2021-01-27 14:26:24 +01:00
this - > getWindowOpenState ( ) = false ;
2020-11-17 13:59:16 +01:00
this - > drawAboutPopup ( ) ;
2020-11-14 21:16:03 +01:00
}
2021-08-25 19:54:59 +02:00
}