Skip to content

Commit 3033d1c

Browse files
committed
added:bt example
1 parent 95cf742 commit 3033d1c

File tree

5 files changed

+375
-0
lines changed

5 files changed

+375
-0
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
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+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>17.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{cd6abe42-badf-4cc9-bfcf-225f922040ca}</ProjectGuid>
25+
<RootNamespace>APPClientBTorrent</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<IncludePath>$(XEngine_Include);$(IncludePath)</IncludePath>
75+
<LibraryPath>$(XEngine_Lib32);$(LibraryPath)</LibraryPath>
76+
</PropertyGroup>
77+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
78+
<ClCompile>
79+
<WarningLevel>Level3</WarningLevel>
80+
<SDLCheck>true</SDLCheck>
81+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
82+
<ConformanceMode>true</ConformanceMode>
83+
</ClCompile>
84+
<Link>
85+
<SubSystem>Console</SubSystem>
86+
<GenerateDebugInformation>true</GenerateDebugInformation>
87+
</Link>
88+
</ItemDefinitionGroup>
89+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
90+
<ClCompile>
91+
<WarningLevel>Level3</WarningLevel>
92+
<FunctionLevelLinking>true</FunctionLevelLinking>
93+
<IntrinsicFunctions>true</IntrinsicFunctions>
94+
<SDLCheck>true</SDLCheck>
95+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
96+
<ConformanceMode>true</ConformanceMode>
97+
</ClCompile>
98+
<Link>
99+
<SubSystem>Console</SubSystem>
100+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
101+
<OptimizeReferences>true</OptimizeReferences>
102+
<GenerateDebugInformation>true</GenerateDebugInformation>
103+
</Link>
104+
</ItemDefinitionGroup>
105+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
106+
<ClCompile>
107+
<WarningLevel>Level3</WarningLevel>
108+
<SDLCheck>true</SDLCheck>
109+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
110+
<ConformanceMode>true</ConformanceMode>
111+
</ClCompile>
112+
<Link>
113+
<SubSystem>Console</SubSystem>
114+
<GenerateDebugInformation>true</GenerateDebugInformation>
115+
</Link>
116+
</ItemDefinitionGroup>
117+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
118+
<ClCompile>
119+
<WarningLevel>Level3</WarningLevel>
120+
<FunctionLevelLinking>true</FunctionLevelLinking>
121+
<IntrinsicFunctions>true</IntrinsicFunctions>
122+
<SDLCheck>true</SDLCheck>
123+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
124+
<ConformanceMode>true</ConformanceMode>
125+
</ClCompile>
126+
<Link>
127+
<SubSystem>Console</SubSystem>
128+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
129+
<OptimizeReferences>true</OptimizeReferences>
130+
<GenerateDebugInformation>true</GenerateDebugInformation>
131+
</Link>
132+
</ItemDefinitionGroup>
133+
<ItemGroup>
134+
<ClCompile Include="APPClient_BTorrent.cpp" />
135+
</ItemGroup>
136+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
137+
<ImportGroup Label="ExtensionTargets">
138+
</ImportGroup>
139+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="源文件">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="头文件">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="资源文件">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="APPClient_BTorrent.cpp">
19+
<Filter>源文件</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>

XEngine_APPClient/XEngine_APPClient.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_UPMaker", "APPCli
1515
EndProject
1616
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_UPFile", "APPClient_UPDate\APPClient_UPFile\APPClient_UPFile.vcxproj", "{D2B84345-CE80-4E29-8A3E-6ACE68EB7ADF}"
1717
EndProject
18+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_BTorrent", "APPClient_BTorrent\APPClient_BTorrent.vcxproj", "{CD6ABE42-BADF-4CC9-BFCF-225F922040CA}"
19+
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2022
Debug|x64 = Debug|x64
@@ -63,6 +65,14 @@ Global
6365
{D2B84345-CE80-4E29-8A3E-6ACE68EB7ADF}.Release|x64.Build.0 = Release|x64
6466
{D2B84345-CE80-4E29-8A3E-6ACE68EB7ADF}.Release|x86.ActiveCfg = Release|Win32
6567
{D2B84345-CE80-4E29-8A3E-6ACE68EB7ADF}.Release|x86.Build.0 = Release|Win32
68+
{CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Debug|x64.ActiveCfg = Debug|x64
69+
{CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Debug|x64.Build.0 = Debug|x64
70+
{CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Debug|x86.ActiveCfg = Debug|Win32
71+
{CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Debug|x86.Build.0 = Debug|Win32
72+
{CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Release|x64.ActiveCfg = Release|x64
73+
{CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Release|x64.Build.0 = Release|x64
74+
{CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Release|x86.ActiveCfg = Release|Win32
75+
{CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Release|x86.Build.0 = Release|Win32
6676
EndGlobalSection
6777
GlobalSection(SolutionProperties) = preSolution
6878
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)