Windows: use wide char interfaces
Exchange file names and command line parameters with the system using wchar_t interfaces: allows preserving values which can be reversibly transcoded in the current multibyte charset (which can't be UTF-8). Store all file paths internally in UTF-8
This commit is contained in:
+9
-5
@@ -2970,6 +2970,7 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
|
||||
#ifndef MINIZ_NO_TIME
|
||||
#include <sys/utime.h>
|
||||
#endif
|
||||
#define MZ_FOPENREAD(f, m) _wfopen(f, m)
|
||||
#define MZ_FOPEN(f, m) fopen(f, m)
|
||||
#define MZ_FCLOSE fclose
|
||||
#define MZ_FREAD fread
|
||||
@@ -3845,20 +3846,23 @@ static size_t mz_zip_file_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBu
|
||||
return MZ_FREAD(pBuf, 1, n, pZip->m_pState->m_pFile);
|
||||
}
|
||||
|
||||
mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags)
|
||||
mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const WCHAR_TYPE *pFilename, mz_uint32 flags)
|
||||
{
|
||||
return mz_zip_reader_init_file_v2(pZip, pFilename, flags, 0, 0);
|
||||
}
|
||||
|
||||
mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size)
|
||||
mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const WCHAR_TYPE *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size)
|
||||
{
|
||||
mz_uint64 file_size;
|
||||
MZ_FILE *pFile;
|
||||
|
||||
if ((!pZip) || (!pFilename) || ((archive_size) && (archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)))
|
||||
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
|
||||
|
||||
pFile = MZ_FOPEN(pFilename, "rb");
|
||||
#ifdef _WIN32
|
||||
pFile = MZ_FOPENREAD(pFilename, L"rb");
|
||||
#else
|
||||
pFile = MZ_FOPENREAD(pFilename, "rb");
|
||||
#endif
|
||||
if (!pFile)
|
||||
return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);
|
||||
|
||||
@@ -5400,7 +5404,7 @@ mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags
|
||||
}
|
||||
|
||||
#ifndef MINIZ_NO_STDIO
|
||||
mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr)
|
||||
mz_bool mz_zip_validate_file_archive(const WCHAR_TYPE *pFilename, mz_uint flags, mz_zip_error *pErr)
|
||||
{
|
||||
mz_bool success = MZ_TRUE;
|
||||
mz_zip_archive zip;
|
||||
|
||||
+8
-4
@@ -1097,9 +1097,13 @@ mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t si
|
||||
/* Read a archive from a disk file. */
|
||||
/* file_start_ofs is the file offset where the archive actually begins, or 0. */
|
||||
/* actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk. If zero the entire file is treated as the archive. */
|
||||
mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
|
||||
mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size);
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WCHAR_TYPE wchar_t
|
||||
#else
|
||||
#define WCHAR_TYPE char
|
||||
#endif
|
||||
mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const WCHAR_TYPE *pFilename, mz_uint32 flags);
|
||||
mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const WCHAR_TYPE *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size);
|
||||
/* Read an archive from an already opened FILE, beginning at the current file position. */
|
||||
/* The archive is assumed to be archive_size bytes long. If archive_size is < 0, then the entire rest of the file is assumed to contain the archive. */
|
||||
/* The FILE will NOT be closed when mz_zip_reader_end() is called. */
|
||||
@@ -1222,7 +1226,7 @@ mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags);
|
||||
|
||||
/* Misc utils/helpers, valid for ZIP reading or writing */
|
||||
mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr);
|
||||
mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr);
|
||||
mz_bool mz_zip_validate_file_archive(const WCHAR_TYPE *pFilename, mz_uint flags, mz_zip_error *pErr);
|
||||
|
||||
/* Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end(). */
|
||||
mz_bool mz_zip_end(mz_zip_archive *pZip);
|
||||
|
||||
@@ -567,6 +567,11 @@ bool path_exists(const string& path)
|
||||
SYSPATH(path, syspath);
|
||||
return ACCESS(syspath, 0) == 0;
|
||||
}
|
||||
bool path_readable(const string& path)
|
||||
{
|
||||
SYSPATH(path, syspath);
|
||||
return ACCESS(syspath, R_OK) == 0;
|
||||
}
|
||||
|
||||
// Allowed punctuation in the path part of an URI according to RFC2396
|
||||
// -_.!~*'():@&=+$,
|
||||
|
||||
@@ -87,6 +87,8 @@ extern int path_fileprops(const std::string path, struct stat *stp,
|
||||
/// Returns true if last elt could be checked to exist. False may mean that
|
||||
/// the file/dir does not exist or that an error occurred.
|
||||
extern bool path_exists(const std::string& path);
|
||||
/// Same but must be readable
|
||||
extern bool path_readable(const std::string& path);
|
||||
|
||||
/// Return separator for PATH environment variable
|
||||
extern std::string path_PATHsep();
|
||||
|
||||
@@ -164,10 +164,15 @@ const string& path_pkgdatadir()
|
||||
// into either utf-8 if transcoding succeeds, or url-encoded
|
||||
bool printableUrl(const string& fcharset, const string& in, string& out)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// On windows our paths are always utf-8
|
||||
out = in;
|
||||
#else
|
||||
int ecnt = 0;
|
||||
if (!transcode(in, out, fcharset, "UTF-8", &ecnt) || ecnt) {
|
||||
out = url_encode(in, 7);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -411,7 +411,8 @@ public:
|
||||
if (m_fn.empty()) {
|
||||
ret1 = mz_zip_reader_init_mem(&zip, m_data, m_cnt, 0);
|
||||
} else {
|
||||
ret1 = mz_zip_reader_init_file(&zip, m_fn.c_str(), 0);
|
||||
SYSPATH(m_fn, realpath);
|
||||
ret1 = mz_zip_reader_init_file(&zip, realpath, 0);
|
||||
}
|
||||
if (!ret1) {
|
||||
if (m_reason) {
|
||||
|
||||
Reference in New Issue
Block a user