OSDN Git Service

規定のブラウザとのクッキー共有機能実装
[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
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                 HRESULT hRes = ::CoInitialize(NULL);
33                 ATLASSERT(SUCCEEDED(hRes));
34                 AtlInitCommonControls(ICC_COOL_CLASSES | ICC_WIN95_CLASSES);
35                 GUID guid;
36                 if(_Module.Init(NULL, hInstance,&guid) != S_OK){
37                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
38                 }
39
40                 AtlAxWinInit();
41
42                 if(InitializeNlite() != TRUE){
43                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
44                 }
45
46                 
47
48                 
49                 //\83\81\83b\83Z\81[\83W\83\8b\81[\83v\93o\98^
50                 CMessageLoop theLoop;
51                 _Module.AddMessageLoop(&theLoop);
52
53
54                 //\83\81\83C\83\93\83E\83B\83\93\83h\83E\8f\89\8aú\89»
55                 wnd.Initialize(localAppDataPath);
56                 wnd.CreateEx(0,0,WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN);
57
58                 //\83\81\83C\83\93\83E\83B\83\93\83h\83E\95\\8e¦
59                 wnd.ShowWindow(nCmdShow);
60                 wnd.UpdateWindow();
61
62                 //\97]\95ª\82É\8am\95Û\82µ\82Ä\82¢\82é\83q\81[\83v\82ð\8aJ\95ú
63                 _heapmin();
64
65
66                 //\83\81\83b\83Z\81[\83W\83\8b\81[\83v\8aJ\8en
67                 nRet = theLoop.Run();
68
69                 //\8fI\97¹\8cã\83\81\83\82\83\8a\83`\83F\83b\83N
70                 vcassert(_heapchk() == _HEAPOK,TEXT("\83q\81[\83v\83G\83\89\81[\82Å\82·"));
71
72                 goto nliteend;
73
74         } catch(nlite::Exception &e){
75
76                 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());
77
78
79                 goto nlitefinally;
80         } catch(nlib::Exception &e){
81
82                 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());
83
84                 goto nlitefinally;
85         }catch(std::exception &e){
86                 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ñ"));
87
88
89
90                 goto nlitefinally;
91         } 
92
93 nlitefinally:
94         wnd.OnException();
95         wnd.DestroyWindow();
96         FreeLibrary(hRich);
97
98 nliteend:
99
100         _Module.RemoveMessageLoop();
101         FinalizeNlite();
102         _Module.Term();
103         ::CoUninitialize();
104
105         return nRet;
106 }
107
108 static BOOL InitializeNlite(){
109
110         BOOL rslt = FALSE;
111
112         try{
113
114                 nlite::appInfo = &CApplicationInfo::getInstance();
115                 INT_PTR err;
116                 INT_PTR count = 0;
117
118                 //WSAData\82ð\8f\89\8aú\89»
119                 while((err = WSAStartup(MAKEWORD(2,0),&wsaData)) == WSASYSNOTREADY){
120
121                         count++;
122                         if(count >= 5)break;
123                         Sleep(500);
124
125
126
127                 }
128
129                 if(err != ERROR_SUCCESS){
130
131                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
132                 }
133
134                 //\83A\83v\83\8a\83P\81[\83V\83\87\83\93\8fî\95ñ\83C\83\93\83X\83^\83\93\83X\90\90¬
135                 const CApplicationInfo &appInfo = CApplicationInfo::getInstance();
136                 CNLiteString userAgent;
137                 userAgent = appInfo.getProcuctName();
138                 userAgent += TEXT("/");
139                 userAgent += appInfo.getProductVersion();
140
141
142
143                 //HTTP\83I\83u\83W\83F\83N\83g\90\90¬
144                 hInternet = WinHttpOpen(userAgent,WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,(LPCWSTR)WINHTTP_NO_PROXY_NAME,(LPCWSTR)WINHTTP_NO_PROXY_BYPASS,0);
145
146                 if(hInternet == NULL){
147
148                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
149
150                 }
151
152                 //nlib\82Ì\8f\89\8aú\89»
153                 InitializeNLIB(hInternet);
154
155                 //\83\8d\81[\83J\83\8b\83A\83v\83\8a\83P\81[\83V\83\87\83\93\83t\83H\83\8b\83_\8c\9f\8dõ
156                 if(SHGetFolderPathW(0,CSIDL_LOCAL_APPDATA,0,SHGFP_TYPE_CURRENT,localAppDataPath) != S_OK){
157
158                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
159                 }
160
161
162                 SystemParametersInfo (SPI_SETLISTBOXSMOOTHSCROLLING,FALSE,FALSE,0);
163
164
165
166                 if(SHGetFolderPathW(0,CSIDL_APPDATA,0,SHGFP_TYPE_CURRENT,appFolderPath) != S_OK){
167
168                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
169                 }
170                 ncvAppSettingPath = appFolderPath;
171                 ncvAppSettingPath += TEXT("\\posite-c\\NiconamaCommentViewer\\AppSetting.xml");
172                 rslt = TRUE;
173         }catch (AppInitException e){
174
175                 rslt = FALSE;
176
177         }
178         
179
180         return rslt;
181 }
182
183
184 VOID FinalizeNlite(){
185
186         //\83\81\83C\83\93\83t\83\8c\81[\83\80\83E\83B\83\93\83h\83E\8cã\8f\88\97\9d
187         wnd.Finalaize();
188
189         //nlib\8cã\8f\88\97\9d
190         FinalizeNLIB();
191
192         //HTTP\83I\83u\83W\83F\83N\83g\8aJ\95ú
193         WinHttpCloseHandle(hInternet);
194
195         //winsock\8aJ\95ú
196         WSACleanup();
197
198         return;
199 }
200