ENH:add mz_zip_reader_extract_to_file_w api
to solove plugin install failed problem by special wide char jira: none Change-Id: Ic7d3efe3fdf852387650abf9df65803da9e46a60 (cherry picked from commit b68ad03717a63675fef2f3ef73d4058bf311adea)
This commit is contained in:
parent
83cf11fc4b
commit
660b407742
|
@ -2987,6 +2987,14 @@ extern "C" {
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW64__)
|
#if defined(_MSC_VER) || defined(__MINGW64__)
|
||||||
|
#ifdef WIN32
|
||||||
|
static FILE *mz_wfopen(const wchar_t *pFilename, const char *pMode)
|
||||||
|
{
|
||||||
|
FILE *pFile = NULL;
|
||||||
|
_wfopen_s(&pFile, pFilename, pMode);
|
||||||
|
return pFile;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
static FILE *mz_fopen(const char *pFilename, const char *pMode)
|
static FILE *mz_fopen(const char *pFilename, const char *pMode)
|
||||||
{
|
{
|
||||||
FILE *pFile = NULL;
|
FILE *pFile = NULL;
|
||||||
|
@ -3004,6 +3012,9 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
|
||||||
#include <sys/utime.h>
|
#include <sys/utime.h>
|
||||||
#endif
|
#endif
|
||||||
#define MZ_FOPEN mz_fopen
|
#define MZ_FOPEN mz_fopen
|
||||||
|
#ifdef WIN32
|
||||||
|
#define MZ_WFOPEN mz_wfopen
|
||||||
|
#endif
|
||||||
#define MZ_FCLOSE fclose
|
#define MZ_FCLOSE fclose
|
||||||
#define MZ_FREAD fread
|
#define MZ_FREAD fread
|
||||||
#define MZ_FWRITE fwrite
|
#define MZ_FWRITE fwrite
|
||||||
|
@ -5117,9 +5128,9 @@ mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index,
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE);
|
return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE);
|
||||||
|
|
||||||
pFile = MZ_FOPEN(pDst_filename, "wb");
|
pFile = MZ_FOPEN(pDst_filename, "wb");
|
||||||
if (!pFile)
|
if (!pFile) {
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);
|
return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);
|
||||||
|
}
|
||||||
status = mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags);
|
status = mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags);
|
||||||
|
|
||||||
if (MZ_FCLOSE(pFile) == EOF)
|
if (MZ_FCLOSE(pFile) == EOF)
|
||||||
|
@ -5137,6 +5148,39 @@ mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index,
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
#ifdef WIN32
|
||||||
|
mz_bool mz_zip_reader_extract_to_file_w(mz_zip_archive *pZip, mz_uint file_index, const wchar_t *pDst_filename, mz_uint flags)
|
||||||
|
{
|
||||||
|
mz_bool status;
|
||||||
|
mz_zip_archive_file_stat file_stat;
|
||||||
|
MZ_FILE * pFile;
|
||||||
|
|
||||||
|
if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
|
||||||
|
return MZ_FALSE;
|
||||||
|
|
||||||
|
if ((file_stat.m_is_directory) || (!file_stat.m_is_supported))
|
||||||
|
return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_FEATURE);
|
||||||
|
|
||||||
|
pFile = MZ_WFOPEN(pDst_filename, "w");
|
||||||
|
if (!pFile) {
|
||||||
|
return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);
|
||||||
|
}
|
||||||
|
status = mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags);
|
||||||
|
|
||||||
|
if (MZ_FCLOSE(pFile) == EOF) {
|
||||||
|
if (status)
|
||||||
|
mz_zip_set_error(pZip, MZ_ZIP_FILE_CLOSE_FAILED);
|
||||||
|
status = MZ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_STDIO)
|
||||||
|
if (status)
|
||||||
|
mz_zip_set_file_times(pDst_filename, file_stat.m_time, file_stat.m_time);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags)
|
mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1211,6 +1211,9 @@ mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state* pState
|
||||||
/* Extracts a archive file to a disk file and sets its last accessed and modified times. */
|
/* Extracts a archive file to a disk file and sets its last accessed and modified times. */
|
||||||
/* This function only extracts files, not archive directory records. */
|
/* This function only extracts files, not archive directory records. */
|
||||||
mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
|
mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
|
||||||
|
#ifdef WIN32
|
||||||
|
mz_bool mz_zip_reader_extract_to_file_w(mz_zip_archive *pZip, mz_uint file_index, const wchar_t *pDst_filename, mz_uint flags);
|
||||||
|
#endif
|
||||||
mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
|
mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
|
||||||
|
|
||||||
/* Extracts a archive file starting at the current position in the destination FILE stream. */
|
/* Extracts a archive file starting at the current position in the destination FILE stream. */
|
||||||
|
|
|
@ -1765,14 +1765,18 @@ int GUI_App::install_plugin(std::string name, std::string package_name, InstallP
|
||||||
mz_bool res = mz_zip_reader_extract_to_file(&archive, stat.m_file_index, dest_zip_file.c_str(), 0);
|
mz_bool res = mz_zip_reader_extract_to_file(&archive, stat.m_file_index, dest_zip_file.c_str(), 0);
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", extract %1% from plugin zip %2%\n") % dest_file % stat.m_filename;
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", extract %1% from plugin zip %2%\n") % dest_file % stat.m_filename;
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
|
#ifdef WIN32
|
||||||
|
std::wstring new_dest_zip_file = boost::locale::conv::utf_to_utf<wchar_t>(dest_path.generic_string());
|
||||||
|
res = mz_zip_reader_extract_to_file_w(&archive, stat.m_file_index, new_dest_zip_file.c_str(), 0);
|
||||||
|
#endif
|
||||||
|
if (res == 0) {
|
||||||
mz_zip_error zip_error = mz_zip_get_last_error(&archive);
|
mz_zip_error zip_error = mz_zip_get_last_error(&archive);
|
||||||
BOOST_LOG_TRIVIAL(error) << "[install_plugin]Archive read error:" << mz_zip_get_error_string(zip_error) << std::endl;
|
BOOST_LOG_TRIVIAL(error) << "[install_plugin]Archive read error:" << mz_zip_get_error_string(zip_error) << std::endl;
|
||||||
close_zip_reader(&archive);
|
close_zip_reader(&archive);
|
||||||
if (pro_fn) {
|
if (pro_fn) { pro_fn(InstallStatusUnzipFailed, 0, cancel); }
|
||||||
pro_fn(InstallStatusUnzipFailed, 0, cancel);
|
|
||||||
}
|
|
||||||
return InstallStatusUnzipFailed;
|
return InstallStatusUnzipFailed;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if (pro_fn) {
|
if (pro_fn) {
|
||||||
pro_fn(InstallStatusNormal, 50 + i/num_entries, cancel);
|
pro_fn(InstallStatusNormal, 50 + i/num_entries, cancel);
|
||||||
|
|
Loading…
Reference in New Issue