Skip to content

Commit 0f01f2c

Browse files
authored
Merge pull request #15 from adriengivry/feature/open_with_overload
Open with Overload supported
2 parents bc10b4c + d3b24f1 commit 0f01f2c

1 file changed

Lines changed: 57 additions & 9 deletions

File tree

  • Sources/Overload/OvEditor/src/OvEditor

Sources/Overload/OvEditor/src/OvEditor/Main.cpp

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,68 @@
44
* @restrictions: This software may not be resold, redistributed or otherwise conveyed to a third party.
55
*/
66

7+
#include <filesystem>
8+
9+
#include <OvTools/Utils/String.h>
10+
711
#include "OvEditor/Core/ProjectHub.h"
812
#include "OvEditor/Core/Application.h"
913

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+
}
1637
#endif
38+
39+
int main(int argc, char** argv)
1740
{
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+
}
2169

2270
if (ready)
2371
{

0 commit comments

Comments
 (0)