Add more unicode APIs
This commit is contained in:
@@ -1,5 +1,21 @@
|
||||
#include "Utility.h"
|
||||
#include <ctime>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
// Per-path mutex to serialize concurrent zip operations on the same target.
|
||||
// Without this, two LabVIEW threads can race: one extracting a zip while
|
||||
// another truncates/writes the same file, corrupting data and crashing LabVIEW.
|
||||
static std::mutex g_zipPathMapMutex;
|
||||
static std::map<std::string, std::shared_ptr<std::mutex>> g_zipPathLocks;
|
||||
|
||||
static std::shared_ptr<std::mutex> GetZipPathLock(const std::string& path) {
|
||||
std::lock_guard<std::mutex> guard(g_zipPathMapMutex);
|
||||
auto& ptr = g_zipPathLocks[path];
|
||||
if (!ptr) ptr = std::make_shared<std::mutex>();
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T get_data(const boost::property_tree::ptree& pt, const std::string& key)
|
||||
@@ -436,6 +452,9 @@ bool AddFolderContentsToZip(zip* archive, const char* folderPath, const char* zi
|
||||
}
|
||||
|
||||
bool ZipFolderWithPassword(const char* folderPath, const char* zipFilePath, const char* password) {
|
||||
auto pathLock = GetZipPathLock(std::string(zipFilePath));
|
||||
std::lock_guard<std::mutex> zipGuard(*pathLock);
|
||||
|
||||
zip* zipArchive;
|
||||
zip_flags_t flags = ZIP_CREATE | ZIP_TRUNCATE;
|
||||
//std::cout << "Open Zip File: " << zipFilePath << std::endl;
|
||||
@@ -819,6 +838,9 @@ std::string GetDateTimeString(const std::string& format) {
|
||||
//}
|
||||
bool ExtractProtectedZipFile(const std::string& zipFileName, const std::string& password, const std::string& modelName, const std::string outputFolder)
|
||||
{
|
||||
auto pathLock = GetZipPathLock(outputFolder);
|
||||
std::lock_guard<std::mutex> zipGuard(*pathLock);
|
||||
|
||||
int error;
|
||||
if (!FileExist(zipFileName))return false;
|
||||
zip_t* archive = zip_open(zipFileName.c_str(), ZIP_RDONLY, &error);
|
||||
|
||||
Reference in New Issue
Block a user