37 using namespace ystdex;
38 using namespace platform;
43 using namespace Drawing;
49 #if !CHRLIB_NODYNAMIC_MAPPING
56 # define DATA_DIRECTORY ROOTW "/Data/"
59 # define DEF_FONT_PATH ROOTW "/Font/FZYTK.TTF"
60 # define DEF_FONT_DIRECTORY ROOTW "/Font/"
62 # define ROOTW "H:\\NDS\\EFSRoot"
63 # define DATA_DIRECTORY ROOTW "\\Data\\"
66 # define DEF_FONT_PATH ROOTW "\\Font\\FZYTK.TTF"
67 # define DEF_FONT_DIRECTORY ROOTW "\\Font\\"
69 #define CONF_PATH "yconf.txt"
74 const auto& data_dir(AccessChild<string>(node,
"DataDirectory"));
75 const auto& font_path(AccessChild<string>(node,
"FontFile"));
76 const auto& font_dir(AccessChild<string>(node,
"FontDirectory"));
78 if(!data_dir.empty() && !font_path.empty() && !font_dir.empty())
79 std::printf(
"Loaded default directory:\n%s\n"
80 "Loaded default font path:\n%s\n"
81 "Loaded default font directory:\n%s\n",
82 data_dir.c_str(), font_path.c_str(), font_dir.c_str());
84 throw LoggedEvent(
"Empty path loaded.");
85 #if !CHRLIB_NODYNAMIC_MAPPING
86 puts(
"Load character mapping file...");
87 p_mapped =
new MappedFile(data_dir +
"cp113.bin");
91 throw LoggedEvent(
"CHRMapEx loading fail.");
92 puts(
"CHRMapEx loaded successfully.");
94 std::printf(
"Trying entering directory %s ...\n", data_dir.c_str());
96 throw LoggedEvent(
"Invalid default data directory found.");
98 throw LoggedEvent(
"Invalid default font file path found.");
109 const char* line(
"--------------------------------");
111 std::printf(
"%s%s%s\n%s\n%s",
112 line, e.GetTitle(), line, e.GetContent(), line);
123 throw LoggedEvent(
"Wrong encoding of configuration file.");
125 NPL::Configuration conf;
128 if(conf.GetNodeRRef().GetSize() != 0)
129 return conf.GetNodeRRef();
131 throw LoggedEvent(
"Invalid file found when reading configuration.");
138 throw LoggedEvent(
"Invalid file found when writing configuration.");
139 tf << NPL::Configuration(
"", node.
Value);
148 std::printf(
"Creating configuration file '%s'...\n",
CONF_PATH);
155 throw LoggedEvent(
"Cannot create file.");
161 std::printf(
"Found configuration file '%s'.\n",
CONF_PATH);
181 ::powerOn(POWER_ALL);
184 ::defaultExceptionHandler();
193 if(!::EFS_Init(EFS_AND_FAT | EFS_DEFAULT_DEVICE,
nullptr))
197 if(!::fatInitDefault())
198 throw FatalError(
" LibFAT Failure ",
199 " An error is preventing the\n"
200 " program from accessing\n"
203 " If you're using an emulator,\n"
204 " make sure it supports DLDI\n"
205 " and that it's activated.\n"
207 " In case you're seeing this\n"
208 " screen on a real DS, make sure\n"
209 " you've applied the correct\n"
210 " DLDI patch (most modern\n"
211 " flashcards do this\n"
214 " Note: Some cards only\n"
215 " autopatch .nds files stored in\n"
216 " the root folder of the card.\n");
223 static yconstexpr char locale_str[]{
"zh_CN.GBK"};
225 if(!std::setlocale(LC_ALL, locale_str))
226 throw LoggedEvent(
"Call of std::setlocale() with %s failed.\n",
234 puts(
"Checking installation...");
239 if(node.GetName() ==
"YFramework")
241 LoadComponents(node.GetNode(
"YFramework"));
243 return std::move(node);
245 catch(std::exception& e)
247 std::printf(
"Error occurred: %s\n", e.what());
249 throw FatalError(
" Invalid Installation ",
250 " Please make sure the data is\n"
251 " stored in correct directory.\n");
256 const string& fong_file,
const string& font_dir)
258 puts(
"Loading font files...");
261 size_t nFileLoaded(fc.LoadTypefaces(fong_file) != 0);
263 if(!font_dir.empty())
266 while((++dir).LastError == 0)
267 if(std::strcmp(dir.GetName(),
FS_Now) != 0
268 && !dir.IsDirectory()
271 FontPath path(font_dir + dir.GetName());
273 if(path != fong_file)
274 nFileLoaded += fc.LoadTypefaces(path) != 0;
276 fc.InitializeDefaultTypeface();
277 if(
const auto nFaces = fc.GetFaces().size())
278 std::printf(
"%u face(s) in %u font file(s)"
279 " are loaded\nsuccessfully.\n", nFaces, nFileLoaded);
281 throw LoggedEvent(
"No fonts found.");
282 puts(
"Setting default font face...");
283 if(
const auto*
const pf = fc.GetDefaultTypefacePtr())
284 std::printf(
"\"%s\":\"%s\",\nsuccessfully.\n",
285 pf->GetFamilyName().c_str(), pf->GetStyleName().c_str());
287 throw LoggedEvent(
"Setting default font face failed.");
291 catch(std::exception& e)
295 throw FatalError(
" Font Caching Failure ",
296 " Please make sure the fonts are\n"
297 " stored in correct path.\n");
303 #if !CHRLIB_NODYNAMIC_MAPPING