diff --git a/.gitignore b/.gitignore index b2f8b363..3290ce2b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ node_modules/ *.vcxproj.user .vs/ +src/windows/ZipComponentUWP/*.aps src/windows/ZipComponentUWP/Bin/*_Debug src/windows/ZipComponentUWP/Bin/*/*.exe src/windows/ZipComponentUWP/Bin/*/*.exp diff --git a/plugin.xml b/plugin.xml index 2964e8c5..f55aeb53 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="3.2.1"> diff --git a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM64_Release/ZipComponentUWP.dll b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM64_Release/ZipComponentUWP.dll index 16fe79ad..d26bf6ba 100644 Binary files a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM64_Release/ZipComponentUWP.dll and b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM64_Release/ZipComponentUWP.dll differ diff --git a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM64_Release/ZipComponentUWP.winmd b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM64_Release/ZipComponentUWP.winmd index 48438534..425c331f 100644 Binary files a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM64_Release/ZipComponentUWP.winmd and b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM64_Release/ZipComponentUWP.winmd differ diff --git a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM_Release/ZipComponentUWP.dll b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM_Release/ZipComponentUWP.dll index 72cccb26..e7d5ea71 100644 Binary files a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM_Release/ZipComponentUWP.dll and b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM_Release/ZipComponentUWP.dll differ diff --git a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM_Release/ZipComponentUWP.winmd b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM_Release/ZipComponentUWP.winmd index 027b5874..16c31ab1 100644 Binary files a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM_Release/ZipComponentUWP.winmd and b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_ARM_Release/ZipComponentUWP.winmd differ diff --git a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x64_Release/ZipComponentUWP.dll b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x64_Release/ZipComponentUWP.dll index 971e5970..f6ae5152 100644 Binary files a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x64_Release/ZipComponentUWP.dll and b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x64_Release/ZipComponentUWP.dll differ diff --git a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x64_Release/ZipComponentUWP.winmd b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x64_Release/ZipComponentUWP.winmd index 944c26ca..66d2e601 100644 Binary files a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x64_Release/ZipComponentUWP.winmd and b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x64_Release/ZipComponentUWP.winmd differ diff --git a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x86_Release/ZipComponentUWP.dll b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x86_Release/ZipComponentUWP.dll index d1e16026..7f3c6696 100644 Binary files a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x86_Release/ZipComponentUWP.dll and b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x86_Release/ZipComponentUWP.dll differ diff --git a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x86_Release/ZipComponentUWP.winmd b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x86_Release/ZipComponentUWP.winmd index d05d62ae..0c3849a7 100644 Binary files a/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x86_Release/ZipComponentUWP.winmd and b/src/windows/ZipComponentUWP/Bin/ZipComponentUWP_x86_Release/ZipComponentUWP.winmd differ diff --git a/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_ARM64_Release/EmptyDotNetComponentUWP.winmd b/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_ARM64_Release/EmptyDotNetComponentUWP.winmd index 6f79b894..a65d982b 100644 Binary files a/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_ARM64_Release/EmptyDotNetComponentUWP.winmd and b/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_ARM64_Release/EmptyDotNetComponentUWP.winmd differ diff --git a/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_ARM_Release/EmptyDotNetComponentUWP.winmd b/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_ARM_Release/EmptyDotNetComponentUWP.winmd index 841196e1..46665c60 100644 Binary files a/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_ARM_Release/EmptyDotNetComponentUWP.winmd and b/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_ARM_Release/EmptyDotNetComponentUWP.winmd differ diff --git a/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_AnyCPU_Release/EmptyDotNetComponentUWP.winmd b/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_AnyCPU_Release/EmptyDotNetComponentUWP.winmd index 8a3ed521..8af13be3 100644 Binary files a/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_AnyCPU_Release/EmptyDotNetComponentUWP.winmd and b/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_AnyCPU_Release/EmptyDotNetComponentUWP.winmd differ diff --git a/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_x64_Release/EmptyDotNetComponentUWP.winmd b/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_x64_Release/EmptyDotNetComponentUWP.winmd index e905c6a0..2dd3e042 100644 Binary files a/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_x64_Release/EmptyDotNetComponentUWP.winmd and b/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_x64_Release/EmptyDotNetComponentUWP.winmd differ diff --git a/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_x86_Release/EmptyDotNetComponentUWP.winmd b/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_x86_Release/EmptyDotNetComponentUWP.winmd index b1010933..936c5f1d 100644 Binary files a/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_x86_Release/EmptyDotNetComponentUWP.winmd and b/src/windows/ZipComponentUWP/Libraries/EmptyDotNetComponentUWP/Bin/EmptyDotNetComponentUWP_x86_Release/EmptyDotNetComponentUWP.winmd differ diff --git a/src/windows/ZipComponentUWP/Source/Resource.h b/src/windows/ZipComponentUWP/Source/Resource.h new file mode 100644 index 00000000..ba9ffb45 --- /dev/null +++ b/src/windows/ZipComponentUWP/Source/Resource.h @@ -0,0 +1,15 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by C:\CG\Projects\sitewaerts\cordova-plugin-zip\src\windows\ZipComponentUWP\ZipComponentUWP.rc +// + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/src/windows/ZipComponentUWP/Source/ZipAlgorithm.cpp b/src/windows/ZipComponentUWP/Source/ZipAlgorithm.cpp index 8d26030b..89575f20 100644 --- a/src/windows/ZipComponentUWP/Source/ZipAlgorithm.cpp +++ b/src/windows/ZipComponentUWP/Source/ZipAlgorithm.cpp @@ -12,8 +12,11 @@ const char* ZipAlgorithm::NameMinizCpp = "miniz-cpp"; ZipAlgorithm* ZipAlgorithm::Create(const char* pchAlgorithmName) { - if( pchAlgorithmName == nullptr ) + if( pchAlgorithmName == nullptr || ::strlen(pchAlgorithmName) == 0 ) + { + throw std::runtime_error("ZipAlgorithm::Create(): invalid algorithm name"); return nullptr; + } if( ::strcmp(pchAlgorithmName, NameAndyZip) == 0 ) return new ZipAlgorithm_andyzip(); @@ -34,14 +37,24 @@ void ZipAlgorithm::Destroy(ZipAlgorithm*& pAlgorithm) void ZipAlgorithm::SetOutputDirWithTrailingSlash(const char* pchOutputDir) { + // Only for empty paths we don't append trailing slashes + if( pchOutputDir == nullptr || pchOutputDir[0] == '\0' ) + m_strOutputDir = ""; + m_strOutputDir = pchOutputDir; - if( m_strOutputDir[m_strOutputDir.length() - 1] != '/' && m_strOutputDir[m_strOutputDir.length() - 1] != '\\' ) + + const char chLastChar = m_strOutputDir[m_strOutputDir.length() - 1]; + if( chLastChar != '/' && chLastChar != '\\' ) m_strOutputDir += '/'; } bool ZipAlgorithm::CreateEntryDir(const std::string& strEntryDir) const { - const char& chLastChar = strEntryDir[strEntryDir.length() - 1]; + const size_t szEntryDirLength = strEntryDir.length(); + if( szEntryDirLength < 1 ) + throw std::runtime_error("ZipAlgorithm::CreateEntryDir(): invalid/empty entry dir"); + + const char& chLastChar = strEntryDir[szEntryDirLength - 1]; if( chLastChar != '/' && chLastChar != '\\' ) return false; diff --git a/src/windows/ZipComponentUWP/Source/ZipAlgorithm_andyzip.cpp b/src/windows/ZipComponentUWP/Source/ZipAlgorithm_andyzip.cpp index 57498aed..12b037c0 100644 --- a/src/windows/ZipComponentUWP/Source/ZipAlgorithm_andyzip.cpp +++ b/src/windows/ZipComponentUWP/Source/ZipAlgorithm_andyzip.cpp @@ -81,7 +81,7 @@ __pragma(pack(pop)) // This is a replacement for the zipfile_reader class. // It fixes an issue in zipfile_reader with local file headers not containing -// the uncompressed size and reduces allocations by reserving memory upfront. +// the uncompressed size and reduces allocations by reserving memory upfront. // Assumes little endianness and supports only deflate for decompression! class ZipAlgorithm_andyzip::Reader { diff --git a/src/windows/ZipComponentUWP/Source/ZipComponent.Version.cpp b/src/windows/ZipComponentUWP/Source/ZipComponent.Version.cpp new file mode 100644 index 00000000..23eab882 --- /dev/null +++ b/src/windows/ZipComponentUWP/Source/ZipComponent.Version.cpp @@ -0,0 +1,20 @@ +// +// DO NOT EDIT THIS FILE MANUALLY +// +// This file is automatically generated in the pre-build step by the UpdateVersion.bat script +// Change the version number in the ZipComponentUWP.rc file +// +// DO NOT EDIT THIS FILE MANUALLY +// +#include "pch.h" +#include +#include +#include "ZipAlgorithm.h" +#include "ZipComponent.h" + +using namespace ZipComponentUWP; + +String^ ZipComponent::GetVersion() +{ + return "1.0.1.0"; +} diff --git a/src/windows/ZipComponentUWP/Source/ZipComponent.cpp b/src/windows/ZipComponentUWP/Source/ZipComponent.cpp index 89c876a0..011b1f59 100644 --- a/src/windows/ZipComponentUWP/Source/ZipComponent.cpp +++ b/src/windows/ZipComponentUWP/Source/ZipComponent.cpp @@ -25,24 +25,32 @@ static inline std::string PlatformStringToStdString(String^ platformString) ZipComponent::ZipComponent(String^ strAlgorithmName, String^ strZipFile, String^ strOutputDir) : m_pAlgorithm(nullptr) { - const std::string stringAlgorithmNameUtf8 = PlatformStringToStdString(strAlgorithmName); - m_pAlgorithm = ZipAlgorithm::Create(stringAlgorithmNameUtf8.c_str()); - if( m_pAlgorithm == nullptr ) + try { - m_strLastError = "Failed to create algorithm: " + StdStringToPlatformString(stringAlgorithmNameUtf8); - return; + const std::string stringAlgorithmNameUtf8 = PlatformStringToStdString(strAlgorithmName); + m_pAlgorithm = ZipAlgorithm::Create(stringAlgorithmNameUtf8.c_str()); + if( m_pAlgorithm == nullptr ) + { + m_strLastError = "Failed to create algorithm: " + StdStringToPlatformString(stringAlgorithmNameUtf8); + return; + } + + m_strZipFileUtf8 = PlatformStringToStdString(strZipFile); + m_strOutputDirUtf8 = PlatformStringToStdString(strOutputDir); + + if( !m_pAlgorithm->Open(m_strZipFileUtf8.c_str(), m_strOutputDirUtf8.c_str()) ) + { + m_strLastError = "Failed to open zip file " + StdStringToPlatformString(m_strZipFileUtf8) + + " (output dir = " + StdStringToPlatformString(m_strOutputDirUtf8) + ")"; + + m_pAlgorithm->Close(); + ZipAlgorithm::Destroy(m_pAlgorithm); + } } - - m_strZipFileUtf8 = PlatformStringToStdString(strZipFile); - m_strOutputDirUtf8 = PlatformStringToStdString(strOutputDir); - - if( !m_pAlgorithm->Open(m_strZipFileUtf8.c_str(), m_strOutputDirUtf8.c_str()) ) + catch( std::exception exception ) { - m_strLastError = "Failed to open zip file " + StdStringToPlatformString(m_strZipFileUtf8) - + " (output dir = " + StdStringToPlatformString(m_strOutputDirUtf8) + ")"; - - m_pAlgorithm->Close(); - ZipAlgorithm::Destroy(m_pAlgorithm); + if( exception.what() ) + m_strLastError += StdStringToPlatformString(std::string("\n\n") + exception.what()); } } @@ -50,8 +58,15 @@ ZipComponent::~ZipComponent() { if( m_pAlgorithm ) { - m_pAlgorithm->Close(); - ZipAlgorithm::Destroy(m_pAlgorithm); + try + { + m_pAlgorithm->Close(); + ZipAlgorithm::Destroy(m_pAlgorithm); + } + catch( std::exception exception ) + { + // Can't do much here, since we're destructing the object + } } } @@ -63,7 +78,17 @@ size_t ZipComponent::GetEntryCount() return 0u; } - return m_pAlgorithm->GetEntryCount(); + try + { + return m_pAlgorithm->GetEntryCount(); + } + catch( std::exception exception ) + { + if( exception.what() ) + m_strLastError += StdStringToPlatformString(std::string("\n\n") + exception.what()); + } + + return 0u; } String^ ZipComponent::GetEntryName(const size_t szEntryIndex) @@ -74,7 +99,17 @@ String^ ZipComponent::GetEntryName(const size_t szEntryIndex) return ""; } - return StdStringToPlatformString(m_pAlgorithm->GetEntryName(szEntryIndex)); + try + { + return StdStringToPlatformString(m_pAlgorithm->GetEntryName(szEntryIndex)); + } + catch( std::exception exception ) + { + if( exception.what() ) + m_strLastError += StdStringToPlatformString(std::string("\n\n") + exception.what()); + } + + return ""; } bool ZipComponent::UnzipEntry(const size_t szEntryIndex) @@ -85,10 +120,29 @@ bool ZipComponent::UnzipEntry(const size_t szEntryIndex) return false; } - return m_pAlgorithm->UnzipEntry(szEntryIndex); + try + { + return m_pAlgorithm->UnzipEntry(szEntryIndex); + } + catch( std::exception exception ) + { + if( exception.what() ) + m_strLastError += StdStringToPlatformString(std::string("\n\n") + exception.what()); + } + + return false; } String^ ZipComponent::GetLastError() { return m_strLastError; } + +// This method is defined in ZipComponent.Version.cpp +// UWP components don't have access to the methods required to read entries out of the modules resource section. +// The pre-build executed UpdateVersion.bat script reads it and updates ZipComponent.Version.cpp accordingly. +// +// String^ ZipComponent::GetVersion() +// { +// return ...; +// } diff --git a/src/windows/ZipComponentUWP/Source/ZipComponent.h b/src/windows/ZipComponentUWP/Source/ZipComponent.h index 5f9e7b2d..bd16c5bd 100644 --- a/src/windows/ZipComponentUWP/Source/ZipComponent.h +++ b/src/windows/ZipComponentUWP/Source/ZipComponent.h @@ -16,6 +16,7 @@ namespace ZipComponentUWP bool UnzipEntry(size_t szEntryIndex); String^ GetLastError(); + String^ GetVersion(); private: ZipAlgorithm* m_pAlgorithm; diff --git a/src/windows/ZipComponentUWP/Source/ZipTest.cpp b/src/windows/ZipComponentUWP/Source/ZipTest.cpp index 11305ce8..17c7698d 100644 --- a/src/windows/ZipComponentUWP/Source/ZipTest.cpp +++ b/src/windows/ZipComponentUWP/Source/ZipTest.cpp @@ -6,58 +6,67 @@ int main(int argc, const char* argv[]) { - // Print app usage if parameter count doesn't match - if( argc != 4 ) + try { - const std::string strPath(argv[0]); - const std::string strAppExecutable(strPath.substr(strPath.find_last_of("/\\") + 1)); - std::cout << "Usage: " << strAppExecutable << " zipFile outputDir algorithm\n\nSupported algorithms:\n"; - std::cout << " " << ZipAlgorithm::NameAndyZip << "\n"; - std::cout << " " << ZipAlgorithm::NameMinizCpp << "\n"; - return EXIT_FAILURE; - } - - // Retrieve input parameters and unzip algorithm matching the provided algorithm name - const char* pchZipFile = argv[1]; - const char* pchOutputDir = argv[2]; - const char* pchAlgorithmName = argv[3]; - auto* pAlgorithm = ZipAlgorithm::Create(pchAlgorithmName); - - if( pAlgorithm == nullptr ) - { - std::cout << "Unsupported algorithm: " << pchAlgorithmName << "\n"; - return EXIT_FAILURE; - } + // Print app usage if parameter count doesn't match + if( argc != 4 ) + { + const std::string strPath(argv[0]); + const std::string strAppExecutable(strPath.substr(strPath.find_last_of("/\\") + 1)); + std::cout << "Usage: " << strAppExecutable << " zipFile outputDir algorithm\n\nSupported algorithms:\n"; + std::cout << " " << ZipAlgorithm::NameAndyZip << "\n"; + std::cout << " " << ZipAlgorithm::NameMinizCpp << "\n"; + return EXIT_FAILURE; + } - if( !pAlgorithm->Open(pchZipFile, pchOutputDir) ) - { - std::cout << "Failed to open zip file: " << pchZipFile << "\n"; - ZipAlgorithm::Destroy(pAlgorithm); - return EXIT_FAILURE; - } + // Retrieve input parameters and unzip algorithm matching the provided algorithm name + const char* pchZipFile = argv[1]; + const char* pchOutputDir = argv[2]; + const char* pchAlgorithmName = argv[3]; + auto* pAlgorithm = ZipAlgorithm::Create(pchAlgorithmName); - auto unzip = [](ZipAlgorithm* pAlgorithm, const char* pchZipFile, const char* pchOutputDir) - { - bool bErrorsOccured = false; - const size_t szEntries = pAlgorithm->GetEntryCount(); - for( size_t i = 0; i < szEntries; ++i ) - if( !pAlgorithm->UnzipEntry(i) ) - bErrorsOccured = true; + if( pAlgorithm == nullptr ) + { + std::cout << "Unsupported algorithm: " << pchAlgorithmName << "\n"; + return EXIT_FAILURE; + } - return bErrorsOccured ? EXIT_FAILURE : EXIT_SUCCESS; - }; + if( !pAlgorithm->Open(pchZipFile, pchOutputDir) ) + { + std::cout << "Failed to open zip file: " << pchZipFile << "\n"; + ZipAlgorithm::Destroy(pAlgorithm); + return EXIT_FAILURE; + } - // Execute the decompression and measure duration - const auto timeBegin = std::chrono::steady_clock::now(); - const int iResult = unzip(pAlgorithm, pchZipFile, pchOutputDir); - const auto timeEnd = std::chrono::steady_clock::now(); + auto unzip = [](ZipAlgorithm* pAlgorithm, const char* pchZipFile, const char* pchOutputDir) + { + bool bErrorsOccured = false; + const size_t szEntries = pAlgorithm->GetEntryCount(); + for( size_t i = 0; i < szEntries; ++i ) + if( !pAlgorithm->UnzipEntry(i) ) + bErrorsOccured = true; - pAlgorithm->Close(); - ZipAlgorithm::Destroy(pAlgorithm); + return bErrorsOccured ? EXIT_FAILURE : EXIT_SUCCESS; + }; - std::cout << "Duration: " << std::chrono::duration_cast(timeEnd - timeBegin).count() << " ms"; - if( iResult != EXIT_SUCCESS ) - std::cout << "Error: " << iResult << std::endl; + // Execute the decompression and measure duration + const auto timeBegin = std::chrono::steady_clock::now(); + const int iResult = unzip(pAlgorithm, pchZipFile, pchOutputDir); + const auto timeEnd = std::chrono::steady_clock::now(); + + pAlgorithm->Close(); + ZipAlgorithm::Destroy(pAlgorithm); + + std::cout << "Duration: " << std::chrono::duration_cast(timeEnd - timeBegin).count() << " ms"; + if (iResult != EXIT_SUCCESS) + std::cout << "Error: " << iResult << std::endl; + + return iResult; + } + catch(std::exception exception) + { + std::cout << "Exception: " << exception.what() << std::endl; + } - return iResult; + return EXIT_FAILURE; } diff --git a/src/windows/ZipComponentUWP/UpdateVersion.bat b/src/windows/ZipComponentUWP/UpdateVersion.bat new file mode 100644 index 00000000..afc8cb24 --- /dev/null +++ b/src/windows/ZipComponentUWP/UpdateVersion.bat @@ -0,0 +1,39 @@ +:: +:: Reads the value "ProductVersion" from the resource file ZipComponentUWP.rc +:: and creates file Source\ZipComponent.Version.cpp containing a method that +:: returns the version as a string. +:: +@ECHO OFF +SET PROJECTPATH=%~dp0 +SET RESOURCEFILE=%PROJECTPATH%ZipComponentUWP.rc +SET VERSIONCPP=%PROJECTPATH%Source\ZipComponent.Version.cpp + +:: The resource file is in unicode format, but FINDSTR can't handle that. So use TYPE to avoid the issue. +FOR /F "tokens=*" %%g IN ('TYPE %RESOURCEFILE% ^| FINDSTR ProductVersion') DO (SET VERSIONSTRING=%%g) + +:: Get the part right from the comma and trim the result +SET "x=%VERSIONSTRING:,=" & SET "VERSIONSTRING=%" + +:: Create or overwrite the cpp file with the GetVersion() method +echo // > %VERSIONCPP% +echo // DO NOT EDIT THIS FILE MANUALLY >> %VERSIONCPP% +echo // >> %VERSIONCPP% +echo // This file is automatically generated in the pre-build step by the UpdateVersion.bat script >> %VERSIONCPP% +echo // Change the version number in the ZipComponentUWP.rc file >> %VERSIONCPP% +echo // >> %VERSIONCPP% +echo // DO NOT EDIT THIS FILE MANUALLY >> %VERSIONCPP% +echo // >> %VERSIONCPP% +echo #include "pch.h" >> %VERSIONCPP% +echo #include ^ >> %VERSIONCPP% +echo #include ^ >> %VERSIONCPP% +echo #include "ZipAlgorithm.h" >> %VERSIONCPP% +echo #include "ZipComponent.h" >> %VERSIONCPP% +echo. >> %VERSIONCPP% +echo using namespace ZipComponentUWP; >> %VERSIONCPP% +echo. >> %VERSIONCPP% +echo String^^ ZipComponent::GetVersion() >> %VERSIONCPP% +echo { >> %VERSIONCPP% +echo return%VERSIONSTRING%; >> %VERSIONCPP% +echo } >> %VERSIONCPP% + +echo UpdateVersion.bat: Set version%VERSIONSTRING% in Source\ZipComponent.Version.cpp \ No newline at end of file diff --git a/src/windows/ZipComponentUWP/ZipComponentUWP.rc b/src/windows/ZipComponentUWP/ZipComponentUWP.rc new file mode 100644 index 00000000..7920fb40 Binary files /dev/null and b/src/windows/ZipComponentUWP/ZipComponentUWP.rc differ diff --git a/src/windows/ZipComponentUWP/ZipComponentUWP.vcxproj b/src/windows/ZipComponentUWP/ZipComponentUWP.vcxproj index b80cf300..d9b3d1a0 100644 --- a/src/windows/ZipComponentUWP/ZipComponentUWP.vcxproj +++ b/src/windows/ZipComponentUWP/ZipComponentUWP.vcxproj @@ -178,6 +178,13 @@ Console false + + UpdateVersion.bat + + + + + @@ -194,6 +201,13 @@ Console false + + UpdateVersion.bat + + + + + @@ -210,6 +224,13 @@ Console false + + UpdateVersion.bat + + + + + @@ -226,6 +247,13 @@ Console false + + UpdateVersion.bat + + + + + @@ -242,6 +270,13 @@ Console false + + UpdateVersion.bat + + + + + @@ -258,6 +293,13 @@ Console false + + UpdateVersion.bat + + + + + @@ -274,6 +316,13 @@ Console false + + UpdateVersion.bat + + + + + @@ -290,6 +339,13 @@ Console false + + UpdateVersion.bat + + + + + @@ -301,6 +357,7 @@ + @@ -445,10 +502,14 @@ + + + + diff --git a/src/windows/ZipComponentUWP/ZipComponentUWP.vcxproj.filters b/src/windows/ZipComponentUWP/ZipComponentUWP.vcxproj.filters index 114d223f..998fc99b 100644 --- a/src/windows/ZipComponentUWP/ZipComponentUWP.vcxproj.filters +++ b/src/windows/ZipComponentUWP/ZipComponentUWP.vcxproj.filters @@ -34,6 +34,9 @@ Source + + Source + @@ -78,8 +81,16 @@ Source + + Source + + + + Resources + + \ No newline at end of file diff --git a/src/windows/ZipProxy.js b/src/windows/ZipProxy.js index 04c0f1d3..b0ed1b8f 100644 --- a/src/windows/ZipProxy.js +++ b/src/windows/ZipProxy.js @@ -162,30 +162,54 @@ function unzipUWP(zipFileIn, outDirIn, zipAlgorithm, progressCallback) try { - var zipUWP = new ZipComponentUWP.ZipComponent(zipAlgorithm, zipFileNative.path, outDirNative.path); - var zipFileIndex = 0; - var zipFileCount = zipUWP.getEntryCount(); + let zipUWP = new ZipComponentUWP.ZipComponent(zipAlgorithm, zipFileNative.path, outDirNative.path); + if( zipUWP == null ) { + let initError = 'ERROR: Failed to initialize ZipComponentUWP!'; + console.log(initError); + return WinJS.Promise.wrapError(initError); + } + console.log('- ZipComponentUWP Version = ' + zipUWP.getVersion()); + + let initError = zipUWP.getLastError(); + if( initError !== '' ) { + console.log(initError); + return WinJS.Promise.wrapError(initError); + } + + let zipFileCount = zipUWP.getEntryCount(); + if( zipFileCount === 0 ) { + console.log('ERROR: No zip entries found! ' + zipUWP.getLastError()); + return WinJS.Promise.wrapError(zipUWP.getLastError()); + } + progressCallback(zipFileCount, 0); - function _fileProcessed() - { + let zipFileIndex = 0; + function _fileProcessed() { progressCallback(zipFileCount, ++zipFileIndex); } - var zipJobs = []; + let zipJobs = []; for(let i = 0; i < zipFileCount; ++i) zipJobs[i] = i; return WinJS.Promise.join(zipJobs.map(function(zipJob) { - return new WinJS.Promise(function(resolve) - { - zipUWP.unzipEntry(zipJob); - resolve(); - }).then(_fileProcessed); + return new WinJS.Promise(function (completeDispatch, errorDispatch) + { + if (zipUWP.unzipEntry(zipJob) === true) { + completeDispatch(); + } else { + let errorName = 'ERROR: Failed to unzip entry [' + zipJob + '] = ' + zipUWP.getEntryName(zipJob); + let errorMessage = 'zipUWP.getLastError() = ' + zipUWP.getLastError(); + console.log(errorName +' ' + errorMessage); + errorDispatch(new WinJS.ErrorFromName(errorName, errorMessage)); + } + }).then(_fileProcessed); } - )).then(function () + )) + .then(function() { progressCallback(zipJobs.length, zipJobs.length); }); @@ -224,9 +248,9 @@ cordova.commandProxy.add("Zip", { return false; } - // Use the fastest algorithm 'andyzip' as default, but fallback to 'jszip' + // Use the algorithm 'miniz-cpp' as default, but fallback to 'jszip' // if the current platform doesn't support the native UWP implementations - let algorithm = args[2] || 'andyzip'; + let algorithm = args[2] || 'miniz-cpp'; if( algorithm !== 'jszip' && !isWindows10orHigher() ) algorithm = 'jszip'; @@ -234,10 +258,10 @@ cordova.commandProxy.add("Zip", { unzipJSZip(args[0], args[1], progressCallback) .then(successCallback, errorCallback || console.error.bind(console)); } - else{ + else { unzipUWP(args[0], args[1], algorithm, progressCallback) .then(successCallback, errorCallback || console.error.bind(console)); } } } -}); +}); \ No newline at end of file diff --git a/zip.js b/zip.js index 579ccca8..61f73d08 100644 --- a/zip.js +++ b/zip.js @@ -9,12 +9,12 @@ function newProgressEvent(result) { } // The optional parameter algorithmName enables to select the zip algorithm under Windows platforms. -// If algorithmName is undefined then ZipProxy.js uses the fastest 'andyzip' implementation if the +// If algorithmName is undefined then ZipProxy.js uses 'miniz-cpp' implementation if the // current platform supports it. Otherwise it falls back to 'jszip'. // Supported algorithms: // 'jszip' Default JavaScript implementation // 'miniz-cpp' Native Windows 10 C/C++ UWP implementation (similar to iOS implementation) -// 'andyzip' Native Windows 10 C/C++ UWP implementation (fastest implementation) +// 'andyzip' Native Windows 10 C/C++ UWP implementation (faster for large files) exports.unzip = function(fileName, outputDirectory, callback, progressCallback, algorithmName) { var win = function(result) { if (result && typeof result.loaded != "undefined") {