VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
main_selector.cpp
2#include <filesystem>
3#include <iostream>
4#include <vector>
5
6#include "components/ErrorUtils.hpp"
7
8#ifdef _WIN32
9 #include <windows.h>
10 #include <process.h>
11 #include <direct.h>
12#else
13 #include <unistd.h>
14 #include <limits.h>
15#endif
16
17std::filesystem::path getSelfDir() {
18#ifdef _WIN32
19 char path[MAX_PATH];
20 GetModuleFileNameA(NULL, path, MAX_PATH);
21 return std::filesystem::path(path).parent_path();
22#else
23 char result[PATH_MAX];
24 ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
25 if (count != -1) {
26 return std::filesystem::path(std::string(result, count)).parent_path();
27 }
28 return std::filesystem::current_path();
29#endif
30}
31
32int main(int argc, char* argv[]) {
33 std::string selectedPath;
34 SDL_SetAppMetadata("Vex Engine", vex::Engine::GetVersionString(), "VexEngine");
35
36 {
37 try {
38 vex::ProjectSelector selector("Vex Project Selector");
39 selector.run([&]() {
40 selectedPath = selector.getSelectedProject();
41 });
42 } catch (const std::exception& e) {
44 }
45 }
46
47 if (selectedPath.empty()) {
48 vex::log(vex::LogLevel::ERROR, "Project path was not passed!");
49 return 0;
50 }
51
52 std::filesystem::path binDir = getSelfDir();
53
54#ifdef _WIN32
55 std::string exeName = "VexEditor.exe";
56 std::filesystem::path fullPath = binDir / exeName;
57
58 if (!std::filesystem::exists(fullPath)) {
59 std::cerr << "[Error] Could not find editor at: " << fullPath << std::endl;
60 std::cout << "Press Enter to exit..." << std::endl;
61 std::cin.get();
62 return 1;
63 }
64
65 const char* args[] = { fullPath.string().c_str(), selectedPath.c_str(), NULL };
66 _spawnv(_P_OVERLAY, fullPath.string().c_str(), args);
67#else
68 std::string exeName = "VexEditor";
69 std::filesystem::path fullPath = binDir / exeName;
70
71 if (!std::filesystem::exists(fullPath)) {
72 std::cerr << "[Error] Could not find editor at: " << fullPath << std::endl;
73 std::cout << "Press Enter to exit..." << std::endl;
74 std::cin.get();
75 return 1;
76 }
77
78 char* args[] = {
79 (char*)exeName.c_str(),
80 (char*)selectedPath.c_str(),
81 NULL
82 };
83
84 execv(fullPath.c_str(), args);
85
86 perror("execv failed");
87 std::cerr << "[Fatal] Failed to launch: " << fullPath << std::endl;
88 std::cout << "Press Enter to exit..." << std::endl;
89 std::cin.get();
90 return 1;
91#endif
92
93 return 0;
94}
Specialized Engine class for the initial project selection screen.
static const char * GetVersionString()
Returns the version string of the engine.
Definition Engine.cpp:42
Specialized Engine class for the initial project selection screen.
void VEX_EXPORT log(const char *fmt,...)
Logs a formatted message.
void VEX_EXPORT handle_critical_exception(const std::exception &e)
Handles a critical exception, forcing termination.