mirror of
https://github.com/ONLYOFFICE/desktop-apps.git
synced 2026-04-07 14:09:22 +08:00
Merge pull request #1103 from ONLYOFFICE/feature/progress_unzipping_updates
Add feature: progress unzipping updates
This commit is contained in:
@ -66,6 +66,7 @@ enum MsgCommands {
|
|||||||
MSG_StartReplacingFiles,
|
MSG_StartReplacingFiles,
|
||||||
MSG_ClearTempFiles,
|
MSG_ClearTempFiles,
|
||||||
MSG_Progress,
|
MSG_Progress,
|
||||||
|
MSG_UnzipProgress,
|
||||||
MSG_StopDownload,
|
MSG_StopDownload,
|
||||||
MSG_OtherError,
|
MSG_OtherError,
|
||||||
MSG_SetLanguage,
|
MSG_SetLanguage,
|
||||||
|
|||||||
@ -224,6 +224,9 @@ void CSvcManager::init()
|
|||||||
m_pUnzip->onComplete([=](int error) {
|
m_pUnzip->onComplete([=](int error) {
|
||||||
onCompleteUnzip(error);
|
onCompleteUnzip(error);
|
||||||
});
|
});
|
||||||
|
m_pUnzip->onProgress([=](int percent) {
|
||||||
|
m_socket->sendMessage(MSG_UnzipProgress, to_tstring(percent));
|
||||||
|
});
|
||||||
m_socket->onMessageReceived([=](void *data, size_t) {
|
m_socket->onMessageReceived([=](void *data, size_t) {
|
||||||
vector<tstring> params;
|
vector<tstring> params;
|
||||||
if (m_socket->parseMessage(data, params) == 3) {
|
if (m_socket->parseMessage(data, params) == 3) {
|
||||||
|
|||||||
@ -34,101 +34,135 @@
|
|||||||
#include "platform_linux/utils.h"
|
#include "platform_linux/utils.h"
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
#include <archive_entry.h>
|
#include <archive_entry.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#define BLOCK_SIZE 10240
|
#define BLOCK_SIZE 10240
|
||||||
|
|
||||||
|
|
||||||
int unzipArchive(const string &zipFilePath, const string &folderPath, std::atomic_bool &run, string &error)
|
class CUnzip::CUnzipPrivate
|
||||||
{
|
{
|
||||||
if (!NS_File::fileExists(zipFilePath) || !NS_File::dirExists(folderPath)) {
|
public:
|
||||||
error = "Archive path is empty or dest dir not exist";
|
CUnzipPrivate()
|
||||||
return UNZIP_ERROR;
|
{}
|
||||||
}
|
~CUnzipPrivate()
|
||||||
|
{}
|
||||||
|
|
||||||
struct archive *arch = archive_read_new();
|
int unzipArchive(const string &zipFilePath, const string &folderPath, string &error)
|
||||||
archive_read_support_filter_xz(arch);
|
{
|
||||||
archive_read_support_format_tar(arch);
|
if (!NS_File::fileExists(zipFilePath) || !NS_File::dirExists(folderPath)) {
|
||||||
if (archive_read_open_filename(arch, zipFilePath.c_str(), BLOCK_SIZE) != ARCHIVE_OK) {
|
error = "Archive path is empty or dest dir not exist";
|
||||||
error = "Cannot open archive";
|
return UNZIP_ERROR;
|
||||||
archive_read_free(arch);
|
}
|
||||||
return UNZIP_ERROR;
|
int prev_percent = -1;
|
||||||
}
|
struct stat file_stat;
|
||||||
|
long total_size = (stat(zipFilePath.c_str(), &file_stat) == 0) ? file_stat.st_size : 0;
|
||||||
|
|
||||||
int res = ARCHIVE_OK;
|
struct archive *arch = archive_read_new();
|
||||||
int ex_code = UNZIP_OK;
|
archive_read_support_filter_xz(arch);
|
||||||
struct archive_entry *entry;
|
archive_read_support_format_tar(arch);
|
||||||
while ((res = archive_read_next_header(arch, &entry)) == ARCHIVE_OK) {
|
if (archive_read_open_filename(arch, zipFilePath.c_str(), BLOCK_SIZE) != ARCHIVE_OK) {
|
||||||
if (!run) {
|
error = "Cannot open archive";
|
||||||
ex_code = UNZIP_ABORT;
|
archive_read_free(arch);
|
||||||
break;
|
return UNZIP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *entryname = archive_entry_pathname(entry);
|
int res = ARCHIVE_OK;
|
||||||
if (!entryname) {
|
int ex_code = UNZIP_OK;
|
||||||
error = "Invalid entry name";
|
struct archive_entry *entry;
|
||||||
break;
|
while ((res = archive_read_next_header(arch, &entry)) == ARCHIVE_OK) {
|
||||||
}
|
if (!run) {
|
||||||
|
ex_code = UNZIP_ABORT;
|
||||||
char outpath[1024] = {0};
|
|
||||||
snprintf(outpath, sizeof(outpath), "%s/%s", folderPath.c_str(), entryname);
|
|
||||||
|
|
||||||
if (archive_entry_filetype(entry) == AE_IFREG) {
|
|
||||||
archive_entry_set_pathname(entry, outpath);
|
|
||||||
res = archive_read_extract(arch, entry, ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM
|
|
||||||
| ARCHIVE_EXTRACT_ACL | ARCHIVE_EXTRACT_FFLAGS
|
|
||||||
| ARCHIVE_EXTRACT_NO_OVERWRITE);
|
|
||||||
if (res != ARCHIVE_OK) {
|
|
||||||
error = "Cannot extract entry";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *entryname = archive_entry_pathname(entry);
|
||||||
|
if (!entryname) {
|
||||||
|
error = "Invalid entry name";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
char outpath[1024] = {0};
|
||||||
|
snprintf(outpath, sizeof(outpath), "%s/%s", folderPath.c_str(), entryname);
|
||||||
|
|
||||||
|
if (archive_entry_filetype(entry) == AE_IFREG) {
|
||||||
|
archive_entry_set_pathname(entry, outpath);
|
||||||
|
res = archive_read_extract(arch, entry, ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM
|
||||||
|
| ARCHIVE_EXTRACT_ACL | ARCHIVE_EXTRACT_FFLAGS
|
||||||
|
| ARCHIVE_EXTRACT_NO_OVERWRITE);
|
||||||
|
if (res != ARCHIVE_OK) {
|
||||||
|
error = "Cannot extract entry";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (total_size > 0 && progress_callback) {
|
||||||
|
int percent = static_cast<int>(100.0 * ((double)archive_filter_bytes(arch, -1)/total_size));
|
||||||
|
if (percent != prev_percent) {
|
||||||
|
progress_callback(percent);
|
||||||
|
prev_percent = percent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (res != ARCHIVE_EOF && ex_code != UNZIP_ABORT) {
|
||||||
|
error = string("Error reading archive: ") + archive_error_string(arch);
|
||||||
|
ex_code = UNZIP_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
archive_read_close(arch);
|
||||||
|
archive_read_free(arch);
|
||||||
|
return ex_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res != ARCHIVE_EOF && ex_code != UNZIP_ABORT) {
|
FnVoidInt complete_callback = nullptr,
|
||||||
error = string("Error reading archive: ") + archive_error_string(arch);
|
progress_callback = nullptr;
|
||||||
ex_code = UNZIP_ERROR;
|
std::atomic_bool run;
|
||||||
}
|
std::future<void> future;
|
||||||
|
};
|
||||||
|
|
||||||
archive_read_close(arch);
|
|
||||||
archive_read_free(arch);
|
|
||||||
return ex_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
CUnzip::CUnzip()
|
|
||||||
|
CUnzip::CUnzip() :
|
||||||
|
pimpl(new CUnzipPrivate)
|
||||||
{
|
{
|
||||||
m_run = false;
|
pimpl->run = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUnzip::~CUnzip()
|
CUnzip::~CUnzip()
|
||||||
{
|
{
|
||||||
m_run = false;
|
pimpl->run = false;
|
||||||
if (m_future.valid())
|
if (pimpl->future.valid())
|
||||||
m_future.wait();
|
pimpl->future.wait();
|
||||||
|
delete pimpl, pimpl = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnzip::extractArchive(const string &zipFilePath, const string &folderPath)
|
void CUnzip::extractArchive(const string &zipFilePath, const string &folderPath)
|
||||||
{
|
{
|
||||||
m_run = false;
|
pimpl->run = false;
|
||||||
if (m_future.valid())
|
if (pimpl->future.valid())
|
||||||
m_future.wait();
|
pimpl->future.wait();
|
||||||
m_run = true;
|
pimpl->run = true;
|
||||||
m_future = std::async(std::launch::async, [=]() {
|
pimpl->future = std::async(std::launch::async, [=]() {
|
||||||
string error;
|
string error;
|
||||||
int res = unzipArchive(zipFilePath, folderPath, m_run, error);
|
int res = pimpl->unzipArchive(zipFilePath, folderPath, error);
|
||||||
if (!error.empty())
|
if (!error.empty())
|
||||||
fprintf(stderr, "%s", error.c_str());
|
fprintf(stderr, "%s", error.c_str());
|
||||||
if (m_complete_callback)
|
if (pimpl->complete_callback)
|
||||||
m_complete_callback(res);
|
pimpl->complete_callback(res);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnzip::stop()
|
void CUnzip::stop()
|
||||||
{
|
{
|
||||||
m_run = false;
|
pimpl->run = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnzip::onComplete(FnVoidInt callback)
|
void CUnzip::onComplete(FnVoidInt callback)
|
||||||
{
|
{
|
||||||
m_complete_callback = callback;
|
pimpl->complete_callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CUnzip::onProgress(FnVoidInt callback)
|
||||||
|
{
|
||||||
|
pimpl->progress_callback = callback;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,11 +57,11 @@ public:
|
|||||||
|
|
||||||
/* callback */
|
/* callback */
|
||||||
void onComplete(FnVoidInt callback);
|
void onComplete(FnVoidInt callback);
|
||||||
|
void onProgress(FnVoidInt callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FnVoidInt m_complete_callback = nullptr;
|
class CUnzipPrivate;
|
||||||
std::atomic_bool m_run;
|
CUnzipPrivate *pimpl = nullptr;
|
||||||
std::future<void> m_future;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CUNZIP_H
|
#endif // CUNZIP_H
|
||||||
|
|||||||
@ -36,123 +36,194 @@
|
|||||||
#include <Shldisp.h>
|
#include <Shldisp.h>
|
||||||
|
|
||||||
|
|
||||||
int extractRecursively(IShellDispatch *pISD, const CComPtr<Folder> &pSrcFolder, const wstring &destFolder, std::atomic_bool &run)
|
class CUnzip::CUnzipPrivate
|
||||||
{
|
{
|
||||||
CComPtr<FolderItems> pItems;
|
public:
|
||||||
if (FAILED(pSrcFolder->Items(&pItems)))
|
CUnzipPrivate()
|
||||||
return UNZIP_ERROR;
|
{}
|
||||||
|
~CUnzipPrivate()
|
||||||
|
{}
|
||||||
|
|
||||||
long itemCount = 0;
|
bool calcFilesCountRecursively(IShellDispatch *pISD, const CComPtr<Folder> &pSrcFolder)
|
||||||
if (FAILED(pItems->get_Count(&itemCount)))
|
{
|
||||||
return UNZIP_ERROR;
|
CComPtr<FolderItems> pItems;
|
||||||
|
if (FAILED(pSrcFolder->Items(&pItems)))
|
||||||
|
return false;
|
||||||
|
|
||||||
for (int i = 0; i < itemCount; i++) {
|
long itemCount = 0;
|
||||||
if (!run)
|
if (FAILED(pItems->get_Count(&itemCount)))
|
||||||
return UNZIP_ABORT;
|
return false;
|
||||||
|
|
||||||
CComPtr<FolderItem> pItem;
|
for (int i = 0; i < itemCount; i++) {
|
||||||
if (FAILED(pItems->Item(CComVariant(i), &pItem)))
|
CComPtr<FolderItem> pItem;
|
||||||
return UNZIP_ERROR;
|
if (FAILED(pItems->Item(CComVariant(i), &pItem)))
|
||||||
|
return false;
|
||||||
|
|
||||||
VARIANT_BOOL isFolder = VARIANT_FALSE;
|
VARIANT_BOOL isFolder = VARIANT_FALSE;
|
||||||
if (FAILED(pItem->get_IsFolder(&isFolder)))
|
if (FAILED(pItem->get_IsFolder(&isFolder)))
|
||||||
return UNZIP_ERROR;
|
return false;
|
||||||
|
|
||||||
if (isFolder == VARIANT_TRUE) {
|
if (isFolder == VARIANT_TRUE) {
|
||||||
// Source path
|
CComPtr<Folder> pSubFolder;
|
||||||
CComPtr<Folder> pSubFolder;
|
if (FAILED(pISD->NameSpace(CComVariant(pItem), &pSubFolder)))
|
||||||
if (FAILED(pISD->NameSpace(CComVariant(pItem), &pSubFolder)))
|
return false;
|
||||||
return UNZIP_ERROR;
|
|
||||||
|
|
||||||
// Dest path
|
if (!calcFilesCountRecursively(pISD, pSubFolder))
|
||||||
BSTR bstrName;
|
return false;
|
||||||
if (FAILED(pItem->get_Name(&bstrName)))
|
|
||||||
return UNZIP_ERROR;
|
|
||||||
|
|
||||||
wstring targetFolder = destFolder + L"\\" + bstrName;
|
} else {
|
||||||
SysFreeString(bstrName);
|
++total_count;
|
||||||
if (CreateDirectory(targetFolder.c_str(), NULL) == 0)
|
}
|
||||||
return UNZIP_ERROR;
|
|
||||||
|
|
||||||
int res = extractRecursively(pISD, pSubFolder, targetFolder, run);
|
|
||||||
if (res != UNZIP_OK)
|
|
||||||
return res;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
CComPtr<Folder> pDestFolder;
|
|
||||||
if (FAILED(pISD->NameSpace(CComVariant(destFolder.c_str()), &pDestFolder)))
|
|
||||||
return UNZIP_ERROR;
|
|
||||||
if (FAILED(pDestFolder->CopyHere(CComVariant(pItem), CComVariant(1024 | 512 | 16 | 4))))
|
|
||||||
return UNZIP_ERROR;
|
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
return UNZIP_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int unzipArchive(const wstring &zipFilePath, const wstring &folderPath, std::atomic_bool &run)
|
|
||||||
{
|
|
||||||
if (!NS_File::fileExists(zipFilePath) || !NS_File::dirExists(folderPath))
|
|
||||||
return UNZIP_ERROR;
|
|
||||||
|
|
||||||
wstring file = NS_File::toNativeSeparators(zipFilePath);
|
|
||||||
wstring path = NS_File::toNativeSeparators(folderPath);
|
|
||||||
|
|
||||||
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
||||||
if (FAILED(hr))
|
|
||||||
return UNZIP_ERROR;
|
|
||||||
|
|
||||||
IShellDispatch *pShell = NULL;
|
|
||||||
hr = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pShell));
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
CoUninitialize();
|
|
||||||
return UNZIP_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CComPtr<Folder> pSrcFolder;
|
int extractRecursively(IShellDispatch *pISD, const CComPtr<Folder> &pSrcFolder, const wstring &destFolder)
|
||||||
if (FAILED(pShell->NameSpace(CComVariant(file.c_str()), &pSrcFolder))) {
|
{
|
||||||
|
CComPtr<FolderItems> pItems;
|
||||||
|
if (FAILED(pSrcFolder->Items(&pItems)))
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
|
||||||
|
long itemCount = 0;
|
||||||
|
if (FAILED(pItems->get_Count(&itemCount)))
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
|
||||||
|
for (int i = 0; i < itemCount; i++) {
|
||||||
|
if (!run)
|
||||||
|
return UNZIP_ABORT;
|
||||||
|
|
||||||
|
CComPtr<FolderItem> pItem;
|
||||||
|
if (FAILED(pItems->Item(CComVariant(i), &pItem)))
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
|
||||||
|
VARIANT_BOOL isFolder = VARIANT_FALSE;
|
||||||
|
if (FAILED(pItem->get_IsFolder(&isFolder)))
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
|
||||||
|
if (isFolder == VARIANT_TRUE) {
|
||||||
|
// Source path
|
||||||
|
CComPtr<Folder> pSubFolder;
|
||||||
|
if (FAILED(pISD->NameSpace(CComVariant(pItem), &pSubFolder)))
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
|
||||||
|
// Dest path
|
||||||
|
BSTR bstrName;
|
||||||
|
if (FAILED(pItem->get_Name(&bstrName)))
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
|
||||||
|
wstring targetFolder = destFolder + L"\\" + bstrName;
|
||||||
|
SysFreeString(bstrName);
|
||||||
|
if (CreateDirectory(targetFolder.c_str(), NULL) == 0)
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
|
||||||
|
int res = extractRecursively(pISD, pSubFolder, targetFolder);
|
||||||
|
if (res != UNZIP_OK)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
CComPtr<Folder> pDestFolder;
|
||||||
|
if (FAILED(pISD->NameSpace(CComVariant(destFolder.c_str()), &pDestFolder)))
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
if (FAILED(pDestFolder->CopyHere(CComVariant(pItem), CComVariant(1024 | 512 | 16 | 4))))
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
if (total_count > 0 && progress_callback) {
|
||||||
|
++curr_count;
|
||||||
|
int percent = static_cast<int>(100.0 * ((double)curr_count / total_count));
|
||||||
|
if (percent != prev_percent) {
|
||||||
|
progress_callback(percent);
|
||||||
|
prev_percent = percent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UNZIP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int unzipArchive(const wstring &zipFilePath, const wstring &folderPath)
|
||||||
|
{
|
||||||
|
if (!NS_File::fileExists(zipFilePath) || !NS_File::dirExists(folderPath))
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
|
||||||
|
wstring file = NS_File::toNativeSeparators(zipFilePath);
|
||||||
|
wstring path = NS_File::toNativeSeparators(folderPath);
|
||||||
|
|
||||||
|
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
||||||
|
if (FAILED(hr))
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
|
||||||
|
IShellDispatch *pShell = NULL;
|
||||||
|
hr = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pShell));
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
CoUninitialize();
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
CComPtr<Folder> pSrcFolder;
|
||||||
|
if (FAILED(pShell->NameSpace(CComVariant(file.c_str()), &pSrcFolder))) {
|
||||||
|
pShell->Release();
|
||||||
|
CoUninitialize();
|
||||||
|
return UNZIP_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev_percent = -1;
|
||||||
|
curr_count = 0;
|
||||||
|
total_count = 0;
|
||||||
|
if (!calcFilesCountRecursively(pShell, pSrcFolder))
|
||||||
|
total_count = 0;
|
||||||
|
int res = extractRecursively(pShell, pSrcFolder, path);
|
||||||
|
pSrcFolder.Release();
|
||||||
pShell->Release();
|
pShell->Release();
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
return UNZIP_ERROR;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int res = extractRecursively(pShell, pSrcFolder, path, run);
|
FnVoidInt complete_callback = nullptr,
|
||||||
pSrcFolder.Release();
|
progress_callback = nullptr;
|
||||||
pShell->Release();
|
std::atomic_bool run;
|
||||||
CoUninitialize();
|
std::future<void> future;
|
||||||
return res;
|
int curr_count = 0,
|
||||||
}
|
total_count = 0,
|
||||||
|
prev_percent = -1;
|
||||||
|
};
|
||||||
|
|
||||||
CUnzip::CUnzip()
|
CUnzip::CUnzip() :
|
||||||
|
pimpl(new CUnzipPrivate)
|
||||||
{
|
{
|
||||||
m_run = false;
|
pimpl->run = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUnzip::~CUnzip()
|
CUnzip::~CUnzip()
|
||||||
{
|
{
|
||||||
m_run = false;
|
pimpl->run = false;
|
||||||
if (m_future.valid())
|
if (pimpl->future.valid())
|
||||||
m_future.wait();
|
pimpl->future.wait();
|
||||||
|
delete pimpl, pimpl = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnzip::extractArchive(const wstring &zipFilePath, const wstring &folderPath)
|
void CUnzip::extractArchive(const wstring &zipFilePath, const wstring &folderPath)
|
||||||
{
|
{
|
||||||
m_run = false;
|
pimpl->run = false;
|
||||||
if (m_future.valid())
|
if (pimpl->future.valid())
|
||||||
m_future.wait();
|
pimpl->future.wait();
|
||||||
m_run = true;
|
pimpl->run = true;
|
||||||
m_future = std::async(std::launch::async, [=]() {
|
pimpl->future = std::async(std::launch::async, [=]() {
|
||||||
int res = unzipArchive(zipFilePath, folderPath, m_run);
|
int res = pimpl->unzipArchive(zipFilePath, folderPath);
|
||||||
if (m_complete_callback)
|
if (pimpl->complete_callback)
|
||||||
m_complete_callback(res);
|
pimpl->complete_callback(res);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnzip::stop()
|
void CUnzip::stop()
|
||||||
{
|
{
|
||||||
m_run = false;
|
pimpl->run = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnzip::onComplete(FnVoidInt callback)
|
void CUnzip::onComplete(FnVoidInt callback)
|
||||||
{
|
{
|
||||||
m_complete_callback = callback;
|
pimpl->complete_callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CUnzip::onProgress(FnVoidInt callback)
|
||||||
|
{
|
||||||
|
pimpl->progress_callback = callback;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,11 +57,11 @@ public:
|
|||||||
|
|
||||||
/* callback */
|
/* callback */
|
||||||
void onComplete(FnVoidInt callback);
|
void onComplete(FnVoidInt callback);
|
||||||
|
void onProgress(FnVoidInt callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FnVoidInt m_complete_callback = nullptr;
|
class CUnzipPrivate;
|
||||||
std::atomic_bool m_run;
|
CUnzipPrivate *pimpl = nullptr;
|
||||||
std::future<void> m_future;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CUNZIP_H
|
#endif // CUNZIP_H
|
||||||
|
|||||||
@ -91,6 +91,7 @@ const char *SVC_TXT_ERR_UNPACKING = QT_TRANSLATE_NOOP("CUpdateManager", "An er
|
|||||||
*TXT_AVAILABLE_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Update is available (version %1)"),
|
*TXT_AVAILABLE_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Update is available (version %1)"),
|
||||||
*TXT_DOWNLOADING_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Downloading new version %1 (%2%)"),
|
*TXT_DOWNLOADING_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Downloading new version %1 (%2%)"),
|
||||||
*TXT_PREPARING_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Preparing update..."),
|
*TXT_PREPARING_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Preparing update..."),
|
||||||
|
*TXT_UNZIP_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "Preparing update (%1%)"),
|
||||||
*TXT_RESTART_TO_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "To finish updating, restart app"),
|
*TXT_RESTART_TO_UPD = QT_TRANSLATE_NOOP("CUpdateManager", "To finish updating, restart app"),
|
||||||
*TXT_ERR_NOT_ALLOWED = QT_TRANSLATE_NOOP("CUpdateManager", "Updates are not allowed!"),
|
*TXT_ERR_NOT_ALLOWED = QT_TRANSLATE_NOOP("CUpdateManager", "Updates are not allowed!"),
|
||||||
*TXT_ERR_URL = QT_TRANSLATE_NOOP("CUpdateManager", "Unable to check update: URL not defined."),
|
*TXT_ERR_URL = QT_TRANSLATE_NOOP("CUpdateManager", "Unable to check update: URL not defined."),
|
||||||
@ -351,6 +352,10 @@ void CUpdateManager::init()
|
|||||||
QMetaObject::invokeMethod(this, "onProgressSlot", Qt::QueuedConnection, Q_ARG(int, std::stoi(params[1])));
|
QMetaObject::invokeMethod(this, "onProgressSlot", Qt::QueuedConnection, Q_ARG(int, std::stoi(params[1])));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MSG_UnzipProgress:
|
||||||
|
QMetaObject::invokeMethod(this, "onUnzipProgressSlot", Qt::QueuedConnection, Q_ARG(int, std::stoi(params[1])));
|
||||||
|
break;
|
||||||
|
|
||||||
case MSG_RequestContentLenght: {
|
case MSG_RequestContentLenght: {
|
||||||
double fileSize = std::stod(params[1])/1024/1024;
|
double fileSize = std::stod(params[1])/1024/1024;
|
||||||
m_packageData->fileSize = (fileSize == 0) ? "--" : QString::number(fileSize, 'f', 1);
|
m_packageData->fileSize = (fileSize == 0) ? "--" : QString::number(fileSize, 'f', 1);
|
||||||
@ -450,6 +455,11 @@ void CUpdateManager::onProgressSlot(const int percent)
|
|||||||
refreshStartPage({"", {TXT_DOWNLOADING_UPD, m_packageData->version, QString::number(percent)}});
|
refreshStartPage({"", {TXT_DOWNLOADING_UPD, m_packageData->version, QString::number(percent)}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CUpdateManager::onUnzipProgressSlot(const int percent)
|
||||||
|
{
|
||||||
|
refreshStartPage({"", {TXT_UNZIP_UPD, QString::number(percent)}});
|
||||||
|
}
|
||||||
|
|
||||||
void CUpdateManager::onError(const QString &error)
|
void CUpdateManager::onError(const QString &error)
|
||||||
{
|
{
|
||||||
const char *_error = SVC_TXT_ERR_OTHER;
|
const char *_error = SVC_TXT_ERR_OTHER;
|
||||||
|
|||||||
@ -141,6 +141,7 @@ private slots:
|
|||||||
void onLoadUpdateFinished(const QString &filePath);
|
void onLoadUpdateFinished(const QString &filePath);
|
||||||
void showStartInstallMessage(QWidget *parent);
|
void showStartInstallMessage(QWidget *parent);
|
||||||
void onProgressSlot(const int percent);
|
void onProgressSlot(const int percent);
|
||||||
|
void onUnzipProgressSlot(const int percent);
|
||||||
void onError(const QString &error);
|
void onError(const QString &error);
|
||||||
void criticalMsg(QWidget *parent, const QString &msg);
|
void criticalMsg(QWidget *parent, const QString &msg);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user