-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: More cleanup of the main file
- Loading branch information
Showing
9 changed files
with
210 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "messaging.hpp" | ||
|
||
#include <hex/subcommands/subcommands.hpp> | ||
|
||
#include <hex/api/plugin_manager.hpp> | ||
#include <hex/helpers/fs.hpp> | ||
#include <hex/helpers/logger.hpp> | ||
|
||
#include <wolv/utils/guards.hpp> | ||
|
||
|
||
#if defined(OS_WINDOWS) | ||
#include <windows.h> | ||
#include <shellapi.h> | ||
#include <codecvt> | ||
#endif | ||
|
||
namespace hex::init { | ||
|
||
/** | ||
* @brief Handles commands passed to ImHex via the command line | ||
* @param argc Argument count | ||
* @param argv Argument values | ||
*/ | ||
void runCommandLine(int argc, char **argv) { | ||
// Suspend logging while processing command line arguments so | ||
// we don't spam the console with log messages while printing | ||
// CLI tool messages | ||
log::suspendLogging(); | ||
ON_SCOPE_EXIT { | ||
log::resumeLogging(); | ||
}; | ||
|
||
std::vector<std::string> args; | ||
|
||
#if defined (OS_WINDOWS) | ||
hex::unused(argv); | ||
|
||
// On Windows, argv contains UTF-16 encoded strings, so we need to convert them to UTF-8 | ||
auto convertedCommandLine = ::CommandLineToArgvW(::GetCommandLineW(), &argc); | ||
if (convertedCommandLine == nullptr) { | ||
log::error("Failed to convert command line arguments to UTF-8"); | ||
std::exit(EXIT_FAILURE); | ||
} | ||
|
||
// Skip the first argument (the executable path) and convert the rest to a vector of UTF-8 strings | ||
for (int i = 1; i < argc; i += 1) { | ||
std::wstring wcharArg = convertedCommandLine[i]; | ||
std::string utf8Arg = std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>().to_bytes(wcharArg); | ||
|
||
args.push_back(utf8Arg); | ||
} | ||
|
||
::LocalFree(convertedCommandLine); | ||
#else | ||
// Skip the first argument (the executable path) and convert the rest to a vector of strings | ||
args = { argv + 1, argv + argc }; | ||
#endif | ||
|
||
|
||
// Load all plugins but don't initialize them | ||
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Plugins)) { | ||
PluginManager::load(dir); | ||
} | ||
|
||
// Setup messaging system to allow sending commands to the main ImHex instance | ||
hex::messaging::setupMessaging(); | ||
|
||
// Process the arguments | ||
hex::subcommands::processArguments(args); | ||
|
||
// Unload plugins again | ||
PluginManager::unload(); | ||
} | ||
|
||
} |
Oops, something went wrong.