-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfoscava.cpp
More file actions
42 lines (41 loc) · 1.73 KB
/
Infoscava.cpp
File metadata and controls
42 lines (41 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <filesystem>
#include <windows.h>
#include <cstdlib>
const std::string APP_SUBDIRECTORY = "main";
const std::string MAIN_EXECUTABLE_NAME = "main.exe";
int main(int argc, char* argv[]) {
char buffer[MAX_PATH];
GetModuleFileNameA(NULL, buffer, MAX_PATH);
std::filesystem::path launcher_path = buffer;
std::filesystem::path install_root_dir = launcher_path.parent_path();
std::filesystem::path main_app_executable_path = install_root_dir / APP_SUBDIRECTORY / MAIN_EXECUTABLE_NAME;
std::string arguments_to_pass = "";
char* user_profile_env = getenv("USERPROFILE");
std::string working_directory_for_main_app_str;
if (user_profile_env) {
working_directory_for_main_app_str = user_profile_env;
} else {
working_directory_for_main_app_str = install_root_dir.string();
}
if (argc > 1) {
std::string filePathArg = argv[1];
if (filePathArg.find(' ') != std::string::npos) {
arguments_to_pass = "--file \"" + filePathArg + "\"";
} else {
arguments_to_pass = "--file " + filePathArg;
}
} else {
arguments_to_pass = "";
}
const char* args_c_str = arguments_to_pass.empty() ? NULL : arguments_to_pass.c_str();
const char* working_dir_c_str = working_directory_for_main_app_str.empty() ? NULL : working_directory_for_main_app_str.c_str();
HINSTANCE result = ShellExecuteA(NULL, "open", main_app_executable_path.string().c_str(),
args_c_str,
working_dir_c_str,
SW_SHOWDEFAULT);
if (reinterpret_cast<INT_PTR>(result) <= 32) {
}
return 0;
}