From 5b07686e16991d20d42d3b051074a98bb655f8b3 Mon Sep 17 00:00:00 2001 From: qwerty2501 Date: Wed, 28 Dec 2011 02:08:34 +0900 Subject: [PATCH] first commit --- nlib_driver/nlib_driver.cpp | 290 ++++++++++++++++++++++++++++++++++++++ nlib_driver/stdafx.cpp | 8 ++ nlite/nlite.cpp | 166 ++++++++++++++++++++++ nlite/nlite_appInfo.cpp | 105 ++++++++++++++ nlite/nlite_commentview.cpp | 229 ++++++++++++++++++++++++++++++ nlite/nlite_mainframe.cpp | 158 +++++++++++++++++++++ nlite/nlite_property.cpp | 334 ++++++++++++++++++++++++++++++++++++++++++++ nlite/stdafx.cpp | 8 ++ nlite_stub/nlite_stub.cpp | 177 +++++++++++++++++++++++ 9 files changed, 1475 insertions(+) create mode 100644 nlib_driver/nlib_driver.cpp create mode 100644 nlib_driver/stdafx.cpp create mode 100644 nlite/nlite.cpp create mode 100644 nlite/nlite_appInfo.cpp create mode 100644 nlite/nlite_commentview.cpp create mode 100644 nlite/nlite_mainframe.cpp create mode 100644 nlite/nlite_property.cpp create mode 100644 nlite/stdafx.cpp create mode 100644 nlite_stub/nlite_stub.cpp diff --git a/nlib_driver/nlib_driver.cpp b/nlib_driver/nlib_driver.cpp new file mode 100644 index 0000000..543987b --- /dev/null +++ b/nlib_driver/nlib_driver.cpp @@ -0,0 +1,290 @@ +// nlib_driver.cpp : ƒRƒ“ƒ\[ƒ‹ ƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚̃Gƒ“ƒgƒŠ ƒ|ƒCƒ“ƒg‚ð’è‹`‚µ‚Ü‚·B +// + +#include "stdafx.h" +#include +#include +#include +#include +#include +#include +#include + + + +//ƒ‰ƒCƒuƒ‰ƒŠƒŠƒ“ƒN +#pragma comment(lib,"Wininet.lib") +#pragma comment(lib,"WinHttp.lib") +#pragma comment(lib,"Iepmapi.lib") +#pragma comment(lib,"ws2_32.lib") +#pragma comment(lib, "shell32.lib" ) +#pragma comment(lib,"expat.lib") +#pragma comment(lib,"sqlite3.lib") +#pragma comment(lib,"sqliteManager.lib") +#pragma comment(lib,"shareCookie.lib") +#pragma comment(lib,"nlib.lib") +#pragma comment(lib,"winmm.lib") +#pragma comment(lib,"JSONParser.lib") + + +NicoLiveStream_P nl; +NicoVideoAuth_P nva; +//NlibProperty_P np; +WSAData wsaData; +HINTERNET hInternet = WinHttpOpen(L"nicoliveTest",WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,(LPCWSTR)WINHTTP_NO_PROXY_NAME,(LPCWSTR)WINHTTP_NO_PROXY_BYPASS,0); + +int nicoLive_setup(void) { + + INT_PTR err; + INT_PTR count = 0; + + + //WSAData‚ð‰Šú‰» + while((err = WSAStartup(MAKEWORD(2,0),&wsaData)) == WSASYSNOTREADY){ + + count++; + if(count >= 5)break; + Sleep(500); + + + + } + + if(err != ERROR_SUCCESS){ + + return NLIB_INITALIZE_FAILED_NETWORK; + } + InitializeNLIB(hInternet); + nl = NicoLiveStream_new(); + nva = NicoVideoAuth_new(); + //np = NlibProperty_ref(); + + NicoVideoAuth_getNicoVideoAuth(nva,BT_GOOGLE_CHROME); + return nl != NULL ? 0 : 1; +} + +int nicoLive_teardown(void) { + NicoLiveStream_delete(&nl); + NicoVideoAuth_delete(&nva); + FinalizeNLIB(); + WinHttpCloseHandle(hInternet); + WSACleanup(); + return 0; +} + + +int FreeList_setup(void){ + + + return 0; +} + + + +NLIB_RESULT callback(NICOLIVE_EVENT eventType,NicoLiveStream_P pNicoLiveStream,LPVOID option,NICOLIVE_PARAM param1,NICOLIVE_PARAM param2){ + + + switch(eventType){ + + case NICOLIVE_EVENT_ERR_CONNECT: + + errprint(TEXT("’ʐMƒGƒ‰[”­¶")); + + break; + + + case NICOLIVE_EVENT_RECEVE_CONNECTRESULT: + + 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); + + break; + + case NICOLIVE_EVENT_RECEVE_CHAT: + + { + int i = 0; + NicoLiveChat_P chatP = (NicoLiveChat_P)param1; + int index = chatP->mailCount; + 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); + + + + for(;i < index;i++){ + + println(TEXT("mail(%d)[%s]"),i,chatP->mail[i]); + + } + + println(TEXT("chatBody::%s"),chatP->chatBuf); + + } + break; + + case NICOLIVE_EVENT_RECEVE_CHATSETTLE: + + + + println(TEXT("recevechatCount::no[%d],count[%d]"),param1,param2); + param1; + + break; + + case NICOLIVE_EVENT_RECEVE_CHATSENDRESULT: + + { + NicoLiveSendResultComment_P nls = (NicoLiveSendResultComment_P)param1; + + println(TEXT("sendresult::no[%s],status[%s],thread[%s]"),nls->no,nls->status,nls->thread); + + } + + break; + + case NICOLIVE_EVENT_SEND_HEARTBEAT: + + { + + NicoLiveHeartBeat_P hbp = (NicoLiveHeartBeat_P)param1; + + 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); + //println(TEXT("heartbeat::watchCount[%d],commentCount[%d],is_restrict[%s],ticket[%s]"),hbp->watchCount,hbp->commentCount,hbp->is_restrict,hbp->ticket); + + + } + + + break; + + + } + + return 0; +} + +NLIB_RESULT myListCallBack(LPVOID option,NicoMyListItem_P pVideo){ + + dumpln(TEXT("video_id:%s"),pVideo->itemData.video_id); + + + + return NLIB_ERR_OK; +} + +static NLIB_RESULT myListGroupCallBack(LPVOID option,NicoMyList_P pMyList){ + WCHAR buf[256]; + NLIB_RESULT rslt; + wcscpy(buf,pMyList->id); + dumpln(TEXT("id:%s"),buf); + rslt = NicoMyList_getMyList(nva,buf,myListCallBack,NULL); + + + + return NLIB_ERR_OK; +} + +void nicoLive_connect(void) { + + dumpline(); + //NlibProperty_setBrowserType(np,BT_INTERNET_EXPLORER); + //CU_ASSERT_EQUAL(NicoLiveStream_connect(nl,BT_INTERNET_EXPLORER,L"lv12345",callback,NULL), NLIB_ERR_GETPLAYERSTATUS_INVALID_LV); + + + + NicoLiveStrream_setResFrom(nl,1000); + NicoLiveStream_setHeartBeatMsec(nl,5000); + NicoLiveStream_setKeapALiveMsec(nl,5000); + //NicoLiveStream_setKeapALiveFlag(nl,FALSE); + + //CU_ASSERT_EQUAL(NicoLiveStream_connect(nl,nva,L"lv66406941",callback,NULL), NLIB_ERR_OK); + WCHAR housoubuf[LENGTH_1024]; + std::wcin.getline(housoubuf,sizeof(housoubuf) / sizeof(housoubuf[0])); + + WCHAR buf[1024]; + + + + for(int index = 0;index < 5;index++){ + CU_ASSERT_EQUAL(NicoLiveStream_connect(nl,nva,housoubuf,callback,NULL), NLIB_ERR_OK); + std::wcin.getline(buf,sizeof(buf) / sizeof(buf[0])); + + LPWSTR mail = L"184"; + LPWSTR exname = L"name"; + LPWSTR exvalue = L"qwerty"; + + LPCWSTR mails[2] = {mail,NULL}; + LPCWSTR extends[3] = {exname,exvalue,NULL}; + + + while(wcslen(buf) > 0){ + + NicoLiveStream_sendChat(nl,buf,mails,NULL); + std::wcin.getline(buf,sizeof(buf) / sizeof(buf[0])); + } + NicoLiveStream_disConnect(nl); + } + + CU_ASSERT_EQUAL(_heapchk(),_HEAPOK); + + //Sleep(3000); + + + /* + //NlibProperty_setBrowserType(np,BT_FIRE_FOX); + CU_ASSERT_EQUAL(NicoLiveStream_connect(nl,BT_FIRE_FOX,L"lv12345",callback,NULL), 0); + //NlibProperty_setBrowserType(np,BT_GOOGLE_CHROME); + CU_ASSERT_EQUAL(NicoLiveStream_connect(nl,BT_GOOGLE_CHROME,L"lv12345",callback,NULL), 0); + //NlibProperty_setBrowserType(np,BT_IE_COMPONENT); + CU_ASSERT_EQUAL(NicoLiveStream_connect(nl,BT_IE_COMPONENT,L"lv12345",callback,NULL), 0); + */ + + return; +} + + +void nicoLive_mylist(void) { + + + + //CU_ASSERT_EQUAL(NicoMyList_getDefList(nva,myListCallBack,NULL), NLIB_ERR_OK); + //CU_ASSERT_EQUAL(NicoMyList_getMyListGroup(nva,myListGroupCallBack,NULL),NLIB_ERR_OK); + CU_ASSERT_EQUAL(NicoMyList_addItem(L"sm16046365"),NLIB_ERR_OK); + check(_heapchk() == _HEAPOK,TEXT("heapƒGƒ‰[‚Å‚·")); + dumpln(TEXT("heapchk:%d"),_heapchk()); + + +} + + +static CU_TestInfo nlive_test[] = { + { "Ú‘±", nicoLive_connect }, + //{"ƒ}ƒCƒŠƒXƒg",nicoLive_mylist}, + CU_TEST_INFO_NULL, +}; + + + +static CU_SuiteInfo suites[] = { + { "nicoLiveStream‚̃eƒXƒg", nicoLive_setup, nicoLive_teardown, nlive_test }, + CU_SUITE_INFO_NULL, /* ––”ö‚ÍCU_SUITE_INFO_NULL‚ŏI’[ */ + +}; + + +int _tmain(int argc, _TCHAR* argv[]) +{ + + + + + + CU_initialize_registry(); + CU_register_suites(suites); + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + + + + getch(); + return 0; +} \ No newline at end of file diff --git a/nlib_driver/stdafx.cpp b/nlib_driver/stdafx.cpp new file mode 100644 index 0000000..e87cba0 --- /dev/null +++ b/nlib_driver/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : •W€ƒCƒ“ƒNƒ‹[ƒh nlib_driver.pch ‚Ì‚Ý‚ð +// ŠÜ‚Þƒ\[ƒX ƒtƒ@ƒCƒ‹‚́AƒvƒŠƒRƒ“ƒpƒCƒ‹Ï‚݃wƒbƒ_[‚É‚È‚è‚Ü‚·B +// stdafx.obj ‚ɂ̓vƒŠƒRƒ“ƒpƒCƒ‹Ï‚ÝŒ^î•ñ‚ªŠÜ‚Ü‚ê‚Ü‚·B + +#include "stdafx.h" + +// TODO: ‚±‚̃tƒ@ƒCƒ‹‚Å‚Í‚È‚­ASTDAFX.H ‚Å•K—v‚È +// ’ljÁƒwƒbƒ_[‚ðŽQÆ‚µ‚Ä‚­‚¾‚³‚¢B diff --git a/nlite/nlite.cpp b/nlite/nlite.cpp new file mode 100644 index 0000000..d51b219 --- /dev/null +++ b/nlite/nlite.cpp @@ -0,0 +1,166 @@ +// nlite.cpp : ƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚̃Gƒ“ƒgƒŠ ƒ|ƒCƒ“ƒg‚ð’è‹`‚µ‚Ü‚·B +// + +#include "stdafx.h" +#include "nlite_include.h" + + +CAppModule _Module; + +const CApplicationInfo* nlite::appInfo = NULL; +static TCHAR localAppDataPath[_MAX_PATH]; + +static WSAData wsaData; //winsockdata +static HINTERNET hInternet = NULL; + +static BOOL InitializeNlite(); //ƒAƒvƒŠƒP[ƒVƒ‡ƒ“‰Šú‰» +static VOID FinalizeNlite(); //ƒAƒvƒŠƒP[ƒVƒ‡ƒ“I—¹ˆ— +static CNliteMainFrame wnd; //ƒƒCƒ“ƒtƒŒ[ƒ€ƒEƒBƒ“ƒhƒE +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, + LPTSTR lpCmdLine, int nCmdShow) +{ + + int nRet = -1; + try{ + if(_Module.Init(NULL, hInstance) != S_OK){ + throw AppInitException(__LINE__,TEXT(__FILE__)); + } + + if(InitializeNlite() != TRUE){ + throw AppInitException(__LINE__,TEXT(__FILE__)); + } + + + + + CMessageLoop theLoop; + _Module.AddMessageLoop(&theLoop); + + + + wnd.CreateEx(0,0,WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN); + wnd.ShowWindow(nCmdShow); + wnd.UpdateWindow(); + wnd.Initialize(localAppDataPath); + _heapmin(); + + + + nRet = theLoop.Run(); + + vcassert(_heapchk() == _HEAPOK,TEXT("ƒq[ƒvƒGƒ‰[‚Å‚·")); + + goto nliteend; + + } catch(nlite::Exception &e){ + tstring errMessage(TEXT("ƒGƒ‰[ƒƒbƒZ[ƒW:")); + errMessage += e.what(); + errMessage += TEXT("\r\ns”ԍ†:"); + std::wostringstream num; + num << e.getLineNo(); + errMessage += num.str(); + errMessage += TEXT("\r\nƒtƒ@ƒCƒ‹–¼:"); + errMessage += e.getFileName(); + + MessageBox(NULL,errMessage.c_str(),TEXT("ƒnƒ“ƒhƒ‹‚³‚ê‚Ä‚È‚¢ƒGƒ‰["),MB_ICONERROR | MB_OK); + + goto nlitefinally; + }catch(std::exception &e){ + + MessageBoxA(NULL,e.what(),"ƒnƒ“ƒhƒ‹‚³‚ê‚Ä‚È‚¢•s–¾‚̃Gƒ‰[",MB_ICONERROR | MB_OK); + + goto nlitefinally; + } + +nlitefinally: + wnd.OnException(); + wnd.DestroyWindow(); + + +nliteend: + + _Module.RemoveMessageLoop(); + FinalizeNlite(); + _Module.Term(); + + + return nRet; +} + +static BOOL InitializeNlite(){ + + BOOL rslt = FALSE; + + try{ + + nlite::appInfo = &CApplicationInfo::getInstance(); + INT_PTR err; + INT_PTR count = 0; + + //WSAData‚ð‰Šú‰» + while((err = WSAStartup(MAKEWORD(2,0),&wsaData)) == WSASYSNOTREADY){ + + count++; + if(count >= 5)break; + Sleep(500); + + + + } + + if(err != ERROR_SUCCESS){ + + throw AppInitException(__LINE__,TEXT(__FILE__)); + } + + const CApplicationInfo &appInfo = CApplicationInfo::getInstance(); + tstring userAgent; + userAgent.reserve(256); + userAgent = appInfo.getProcuctName(); + userAgent += TEXT("/"); + userAgent += appInfo.getProductVersion(); + + + hInternet = WinHttpOpen(userAgent.c_str(),WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,(LPCWSTR)WINHTTP_NO_PROXY_NAME,(LPCWSTR)WINHTTP_NO_PROXY_BYPASS,0); + + if(hInternet == NULL){ + + throw AppInitException(__LINE__,TEXT(__FILE__)); + + } + + InitializeNLIB(hInternet); + + if(SHGetFolderPathW(0,CSIDL_LOCAL_APPDATA,0,SHGFP_TYPE_CURRENT,localAppDataPath) != S_OK){ + + throw AppInitException(__LINE__,TEXT(__FILE__)); + } + + + SystemParametersInfo (SPI_SETLISTBOXSMOOTHSCROLLING,FALSE,FALSE,0); + + + }catch (AppInitException e){ + + return rslt; + + } + + + + rslt = TRUE; + + + return rslt; +} + + + VOID FinalizeNlite(){ + + wnd.Finalaize(); + FinalizeNLIB(); + WinHttpCloseHandle(hInternet); + WSACleanup(); + + return; + } \ No newline at end of file diff --git a/nlite/nlite_appInfo.cpp b/nlite/nlite_appInfo.cpp new file mode 100644 index 0000000..f57ec34 --- /dev/null +++ b/nlite/nlite_appInfo.cpp @@ -0,0 +1,105 @@ +#include "stdafx.h" +#include "nlite_include.h" + + +CApplicationInfo::CApplicationInfo(){ + + struct LANGANDCODEPAGE { + + WORD wLanguage; + WORD wCodePage; + } *lpTranslate; + TCHAR szModuleName[_MAX_PATH + 1] = {0}; //ƒAƒvƒŠƒP[ƒVƒ‡ƒ“ƒtƒ@ƒCƒ‹–¼ + try{ + + DWORD dwReserved; + LPTSTR errMessage = NULL; + int nRet = GetModuleFileName(NULL,szModuleName,ARRAYSIZE(szModuleName)); + assert(nRet > 0); + + if(nRet <= 0){ + + + throw AppInitException(__LINE__,TEXT(__FILE__)); + } + + + DWORD dwSize = GetFileVersionInfoSize(szModuleName,&dwReserved); + + assert(dwSize > 0); + + if(dwSize <= 0){ + + throw AppInitException(__LINE__,TEXT(__FILE__)); + } + + pBlock = malloc(dwSize); + assert(pBlock != NULL); + + BOOL bRet = GetFileVersionInfo(szModuleName,0,dwSize,pBlock); + + assert(bRet); + + if(bRet != TRUE){ + throw AppInitException(__LINE__,TEXT(__FILE__)); + } + + UINT ulen; + if(VerQueryValue(pBlock,TEXT("\\VarFileInfo\\Translation"),(LPVOID*)&lpTranslate,&ulen) == FALSE){ + throw AppInitException(__LINE__,TEXT(__FILE__)); + } + + TCHAR subBlock[_MAX_PATH]; + _stprintf(subBlock,TEXT("\\StringFileInfo\\%04x%04x\\ProductVersion"),lpTranslate->wLanguage,lpTranslate->wCodePage); + + if(VerQueryValue(pBlock,subBlock,(LPVOID *)&pProductVersion,&ulen) == FALSE){ + + throw AppInitException(__LINE__,TEXT(__FILE__)); + + } + + _stprintf(subBlock,TEXT("\\StringFileInfo\\%04x%04x\\OriginalFilename"),lpTranslate->wLanguage,lpTranslate->wCodePage); + + if(VerQueryValue(pBlock,subBlock,(LPVOID *)&pOriginalFileName,&ulen) == FALSE){ + + throw AppInitException(__LINE__,TEXT(__FILE__)); + + } + + _stprintf(subBlock,TEXT("\\StringFileInfo\\%04x%04x\\LegalCopyright"),lpTranslate->wLanguage,lpTranslate->wCodePage); + + if(VerQueryValue(pBlock,subBlock,(LPVOID *)&pLegalCopyright,&ulen) == FALSE){ + + throw AppInitException(__LINE__,TEXT(__FILE__)); + + } + + _stprintf(subBlock,TEXT("\\StringFileInfo\\%04x%04x\\ProductName"),lpTranslate->wLanguage,lpTranslate->wCodePage); + + if(VerQueryValue(pBlock,subBlock,(LPVOID *)&pProductName,&ulen) == FALSE){ + + throw AppInitException(__LINE__,TEXT(__FILE__)); + + } + + + } catch (const AppInitException& e){ + + + safeFree(pBlock); + + throw e; + } + + return; + + + +} + + +CApplicationInfo::~CApplicationInfo(){ + + + safeFree(pBlock); +} \ No newline at end of file diff --git a/nlite/nlite_commentview.cpp b/nlite/nlite_commentview.cpp new file mode 100644 index 0000000..184fdf2 --- /dev/null +++ b/nlite/nlite_commentview.cpp @@ -0,0 +1,229 @@ +#include "stdafx.h" +#include "nlite_include.h" + + + + +VOID CCommentView::CommentLineSet(LPCTSTR chat,UINT_PTR count){ + + + + CDC cdc = listBox.GetDC(); + + RECT drowSize = {0}; + header.GetItemRect(COMMENT,&drowSize); + drowSize.left += 2; + drowSize.top += 2; + drowSize.right -= 2; + drowSize.bottom = 0; + + SelectObject(cdc,AtlGetDefaultGuiFont()); + cdc.DrawTextW(chat,-1,&drowSize, DT_CALCRECT | DT_WORDBREAK); + drowSize.top -= 2; + drowSize.left -= 2; + drowSize.right += 2; + drowSize.bottom += 2; + + listBox.SetItemHeight(listBox.GetCount() -1,drowSize.bottom - drowSize.top); + + return; +} + + +VOID CCommentView::OnHeaderTrack(){ + + Lock(); + + UINT_PTR commentCount = commentlist.Size(); + listBox.ResetContent(); + for(UINT_PTR index =0;index < commentCount;index++){ + listBox.AddString(NULL); + CommentLineSet(commentlist.GetChatAt(index).chatBuf.c_str(),index); + + } + + Unlock(); + + listBox.InvalidateRect(NULL,TRUE); + + + +} + +VOID CCommentView::OnChatReceve(NicoLiveChat_P chat,UINT_PTR count){ + + + + Lock(); + commentlist.OnChatReceve(chat,count); + listBox.AddString(NULL); + Unlock(); + + CommentLineSet(chat->chatBuf,count); + + +} + +VOID CCommentView::OnChatReceveSettle(UINT_PTR commentCount,UINT_PTR commentCountSum){ + + return; +} + + +VOID CCommentView::OnDrawList(LPDRAWITEMSTRUCT lpDrawItemStruct){ + + + + Lock(); + + RECT noViewRect; + RECT userNameViewRect; + RECT timeViewRect; + RECT chatViewRect; + RECT infoViewRect; + + header.GetItemRect(NO,&noViewRect); + header.GetItemRect(USERNAME,&userNameViewRect); + header.GetItemRect(TIME,&timeViewRect); + header.GetItemRect(COMMENT,&chatViewRect); + header.GetItemRect(INFO,&infoViewRect); + + noViewRect.left += 2; + userNameViewRect.left += 2; + timeViewRect.left += 2; + chatViewRect.left += 2; + infoViewRect.left += 2; + + noViewRect.right += 2; + userNameViewRect.right += 2; + timeViewRect.right += 2; + chatViewRect.right += 2; + infoViewRect.right += 2; + + noViewRect.top = lpDrawItemStruct->rcItem.top + 2; + userNameViewRect.top = lpDrawItemStruct->rcItem.top + 2; + timeViewRect.top = lpDrawItemStruct->rcItem.top + 2; + chatViewRect.top = lpDrawItemStruct->rcItem.top + 2; + infoViewRect.top = lpDrawItemStruct->rcItem.top + 2; + + noViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2; + userNameViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2; + timeViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2; + chatViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2; + infoViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2; + + CChatData &chatData = commentlist.GetChatAt(lpDrawItemStruct->itemID); + + time_t chatTime = (time_t)difftime(chatData.date,streamStatus.start_time); + tm ct = *gmtime(&chatTime); + + + TCHAR noString[sizeof(chatData.no) * 8]; + TCHAR dateString[LENGTH_16]; + _stprintf(noString,TEXT("%u"),chatData.no); + + _tcsftime(dateString,ARRAY_LENGTH(dateString),ct.tm_hour != 0 ? TEXT("%H:%M:%S") : TEXT("%M:%S"),&ct); + + CBrush bkBurush; + CPen outLinePen; + CPen colLinePen; + //‘I‘ðó‘Ô‚©ƒ`ƒFƒbƒN + if ((lpDrawItemStruct->itemState) & (ODS_SELECTED)) + { + + //ƒuƒ‰ƒVì¬ + bkBurush=CreateSolidBrush(RGB(255,240,240)); +// outLinePen = CreatePen(PS_SOLID,3,RGB(255,0,0)); + //ƒeƒLƒXƒg‚Ì”wŒiF‚ðŽw’è + SetBkColor(lpDrawItemStruct->hDC,RGB(255,240,240)) ; + } + else + { + //ƒuƒ‰ƒVì¬ + bkBurush=CreateSolidBrush(viewproperty.backColor); + + + //ƒeƒLƒXƒg‚Ì”wŒiF‚ðŽw’è + SetBkColor(lpDrawItemStruct->hDC,viewproperty.backColor) ; + } + + outLinePen = CreatePen(PS_SOLID,1,RGB(127,127,127)); + //ƒeƒLƒXƒg‚̃Jƒ‰[‚ðÝ’è + SetTextColor(lpDrawItemStruct->hDC,viewproperty.baseStringColor); + + SelectObject(lpDrawItemStruct->hDC,bkBurush); + SelectObject(lpDrawItemStruct->hDC,outLinePen); + Rectangle(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom); + DeleteObject(outLinePen); + DeleteObject(colLinePen); + DeleteObject(bkBurush); + + ::DrawText(lpDrawItemStruct->hDC,noString,_tcslen(noString),&noViewRect,DT_WORD_ELLIPSIS); + + ::DrawText(lpDrawItemStruct->hDC,chatData.user_id.c_str(),chatData.user_id.length(),&userNameViewRect,DT_WORD_ELLIPSIS); + + ::DrawText(lpDrawItemStruct->hDC,chatData.chatBuf.c_str(),chatData.chatBuf.length(),&chatViewRect,DT_WORDBREAK); + + ::DrawText(lpDrawItemStruct->hDC,dateString,_tcslen(dateString),&timeViewRect,DT_WORD_ELLIPSIS); + + + Unlock(); + + + + + return; +} + + + +VOID CCommentList::OnChatReceve(NicoLiveChat_P chatData_in, UINT_PTR count){ + + + CChatData chatData; + chatData.SetChat(*chatData_in); + + + + chatList.push_back(chatData); + return; +} + + + +VOID CChatData::SetChat(NicoLiveChat &chat_in){ + + + this->anonymity = _ttol(chat_in.anonymity); + this->premium = _ttol(chat_in.premium); + this->chatBuf = chat_in.chatBuf; + this->no = _ttol(chat_in.no); + + if(_tcscmp(chat_in.locale,TEXT("jp")) == 0){ + this->locale = cuntry::jp; + } else { + this->locale = cuntry::unknown; + } + this->mail.reserve(chat_in.mailCount); + for(UINT_PTR index = 0;index < chat_in.mailCount ;index++){ + + this->mail.push_back(chat_in.mail[index]); + } + + this->name = chat_in.name; + + this->user_id = chat_in.user_id; + + + + this->vpos = _ttol(chat_in.vpos); + this->thread = _ttol(chat_in.thread); + this->date = _ttol(chat_in.date); + + + + return; +} + + + diff --git a/nlite/nlite_mainframe.cpp b/nlite/nlite_mainframe.cpp new file mode 100644 index 0000000..eaa3325 --- /dev/null +++ b/nlite/nlite_mainframe.cpp @@ -0,0 +1,158 @@ +#include "stdafx.h" +#include "nlite_include.h" + + + + +static const RECT commentViewSize = {5,0,5,0}; + + + + +//ƒTƒCƒY•ÏXˆ— +VOID CNliteMainFrame::ChangeSize(const SIZE& client){ + + + + + + tabctrl.MoveWindow(0,toolBarHeight,client.cx,client.cy - (toolBarHeight + statusBarHeight + commentWriteWindowSize.cy)); + + + RECT tabClientRect; + tabctrl.GetClientRect(&tabClientRect); + tabctrl.AdjustRect(FALSE,&tabClientRect); + + + + + commentView.MoveWindow(tabClientRect.left, tabClientRect.top,tabClientRect.right - tabClientRect.left, tabClientRect.bottom - tabClientRect.top); + + commentWriteWindow.MoveWindow(0,client.cy - (commentWriteWindowSize.cy + statusBarHeight),client.cx,client.cy); + + + + return; +} + +LRESULT CNliteMainFrame::OnCreate(LPCREATESTRUCT lpcs){ + + + // ƒXƒe[ƒ^ƒXƒo[‚ðì¬ + vcverify(CreateSimpleStatusBar(),TEXT("ƒXƒe[ƒ^ƒXƒo[ì¬‚ÉŽ¸”s‚µ‚Ü‚µ‚½")); + tabctrl.Create(m_hWnd,0,NULL,WS_CHILD | WS_CLIPCHILDREN | WS_DLGFRAME); + commentView.Create(tabctrl.m_hWnd); + + commentWriteWindow.Create(m_hWnd,0,NULL,WS_CHILD | WS_VISIBLE); + + CreateSimpleReBar(); + HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd,IDC_NLITE, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE); + lvNoCombo.Create(m_hWnd, CRect(0, 0, 100, 100), NULL,WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWN , 0, IDC_COMBO_REBAR); + + + subLiveNoComboBox.SubclassWindow(lvNoCombo.GetEditCtrl()); + lvNoCombo.SetFont(AtlGetDefaultGuiFont()); + + + + AddSimpleReBarBand(hWndToolBar); + AddSimpleReBarBand(lvNoCombo,TEXT("•ú‘—URL")); + SizeSimpleReBarBands(); + + + + tabctrl.SetFont(hTabFont); + tabctrl.SetWindowPos(HWND_BOTTOM,0,0,0,0,SWP_SHOWWINDOW); + tabctrl.AddItem(TCIF_TEXT | TCIF_PARAM, _T("ƒRƒƒ“ƒgˆê——"), 0, (DWORD)commentView.m_hWnd); + + + + // ƒƒbƒZ[ƒWƒ‹[ƒv‚ɃƒbƒZ[ƒWƒtƒBƒ‹ƒ^‚ƃAƒCƒhƒ‹ƒnƒ“ƒhƒ‰‚ð’ljÁ + CMessageLoop* pLoop = _Module.GetMessageLoop(); + pLoop->AddMessageFilter(this); + pLoop->AddIdleHandler(this); + + RECT wndRect; + this->GetWindowRect(&wndRect); + + LONG cyMaxImized = GetSystemMetrics (SM_CYMAXIMIZED); + wndRect.bottom = nliteProperty.mfp.windowSize.cy != 0 ? nliteProperty.mfp.windowSize.cy : (LONG)cyMaxImized / 2; + wndRect.right = nliteProperty.mfp.windowSize.cx != 0 ? nliteProperty.mfp.windowSize.cx : commentViewSize.left + commentViewSize.right + 20 + commentView.GetColumnHolSizeSum(); + + + + RECT statusbarRect; + ::GetClientRect(m_hWndStatusBar,&statusbarRect); + + statusBarHeight = statusbarRect.bottom - statusbarRect.top; + + + + this->MoveWindow(wndRect.left,wndRect.top,wndRect.right,wndRect.bottom); + + + + + return 0; +} + +NLIB_RESULT CNliteMainFrame::LiveCallBack(NICOLIVE_EVENT eventType,NicoLiveStream_P pNicoLiveStream,LPVOID option,NICOLIVE_PARAM param1,NICOLIVE_PARAM param2){ + + CLiveUserData &userData = (*(CLiveUserData*)option); + + try{ + switch(eventType){ + + case NICOLIVE_EVENT_RECEVE_CONNECTRESULT: + + userData.OnChatReceveStart(*NicoLiveStream_getStreamStatus(pNicoLiveStream)); + + break; + + case NICOLIVE_EVENT_RECEVE_CHAT: + + userData.OnChatReceve((NicoLiveChat_P) param1,param2); + + break; + + case NICOLIVE_EVENT_RECEVE_CHATSETTLE: + + userData.OnChatReceveSettle(param1,param2); + + break; + + case NICOLIVE_EVENT_RECEVE_CHATSENDRESULT: + + break; + + case NICOLIVE_EVENT_SEND_HEARTBEAT: + + break; + + case NICOLIVE_EVENT_ERR_CONNECT: + + throw NLiveException(TEXT("Ú‘±ƒGƒ‰[‚Å‚·"),__LINE__,TEXT(__FILE__)); + + break; + + default: + + throw NLiveException(TEXT("—\Šú‚µ‚È‚¢ƒƒbƒZ[ƒW‚ª‘—M‚³‚ê‚Ü‚µ‚½"),__LINE__,TEXT(__FILE__)); + + break; + } + + } catch(Exception e){ + + ::MessageBox(NULL,e.what(),TEXT("ƒnƒ“ƒhƒ‹‚³‚ê‚Ä‚¢‚È‚¢ƒGƒ‰["),MB_OK | MB_ICONSTOP | MB_TASKMODAL); + + } catch(std::exception e){ + + ::MessageBoxA(NULL,e.what(),"ƒnƒ“ƒhƒ‹‚³‚ê‚Ä‚¢‚È‚¢ƒGƒ‰[",MB_OK | MB_ICONSTOP | MB_TASKMODAL); + } + + + + + return NLIB_ERR_OK; +} \ No newline at end of file diff --git a/nlite/nlite_property.cpp b/nlite/nlite_property.cpp new file mode 100644 index 0000000..9dd057c --- /dev/null +++ b/nlite/nlite_property.cpp @@ -0,0 +1,334 @@ +#include "stdafx.h" +#include "nlite_include.h" + + + +#define NLITE_READ_INI_INT(cs,mm,path) cs.mm = GetPrivateProfileInt(cs.GetSectionName(),TEXT(#mm),cs.mm,path) + +#define NLITE_READ_INI_STR(cs,mm,bv,path) \ + GetPrivateProfileString(cs.GetSectionName(),TEXT(#mm),cs.mm.c_str(),&bv[0],bv.size(),path);\ + cs.mm = &bv[0]\ + /*ƒ}ƒNƒ@I—¹*/ + +#define NLITE_WRITE_INI_INT(cs,mm,path) WritePrivateProfileInt(cs.GetSectionName(),TEXT(#mm),cs.mm,path) + +#define NLITE_WRITE_INI_STR(cs,mm,path) WritePrivateProfileString(cs.GetSectionName(),TEXT(#mm),cs.mm.c_str(),path) + + +#define NLITE_HOLIZONE_SIZE TEXT("headerholSize%u") + + +static const LPCTSTR bt_none = TEXT("none"); +static const LPCTSTR bt_ie = TEXT("ie"); +static const LPCTSTR bt_chrome = TEXT("chrome"); +static const LPCTSTR bt_firefox = TEXT("firefox"); +static const LPCTSTR bt_iecm = TEXT("iecm"); + +static +BOOL +WINAPI +WritePrivateProfileInt( + LPCTSTR lpAppName, + LPCTSTR lpKeyName, + LONG lData, + LPCTSTR lpFileName +) +{ + TCHAR value[LENGTH_256]; + + _stprintf(value, TEXT("%d"), lData); + return WritePrivateProfileString( + lpAppName, + lpKeyName, + value, + lpFileName); +} + + +VOID Property::ReadIniFile(){ + + CreatePropertyFile(); + + std::vector buffer(LENGTH_2048); + + //crp‚̐ݒè’l“ǂݍž‚Ý + + NLITE_READ_INI_INT(crp,besideLengthFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(crp,bspReadFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(crp,commentReadFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(crp,managementReadFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(crp,maxCommentLength,propertyPath.c_str()); + + NLITE_READ_INI_INT(crp,newLineReadFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(crp,ngUserReadFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(crp,ngWordReadFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(crp,teropReadFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(crp,userCommentReadFlag,propertyPath.c_str()); + + NLITE_READ_INI_STR(crp,outString,buffer,propertyPath.c_str()); + + NLITE_READ_INI_STR(crp,shortComment,buffer,propertyPath.c_str()); + + + //commentviewÝ’è’l“ǂݍž‚Ý + + NLITE_READ_INI_INT(cvp,anonymousIDLinkColor,propertyPath.c_str()); + + NLITE_READ_INI_INT(cvp,backColor,propertyPath.c_str()); + + NLITE_READ_INI_INT(cvp,baseStringColor,propertyPath.c_str()); + + NLITE_READ_INI_INT(cvp,commentFoldingFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(cvp,commentTimeType,propertyPath.c_str()); + + NLITE_READ_INI_INT(cvp,IDLinkColor,propertyPath.c_str()); + + NLITE_READ_INI_INT(cvp,lineColor,propertyPath.c_str()); + + LPCTSTR headerFormat = NLITE_HOLIZONE_SIZE; + TCHAR headerKey[_MAX_PATH]; + + for(UINT_PTR index = 0;index < ARRAY_LENGTH(cvp.headerholSize);index++){ + _stprintf(headerKey,headerFormat,index); + cvp.headerholSize[index] = GetPrivateProfileInt(cvp.GetSectionName(),headerKey,cvp.headerholSize[index],propertyPath.c_str()); + } + + //mainframeÝ’è’l“ÇŽæ + + NLITE_READ_INI_INT(mfp,windowFrontFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(mfp,windowSize.cx,propertyPath.c_str()); + + NLITE_READ_INI_INT(mfp,windowSize.cy,propertyPath.c_str()); + + //generalÝ’è’l“ÇŽæ + + NLITE_READ_INI_INT(gp,activeCountTimeFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(gp,autoColorRegisterFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(gp,autoNameRegisterFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(gp,autoNameUpdateFlag,propertyPath.c_str()); + + NLITE_READ_INI_STR(gp,browserPath,buffer,propertyPath.c_str()); + + NLITE_READ_INI_INT(gp,commentLogAutoSaveFlag,propertyPath.c_str()); + + NLITE_READ_INI_STR(gp,commentPath,buffer,propertyPath.c_str()); + + NLITE_READ_INI_INT(gp,defaultBroserFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(gp,numberNameFlag,propertyPath.c_str()); + + NLITE_READ_INI_INT(gp,userCountUpdateFlag,propertyPath.c_str()); + + + + typedef std::map funcs_type; + + funcs_type funcs; + funcs.insert(std::make_pair(bt_none, BT_NOSETTING)); + funcs.insert(std::make_pair(bt_ie, BT_INTERNET_EXPLORER)); + funcs.insert(std::make_pair(bt_firefox, BT_FIRE_FOX)); + funcs.insert(std::make_pair(bt_chrome, BT_GOOGLE_CHROME)); + funcs.insert(std::make_pair(bt_iecm,BT_IE_COMPONENT)); + + tstring browserTypeName; + + GetPrivateProfileString(gp.GetSectionName(),TEXT(TOSTR(browserType)),bt_none,&buffer[0],buffer.size(),propertyPath.c_str()); + browserTypeName = &buffer[0]; + + funcs_type::iterator it = funcs.find(browserTypeName); + if (it != funcs.end()){ + + gp.browserType = it->second; + }else{ + throw AppInitException(__LINE__,TEXT(__FILE__)); + } + + return; +} + + +VOID Property::CreatePropertyFile(){ + + propertyPath = appLocalPath; + + propertyPath += TEXT("\\qwerty_nico"); + + if(PathIsDirectory(propertyPath.c_str()) == FALSE){ + + if(CreateDirectory(propertyPath.c_str(),NULL) == 0){ + throw Exception(TEXT("Ý’èƒtƒ@ƒCƒ‹ì¬‚ÉŽ¸”s‚µ‚Ü‚µ‚½"),__LINE__,TEXT(__FILE__)); + } + + } + + propertyPath += TEXT("\\nlite"); + + if(PathIsDirectory(propertyPath.c_str()) == FALSE){ + + if(CreateDirectory(propertyPath.c_str(),NULL) == 0){ + throw Exception(TEXT("Ý’èƒtƒ@ƒCƒ‹ì¬‚ÉŽ¸”s‚µ‚Ü‚µ‚½"),__LINE__,TEXT(__FILE__)); + } + + } + + propertyPath += TEXT("\\property.ini"); + + + if(PathFileExists(propertyPath.c_str())== FALSE || PathIsDirectory(propertyPath.c_str()) == TRUE){ + HANDLE hPropertyini = CreateFile(propertyPath.c_str(),GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); + + if(hPropertyini == INVALID_HANDLE_VALUE ){ + + throw Exception(TEXT("Ý’èƒtƒ@ƒCƒ‹ì¬‚ÉŽ¸”s‚µ‚Ü‚µ‚½"),__LINE__,TEXT(__FILE__)); + + } + + + CloseHandle(hPropertyini); + } + + return; +} + + +VOID Property::WriteIniFile(){ + + CreatePropertyFile(); + + //ƒRƒƒ“ƒg“ǂݏグÝ’菑‚«ž‚Ý + + NLITE_WRITE_INI_INT(crp,besideLengthFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(crp,bspReadFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(crp,commentReadFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(crp,managementReadFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(crp,maxCommentLength,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(crp,newLineReadFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(crp,ngUserReadFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(crp,ngWordReadFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(crp,teropReadFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(crp,userCommentReadFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_STR(crp,outString,propertyPath.c_str()); + + NLITE_WRITE_INI_STR(crp,shortComment,propertyPath.c_str()); + + + //commentviewÝ’è’l‘‚«ž‚Ý + + NLITE_WRITE_INI_INT(cvp,anonymousIDLinkColor,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(cvp,backColor,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(cvp,baseStringColor,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(cvp,commentFoldingFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(cvp,commentTimeType,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(cvp,IDLinkColor,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(cvp,lineColor,propertyPath.c_str()); + + LPCTSTR headerFormat = NLITE_HOLIZONE_SIZE; + TCHAR headerKey[_MAX_PATH]; + + for(UINT_PTR index = 0;index < ARRAY_LENGTH(cvp.headerholSize);index++){ + _stprintf(headerKey,headerFormat,index); + cvp.headerholSize[index] = WritePrivateProfileInt(cvp.GetSectionName(),headerKey,cvp.headerholSize[index],propertyPath.c_str()); + } + + //mainframeÝ’è’l‘‚«ž‚Ý + + NLITE_WRITE_INI_INT(mfp,windowFrontFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(mfp,windowSize.cx,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(mfp,windowSize.cy,propertyPath.c_str()); + + //generalÝ’è’l‘‚«ž‚Ý + + NLITE_WRITE_INI_INT(gp,activeCountTimeFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(gp,autoColorRegisterFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(gp,autoNameRegisterFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(gp,autoNameUpdateFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_STR(gp,browserPath,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(gp,commentLogAutoSaveFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_STR(gp,commentPath,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(gp,defaultBroserFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(gp,numberNameFlag,propertyPath.c_str()); + + NLITE_WRITE_INI_INT(gp,userCountUpdateFlag,propertyPath.c_str()); + + tstring browserTypeName; + + + switch (gp.browserType){ + + case BT_NOSETTING: + + browserTypeName = bt_none; + + break; + + case BT_INTERNET_EXPLORER: + + browserTypeName = bt_ie; + + break; + + case BT_GOOGLE_CHROME: + + browserTypeName = bt_chrome; + + break; + + case BT_FIRE_FOX: + + browserTypeName = bt_firefox; + + break; + + case BT_IE_COMPONENT: + browserTypeName = bt_iecm; + break; + + default: + browserTypeName = bt_none; + break; + + } + + WritePrivateProfileString(gp.GetSectionName(),TEXT(TOSTR(browserType)),browserTypeName.c_str(),propertyPath.c_str()); + + return; +} \ No newline at end of file diff --git a/nlite/stdafx.cpp b/nlite/stdafx.cpp new file mode 100644 index 0000000..a79bab0 --- /dev/null +++ b/nlite/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : •W€ƒCƒ“ƒNƒ‹[ƒh nlite.pch ‚Ì‚Ý‚ð +// ŠÜ‚Þƒ\[ƒX ƒtƒ@ƒCƒ‹‚́AƒvƒŠƒRƒ“ƒpƒCƒ‹Ï‚݃wƒbƒ_[‚É‚È‚è‚Ü‚·B +// stdafx.obj ‚ɂ̓vƒŠƒRƒ“ƒpƒCƒ‹Ï‚ÝŒ^î•ñ‚ªŠÜ‚Ü‚ê‚Ü‚·B + +#include "stdafx.h" + +// TODO: ‚±‚̃tƒ@ƒCƒ‹‚Å‚Í‚È‚­ASTDAFX.H ‚Å•K—v‚È +// ’ljÁƒwƒbƒ_[‚ðŽQÆ‚µ‚Ä‚­‚¾‚³‚¢B diff --git a/nlite_stub/nlite_stub.cpp b/nlite_stub/nlite_stub.cpp new file mode 100644 index 0000000..60158ef --- /dev/null +++ b/nlite_stub/nlite_stub.cpp @@ -0,0 +1,177 @@ +#define _CRT_SECURE_NO_WARNINGS 1 //vc++‚Ì‚¨‚¹‚Á‚©‚¢‚ÈŒx‚ðÁ‚·ƒ}ƒNƒ +#define _CRT_NON_CONFORMING_SWPRINTFS 1 //vc++‚Ì‚¨‚¹‚Á‚©‚¢‚ÈŒx‚ðÁ‚·ƒ}ƒNƒ + +#include +#include +#include "nlib_stub.h" +#include +#include +#include +#include +#include + + + +static void *nlibmemory; +static BROWSERTYPE browserType; +static unsigned int WINAPI commentthread(VOID *usadata); +NicoLiveStream_P NicoLiveStream_new(){ + + NicoLiveStream_P rslt = (NicoLiveStream_P)malloc(sizeof(NicoLiveStream)); + ZeroMemory(rslt,sizeof(*rslt)); + rslt->endEvent = CreateEvent(NULL,TRUE,FALSE,NULL); + return rslt; +} + +VOID NicoLiveStream_delete(NicoLiveStream_P* self){ + + NicoLiveStream_disConnect(*self); + CloseHandle((*self)->endEvent); + free(*self); + *self = NULL; + return; +} + +NicoVideoAuth_P NicoVideoAuth_new(){ + + return (NicoVideoAuth_P)malloc(65536); +} + +VOID NicoVideoAuth_delete(NicoVideoAuth_P *self){ + + free(*self); + *self= NULL; +} + + +NLIB_RESULT InitializeNLIB(HINTERNET hInternet){ + + nlibmemory = malloc(65536); + + return NLIB_ERR_OK; +} + + +VOID FinalizeNLIB(){ + + free(nlibmemory); +} + +NLIB_RESULT NicoVideoAuth_getNicoVideoAuth(NicoVideoAuth_P self,BROWSERTYPE browserType){ + + ::browserType = browserType; + + return NLIB_ERR_OK; +} + +NLIB_RESULT NicoLiveStream_connect(NicoLiveStream_P self,NicoVideoAuth_P nicoVideoAuth,LPCWSTR url,NicoRecvCallBack callback,LPVOID option){ + + NLIB_RESULT rslt = NLIB_ERR_OK; + + NicoLiveStream_disConnect(self); + + self->callback = callback; + self->option = option; + self->threadHandle = (HANDLE)_beginthreadex(NULL,0,commentthread,self,0,NULL); + + + + return rslt; +} + +VOID NicoLiveStream_disConnect(NicoLiveStream_P self){ + + SetEvent(self->endEvent); + if(self->threadHandle != INVALID_HANDLE_VALUE){ + WaitForSingleObject(self->threadHandle,INFINITE); + CloseHandle(self->threadHandle); + } + + + + self->threadHandle = NULL; + + ResetEvent(self->endEvent); + return; +} + +StreamStatus_P NicoLiveStream_getStreamStatus(NicoLiveStream_P self){ + + self->stream.base_time = 1324709820; + self->stream.open_time = 1324709820; + self->stream.end_time = 1324713599; + self->stream.start_time = 1324710000; + + _tcscpy(self->stream.id,TEXT("lv75313550")); + _tcscpy(self->stream.default_community,TEXT("co1187609")); + + self->stream.is_owner = FALSE; + self->stream.provider_type = COMMUNITY_PROVIDER_TYPE; + + + return &self->stream; +} + + +unsigned int WINAPI commentthread(VOID *usadata){ + + NicoLiveStream_P self = (NicoLiveStream_P)usadata; + + NicoLiveThreadComment threadcomment; + threadcomment.last_res = TEXT("256"); + threadcomment.server_time = TEXT("12345467"); + threadcomment.thread = TEXT("1234567"); + threadcomment.ticket = TEXT("0x12334445"); + self->callback(NICOLIVE_EVENT_RECEVE_CONNECTRESULT,self,self->option,(NICOLIVE_PARAM)&threadcomment,0); + + NicoLiveChat liveChat; + TCHAR noBuf[sizeof(UINT_PTR) * 8]; + liveChat.anonymity = TEXT(""); + + liveChat.date = TEXT("1324713598"); + liveChat.locale = TEXT("jp"); + LPCTSTR mails[] = {TEXT("184"),NULL}; + liveChat.mail = &mails[0]; + liveChat.mailCount = ARRAY_LENGTH(mails) - 1; + liveChat.name = TEXT(""); + liveChat.no = noBuf; + liveChat.premium = TEXT("1"); + liveChat.thread = TEXT("1000254"); + liveChat.user_id = TEXT("testuser"); + liveChat.vpos = TEXT("8852"); + int commentcount = 0; + + DWORD rslt; + for(int indexfirst = 0; indexfirst < 1000;indexfirst++){ + liveChat.chatBuf = commentcount % 2 == 0 ? TEXT("testcomment‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ") : TEXT("test"); + _stprintf((LPTSTR)liveChat.no,TEXT("%u"),commentcount); + self->callback(NICOLIVE_EVENT_RECEVE_CHAT,self,self->option,(NICOLIVE_PARAM)&liveChat,indexfirst); + commentcount++; + } + + + for(int index = 0,index2; index < 100;index++){ + + + for(index2 = 0;index2 < 3;index2++){ + + liveChat.chatBuf = commentcount % 2 == 0 ? TEXT("testcomment‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ‚ ") : TEXT("test"); + _stprintf((LPTSTR)liveChat.no,TEXT("%u"),commentcount); + self->callback(NICOLIVE_EVENT_RECEVE_CHAT,self,self->option,(NICOLIVE_PARAM)&liveChat,index + index2); + commentcount++; + } + + self->callback(NICOLIVE_EVENT_RECEVE_CHATSETTLE,self,self->option,100,commentcount); + if(( rslt = WaitForSingleObject(self->endEvent,0)) != WAIT_TIMEOUT){ + + goto end; + } + + + + } +end: + + _endthreadex(0); + return 0; +} \ No newline at end of file -- 2.11.0