123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807 |
- /************************************************************************/
- /*
- 1.导入时,选择可用的指定域名和相片类型的共享目录;
- 2.导出时,从所有共享目录中查找指定域名的订单文件夹;
- 3.查看相片时,从所有共享目录中查找指定域名的订单文件夹;
- 4.选片和选设计时,从所有共享目录中查找指定域名的订单文件夹;
- */
- /************************************************************************/
- BOOL g_bAllBranch = TRUE;
- CWnd g_pMainWnd = NULL;
- CString g_branchip = _T("");
- CString g_branchname = _T("");
- CArray<CStringArray,CStringArray> g_aryOfSharePathInfo;
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // 第一步,登陆时获取NetShareInfo表信息;
- /************************************************************************/
- /*
- Date: 2015-04-11
- Author: Jeff
- 函数:GetSharePathInfo
- 描述:获取共享目录表的所有信息;
- 参数:
- 返回:成功返回TRUE;
- 注意:获取的表记录存储在全局变量g_aryOfSharePathInfo中;
- 调用约定:在登陆软件时调用,且必须连接的服务器是本店的;
- */
- /************************************************************************/
- BOOL CMainFrame::GetSharePathInfo()
- {
- // 1.连接的数据库必须是本局域网的服务器;
- if ( g_bAllBranch || !g_branchname.IsEmpty() || !g_branchip.IsEmpty() )
- {
- // 非当前局域网服务器;
- return FALSE;
- }
- // 2.获取当前连接的分店域名是否与g_domain一致;
- g_sendhead.bsql = 0;
- g_sendhead.code[0] = 29;
- g_sendhead.tabcount = 1;
- g_pMainWnd->ProcessChatMessageRequest2(23);
- if ( !g_bSendOK )
- {
- // 连接服务器失败;
- return FALSE;
- }
- CArray<CStringArray,CStringArray> strArray;
- DataToArray(&strArray);
- CString strCurBranchDomain = _T("");
- if ( strArray.GetSize() )
- {
- strCurBranchDomain = strArray.ElementAt(0).ElementAt(0);
- if ( strCurBranchDomain.Find(_T(".ly.com")) == -1)
- {
- // 当前获取的域名有错;
- return FALSE;
- }
- }
- if ( g_domain.CompareNoCase(strCurBranchDomain) != 0)
- {
- // 当前连接的分店域名与局域网服务器域名不一致;
- return FALSE;
- }
- // 3.获取可用的共享信息;//select * from NetShareInfo where enable = 1;
- CString strFilter = _T("");
- strFilter.Format(_T("enable = 1"));
- int g_nYearposTemp=g_nYearpos;
- g_nYearpos=-1;
- g_bSendOK = 0;
- g_sendhead.bsql = 0;
- g_sendhead.code[0] = 236;
- g_sendhead.tabcount = 1;
- g_pMainWnd->ProcessChatMessageRequest2(strFilter);
- g_nYearpos = g_nYearposTemp;
- if ( !g_bSendOK )
- {
- // 获取共享信息失败;
- return FALSE;
- }
- g_aryOfSharePathInfo.RemoveAll();
- DataToArray(&g_aryOfSharePathInfo);
- return g_aryOfSharePathInfo.GetSize() ? TRUE : FALSE;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // 每次登陆本地服务器时,获取NetShareInfo表;
- void Login3::GetNetShareInfo()
- {
- #if 1
- if ( g_branchname.IsEmpty() ) // 如果是空域名,表示本店;
- {
- if ( g_aryOfSharePathInfo.GetSize() == 0 ) // 如果元素空,重新获取表;
- {
- g_pMainWnd->GetSharePathInfo();
- }
- }
- #else
- // 或者,移除之前的全部,重新获取;
- if ( g_branchname.IsEmpty() )
- {
- g_aryOfSharePathInfo.RemoveAll();
- g_pMainWnd->GetSharePathInfo();
- }
- #endif
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // 第二步,在所有导入前,获取可用的共享目录;
- /************************************************************************/
- /*
- Date: 2015-04-10
- Author: Jeff
- 函数:GetEnableShareDirectory
- 描述:返回指定相片类型可用的共享目录;
- 参数:
- IN: nPhotoType 相片类型;
- IN: lpOrderNum 订单号;
- IN: lpDomain 分店域名;
- OUT: lpEnableShareDirectory 可用的共享目录;
- 返回:成功返回TRUE;
- 注意:用于导入相片,最后返回的共享目录,使用MakeSuerDirectoryPathExists函数创建目录;
- 调用约定:#
- 测试:通过;
- */
- /************************************************************************/
- BOOL GetEnableShareDirectory(IN const int &nPhotoType, IN LPCTSTR lpOrderNum, IN LPCTSTR lpDomain, OUT LPTSTR lpEnableShareDirectory)
- {
- // 需要判断域名有效性;
- if (lpDomain && strcmp(lpDomain, "") != 0)
- {
- TCHAR *szResult = strstr(lpDomain,".ly.com");
- if(szResult == NULL)
- {
- // 传入的域名有误;
- return FALSE;
- }
- }
- // 1.先判断当前局域网原始共享目录可用大小(是否小于20G);
- TCHAR szShare[MAX_PATH] = { 0 };
- GetLoaclShareDirectory(nPhotoType,szShare);// 获取本地指定相片类型的共享目录;
-
- // 如果订单号存在原始共享目录中,判断目录容量是否有5G大小,如果有则存入,否则存入到别的优先级高的共享目录;
- TCHAR szOrderNum[MAX_PATH] = { 0 };
- TCHAR szLocalOrder[MAX_PATH] = { 0 };
- if ( lpDomain == NULL || strcmp(lpDomain,"") == 0)
- {
- // 分店域名为空,则为本店;
- sprintf(szLocalOrder, "%s\\%s", szShare, lpOrderNum);
- }
- else
- {// 分店域名不为空;
-
- if ( strcmp(lpDomain, g_domain) == 0)
- {
- // 本店域名;
- sprintf(szLocalOrder, "%s\\%s", szShare, lpOrderNum);
- }
- else
- {
- sprintf(szLocalOrder, "%s\\%s\\%s", szShare, lpDomain, lpOrderNum);
- }
- }
- double dTotalNum = 0.0;
- double dFreeNum = 0.0;
- if ( !GetDiskSpaceInfo(szShare,dTotalNum,dFreeNum) )
- {
- // 获取硬盘大小失败;
- return FALSE;
- }
- // 订单文件夹存在且原始共享目录可用大小>5G 或者 订单文件夹不存在时,容量必须大于指定值;
- if ((PathFileExists(szLocalOrder) && dFreeNum > MINI_CAPACITY) || dFreeNum > 50)
- {
- // 返回原始共享目录;
- sprintf(lpEnableShareDirectory, "%s", szLocalOrder);
- return TRUE;
- }
- //////////////////////////////////////////////////////////////////////////
- // 原始共享目录不可用,使用其他高优先级共享目录;
- if ( g_aryOfSharePathInfo.GetSize() == 0)
- {
- // 记录为空,则仍旧使用原始共享目录;
- AfxMessageBox(_T("硬盘容量小于30G,请添加新共享硬盘!"));
- sprintf(lpEnableShareDirectory, "%s", szLocalOrder);
- return TRUE;
- }
- typedef struct _STNetSharePathInfo__
- {
- BYTE byPhotType;
- BYTE byminCapacity;
- BYTE bymaxCapacity;
- BYTE byPriority;
- CString strBranchId;
- CString strSharePath;
- }STNetSharePathInfo,*pSTNetSharePathInfo;
- BOOL bGetEnable = FALSE;
- BYTE byCurPriority = 0;
- int nSize = g_aryOfSharePathInfo.GetSize();
- // 如果没找到合适的共享目录,依旧使用原始共享目录或者使用优先级最高的那个;
- for ( int i = 0; i < nSize; i++)
- {
- // 域名是否与本店域名相同;
- if( g_aryOfSharePathInfo.ElementAt(i).ElementAt(1).CompareNoCase(g_domain) != 0 )
- continue;
- STNetSharePathInfo tempNetShaerInfo;
- // 获取高优先级共享目录,依次取低优先级目录,直到获取可用目录为止;
- tempNetShaerInfo.byPhotType = atoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(5));
- tempNetShaerInfo.byminCapacity = atoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(3));
- tempNetShaerInfo.bymaxCapacity = atoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(4));
- tempNetShaerInfo.byPriority = atoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(6));
- tempNetShaerInfo.strBranchId = g_aryOfSharePathInfo.ElementAt(i).ElementAt(1);
- tempNetShaerInfo.strSharePath = g_aryOfSharePathInfo.ElementAt(i).ElementAt(2);
- if ( tempNetShaerInfo.byPhotType == nPhotoType )
- {
- //////////////////////////////////////////////////////////////////////////
- // 判断目录下是否有订单文件夹;
- if (lpDomain && strcmp(lpDomain,"") != 0)
- {
- sprintf(szOrderNum,"%s\\%s\\%s",tempNetShaerInfo.strSharePath, lpDomain ,lpOrderNum);
- }
- else
- {
- sprintf(szOrderNum,"%s\\%s",tempNetShaerInfo.strSharePath, lpOrderNum);
- }
- // 存在且目录容量仍大于mincapacity可用;
- if ( PathFileExists(szOrderNum) )
- {
- if ( !GetDiskSpaceInfo(tempNetShaerInfo.strSharePath,dTotalNum,dFreeNum) )
- {
- // 获取硬盘大小失败;
- continue;
- }
- if ( dFreeNum > tempNetShaerInfo.byminCapacity )
- {
- bGetEnable = TRUE;
- break;
- }
- }
- // 判断共享路径是否可用;
- if ( GetDiskSpaceInfo(tempNetShaerInfo.strSharePath,dTotalNum,dFreeNum) )
- {
- if ( dFreeNum > tempNetShaerInfo.bymaxCapacity )
- {
- // 获取最高优先级的共享目录;
- if ( byCurPriority < tempNetShaerInfo.byPriority)
- {
- byCurPriority = tempNetShaerInfo.byPriority;
- if (lpDomain && strcmp(lpDomain, "") != 0)
- {
- sprintf(szOrderNum, "%s\\%s\\%s", tempNetShaerInfo.strSharePath, lpDomain, lpOrderNum);
- }
- else
- {
- sprintf(szOrderNum, "%s\\%s", tempNetShaerInfo.strSharePath, lpOrderNum);
- }
- bGetEnable = TRUE;
- }
- }
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////
- // 返回结果;
- if(bGetEnable)
- sprintf(lpEnableShareDirectory,"%s",szOrderNum);
- else
- sprintf(lpEnableShareDirectory, "%s", szLocalOrder);
- return bGetEnable;
- }
- /************************************************************************/
- /*
- Date: 2015-04-15
- Author: Jeff
- 函数:GetLoaclShareDirectory
- 描述:获取指定相片类型的本地原始共享目录名;
- 参数:
- IN: nPhotoType 相片类型;
- 返回:成功返回TRUE;
- 注意:#;
- 调用约定:#
- */
- /************************************************************************/
- void GetLoaclShareDirectory(IN int const nPhotoType, OUT LPTSTR lpResultPath)
- {
- if ( g_serverbak.IsEmpty() )
- {
- // 主机名空;
- return;
- }
- switch( nPhotoType )
- {
- case 1:
- sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "客户原片(管理软件)$");
- break;
- case 2:
- sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "修好的片(管理软件)$");
- break;
- case 3:
- sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "精修好的片(管理软件)$");
- break;
- case 4:
- sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "设计好的片(管理软件)$");
- break;
- #ifdef ENTERPRISE_VERSION
- #ifndef CHILD_VERSION
- case 5:
- sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "客户原片备份(管理软件)$");
- break;
- case 6:
- sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "修好的片备份(管理软件)$");
- break;
- case 7:
- sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "精修好的片备份(管理软件)$");
- break;
- case 8:
- sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "设计好的片备份(管理软件)$");
- break;
- #else
- case 5:
- sprintf(lpResultPath, "\\\\%s\\%s", g_serverbak, "客户原片备份(儿童管理软件)$");
- break;
- case 6:
- sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "修好的片备份(儿童管理软件)$");
- break;
- case 7:
- sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "精修好的片备份(儿童管理软件)$");
- break;
- case 8:
- sprintf(lpResultPath,"\\\\%s\\%s", g_serverbak, "设计好的片备份(儿童管理软件)$");
- break;
- #endif
- #endif
- default:
- break;
- }
- }
- /************************************************************************/
- /*
- Date: 2015-04-08
- Author: Jeff
- 函数:GetDiskSpaceInfo
- 描述:获取指定目录或盘符的容量信息;
- 参数:
- IN: lpRootPathName 根目录名称;
- INOUT: dTotalNum 总容量;
- INOUT: dFreeNum 可用容量;
- 返回:
- 注意:
- GetDiskFreeSpace函数不能满足当前超过2T的硬盘容量,因为里面的数据类型是UINT,最大支持32位(4G);
- GetDiskFreeSpaceEx支持64位(16384P=1024*16384T)
- 只能获取本机硬盘信息,且路径必须包含":"冒号;
- 调用约定:
- */
- /************************************************************************/
- BOOL GetDiskSpaceInfo(IN LPCTSTR lpRootPathName,IN OUT double &dTotalNum, IN OUT double &dFreeNum)
- {
- // 校验参数有效性;
- if(lpRootPathName == NULL || _tcscmp(lpRootPathName,_T("")) == 0)
- {
- //_tprintf_s(_T("根目录为空!"));
- return FALSE;
- }
- // 如果长度==1;
- int nlen = _tcslen(lpRootPathName);
- if((1 == nlen) || ( 2 == nlen && lpRootPathName[nlen-1] != _T(':')))
- {
- //_tprintf_s(_T("根目录无效!\n"));
- return FALSE;
- }
- if ( !PathFileExists(lpRootPathName))
- {
- //_tprintf_s(_T("根目录不存在!\n"));
- return FALSE;
- }
- BOOL fResult = FALSE;
- DWORD dwSectPerClust; // 每簇的扇区数;
- DWORD dwBytesPerSect; // 每个扇区的字节数;
- DWORD dwFreeClusters; // 可用簇数;
- DWORD dwTotalClusters; // 总簇数;
- typedef BOOL (WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER,PULARGE_INTEGER, PULARGE_INTEGER);
- P_GDFSE pGetDiskFreeSpaceEx = NULL;
- /*unsigned*/ __int64 i64FreeBytesToCaller;
- /*unsigned*/ __int64 i64TotalBytes;
- /*unsigned*/ __int64 i64FreeBytes;
- // 调用GetDiskFreeSpaceEx失败则调用GetDiskSpace;
- #ifdef UNICODE
- pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle(_T("kernel32.dll")),"GetDiskFreeSpaceExW");
- #else
- pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle("kernel32.dll"),"GetDiskFreeSpaceExA");
- #endif
- if ( pGetDiskFreeSpaceEx )
- {
- fResult = pGetDiskFreeSpaceEx(lpRootPathName,
- (PULARGE_INTEGER)&i64FreeBytesToCaller,
- (PULARGE_INTEGER)&i64TotalBytes,
- (PULARGE_INTEGER)&i64FreeBytes);
- if ( fResult )
- {
- // 将单位由byte转为G byte;
- dTotalNum = (double)i64TotalBytes/1024/1024/1024;
- dFreeNum = (double)i64FreeBytes/1024/1024/1024;
- }
- }
- else
- {
- fResult = GetDiskFreeSpace(lpRootPathName,
- &dwSectPerClust,
- &dwBytesPerSect,
- &dwFreeClusters,
- &dwTotalClusters);
- if ( fResult )
- {
- // 成功获得容量信息;
- i64TotalBytes = (__int64)dwTotalClusters * dwSectPerClust * dwBytesPerSect;
- i64FreeBytes = (__int64)dwFreeClusters * dwSectPerClust * dwBytesPerSect;
- // 将单位由byte转为G byte;
- dTotalNum = (double)i64TotalBytes/1024/1024/1024;
- dFreeNum = (double)i64FreeBytes/1024/1024/1024;
- }
- }
- return fResult;
- }
- /************************************************************************/
- /*
- 函数:LoadSpecifiedDirectory
- 描述:加载指定目录的相片;
- 参数:
- IN:lpSpecifiedDirectory指定的目录;
- 返回:
- 注意:
- 调用约定:
- */
- /************************************************************************/
- int LoadSpecifiedDirectoryImages(IN LPCTSTR lpSpecifiedDirectory, OUT CStringArray &AryOfImagePath)
- {
- // 1.判定目录有效性;
- if ( lpSpecifiedDirectory == NULL || strcmp(lpSpecifiedDirectory,_T("")) == 0)
- {
- // 目录无效;
- return -1;
- }
- using namespace helper_coffs;
- ffsco o;
- o.dirs(1);
- o.find(lpSpecifiedDirectory, LPCSTR("*.*"));
- ffsco::typeT cfs;
- ffsco::typeT::iterator it;
- cfs = o.co_file();
- CString strName;
- for (it = cfs.begin(); cfs.end() != it; it++)
- {
- // 去除目录级文件;
- // 去除ok文件;
- // 去除modifytime文件;
- // 去除s+m缩略图;
- strName = it->c_str();
- strName.MakeLower();
- if ( strName.Find('.') == -1)
- continue;
- else
- {
- CString str = strName.Mid( strName.ReverseFind('\\') + 1 );
- if ( str.Find('.') == -1)
- continue;
- }
- // 如果在相片前或后加修饰,都会有bug,最佳做法是缩略图放在另一子文件夹中;
- // 产生的bug:使用原名导入相片时,相片名可能第一个字母就是s或m;
- if ( strName.GetAt( strName.ReverseFind('\\') + 1 ) == 's' )continue;
- if ( strName.GetAt( strName.ReverseFind('\\') + 1 ) == 'm' )continue;
- if ( strName.Find(_T(".jpg")) == -1 )continue;
- AryOfImagePath.Add(strName);
- }
- }
- /************************************************************************/
- /*
- 函数:LoadSharedDirectoryPhotos
- 描述:加载指定相片类型、订单号、分店域名的相片路径集合;
- 参数:
- IN:nPhotoType 相片类型;
- IN:lpOrderNum 订单号;
- IN:lpDomain 分店域名(若域名空代表本店);
- OUT:AryOfImagesPath 返回的相片路径集合;
- 返回:
- 注意:
- 调用约定:
- */
- /************************************************************************/
- BOOL LoadSharedDirectoryPhotos(IN CONST INT &nPhotoType, IN LPCTSTR lpOrderNum, IN LPCTSTR lpDomain, OUT CStringArray &AryOfImagePath)
- {
- // 若域名非空,判断域名有效性;
- if ( lpDomain && strcmp(lpDomain, _T("")) != 0 )
- {
- TCHAR * szResult = strstr(lpDomain,_T(".ly.com"));
- if ( szResult == NULL )
- {
- // 传入域名错误;
- return FALSE;
- }
- }
- // 2.查找早期的固定的原始共享目录;
- TCHAR szShareDirectory[MAX_PATH] = {0};
- GetLoaclShareDirectory(nPhotoType, szShareDirectory);
- TCHAR szOrderPath[MAX_PATH] = {0};
- if ( lpDomain == NULL || lpDomain[0] == '\0')
- {
- // 分店域名空,代表本店;
- sprintf(szOrderPath, _T("%s\\%s"), lpOrderNum);
- }
- else
- {
- // 若域名非空,则与本店比较,防止域名仍为本店;
- if ( strcmp(lpDomain, g_domain) == 0 )
- {
- // 本店域名;
- sprintf(szOrderPath, _T("%s\\%s"), szShareDirectory, lpOrderNum);
- }
- else
- {
- sprintf(szOrderPath, _T("%s\\%s\\%s"), szShareDirectory, lpDomain, lpOrderNum);
- }
- }
- // #所有能被找到的共享目录;
- CStringArray aryOfOrderDirectory;
- if ( PathFileExists(szOrderPath) )
- {
- aryOfOrderDirectory.Add(szOrderPath);
- // 将该订单目录添加到数组中;
- LoadSpecifiedDirectoryImages(szOrderPath, AryOfImagePath);
- }
- // 3.查找NetShareInfo中的共享目录并加载;
- int nSize = aryOfOrderDirectory.GetSize();
- for ( int i = 0; i < nSize; i++ )
- {
- if ( nPhotoType != _ttoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(5)) )
- {
- continue;
- }
- // 遍历所有共享路径;
- sprintf(szShareDirectory, _T("%s"), g_aryOfSharePathInfo.ElementAt(i).ElementAt(2));
- if (lpDomain && strcmp(lpDomain,"") != 0)
- {
- sprintf(szOrderPath, _T("%s\\%s\\%s"), szShare,lpDomain, lpOrderNum);
- }
- else
- {
- sprintf(szOrderPath, _T("%s\\%s"), szShare, lpOrderNum);
- }
- if ( PathFileExists(szOrderPath) )
- {
- aryOfOrderDirectory.Add(szOrderPath);
- LoadSpecifiedDirectoryImages(szOrderPath, AryOfImagePath);
- }
- }
- return TRUE;
- }
- /************************************************************************/
- /*
- 函数:LoadSpecifiedDirectory
- 描述:加载指定目录的相片;
- 参数:
- IN:lpSpecifiedDirectory 指定的目录;
- IN:AryOfImage 要查找的相片名;
- 返回:
- 注意:
- 调用约定:
- */
- /************************************************************************/
- int LoadSpecifiedDirectoryImages(IN LPCTSTR lpSpecifiedDirectory, IN CStringArray &AryOfImage, OUT CStringArray &AryOfImagePath)
- {
- // 1.判定目录有效性;
- if ( lpSpecifiedDirectory == NULL || strcmp(lpSpecifiedDirectory,_T("")) == 0)
- {
- // 目录无效;
- return -1;
- }
- using namespace helper_coffs;
- ffsco o;
- o.dirs(1);
- o.find(lpSpecifiedDirectory, LPCSTR("*.*"));
- ffsco::typeT cfs;
- ffsco::typeT::iterator it;
- cfs = o.co_file();
- CString strName;
- for (it = cfs.begin(); cfs.end() != it; it++)
- {
- // 去除目录级文件;
- // 去除ok文件;
- // 去除modifytime文件;
- // 去除s+m缩略图;
- strName = it->c_str();
- strName.MakeLower();
- if ( strName.Find('.') == -1)
- {
- it = cfs.erase(it);
- continue;
- }
- else
- {
- CString str = strName.Mid( strName.ReverseFind('\\') + 1 );
- if ( str.Find('.') == -1)
- {
- it = cfs.erase(it);
- continue;
- }
- }
- // 如果在相片前或后加修饰,都会有bug,最佳做法是缩略图放在另一子文件夹中;\
- // 产生的bug:使用原名导入相片时,相片名可能第一个字母就是s或m;
- if ( strName.GetAt( strName.ReverseFind('\\') + 1 ) == 's' ){
- it = cfs.erase(it);
- continue;
- }
- if ( strName.GetAt( strName.ReverseFind('\\') + 1 ) == 'm' ){
- it = cfs.erase(it);
- continue;
- }
- if ( strName.Find(_T(".jpg")) == -1 ){
- it = cfs.erase(it);
- continue;
- }
- }
- // AryOfImage 从尾部开始查找,查找成功后并删除,最终查找完全部共享目录都没找到的,就是相片不存在;
- for ( it = cfs.begin(); it != cfs.end(); it++ )
- {
- strName = it->c_str();
- for ( int i = AryOfImage.GetSize() - 1; i > -1; i--)
- {
- if ( strName.CompareNoCase(AryOfImage.ElementAt(i)) == 0 )
- {
-
- }
- }
- }
- }
- /************************************************************************/
- /*
- 函数:LoadSpecifiedImagesDirectory
- 描述:加载指定相片类型、订单、域名的相片名的共享路径;
- 参数:
- IN:
- IN:
- IN:
- IN:
- OUT:
- 返回:
- 注意:
- 示例:
- */
- /************************************************************************/
- BOOL LoadSpecifiedImagesDirectory(IN CONST INT &nPhotoType, IN LPCTSTR lpOrderNum, IN LPCTSTR lpDomain, IN CStringArray &AryOfImage, OUT CStringArray &AryOfImagePath)
- {
- // 若域名非空,判断域名有效性;
- if ( lpDomain && strcmp(lpDomain,_T("")) != 0 )
- {
- TCHAR *szResult = strstr(lpDomain,_T(".ly.com"));
- return FALSE;
- }
- // 2.查找早期的固定的原始共享目录;
- TCHAR szShareDirectory[MAX_PATH] = {0};
- GetLoaclShareDirectory(nPhotoType, szShareDirectory);
- TCHAR szOrderPath[MAX_PATH] = {0};
- if ( lpDomain == NULL || lpDomain[0] == '\0')
- {
- // 分店域名空,代表本店;
- sprintf(szOrderPath, _T("%s\\%s"), lpOrderNum);
- }
- else
- {
- // 若域名非空,则与本店比较,防止域名仍为本店;
- if ( strcmp(lpDomain, g_domain) == 0 )
- {
- // 本店域名;
- sprintf(szOrderPath, _T("%s\\%s"), szShareDirectory, lpOrderNum);
- }
- else
- {
- sprintf(szOrderPath, _T("%s\\%s\\%s"), szShareDirectory, lpDomain, lpOrderNum);
- }
- }
- int nSize = 0;
- CString strImage = _T("");
- AryOfImagePath.RemoveAll(); // 清除数组;
- // #所有能被找到的共享目录;
- if ( PathFileExists(szOrderPath) )
- {
- nSize = AryOfImage.GetSize();
- for ( int i = 0; i < nSize; i++ )
- {
- strImage.Format(_T("%s\\%s.jpg"), lpOrderNum, AryOfImage.ElementAt(i));
- // 如果指定相片名的相片存在,记录路径;
- if ( PathFileExists(strImage) )
- {
- AryOfImagePath.Add(strImage);
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////
- // 查找其他共享目录是否存在订单文件夹;
- nSize = g_aryOfSharePathInfo.GetSize();
- for ( int i = 0; i < nSize; i++)
- {
- if ( nPhotoType != atoi(g_aryOfSharePathInfo.ElementAt(i).ElementAt(5)) )
- {
- continue;
- }
- // 逐一加载其他共享目录;
- sprintf(szShareDirectory, _T("%s"), g_aryOfSharePathInfo.ElementAt(i).ElementAt(2));
- if (lpDomain && strcmp(lpDomain,"") != 0)
- {
- sprintf(szOrderPath, _T("%s\\%s\\%s"), szShareDirectory, lpDomain, lpOrderNum);
- }
- else
- {
- sprintf(szOrderPath, _T("%s\\%s"), szShareDirectory, lpOrderNum);
- }
- if ( !PathFileExists(szOrderPath))
- {
- continue;
- }
- for ( int n = 0; n < AryOfImage.GetSize(); n++)
- {
- strImage.Format(_T("%s\\%s.jpg"), szOrderPath, AryOfImage.ElementAt(n));
- if ( PathFileExists(strImage) )
- {
- AryOfImagePath.Add(strImage);
- }
- }
- }
- return TRUE;
- }
|