33#define EXCEPTION_HEADER " I'VE GOT A PRESENT FOR YA"
44#define RESOURCES " Resources"
55#define BINARIES " Resources/Binaries"
6+ #define ERROR_HEADER " Error"
67
78#include < vector>
8- #include < cstdlib>
99#include < string>
1010#include < filesystem>
1111#include < iostream>
12+ #include < windows.h>
1213
1314// Links local executable to the main application of the project
1415int main (int argc, const char ** argv)
1516{
17+ // Disable console from the start
18+ ShowWindow (GetConsoleWindow (), SW_HIDE);
19+
1620 // Create /Logs if they doesn't exists
1721 std::filesystem::create_directory (" Logs" );
1822
1923 if (!std::filesystem::exists (RESOURCES))
2024 {
21- std::cout << " Folder \" " << RESOURCES <<" \" doesn't exist!" << std::endl
22- << " You cannot use Hotkey Editor without configs and Qt binary files." << std::endl
23- << " Check your installation instruction." << std::endl;
25+ std::string msg = std::string () + RESOURCES + " folder doesn't exist!" + ' \n ' +
26+ " You cannot use Hotkey Editor without configs and Qt binary files." + ' \n ' +
27+ " Please, check your installation instruction." + ' \n ' ;
28+ std::cout << msg.c_str () << std::endl;
29+ MessageBox (HWND_DESKTOP, msg.c_str (), ERROR_HEADER, MB_OK);
2430 return -1 ;
2531 }
2632
2733 if (!std::filesystem::exists (BINARIES))
2834 {
29- std::cout << " Folder \" " << BINARIES << " \" doesn't exist!" << std::endl
30- << " You cannot use Hotkey Editor without Qt binary files." << std::endl
31- << " Check your installation instruction." << std::endl;
35+ std::string msg = std::string () + BINARIES + " folder doesn't exist!" + ' \n ' +
36+ " You cannot use Hotkey Editor without configs and Qt binary files." + ' \n ' +
37+ " Please, check your installation instruction." + ' \n ' ;
38+ std::cout << msg.c_str () << std::endl;
39+ MessageBox (HWND_DESKTOP, msg.c_str (), ERROR_HEADER, MB_OK);
3240 return -1 ;
3341 }
3442
@@ -38,23 +46,31 @@ int main(int argc, const char** argv)
3846 std::vector<std::string> vec;
3947 vec.reserve (3 );
4048
41- // Split Cmake's path by / in PROJECT_EXE_RELATIVE_PATH
49+ // Split Cmake's path by / in PROJECT_EXE_RELATIVE_PATH string
4250 while (getline (ss, tmp, del))
4351 vec.push_back (tmp);
4452
45- // Concat all stirng parts with \ character and excluding the last
46- std::string accum = vec.at (0 );
53+ // Combine all dirs into single string
54+ std::string dir = vec.at (0 );
4755 for (int i = 1 ; i < vec.size () - 1 ; i++)
48- accum += ' \\ ' + vec.at (i);
56+ dir += ' \\ ' + vec.at (i);
4957
50- // Form command like `start /D "Resources\Binaries" LoadEditor.exe`
51- std::string realExecutablePath = " start /D \" " + accum + " \" " + " " + vec.at (vec.size () - 1 );
58+ // Refactor later to work with UTF-8 and provide args to the real executable.
59+ HINSTANCE hRet = ShellExecuteA (
60+ HWND_DESKTOP, // Parent window
61+ " open" , // Operation to perform
62+ vec.at (vec.size () - 1 ).c_str (), // Path to program
63+ NULL , // Parameters
64+ dir.c_str (), // Default directory
65+ SW_HIDE); // How to open
5266
53- // Add commands from argv. Skip first argument because it is just MainStarter.cpp .exe name
54- for (int i = 1 ; i < argc; i++)
55- realExecutablePath += " " + std::string (argv[i]);
67+ if (reinterpret_cast <size_t >(hRet) <= 32 )
68+ {
69+ std::string msg = std::string () + " Unable to start editor, error code: " + std::to_string (reinterpret_cast <size_t >(hRet));
70+ MessageBox (HWND_DESKTOP, msg.c_str (), ERROR_HEADER, MB_OK);
71+ return -1 ;
72+ }
5673
57- // Call the main executable
58- return system (realExecutablePath.c_str ());
74+ return 0 ;
5975}
6076#endif
0 commit comments