YSTest: Environment.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

Environment.cpp
浏览该文件的文档.
1 /*
2 © 2013-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "Helper/YModules.h"
29 #include YFM_Helper_Environment
30 #include YFM_Helper_Initialization // for InitializeEnvironment,
31 // ShowInitializedLog, InitializeKeyModule, LoadComponents;
32 #if YCL_DS
33 # include YFM_YCLib_NativeAPI // for ::powerOn, ::defaultExceptionHandler,
34 // platform_ex::InitializeFileSystem;
35 # include YFM_DS_YCLib_DSVideo // for platform_ex::DSConsoleInit;
36 # include YFM_YCLib_Video // for platform::ColorSpace;
37 #elif YCL_Win32
38 # include YFM_Win32_YCLib_Consoles // for platform_ex::FixConsoleHandler;
39 # include YFM_Win32_YCLib_MinGW32 // for platform_ex::Win32Exception;
40 # include YFM_YSLib_Core_YCoreUtilities // for FetchEnvironmentVariable;
41 # include YFM_YCLib_Debug // for platform_ex::SendDebugString;
42 #endif
43
44 namespace YSLib
45 {
46
47 using namespace platform_ex;
48 #if YF_Hosted
49 using namespace Host;
50 #endif
51
52 Environment::Environment(Application& app)
53 {
54 std::set_terminate(terminate);
55 #if YCL_DS
56
57 using namespace platform;
58
59 ::powerOn(POWER_ALL);
60 ::defaultExceptionHandler();
61 DSConsoleInit(true, ColorSpace::Lime);
62 FetchCommonLogger().SetSender([&](Logger::Level lv, Logger&,
63 const char* str) YB_NONNULL(4) ynothrowv{
64 if(ShowInitializedLog || lv <= Descriptions::Alert)
65 {
66 if(!ShowInitializedLog)
67 {
68 static struct Init
69 {
70 Init()
71 {
72 DSConsoleInit({}, ColorSpace::White, ColorSpace::Blue);
73 }
74 } init;
75 }
76 std::fprintf(stderr, "%s\n", Nonnull(str));
77 std::fflush(stderr);
78 }
79 });
80 InitializeKeyModule([&]{
81 app.AddExit(ystdex::any(ystdex::in_place<FileSystem>));
82 }, yfsig, " LibFAT Failure ",
83 " An error is preventing the\n"
84 " program from accessing\n"
85 " external files.\n"
86 "\n"
87 " If you're using an emulator,\n"
88 " make sure it supports DLDI\n"
89 " and that it's activated.\n"
90 "\n"
91 " In case you're seeing this\n"
92 " screen on a real DS, make sure\n"
93 " you've applied the correct\n"
94 " DLDI patch (most modern\n"
95 " flashcards do this\n"
96 " automatically).\n"
97 "\n"
98 " Note: Some cards only\n"
99 " autopatch .nds files stored in\n"
100 " the root folder of the card.\n");
101 #elif YCL_Win32
102 TryExpr(FixConsoleHandler())
103 CatchExpr(Win32Exception&,
104 YTraceDe(Warning, "Console handler setup failed."))
105
106 string env_str;
107
108 // TODO: Extract as %YCoreUtilities functions?
109 if(FetchEnvironmentVariable(env_str, "YF_DEBUG_OUTPUT"))
110 FilterExceptions([&]{
111 if(env_str == "1")
112 FetchCommonLogger().SetSender(SendDebugString);
113 });
114 #endif
115 #if false
116 // TODO: Review locale APIs compatibility.
117 static yconstexpr const char locale_str[]{"zh_CN.GBK"};
118
119 if(!std::setlocale(LC_ALL, locale_str))
120 throw GeneralEvent("Call of std::setlocale() with %s failed.\n",
121 locale_str);
122 #endif
123 // NOTE: Ensure root node is initialized before lifetime of environment
124 // begins.
125 string res;
126
127 YTraceDe(Notice, "Checking installation...");
128 InitializeKeyModule([&]{
129 Root = LoadConfiguration(true);
130 if(Root.GetName() == "YFramework")
131 Root = PackNodes(string(), std::move(Root));
132 LoadComponents(app, AccessNode(Root, "YFramework"));
133 YTraceDe(Notice, "Check of installation succeeded.");
134 }, yfsig, " Invalid Installation ",
135 " Please make sure the data is\n stored in correct directory.\n");
136 YF_Trace(Debug, "Environment lifetime began.");
137 }
138 Environment::~Environment()
139 {
140 YF_Trace(Debug, "Environment lifetime ended.");
141 }
142
143 } // namespace YSLib;
144
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:313
platform::Descriptions::Debug
Definition: YCommon.h:170
YSLib::PackNodes
ValueNode PackNodes(_tString &&name, _tParams &&...args)
取以指定分量为参数对应初始化得到的值类型节点为子节点的值类型节点。
Definition: ValueNode.h:1142
platform::Descriptions::Alert
Definition: YCommon.h:164
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
platform
默认平台命名空间。
Definition: Container.h:47
yfsig
#define yfsig
展开为表示函数签名的预定义变量的宏。
Definition: ydef.h:728
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:679
YSLib::AccessNode
const ValueNode & AccessNode(const ValueNode &node, const _tKey &name)
Definition: ValueNode.h:866
platform::Logger::SetSender
void SetSender(Sender)
设置发送器。
YSLib::Environment::~Environment
~Environment()
Definition: Environment.cpp:138
YSLib::Consoles::Blue
Definition: YConsole.h:62
platform::Descriptions::RecordLevel
RecordLevel
记录等级。
Definition: YCommon.h:161
TryExpr
#define TryExpr(...)
指定表达式在 try 块中求值。
Definition: YBaseMacro.h:120
ystdex::any
基于类型擦除的动态泛型对象。
Definition: any.h:845
YSLib::Application
程序实例。
Definition: YApplication.h:46
CatchExpr
#define CatchExpr(_ex,...)
指定表达式作为异常处理器。
Definition: YBaseMacro.h:129
YSLib::FilterExceptions
bool FilterExceptions(_func f, const char *desc={}, RecordLevel lv=Alert, ExceptionTracer trace=ExtractAndTrace) ynothrow
调用函数并过滤宿主异常。
Definition: YException.h:203
platform_ex::Windows::FixConsoleHandler
YF_API void FixConsoleHandler(int(WINAPI *)(unsigned long)={}, bool=true)
安装控制台处理器。
YSLib::Application::AddExit
void AddExit(_tParam &&arg)
Definition: YApplication.h:109
YF_Trace
#define YF_Trace(_lv,...)
YCLib 默认调试跟踪。
Definition: Debug.h:294
platform::Descriptions::Notice
Definition: YCommon.h:168
YSLib::InitializeKeyModule
YF_API void InitializeKeyModule(std::function< void()>, const char *, const char *, string_view)
初始化关键模块。
Definition: Initialization.cpp:337
YSLib::Environment::Environment
Environment(Application &)
构造：初始化环境。
Definition: Environment.cpp:52
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:786
platform::Logger
日志记录器。
Definition: Debug.h:94
YModules.h
YSLib::YB_NONNULL
YF_API YB_NONNULL(1, 2) ValueNode LoadNPLA1File(const char *disp
载入 NPLA1 配置文件。
platform::Nonnull
_type && Nonnull(_type &&p) ynothrowv
断言并返回非空参数。
Definition: Debug.h:422
platform::FetchCommonLogger
YF_API Logger & FetchCommonLogger()
取公共日志记录器。
YSLib::GeneralEvent
std::runtime_error GeneralEvent
一般运行时异常事件类。
Definition: YException.h:46
platform::Descriptions::Warning
Definition: YCommon.h:167
platform::terminate
YB_NORETURN YF_API void terminate() ynothrow
异常终止函数。
Definition: YCommon.cpp:47
platform_ex
平台扩展命名空间。
Definition: Android.h:45
YSLib::Text::str
const char const char * str
Definition: TextFile.h:81
YSLib::LoadConfiguration
YF_API ValueNode LoadConfiguration(bool={})
载入默认配置。
Definition: Initialization.cpp:453
YSLib::LoadComponents
YF_API void LoadComponents(Application &, const ValueNode &)
初始化应用程序组件。
Definition: Initialization.cpp:430
YSLib::FetchEnvironmentVariable
bool FetchEnvironmentVariable(string &res, const char *var)
Definition: YCoreUtilities.cpp:46
YSLib::Consoles::White
Definition: YConsole.h:68
YSLib::lv
RecordLevel lv
Definition: YException.cpp:58