filetrans.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "filetrans.h"
  2. #include "wsnumchk.h"
  3. #include "filesplitter.h"
  4. #include "resppacktran.h"
  5. #include "resppackmerge.h"
  6. #include "respsubminpnum.h"
  7. FileTrans::FileTrans(QString fileName, QString fileType, QString submitWay, QString memo, QString host, QString port, QString userHash)
  8. {
  9. this->fileName = fileName;
  10. this->fileType = fileType;
  11. this->submitWay = submitWay;
  12. this->memo = memo;
  13. this->host = host;
  14. this->port = port;
  15. this->userHash = userHash;
  16. }
  17. void FileTrans::run()
  18. {
  19. FileSplitter splitter(fileName);
  20. QStringList list = splitter.getSplitResult();
  21. WSNumChk numchk(this->host,this->port);
  22. bool allupload = true;
  23. QString packName;
  24. for(int i=0;i<list.size();i++)
  25. {
  26. packName = list.at(i);
  27. QString json = numchk.PackTran(packName,this->userHash);
  28. RespPackTran response(json);
  29. if(response.getRtnCode()==1)
  30. {
  31. QFile::remove(packName);
  32. }
  33. else
  34. {
  35. allupload = false;
  36. qDebug()<<response.getRtnMemo();
  37. }
  38. }
  39. bool succeed = false;
  40. if(allupload)
  41. {
  42. QString json = numchk.PackMerge(packName,this->userHash);
  43. RespPackMerge response(json);
  44. if(response.getRtnCode()==1)
  45. {
  46. QFileInfo fileinfo(fileName);
  47. json = numchk.submitPnumFile(fileinfo.fileName(),response.getFileHash(),fileType,submitWay,memo,userHash);
  48. RespSubminPNum resp(json);
  49. if(resp.getRtnCode()>0)
  50. {
  51. succeed = true;
  52. splitter.cleanup();
  53. }
  54. }
  55. }
  56. }