Skip to content

Commit 9cd56f7

Browse files
committed
added:up file make list for client example
1 parent 9d1536e commit 9cd56f7

File tree

4 files changed

+379
-0
lines changed

4 files changed

+379
-0
lines changed
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
#pragma once
2+
#ifdef _MSC_BUILD
3+
#include <Windows.h>
4+
#include <tchar.h>
5+
#pragma comment(lib,"Ws2_32.lib")
6+
#pragma comment(lib,"../../../XEngine_Source/Debug/jsoncpp")
7+
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib")
8+
#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi.lib")
9+
#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIHelp.lib")
10+
#endif
11+
#include <stdio.h>
12+
#include <stdlib.h>
13+
#include <string.h>
14+
#include <signal.h>
15+
#include <string>
16+
#include <list>
17+
#include <thread>
18+
#include <json/json.h>
19+
using namespace std;
20+
#include <XEngine_Include/XEngine_CommHdr.h>
21+
#include <XEngine_Include/XEngine_Types.h>
22+
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
23+
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
24+
#include <XEngine_Include/XEngine_SystemSdk/ProcFile_Define.h>
25+
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Define.h>
26+
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Error.h>
27+
#include <XEngine_Include/XEngine_NetHelp/APIHelp_Define.h>
28+
#include <XEngine_Include/XEngine_NetHelp/APIHelp_Error.h>
29+
30+
typedef struct
31+
{
32+
TCHAR tszFilePath[MAX_PATH];
33+
TCHAR tszFileName[MAX_PATH];
34+
}HELPMODULE_FILELIST, * LPHELPMODULE_FILELIST;
35+
/********************************************************************
36+
函数名称:HelpModule_Api_BuildVer
37+
函数功能:构建应用更新文件
38+
参数.一:lpszPath
39+
In/Out:In
40+
类型:常量字符指针
41+
可空:N
42+
意思:要构建哪个目录中的所有文件列表
43+
参数.二:lpszLocalFile
44+
In/Out:In
45+
类型:常量字符指针
46+
可空:N
47+
意思:构建后保存的列表文件地址
48+
参数.三:lpszRemoteFile
49+
In/Out:In
50+
类型:常量字符指针
51+
可空:N
52+
意思:更新匹配文件保存地址,这个文件需要上传的服务器用来与lpszLocalFile判断是否有更新
53+
参数.四:lpszDlUrl
54+
In/Out:In
55+
类型:常量字符指针
56+
可空:Y
57+
意思:更新地址,用 http://www.xxx.com/UPFile/ 表示,我们会自动填充后面的文件名和路径
58+
参数.五:bSubDir
59+
In/Out:In
60+
类型:逻辑型
61+
可空:Y
62+
意思:是否包含子目录,是否把子目录下的所有文件都构建成更新包
63+
返回值
64+
类型:逻辑型
65+
意思:是否构建成功
66+
备注:次函数可以帮助你快速构建一个可更新的文件列表,方便你快速使用我们的更新SDK
67+
*********************************************************************/
68+
BOOL HelpModule_Api_BuildVer(TCHAR* ptszLocalBuffer, TCHAR* ptszRemoteBuffer, int* pInt_LocalLen, int* pInt_RemoteLen, LPCTSTR lpszPath, LPCTSTR lpszDlUrl, BOOL bSubDir = TRUE)
69+
{
70+
int nListCount;
71+
CHAR** ppszListDir;
72+
list<HELPMODULE_FILELIST> stl_ListFile;
73+
//枚举文件
74+
if (!SystemApi_File_EnumFile(lpszPath, &ppszListDir, &nListCount, NULL, NULL, bSubDir, 1))
75+
{
76+
return FALSE;
77+
}
78+
for (int i = 0; i < nListCount; i++)
79+
{
80+
HELPMODULE_FILELIST st_FileList;
81+
memset(&st_FileList, '\0', sizeof(HELPMODULE_FILELIST));
82+
83+
if (!BaseLib_OperatorString_GetFileAndPath(ppszListDir[i], st_FileList.tszFilePath, st_FileList.tszFileName))
84+
{
85+
return FALSE;
86+
}
87+
stl_ListFile.push_back(st_FileList);
88+
}
89+
BaseLib_OperatorMemory_Free((XPPPMEM)&ppszListDir, nListCount);
90+
91+
Json::Value st_JsonLocalRoot;
92+
Json::Value st_JsonLocalArray;
93+
Json::Value st_JsonLocalObject;
94+
95+
Json::Value st_JsonRemoteRoot;
96+
Json::Value st_JsonRemoteArray;
97+
Json::Value st_JsonRemoteObject;
98+
Json::Value st_JsonRemoteOPtion;
99+
Json::StreamWriterBuilder st_JsonBuilder;
100+
//判断是否是自定义版本
101+
TCHAR tszTimer[64];
102+
XENGINE_LIBTIMER st_Timer;
103+
104+
memset(tszTimer, '\0', sizeof(tszTimer));
105+
memset(&st_Timer, '\0', sizeof(XENGINE_LIBTIMER));
106+
107+
BaseLib_OperatorTime_GetSysTime(&st_Timer);
108+
_stprintf_s(tszTimer, _T("%04d%02d%02d%02d%02d%02d"), st_Timer.wYear, st_Timer.wMonth, st_Timer.wDay, st_Timer.wHour, st_Timer.wMinute, st_Timer.wSecond);
109+
__int64x m_nFileVer = _ttoi64(tszTimer);
110+
111+
st_JsonLocalRoot["MainVersion"] = (Json::UInt64)m_nFileVer;
112+
113+
st_JsonRemoteOPtion["st_JsonRemoteOPtion"] = 0;
114+
st_JsonRemoteRoot["MainVersion"] = (Json::UInt64)m_nFileVer;
115+
st_JsonRemoteRoot["MainDescription"] = _T("File UPData Des!");
116+
st_JsonRemoteRoot["FileVerOPtion"] = st_JsonRemoteOPtion;
117+
//开始构架JSON文件列表
118+
list<HELPMODULE_FILELIST>::const_iterator stl_ListIterator = stl_ListFile.begin();
119+
for (unsigned int i = 1; stl_ListIterator != stl_ListFile.end(); stl_ListIterator++, i++)
120+
{
121+
TCHAR tszFileCode[64];
122+
memset(tszFileCode, '\0', sizeof(tszFileCode));
123+
124+
_stprintf_s(tszFileCode, _T("XYRYUPVERCODE%d"), i);
125+
126+
st_JsonLocalObject["ModuleVersion"] = (Json::UInt64)m_nFileVer;
127+
st_JsonLocalObject["ModuleCode"] = tszFileCode;
128+
st_JsonLocalObject["ModuleName"] = stl_ListIterator->tszFileName;
129+
st_JsonLocalObject["ModulePath"] = stl_ListIterator->tszFilePath;
130+
TCHAR tszDlPath[1024];
131+
memset(tszDlPath, '\0', sizeof(tszDlPath));
132+
//删除指定字符串
133+
int nPathType = 0;
134+
BaseLib_OperatorString_GetPath(stl_ListIterator->tszFilePath, &nPathType);
135+
if (1 == nPathType)
136+
{
137+
TCHAR tszDelPath[MAX_PATH];
138+
TCHAR tszSubPath[MAX_PATH];
139+
140+
memset(tszDelPath, '\0', MAX_PATH);
141+
memset(tszSubPath, '\0', MAX_PATH);
142+
143+
_tcscpy(tszDelPath, lpszPath);
144+
_tcscpy(tszSubPath, stl_ListIterator->tszFilePath);
145+
146+
tszDelPath[_tcslen(tszDelPath) - 2] = '\0';
147+
BaseLib_OperatorString_DelLastForChar(tszDelPath, '\\');
148+
_tcscat(tszDelPath, "\\");
149+
150+
BaseLib_OperatorString_DelSub(tszSubPath, tszDelPath);
151+
BaseLib_OperatorString_FixPath(tszSubPath, 2);
152+
_stprintf_s(tszDlPath, _T("%s%s%s"), lpszDlUrl, tszSubPath, stl_ListIterator->tszFileName);
153+
}
154+
else
155+
{
156+
_stprintf_s(tszDlPath, _T("%s%s%s"), lpszDlUrl, stl_ListIterator->tszFilePath + 2, stl_ListIterator->tszFileName);
157+
}
158+
st_JsonRemoteObject["ModuleRun"] = false;
159+
st_JsonRemoteObject["ModuleVersion"] = (Json::UInt64)m_nFileVer;
160+
st_JsonRemoteObject["ModuleCode"] = tszFileCode;
161+
st_JsonRemoteObject["ModuleName"] = stl_ListIterator->tszFileName;
162+
st_JsonRemoteObject["ModuleDownload"] = tszDlPath;
163+
st_JsonRemoteArray.append(st_JsonRemoteObject);
164+
st_JsonLocalArray.append(st_JsonLocalObject);
165+
}
166+
st_JsonLocalRoot["FileList"] = st_JsonLocalArray;
167+
168+
Json::Value st_JsonRemoteDel;
169+
st_JsonRemoteRoot["UPList"] = st_JsonRemoteArray;
170+
st_JsonRemoteRoot["DelList"] = st_JsonRemoteDel;
171+
st_JsonBuilder["emitUTF8"] = true;
172+
//写到JSON文件
173+
*pInt_LocalLen = Json::writeString(st_JsonBuilder, st_JsonLocalRoot).length();
174+
*pInt_RemoteLen = Json::writeString(st_JsonBuilder, st_JsonRemoteRoot).length();
175+
memcpy(ptszLocalBuffer, Json::writeString(st_JsonBuilder, st_JsonLocalRoot).c_str(), *pInt_LocalLen);
176+
memcpy(ptszRemoteBuffer, Json::writeString(st_JsonBuilder, st_JsonRemoteRoot).c_str(), *pInt_RemoteLen);
177+
178+
return TRUE;
179+
}
180+
181+
int main(int argc, char** argv)
182+
{
183+
#ifdef _MSC_BUILD
184+
WSADATA st_WSAData;
185+
WSAStartup(MAKEWORD(2, 2), &st_WSAData);
186+
#endif
187+
LPCTSTR lpszPath = _T("D:\\libxengine\\*");
188+
LPCTSTR lpszLocalFile = _T("D:\\XEngine_Storage\\XEngine_APPClient\\Debug\\LocalFile.txt");
189+
LPCTSTR lpszPostFile = _T("http://192.168.1.8:5102/api?filename=xengine/upfile.txt&storeagekey=storagekey1");
190+
LPCTSTR lpszDownload = _T("http://192.168.1.8:5101/storagekey1/xengine/");
191+
int nLocalLen = 1024 * 1024 * 10;
192+
int nRemoteLen = 1024 * 1024 * 10;
193+
TCHAR* ptszLocalBuffer = (TCHAR*)malloc(nLocalLen);
194+
TCHAR* ptszRemoteBuffer = (TCHAR*)malloc(nRemoteLen);
195+
196+
memset(ptszLocalBuffer, '\0', nLocalLen);
197+
memset(ptszRemoteBuffer, '\0', nRemoteLen);
198+
199+
if (!HelpModule_Api_BuildVer(ptszLocalBuffer, ptszRemoteBuffer, &nLocalLen, &nRemoteLen, lpszPath, lpszDownload))
200+
{
201+
printf("erron\n");
202+
return 0;
203+
}
204+
SystemApi_File_SaveBuffToFile(lpszLocalFile, ptszLocalBuffer, nLocalLen);
205+
//如果服务器支持,可以直接把更新数据提交到服务器
206+
if (!APIHelp_HttpRequest_Custom(_T("POST"), lpszPostFile, ptszRemoteBuffer, NULL, NULL, &nRemoteLen))
207+
{
208+
printf("erron\n");
209+
}
210+
#ifdef _MSC_BUILD
211+
WSACleanup();
212+
#endif
213+
return 0;
214+
}
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>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{7a3d7491-0a28-423d-a8d6-ff4776bcecb7}</ProjectGuid>
25+
<RootNamespace>APPClientUPMaker</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>MultiByte</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);../../../XEngine_Source/XEngine_ThirdPart/jsoncpp;$(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;_CRT_SECURE_NO_WARNINGS;%(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_UPMaker.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_UPMaker.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>

0 commit comments

Comments
 (0)