OSDN Git Service

主コメ選択時にエディットの色が変わる機能を追加
[nlite/nlite.git] / nlib_driver / nlib_driver.cpp
1 // nlib_driver.cpp : \83R\83\93\83\\81[\83\8b \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
6 #include <qwerty\windebuger.h>
7
8 #include <shareCookie\shareCookie.h>
9 #include <shareCookie\browserType.h>
10 #include <nlib\nlib.h>
11 #include <nlib\nlib_define.h>
12
13
14
15 //\83\89\83C\83u\83\89\83\8a\83\8a\83\93\83N
16 #pragma comment(lib,"Wininet.lib")
17 #pragma comment(lib,"WinHttp.lib")
18 #pragma comment(lib,"Iepmapi.lib")
19 #pragma comment(lib,"ws2_32.lib")
20 #pragma comment(lib, "shell32.lib" )
21 #pragma comment(lib,"expat.lib")
22 #pragma comment(lib,"sqlite3.lib")
23 #pragma comment(lib,"sqliteManager.lib")
24 #pragma comment(lib,"shareCookie.lib")
25 #pragma comment(lib,"nlib.lib")
26 #pragma comment(lib,"winmm.lib")
27 #pragma comment(lib,"JSONParser.lib")
28
29
30 NicoLiveStream_P nl;
31 NicoVideoAuth_P nva;
32 WSAData wsaData;
33 HINTERNET hInternet = WinHttpOpen(L"nicoliveTest",WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,(LPCWSTR)WINHTTP_NO_PROXY_NAME,(LPCWSTR)WINHTTP_NO_PROXY_BYPASS,0);
34
35 int nicoLive_setup(void) {
36
37         INT_PTR err;
38         INT_PTR count = 0;
39
40
41         //WSAData\82ð\8f\89\8aú\89»
42         while((err = WSAStartup(MAKEWORD(2,0),&wsaData)) == WSASYSNOTREADY){
43
44                 count++;
45                 if(count >= 5)break;
46                 Sleep(500);
47
48
49
50         }
51
52         if(err != ERROR_SUCCESS){
53
54                 return NLIB_INITALIZE_FAILED_NETWORK;
55         }
56         InitializeNLIB(hInternet);
57         nl = NicoLiveStream_new();
58         nva = NicoVideoAuth_new();
59         NicoVideoAuth_getNicoVideoAuth(nva,BT_GOOGLE_CHROME);
60         return nl != NULL ? 0 : 1;
61 }
62
63 int nicoLive_teardown(void) {
64   NicoLiveStream_delete(&nl);
65   NicoVideoAuth_delete(&nva);
66   FinalizeNLIB();
67   WinHttpCloseHandle(hInternet);
68   WSACleanup();
69   return 0;
70 }
71
72
73
74
75 NLIB_RESULT callback(NICOLIVE_EVENT eventType,NicoLiveStream_P pNicoLiveStream,LPVOID option,NICOLIVE_PARAM param1,NICOLIVE_PARAM param2){
76
77
78         switch(eventType){
79
80         case NICOLIVE_EVENT_ERR_CONNECT:
81
82                 errprint(TEXT("\92Ê\90M\83G\83\89\81[\94­\90¶"));
83
84                 break;
85
86
87         case NICOLIVE_EVENT_RECEVE_CONNECTRESULT:
88
89                 println(TEXT("receveStart::last_res[%s],thread[%s],ticket[%s],server_time[%s]"),((NicoLiveThreadComment_P)param1)->last_res,((NicoLiveThreadComment_P)param1)->thread,((NicoLiveThreadComment_P)param1)->ticket,((NicoLiveThreadComment_P)param1)->server_time);
90                 
91                 break;
92
93         case NICOLIVE_EVENT_RECEVE_CHAT:
94
95                 {
96                         int i = 0;
97                         NicoLiveChat_P chatP = (NicoLiveChat_P)param1;
98                         int index = chatP->mailCount;
99                         println(TEXT("recevechat::no[%s],locale[%s],vpos[%s],date[%s],premium[%s],anonymity[%s],thread[%s],user_id[%s],name[%s]"),chatP->no,chatP->locale,chatP->vpos,chatP->date,chatP->premium,chatP->anonymity,chatP->thread,chatP->user_id,chatP->name);
100
101
102
103                         for(;i < index;i++){
104
105                                 println(TEXT("mail(%d)[%s]"),i,chatP->mail[i]);
106
107                         }
108
109                         println(TEXT("chatBody::%s"),chatP->chatBuf);
110
111                 }
112                 break;
113
114         case NICOLIVE_EVENT_RECEVE_CHATSETTLE:
115
116
117                 
118                 println(TEXT("recevechatCount::no[%d],count[%d]"),param1,param2);
119                 param1;
120                 
121                 break;
122
123         case NICOLIVE_EVENT_RECEVE_CHATSENDRESULT:
124
125                 {
126                         NicoLiveSendResultComment_P nls = (NicoLiveSendResultComment_P)param1;
127                         
128                         println(TEXT("sendresult::no[%s],status[%s],thread[%s]"),nls->no,nls->status,nls->thread);
129
130                 }
131
132                 break;
133
134         case NICOLIVE_EVENT_SEND_HEARTBEAT:
135
136                 {
137
138                         NicoLiveHeartBeat_P hbp = (NicoLiveHeartBeat_P)param1;
139
140                         println(TEXT("heartbeat::time[%llu],watchCount[%d],commentCount[%d],is_restrict[%s],ticket[%s]"),hbp->time,hbp->watchCount,hbp->commentCount,hbp->is_restrict,hbp->ticket);
141                         //println(TEXT("heartbeat::watchCount[%d],commentCount[%d],is_restrict[%s],ticket[%s]"),hbp->watchCount,hbp->commentCount,hbp->is_restrict,hbp->ticket);
142                 
143
144                 }
145
146
147                 break;
148
149
150         }
151
152         return 0;
153 }
154
155 NLIB_RESULT myListCallBack(LPVOID option,NicoMyListItem_P pVideo){
156
157 //      dumpln(TEXT("video_id:%s"),pVideo->itemData.video_id);
158
159
160
161         return NLIB_ERR_OK;
162 }
163
164 static NLIB_RESULT myListGroupCallBack(LPVOID option,NicoMyList_P pMyList){
165         WCHAR buf[256];
166         NLIB_RESULT rslt;
167 //      wcscpy(buf,pMyList->id);
168         dumpln(TEXT("id:%s"),buf);
169         rslt = NicoMyList_getMyList(nva,buf,myListCallBack,NULL);
170         
171         
172
173         return NLIB_ERR_OK;
174 }
175
176 void nicoLive_connect(void) {
177         
178         dumpline();
179         NicoLiveStrream_setResFrom(nl,1000);
180         //NicoLiveStream_setHeartBeatMsec(nl,5000);
181         //NicoLiveStream_setKeapALiveMsec(nl,5000);
182         //NicoLiveStream_setKeapALiveFlag(nl,FALSE);
183         
184         
185         WCHAR housoubuf[LENGTH_1024];
186         std::wcin.getline(housoubuf,sizeof(housoubuf) / sizeof(housoubuf[0]));
187         
188         WCHAR buf[1024];
189         
190         
191
192         for(int index = 0;index < 5;index++){
193                 check(NicoLiveStream_connect(nl,nva,housoubuf,callback,NULL) ==  NLIB_ERR_OK,TEXT("\90Ú\91±\82É\8e¸\94s\82µ\82Ü\82µ\82½"));
194 //              NicoLiveStream_queryStreamInfo(nl);
195                 std::wcin.getline(buf,sizeof(buf) / sizeof(buf[0]));
196
197                 LPWSTR mail = L"184";
198                 LPWSTR exname = L"name";
199                 LPWSTR exvalue = L"qwerty";
200
201                 LPCWSTR mails[2] = {mail,NULL};
202                 LPCWSTR extends[3] = {exname,exvalue,NULL};
203                 
204
205                 while(wcslen(buf) > 0){
206
207                         NicoLiveStream_sendChat(nl,buf,mails,NULL);
208                         std::wcin.getline(buf,sizeof(buf) / sizeof(buf[0]));
209                 }
210                 NicoLiveStream_disConnect(nl);
211         }
212         
213         check(_heapchk() == _HEAPOK,TEXT("\83q\81[\83v\83G\83\89\81[\82Å\82·"));
214         
215         //Sleep(3000);
216
217
218         
219
220
221         return;
222 }
223
224
225 void nicoLive_mylist(void) {
226
227         
228
229         //check(NicoMyList_getDefList(nva,myListCallBack,NULL) ==  NLIB_ERR_OK,TEXT("\82Æ\82è\82 \82¦\82¸\83}\83C\83\8a\83X\83g\8eæ\93¾\82É\8e¸\94s\82µ\82Ü\82µ\82½"));
230         //check(NicoMyList_getMyListGroup(nva,myListGroupCallBack,NULL) == NLIB_ERR_OK,TEXT("\83}\83C\83\8a\83X\83g\83O\83\8b\81[\83v\93o\98^\82É\8e¸\94s\82µ\82Ü\82µ\82½"));
231         //check(NicoMyList_addItem(L"sm16046365") == NLIB_ERR_OK,TEXT("\83}\83C\83\8a\83X\83g\93o\98^\82É\8e¸\94s\82µ\82Ü\82µ\82½!"));
232         //check(_heapchk() == _HEAPOK,TEXT("heap\83G\83\89\81[\82Å\82·"));
233         dumpln(TEXT("heapchk:%d"),_heapchk());
234
235
236 }
237
238
239
240
241 int _tmain(int argc, _TCHAR* argv[])
242 {
243
244         
245         nicoLive_setup();
246         
247
248
249         nicoLive_connect();
250         //nicoLive_mylist();
251         
252         nicoLive_teardown();
253
254
255         _getch();
256         return 0;
257 }