2021-02-10 17:17:09 +00:00
# include <hex.hpp>
2021-08-29 20:15:18 +00:00
# include <hex/helpers/utils.hpp>
# include <hex/helpers/logger.hpp>
2020-11-10 14:26:38 +00:00
# include "window.hpp"
2021-04-20 19:46:48 +00:00
# include "init/splash_window.hpp"
# include "init/tasks.hpp"
2021-09-08 13:18:24 +00:00
# include <hex/helpers/file.hpp>
2021-12-22 12:16:51 +00:00
int main ( int argc , char * * argv , char * * envp ) {
2021-01-13 16:28:27 +00:00
using namespace hex ;
2022-02-01 17:09:40 +00:00
ImHexApi : : System : : impl : : setProgramArguments ( argc , argv , envp ) ;
2021-01-13 16:28:27 +00:00
2022-02-15 21:36:36 +00:00
# if defined(OS_WINDOWS)
2022-02-15 22:07:48 +00:00
ImHexApi : : System : : impl : : setBorderlessWindowMode ( true ) ;
2022-02-15 21:36:36 +00:00
# endif
2021-04-20 19:46:48 +00:00
// Initialization
{
2021-08-22 18:24:42 +00:00
Window : : initNative ( ) ;
2022-01-13 13:34:27 +00:00
hex : : log : : info ( " Welcome to ImHex! " ) ;
2021-12-30 22:21:32 +00:00
init : : WindowSplash splashWindow ;
2021-04-20 19:46:48 +00:00
2022-02-15 22:07:48 +00:00
// Intel's OpenGL driver has weird bugs that cause the drawn window to be offset to the bottom right.
// This can be fixed by either using Mesa3D's OpenGL Software renderer or by simply disabling it.
// If you want to try if it works anyways on your GPU, set the hex.builtin.setting.interface.force_borderless_window_mode setting to 1
2022-02-17 14:22:29 +00:00
if ( ImHexApi : : System : : isBorderlessWindowModeEnabled ( ) ) {
bool isIntelGPU = hex : : containsIgnoreCase ( splashWindow . getGPUVendor ( ) , " Intel " ) ;
ImHexApi : : System : : impl : : setBorderlessWindowMode ( ! isIntelGPU ) ;
2022-02-15 22:07:48 +00:00
2022-02-17 14:22:29 +00:00
if ( isIntelGPU )
log : : warn ( " Intel GPU detected! Intel's OpenGL driver has bugs that can cause issues when using ImHex. If you experience any rendering bugs, please try the Mesa3D Software Renderer " ) ;
}
2022-02-15 22:07:48 +00:00
2021-04-20 19:46:48 +00:00
for ( const auto & [ name , task ] : init : : getInitTasks ( ) )
splashWindow . addStartupTask ( name , task ) ;
if ( ! splashWindow . loop ( ) )
2022-02-01 17:09:40 +00:00
ImHexApi : : System : : getInitArguments ( ) . insert ( { " tasks-failed " , { } } ) ;
2021-04-20 19:46:48 +00:00
}
// Clean up
ON_SCOPE_EXIT {
for ( const auto & [ name , task ] : init : : getExitTasks ( ) )
task ( ) ;
} ;
// Main window
{
2022-02-15 22:07:48 +00:00
Window window ;
2021-04-20 19:46:48 +00:00
if ( argc = = 1 )
2022-01-24 19:53:17 +00:00
; // No arguments provided
2021-04-20 19:46:48 +00:00
else if ( argc = = 2 )
2021-09-08 13:18:24 +00:00
EventManager : : post < RequestOpenFile > ( argv [ 1 ] ) ;
2021-04-20 19:46:48 +00:00
else {
2022-01-13 13:34:27 +00:00
hex : : log : : fatal ( " Usage: {} [<file_name>] " , argv [ 0 ] ) ;
2021-08-20 22:51:50 +00:00
return EXIT_FAILURE ;
2021-04-20 19:46:48 +00:00
}
window . loop ( ) ;
}
2021-01-12 15:50:15 +00:00
return EXIT_SUCCESS ;
2020-11-10 14:26:38 +00:00
}