-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathEditorEntry.cpp
More file actions
144 lines (118 loc) · 3.82 KB
/
Copy pathEditorEntry.cpp
File metadata and controls
144 lines (118 loc) · 3.82 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#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/CrashHandler.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");
// 崩溃捕获与会话标记:先检测上一会话是否异常退出(必须在写入本次标记之前),
// 再安装 minidump 处理器并落下本次会话标记;正常退出时清除标记。
const std::filesystem::path crashDumpDir = PathUtils::GetPersistentDataDir() / "CrashDumps";
const std::filesystem::path sessionMarker = PathUtils::GetPersistentDataDir() / "editor_session.lock";
const bool lastSessionCrashed = CrashHandler::HasAbnormalExit(sessionMarker);
CrashHandler::Install(crashDumpDir);
CrashHandler::BeginSessionMarker(sessionMarker);
Editor::SetPreviousSessionCrashed(lastSessionCrashed);
if (lastSessionCrashed)
{
LogWarn("检测到上次编辑器会话异常退出,崩溃转储目录: {}", crashDumpDir.string());
}
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;
}
// 正常退出:清除会话标记(崩溃路径不会走到这里,标记保留给下次启动检测)
CrashHandler::EndSessionMarker();
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());
}