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+ }
0 commit comments