|
4 | 4 | * @restrictions: This software may not be resold, redistributed or otherwise conveyed to a third party. |
5 | 5 | */ |
6 | 6 |
|
| 7 | +#include <filesystem> |
| 8 | + |
| 9 | +#include <OvTools/Utils/String.h> |
| 10 | + |
7 | 11 | #include "OvEditor/Core/ProjectHub.h" |
8 | 12 | #include "OvEditor/Core/Application.h" |
9 | 13 |
|
10 | | -#ifdef _DEBUG |
11 | | - int main() |
12 | | -#else |
13 | | - #undef APIENTRY |
14 | | - #include "Windows.h" |
15 | | - INT WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow) |
| 14 | +#undef APIENTRY |
| 15 | +#include "Windows.h" |
| 16 | + |
| 17 | +/** |
| 18 | +* When Overload is launched from a project file, we should consider the executable path as |
| 19 | +* the current working directory |
| 20 | +* @param p_executablePath |
| 21 | +*/ |
| 22 | +void UpdateWorkingDirectory(const std::string& p_executablePath) |
| 23 | +{ |
| 24 | + if (!IsDebuggerPresent()) |
| 25 | + { |
| 26 | + std::filesystem::current_path(OvTools::Utils::PathParser::GetContainingFolder(p_executablePath)); |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +int main(int argc, char** argv); |
| 31 | + |
| 32 | +#ifndef _DEBUG |
| 33 | +INT WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow) |
| 34 | +{ |
| 35 | + main(__argc, __argv); |
| 36 | +} |
16 | 37 | #endif |
| 38 | + |
| 39 | +int main(int argc, char** argv) |
17 | 40 | { |
18 | | - OvEditor::Core::ProjectHub* hub = new OvEditor::Core::ProjectHub(); |
19 | | - auto[ready, projectPath, projectName] = hub->Run(); |
20 | | - delete hub; |
| 41 | + UpdateWorkingDirectory(argv[0]); |
| 42 | + |
| 43 | + bool ready = false; |
| 44 | + std::string projectPath; |
| 45 | + std::string projectName; |
| 46 | + |
| 47 | + { |
| 48 | + OvEditor::Core::ProjectHub hub; |
| 49 | + |
| 50 | + if (argc < 2) |
| 51 | + { |
| 52 | + // No project file given as argument ==> Open the ProjectHub |
| 53 | + std::tie(ready, projectPath, projectName) = hub.Run(); |
| 54 | + } |
| 55 | + else |
| 56 | + { |
| 57 | + // Project file given as argument ==> Open the project |
| 58 | + std::string projectFile = argv[1]; |
| 59 | + |
| 60 | + if (OvTools::Utils::PathParser::GetExtension(projectFile) == "ovproject") |
| 61 | + { |
| 62 | + ready = true; |
| 63 | + projectPath = OvTools::Utils::PathParser::GetContainingFolder(projectFile); |
| 64 | + projectName = OvTools::Utils::PathParser::GetElementName(projectFile); |
| 65 | + OvTools::Utils::String::Replace(projectName, ".ovproject", ""); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
21 | 69 |
|
22 | 70 | if (ready) |
23 | 71 | { |
|
0 commit comments