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