12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108 |
- // CPhotoFTPSendDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "CPhotoFTPSend.h"
- #include "CPhotoFTPSendDlg.h"
- //#include "FTPSend.h"
- #include "FTPSend2.h"
- #include <process.h>
- #include "MyLock.h"
- #include "Shlwapi.h"
- #include "./helper/ffsco.h"
- #include "SetDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- int g_port=21;
- int g_nFail=0;
- CStringArray g_connedip; // 与g_pSend成对;
- // g_servrip与g_failcount是成对出现的;同一索引元素位置一一对应;
- CStringArray g_serverip;
- CArray<int,int>g_failcount;
- CCPhotoFTPSendDlg *g_pMainWnd=NULL;
- CString g_mainpath;
- extern CFont g_listctrlfont;
- //#define IPC_CUSTOM_MSG3 _T("{D4F876E2-w78F-22D5-q98A-Y0B0D07B8AAA}")
- #define IPC_CUSTOM_MSG3 _T("{E4F876E2-Q78F-22D5-C98A-Y0B0D07B8AAA}")
- UINT g_wmClose2 = RegisterWindowMessage(IPC_CUSTOM_MSG3);
- /////////////////////////////////////////////////////////////////////////////
- // CCPhotoFTPSendDlg
- #pragma comment(lib, "Shlwapi.lib")
- #define WM_ICON_NOTIFY WM_USER+12
- BOOL g_check1=1;
- int g_num=5;
- void WriteLogin(CString str)
- {
- MyLock lock("PhotoFTPSendLogfile");
- try
- {
- CStdioFile fp;
- CString path=g_mainpath+"\\CPhotoFTPSend.log";
- if(::PathFileExists (path))
- {
- fp.Open (path, CFile::modeWrite);
- int length=fp.GetLength ();
- if(length>1024*1024)
- {
- fp.Close ();
- ::DeleteFile (path);
- return;
- }
- fp.SeekToEnd ();
- }
- else
- fp.Open (path, CFile::modeCreate|CFile::modeWrite);
- fp.WriteString (CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S")+" "+str+"\r\n" );
- fp.Close ();
- }
- catch(...)
- {
- }
- }
- int FindArray(CStringArray *pArray, CString Str)
- {
- for(int i=0; i<pArray->GetSize (); i++)
- {
- if(pArray->ElementAt (i)==Str)
- return i;
- }
- return -1;
- }
- void LoadBranchInfo(CArray<CStringArray, CStringArray>*pList1array)
- {
- MyLock lock("savebranchinfo");
- CFile fp;
- CString path=g_mainpath+"\\branchinfo.dat";
- if(::PathFileExists (path)==0)
- {
- return;
- }
- fp.Open (path, CFile::modeRead);
- DWORD leng=fp.GetLength ();
- if(leng<sizeof(DWORD)*2)
- {
- fp.Close ();return;
- }
- DWORD flag;
- fp.Seek(-(int)sizeof(DWORD),CFile::end);
- fp.Read (&flag, sizeof(DWORD));
- //if(flag!=889900)
- if(flag!=889900)
- {
- fp.Close ();return;
- }
- fp.SeekToBegin ();
- DWORD arraysize;
- fp.Read (&arraysize, sizeof(DWORD));
- BYTE *pData=new BYTE[leng-sizeof(DWORD)];
- fp.Read (pData,leng-sizeof(DWORD));
- fp.Close ();
- CMemFile memfile;
- memfile.Attach (pData,leng-sizeof(DWORD));
- CArchive ar(&memfile, CArchive::load);
- pList1array->RemoveAll ();
- pList1array->SetSize(arraysize, 1);
- for(int ii=0; ii<pList1array->GetSize (); ii++)
- {
- pList1array->ElementAt (ii).Serialize (ar);
- }
- ar.Close();
- memfile.Detach ();
- delete []pData;
- }
- void MySleep(int s)
- {
- int step=2000;
- int count=s/step;
- for(int i=0; i<count; i++)
- {
- if(g_pMainWnd->m_bTerminate)break;
- if(g_pMainWnd->m_bTerminate2)break;
- ::Sleep (step);
- }
- }
- void LoadTaskFromFile(CString path, CStringArray *array)
- {
- MyLock lock("uploadtaskaccess");
- CFile fp;
- if(fp.Open (path, CFile::modeRead))
- {
- DWORD length=fp.GetLength ();
- if(!length)return;
- CArchive ar(&fp, CArchive::load);
- array->Serialize (ar);
- fp.Close ();
- }
- else
- WriteLogin("读取任务"+path+"失败!");
- }
- void SaveUploadFileStaus(CString path, CStringArray *array)
- {
- MyLock lock("uploadtaskaccess");
- CFile fp;
- if(fp.Open (path, CFile::modeCreate|CFile::modeWrite))
- {
- CArchive ar(&fp, CArchive::store);
- array->Serialize (ar);
- ar.Close();
- fp.Close ();
- }
- else
- WriteLogin("保存已发"+path+"失败!");
- }
- /************************************************************************/
- /*
- /* 函数:GetIDFromInfo
- /* 描述:dat上传任务文件返回的CString对象中获取信息;
- /* 参数:
- /* info dat文件序列化后返回的CString对象;
- /* taskpath dat文件路径;
- /* id dat文件对应的订单号;
- /* type dat文件要上传的相片类型;
- /* 返回:
- */
- /************************************************************************/
- void GetIDFromInfo(CString info , CString taskpath , CString &id, CString &type )
- {
- CString g_path1;
- CString g_path2;
- CString g_path3;
- CString g_path4;
- g_path1="\\客户原片(管理软件)$";
- g_path2="\\修好的片(管理软件)$";
- g_path3="\\设计好的片(管理软件)$";
- g_path4="\\精修好的片(管理软件)$";
- if(taskpath.Find(g_path1)!=-1)type= "原片";
- if(taskpath.Find(g_path2)!=-1)type= "初修片";
- if(taskpath.Find(g_path3)!=-1)type= "设计片";
- if(taskpath.Find(g_path4)!=-1)type= "精修片";
- int pos=info.Find (";");
- if(pos!=-1)id=info.Left (pos);
- }
- CString g_taskpath[MAX_THREAD]={""};
- BOOL g_bActive[MAX_THREAD]={1};
- CFTPSend2 *g_pSend[MAX_THREAD]={NULL};
- unsigned __stdcall ProcessTask(LPVOID lpParam)
- {
- int pos=int(lpParam);
- CString taskpath=g_taskpath[pos];
- if(taskpath.IsEmpty ())
- {
- goto ll;
- }
- // 任务文件存在,设置界面为等待中....
- if(::PathFileExists (taskpath))
- {
- CString path=taskpath;
- g_pMainWnd->ModifyStaus(path, "等待中...");
- CStringArray m_uploadtaskarray;
- LoadTaskFromFile(path, &m_uploadtaskarray);
- if(m_uploadtaskarray.GetSize()<10)
- {
- WriteLogin("读取任务"+path+"失败!!");
- goto ll;
- }
- CString dir=path.Left (path.ReverseFind ('\\')+1);
- CString clientid,filepath,filename,status,phototype;
- CString dirinfile=m_uploadtaskarray.ElementAt (4); // 4 = 相片所在根目录;
- if(dirinfile!="")dir=dirinfile;
- GetIDFromInfo(m_uploadtaskarray.ElementAt (0), dir, clientid, phototype); // 0 = 订单号;顾客;
- CString domain=m_uploadtaskarray.ElementAt (1); // 目录域名;
- CString savedomain=m_uploadtaskarray.ElementAt (2); // 源域名;
- WriteTextLog("%s,%s,%s,%s,%s,%s,%s,%s",
- m_uploadtaskarray.ElementAt(0),
- m_uploadtaskarray.ElementAt(1),
- m_uploadtaskarray.ElementAt(2),
- m_uploadtaskarray.ElementAt(3),
- m_uploadtaskarray.ElementAt(4),
- m_uploadtaskarray.ElementAt(5),
- m_uploadtaskarray.ElementAt(6),
- m_uploadtaskarray.ElementAt(7));
- if(savedomain==domain)savedomain="";
- CString ziptype=m_uploadtaskarray.ElementAt (3); // 压缩像素;
- int typepos=ziptype.Find ("x");
- if(typepos==-1)
- ziptype="";
- else
- ziptype.Left (typepos);
- CString ip,hskip;
- // 目标域名不为空时,传域名;
- if(domain!="")
- ip=g_pMainWnd->GetBranchIP(domain,hskip);
- else // 目标域名空时,传任务路径;
- ip=g_pMainWnd->GetBranchIP(dir,hskip);
- // 记录pos索引所在任务的连接ip;
- g_connedip.SetAt (pos, ip);
- if(::FindArray (&g_serverip, ip)==-1)
- {
- g_serverip.Add (ip);
- g_failcount.Add (0);
- }
- if(clientid.IsEmpty () || phototype.IsEmpty ())
- goto ll;
- // 获取ftp的登陆用户和密码;
- CString user,pass;
- g_pMainWnd->GetUserPswFromPhotoType(phototype, user, pass);
- CFTPSend2 *pftp=NULL;
- g_pSend[pos]=pftp;
- // 从第10个开始,j+=2的原因是:j=路径,j+1=上传状态;
- for(int j=10; j<m_uploadtaskarray.GetSize(); j+=2)
- {
- if(g_pMainWnd->m_bTerminate)
- break;
- if(g_pMainWnd->m_bTerminate1[pos])
- break;
- if(g_pMainWnd->IsStatusPause(path))
- break;
- g_pMainWnd->ModifyStaus(path, "上传中");
- // 获取上传文件路径;
- filename=m_uploadtaskarray.ElementAt(j);
- filepath=dir+filename;
- // 获取上传文件上传状态;
- status=m_uploadtaskarray.ElementAt(j+1);
- if(status=="OK")
- continue;
- // 如果上传文件为ok2.dat,表示上传结束;
- if(::PathFileExists (filepath) || "ok2.dat"==filename)
- {
- if(pftp==NULL)
- {
- g_pMainWnd->ModifyStaus(path, "开始连接");
- pftp=new CFTPSend2;
- g_pSend[pos]=pftp;
- pftp->m_path=path;
- pftp->m_pos=pos;
- pftp->m_bStop =&(g_pMainWnd->m_bTerminate);
- pftp->m_ziptype=ziptype;
- if(hskip=="")
- {
- #if TESTLOCAL
- ip = TEST_SERVER;
- // user="aaa";
- // pass="aaa";
- #endif
- if(!pftp->LogOnToServer(ip,g_pMainWnd->m_port, user, pass))
- {
- int pos=::FindArray (&g_serverip, ip);
- if(pos!=-1)
- {
- int count=g_failcount.ElementAt (pos);
- g_failcount.SetAt (pos, count+1);
- }
- g_pMainWnd->ModifyStaus3(path, -1, ip);
- delete pftp;pftp=NULL;g_pSend[pos]=pftp;
- ::Sleep (2000);
- break;
- }
- }
- else
- {
- BOOL bConned=0;
- #if TESTLOCAL
- ip = TEST_SERVER;
- // user="aaa";
- // pass="aaa";
- #endif
- if(!pftp->LogOnToServer(ip,g_pMainWnd->m_port, user, pass))
- bConned=0;
- if(bConned==0)
- {
- int pos=::FindArray (&g_serverip, ip);
- if(pos!=-1)
- {
- int count=g_failcount.ElementAt (pos);
- g_failcount.SetAt (pos, count+1);
- }
- ip=hskip;
- g_connedip.SetAt (pos, ip);
- if(::FindArray (&g_serverip, ip)==-1)
- {
- g_serverip.Add (ip);
- g_failcount.Add (0);
- }
- #ifdef TESTLOCAL
- ip = TEST_SERVER;
- // user="aaa";
- // pass="aaa";
- #endif
- if(!pftp->LogOnToServer(ip,g_pMainWnd->m_port, user, pass))
- {
- int pos=::FindArray (&g_serverip, ip);
- if(pos!=-1)
- {
- int count=g_failcount.ElementAt (pos);
- g_failcount.SetAt (pos, count+1);
- }
- g_pMainWnd->ModifyStaus3(path, -1, ip);
- delete pftp;pftp=NULL;g_pSend[pos]=pftp;
- ::Sleep (2000);
- break;
- }
- }
- }
- g_pMainWnd->ModifyStaus(path, "连接成功");
- }
- g_pMainWnd->ModifyStaus(path, "上传中..");
- int ret;
- if(savedomain.IsEmpty ())
- ret = pftp->MoveFile(clientid+"\\"+filename,filepath, "ok2.dat"==filename);
- else
- ret = pftp->MoveFile(savedomain+"\\"+clientid+"\\"+filename,filepath, "ok2.dat"==filename);
-
- // delete pftp;pftp=NULL; //g_pSend[pos]=pftp;
- g_pMainWnd->ModifyStaus(path, "上传结束");
- if(ret==3)//关闭线程
- {
- g_pMainWnd->ModifyStaus(path, "等待中");
- break;
- }
- else if(ret!=1 )
- {
- g_nFail++;
- g_pMainWnd->ModifyStaus3(path, ret, filename);
- break;
- int pos=::FindArray (&g_serverip, ip);
- if(pos!=-1)
- {
- int count=g_failcount.ElementAt (pos);
- g_failcount.SetAt (pos, count+1);
- }
- j-=2;
- ::Sleep (2000);
- continue;
- }
- }
- m_uploadtaskarray.SetAt (j+1, "OK");
- // GetSize() -2 的原因是,最后一个是空字符,而ok2.dat则必须是倒数第2个;
- if(m_uploadtaskarray.ElementAt(m_uploadtaskarray.GetSize()-2)!="ok2.dat")
- {
- m_uploadtaskarray.Add("ok2.dat");
- m_uploadtaskarray.Add("");
- }
- SaveUploadFileStaus(path, &m_uploadtaskarray);
- g_pMainWnd->ModifyStaus(path, "保存状态");
- g_pMainWnd->CheckTaskOK(path);
- g_pMainWnd->ModifyStaus(path, "检查是否传完");
- ::Sleep (500);
- }
- if(pftp)
- delete pftp;
- pftp=NULL;
- g_pSend[pos]=pftp;
- ::Sleep (1000);
- }
- else
- {
- g_pMainWnd->ModifyStaus2(taskpath);
- // AfxMessageBox("m");
- }
- ll: g_pMainWnd->m_bRunning1[pos]=false;
- g_pMainWnd->m_bTerminate1[pos]=false;
- _endthreadex( 0 );
- return 0;
- }
- unsigned __stdcall SendMsgThread2(LPVOID lpParam)
- {
- while(1)
- {
- if(g_pMainWnd->m_bTerminate2)
- break;
- // 由于branchinfo.dat中的地址一直在变,所以必须实时去获取branchinfo.dat中的IP信息; // 2015-09-22;
- LoadBranchInfo(&(g_pMainWnd->m_branchinfoarray));
- g_pMainWnd->LoadTaskFunc();
- MySleep(1000*60*2);
- }
- g_pMainWnd->m_bRunning2=false;
- g_pMainWnd->m_bTerminate2=false;
- _endthreadex( 0 );
- return 0;
- }
- unsigned __stdcall SendMsgThread(LPVOID lpParam)
- {
- while(1)
- {
- int i = 0;
- if(g_pMainWnd->m_bTerminate)
- break;
- int threadpos=-1;
- for( i=0; i<g_num; i++)
- {
- if(g_pMainWnd->m_bRunning1[i])continue;
- threadpos=i;break;
- }
- if(threadpos==-1)//没有空余线程
- {
- ::MySleep (60000);
- continue;
- }
- CStringArray taskpatharray;
- // WriteLogin("检查任务");
- g_taskpath[threadpos]="";
- {
- MyLock lock("accesslist1array");
- // WriteLogin("检查任务..");
- CArray<CStringArray, CStringArray>*pList1array=&(g_pMainWnd->m_List1array);
- int size=pList1array->GetSize ();
- while(size)
- {
- // 索引4 返回任务状态;
- if(pList1array->ElementAt (size-1).ElementAt (4)=="暂停")
- {
- // WriteLogin("暂停");
- size--;
- continue;
- }
- if(pList1array->ElementAt (size-1).ElementAt (4)=="上传完毕")
- {
- // WriteLogin("上传完毕");
- size--;
- continue;
- }
- if(pList1array->ElementAt (size-1).ElementAt (4)=="任务文件丢失" && ::PathFileExists (pList1array->ElementAt (size-1).ElementAt(6))==0 )
- {
- // WriteLogin("文件丢失"+pList1array->ElementAt (size-1).ElementAt(6));
- size--;
- continue;
- }
- BOOL bExist=0;
- for(int i=0; i<g_num; i++)
- {
- if(g_pMainWnd->m_bRunning1[i])
- {
- if(g_taskpath[i]==pList1array->ElementAt (size-1).ElementAt(6)) // 索引6返回*.dat路径
- {
- // WriteLogin("存在");
- bExist=1;break;
- }
- }
- }
- if(bExist)
- {
- size--;
- continue;
- }
- taskpatharray.Add (pList1array->ElementAt (size-1).ElementAt(6));
- size--;
- // g_taskpath[threadpos]=pList1array->ElementAt (size-1).ElementAt(6);
- // break;
- }
- }
- // WriteLogin("检查完毕");
- ///////////////计算优先级
- if(taskpatharray.GetSize ()==0)
- {
- ::MySleep (10000);
- continue;
- }
- // 任务数量大于1;
- if(taskpatharray.GetSize ()>1 )//&& g_serverip.GetSize ()>1)
- {
- CString ip;
- if(g_serverip.GetSize ())
- ip=g_serverip.ElementAt (0);
- for( i=1; i<g_serverip.GetSize (); i++)
- {
- if(g_failcount.ElementAt (i)<g_failcount.ElementAt (i-1))
- {
- ip=g_serverip.ElementAt (i);
- }
- }
- for( i=0; i<taskpatharray.GetSize (); i++)
- {
- CString path=taskpatharray.ElementAt (i);
- CStringArray m_uploadtaskarray;
- LoadTaskFromFile(path, &m_uploadtaskarray);
- if(m_uploadtaskarray.GetSize()<10)
- {
- continue;
- }
- CString domain=m_uploadtaskarray.ElementAt (1); // 目标域名;
- CString savedomain=m_uploadtaskarray.ElementAt (2); // 源域名;
- if(savedomain==domain)savedomain="";
- CString ip2,hskip;
- if(domain!="")
- ip2=g_pMainWnd->GetBranchIP(domain,hskip);
- else
- ip2=g_pMainWnd->GetBranchIP(path,hskip);
- if(::FindArray (&g_serverip, ip2)==-1)
- {
- g_serverip.Add (ip2);
- g_failcount.Add (0);
- }
- if(hskip!="")
- {
- if(::FindArray (&g_serverip, hskip)==-1)
- {
- g_serverip.Add (hskip);
- g_failcount.Add (0);
- }
- if(ip==ip2 || ip==hskip)
- {
- g_taskpath[threadpos]=taskpatharray.ElementAt (i);
- break;
- }
- }
- else
- {
- if(ip==ip2)
- {
- g_taskpath[threadpos]=taskpatharray.ElementAt (i);
- break;
- }
- }
- }
- }
- if(g_taskpath[threadpos].IsEmpty ())g_taskpath[threadpos]=taskpatharray.ElementAt (0);
- g_pMainWnd->m_bTerminate1[threadpos]=false;
- g_pMainWnd->m_bRunning1[threadpos]=false;
- g_pMainWnd->m_hThread1[threadpos] = NULL;
- g_pMainWnd->m_bRunning1[threadpos]=true;
- g_pMainWnd->m_hThread1[threadpos] = (HANDLE)_beginthreadex(NULL,0, ProcessTask,(LPVOID)threadpos,0,&(g_pMainWnd->m_dwThreadID1[threadpos]));
- ::MySleep (1000);
- }
- for(int i=0; i<g_num; i++)
- {
- while(1)
- {
- if(g_pMainWnd->m_bRunning1[i])
- ::Sleep (1000);
- else
- break;
- }
- }
- g_pMainWnd->m_bRunning=false;
- g_pMainWnd->m_bTerminate=false;
- _endthreadex( 0 );
- return 0;
- }
- CCPhotoFTPSendDlg::CCPhotoFTPSendDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CCPhotoFTPSendDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CCPhotoFTPSendDlg)
- m_host = _T("IT-PC");
- // m_host = _T("valuefriend.gicp.net");
- m_user = _T("aaa");
- m_pass = _T("aaa");
- m_port = g_port;
- m_fwhost = _T("");
- m_fwport = g_port;
- m_fwuser = _T("");
- m_fwpass = _T("");
- m_lfile = _T("");
- m_rfile = _T("");
- m_pasv = 1;
- m_put = 0;
- m_logontype = 0;
- m_acct = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_bTerminate=false;
- m_bRunning=false;
- m_hThread = NULL;
- m_bTerminate2=false;
- m_bRunning2=false;
- m_hThread2 = NULL;
- for(int i=0; i<MAX_THREAD; i++)
- {
- m_bTerminate1[i]=false;
- m_bRunning1[i]=false;
- m_hThread1[i] = NULL;
- g_connedip.Add ("");
- }
- CString version = _T ("Version 1.0");
- g_check1=AfxGetApp()->GetProfileInt (version, "bcontinue", 1);
- g_num=min(10, AfxGetApp()->GetProfileInt (version, "nthreadcount", 5));
- }
- void CCPhotoFTPSendDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CCPhotoFTPSendDlg)
- DDX_Control(pDX, IDC_LIST1, m_List1);
- DDX_Text(pDX, IDC_EDIT1, m_host);
- DDX_Text(pDX, IDC_EDIT2, m_user);
- DDX_Text(pDX, IDC_EDIT3, m_pass);
- DDX_Text(pDX, IDC_EDIT4, m_port);
- DDX_Text(pDX, IDC_EDIT5, m_fwhost);
- DDX_Text(pDX, IDC_EDIT6, m_fwport);
- DDX_Text(pDX, IDC_EDIT7, m_fwuser);
- DDX_Text(pDX, IDC_EDIT8, m_fwpass);
- DDX_Text(pDX, IDC_EDIT9, m_lfile);
- DDX_Text(pDX, IDC_EDIT10, m_rfile);
- DDX_Check(pDX, IDC_CHECK1, m_pasv);
- DDX_Radio(pDX, IDC_RADIO1, m_put);
- DDX_Radio(pDX, IDC_RADIO3, m_logontype);
- DDX_Text(pDX, IDC_EDIT11, m_acct);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CCPhotoFTPSendDlg, CDialog)
- //{{AFX_MSG_MAP(CCPhotoFTPSendDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_WM_DESTROY()
- ON_WM_TIMER()
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
- ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
- ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
- ON_COMMAND(IDM_OPEN, OnOpen)
- ON_COMMAND(IDM_EXIT, OnExit)
- ON_WM_CLOSE()
- ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
- ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
- ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
- //}}AFX_MSG_MAP
- ON_CONTROL_RANGE(BN_CLICKED,IDC_RADIO3,IDC_RADIO11,OnRadio)
- ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
- ON_REGISTERED_MESSAGE(g_wmClose2, OnAbortClose)
- END_MESSAGE_MAP()
- LRESULT CCPhotoFTPSendDlg::OnAbortClose(WPARAM wParam, LPARAM lParam)
- {
- HWND hwnd=::FindWindow (NULL, "数据服务器");
- if(hwnd)
- {
- ::PostMessage (hwnd, g_wmClose2, NULL, NULL);
- }
- return 1;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCPhotoFTPSendDlg message handlers
- LRESULT CCPhotoFTPSendDlg::OnTrayNotification(WPARAM wParam,LPARAM lParam)
- {
- return m_TrayIcon.OnTrayNotification(wParam,lParam);
- }
- void DeleteDirectory(CString strDir)
- {
- try
- {
- // 首先删除文件及子文件夹
- CFileFind ff;
- BOOL bFound = ff.FindFile(strDir+"\\*", 0);
- while(bFound)
- {
- bFound = ff.FindNextFile();
- if(ff.GetFileName()=="."||ff.GetFileName()=="..")
- continue;
- // 去掉文件(夹)只读等属性
- SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL);
- if(ff.IsDirectory()) { // 递归删除子文件夹
- DeleteDirectory(ff.GetFilePath());
- RemoveDirectory(ff.GetFilePath());
- }
- else {
- DeleteFile(ff.GetFilePath()); // 删除文件
- }
- }
- ff.Close();
- // 然后删除该文件夹
- RemoveDirectory(strDir);
- }
- catch(...)
- {
- }
- // int SHFileOperation( LPSHFILEOPSTRUCT lpFileOp );
- }
- BOOL CCPhotoFTPSendDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- g_pMainWnd=this;
- ////////////////////////////
- if(0)
- {
- MessageBox("1");
- CString ip="IT-PC";
- int pos=0;
- CStringArray m_uploadtaskarray;
- using namespace helper_coffs;
- ffsco o;
- o.dirs(0);
- o.find(LPCSTR("e:\\ccc"), LPCSTR("*.*"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_file();
- for (it = coo.begin(); coo.end() != it; it ++)
- {
- CString path=(*it).c_str();
- m_uploadtaskarray.Add (path.Right (path.GetLength ()-path.ReverseFind ('\\')-1));
- }
- CString dir="e:\\ccc\\";
- CString ziptype,path;
- CFTPSend2 *pftp=NULL;//g_pSend[pos]=pftp;
- for(int j=0; j<m_uploadtaskarray.GetSize(); j++)
- {
- CString filename=m_uploadtaskarray.ElementAt (j);
- CString filepath=dir+filename;
- if(::PathFileExists (filepath) )
- {
- if(pftp==NULL)
- {
- g_pMainWnd->ModifyStaus(path, "开始连接");
- pftp=new CFTPSend2;//g_pSend[pos]=pftp;
- pftp->m_path=path;
- pftp->m_pos=pos;
- pftp->m_bStop =&(g_pMainWnd->m_bTerminate);
- pftp->m_ziptype=ziptype;
- if(!pftp->LogOnToServer(ip,g_pMainWnd->m_port, "aaa", "aaa"))
- {
- MessageBox("连接失败");
- g_pMainWnd->ModifyStaus3(path, -1, ip);
- delete pftp;pftp=NULL;//g_pSend[pos]=pftp;
- ::Sleep (2000);
- break;
- }
- }
- g_pMainWnd->ModifyStaus(path, "开始上传");
- int ret;
- ret=pftp->MoveFile(filename,filepath, "ok2.dat"==filename);
- // delete pftp;pftp=NULL; //g_pSend[pos]=pftp;
- g_pMainWnd->ModifyStaus(path, "上传结束");
- if(ret!=1 )
- { //MessageBox("上传失败");
- g_nFail++;
- g_pMainWnd->ModifyStaus3(path, ret, filename);
- ::Sleep (2000);continue;
- }
- }
- ::Sleep (500);
- }
- delete pftp;pftp=NULL;
- MessageBox("ok");
- CDialog::OnOK();
- return 0;
- }
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- g_listctrlfont.CreatePointFont (110, _T("System"));
- // m_List1.SetHeadings("发往,120;客人,250;类型,100;已上传,100;状态,150;任务路径,100" );
- // m_List1.LoadColumnInfo (100);
- m_List1.InsertColumn(0, "发往", LVCFMT_LEFT, 140);
- m_List1.InsertColumn(1, "客人", LVCFMT_LEFT, 250);
- m_List1.InsertColumn(2, "类型", LVCFMT_LEFT, 80);
- m_List1.InsertColumn(3, "已上传", LVCFMT_LEFT, 100);
- m_List1.InsertColumn(4, "状态", LVCFMT_LEFT, 150);
- m_List1.InsertColumn(5, "日期", LVCFMT_LEFT, 100);
- m_List1.InsertColumn(6, "任务路径", LVCFMT_LEFT, 120);
- m_List1.SetFont (&g_listctrlfont);
- m_List1.SetExtendedStyle(LVS_EX_FLATSB|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
- TCHAR szDir[MAX_PATH];
- ::GetModuleFileName (NULL, szDir, MAX_PATH);
- g_mainpath=szDir;
- g_mainpath=g_mainpath.Left (g_mainpath.ReverseFind ('\\'));
- CString path=g_mainpath+"\\temp";
- DeleteDirectory(path);
- m_bFirst=1;
- LoadTaskFunc();
- m_bFirst=0;
- SetTimer(4, 5000, NULL);
- SetTimer(1, 200, NULL);
- SetTimer(5, 10000, NULL);
- return TRUE; // return TRUE unless you set the focus to a control
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CCPhotoFTPSendDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CCPhotoFTPSendDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- // hide/show firewall edit ctrls as appropriate
- void CCPhotoFTPSendDlg::OnRadio(UINT nID)
- {
- UpdateData(TRUE);
- for(int i=IDC_EDIT5;i<=IDC_EDIT8;i++)
- GetDlgItem(i)->EnableWindow(m_logontype);
- }
- void CCPhotoFTPSendDlg::GetUserPswFromPhotoType(CString type, CString &user, CString &pass)
- {
- if(type=="原片")
- {
- user="photo1account";
- pass="lyfzphoto1account";
- }
- else if(type=="初修片")
- {
- user="photo2account";
- pass="lyfzphoto2account";
- }
- else if(type=="精修片")
- {
- user="photo3account";
- pass="lyfzphoto3account";
- }
- else if(type=="设计片")
- {
- user="photo4account";
- pass="lyfzphoto4account";
- }
- else
- {
- user="";
- pass="";
- }
- }
- int CCPhotoFTPSendDlg::FTPFile(CString path, CString name)
- {
- return 0;
- }
- void CCPhotoFTPSendDlg::OnButton1()
- {
- }
- BOOL CCPhotoFTPSendDlg::TerminateThread()
- {
- try
- {
- if ( !m_bRunning )
- return TRUE;
- m_bTerminate=true;
- for( ; ; )
- {
- if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
- break;
- MSG msg;
- while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
- {
- if (!AfxGetApp()->PumpMessage())
- break;
- }
- }
- ::CloseHandle(m_hThread);
- m_bRunning=false;
- return TRUE;
- }
- catch(...)
- {
- }
- }
- BOOL CCPhotoFTPSendDlg::TerminateThread2()
- {
- try
- {
- if ( !m_bRunning2 )
- return TRUE;
- m_bTerminate2=true;
- for( ; ; )
- {
- if ( ::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0 )
- break;
- MSG msg;
- while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
- {
- if (!AfxGetApp()->PumpMessage())
- break;
- }
- }
- ::CloseHandle(m_hThread2);
- m_bRunning2=false;
- return TRUE;
- }
- catch(...)
- {
- }
- }
- void CloseFTP(int pos)
- {
- try
- {
- CFTPSend2 *pftp=g_pSend[pos];
- if(pftp)
- {
- delete pftp;
- pftp=NULL;
- g_pSend[pos]=pftp;
- }
- }
- catch(...)
- {
- }
- }
- BOOL CCPhotoFTPSendDlg::TerminateThread1(int pos)
- {
- try
- {
- CloseFTP(pos);
- if ( ! (m_bRunning1[pos]) )
- return TRUE;
- m_bTerminate1[pos]=true;
- ::TerminateThread (m_hThread1[pos], 0);
- ::CloseHandle(m_hThread1[pos]);
- m_bRunning1[pos]=false;
- return 1;
- for( ; ; )
- {
- if ( ::WaitForSingleObject(m_hThread1[pos], 0) == WAIT_OBJECT_0 )
- break;
- MSG msg;
- while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
- {
- if (!AfxGetApp()->PumpMessage())
- break;
- }
- }
- ::CloseHandle(m_hThread1[pos]);
- m_bRunning1[pos]=false;
- return TRUE;
- }
- catch(...)
- {
- }
- }
- BOOL g_bOldSaveType=0;
- void CCPhotoFTPSendDlg::LoadTaskFunc()
- {
- CArray<CStringArray, CStringArray>m_List1temparray;
- CString g_path1;
- CString g_path2;
- CString g_path3;
- CString g_path4;
- char server[50];
- DWORD leng=50;
- ::GetComputerName (server, &leng);
- g_path1=g_path2=g_path3=g_path4=server;
- g_path1="\\\\"+g_path1+"\\客户原片(管理软件)$";
- g_path2="\\\\"+g_path2+"\\修好的片(管理软件)$";
- g_path3="\\\\"+g_path3+"\\设计好的片(管理软件)$";
- g_path4="\\\\"+g_path4+"\\精修好的片(管理软件)$";
- // 所有"上传任务"文件夹集合;在 客户原片(管理软件)$ 和该目录下的分店目录中,都有一个"上传任务"文件夹;
- CStringArray dirarray;
- // 所有"上传任务"文件夹中的全部dat文件路径集合;
- CStringArray taskarray;
- CString path;
- using namespace helper_coffs;
- CString patharray[4]={g_path2,g_path1,g_path3,g_path4};
- if(m_bFirst==0)
- {
- if(g_bOldSaveType)
- {
- g_bOldSaveType=0;
- }
- else
- {
- WriteLogin("读取任务");
- // 查找出所有"上传文件"目录;
- ffsco o;
- o.dirs(1);
- o.find(LPCSTR(g_path1), LPCSTR("*.*"));WriteLogin(g_path1);
- if(g_pMainWnd->m_bTerminate)return;
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_dir();
- it = coo.begin();
- it ++;
- for (;coo.end() != it;it ++)
- {
- if(m_bTerminate)return;
- path=(*it).c_str();
- if(path.Find("上传任务")==-1)continue;
- if(::FindArray (&dirarray, path)==-1)
- dirarray.Add (path);
- }
- // 查找出所有上传dat文件;
- for(int i=0; i<dirarray.GetSize (); i++)
- {
- ffsco o;
- o.dirs(0);
- o.find(LPCSTR(dirarray.ElementAt (i)), LPCSTR("*.dat"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_file();
- for (it = coo.begin(); coo.end() != it;it ++)
- {
- path=(*it).c_str();
- if( ::FindArray (&taskarray, path)==-1)
- {
- taskarray.Add (path);
- WriteLogin(path);
- }
- }
- }
- }
- }
- if(m_bTerminate)return;
- WriteLogin("从文件读取任务");
- {
- // 读取运行目录下的uploaktask.dat文件内容;
- CFile fp;
- MyLock lock("maintaskmanage");
- if(fp.Open(g_mainpath+"\\uploadtask.dat", CFile::modeRead))
- {
- DWORD leng=fp.GetLength ();
- DWORD arraysize;
- fp.Read (&arraysize, sizeof(DWORD));
- BYTE *pData=new BYTE[leng-sizeof(DWORD)];
- fp.Read (pData,leng-sizeof(DWORD));
- fp.Close ();
- try
- {
- CMemFile memfile;
- memfile.Attach (pData,leng-sizeof(DWORD));
- CArchive ar(&memfile, CArchive::load);
- m_List1temparray.SetSize(arraysize, 1);
- for(int ii=0; ii<m_List1temparray.GetSize (); ii++)
- {
- m_List1temparray.ElementAt (ii).Serialize (ar);
- }
- ar.Close();
- memfile.Detach ();
- delete []pData;
- }
- catch(...)
- {
- ::WriteLogin ("读取任务文件失败");
- ::DeleteFile(g_mainpath+"\\uploadtask.dat");
- if(m_bFirst)
- CDialog::OnCancel ();
- else
- OnExit();
- return;
- }
- for(int ii=0; ii<m_List1temparray.GetSize (); ii++)
- {
- if(m_List1temparray.ElementAt (ii).GetSize ()==10) // 每一个元素大小固定在10个;
- {
- CString modifydate;
- if(::PathFileExists (m_List1temparray.ElementAt (ii).ElementAt (5))) // 索引5:上传完成日期;这里应该搞错了,应该填索引6;
- {
- modifydate=GetModifyDate(m_List1temparray.ElementAt (ii).ElementAt (5));
- }
- m_List1temparray.ElementAt (ii).InsertAt (5, modifydate);
- }
- }
- int aa=0;
- while(m_List1temparray.GetSize ()>500)
- {
- for(int i=m_List1temparray.GetSize ()-1; i>=0; i--)
- {
- if(m_List1temparray.ElementAt (i).ElementAt (4)=="上传完毕")
- {
- m_List1temparray.RemoveAt(i);break;
- }
- }
- aa++;
- if(aa>20)break;
- }
- WriteLogin("读取任务文件成功");
- }
- else
- WriteLogin("打开任务文件失败");
- }
- BOOL bNeedLoad=0;
- {
- int i = 0;
- int oldsize=m_List1temparray.GetSize();
- for( i=0; i<taskarray.GetSize (); i++)
- {
- WriteLogin("读取"+taskarray.ElementAt (i));
- if(TaskExist(taskarray.ElementAt (i), &m_List1temparray))
- {
- // 存在,且未上传完成;
- WriteLogin("失败1");
- continue;
- }
- // 获取每个*.dat中的目标分店域名;
- if(GetBranch(taskarray.ElementAt (i))=="")
- {
- WriteLogin("失败2");
- continue;
- }
- // 相片数量;
- int photocount=0;
- // 顾客昵称;
- CString client=GetClient(taskarray.ElementAt (i), photocount); // 返回顾客名字,以及相片数量;
- if(client=="")
- {
- WriteLogin("失败3");
- continue;
- }
- // size 任务个数;
- int size=m_List1temparray.GetSize();
- m_List1temparray.SetSize(size+1, 1);
- // 添加新的任务到uploadtask.dat中,即m_Listtemparray;
- m_List1temparray.ElementAt (size).Add (GetBranch(taskarray.ElementAt (i)));
- m_List1temparray.ElementAt (size).Add (client);
- m_List1temparray.ElementAt (size).Add (GetPhotoType(taskarray.ElementAt (i)));
- client.Format ("%d/%d", 0, photocount);
- m_List1temparray.ElementAt (size).Add (client);
- m_List1temparray.ElementAt (size).Add ("等待中");
- m_List1temparray.ElementAt (size).Add (GetModifyDate(taskarray.ElementAt (i)));
- m_List1temparray.ElementAt (size).Add (taskarray.ElementAt (i));
- m_List1temparray.ElementAt (size).Add ("");
- m_List1temparray.ElementAt (size).Add ("");
- m_List1temparray.ElementAt (size).Add ("");
- m_List1temparray.ElementAt (size).Add (""); bNeedLoad=1;
- }
- MyLock lock("accesslist1array");
- m_List1array.RemoveAll ();
- m_List1array.SetSize(m_List1temparray.GetSize (), 1);
- int size=m_List1temparray.GetSize ();
- for( i=oldsize; i<size; i++)
- {
- m_List1array.ElementAt (i-oldsize).Copy (m_List1temparray.ElementAt (i));
- }
- for( i=0; i<oldsize; i++)
- {
- m_List1array.ElementAt (size-oldsize+i).Copy (m_List1temparray.ElementAt (i));
- }
- if(size!=oldsize)bNeedLoad=1;
- }
- if(bNeedLoad || m_List1.GetItemCount ()==0 )
- {
- FillGrid();
- SaveTask();
- }
- }
- CString CCPhotoFTPSendDlg::GetBranch(CString path)
- {
- // 1.由本店上传到其他分店;
- int pos=path.Find(".ly.com");
- if(pos==-1)
- {
- //本店传出
- MyLock lock("uploadtaskaccess");
- CFile fp;
- if(fp.Open (path, CFile::modeRead))
- {
- DWORD length=fp.GetLength ();
- if(!length)return "";
- CArchive ar(&fp, CArchive::load);
- CStringArray array;
- array.Serialize (ar);
- fp.Close ();
- if(!array.GetSize ()>2)return "";
- // 读取目标域名;
- if(array.ElementAt (1).Find (".ly.com")==-1)
- return "";
- CString str=GetBranchNameFromDoMain(array.ElementAt (1));
- if(str.IsEmpty ())
- return "";
- return "本店->"+str;
- }
- else
- return "";
- }
- // 2.由分店上传回分店服务器;
- CString pathbak=path;
- path=path.Left(pos+7);
- path=path.Right(path.GetLength()-path.ReverseFind('\\')-1);
- CString from =GetBranchNameFromDoMain(path)+"->";
- CString des;
- MyLock lock("uploadtaskaccess");
- CFile fp;
- if(fp.Open (pathbak, CFile::modeRead))
- {
- DWORD length=fp.GetLength ();
- if(length)
- {
- CArchive ar(&fp, CArchive::load);
- CStringArray array;
- array.Serialize (ar);
- fp.Close ();
- if(array.GetSize ()>=2)
- {
- if(array.ElementAt (1).Find (".ly.com")!=-1)
- des=GetBranchNameFromDoMain(array.ElementAt (1));
- }
- }
- }
- else
- des="";
- return from+des;
- }
- CString CCPhotoFTPSendDlg::GetBranchNameFromDoMain(CString domain)
- {
- BOOL bLoad=0;
- if(1)
- {
- MyLock lock("savebranchinfo");
- if(m_branchinfoarray.GetSize ()==0)
- bLoad=1;
- }
- if(bLoad)LoadBranchInfo(&m_branchinfoarray);
- MyLock lock("savebranchinfo");
- for(int i=0; i<m_branchinfoarray.GetSize (); i++)
- {
- if(domain==m_branchinfoarray.ElementAt (i).ElementAt (0))
- {
- // MessageBox(m_branchinfoarray.ElementAt (i).ElementAt (1));
- return m_branchinfoarray.ElementAt (i).ElementAt (1);
- }
- }
- return "";
- }
- CString CCPhotoFTPSendDlg::GetBranchIP(CString path, CString &hskip)
- {
- if(path.Find ("\\")==-1)
- return GetBranchIPFromDoMain(path, hskip);
- int pos=path.Find(".ly.com");
- if(pos==-1)
- return "";
- path=path.Left(pos+7);
- path=path.Right(path.GetLength()-path.ReverseFind('\\')-1);
- return GetBranchIPFromDoMain(path, hskip);
- }
- CString CCPhotoFTPSendDlg::GetBranchIPFromDoMain(CString domain, CString &hskip)
- {
- BOOL bLoad=0;
- if(1)
- {
- // MyLock lock("savebranchinfo");
- // if(m_branchinfoarray.GetSize ()==0)
- bLoad=1;
- }
- if(bLoad)LoadBranchInfo(&m_branchinfoarray);
- MyLock lock("savebranchinfo");
- for(int i=0; i<m_branchinfoarray.GetSize (); i++)
- {
- if(domain==m_branchinfoarray.ElementAt (i).ElementAt (0))
- {
- if(m_branchinfoarray.ElementAt (i).GetSize ()>6)
- hskip=m_branchinfoarray.ElementAt (i).ElementAt (6);
- return m_branchinfoarray.ElementAt (i).ElementAt (2);
- }
- }
- return "";
- }
- // path:任务文件*.dat;
- // size:相片数量;
- CString CCPhotoFTPSendDlg::GetClient(CString path, int &size)
- {
- MyLock lock("uploadtaskaccess");
- CFile fp;
- if(fp.Open (path, CFile::modeRead))
- {
- DWORD length=fp.GetLength ();
- if(length==0)
- {
- fp.Close ();
- ::DeleteFile (path);
- return "";
- }
- CStringArray m_uploadtaskarray;
- CArchive ar(&fp, CArchive::load);
- m_uploadtaskarray.Serialize (ar);
- fp.Close ();
- if(m_uploadtaskarray.GetSize())
- {
- size=(m_uploadtaskarray.GetSize()-10)/2; // 返回相片数量;
- return m_uploadtaskarray.ElementAt(0);
- }
- }
- return "";
- }
- CString CCPhotoFTPSendDlg::GetPhotoType(CString path)
- {
- WriteLogin("获取类型"+path);
- CString g_path1;
- CString g_path2;
- CString g_path3;
- CString g_path4;
- g_path1="\\客户原片(管理软件)$";
- g_path2="\\修好的片(管理软件)$";
- g_path3="\\设计好的片(管理软件)$";
- g_path4="\\精修好的片(管理软件)$";
- CStringArray m_uploadtaskarray;
- LoadTaskFromFile(path, &m_uploadtaskarray);
- if(m_uploadtaskarray.GetSize()<10)
- {
- WriteLogin("获取类型失败1");
- return "";
- }
- CString dir=path;
- CString dirinfile=m_uploadtaskarray.ElementAt (4);
- if(dirinfile!="")
- {
- WriteLogin("目录"+dir);
- dir=dirinfile;
- }
- if(dir.Find(g_path1)!=-1)return "原片";
- if(dir.Find(g_path2)!=-1)return "初修片";
- if(dir.Find(g_path3)!=-1)return "设计片";
- if(dir.Find(g_path4)!=-1)return "精修片";
- WriteLogin("获取类型失败2");
- return "";
- }
- BOOL CCPhotoFTPSendDlg::SaveTask()
- {
- MyLock lock2("accesslist1array");
- CMemFile memfile;
- CArchive ar(&memfile, CArchive::store);
- for(int ii=0; ii<m_List1array.GetSize (); ii++)
- {
- m_List1array.ElementAt (ii).Serialize (ar);
- }
- ar.Close();
- CFile fp;
- MyLock lock("maintaskmanage");
- if(fp.Open(g_mainpath+"\\uploadtask.dat", CFile::modeCreate|CFile::modeWrite))
- {
- DWORD nBranchDataLeng=memfile.GetLength ();
- BYTE *pBranchData=memfile.Detach();
- DWORD size=m_List1array.GetSize ();
- fp.Write(&size, sizeof(DWORD));
- fp.Write(pBranchData, nBranchDataLeng);
- fp.Close();
- delete []pBranchData;
- return 1;
- }
- else
- WriteLogin("保存上传任务失败!");
- return 0;
- }
- void CCPhotoFTPSendDlg::FillGrid()
- {
- MyLock lock("accesslist1array");
- m_List1.DeleteAllItems ();
- int count=0;
- for(int ii=0; ii<m_List1array.GetSize (); ii++)
- {
- for(int jj=0; jj<7; jj++)
- {
- if(jj==0)
- m_List1.InsertItem (ii, m_List1array.ElementAt (ii).ElementAt (jj));
- else
- m_List1.SetItemText (ii, jj, m_List1array.ElementAt (ii).ElementAt (jj));
- }
- }
- /*m_List1.DeleteAllItems2 ();
- int ii=0;
- m_List1.m_arLabels.SetSize( m_List1array.GetSize (), 1 );
- int count=0;
- for(ii=0; ii<m_List1.m_arLabels.GetSize (); ii++)
- {
- m_List1.m_arLabels.ElementAt (count++).Copy (m_List1array.ElementAt (ii));
- }
- m_List1.m_arLabels.SetSize(count, 1);
- ii=count;
- m_List1.m_LabelCount=ii;
- m_List1.SetItemCountEx (ii);*/
- }
- BOOL CCPhotoFTPSendDlg::TaskExist(CString path, CArray<CStringArray, CStringArray>*pList1array)
- {
- for(int i=0; i<pList1array->GetSize(); i++)
- {
- if(path==pList1array->ElementAt(i).ElementAt(6))
- {
- if(pList1array->ElementAt(i).ElementAt(4)!="上传完毕")
- return 1;
- }
- }
- return 0;
- }
- void CCPhotoFTPSendDlg::ModifyStaus(CString path, CString info)
- {
- MyLock lock("accesslist1array");
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(path==m_List1array.ElementAt(i).ElementAt(6) && "上传完毕"!=m_List1array.ElementAt(i).ElementAt(4))
- {
- m_List1array.ElementAt(i).SetAt(4, info);
- m_List1.SetItemText (i, 4, info);
- //FillGrid();
- break;
- }
- }
- }
- extern CString g_failstr;
- void CCPhotoFTPSendDlg::ModifyStaus3(CString path, int type, CString ip)
- {
- MyLock lock("accesslist1array");
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(path==m_List1array.ElementAt(i).ElementAt(6) && "上传完毕"!=m_List1array.ElementAt(i).ElementAt(4))
- {
- if(type==-1)
- m_List1array.ElementAt(i).SetAt(4, "连接服务器"+ip+"失败");
- else
- m_List1array.ElementAt(i).SetAt(4, "上传文件失败:"+ip+g_failstr);
- // FillGrid();
- m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
- break;
- }
- }
- }
- void CCPhotoFTPSendDlg::ModifyStaus4(CString path, CString str,int pos)
- {
- MyLock lock2("accessrefreshlist");
- MyLock lock("accesslist1array");
- // if(m_bRunning1[pos]==0)return;
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(path==m_List1array.ElementAt(i).ElementAt(6) && m_List1array.ElementAt(i).ElementAt(4)!="上传完毕")
- {
- if(m_List1array.ElementAt(i).ElementAt(4)!="暂停")
- {
- m_List1array.ElementAt(i).SetAt(4, str);
- m_List1.SetItemText (i, 4, str);
- }
- break;
- }
- }
- }
- void CCPhotoFTPSendDlg::ModifyStaus2(CString path)
- {
- {
- MyLock lock("accesslist1array");
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(path==m_List1array.ElementAt(i).ElementAt(6) && m_List1array.ElementAt(i).ElementAt(4)!="上传完毕")
- {
- m_List1array.ElementAt(i).SetAt(4, "任务文件丢失");
- m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
- // FillGrid();
- break;
- }
- }
- }
- SaveTask();
- }
- void CCPhotoFTPSendDlg::OnDestroy()
- {
- CDialog::OnDestroy();
- // TODO: Add your message handler code here
- }
- void CCPhotoFTPSendDlg::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- if(nIDEvent==1)
- {
- KillTimer(1);
- #ifndef _DEBUG
- OnClose();
- #endif
- UpdateData(TRUE);
- m_bTerminate=false;
- m_bRunning=false;
- m_hThread = NULL;
- m_bRunning=true;
- m_hThread = (HANDLE)_beginthreadex(NULL,0, SendMsgThread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
- m_bTerminate2=false;
- m_bRunning2=false;
- m_hThread2 = NULL;
- m_bRunning2=true;
- m_hThread2 = (HANDLE)_beginthreadex(NULL,0, SendMsgThread2,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID2);
- SetTimer(3, 40000, NULL);
- }
- else if(nIDEvent==3)
- {//settimer
- return;
- MyLock lock("g_bActiveaccess");
- for(int i=0; i<g_num; i++)
- {
- if(g_bActive[i]==0 && g_taskpath[i]!="" && m_bRunning1[i])
- {
- g_pMainWnd->ModifyStaus(g_taskpath[i], "连接超时");g_nFail++;
- TerminateThread1(i);
- CString ip=g_connedip.ElementAt (i);
- int pos=::FindArray (&g_serverip, ip);
- if(pos!=-1)
- {
- int count=g_failcount.ElementAt (pos);
- g_failcount.SetAt (pos, count+1);
- }
- }
- g_bActive[i]=0;
- }
- }
- else if(nIDEvent==4)
- {
- static DWORD ticks=::GetTickCount();
- if(g_nFail>30 && (GetTickCount()-ticks>1000*60*5) )
- {
- OnExit();
- }
- }
- else if(nIDEvent==5)
- {
- HWND hwnd=::FindWindow (NULL, "数据服务器");
- if(hwnd)
- {
- ::PostMessage (hwnd, g_wmClose2, NULL, NULL);
- }
- }
- }
- void CCPhotoFTPSendDlg::CheckTaskOK(CString path)
- {
- MyLock lock("uploadtaskaccess");
- CFile fp;
- if(fp.Open (path, CFile::modeRead))
- {
- DWORD length=fp.GetLength ();
- if(!length)return;
- CArchive ar(&fp, CArchive::load);
- CStringArray m_uploadtaskarray;
- m_uploadtaskarray.Serialize (ar);
- fp.Close ();
- BOOL bFind=0;
- int count1=0;
- int count2=0;
- for(int j=10; j<m_uploadtaskarray.GetSize(); j+=2)
- {
- if(m_uploadtaskarray.ElementAt (j+1)!="OK")
- {
- bFind=1;
- }
- else
- count1++;
- count2++;
- }
- if(bFind==0)//全部传完
- {
- BOOL bSave=0;
- {
- MyLock lock("accesslist1array");
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(path==m_List1array.ElementAt(i).ElementAt(6) && m_List1array.ElementAt(i).ElementAt(4)!="上传完毕")
- {
- m_List1array.ElementAt(i).SetAt(4, "上传完毕");
- CString str;
- str.Format ("%d/%d", count1, count2);
- m_List1array.ElementAt(i).SetAt(3, str);
- m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
- m_List1.SetItemText (i, 3, str);
- // FillGrid();
- bSave=1;
- break;
- }
- }
- }
- if(bSave)
- {
- if(SaveTask())
- {
- ::DeleteFile (path);
- }
- }
- }
- else
- {
- BOOL bSave=0;
- {
- MyLock lock("accesslist1array");
- for(int i=0; i<m_List1array.GetSize(); i++)
- {
- if(path==m_List1array.ElementAt(i).ElementAt(6) && m_List1array.ElementAt(i).ElementAt(4)!="上传完毕")
- {
- CString str;
- str.Format ("%d/%d", count1, count2);
- m_List1array.ElementAt(i).SetAt(3, str);
- if(m_List1array.ElementAt(i).ElementAt(4)!="暂停")
- {
- m_List1array.ElementAt(i).SetAt(4, "上传中");
- m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
- }
- m_List1.SetItemText (i, 3, str);
- // FillGrid();
- bSave=1;
- break;
- }
- }
- }
- if(bSave)
- {
- SaveTask();
- }
- }
- }
- else
- WriteLogin("检查任务是否完成"+path+"失败!");
- }
- void CCPhotoFTPSendDlg::OnButton2()
- {
- MyLock lock2("accessrefreshlist");
- // TODO: Add your control notification handler code here
- if(m_pathbak.IsEmpty() )
- {
- AfxMessageBox("请先选中您要取消的任务!", MB_ICONINFORMATION);
- return;
- }
- CString path=m_pathbak;
- if(AfxMessageBox("是否取消"+m_clientinfo+"上传任务?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
- BOOL bSave=0;
- {
- MyLock lock("accesslist1array");
- for(int i=0; i<m_List1array.GetSize (); i++)
- {
- if(path==m_List1array.ElementAt (i).ElementAt (6) && ("上传完毕"!=m_List1array.ElementAt(i).ElementAt(4)||"任务文件丢失"==m_List1array.ElementAt(i).ElementAt(4) ))
- {
- for(int j=0; j<g_num; j++)
- {
- if(g_taskpath[j]==path && m_bRunning1[j])
- {
- TerminateThread1(j);
- }
- }
- if(::DeleteFile (path))
- {
- m_List1array.RemoveAt(i);
- m_List1.DeleteItem (i);
- bSave=1;
- }
- else
- {
- ::Sleep(1000);
- if(::DeleteFile (path))
- {
- m_List1array.RemoveAt(i);
- m_List1.DeleteItem (i);
- bSave=1;
- }
- }
- if("任务文件丢失"==m_List1array.ElementAt(i).ElementAt(4))
- {
- if(bSave==0)
- {
- m_List1array.RemoveAt(i);
- m_List1.DeleteItem (i);
- }
- bSave=1;
- }
- if(bSave==0)
- AfxMessageBox("取消任务失败,请稍候再试!", MB_ICONINFORMATION);
- break;
- }
- }
- }
- if(bSave)
- {
- SaveTask();
- }
- }
- void CCPhotoFTPSendDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- POSITION pos;
- pos=m_List1.GetFirstSelectedItemPosition();
- if(pos==NULL)
- {
- return;
- }
- int iItem=m_List1.GetNextSelectedItem(pos);
- m_pathbak=m_List1.GetItemText (iItem, 6);
- m_clientinfo=m_List1.GetItemText (iItem, 0)+";"+m_List1.GetItemText (iItem, 1)+";"+m_List1.GetItemText (iItem, 2);
- *pResult = 0;
- }
- void CCPhotoFTPSendDlg::OnButton3()
- {
- MyLock lock2("accessrefreshlist");
- // TODO: Add your control notification handler code here
- if(m_pathbak.IsEmpty() )
- {
- AfxMessageBox("请先选中您要暂停的任务!", MB_ICONINFORMATION);
- return;
- }
- CString path=m_pathbak;
- if(AfxMessageBox("是否暂停"+m_clientinfo+"上传任务?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
- BOOL bSave=0;
- {
- MyLock lock("accesslist1array");
- for(int i=0; i<m_List1array.GetSize (); i++)
- {
- if(path==m_List1array.ElementAt (i).ElementAt(6) && "上传完毕"!=m_List1array.ElementAt(i).ElementAt(4))
- {
- for(int j=0; j<g_num; j++)
- {
- if(g_taskpath[j]==path && m_bRunning1[j])
- {
- TerminateThread1(j);
- }
- }
- m_List1array.ElementAt (i).SetAt (4, "暂停");
- m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
- bSave=1;
- break;
- }
- }
- }
- if(bSave) SaveTask();
- }
- BOOL CCPhotoFTPSendDlg::IsStatusPause(CString path)
- {
- MyLock lock("accesslist1array");
- for(int i=0; i<m_List1array.GetSize (); i++)
- {
- if(path==m_List1array.ElementAt (i).ElementAt(6) && "暂停"==m_List1array.ElementAt(i).ElementAt(4))
- {
- return 1;
- }
- }
- return 0;
- }
- void CCPhotoFTPSendDlg::OnButton4()
- {
- MyLock lock2("accessrefreshlist");
- // TODO: Add your control notification handler code here
- if(m_pathbak.IsEmpty() )
- {
- AfxMessageBox("请先选中您要继续上传的任务!", MB_ICONINFORMATION);
- return;
- }
- CString path=m_pathbak;
- if(AfxMessageBox("是否继续"+m_clientinfo+"上传任务?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
- BOOL bSave=0;
- {
- MyLock lock("accesslist1array");
- for(int i=0; i<m_List1array.GetSize (); i++)
- {
- if(path==m_List1array.ElementAt (i).ElementAt(6) && "上传完毕"!=m_List1array.ElementAt(i).ElementAt(4))
- {
- for(int j=0; j<g_num; j++)
- {
- if( m_bRunning1[j])
- {
- TerminateThread1(j);
- }
- }
- // g_pMainWnd->m_bTerminate1[0]=g_pMainWnd->m_bTerminate1[1]=g_pMainWnd->m_bTerminate1[2]=g_pMainWnd->m_bTerminate1[3]=g_pMainWnd->m_bTerminate1[4]=1;
- m_List1array.ElementAt (i).SetAt (4, "等待中");
- m_List1.SetItemText (i, 4, m_List1array.ElementAt (i).ElementAt (4));
- // FillGrid();
- bSave=1;
- break;
- }
- }
- }
- if(bSave)SaveTask();
- }
- //mylock
- void CCPhotoFTPSendDlg::OnCancel()
- {
- // TODO: Add extra cleanup here
- }
- void CCPhotoFTPSendDlg::OnOpen()
- {
- // TODO: Add your command handler code here
- ShowWindow(SW_SHOW);
- }
- void CCPhotoFTPSendDlg::OnExit()
- {
- // TODO: Add your command handler code here
- if(m_bTerminate)return;
- m_TrayIcon.RemoveIcon();
- for(int i=0; i<g_num; i++)
- {
- if(g_taskpath[i]!="" && m_bRunning1[i])
- {
- TerminateThread1(i);
- }
- }
- TerminateThread();TerminateThread2();
- CDialog::OnCancel ();
- }
- void CCPhotoFTPSendDlg::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
- m_TrayIcon.Create(this,WM_ICON_NOTIFY,"客照上传服务器" ,m_hIcon,IDR_MENUtray); //构造
- ShowWindow(SW_HIDE); //隐藏窗口
- }
- //SetSize
- void CCPhotoFTPSendDlg::OnButton5()
- {
- MyLock lock2("accessrefreshlist");
- // TODO: Add your control notification handler code here
- if(m_pathbak.IsEmpty() )
- {
- AfxMessageBox("请先选中您要清除的任务!", MB_ICONINFORMATION);
- return;
- }
- CString path=m_pathbak;
- if(AfxMessageBox("是否清除"+m_clientinfo+"上传任务?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
- BOOL bSave=0;
- {
- MyLock lock("accesslist1array");
- for(int i=0; i<m_List1array.GetSize (); i++)
- {
- if(path==m_List1array.ElementAt (i).ElementAt (6) && "上传完毕"==m_List1array.ElementAt(i).ElementAt(4))
- {
- ::DeleteFile (path);
- m_List1array.RemoveAt(i);
- m_List1.DeleteItem (i);
- bSave=1;
- break;
- }
- }
- }
- if(bSave)
- {
- SaveTask();
- }
- }
- void CCPhotoFTPSendDlg::OnButton6()
- {
- MyLock lock2("accessrefreshlist");
- // TODO: Add your control notification handler code here
- CString path;
- if(AfxMessageBox("是否清除全部已传完的记录?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
- {
- MyLock lock("accesslist1array");
- for(int i=m_List1array.GetSize ()-1; i>=0; i--)
- {
- path=m_List1array.ElementAt(i).ElementAt(6);
- if("上传完毕"==m_List1array.ElementAt(i).ElementAt(4))
- {
- ::DeleteFile (path);
- m_List1array.RemoveAt(i);
- m_List1.DeleteItem (i);
- }
- }
- }
- SaveTask();
- }
- void CCPhotoFTPSendDlg::OnButton7()
- {
- // TODO: Add your control notification handler code here
- SetDlg dlg;
- dlg.DoModal ();
- }
- CString CCPhotoFTPSendDlg::GetModifyDate(CString path)
- {
- HANDLE hFile;
- WIN32_FIND_DATA wfd;
- SYSTEMTIME systime;
- FILETIME localtime;
- CString stime; //输出时间
- memset(&wfd, 0, sizeof(wfd));
- if((hFile=FindFirstFile(path, &wfd))==INVALID_HANDLE_VALUE)
- return "";
- //ok,转换时间
- // FileTimeToLocalFileTime(&wfd.ftLastWriteTime,&localtime);
- FileTimeToLocalFileTime(&wfd.ftCreationTime,&localtime);
- FileTimeToSystemTime(&localtime,&systime);
- stime.Format("%4d-%02d-%02d",systime.wYear,systime.wMonth,systime.wDay);
- return stime;
- }
- //g_wmClose2
- BOOL CCPhotoFTPSendDlg::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: Add your specialized code here and/or call the base class
- if(pMsg->message==WM_KEYDOWN)
- {
- switch (pMsg->wParam)
- {
- case VK_F2:
- if(AfxMessageBox("全盘扫描任务需要较长时间,是否继续?", MB_YESNO|MB_ICONSTOP)!=IDYES)return 1;
- g_bOldSaveType=1;
- return 1;
- }
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- //连接超时
|