1+ #ifdef _MSC_BUILD
2+ #include < Windows.h>
3+ #include < tchar.h>
4+ #endif
5+ #include < stdio.h>
6+ #include < stdlib.h>
7+ #include < string.h>
8+ #include < thread>
9+ #include < XEngine_Include/XEngine_CommHdr.h>
10+ #include < XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
11+ #include < XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
12+ #include " ../../XEngine_Source/StorageModule_BTorrent/BTorrent_Define.h"
13+ #include " ../../XEngine_Source/StorageModule_BTorrent/BTorrent_Error.h"
14+
15+ #ifdef _MSC_BUILD
16+ #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib")
17+ #pragma comment(lib,"../../XEngine_Source/Debug/StorageModule_BTorrent.lib")
18+ #endif
19+
20+ // g++ -std=c++17 -Wall -g NetHelp_APPBTorrent.cpp -o AVCodec_APPPlayer.exe -L ../../XEngine_Source/StorageModule_BTorrent -lXEngine_BaseLib -lStorageModule_BTorrent
21+
22+
23+ int BTorrent_Parse (LPCXSTR lpszFile)
24+ {
25+ XNETHANDLE xhToken;
26+
27+ if (!BTorrent_Parse_Init (&xhToken, lpszFile))
28+ {
29+ printf (" BTorrent_Parse_Init:%lX\n " , BTorrent_GetLastError ());
30+ return -1 ;
31+ }
32+ int nListCount = 0 ;
33+ BTORRENT_PARSEMAP** ppSt_ParseNode;
34+ if (!BTorrent_Parse_GetNode (xhToken, &ppSt_ParseNode, &nListCount))
35+ {
36+ printf (" BTorrent_Parse_GetNode:%lX\n " , BTorrent_GetLastError ());
37+ return -1 ;
38+ }
39+ for (int i = 0 ; i < nListCount; i++)
40+ {
41+ printf (" BTorrent_Parse_GetNode:%d = %s\n " , ppSt_ParseNode[i]->nValue , ppSt_ParseNode[i]->tszValue );
42+ }
43+ BaseLib_OperatorMemory_Free ((XPPPMEM)&ppSt_ParseNode, nListCount);
44+ nListCount = 0 ;
45+
46+ if (!BTorrent_Parse_GetTracker (xhToken, &ppSt_ParseNode, &nListCount))
47+ {
48+ printf (" BTorrent_Parse_GetTracker:%lX\n " , BTorrent_GetLastError ());
49+ return -1 ;
50+ }
51+ for (int i = 0 ; i < nListCount; i++)
52+ {
53+ printf (" BTorrent_Parse_GetTracker:%d = %s\n " , ppSt_ParseNode[i]->nValue , ppSt_ParseNode[i]->tszValue );
54+ }
55+ BaseLib_OperatorMemory_Free ((XPPPMEM)&ppSt_ParseNode, nListCount);
56+ nListCount = 0 ;
57+
58+ if (!BTorrent_Parse_GetSeeds (xhToken, &ppSt_ParseNode, &nListCount))
59+ {
60+ printf (" BTorrent_Parse_GetSeeds:%lX\n " , BTorrent_GetLastError ());
61+ return -1 ;
62+ }
63+ for (int i = 0 ; i < nListCount; i++)
64+ {
65+ printf (" BTorrent_Parse_GetSeeds:%d = %s\n " , ppSt_ParseNode[i]->nValue , ppSt_ParseNode[i]->tszValue );
66+ }
67+ BaseLib_OperatorMemory_Free ((XPPPMEM)&ppSt_ParseNode, nListCount);
68+ nListCount = 0 ;
69+
70+ int nPieceLen = 0 ;
71+ int nPieceCount = 0 ;
72+ if (!BTorrent_Parse_GetPiece (xhToken, &nPieceLen, &nPieceCount))
73+ {
74+ printf (" BTorrent_Parse_GetPiece:%lX\n " , BTorrent_GetLastError ());
75+ return -1 ;
76+ }
77+ printf (" BTorrent_Parse_GetPiece:%d %d\n " , nPieceLen, nPieceCount);
78+
79+ XCHAR tszHash[4196 ];
80+ XCHAR tszCreator[4196 ];
81+ XCHAR tszComment[4196 ];
82+
83+ memset (tszHash, ' \0 ' , sizeof (tszHash));
84+ memset (tszCreator, ' \0 ' , sizeof (tszCreator));
85+ memset (tszComment, ' \0 ' , sizeof (tszComment));
86+
87+ if (!BTorrent_Parse_GetInfo (xhToken, tszHash, tszCreator, tszComment))
88+ {
89+ printf (" BTorrent_Parse_GetPiece:%lX\n " , BTorrent_GetLastError ());
90+ return -1 ;
91+ }
92+ printf (" BTorrent_Parse_GetInfo:%s\n %s\n %s\n " , tszHash, tszCreator, tszComment);
93+
94+ XCHAR tszFile[MAX_PATH];
95+ memset (tszFile, ' \0 ' , MAX_PATH);
96+ BTORRENT_FILEINFO** ppSt_FileList;
97+ if (!BTorrent_Parse_GetFile (xhToken, tszFile, &ppSt_FileList, &nListCount))
98+ {
99+ printf (" BTorrent_Parse_GetFile:%lX\n " , BTorrent_GetLastError ());
100+ return -1 ;
101+ }
102+ for (int i = 0 ; i < nListCount; i++)
103+ {
104+ printf (" BTorrent_Parse_GetFile:%s %s %s %s %lld %lld %lld %d %d\n " , ppSt_FileList[i]->tszFileHash , ppSt_FileList[i]->tszFilePath , ppSt_FileList[i]->tszFileName , ppSt_FileList[i]->tszFileLink , ppSt_FileList[i]->nFileOffset , ppSt_FileList[i]->nFileSize , ppSt_FileList[i]->nFileTime , ppSt_FileList[i]->nFileStart , ppSt_FileList[i]->nFileEnd );
105+ }
106+ BaseLib_OperatorMemory_Free ((XPPPMEM)&ppSt_FileList, nListCount);
107+
108+ BTorrent_Parse_Destory (xhToken);
109+ return 0 ;
110+ }
111+ int BTorrent_Creator (LPCXSTR lpszFile)
112+ {
113+ XNETHANDLE xhToken;
114+ #ifdef _MSC_BUILD
115+ LPCXSTR lpszFileDir = _X (" D:\\ 321" );
116+ #else
117+ LPCXSTR lpszFileDir = _X (" ./321" );
118+ #endif
119+
120+ if (!BTorrent_Creator_Init (&xhToken, lpszFileDir))
121+ {
122+ printf (" BTorrent_Creator_Init:%lX\n " , BTorrent_GetLastError ());
123+ return -1 ;
124+ }
125+
126+ BTorrent_Creator_AddTracker (xhToken, " http://wwww.xyry.org/anno" );
127+ BTorrent_Creator_SetInfo (xhToken, " xengine" , " xengine btorrent V7.11" );
128+
129+ if (!BTorrent_Creator_GetTorrent (xhToken, lpszFile))
130+ {
131+ printf (" BTorrent_Creator_GetTorrent:%lX\n " , BTorrent_GetLastError ());
132+ return -1 ;
133+ }
134+ BTorrent_Creator_Destory (xhToken);
135+ return 0 ;
136+ }
137+ int BTorrent_Download ()
138+ {
139+ XNETHANDLE xhToken;
140+ #ifdef _MSC_BUILD
141+ LPCXSTR lpszBTFile = _X (" D:\\ 123.torrent" );
142+ LPCXSTR lpszFileDir = _X (" D:\\ 321" );
143+ #else
144+ LPCXSTR lpszBTFile = _X (" ./123.torrent" );
145+ LPCXSTR lpszFileDir = _X (" ./321" );
146+ #endif
147+
148+ if (!BTorrent_DLoader_Create (&xhToken, lpszBTFile, lpszFileDir))
149+ {
150+ printf (" BTorrent_Creator_Init:%lX\n " , BTorrent_GetLastError ());
151+ return -1 ;
152+ }
153+ bool bRun = TRUE ;
154+
155+ while (1 )
156+ {
157+ int nListCount = 0 ;
158+ ENUM_BTORRENT_EVENT_TYPE** ppenEventList;
159+ BTorrent_DLoader_Query (xhToken, &ppenEventList, &nListCount);
160+ for (int i = 0 ; i < nListCount; i++)
161+ {
162+ if (ENUM_BTORRENT_EVENT_TYPE_STATUS == *(ppenEventList[i]))
163+ {
164+ BTORRENT_DLOADER st_DLStatus;
165+ BTorrent_DLoader_GetStatus (xhToken, &st_DLStatus);
166+
167+ printf (" %s-%d:%lld,%lld\n " , st_DLStatus.tszFileName , st_DLStatus.nDLStatus , st_DLStatus.nDLoadTotal , st_DLStatus.nDLCount );
168+ }
169+ else if (ENUM_BTORRENT_EVENT_TYPE_COMPLETE == *(ppenEventList[i]))
170+ {
171+ bRun = FALSE ;
172+ break ;
173+ }
174+ printf (" %d\n " , *(ppenEventList[i]));
175+ }
176+ if (!bRun)
177+ {
178+ break ;
179+ }
180+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
181+ BaseLib_OperatorMemory_Free ((XPPPMEM)&ppenEventList, nListCount);
182+ }
183+
184+ BTorrent_DLoader_Close (xhToken);
185+ return 0 ;
186+ }
187+ int main ()
188+ {
189+ #ifdef _MSC_BUILD
190+ LPCXSTR lpszFile = _X (" D:\\ 321.torrent" );
191+ #else
192+ LPCXSTR lpszFile = _X (" ./321.torrent" );
193+ #endif
194+
195+ BTorrent_Download ();
196+ BTorrent_Creator (lpszFile);
197+ BTorrent_Parse (lpszFile);
198+
199+ return 0 ;
200+ }
0 commit comments