OSDN Git Service

847d433e738bfe81622d7bf51eed2e838eeb5802
[nlite/nlite.git] / nlite / nlite.cpp
1 // nlite.cpp : \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82Ì\83G\83\93\83g\83\8a \83|\83C\83\93\83g\82ð\92è\8b`\82µ\82Ü\82·\81B
2 //
3
4 #include "stdafx.h"
5 #include "nlite_include.h"
6 using namespace nlite;
7 CAppModule _Module;
8
9
10
11
12 static TCHAR localAppDataPath[_MAX_PATH];
13
14 static WSAData wsaData;                                                 //winsockdata
15 static HINTERNET hInternet = NULL;
16
17 static BOOL InitializeNlite();                                  //\83A\83v\83\8a\83P\81[\83V\83\87\83\93\8f\89\8aú\89»
18 static VOID FinalizeNlite();                                    //\83A\83v\83\8a\83P\81[\83V\83\87\83\93\8fI\97¹\8f\88\97\9d
19 static CNliteMainFrame wnd;                                             //\83\81\83C\83\93\83t\83\8c\81[\83\80\83E\83B\83\93\83h\83E
20
21 //\83\81\83C\83\93\8aÖ\90\94
22 int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE,
23         LPTSTR lpCmdLine, int nCmdShow)
24 {
25         HINSTANCE hRich = LoadLibrary(CRichEditCtrl::GetLibraryName());
26         int nRet = -1;
27         try{
28
29                 //
30                 //\83A\83v\83\8a\83P\83P\81[\83V\83\87\83\93\8f\89\8aú\89»\8f\88\97\9d
31                 //
32
33                 InitCommonControls();
34
35                 if(_Module.Init(NULL, hInstance) != S_OK){
36                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
37                 }
38                         
39                 if(InitializeNlite() != TRUE){
40                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
41                 }
42                 
43                 
44
45                 
46                 
47                 //\83\81\83b\83Z\81[\83W\83\8b\81[\83v\93o\98^
48                 CMessageLoop theLoop;
49                 _Module.AddMessageLoop(&theLoop);
50
51
52                 //\83\81\83C\83\93\83E\83B\83\93\83h\83E\8f\89\8aú\89»
53                 wnd.Initialize(localAppDataPath);
54                 wnd.CreateEx(0,0,WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN);
55
56                 //\83\81\83C\83\93\83E\83B\83\93\83h\83E\95\\8e¦
57                 wnd.ShowWindow(nCmdShow);
58                 wnd.UpdateWindow();
59                 
60                 //\97]\95ª\82É\8am\95Û\82µ\82Ä\82¢\82é\83q\81[\83v\82ð\8aJ\95ú
61                 _heapmin();
62
63                 
64                 //\83\81\83b\83Z\81[\83W\83\8b\81[\83v\8aJ\8en
65                 nRet = theLoop.Run();
66
67                 //\8fI\97¹\8cã\83\81\83\82\83\8a\83`\83F\83b\83N
68                 vcassert(_heapchk() == _HEAPOK,TEXT("\83q\81[\83v\83G\83\89\81[\82Å\82·"));
69
70                 goto nliteend;
71                 
72         } catch(nlite::Exception &e){
73                 
74                 UnexpectedErrorMessageShow(TEXT("\83n\83\93\83h\83\8b\82³\82ê\82Ä\82¢\82È\82¢\83G\83\89\81["),e.what(),e.getLineNo(),e.getFileName(),e.getFunctionName());
75                 
76
77                 goto nlitefinally;
78         } catch(nlib::Exception &e){
79                 
80                 UnexpectedErrorMessageShow(TEXT("nlib\82Å\83n\83\93\83h\83\8b\82³\82ê\82Ä\82¢\82È\82¢\83G\83\89\81["),e.what(),e.getLineNo(),e.getFileName(),e.getFunctionName());
81                 
82                 goto nlitefinally;
83         }catch(std::exception &e){
84                 UnexpectedErrorMessageShow(TEXT("\83n\83\93\83h\83\8b\82³\82ê\82Ä\82¢\82È\82¢\83G\83\89\81["),CComBSTR(e.what()),-1,TEXT("\94­\90\83t\83@\83C\83\8b\82ª\93Á\92è\8fo\97\88\82Ü\82¹\82ñ"),TEXT("\94­\90\8aÖ\90\94\82ª\93Á\92è\82Å\82«\82Ü\82¹\82ñ"));
85
86                 
87
88                 goto nlitefinally;
89         } 
90
91 nlitefinally:
92         wnd.OnException();
93         wnd.DestroyWindow();
94         FreeLibrary(hRich);
95
96 nliteend:
97
98         _Module.RemoveMessageLoop();
99         FinalizeNlite();
100         _Module.Term();
101
102
103         return nRet;
104 }
105
106 static BOOL InitializeNlite(){
107
108         BOOL rslt = FALSE;
109
110         try{
111                 
112                 nlite::appInfo = &CApplicationInfo::getInstance();
113                 INT_PTR err;
114                 INT_PTR count = 0;
115
116                 //WSAData\82ð\8f\89\8aú\89»
117                 while((err = WSAStartup(MAKEWORD(2,0),&wsaData)) == WSASYSNOTREADY){
118
119                         count++;
120                         if(count >= 5)break;
121                         Sleep(500);
122
123
124
125                 }
126                 
127                 if(err != ERROR_SUCCESS){
128
129                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
130                 }
131
132                 const CApplicationInfo &appInfo = CApplicationInfo::getInstance();
133                 CNLiteString userAgent;
134                 userAgent = appInfo.getProcuctName();
135                 userAgent += TEXT("/");
136                 userAgent += appInfo.getProductVersion();
137
138
139                 hInternet = WinHttpOpen(userAgent,WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,(LPCWSTR)WINHTTP_NO_PROXY_NAME,(LPCWSTR)WINHTTP_NO_PROXY_BYPASS,0);
140
141                 if(hInternet == NULL){
142
143                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
144
145                 }
146
147                 InitializeNLIB(hInternet);
148
149                 if(SHGetFolderPathW(0,CSIDL_LOCAL_APPDATA,0,SHGFP_TYPE_CURRENT,localAppDataPath) != S_OK){
150
151                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
152                 }
153
154
155                 SystemParametersInfo (SPI_SETLISTBOXSMOOTHSCROLLING,FALSE,FALSE,0);
156
157
158         }catch (AppInitException e){
159
160                 return rslt;
161
162         }
163
164
165
166         rslt = TRUE;
167
168
169         return rslt;
170 }
171
172
173  VOID FinalizeNlite(){
174
175          wnd.Finalaize();
176          FinalizeNLIB();
177          WinHttpCloseHandle(hInternet);
178          WSACleanup();
179
180          return;
181  }
182