YSTest: main.cpp 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
YSTest_ARM9/source/main.cpp
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2009 - 2013.
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 //标识主源文件。
29 #ifdef YSL_ARM9_MAIN_CPP_
30 # error The main source file has already compiled. Try to make the macro \
31 YSL_ARM9_MAIN_CPP_ be defined iff. once in the project.
32 #endif
33
34 #define YSL_ARM9_MAIN_CPP_ YSL_MAIN_CPP_
35
36 #ifdef YSL_MAIN_CPP_
37 # error The main source file has already compiled. Try to make the macro \
38 YSL_MAIN_CPP_ be defined iff. once in the project.
39 #endif
40 #define YSL_MAIN_CPP_
41
42 //定义使用 EFSLib 。
43 //#define USE_EFS
44
45 //包含文件。
46 #include "ShlExplorer.h"
47
48 using namespace platform;
49 using std::puts;
50
51 YSL_BEGIN
52
53 //调试功能。
54 namespace
55 {
56
58 class Log : private noncopyable
59 {
60 public:
64 yconstfn DefDeCtor(Log)
68 virtual DefEmptyDtor(Log)
69
74 Log&
75 operator<<(char)
76 {
77 return *this;
78 }
83 Log&
84 operator<<(const char*)
85 {
86 return *this;
87 }
91 Log&
92 operator<<(const string& s)
93 {
94 return operator<<(s.c_str());
95 }
96
101 void
102 Error(const char*)
103 {}
107 void
108 Error(const string& s)
109 {
110 Error(s.c_str());
111 }
116 void
117 FatalError(const char* s)
118 {
119 ShowFatalError(s);
120 }
125 void
126 FatalError(const string& s)
127 {
128 FatalError(s.c_str());
129 }
130 };
131
132
133 #ifdef YSL_USE_MEMORY_DEBUG
134
135 void
136 OnExit_DebugMemory_continue()
137 {
138 std::puts("Input to continue...");
139 platform::WaitForInput();
140 }
141
145 template<std::size_t _vN, class _tContainer>
146 void
147 OnExit_DebugMemory_print(_tContainer& con, const char* item_name)
148 {
149 if(!con.empty())
150 {
151 std::fprintf(stderr, "%i %s(s) detected:\n", con.size(), item_name);
152
153 typename _tContainer::size_type n(0);
154
155 for(const auto& item : con)
156 {
157 if(n++ < _vN)
158 GetDebugMemoryList().Print(item, stderr);
159 else
160 {
161 n = 0;
162 OnExit_DebugMemory_continue();
163 }
164 }
165 OnExit_DebugMemory_continue();
166 }
167 }
168
172 void
173 OnExit_DebugMemory()
174 {
175 using namespace platform;
176
177 YDebugSetStatus();
178 YDebugBegin();
179 std::puts("Normal exit;");
180
181 // std::FILE* fp(std::freopen("memdbg.log", "w", stderr));
182 OnExit_DebugMemory_print<4>(GetDebugMemoryList().Blocks, "memory leak");
183 OnExit_DebugMemory_print<4>(GetDebugMemoryList().DuplicateDeletedBlocks,
184 "duplicate memory deleting");
185 #if 0
186 DebugMemory.PrintAll(stderr);
187 DebugMemory.PrintAll(fp);
188 DebugMemory.PrintAllDuplicate(stderr);
189 DebugMemory.PrintAllDuplicate(fp);
190 #endif
191 // std::fclose(fp);
192 std::puts("Input to terminate...");
193 WaitForInput();
194 }
195
196 #endif
197
201 void
202 Repaint(Desktop& dsk)
203 {
204 SetInvalidationOf(dsk);
205 dsk.Validate();
206 dsk.Update();
207 }
208
209 } // unnamed namespace;
210
211
213
214
215
216 YSL_END
217
218 int
219 #if YCL_MINGW32
220 WINAPI
221 WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
222 //WinMain(HINSTANCE hThis, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmd)
223 #else
224 main()
225 //main(int argc, char* argv[])
226 #endif
227 {
228 using namespace YSLib;
229
230 Log log;
231
232 try
233 {
234 {
235 //应用程序实例。
236 DSApplication app;
237
238 //platform::YDebugSetStatus(false);
239 {
240 using namespace YSLib::UI;
241
242 Desktop dsk_up(app.GetScreenUp()), dsk_dn(app.GetScreenDown());
243 Label lblTitle({50, 20, 100, 22}), lblStatus({60, 80, 120, 22}),
244 lblDetails({30, 20, 160, 22});
245 ProgressBar pb({8, 168, 240, 16}, 10);
246
247 AddWidgets(dsk_up, lblTitle, lblStatus, pb);
248 dsk_dn += lblDetails;
249 yunseq(
250 dsk_up.Background = SolidBrush(Color(240, 216, 192)),
251 dsk_dn.Background
252 = SolidBrush(FetchGUIState().Colors[Styles::Desktop]),
253 //Color(240, 216, 240),
254 lblTitle.Text = G_APP_NAME,
255 lblStatus.Text = u"Now loading...",
256 lblDetails.Text = u"初始化中，请稍后……",
257 lblDetails.ForeColor = Drawing::ColorSpace::White
258 );
259 lblDetails.Background = nullptr;
260 SetInvalidationOf(dsk_up);
261 yunseq(dsk_up.Validate(), dsk_dn.Validate());
262 dsk_up.Update(), dsk_dn.Update();
263 //初始化所有图像资源。
264 for(size_t i(0); i < 10; ++i)
265 {
266 pb.SetValue(i);
267 // Invalidate(pb);
268 dsk_up.Background
269 = SolidBrush(Color(255 - i * 255 / 10, 216, 192));
270 Repaint(dsk_up);
271 YReader::FetchImage(i);
272 }
273 pb.SetValue(10);
274 Repaint(dsk_up);
275 }
276 Execute(app, make_shared<YReader::ShlExplorer>());
277 //释放 Shell （必要，保证释放 Shell 且避免资源泄漏）。
278 YReader::Cleanup();
279 }
280
281 #ifdef YSL_USE_MEMORY_DEBUG
282 OnExit_DebugMemory();
283 #endif
284 }
285 catch(std::exception& e)
286 {
287 log.FatalError(e.what());
288 }
289 catch(...)
290 {
291 log.FatalError("Unhandled exception @ main function;");
292 }
293 // TODO: Return exit code properly.
294 return 0;
295 }
296