@@ -141,6 +141,148 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>
141141 *pInt_ListCount = pStl_ListParse->size ();
142142 return TRUE ;
143143}
144+ /* *******************************************************************
145+ 函数名称:APIHelp_Distributed_DLStorage
146+ 函数功能:通过URLKEY得到一个对应下载地址
147+ 参数.一:lpszMsgBuffer
148+ In/Out:In
149+ 类型:常量字符指针
150+ 可空:N
151+ 意思:输入要解析的URL
152+ 参数.二:pStl_ListBucket
153+ In/Out:In
154+ 类型:容器指针
155+ 可空:N
156+ 意思:输入要解析的列表
157+ 参数.三:pSt_StorageBucket
158+ In/Out:Out
159+ 类型:数据结构指针
160+ 可空:N
161+ 意思:输出获取到的可用存储
162+ 返回值
163+ 类型:逻辑型
164+ 意思:是否成功
165+ 备注:
166+ *********************************************************************/
167+ BOOL CAPIHelp_Distributed::APIHelp_Distributed_DLStorage (LPCTSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket)
168+ {
169+ APIHelp_IsErrorOccur = FALSE ;
170+
171+ if ((NULL == lpszMsgBuffer) || (NULL == pSt_StorageBucket))
172+ {
173+ APIHelp_IsErrorOccur = TRUE ;
174+ APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT;
175+ return FALSE ;
176+ }
177+ BOOL bFound = FALSE ;
178+ TCHAR tszKeyStr[128 ];
179+ memset (tszKeyStr, ' \0 ' , sizeof (tszKeyStr));
180+ // 获得key
181+ int i = 1 ;
182+ int nLen = _tcslen (lpszMsgBuffer);
183+ for (; i < nLen; i++)
184+ {
185+ if (' /' == lpszMsgBuffer[i])
186+ {
187+ bFound = TRUE ;
188+ memcpy (tszKeyStr, lpszMsgBuffer + 1 , i - 1 );
189+ break ;
190+ }
191+ }
192+ if (!bFound)
193+ {
194+ APIHelp_IsErrorOccur = TRUE ;
195+ APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
196+ return FALSE ;
197+ }
198+ bFound = FALSE ;
199+ // 获得对应存储
200+ for (auto stl_ListIterator = pStl_ListBucket->begin (); stl_ListIterator != pStl_ListBucket->end (); stl_ListIterator++)
201+ {
202+ if (0 == _tcsncmp (tszKeyStr, stl_ListIterator->tszBuckKey , _tcslen (tszKeyStr)))
203+ {
204+ bFound = TRUE ;
205+ *pSt_StorageBucket = *stl_ListIterator;
206+ break ;
207+ }
208+ }
209+ if (!bFound)
210+ {
211+ APIHelp_IsErrorOccur = TRUE ;
212+ APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
213+ return FALSE ;
214+ }
215+ _tcscpy (pSt_StorageBucket->tszFileName , lpszMsgBuffer + i);
216+ return TRUE ;
217+ }
218+ /* *******************************************************************
219+ 函数名称:APIHelp_Distributed_UPStorage
220+ 函数功能:通过分布式存储列表获得一个存储地址
221+ 参数.一:pStl_ListBucket
222+ In/Out:In
223+ 类型:容器指针
224+ 可空:N
225+ 意思:输入要解析的列表
226+ 参数.二:pSt_StorageBucket
227+ In/Out:Out
228+ 类型:数据结构指针
229+ 可空:N
230+ 意思:输出获取到的可用存储
231+ 返回值
232+ 类型:逻辑型
233+ 意思:是否成功
234+ 备注:
235+ *********************************************************************/
236+ BOOL CAPIHelp_Distributed::APIHelp_Distributed_UPStorage (list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket)
237+ {
238+ APIHelp_IsErrorOccur = FALSE ;
239+
240+ if ((NULL == pStl_ListBucket) || (NULL == pSt_StorageBucket))
241+ {
242+ APIHelp_IsErrorOccur = TRUE ;
243+ APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT;
244+ return FALSE ;
245+ }
246+ BOOL bFound = FALSE ;
247+ int nLastLevel = 9999 ;
248+ for (auto stl_ListIterator = pStl_ListBucket->begin (); stl_ListIterator != pStl_ListBucket->end (); stl_ListIterator++)
249+ {
250+ // 只处理启用的
251+ if (stl_ListIterator->bEnable )
252+ {
253+ // 处理优先级
254+ if (stl_ListIterator->nLevel < nLastLevel)
255+ {
256+ int nListCount = 0 ;
257+ __int64u nDirCount = 0 ; // 当前目录大小
258+ CHAR** ppListFile;
259+ SystemApi_File_EnumFile (stl_ListIterator->tszFilePath , &ppListFile, &nListCount, NULL , NULL , TRUE , 1 );
260+ for (int j = 0 ; j < nListCount; j++)
261+ {
262+ struct __stat64 st_FStat;
263+ _stat64 (ppListFile[j], &st_FStat);
264+ nDirCount += st_FStat.st_size ;
265+ }
266+ BaseLib_OperatorMemory_Free ((XPPPMEM)&ppListFile, nListCount);
267+ // 如果当前目录大小大于设定的大小.那么忽略
268+ if (nDirCount >= APIHelp_Distributed_GetSize (stl_ListIterator->tszBuckSize ))
269+ {
270+ continue ;
271+ }
272+ bFound = TRUE ;
273+ nLastLevel = stl_ListIterator->nLevel ;
274+ *pSt_StorageBucket = *stl_ListIterator;
275+ }
276+ }
277+ }
278+ if (!bFound)
279+ {
280+ APIHelp_IsErrorOccur = TRUE ;
281+ APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_NOTFOUND;
282+ return FALSE ;
283+ }
284+ return TRUE ;
285+ }
144286// ////////////////////////////////////////////////////////////////////////
145287// 保护函数
146288// ////////////////////////////////////////////////////////////////////////
@@ -199,4 +341,47 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_FileListParse(LPCTSTR lpszMsgBuff
199341 break ;
200342 }
201343 return TRUE ;
344+ }
345+ /* *******************************************************************
346+ 函数名称:APIHelp_Distributed_GetSize
347+ 函数功能:获取存储设置大小
348+ 参数.一:lpszMsgBuffer
349+ In/Out:In
350+ 类型:常量字符指针
351+ 可空:N
352+ 意思:输入要获取的缓冲区
353+ 返回值
354+ 类型:整数型
355+ 意思:获取到的大小字节
356+ 备注:
357+ *********************************************************************/
358+ __int64u CAPIHelp_Distributed::APIHelp_Distributed_GetSize (LPCTSTR lpszMsgBuffer)
359+ {
360+ APIHelp_IsErrorOccur = FALSE ;
361+
362+ TCHAR tszSizeStr[64 ];
363+ TCHAR tszUnitStr[4 ];
364+
365+ memset (tszSizeStr, ' \0 ' , sizeof (tszSizeStr));
366+ memset (tszUnitStr, ' \0 ' , sizeof (tszUnitStr));
367+ // 分别得到数字和单位
368+ memcpy (tszSizeStr, lpszMsgBuffer, _tcslen (lpszMsgBuffer) - 2 );
369+ BaseLib_OperatorString_GetLastString (lpszMsgBuffer, 2 , tszUnitStr);
370+
371+ __int64u nllSize = _ttoi64 (tszSizeStr);
372+ // 得到单位大小
373+ if (0 == _tcsncmp (tszUnitStr, _T (" KB" ), 2 ))
374+ {
375+ nllSize = nllSize * 1024 ;
376+ }
377+ else if (0 == _tcsncmp (tszUnitStr, _T (" MB" ), 2 ))
378+ {
379+ nllSize = nllSize * 1024 * 1024 ;
380+ }
381+ else if (0 == _tcsncmp (tszUnitStr, _T (" GB" ), 2 ))
382+ {
383+ nllSize = nllSize * 1024 * 1024 * 1024 ;
384+ }
385+
386+ return nllSize;
202387}
0 commit comments