Feature: add menu-driven compress/extract via custom file+folder picker
This commit is contained in:
@@ -637,7 +637,8 @@ CMy2015RemoteDlg::CMy2015RemoteDlg(CWnd* pParent): CDialogLangEx(CMy2015RemoteDl
|
||||
m_bmOnline[52].LoadBitmap(IDB_BITMAP_WEBDESKTOP);
|
||||
m_bmOnline[53].LoadBitmap(IDB_BITMAP_PLUGINCONFIG);
|
||||
m_bmOnline[54].LoadBitmap(IDB_BITMAP_SNAPSHOT); // "播放快照" 菜单的眼睛图标
|
||||
|
||||
m_bmOnline[55].LoadBitmap(IDB_BITMAP_COMPRESS);
|
||||
m_bmOnline[56].LoadBitmap(IDB_BITMAP_UNCOMPRESS);
|
||||
for (int i = 0; i < PAYLOAD_MAXTYPE; i++) {
|
||||
m_ServerDLL[i] = nullptr;
|
||||
m_ServerBin[i] = nullptr;
|
||||
@@ -919,6 +920,8 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx)
|
||||
ON_COMMAND(ID_WEB_REMOTE_CONTROL, &CMy2015RemoteDlg::OnWebRemoteControl)
|
||||
ON_COMMAND(ID_PROXY_PORT_AUTORUN, &CMy2015RemoteDlg::OnProxyPortAutorun)
|
||||
ON_COMMAND(ID_SCREENPREVIEW_LOOP, &CMy2015RemoteDlg::OnScreenpreviewLoop)
|
||||
ON_COMMAND(ID_MENU_COMPRESS, &CMy2015RemoteDlg::OnMenuCompress)
|
||||
ON_COMMAND(ID_MENU_UNCOMPRESS, &CMy2015RemoteDlg::OnMenuUncompress)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
@@ -989,6 +992,8 @@ VOID CMy2015RemoteDlg::CreateSolidMenu()
|
||||
m_MainMenu.SetMenuItemBitmaps(ID_MAIN_NETWORK, MF_BYCOMMAND, &m_bmOnline[29], &m_bmOnline[29]);
|
||||
m_MainMenu.SetMenuItemBitmaps(ID_TRIGGER_SETTINGS, MF_BYCOMMAND, &m_bmOnline[51], &m_bmOnline[51]);
|
||||
m_MainMenu.SetMenuItemBitmaps(ID_MAIN_EXIT, MF_BYCOMMAND, &m_bmOnline[26], &m_bmOnline[26]);
|
||||
m_MainMenu.SetMenuItemBitmaps(ID_MENU_COMPRESS, MF_BYCOMMAND, &m_bmOnline[55], &m_bmOnline[55]);
|
||||
m_MainMenu.SetMenuItemBitmaps(ID_MENU_UNCOMPRESS, MF_BYCOMMAND, &m_bmOnline[56], &m_bmOnline[56]);
|
||||
// Tools menu
|
||||
m_MainMenu.SetMenuItemBitmaps(ID_TOOL_INPUT_PASSWORD, MF_BYCOMMAND, &m_bmOnline[30], &m_bmOnline[30]);
|
||||
m_MainMenu.SetMenuItemBitmaps(ID_TOOL_IMPORT_LICENSE, MF_BYCOMMAND, &m_bmOnline[31], &m_bmOnline[31]);
|
||||
@@ -10915,3 +10920,112 @@ void CMy2015RemoteDlg::OnScreenpreviewLoop()
|
||||
ShowMessage(_TR("提示"), msg);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== ZSTA 压缩 / 解压 =====
|
||||
#include "ZstdArchive.h"
|
||||
#include "ZstaPickerDlg.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// 把一组源路径压缩为单个 .zsta 文件(弹出保存对话框选择输出)
|
||||
// 调用者只负责传路径,输出路径与压缩过程由本函数处理
|
||||
void CompressPathsToZsta(CWnd* parent, const std::vector<std::string>& srcPaths)
|
||||
{
|
||||
if (srcPaths.empty()) return;
|
||||
|
||||
// 默认输出文件名:第一个源的 basename 或 archive
|
||||
std::string defaultName;
|
||||
{
|
||||
std::string first = srcPaths[0];
|
||||
while (!first.empty() && (first.back() == '/' || first.back() == '\\'))
|
||||
first.pop_back();
|
||||
size_t pos = first.find_last_of("/\\");
|
||||
defaultName = (pos == std::string::npos) ? first : first.substr(pos + 1);
|
||||
if (srcPaths.size() > 1) defaultName = "archive";
|
||||
defaultName += ".zsta";
|
||||
}
|
||||
|
||||
CFileDialog saveDlg(FALSE, _T("zsta"), CString(defaultName.c_str()),
|
||||
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
|
||||
_T("ZSTA Files (*.zsta)|*.zsta|All Files (*.*)|*.*||"),
|
||||
parent);
|
||||
CString saveTitle = _TR("选择压缩输出文件");
|
||||
saveDlg.m_ofn.lpstrTitle = saveTitle;
|
||||
if (saveDlg.DoModal() != IDOK) return;
|
||||
|
||||
std::string outPath = std::string(CT2A(saveDlg.GetPathName().GetString()));
|
||||
auto err = zsta::CZstdArchive::Compress(srcPaths, outPath, 3);
|
||||
if (err == zsta::Error::Success) {
|
||||
Mprintf("ZSTA 压缩成功: %u 项 -> %s\n",
|
||||
(unsigned)srcPaths.size(), outPath.c_str());
|
||||
CString msg;
|
||||
msg.FormatL("压缩成功 (%u 项):\n%s",
|
||||
(unsigned)srcPaths.size(), outPath.c_str());
|
||||
parent->MessageBox(msg, _TR("提示"), MB_OK | MB_ICONINFORMATION);
|
||||
} else {
|
||||
Mprintf("ZSTA 压缩失败 [%s]: -> %s\n",
|
||||
zsta::CZstdArchive::GetErrorString(err), outPath.c_str());
|
||||
CString msg;
|
||||
msg.FormatL("压缩失败: %s", zsta::CZstdArchive::GetErrorString(err));
|
||||
parent->MessageBox(msg, _TR("错误"), MB_OK | MB_ICONERROR);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void CMy2015RemoteDlg::OnMenuCompress()
|
||||
{
|
||||
CZstaPickerDlg picker(this);
|
||||
if (picker.DoModal() != IDOK) return;
|
||||
if (picker.m_Paths.empty()) {
|
||||
MessageBoxL("未选择任何文件或文件夹", "提示", MB_OK | MB_ICONINFORMATION);
|
||||
return;
|
||||
}
|
||||
CompressPathsToZsta(this, picker.m_Paths);
|
||||
}
|
||||
|
||||
void CMy2015RemoteDlg::OnMenuUncompress()
|
||||
{
|
||||
const DWORD MAX_BUF = 64 * 1024;
|
||||
std::vector<TCHAR> buf(MAX_BUF, 0);
|
||||
CFileDialog dlg(TRUE, _T("zsta"), NULL,
|
||||
OFN_ALLOWMULTISELECT | OFN_EXPLORER |
|
||||
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST,
|
||||
_T("ZSTA Files (*.zsta)|*.zsta|All Files (*.*)|*.*||"), this);
|
||||
dlg.m_ofn.lpstrFile = buf.data();
|
||||
dlg.m_ofn.nMaxFile = MAX_BUF;
|
||||
CString title = _TR("请选择要解压的 ZSTA 文件 (可多选)");
|
||||
dlg.m_ofn.lpstrTitle = title;
|
||||
if (dlg.DoModal() != IDOK) return;
|
||||
|
||||
int ok = 0, fail = 0;
|
||||
POSITION pos = dlg.GetStartPosition();
|
||||
while (pos) {
|
||||
CString cpath = dlg.GetNextPathName(pos);
|
||||
std::string src(CT2A(cpath.GetString()));
|
||||
|
||||
// 目标目录:去掉 .zsta 后缀;若无该后缀则追加 _extract
|
||||
std::string dst;
|
||||
if (src.size() >= 5) {
|
||||
std::string ext = src.substr(src.size() - 5);
|
||||
for (char& c : ext) c = (char)tolower((unsigned char)c);
|
||||
if (ext == ".zsta") dst = src.substr(0, src.size() - 5);
|
||||
}
|
||||
if (dst.empty()) dst = src + "_extract";
|
||||
|
||||
auto err = zsta::CZstdArchive::Extract(src, dst);
|
||||
if (err == zsta::Error::Success) {
|
||||
++ok;
|
||||
Mprintf("ZSTA 解压成功: %s -> %s\n", src.c_str(), dst.c_str());
|
||||
} else {
|
||||
++fail;
|
||||
Mprintf("ZSTA 解压失败 [%s]: %s\n",
|
||||
zsta::CZstdArchive::GetErrorString(err), src.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
CString msg;
|
||||
msg.FormatL("解压完成: 成功 %d, 失败 %d", ok, fail);
|
||||
MessageBox(msg, _TR("提示"),
|
||||
MB_OK | (fail > 0 ? MB_ICONWARNING : MB_ICONINFORMATION));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user