Add more unicode APIs

This commit is contained in:
2026-04-07 07:59:46 +10:00
parent 6d792ee4c0
commit cb3e856a6e
5 changed files with 195 additions and 1 deletions

View File

@@ -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);