29 #include YFM_Helper_Initialization
30 #include YFM_YSLib_Core_YApplication
31 #include YFM_Helper_GUIApplication
32 #include YFM_YCLib_Debug
33 #include YFM_CHRLib_MappingEx
34 #include YFM_YCLib_MemoryMapping
35 #include YFM_YSLib_Service_FileSystem
38 #include YFM_NPL_SContext
40 using namespace ystdex;
41 using namespace platform;
47 using namespace Drawing;
55 stack<std::function<void()>> app_exit;
57 Drawing::FontCache* p_font_cache;
59 #if !CHRLIB_NODYNAMIC_MAPPING
63 MIMEBiMapping* p_mapping;
66 const char TU_MIME[]{u8R
"NPLA1(
68 (octet-stream "bin" "so")
69 (x-msdownload "exe" "dll" "com" "bat" "msi")
70 (x-font-ttf "ttf" "ttc")
75 (midi "mid" "midi" "rmi")
89 (plain "txt" "conf" "def" "ini" "log" "in")
91 (x-c++ "cc" "cpp" "cxx" "h" "hh" "hpp" "hxx" "inl")
97 # define DATA_DIRECTORY ROOTW "/Data/"
100 # define DEF_FONT_PATH ROOTW "/Font/FZYTK.TTF"
101 # define DEF_FONT_DIRECTORY ROOTW "/Font/"
104 # define DATA_DIRECTORY ROOTW "\\"
107 # define DEF_FONT_PATH "C:\\Windows\\Fonts\\SimSun.ttc"
108 # define DEF_FONT_DIRECTORY ROOTW "\\"
110 #define CONF_PATH "yconf.txt"
113 LoadComponents(
const ValueNode& node)
115 const auto& data_dir(AccessChild<string>(node,
"DataDirectory"));
116 const auto& font_path(AccessChild<string>(node,
"FontFile"));
117 const auto& font_dir(AccessChild<string>(node,
"FontDirectory"));
119 if(!data_dir.empty() && !font_path.empty() && !font_dir.empty())
120 std::printf(
"Loaded default directory:\n%s\n"
121 "Loaded default font path:\n%s\n"
122 "Loaded default font directory:\n%s\n",
123 data_dir.c_str(), font_path.c_str(), font_dir.c_str());
125 throw LoggedEvent(
"Empty path loaded.");
126 #if !CHRLIB_NODYNAMIC_MAPPING
127 puts(
"Load character mapping file...");
128 p_mapped =
new MappedFile(data_dir +
"cp113.bin");
129 if(p_mapped->GetSize() != 0)
132 throw LoggedEvent(
"CHRMapEx loading fail.");
133 puts(
"CHRMapEx loaded successfully.");
135 std::printf(
"Trying entering directory %s ...\n", data_dir.c_str());
137 throw LoggedEvent(
"Invalid default data directory found.");
139 throw LoggedEvent(
"Invalid default font file path found.");
150 const char* line(
"--------------------------------");
152 std::printf(
"%s%s%s\n%s\n%s",
153 line, e.GetTitle(), line, e.GetContent(), line);
165 std::printf(
"Creating %s '%s'...\n", disp, path);
168 if(
TextFile tf{path, std::ios_base::out | std::ios_base::trunc})
180 std::printf(
"Found %s '%s'.\n", disp, path);
191 throw LoggedEvent(
"Wrong encoding of configuration file.");
196 if(conf.GetNodeRRef().GetSize() != 0)
197 return conf.GetNodeRRef();
199 throw LoggedEvent(
"Invalid file found when reading configuration.");
206 throw LoggedEvent(
"Invalid file found when writing configuration.");
214 return PackNodes(
"YFramework", MakeNode(
"DataDirectory",
237 ::powerOn(POWER_ALL);
240 ::defaultExceptionHandler();
249 if(!::EFS_Init(EFS_AND_FAT | EFS_DEFAULT_DEVICE,
nullptr))
253 if(!::fatInitDefault())
255 " An error is preventing the\n"
256 " program from accessing\n"
259 " If you're using an emulator,\n"
260 " make sure it supports DLDI\n"
261 " and that it's activated.\n"
263 " In case you're seeing this\n"
264 " screen on a real DS, make sure\n"
265 " you've applied the correct\n"
266 " DLDI patch (most modern\n"
267 " flashcards do this\n"
270 " Note: Some cards only\n"
271 " autopatch .nds files stored in\n"
272 " the root folder of the card.\n");
279 static yconstexpr char locale_str[]{
"zh_CN.GBK"};
281 if(!std::setlocale(LC_ALL, locale_str))
282 throw LoggedEvent(
"Call of std::setlocale() with %s failed.\n",
290 puts(
"Checking installation...");
295 if(node.GetName() ==
"YFramework")
297 LoadComponents(node.at(
"YFramework"));
301 catch(std::exception& e)
303 std::printf(
"Error occurred: %s\n", e.what());
306 " Please make sure the data is\n"
307 " stored in correct directory.\n");
312 const string& font_dir)
314 puts(
"Loading font files...");
319 if(!font_dir.empty())
329 && dir.GetNodeCategory() != NodeCategory::Directory
332 FontPath path(font_dir + dir.GetName());
334 if(path != fong_file)
342 if(
const auto nFaces = fc.GetFaces().size())
343 std::printf(
"%u face(s) in %u font file(s)"
344 " are loaded\nsuccessfully.\n", nFaces, nFileLoaded);
347 puts(
"Setting default font face...");
349 std::printf(
"\"%s\":\"%s\",\nsuccessfully.\n",
350 pf->GetFamilyName().c_str(), pf->GetStyleName().c_str());
352 throw LoggedEvent(
"Setting default font face failed.");
356 catch(std::exception& e)
361 " Please make sure the fonts are\n"
362 " stored in correct path.\n");
368 while(!app_exit.empty())
374 #if !CHRLIB_NODYNAMIC_MAPPING
403 const auto& node(
FetchRoot()[
"YFramework"]);
406 AccessChild<string>(node,
"FontFile"),
407 AccessChild<string>(node,
"FontDirectory"));
409 return *p_font_cache;
422 (AccessChild<string>(
FetchRoot()[
"YFramework"],
"DataDirectory")
423 +
"MIMEExtMap.txt").c_str(), []{
void InitializeDefaultTypeface()
初始化默认字型。
YF_API ValueNode InitializeInstalled()
初始化已安装项:检查安装完整性并载入主配置文件的配置项。
Text::Encoding Encoding
编码。
YF_API ValueNode & FetchRoot()
取值类型根节点。
YF_API void YDebugBegin()
调试模式:显示控制台。
YF_API ValueNode LoadNPLA1(ValueNode &&)
读取 NPLA1 翻译单元。
YF_API bool ufexists(const char *) ynothrow
判断指定 UTF-8 文件名的文件是否存在。
YF_API MIMEBiMapping & FetchMIMEBiMapping()
取 MIME 类型名和文件扩展名双向映射对象。
ValueNode PackNodes(_tString &&name, _tParams &&...args)
取以指定分量为参数对应初始化得到的值类型节点为子节点的值类型节点。
#define DEF_FONT_DIRECTORY
YF_API void Analyze(ValueNode &, const TokenList &)
分析指定源,取抽象语法树储存至指定值类型节点。
YF_API void SaveConfiguration(const ValueNode &)
保存默认配置。
YF_API void YDebugSetStatus(bool=true)
调试模式:设置状态。
YB_NORETURN YF_API void terminate() ynothrow
异常终止函数。
#define YB_UNLIKELY(expr)
分支预测提示。
YF_API ValueNode LoadConfiguration(bool={})
载入默认配置。
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
yconstfn const string & name
YF_API Drawing::FontCache & FetchDefaultFontCache()
取默认字体缓存。
GSStringTemplate< char >::basic_string string
YF_API void YConsoleInit(std::uint8_t dspIndex, Color fc=ColorSpace::White, Color bc=ColorSpace::Black)
启动控制台。
YF_API ValueNode LoadNPLA1File(const char *disp, const char *path, ValueNode(*creator)(), bool show_info={})
载入 NPLA1 配置文件。
YF_API ValueNode ReadConfiguration(TextFile &)
从文本文件中读取配置。
YF_API void InitializeSystemFontCache(Drawing::FontCache &, const string &, const string &)
初始化系统字体缓存。
ystdex::indirect_input_iterator< HDirectory * > FileIterator
文件迭代器。
virtual bool is_self(const value_type &)=0
YF_API void AddMIMEItems(MIMEBiMapping &, const ValueNode &, MIMEBiMapping::MIMEType &&={})
根据 NPLA1 节点内容增加 MIME 映射。
YF_API void Uninitialize() ynothrow
反初始化。
YB_NORETURN YF_API void HandleFatalError(const FatalError &) ynothrow
处理致命错误:显示错误信息并终止程序。
size_t LoadTypefaces(const FontPath &)
从字体文件组中载入字型信息。
YF_API void InitializeEnviornment()
初始化环境。
#define yconstexpr
指定编译时常量表达式。
std::string FontPath
字体文件路径。
YF_API void WriteConfiguration(TextFile &, const ValueNode &)
写入配置至文本文件。
yconstexpr Encoding UTF_8(csUTF8)
const Typeface * GetDefaultTypefacePtr() const
取默认字型指针。