-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEditorEntry.cpp
More file actions
129 lines (103 loc) · 2.86 KB
/
EditorEntry.cpp
File metadata and controls
129 lines (103 loc) · 2.86 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "EngineEntry.h"
#include <memory>
#include <iostream>
#include <clocale>
#include <filesystem>
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <openssl/crypto.h>
#include <openssl/opensslv.h>
#ifndef _MSC_VER
#include "Resources/RuntimeAsset/RuntimeScene.h"
#endif
#include "Application/Editor.h"
#include "Application/ProjectSettings.h"
#include "Utils/Logger.h"
#include "Utils/PathUtils.h"
namespace
{
void ConfigureWorkingDirectory(const char* executablePath)
{
if (!executablePath || executablePath[0] == '\0')
{
return;
}
std::filesystem::path path(executablePath);
std::filesystem::path workDir;
std::error_code ec;
if (std::filesystem::is_directory(path, ec))
{
workDir = path;
}
else
{
workDir = path.parent_path();
}
if (!workDir.empty())
{
std::error_code changeEc;
std::filesystem::current_path(workDir, changeEc);
if (changeEc)
{
LogError("设置工作目录失败: {}", changeEc.message());
}
else
{
LogInfo("工作目录已设置为: {}", workDir.string());
}
}
}
}
static int EditorEntryImpl(int argc, char* argv[], const char* executablePath)
{
#if defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER >= 0x10100000L)
OPENSSL_init_crypto(OPENSSL_INIT_NO_ATEXIT, nullptr);
#endif
std::setlocale(LC_ALL, ".UTF8");
#if defined(_WIN32) || defined(_WIN64)
SetConsoleOutputCP(CP_UTF8);
#endif
ConfigureWorkingDirectory(executablePath);
PathUtils::Initialize("Luma Editor");
LogInfo("正在以编辑器模式启动...");
ApplicationConfig config;
config.title = "Luma Editor";
config.width = 1600;
config.height = 900;
std::unique_ptr<ApplicationBase> app = std::make_unique<Editor>(config);
try
{
app->Run();
}
catch (const std::exception& e)
{
LogError("编辑器遇到致命错误: {}", e.what());
#if defined(_WIN32) || defined(_WIN64)
MessageBoxA(NULL, e.what(), "Fatal Error", MB_OK | MB_ICONERROR);
#endif
return -1;
}
return 0;
}
ENTRY_API int LumaEngine_Editor_Entry(int argc, char* argv[], const char* currentExePath,
const char* androidPackageName)
{
#if defined(__ANDROID__)
PathUtils::InjectAndroidPackageName(androidPackageName ? androidPackageName : "");
#else
(void)androidPackageName;
#endif
std::string executablePath;
if (!currentExePath)
{
executablePath = GetExecutablePath();
}
else
{
executablePath = currentExePath;
}
return EditorEntryImpl(argc, argv, executablePath.c_str());
}