// ReleaseProjDlg.cpp : 实现文件
//
#include "pch.h"
#include "ProjOnlineRelease.h"
#include "ReleaseProjDlg.h"
#include "afxdialogex.h"
#include "Lib_Global.h"
#include "SetReleaseStatusDlg.h"
#include "ResourceSwitch.h"
volatile UINT g_nFileCount = 0;
volatile UINT g_nOkCount = 0;
volatile ULONGLONG g_nBeginTime = 0;
std::string g_sUploadFileUrl = "http://hc.gongge.com.cn:8091/api/file/uploadFiles";
std::string g_sAccess_token = "access_token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0aW1lU3RhbXAiOjE2NDQ5MDE2MTA2MjcsImdJZCI6IjY3NDQ4MDk0OTMxOTAwNzA1OTgifQ._dzEiGA9IZTAtYsMRNgJx6SzupAEVCZ10VWgKexibDA";
std::string g_sUploadPartFileUrl = "http://hc.gongge.com.cn:8091/api/file/uploadBigFile";
std::string g_sProjId = "1526aedf-10d9-406e-acc9-bd9195c3b367";
std::string g_sProjDir;
volatile bool g_bBeginUpload = false;
volatile bool g_bEndUploadFile = false;
volatile bool g_bEndUploadMdsFile = false;
volatile bool g_bEndUploadPartFile = false;
volatile bool g_bExitUpload = false;
HANDLE g_hMutex; // 线程互斥
//#define THRED_NUM 5
DWORD WINAPI UploadFileFunc(LPVOID lpParam)
{
threadInfo* pInfo = (threadInfo*)lpParam;
int nCodeNum = pInfo->nCodeNum;
std::vector<vecFilesInfo>& vecInfo = pInfo->vecInfo;
for (auto iterFileGroup = vecInfo.begin(); iterFileGroup != vecInfo.end(); ++iterFileGroup)
{
if (g_bExitUpload)
{
break;
}
std::vector<FileInfo>& vecFileInfo = *iterFileGroup;
int nStatus = -1;
if (!CUploadUtils::CurlPostUploadFile(g_sUploadFileUrl.c_str(),g_sAccess_token.c_str(),g_sProjId.c_str(),false,vecFileInfo,nStatus))
{
CString sError;
sError.Format(_T("ZLY::小文件组上传失败,dStatusCode= %d!"),(int)nStatus);
OutputDebugString(sError);
// 更新进度条
WaitForSingleObject(g_hMutex, INFINITE);
g_nOkCount += (int)vecFileInfo.size();
ULONGLONG dCurrentTime = GetTickCount64();
double dTime = ((double)(dCurrentTime - g_nBeginTime))/1000;
CString sTip;
sTip.Format(_T("当前处理完成个数 %d / %d,耗时 %.3f 秒,剩余 %d 个!"),g_nOkCount,g_nFileCount,dTime,g_nFileCount-g_nOkCount);
if (pInfo->ctrlTip)
pInfo->ctrlTip->SetWindowText(sTip);
if (pInfo->pctrlProgress)
pInfo->pctrlProgress->SetPos(g_nOkCount);
ReleaseMutex(g_hMutex);
continue;
}
// 更新进度条
WaitForSingleObject(g_hMutex, INFINITE);
g_nOkCount += (int)vecFileInfo.size();
ULONGLONG dCurrentTime = GetTickCount64();
double dTime = ((double)(dCurrentTime - g_nBeginTime))/1000;
CString sTip;
sTip.Format(_T("当前上传文件完成个数 %d / %d,耗时 %.3f 秒,剩余 %d 个!"),g_nOkCount,g_nFileCount,dTime,g_nFileCount-g_nOkCount);
if (pInfo->ctrlTip)
pInfo->ctrlTip->SetWindowText(sTip);
if (pInfo->pctrlProgress)
pInfo->pctrlProgress->SetPos(g_nOkCount);
ReleaseMutex(g_hMutex);
}
if (g_nOkCount == g_nFileCount)
{
g_bEndUploadFile = true;
}
return 0;
}
DWORD WINAPI CompressUploadFunc(LPVOID lpParam)
{
threadInfo* pInfo = (threadInfo*)lpParam;
int nCodeNum = pInfo->nCodeNum;
std::vector<vecFilesInfo>& vecInfo = pInfo->vecInfo;
for (auto iterFileGroup = vecInfo.begin(); iterFileGroup != vecInfo.end(); ++iterFileGroup)
{
if (g_bExitUpload)
{
break;
}
// 压缩文件
std::vector<FileInfo> vecFileInfo;
vecFileInfo.clear();
std::vector<FileInfo>& vecFileInfoTemp = *iterFileGroup;
for (auto itorTemp = vecFileInfoTemp.begin(); itorTemp != vecFileInfoTemp.end(); itorTemp++)
{
if (g_bExitUpload)
{
return -1;
}
wstring wsFolder = itorTemp->strFilePath;
string sFolder = CUploadUtils::wstring2string(wsFolder);
CString strFolder = sFolder.c_str();
CString strFolderZip = strFolder + _T(".zip");
CString sMsg;
sMsg.Format(_T("ZLY:当前正在压缩处理文件夹名称= %s!"),strFolder);
OutputDebugString(sMsg);
// 文件压缩
CString strError;
if (!CUploadUtils::ZipPackage(strFolder,strFolderZip,strError))
{
CString sTip;
sTip.Format(_T("当前文件压缩出现错误,文件名称= !"),strFolder);
if (pInfo->ctrlTip)
pInfo->ctrlTip->SetWindowText(sTip);
sMsg.Format(_T("ZLY:文件压缩出现错误,文件名称= %s!"),strFolder);
OutputDebugString(sMsg);
continue;
}
FileInfo stufileTemp;
string sTemp = strFolderZip;
stufileTemp.strFilePath = CUploadUtils::string2wstring(sTemp);
stufileTemp.strFileDir = itorTemp->strFileDir;
vecFileInfo.push_back(stufileTemp);
}
Sleep(200);
// 文件上传
int nStatus = -1;
if (!CUploadUtils::CurlPostUploadFile(g_sUploadFileUrl.c_str(),g_sAccess_token.c_str(),g_sProjId.c_str(),true,vecFileInfo,nStatus))
{
CString sError;
sError.Format(_T("ZLY::压缩文件组上传失败,dStatusCode= %d!"),(int)nStatus);
OutputDebugString(sError);
// 更新进度条
WaitForSingleObject(g_hMutex, INFINITE);
g_nOkCount += (int)vecFileInfoTemp.size();
ULONGLONG dCurrentTime = GetTickCount64();
double dTime = ((double)(dCurrentTime - g_nBeginTime))/1000;
CString sTip;
sTip.Format(_T("当前处理完成个数 %d / %d,耗时 %.3f 秒,剩余 %d 个!"),g_nOkCount,g_nFileCount,dTime,g_nFileCount-g_nOkCount);
if (pInfo->ctrlTip)
pInfo->ctrlTip->SetWindowText(sTip);
if (pInfo->pctrlProgress)
pInfo->pctrlProgress->SetPos(g_nOkCount);
ReleaseMutex(g_hMutex);
// 删除压缩包
for (auto itorTemp = vecFileInfo.begin(); itorTemp != vecFileInfo.end(); itorTemp++)
{
wstring wsFolder = itorTemp->strFilePath;
string sFolder = CUploadUtils::wstring2string(wsFolder);
CString strFolderZip = sFolder.c_str();
::DeleteFile(strFolderZip);
}
continue;
}
//Sleep(1000);
// 更新进度条
WaitForSingleObject(g_hMutex, INFINITE);
g_nOkCount += (int)vecFileInfoTemp.size();
ULONGLONG dCurrentTime = GetTickCount64();
double dTime = ((double)(dCurrentTime - g_nBeginTime))/1000;
CString sTip;
sTip.Format(_T("当前上传完成个数 %d / %d,耗时 %.3f 秒,剩余 %d 个!"),g_nOkCount,g_nFileCount,dTime,g_nFileCount-g_nOkCount);
if (pInfo->ctrlTip)
{
pInfo->ctrlTip->SetWindowText(sTip);
}
if (pInfo->pctrlProgress)
pInfo->pctrlProgress->SetPos(g_nOkCount);
ReleaseMutex(g_hMutex);
// 删除压缩包
for (auto itorTemp = vecFileInfo.begin(); itorTemp != vecFileInfo.end(); itorTemp++)
{
wstring wsFolder = itorTemp->strFilePath;
string sFolder = CUploadUtils::wstring2string(wsFolder);
CString strFolderZip = sFolder.c_str();
::DeleteFile(strFolderZip);
}
}
if (g_nOkCount == g_nFileCount)
{
g_bEndUploadMdsFile = true;
}
return 0;
}
DWORD WINAPI UploadPartFileFunc(LPVOID lpParam)
{
threadPartInfo* pInfo = (threadPartInfo*)lpParam;
for (int i = 0; i < pInfo->vecFileName.size(); ++i)
{
if (g_bExitUpload)
{
break;
}
string sFileName = pInfo->vecFileName[i];
wstring wsFileName;
CString sTip;
sTip.Format(_T("正在上传大文件: 当前完成 %d / %d个,剩余 %d 个!"),g_nOkCount,g_nFileCount,g_nFileCount-g_nOkCount);
pInfo->ctrlUpTip->SetWindowText(sTip);
CString strDirPath;
CString strPath = sFileName.c_str();
CString strProjDir = g_sProjDir.c_str();
int nIndex = strPath.Find(strProjDir);
if (nIndex != -1)
{
strDirPath = strPath.Mid(nIndex + strProjDir.GetLength()+1, strPath.GetLength() - nIndex - strProjDir.GetLength()-1);
std::string sSubPath = strDirPath;
wsFileName = CUploadUtils::string2wstring(sSubPath);
}
CString strFileName = sFileName.c_str();
int nPos = strFileName.ReverseFind('\\');
if (nPos > -1)
{
strFileName = strFileName.Mid(nPos+1);
}
if (strFileName.GetLength() > 30)
{
strFileName = strFileName.Mid(strFileName.GetLength()-30,30);
}
sTip.Format(_T("正在对大文件 %s进行分片..."),strFileName);
pInfo->ctrlDownTip->SetWindowText(sTip);
// 拆分文件并上传
std::vector<partFileInfo> vecPartFileInfo;
int nShareCount
没有合适的资源?快使用搜索试试~ 我知道了~
上传数据至服务端:MFC多线程、文件压缩、上传数据、进度条
共59个文件
h:18个
cpp:16个
png:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 162 浏览量
2023-02-10
09:36:30
上传
评论
收藏 186KB ZIP 举报
温馨提示
上传数据至服务端:MFC多线程、文件压缩、上传数据、进度条
资源推荐
资源详情
资源评论
收起资源包目录
UploadDataToCloud.zip (59个子文件)
ReleaseProjectOnline
FileMiniZip.cpp 11KB
UploadUtils.h 5KB
Myprogressctrl.cpp 4KB
ReleaseProjDlg.cpp 39KB
ReleaseProjectOnline.vcxproj 14KB
ReleaseProjectOnlineAPI.cpp 1KB
Lib_Global.cpp 27KB
Listener.h 702B
ReleaseProjectOnline.cpp 2KB
PngButton.cpp 2KB
ProjOnlineRelease.cpp 32KB
framework.h 1KB
ResourceSwitch.h 444B
ReleaseProjectOnline.props 944B
UploadUtils.cpp 27KB
res
wait3.ico 766B
wait4.ico 766B
关闭.png 167B
msgbar.png 710B
wait2.ico 766B
yhm2.png 2KB
wait6.ico 766B
mm2.png 2KB
ReleaseProjectOnline.rc2 696B
wait7.ico 766B
mm1.png 2KB
wait1.ico 766B
wait5.ico 766B
bj.png 37KB
按钮.png 4KB
yhm1.png 2KB
Lib_Global.h 8KB
SetReleaseStatusDlg.cpp 6KB
Resource.h 6KB
ReleaseProjectOnline.rc 18KB
pch.h 1KB
ProjOnlineRelease.h 6KB
ReleaseProjectOnline.vcxproj.filters 6KB
ReleaseProjectOnline.h 512B
ResourceSwitch.cpp 395B
DlgLoginPubServer.h 2KB
ReleaseProjectOnline.sln 1KB
SetReleaseStatusDlg.h 825B
Myprogressctrl.h 617B
DlgLoginPubServer.cpp 18KB
Listener.cpp 7KB
pch.cpp 198B
ReleaseProjectOnline.vcxproj.user 165B
PngButton.h 814B
ReleaseProjDlg.h 3KB
ReleaseProjectOnline.aps 84KB
DownloadTasks.cpp 10KB
DownloadTasks.h 1KB
ThreadWaitDlg.h 1KB
ThreadWaitDlg.cpp 4KB
FileMiniZip.h 3KB
~AutoRecover.ReleaseProjectOnline.vcxproj 14KB
ReleaseProjectOnline.def 163B
targetver.h 295B
共 59 条
- 1
资源评论
欧特克_Glodon
- 粉丝: 4w+
- 资源: 64
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功