Skip to content

Commit 276269e

Browse files
Revert "Rethinking executable dependecies"
This reverts commit 0272c68.
1 parent 587e3f6 commit 276269e

File tree

5 files changed

+146
-9
lines changed

5 files changed

+146
-9
lines changed

CmakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
22

33
if (NOT WIN32)
4-
message(FATAL_ERROR "This program has been specified to compile on Microsoft Windows only.")
4+
message(FATAL_ERROR "This program has been specified to compile on Microsoft Windows OS only.")
55
endif()
66

77
set(CMAKE_CXX_STANDARD 20)
@@ -23,7 +23,7 @@ file(MAKE_DIRECTORY ${PROJECT_DESTINATION_RESOURCES_FOLDER})
2323
file(MAKE_DIRECTORY ${PROJECT_DESTINATION_BIN_FOLDER})
2424
file(MAKE_DIRECTORY ${PROJECT_DESTINATION_LOGS_FOLDER})
2525

26-
# Do not remove this prefix path
26+
# TODO: temporary
2727
set(CMAKE_PREFIX_PATH "C:/Qt/5.15.2/mingw81_64" "C:/Qt/Tools/mingw_64")
2828

2929
set(CMAKE_BUILD_PARALLEL_LEVEL 10)

src/CmakeLists.txt

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# Editor target name
2222
set(MAIN_TARGET_NAME "HotkeyEditor")
23-
set(ACTUAL_EXE_NAME "GenHotkeys")
23+
set(ACTUAL_EXE_NAME "LoadEditor")
2424

2525
# Define editor executable
2626
add_executable(${MAIN_TARGET_NAME})
@@ -39,6 +39,9 @@
3939

4040
# Remove all GUI sources from main sources list
4141
list(REMOVE_ITEM SOURCES ${EXCLUDED_GRAPHIC_SOURCES})
42+
43+
# Remove launch target source file from main sources list
44+
list(REMOVE_ITEM SOURCES "MainStarter.cpp")
4245

4346
# Assign source files to the main target
4447
target_sources(
@@ -52,7 +55,7 @@
5255
set_target_properties(
5356
${MAIN_TARGET_NAME}
5457
PROPERTIES
55-
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_DESTINATION_FOLDER}
58+
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_DESTINATION_BIN_FOLDER}
5659
OUTPUT_NAME ${ACTUAL_EXE_NAME}
5760
)
5861

@@ -64,6 +67,31 @@
6467

6568
# Add graphic dependency to the main target
6669
target_link_libraries(${MAIN_TARGET_NAME} PRIVATE GUI)
70+
71+
# Starter target configuration
72+
73+
# Starter target name
74+
set(STARTER_TARGET_NAME "HotkeyEditorStarter")
75+
76+
# Define starter executable with source files
77+
add_executable(
78+
${STARTER_TARGET_NAME}
79+
"MainStarter.cpp"
80+
"GUI/QtSources/StarterDescription.rc"
81+
)
82+
83+
# Define output directory and file name
84+
set_target_properties(
85+
${STARTER_TARGET_NAME}
86+
PROPERTIES
87+
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_DESTINATION_FOLDER}
88+
OUTPUT_NAME ${MAIN_TARGET_NAME}
89+
)
90+
91+
# Create a preprocessor variable with the path to the main program relative to the starter
92+
target_compile_definitions(${STARTER_TARGET_NAME} PRIVATE
93+
-DPROJECT_EXE_RELATIVE_PATH="$<PATH:RELATIVE_PATH,$<TARGET_FILE:${MAIN_TARGET_NAME}>,${PROJECT_DESTINATION_FOLDER}>"
94+
)
6795

6896
# Managing additional source files
6997

@@ -110,6 +138,7 @@
110138
find_program(QTENV_BAT qtenv2.bat)
111139

112140
if(CMAKE_BUILD_TYPE STREQUAL "Release")
141+
113142
# Deploy Qt and other dlls to the Editor/Resource folder
114143
add_custom_command(
115144
TARGET ${MAIN_TARGET_NAME}
@@ -120,7 +149,8 @@
120149
COMMAND ${WINDEPLOYQT_PROGRAM}
121150
--compiler-runtime
122151
--force
123-
--dir ${PROJECT_DESTINATION_BIN_FOLDER} # Actually redirects qt's libraries to the different folder
152+
--dir $<TARGET_PROPERTY:${MAIN_TARGET_NAME},RUNTIME_OUTPUT_DIRECTORY>
124153
$<TARGET_FILE:${MAIN_TARGET_NAME}>
125154
)
126-
endif()
155+
156+
endif()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
IDI_ICON1 ICON DISCARDABLE "EditorIcon.ico"
2+
3+
1 VERSIONINFO
4+
FILEVERSION 0,3,0,0
5+
PRODUCTVERSION 0,3,0,0
6+
BEGIN
7+
BLOCK "StringFileInfo"
8+
BEGIN
9+
BLOCK "040904E4"
10+
BEGIN
11+
VALUE "FileDescription", "Hotkeys Editor For C&C: Generals"
12+
VALUE "ProductVersion", "0.3.0.0"
13+
VALUE "FileVersion", "0.3.0.0"
14+
VALUE "ProductName", "GenHotkeys"
15+
VALUE "InternalName", "GenHotkeys"
16+
VALUE "OriginalFilename", "LoadEditor.exe"
17+
VALUE "CompanyName", "GenHotkeys Developers. All rights reserved."
18+
VALUE "LegalCopyright", "Copyright (C) GenHotkeys Devs 2023-2025"
19+
VALUE "Licence", "GNU GPL v3"
20+
VALUE "Info", "https://github.com/MahBoiDeveloper/GZHHotkeysEditor"
21+
VALUE "Comment", "GenHotkeys"
22+
END
23+
END
24+
25+
BLOCK "VarFileInfo"
26+
BEGIN
27+
VALUE "Translation", 0x409, 1252
28+
END
29+
END

src/Logger.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ using namespace std;
1717
// Disable console if it is really opened.
1818
ShowWindow(GetConsoleWindow(), SW_HIDE);
1919

20+
int i = 0;
21+
2022
vector<filesystem::directory_entry> files;
21-
for (const auto& entry : filesystem::directory_iterator("Logs"))
23+
for (const auto& entry : filesystem::directory_iterator("..\\..\\Logs"))
2224
if (entry.is_regular_file())
2325
files.push_back(entry);
2426

@@ -46,8 +48,8 @@ using namespace std;
4648
// Due to Logger is a singleton, we must create check if folder Logs exists.
4749
if (!LogFile.is_open())
4850
{
49-
filesystem::create_directory("Logs");
50-
LogFile.open(string("Logs") + GetLogFileName());
51+
filesystem::create_directory("..\\..\\Logs");
52+
LogFile.open(string("..\\..\\") + GetLogFileName());
5153
}
5254

5355
if (!LogFile.is_open())

src/MainStarter.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#ifdef PROJECT_EXE_RELATIVE_PATH
2+
3+
#define EXCEPTION_HEADER "I'VE GOT A PRESENT FOR YA"
4+
#define RESOURCES "Resources"
5+
#define BINARIES "Resources/Binaries"
6+
#define ERROR_HEADER "Error"
7+
8+
#include <vector>
9+
#include <string>
10+
#include <filesystem>
11+
#include <iostream>
12+
#include <windows.h>
13+
14+
// Links local executable to the main application of the project
15+
int main(int argc, const char** argv)
16+
{
17+
// Disable console from the start
18+
ShowWindow(GetConsoleWindow(), SW_HIDE);
19+
20+
// Create /Logs if they doesn't exists
21+
std::filesystem::create_directory("Logs");
22+
23+
if (!std::filesystem::exists(RESOURCES))
24+
{
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);
30+
return -1;
31+
}
32+
33+
if (!std::filesystem::exists(BINARIES))
34+
{
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);
40+
return -1;
41+
}
42+
43+
std::stringstream ss(PROJECT_EXE_RELATIVE_PATH);
44+
std::string tmp = "";
45+
const char del = '/';
46+
std::vector<std::string> vec;
47+
vec.reserve(3);
48+
49+
// Split Cmake's path by / in PROJECT_EXE_RELATIVE_PATH string
50+
while (getline(ss, tmp, del))
51+
vec.push_back(tmp);
52+
53+
// Combine all dirs into single string
54+
std::string dir = vec.at(0);
55+
for (int i = 1; i < vec.size() - 1; i++)
56+
dir += '\\' + vec.at(i);
57+
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
66+
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+
}
73+
74+
return 0;
75+
}
76+
#endif

0 commit comments

Comments
 (0)