Refactor project structure
This commit is contained in:
2952
core/ANSLicensingSystem/ANSLicense.cpp
Normal file
2952
core/ANSLicensingSystem/ANSLicense.cpp
Normal file
File diff suppressed because it is too large
Load Diff
395
core/ANSLicensingSystem/ANSLicense.h
Normal file
395
core/ANSLicensingSystem/ANSLicense.h
Normal file
@@ -0,0 +1,395 @@
|
||||
#ifndef ANSLICENSE_H
|
||||
#define ANSLICENSE_H
|
||||
|
||||
#ifdef ANSLICENSE_EXPORTS
|
||||
#define ANSLICENSE_API __declspec(dllexport)
|
||||
#else
|
||||
#define ANSLICENSE_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include "anslicensing.h"
|
||||
#include "LabVIEWHeader/extcode.h"
|
||||
#include <mutex>
|
||||
#ifdef _UNICODE
|
||||
#define _T(s) L##s
|
||||
#define _tprintf wprintf
|
||||
#define _tcscmp wcscmp
|
||||
#define _tfopen fopen
|
||||
#else
|
||||
#define _T(s) (s)
|
||||
#define _TL(s) L##s
|
||||
#define _tprintf printf
|
||||
#define _tcscmp strcmp
|
||||
#define _tfopen fopen
|
||||
#endif
|
||||
|
||||
enum LicenseKeyStatus {
|
||||
SUCCESS = 0,
|
||||
INVALID_LICENSE_KEY = 1,
|
||||
INVALID_HARDWARE_ID = 2,
|
||||
LICENSE_EXPIRED = 3,
|
||||
INVALID_ACTIVATION_KEY = 4,
|
||||
PAYMENT_REQUIRED = 5,
|
||||
INVALID_PRODUCT = 6,
|
||||
UNKNOWN = 7
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int32 cnt; /* number of bytes that follow */
|
||||
double value[1]; /* value of double */
|
||||
} LDbl, * LDblPtr, ** LDblHandle;
|
||||
|
||||
namespace ANSCENTER
|
||||
{
|
||||
|
||||
// Precision used for GPU inference
|
||||
|
||||
enum OCRType {
|
||||
SINGLETEXT = 0,
|
||||
STRUCTURE = 1
|
||||
};
|
||||
|
||||
enum OCRLanguage {
|
||||
ENGLISH = 0,
|
||||
CHINESE = 1,
|
||||
FRENCH = 2,
|
||||
GERMANY = 3,
|
||||
JAPANESE= 4,
|
||||
KOREAN = 5,
|
||||
CUSTOM =6
|
||||
};
|
||||
// Precision used for GPU inference
|
||||
enum class Precision {
|
||||
// Full precision floating point value
|
||||
FP32,
|
||||
// Half prevision floating point value
|
||||
FP16,
|
||||
// Int8 quantization.
|
||||
// Has reduced dynamic range, may result in slight loss in accuracy.
|
||||
// If INT8 is selected, must provide path to calibration dataset directory.
|
||||
INT8,
|
||||
};
|
||||
|
||||
// Options for the network
|
||||
struct Options {
|
||||
// Precision to use for GPU inference.
|
||||
Precision precision = Precision::FP16;
|
||||
// If INT8 precision is selected, must provide path to calibration dataset
|
||||
// directory.
|
||||
std::string calibrationDataDirectoryPath;
|
||||
// The batch size to be used when computing calibration data for INT8
|
||||
// inference. Should be set to as large a batch number as your GPU will
|
||||
// support.
|
||||
int32_t calibrationBatchSize = 128;
|
||||
// The batch size which should be optimized for.
|
||||
int32_t optBatchSize = 1;
|
||||
// Maximum allowable batch size
|
||||
int32_t maxBatchSize = 16;
|
||||
// GPU device index
|
||||
int deviceIndex = 0;
|
||||
// Directory where the engine file should be saved
|
||||
std::string engineFileDir = ".";
|
||||
|
||||
// Maximum allowed input width
|
||||
int32_t maxInputWidth = -1; // Default to -1 --> expecting fixed input size
|
||||
// Minimum allowed input width
|
||||
int32_t minInputWidth = -1; // Default to -1 --> expecting fixed input size
|
||||
// Optimal input width
|
||||
int32_t optInputWidth = -1; // Default to -1 --> expecting fixed input size
|
||||
|
||||
// Maximum allowed input height
|
||||
int32_t maxInputHeight = -1; // Default to -1 --> expecting fixed input size
|
||||
// Minimum allowed input height
|
||||
int32_t minInputHeight = -1; // Default to -1 --> expecting fixed input size
|
||||
// Optimal input height
|
||||
int32_t optInputHeight = -1; // Default to -1 --> expecting fixed input size
|
||||
|
||||
// GPU clock lock frequency in MHz.
|
||||
// -1 = auto (default) — query max supported clock and lock at ~80%
|
||||
// 0 = disabled — let the driver manage clocks dynamically
|
||||
// >0 = lock at this specific MHz value (e.g. 2400)
|
||||
// Prevents GPU power throttling that causes TensorRT timing instability
|
||||
// on laptop GPUs. Requires elevated privileges; fails gracefully if not.
|
||||
int32_t gpuClockLockMHz = -1;
|
||||
};
|
||||
|
||||
enum PrecisionType {
|
||||
INT8 = 0,
|
||||
FP16 = 1,
|
||||
FP32 = 2,
|
||||
};
|
||||
enum EngineType {
|
||||
CPU = 0,
|
||||
NVIDIA_GPU = 1,
|
||||
OPENVINO_GPU = 2,
|
||||
AMD_GPU = 3,
|
||||
AUTO_DETECT = 99 // default: hardware auto-detection
|
||||
};
|
||||
enum DetectionType {
|
||||
CLASSIFICATION = 0,
|
||||
DETECTION = 1,
|
||||
SEGMENTATION = 2,
|
||||
FACEDETECTOR = 3,
|
||||
FACERECOGNIZER = 4,
|
||||
LICENSEPLATE = 5,
|
||||
TEXTSCENSE = 6,
|
||||
KEYPOINT=7,
|
||||
OBB = 8 // Oriented Bounding Box
|
||||
};
|
||||
enum ModelType {
|
||||
TENSORFLOW = 0,
|
||||
YOLOV4 = 1,
|
||||
YOLOV5 = 2,
|
||||
YOLOV8 = 3,
|
||||
TENSORRT = 4,
|
||||
OPENVINO = 5,
|
||||
FACEDETECT = 6,
|
||||
FACERECOGNIZE = 7,
|
||||
ALPR = 8,
|
||||
OCR = 9,
|
||||
ANOMALIB = 10,
|
||||
POSE=11,
|
||||
SAM=12,
|
||||
ODHUBMODEL = 13,
|
||||
YOLOV10RTOD = 14, // TensorRT Object Detection for Yolov10
|
||||
YOLOV10OVOD = 15, // OpenVINO Object Detection for Yolov10
|
||||
CUSTOMDETECTOR = 16, // Custom Detector
|
||||
YOLOV12 = 17, // YoloV12 standard for yolov12
|
||||
CUSTOMPY = 18, // Custom Python script model
|
||||
MOTIONDETECTOR = 19, // Motion Detector,
|
||||
ONNXCL =20,
|
||||
ONNXPOSE=21,
|
||||
RTPOSE=22,
|
||||
ONNXSEG = 23,
|
||||
RTSEG = 24,
|
||||
ONNXOBB = 25,
|
||||
RTOBB = 26,
|
||||
MOVIENET=27,
|
||||
ONNXSAM3=28,
|
||||
RTSAM3 = 29,
|
||||
ONNXYOLO = 30,
|
||||
RTYOLO = 31
|
||||
};
|
||||
enum TrackerType {
|
||||
BYTETRACK = 0,
|
||||
UCMC = 1,
|
||||
OCSORT = 2
|
||||
};
|
||||
enum ANSPRODUCTS {
|
||||
ANNHUB = 1000,
|
||||
DLHUB = 1001,
|
||||
ODHUB = 1002,
|
||||
ANSVIS = 1003,
|
||||
ANS_FACERECOGNIZE = 1004,
|
||||
ANS_OCR = 1005,
|
||||
ANS_ALPR =1006,
|
||||
ANS_CV = 1007,
|
||||
ANS_TS = 1008
|
||||
};
|
||||
enum ANSLICENSESTATUS {
|
||||
ACTIVE = 0,
|
||||
EXPIRED = 1,
|
||||
TRIAL=2,
|
||||
UNLICENSE = 3
|
||||
};
|
||||
struct ModelConfig {
|
||||
DetectionType detectionType;
|
||||
ModelType modelType;
|
||||
PrecisionType precisionType;
|
||||
int inpWidth;
|
||||
int inpHeight;
|
||||
float modelConfThreshold;
|
||||
float modelMNSThreshold;
|
||||
float detectionScoreThreshold;
|
||||
int numKPS; // Number of pose keypoint
|
||||
float kpsThreshold;
|
||||
bool autoGPUDetection;
|
||||
float unknownPersonThreshold;
|
||||
int gpuOptBatchSize = 1; // The batch size which should be optimized for.
|
||||
int gpuMaxBatchSize = 1; // Maximum allowable batch size
|
||||
int gpuDeviceIndex = 0; // GPU device index
|
||||
|
||||
// Maximum allowed input width
|
||||
int32_t maxInputWidth = -1; // Default to -1 --> expecting fixed input size
|
||||
// Minimum allowed input width
|
||||
int32_t minInputWidth = -1; // Default to -1 --> expecting fixed input size
|
||||
// Optimal input width
|
||||
int32_t optInputWidth = -1; // Default to -1 --> expecting fixed input size
|
||||
|
||||
// Maximum allowed input height
|
||||
int32_t maxInputHeight = -1; // Default to -1 --> expecting fixed input size
|
||||
// Minimum allowed input height
|
||||
int32_t minInputHeight = -1; // Default to -1 --> expecting fixed input size
|
||||
// Optimal input height
|
||||
int32_t optInputHeight = -1; // Default to -1 --> expecting fixed input size
|
||||
};
|
||||
|
||||
struct ANSLicenseInfo {
|
||||
std::string productName;
|
||||
std::string licenseKey;
|
||||
std::string activationKey;
|
||||
std::string hardwareId;
|
||||
ANSLICENSESTATUS licenseStatus;
|
||||
int remainingDays;
|
||||
int enableFeature;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class ANSLICENSE_API SPDLogger
|
||||
{// Singleton design pattern
|
||||
protected:
|
||||
SPDLogger(const std::string& loggerFileName, bool consoleLoggerEnable = false)
|
||||
: _loggerFileName(loggerFileName), _consoleLoggerEnable(consoleLoggerEnable) {
|
||||
Init();
|
||||
}
|
||||
void Init();
|
||||
void ConfigureLogger();
|
||||
std::string _loggerFileName{};
|
||||
bool _consoleLoggerEnable{true};
|
||||
// Deleting copy constructor and assignment operator to ensure singleton
|
||||
SPDLogger(const SPDLogger&) = delete;
|
||||
SPDLogger& operator=(const SPDLogger&) = delete;
|
||||
|
||||
public:
|
||||
bool Release();
|
||||
~SPDLogger();
|
||||
// Static method to get the singleton instance
|
||||
static SPDLogger& GetInstance(const std::string& loggerFileName, bool consoleLoggerEnable = false) {
|
||||
static SPDLogger instance(loggerFileName, consoleLoggerEnable);
|
||||
return instance;
|
||||
}
|
||||
void Disable();
|
||||
void Enable();
|
||||
void LogTrace(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
||||
void LogDebug(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
||||
void LogInfo(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
||||
void LogWarn(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
||||
void LogError(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
||||
void LogFatal(const std::string& source, const std::string& messsage, const std::string& fileSource, int lineSource);
|
||||
};
|
||||
|
||||
class ANSLICENSE_API ANSLSHelper {
|
||||
private:
|
||||
LicenseTemplate* _licenseTemplate = nullptr;
|
||||
License* _license = nullptr;
|
||||
std::wstring _licenseFilePath = _T("");
|
||||
std::wstring _licenseServiceURL = _T("");
|
||||
std::wstring _sdkLicenseKey = _T("");
|
||||
std::wstring _privateKey = _T("");
|
||||
std::wstring _publicKey = _T("");
|
||||
|
||||
SPDLogger& _logger = SPDLogger::GetInstance("License");
|
||||
std::string LoadLicenseContent();
|
||||
void Setup5x5LicenseTemplate();// This is simple case
|
||||
std::wstring GetProductId(std::string licenseKey);
|
||||
|
||||
public:
|
||||
ANSLSHelper();
|
||||
ANSLSHelper(std::string licenseServiceURL);
|
||||
ANSLSHelper(std::string privateKey, std::string licenseServiceURL);
|
||||
ANSLSHelper(std::string privateKey, std::string publicKey, std::string licenseServiceURL);
|
||||
~ANSLSHelper();
|
||||
|
||||
void SetupLicenseTemplate();
|
||||
|
||||
[[nodiscard]] bool MatchCurrentHardwareId(std::string hwid);
|
||||
[[nodiscard]] bool DectectClockmanipulation(int year, int month, int date);
|
||||
|
||||
[[nodiscard]] std::string GetLicenseData(std::string licenseKey);
|
||||
[[nodiscard]] int ActivateLicense(std::string licenseKey, std::string registrationName, std::string& activationKey); // Always activate the license (need internet connection)
|
||||
[[nodiscard]] int ActivateLicenseWithCustomHWID(std::string licenseKey, std::string registrationName, std::string hardwareId, std::string& activationKey); // Always activate the license (need internet connection)
|
||||
|
||||
[[nodiscard]] bool LoadLicenseTemplate(std::string templateFilePath);
|
||||
[[nodiscard]] std::string SaveLicenseTemplate(std::string templateFilePath, bool savePrivateKey);
|
||||
|
||||
// These are the common methods to be used
|
||||
void SetLicenseServiceURL(std::string licenseServiceURL);
|
||||
[[nodiscard]] std::string GetCurrentHardwareId();
|
||||
void LoadLicense(std::string licenseKey);
|
||||
[[nodiscard]] std::string SaveLicense();
|
||||
[[nodiscard]] std::string GenerateKey(int productId, std::string registrationName, int productFeature, bool trialLicense);
|
||||
[[nodiscard]] std::string GenerateKey(int productId, std::string registrationName, int productFeature, int expiredYear, int expiredMonth, int expiredDate);
|
||||
[[nodiscard]] bool IsLicenseKeyValid(std::string licenseKey, std::string registrationName); // Only check the license key with registration name and expiration date only. This is used when developer to use internal APIs called
|
||||
[[nodiscard]] bool CheckLicenseKey(std::string licenseKey, std::string registrationName, int productId, int& enabledFeatures); // Check if the license key is valid
|
||||
[[nodiscard]] int ValidateLicense(std::string licenseKey, std::string registrationName, std::string& activationKey);
|
||||
[[nodiscard]] int ValidateLicenseWithCustomHWID(std::string licenseKey, std::string registrationName, std::string customHWID, std::string& activationKey);
|
||||
|
||||
[[nodiscard]] int GenerateOfflineActivationData(std::string licenseKey, std::string registrationName, std::string& offlineActivationData);
|
||||
[[nodiscard]] int InstallOfflineLicense(std::string licenseKey, std::string registrationName, std::string activationKey);
|
||||
|
||||
// Utilities
|
||||
[[nodiscard]] static int ExtractModelZipFile(std::string modelZipFile, std::string password, std::string modelName, std::string& extractedOutputFolder);
|
||||
[[nodiscard]] static bool ZipFolerWithPassword(std::string folderPath, std::string zipFilePath, std::string password);
|
||||
[[nodiscard]] static int PrepareEdgeModel(std::string modelZipFile, std::string zipFilePassword, std::string edgePassword, std::string modelName, std::string edgeSerialNumber, std::string& configFilePathName, std::string& labelMapPathName, std::string& outputModelFolder);
|
||||
[[nodiscard]] static std::string GetSystemHardwareInformation();
|
||||
[[nodiscard]] static bool ReleaseLogger();
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ANSLICENSE_API ANSLicenseHelper {
|
||||
private:
|
||||
[[nodiscard]] static bool deleteRecursively(const std::string& pathStr, bool safeMode);
|
||||
[[nodiscard]] static bool isPathSafe(const std::string& pathStr);
|
||||
public:
|
||||
[[nodiscard]] static bool LicenseVerification(std::string licenseKey, int productId, std::string registrationName);
|
||||
[[nodiscard]] static EngineType CheckHardwareInformation();
|
||||
[[nodiscard]] static std::string ListLicenses();
|
||||
[[nodiscard]] static int ActivateTrialLicense(std::string productName);
|
||||
[[nodiscard]] static int DeactivateLicense(std::string productName);
|
||||
[[nodiscard]] static int ActivateLicense(std::string productName, std::string licenseKey);
|
||||
[[nodiscard]] static int ActivateLicenseWithCustomHWID(std::string productName, std::string licenseKey, std::string hwid, std::string& activationKey);
|
||||
[[nodiscard]] static std::string DecodeValidationData(const char* validationData);
|
||||
[[nodiscard]] static std::string GenerateActivationDataFile(std::string activationKey,std::string licenseKey, std::string hardwareId, std::string validationData);
|
||||
[[nodiscard]] static std::string DecodeBase64(std::string base64String);
|
||||
[[nodiscard]] static bool RemoveTrialLicenseKeys(std::string registrationName);
|
||||
[[nodiscard]] static bool DeleleteRecursively(const std::string& pathStr) {
|
||||
return deleteRecursively(pathStr, true);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
extern "C" __declspec(dllexport) int CreateANSLSHandle(ANSCENTER::ANSLSHelper * *Handle, const char* privateKey, const char* publicKey, const char* licenseServiceURL);
|
||||
extern "C" __declspec(dllexport) int Release(ANSCENTER::ANSLSHelper * *Handle);
|
||||
extern "C" __declspec(dllexport) void SetLicenseServiceURL(ANSCENTER::ANSLSHelper * *Handle, const char* licenseServiceURL);
|
||||
extern "C" __declspec(dllexport) int GetLicenseData(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, LStrHandle licenseData);
|
||||
extern "C" __declspec(dllexport) int LoadLicenseTemplate(ANSCENTER::ANSLSHelper * *Handle, const char* templateFilePath);
|
||||
extern "C" __declspec(dllexport) int GetCurrentHardwareId(ANSCENTER::ANSLSHelper * *Handle, LStrHandle currentHwID);
|
||||
extern "C" __declspec(dllexport) int GenerateKey(ANSCENTER::ANSLSHelper * *Handle, int productId, const char* registrationName, int productFeature, int trialLicense, LStrHandle generatedKey);
|
||||
extern "C" __declspec(dllexport) int GenerateKeyWithExpiredDate(ANSCENTER::ANSLSHelper * *Handle, int productId, const char* registrationName, int productFeature, int expiredYear, int expiredMonth, int expiredDate, LStrHandle generatedKey);
|
||||
extern "C" __declspec(dllexport) int CheckLicenseKey(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, int productId);// , LStrHandle strEnableFeature); // Check if the license key is valid
|
||||
extern "C" __declspec(dllexport) int ValidateLicense(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, const char* existingActivationKey, LStrHandle activationKey);
|
||||
extern "C" __declspec(dllexport) int ActivateLicense(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, LStrHandle activationKey); // Always activate the license (need internet connection)
|
||||
extern "C" __declspec(dllexport) int ActivateLicenseWithCustomHWID(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, const char* hardwareId, LStrHandle activationKey); // Always activate the license (need internet connection)
|
||||
extern "C" __declspec(dllexport) int IsLicenseKeyValid(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName); // Only check the license key with registration name and expiration date only. This is used when developer to use internal APIs called
|
||||
extern "C" __declspec(dllexport) int GenerateOfflineActivationData(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, LStrHandle offlineActivationData);
|
||||
extern "C" __declspec(dllexport) int InstallOfflineLicense(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, const char* activationKey);
|
||||
|
||||
|
||||
// Utilities
|
||||
extern "C" __declspec(dllexport) int ExtractModelZipFile(const char* modelZipFile, const char* password, const char* modelName, LStrHandle extractedOutputFolder);
|
||||
extern "C" __declspec(dllexport) int ZipFolderToZipFile(const char* modelFolderSource,const char* modelZipFileDes, const char* password);
|
||||
extern "C" __declspec(dllexport) int PrepareEdgeModel(const char* modelZipFile, const char* zipFilePassword, const char* edgePassword, const char* modelName, const char* edgeSerialNumber, LStrHandle pathArray);
|
||||
extern "C" __declspec(dllexport) int GetSystemHardwareInformation(LStrHandle systemHardwareInformation);
|
||||
extern "C" __declspec(dllexport) int ReleaseLoggers();
|
||||
extern "C" __declspec(dllexport) int ListANSLicenses(std::string &listLicense);
|
||||
extern "C" __declspec(dllexport) int ListANSLicenses_LV(LStrHandle ansProductLicenses);
|
||||
extern "C" __declspec(dllexport) int ActivateTrialLicense(const char* productName);
|
||||
extern "C" __declspec(dllexport) int DeactivateLicense(const char* productName);
|
||||
extern "C" __declspec(dllexport) int ActivateProductLicense(const char* productName, const char* licenseKey);
|
||||
extern "C" __declspec(dllexport) int ActivateProductLicenseWithCustomHWID(const char* productName, const char* licenseKey, const char* hwid, LStrHandle lvActivationKey);
|
||||
extern "C" __declspec(dllexport) int GetRegistrationName(const char* validationData, LStrHandle registrationName);
|
||||
extern "C" __declspec(dllexport) int GenerateActivationKeyData(const char* activationKey, const char* licenseKey, const char* hardwareId, const char* validationData, LStrHandle activationData);
|
||||
extern "C" __declspec(dllexport) int ANSLicenseVerification(const char* licenseKey, int productId, const char* registrationName);
|
||||
extern "C" __declspec(dllexport) int ANSModelConversion(const char* zipModelFile, const char* zipModelPassword);
|
||||
extern "C" __declspec(dllexport) int DeletePathRecursively(const char* pathTobeDeleted);
|
||||
|
||||
#endif
|
||||
67
core/ANSLicensingSystem/CMakeLists.txt
Normal file
67
core/ANSLicensingSystem/CMakeLists.txt
Normal file
@@ -0,0 +1,67 @@
|
||||
# ANSLicensingSystem — DLL for license validation (also used by LabVIEW)
|
||||
add_library(ANSLicensingSystem SHARED
|
||||
ANSLicense.cpp
|
||||
ANSLicense.h
|
||||
Utility.cpp
|
||||
Utility.h
|
||||
pch.cpp
|
||||
pch.h
|
||||
framework.h
|
||||
dllmain.cpp
|
||||
)
|
||||
|
||||
target_include_directories(ANSLicensingSystem PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${SHARED_INCLUDE_DIR}
|
||||
# These are needed by consumers because ANSLicense.h / Utility.h include them
|
||||
${RESEARCH_DIR} # for LabVIEWHeader/extcode.h
|
||||
${ANSLIBS_DIR}/ZLIB/include # for zlib.h (Utility.h includes it)
|
||||
${VCPKG_INCLUDE_DIR} # for zip.h (Utility.h includes it)
|
||||
)
|
||||
|
||||
target_include_directories(ANSLicensingSystem PRIVATE
|
||||
${ANLS_ROOT}/ANSLIB/anszip
|
||||
${RESEARCH_DIR}/ANS-HWiNFO/include
|
||||
${RESEARCH_DIR}/spdlog-1.12.0/include
|
||||
)
|
||||
|
||||
target_link_libraries(ANSLicensingSystem
|
||||
PRIVATE anslicensing
|
||||
PRIVATE labview
|
||||
PRIVATE opencv
|
||||
PRIVATE zlib_dep
|
||||
PRIVATE spdlog_dep
|
||||
PRIVATE boost
|
||||
)
|
||||
|
||||
target_link_directories(ANSLicensingSystem PRIVATE
|
||||
${RESEARCH_DIR}/ANS-HWiNFO/lib
|
||||
${RESEARCH_DIR}/boost_lib
|
||||
${VCPKG_LIB_DIR}
|
||||
${ANLS_ROOT}/ANSLIB/anszip/x64/Release
|
||||
)
|
||||
|
||||
# BASE64 class — not exported from anslicensing.dll, compile directly
|
||||
target_include_directories(ANSLicensingSystem PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/core/anslicensing
|
||||
)
|
||||
target_sources(ANSLicensingSystem PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/core/anslicensing/base64.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(ANSLicensingSystem PRIVATE
|
||||
HWiNFO.lib OpenCL.lib OpenCLExt.lib
|
||||
bz2.lib zip.lib
|
||||
libboost_log-vc143-mt-x64-1_82.lib
|
||||
shlwapi.lib winhttp.lib
|
||||
${WIN_COMMON_LIBS}
|
||||
)
|
||||
|
||||
target_compile_definitions(ANSLicensingSystem PRIVATE
|
||||
ANSLICENSE_EXPORTS
|
||||
ANSLICENSINGSYSTEM_EXPORTS
|
||||
UNICODE _UNICODE
|
||||
_USRDLL
|
||||
)
|
||||
|
||||
target_precompile_headers(ANSLicensingSystem PRIVATE pch.h)
|
||||
895
core/ANSLicensingSystem/Utility.cpp
Normal file
895
core/ANSLicensingSystem/Utility.cpp
Normal file
@@ -0,0 +1,895 @@
|
||||
#include "Utility.h"
|
||||
#include <ctime>
|
||||
|
||||
template <typename T>
|
||||
T get_data(const boost::property_tree::ptree& pt, const std::string& key)
|
||||
{
|
||||
T ret;
|
||||
if (boost::optional<T> data = pt.get_optional<T>(key))
|
||||
{
|
||||
ret = data.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return T();
|
||||
//throw std::runtime_error("Could not read the data from ptree: [key: " + key + "]");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
// Convert file path to only the filename
|
||||
std::string path_to_filename(std::string path) {
|
||||
return path.substr(path.find_last_of("/\\") + 1);
|
||||
}
|
||||
std::string GetMainFolderDir() {
|
||||
std::string loggerDir = "C:\\ProgramData\\ANSCENTER";
|
||||
if (!FolderExist(loggerDir)) {
|
||||
CreateDirectory(loggerDir);
|
||||
}
|
||||
return loggerDir;
|
||||
}
|
||||
|
||||
std::string GetLoggerDir()
|
||||
{
|
||||
std::string mainFolderDir = GetMainFolderDir();
|
||||
#ifdef _WIN32
|
||||
const char pathSeparator = '\\'; // Windows uses backslash
|
||||
#else
|
||||
const char pathSeparator = '/'; // Unix-like systems use forward slash
|
||||
#endif
|
||||
std::string loggerDir = mainFolderDir+ pathSeparator+"Logs";
|
||||
if (!FolderExist(loggerDir)) {
|
||||
CreateDirectory(loggerDir);
|
||||
}
|
||||
return loggerDir;
|
||||
}
|
||||
std::string GetLicenseDir()
|
||||
{
|
||||
std::string mainFolderDir = GetMainFolderDir();
|
||||
#ifdef _WIN32
|
||||
const char pathSeparator = '\\'; // Windows uses backslash
|
||||
#else
|
||||
const char pathSeparator = '/'; // Unix-like systems use forward slash
|
||||
#endif
|
||||
std::string loggerDir = mainFolderDir + pathSeparator + "Licenses";
|
||||
if (!FolderExist(loggerDir)) {
|
||||
CreateDirectory(loggerDir);
|
||||
}
|
||||
return loggerDir;
|
||||
}
|
||||
std::wstring String2WString(const std::string input)
|
||||
{
|
||||
auto w = fs::path(input).wstring();
|
||||
return w;
|
||||
}
|
||||
std::string WString2String(const std::wstring input)
|
||||
{
|
||||
auto s = fs::path(input).string();
|
||||
return s;
|
||||
}
|
||||
std::string Dash2Underscore(std::string text)
|
||||
{
|
||||
std::replace(text.begin(), text.end(), '-', '_');
|
||||
return text;
|
||||
}
|
||||
std::string Underscore2Dash(std::string text) {
|
||||
std::replace(text.begin(), text.end(), '_', '-');
|
||||
return text;
|
||||
}
|
||||
std::string Space2Underscore(std::string text) {
|
||||
std::replace(text.begin(), text.end(), ' ', '_');
|
||||
return text;
|
||||
}
|
||||
|
||||
bool FileExist(const std::string& filePath) {
|
||||
return fs::exists(filePath) && fs::is_regular_file(filePath);
|
||||
}
|
||||
bool FolderExist(const std::string& folderPath) {
|
||||
return fs::is_directory(folderPath);
|
||||
}
|
||||
bool CreateDirectory(const std::string& folderPath) {
|
||||
try {
|
||||
fs::create_directory(folderPath);
|
||||
return true;
|
||||
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Creating directory: " << ex.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool RenameFile(const std::string& oldFilePath, const std::string& newFilePath) {
|
||||
try {
|
||||
fs::rename(oldFilePath, newFilePath);
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error renaming file: " << ex.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool CopyFile(const std::string& sourceFilePath, const std::string& destinationFilePath) {
|
||||
try {
|
||||
fs::copy_file(sourceFilePath, destinationFilePath, fs::copy_options::overwrite_existing);
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error copying file: " << ex.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void CopyFiles(const std::string& sourceFolder, const std::string& destinationFolder)
|
||||
{
|
||||
for (const auto& entry : std::filesystem::directory_iterator(sourceFolder))
|
||||
{
|
||||
if (entry.is_regular_file())
|
||||
{
|
||||
std::filesystem::copy(entry.path(), destinationFolder / entry.path().filename());
|
||||
}
|
||||
}
|
||||
}
|
||||
bool DeleteFile(const std::string& filePath) {
|
||||
try {
|
||||
fs::remove(filePath);
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error deleting file: " << ex.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
std::string FindFilePathInFileList(const std::vector<std::string>& vec, const std::string& substring)
|
||||
{
|
||||
auto it = std::find_if(vec.begin(), vec.end(), [&substring](const std::string& str) {
|
||||
return str.find(substring) != std::string::npos;
|
||||
});
|
||||
|
||||
return (it != vec.end()) ? *it : "";
|
||||
}
|
||||
bool DeleteLicenseFile(const std::string& filePath) {
|
||||
try {
|
||||
fs::remove(filePath);
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error deleting file: " << ex.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void ToLowerCase(std::string& str) {
|
||||
for (auto& c : str)
|
||||
{
|
||||
c = tolower(c);
|
||||
}
|
||||
}
|
||||
|
||||
std::string toLower(const std::string& str) {
|
||||
std::string result = str;
|
||||
std::transform(result.begin(), result.end(), result.begin(), ::tolower);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string GetFileExtension(const std::string& filePath) {
|
||||
fs::path path(filePath);
|
||||
std::string extensionFile= path.extension().string();
|
||||
ToLowerCase(extensionFile);
|
||||
return extensionFile;
|
||||
}
|
||||
std::vector<std::string> ListFilesInFolder(const std::string& folderPath) {
|
||||
std::vector<std::string> filePaths;
|
||||
try {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(folderPath)) {
|
||||
if (entry.is_regular_file()) {
|
||||
std::string filePath = entry.path().string();
|
||||
std::string fileName = GetFileNameWithoutExtension(filePath);
|
||||
std::string _licenseKey, _activationKey, _validationData;
|
||||
if (ReadLicenseKeyFile(filePath, _licenseKey, _activationKey, _validationData)) {
|
||||
filePaths.push_back(entry.path().string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error listing files in folder: " << ex.what() << std::endl;
|
||||
}
|
||||
|
||||
return filePaths;
|
||||
}
|
||||
void DeleteFilesInFolderExcept(const std::string& folderPath, const std::vector<std::string>& filesToKeep) {
|
||||
try {
|
||||
for (const auto& entry : fs::directory_iterator(folderPath)) {
|
||||
if (entry.is_regular_file()) {
|
||||
std::string fileName = entry.path().filename().string();
|
||||
if (std::find(filesToKeep.begin(), filesToKeep.end(), fileName) == filesToKeep.end()) {
|
||||
// File is not in the list of files to keep; delete it.
|
||||
fs::remove(entry.path());
|
||||
std::cout << "Deleted: " << entry.path() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error deleting files in folder: " << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
bool DeleteFolder(const std::string& folderPath) {
|
||||
try {
|
||||
fs::remove_all(folderPath);
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error deleting folder: " << ex.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
std::string GetFileNameWithoutExtension(const std::string& filePath) {
|
||||
fs::path path(filePath);
|
||||
return path.stem().string();
|
||||
}
|
||||
std::string ReadFileContent(std::string filePath) {
|
||||
std::ifstream ifs(filePath);
|
||||
return std::string((std::istreambuf_iterator<char>(ifs)),
|
||||
(std::istreambuf_iterator<char>()));
|
||||
}
|
||||
std::string ReadFileAsBinary(const std::string& filename) {
|
||||
std::ifstream file(filename, std::ios::binary);
|
||||
if (!file) {
|
||||
std::cerr << "Failed to open file: " << filename << std::endl;
|
||||
return ""; // Return an empty string to indicate failure
|
||||
}
|
||||
|
||||
// Read the file content into a stringstream
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
|
||||
// Convert the stringstream to a string
|
||||
return buffer.str();
|
||||
}
|
||||
int ReadAllBytes(std::string filePath, std::vector<char>& allDataBytes) {
|
||||
// Open the file in binary mode
|
||||
std::ifstream file(filePath, std::ios::binary);
|
||||
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "Failed to open file." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get the file size
|
||||
file.seekg(0, std::ios::end);
|
||||
std::streampos fileSize = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
// Create a vector to store the file data
|
||||
std::vector<char> fileData(fileSize);
|
||||
|
||||
// Read the file into the vector
|
||||
if (!file.read(fileData.data(), fileSize)) {
|
||||
std::cerr << "Failed to read file." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
allDataBytes = fileData;
|
||||
|
||||
return 0;
|
||||
}
|
||||
// Functionto get parent folder path (C:\ParentFolder\FileName) -> C:\ParentFolder
|
||||
std::string GetParentFolder(const std::string& filePath) {
|
||||
size_t lastSlashPos = filePath.find_last_of("/\\"); // Handle both '/' and '\'
|
||||
if (lastSlashPos != std::string::npos) {
|
||||
return filePath.substr(0, lastSlashPos);
|
||||
}
|
||||
return ""; // Return an empty string if there is no folder
|
||||
}
|
||||
// Function to extract the folder name from a file path or file name
|
||||
std::string ExtractFolderName(const std::string& directoryPath) {
|
||||
std::filesystem::path path(directoryPath);
|
||||
return path.stem().string();
|
||||
}
|
||||
// Function to create a file path from a folder name and a file name
|
||||
std::string CreateFilePath(const std::string& folderName, const std::string& fileName) {
|
||||
#ifdef _WIN32
|
||||
const char pathSeparator = '\\'; // Windows uses backslash
|
||||
#else
|
||||
const char pathSeparator = '/'; // Unix-like systems use forward slash
|
||||
#endif
|
||||
std::string folder = folderName;
|
||||
if (!folder.empty() && folder.back() != pathSeparator) {
|
||||
folder += pathSeparator;
|
||||
}
|
||||
return folder + fileName;
|
||||
}
|
||||
|
||||
std::filesystem::path GetSafeTempDirectory() {
|
||||
std::filesystem::path systemTemp = std::filesystem::temp_directory_path();
|
||||
std::filesystem::path fallbackTemp = "C:\\ProgramData\\Jh7O7nUe7vS\\";
|
||||
|
||||
// Ensure fallback directory exists
|
||||
if (!std::filesystem::exists(fallbackTemp)) {
|
||||
try {
|
||||
std::filesystem::create_directories(fallbackTemp);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "Failed to create fallback temp directory: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert systemTemp to lowercase string for checking
|
||||
std::string systemTempStr = toLower(systemTemp.string());
|
||||
|
||||
// Check if systemTemp does not exist or contains "c:\windows"
|
||||
if (!std::filesystem::exists(systemTemp) ||
|
||||
systemTempStr.find("windows") != std::string::npos) {
|
||||
return fallbackTemp;
|
||||
}
|
||||
|
||||
return systemTemp;
|
||||
}
|
||||
std::string GenerateOutputFolder(std::string modelFilePath, std::string modelName, bool edgeDeviceModel) {
|
||||
// Get the path to the Temp folder
|
||||
std::filesystem::path tempFolderPath = GetSafeTempDirectory();
|
||||
std::string outputFolder = "";
|
||||
outputFolder.clear();
|
||||
if (std::filesystem::exists(tempFolderPath)) {
|
||||
std::string strTempPath = tempFolderPath.string();
|
||||
#ifdef _WIN32
|
||||
const char pathSeparator = '\\'; // Windows uses backslash
|
||||
#else
|
||||
const char pathSeparator = '/'; // Unix-like systems use forward slash
|
||||
#endif
|
||||
std::string baseFolder = strTempPath + "Models";
|
||||
if(!FolderExist(baseFolder)) {
|
||||
CreateDirectory(baseFolder);
|
||||
}
|
||||
std::string EdgeModelsFolder = baseFolder + pathSeparator + "EdgeModels";
|
||||
if (!FolderExist(EdgeModelsFolder)) {
|
||||
CreateDirectory(EdgeModelsFolder);
|
||||
}
|
||||
std::string EngineModelsFolder = baseFolder + pathSeparator + "EngineModels";
|
||||
if (!FolderExist(EngineModelsFolder)) {
|
||||
CreateDirectory(EngineModelsFolder);
|
||||
}
|
||||
if(edgeDeviceModel)
|
||||
outputFolder = EdgeModelsFolder + pathSeparator + modelName;
|
||||
else
|
||||
outputFolder = EngineModelsFolder + pathSeparator + modelName;
|
||||
return outputFolder;
|
||||
}
|
||||
else {
|
||||
return outputFolder;
|
||||
}
|
||||
}
|
||||
|
||||
bool ExtractPasswordProtectedZip(const std::string& zipFileName,
|
||||
const std::string& password,
|
||||
const std::string& modelName,
|
||||
std::string& outputFolder,
|
||||
bool edgeDeviceModel) {
|
||||
outputFolder = GenerateOutputFolder(zipFileName, modelName, edgeDeviceModel);
|
||||
return ExtractProtectedZipFile(zipFileName, password, modelName, outputFolder);
|
||||
}
|
||||
|
||||
|
||||
bool AddFileToZip(zip* archive, const char* filePath, const char* zipPath, const char* password) {
|
||||
struct zip_source* source = zip_source_file(archive, filePath, 0, 0);
|
||||
if (!source) {
|
||||
std::cerr << "Failed to add file '" << filePath << "' to ZIP archive." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (zip_file_add(archive, zipPath, source, ZIP_FL_OVERWRITE) == -1) {
|
||||
std::cerr << "Failed to add file '" << filePath << "' to ZIP archive." << std::endl;
|
||||
zip_source_free(source);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the index of the added file
|
||||
zip_int64_t fileIndex = zip_name_locate(archive, zipPath, 0);
|
||||
if (fileIndex < 0) {
|
||||
std::cerr << "Failed to locate file '" << zipPath << "' in ZIP archive." << std::endl;
|
||||
zip_source_free(source);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set encryption for the added file
|
||||
if (zip_file_set_encryption(archive, fileIndex, ZIP_EM_AES_256, password) == -1) {
|
||||
std::cerr << "Failed to set encryption for file '" << zipPath << "' in ZIP archive." << std::endl;
|
||||
zip_source_free(source);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddFolderContentsToZip(zip* archive, const char* folderPath, const char* zipPath, const char* password) {
|
||||
try {
|
||||
fs::path dir(folderPath);
|
||||
|
||||
if (!fs::exists(dir) || !fs::is_directory(dir)) {
|
||||
std::cerr << "Failed to open directory '" << folderPath << "'." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const fs::directory_entry& entry : fs::directory_iterator(dir)) {
|
||||
std::string entryName = entry.path().filename().string();
|
||||
std::string entryPath = (zipPath && zipPath[0] != '\0') ? std::string(zipPath) + "/" + entryName : entryName;
|
||||
std::string filePath = folderPath + std::string("/") + entryName;
|
||||
|
||||
if (fs::is_directory(entry.status())) {
|
||||
if (entryName != "." && entryName != "..") {
|
||||
if (!AddFolderContentsToZip(archive, filePath.c_str(), entryPath.c_str(), password)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!AddFileToZip(archive, filePath.c_str(), entryPath.c_str(), password)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error: " << ex.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ZipFolderWithPassword(const char* folderPath, const char* zipFilePath, const char* password) {
|
||||
zip* zipArchive;
|
||||
zip_flags_t flags = ZIP_CREATE | ZIP_TRUNCATE;
|
||||
//std::cout << "Open Zip File: " << zipFilePath << std::endl;
|
||||
zipArchive = zip_open(zipFilePath, flags, nullptr);
|
||||
if (!zipArchive) {
|
||||
std::cerr << "Failed to create ZIP archive." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set a password for the ZIP file
|
||||
if (zip_set_default_password(zipArchive, password) == -1) {
|
||||
std::cerr << "Failed to set the password for the ZIP file." << std::endl;
|
||||
zip_close(zipArchive);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add folder contents to the ZIP archive
|
||||
if (!AddFolderContentsToZip(zipArchive, folderPath, "", password)) {
|
||||
zip_close(zipArchive);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Save the ZIP archive to the file
|
||||
if (zip_close(zipArchive) == -1) {
|
||||
std::cerr << "Failed to save the ZIP archive to the file." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string VectorToCommaSeparatedString(const std::vector<std::string>& inputVector) {
|
||||
std::string result;
|
||||
for (size_t i = 0; i < inputVector.size(); ++i) {
|
||||
result += inputVector[i];
|
||||
if (i < inputVector.size() - 1) {
|
||||
result += ",";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
std::string VectorToSeparatedString(const std::vector<std::string>& inputVector) {
|
||||
std::string result;
|
||||
for (size_t i = 0; i < inputVector.size(); ++i) {
|
||||
result += inputVector[i];
|
||||
if (i < inputVector.size() - 1) {
|
||||
result += ";";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
std::vector<std::string> Split(const std::string str, const std::string regex_str) {
|
||||
std::regex regexz(regex_str);
|
||||
return { std::sregex_token_iterator(str.begin(), str.end(), regexz, -1),
|
||||
std::sregex_token_iterator() };
|
||||
}
|
||||
|
||||
std::vector<std::string> GetTrialLicenseKeyFiles(std::string registrationName) {
|
||||
std::vector < std::string> trialLicenseKeyFiles;
|
||||
std::string trialLicenseKeyFileName = registrationName + "_Trial.lic";
|
||||
if (CreateDirectory("C:\\ProgramData\\Apple")) {
|
||||
std::string trialLicenseKeyFile1 = CreateFilePath("C:\\ProgramData\\Apple", trialLicenseKeyFileName);
|
||||
trialLicenseKeyFiles.push_back(trialLicenseKeyFile1);
|
||||
}
|
||||
if (CreateDirectory("C:\\ProgramData\\Licenses")) {
|
||||
std::string trialLicenseKeyFile2 = CreateFilePath("C:\\ProgramData\\Licenses", trialLicenseKeyFileName);
|
||||
trialLicenseKeyFiles.push_back(trialLicenseKeyFile2);
|
||||
}
|
||||
if (CreateDirectory("C:\\ProgramData\\McAfee")) {
|
||||
std::string trialLicenseKeyFile3 = CreateFilePath("C:\\ProgramData\\McAfee", trialLicenseKeyFileName);
|
||||
trialLicenseKeyFiles.push_back(trialLicenseKeyFile3);
|
||||
}
|
||||
if (CreateDirectory("C:\\ProgramData\\NVIDIA")) {
|
||||
std::string trialLicenseKeyFile4 = CreateFilePath("C:\\ProgramData\\NVIDIA", trialLicenseKeyFileName);
|
||||
trialLicenseKeyFiles.push_back(trialLicenseKeyFile4);
|
||||
}
|
||||
if (CreateDirectory("C:\\ProgramData\\National Instruments")) {
|
||||
std::string trialLicenseKeyFile5 = CreateFilePath("C:\\ProgramData\\National Instruments", trialLicenseKeyFileName);
|
||||
trialLicenseKeyFiles.push_back(trialLicenseKeyFile5);
|
||||
}
|
||||
if (CreateDirectory("C:\\ProgramData\\Microsoft")) {
|
||||
std::string trialLicenseKeyFile6 = CreateFilePath("C:\\ProgramData\\Microsoft", trialLicenseKeyFileName);
|
||||
trialLicenseKeyFiles.push_back(trialLicenseKeyFile6);
|
||||
}
|
||||
return trialLicenseKeyFiles;
|
||||
}
|
||||
bool ReadLicenseKeyFile(std::string licenseKeyFilePath, std::string& licenseKey, std::string& activationKey, std::string& validationData) {
|
||||
try {
|
||||
if (!FileExist(licenseKeyFilePath))return false;
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_json(licenseKeyFilePath, pt);
|
||||
|
||||
auto itLicenseKey = pt.get_child("license_key");
|
||||
licenseKey = itLicenseKey.get_value<std::string>();
|
||||
|
||||
auto itActivationKey = pt.get_child("activation_key");
|
||||
activationKey = itActivationKey.get_value<std::string>();
|
||||
|
||||
auto itRegistrationName = pt.get_child("license_key_validation_data");
|
||||
validationData = itRegistrationName.get_value<std::string>();
|
||||
|
||||
if ((licenseKey.empty()) ||
|
||||
(activationKey.empty()) ||
|
||||
(validationData.empty())) return false;
|
||||
return true;
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
std::cout<<"Read License key"<< e.what()<< std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
std::string GetTrialLicenseKey(std::string registrationName) {
|
||||
std::string trialLicenseKey;
|
||||
std::vector<std::string> trialLicenseKeys;
|
||||
trialLicenseKeys.clear();
|
||||
|
||||
// Get all licenseKeys from vavious places
|
||||
std::vector < std::string> trialLicenseKeyFiles =GetTrialLicenseKeyFiles(registrationName);
|
||||
size_t trialSize = trialLicenseKeyFiles.size();
|
||||
for (size_t i = 0; i < trialSize; i++) {
|
||||
std::string trialLicenseFile = trialLicenseKeyFiles[i];
|
||||
if (FileExist(trialLicenseFile)) {
|
||||
std::string trialLicenseKey = ReadFileContent(trialLicenseFile);
|
||||
trialLicenseKeys.push_back(trialLicenseKey);
|
||||
}
|
||||
}
|
||||
sort(trialLicenseKeys.begin(), trialLicenseKeys.end());
|
||||
trialLicenseKeys.erase(unique(trialLicenseKeys.begin(), trialLicenseKeys.end()), trialLicenseKeys.end());
|
||||
|
||||
size_t lSize = trialLicenseKeys.size();
|
||||
if (lSize == 1) trialLicenseKey = trialLicenseKeys[0];
|
||||
return trialLicenseKey;
|
||||
}
|
||||
|
||||
bool UpdateTrialLicenseKey(std::string trialLicenseKey, std::string registrationName) {
|
||||
try {
|
||||
std::vector < std::string> trialLicenseKeyFiles = GetTrialLicenseKeyFiles(registrationName);
|
||||
size_t trialSize = trialLicenseKeyFiles.size();
|
||||
for (size_t i = 0; i < trialSize; i++) {
|
||||
try {
|
||||
std::string trialLicenseFile = trialLicenseKeyFiles[i];
|
||||
std::ofstream(trialLicenseFile) << trialLicenseKey;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error: " << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error: " << ex.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool RemoveTrialLicenseKey(std::string registrationName) {
|
||||
try {
|
||||
std::vector < std::string> trialLicenseKeyFiles = GetTrialLicenseKeyFiles(registrationName);
|
||||
size_t trialSize = trialLicenseKeyFiles.size();
|
||||
for (size_t i = 0; i < trialSize; i++) {
|
||||
try {
|
||||
DeleteFile(trialLicenseKeyFiles[i]);
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error: " << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error: " << ex.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int GetExpirationDate(std::string licenseData, int &productId) {
|
||||
if (licenseData.empty()) return -1;
|
||||
int remainDate = -1;
|
||||
std::stringstream ss;
|
||||
ss << licenseData;
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_json(ss, pt);
|
||||
auto rootNode = pt.get_child("licenseData");
|
||||
auto childNode = rootNode.get_child("remaining_days");
|
||||
remainDate = childNode.get_value<int>();
|
||||
|
||||
childNode = rootNode.get_child("valid_product_id");
|
||||
productId = childNode.get_value<int>();
|
||||
|
||||
return remainDate;
|
||||
}
|
||||
|
||||
|
||||
std::string GetStringCurrentDateTime() {
|
||||
// Get the current time
|
||||
std::time_t t = std::time(nullptr);
|
||||
std::tm now = {}; // Initialize to all zeros
|
||||
localtime_s(&now, &t);
|
||||
// Convert the time to a string
|
||||
std::stringstream ss;
|
||||
ss << std::put_time(&now, "%Y%m%d%H%M%S");
|
||||
std::string currentDateTime = ss.str();
|
||||
return currentDateTime;
|
||||
}
|
||||
|
||||
std::string GetDateTimeString(const std::string& format) {
|
||||
// Get the current time
|
||||
std::time_t t = std::time(nullptr);
|
||||
std::tm now = {}; // Initialize to all zeros
|
||||
localtime_s(&now, &t);
|
||||
// Convert the time to a string
|
||||
std::stringstream ss;
|
||||
ss << std::put_time(&now, format.c_str());
|
||||
std::string currentDateTime = ss.str();
|
||||
return currentDateTime;
|
||||
}
|
||||
|
||||
// For traing engine
|
||||
//bool ExtractProtectedZipFile(const std::string& zipFileName, const std::string& password, const std::string& modelName, const std::string outputFolder)
|
||||
//{
|
||||
// int error;
|
||||
// if (!FileExist(zipFileName))return false;
|
||||
// zip_t* archive = zip_open(zipFileName.c_str(), ZIP_RDONLY, &error);
|
||||
// if (!archive) {
|
||||
// std::cerr << "Error opening ZIP archive: " << zip_strerror(archive) << std::endl;
|
||||
// return false;
|
||||
// }
|
||||
// try {
|
||||
// if (!password.empty()) {
|
||||
// if (zip_set_default_password(archive, password.c_str()) == -1) {
|
||||
// std::cerr << "Error setting password: " << zip_strerror(archive) << std::endl;
|
||||
// zip_close(archive);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// int numEntries = (int)zip_get_num_entries(archive, 0);
|
||||
// for (int i = 0; i < numEntries; i++) {
|
||||
// zip_file_t* file = zip_fopen_index(archive, i, 0);
|
||||
// if (!file) {
|
||||
// std::cerr << "Error opening file in ZIP: " << zip_strerror(archive) << std::endl;
|
||||
// zip_close(archive);
|
||||
// return false;
|
||||
// }
|
||||
// // Check if the folder exists
|
||||
// if (!std::filesystem::exists(outputFolder)) {
|
||||
// // Folder does not exist, so create it
|
||||
// try {
|
||||
// std::filesystem::create_directories(outputFolder);
|
||||
// }
|
||||
// catch (const std::exception& ex) {
|
||||
// std::cerr << "Error opening file in ZIP: " << ex.what() << std::endl;
|
||||
// zip_close(archive);
|
||||
// zip_fclose(file);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// try {// otherwise extract to the output folder
|
||||
// const char* filename = zip_get_name(archive, i, 0);
|
||||
// std::string outputPath = CreateFilePath(outputFolder, filename);
|
||||
//
|
||||
// // Check if filename ends with '/' indicating it's a directory
|
||||
// if (outputPath.back() == '/') {// Create the directory and its parents as needed
|
||||
// fs::create_directories(outputPath);
|
||||
// }
|
||||
// else {// Proceed to extract the file
|
||||
// std::ofstream output(outputPath, std::ios::binary);
|
||||
// if (!output.is_open()) {
|
||||
// zip_fclose(file);
|
||||
// }
|
||||
// else {
|
||||
// const size_t buffer_size = 4096;
|
||||
// unsigned char buffer[buffer_size];
|
||||
// zip_int64_t bytesRead;
|
||||
// while ((bytesRead = zip_fread(file, buffer, buffer_size)) > 0) {
|
||||
// output.write(reinterpret_cast<char*>(buffer), bytesRead);
|
||||
// }
|
||||
// zip_fclose(file);
|
||||
// output.close();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (const std::exception& ex) {
|
||||
// std::cerr << "Error creating output file: " << ex.what() << std::endl;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (...) {
|
||||
// zip_close(archive);
|
||||
// return false;
|
||||
// }
|
||||
// zip_close(archive);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
//bool ExtractProtectedZipFile(const std::string& zipFileName, const std::string& password, const std::string& modelName, const std::string outputFolder) {
|
||||
// int error;
|
||||
// if (!FileExist(zipFileName)) return false;
|
||||
//
|
||||
// zip_t* archive = zip_open(zipFileName.c_str(), ZIP_RDONLY, &error);
|
||||
// if (!archive) {
|
||||
// std::cerr << "Error opening ZIP archive: " << zip_strerror(archive) << std::endl;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// if (!password.empty()) {
|
||||
// if (zip_set_default_password(archive, password.c_str()) == -1) {
|
||||
// std::cerr << "Error setting password: " << zip_strerror(archive) << std::endl;
|
||||
// zip_close(archive);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// int numEntries = static_cast<int>(zip_get_num_entries(archive, 0));
|
||||
// for (int i = 0; i < numEntries; i++) {
|
||||
// zip_file_t* file = zip_fopen_index(archive, i, 0);
|
||||
// if (!file) {
|
||||
// std::cerr << "Error opening file in ZIP: " << zip_strerror(archive) << std::endl;
|
||||
// zip_close(archive);
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// // Check and create the output folder if necessary
|
||||
// if (!std::filesystem::exists(outputFolder)) {
|
||||
// try {
|
||||
// std::filesystem::create_directories(outputFolder);
|
||||
// }
|
||||
// catch (const std::exception& ex) {
|
||||
// std::cerr << "Error creating output directory: " << ex.what() << std::endl;
|
||||
// zip_fclose(file);
|
||||
// zip_close(archive);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// const char* filename = zip_get_name(archive, i, 0);
|
||||
// std::string outputPath = CreateFilePath(outputFolder, filename);
|
||||
//
|
||||
// // Check if the path is a directory and create it if necessary
|
||||
// if (outputPath.back() == '/') {
|
||||
// std::filesystem::create_directories(outputPath);
|
||||
// }
|
||||
// else {
|
||||
// std::ofstream output(outputPath, std::ios::binary);
|
||||
// if (!output.is_open()) {
|
||||
// std::cerr << "Error creating output file: " << outputPath << std::endl;
|
||||
// zip_fclose(file);
|
||||
// zip_close(archive);
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// const size_t buffer_size = 4096;
|
||||
// unsigned char buffer[buffer_size];
|
||||
// zip_int64_t bytesRead;
|
||||
// while ((bytesRead = zip_fread(file, buffer, buffer_size)) > 0) {
|
||||
// output.write(reinterpret_cast<char*>(buffer), bytesRead);
|
||||
// }
|
||||
//
|
||||
// output.close();
|
||||
// }
|
||||
//
|
||||
// zip_fclose(file);
|
||||
// }
|
||||
// catch (const std::exception& ex) {
|
||||
// std::cerr << "Error creating output file: " << ex.what() << std::endl;
|
||||
// zip_fclose(file);
|
||||
// zip_close(archive);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (...) {
|
||||
// zip_close(archive);
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// zip_close(archive);
|
||||
// return true;
|
||||
//}
|
||||
bool ExtractProtectedZipFile(const std::string& zipFileName, const std::string& password, const std::string& modelName, const std::string outputFolder)
|
||||
{
|
||||
int error;
|
||||
if (!FileExist(zipFileName))return false;
|
||||
zip_t* archive = zip_open(zipFileName.c_str(), ZIP_RDONLY, &error);
|
||||
if (!archive) {
|
||||
std::cerr << "Error opening ZIP archive: " << zip_strerror(archive) << std::endl;
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (!password.empty()) {
|
||||
if (zip_set_default_password(archive, password.c_str()) == -1) {
|
||||
std::cerr << "Error setting password: " << zip_strerror(archive) << std::endl;
|
||||
zip_close(archive);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int numEntries = (int)zip_get_num_entries(archive, 0);
|
||||
for (int i = 0; i < numEntries; i++) {
|
||||
zip_file_t* file = zip_fopen_index(archive, i, 0);
|
||||
if (!file) {
|
||||
std::cerr << "Error opening file in ZIP: " << zip_strerror(archive) << std::endl;
|
||||
zip_close(archive);
|
||||
return false;
|
||||
}
|
||||
// Check if the folder exists
|
||||
if (!std::filesystem::exists(outputFolder)) {
|
||||
// Folder does not exist, so create it
|
||||
try {
|
||||
std::filesystem::create_directories(outputFolder);
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error opening file in ZIP: " << ex.what() << std::endl;
|
||||
zip_close(archive);
|
||||
zip_fclose(file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {// otherwise extract to the output folder
|
||||
const char* filename = zip_get_name(archive, i, 0);
|
||||
std::string outputPath = CreateFilePath(outputFolder, filename);
|
||||
|
||||
// Check if filename ends with '/' indicating it's a directory
|
||||
if (outputPath.back() == '/') {// Create the directory and its parents as needed
|
||||
fs::create_directories(outputPath);
|
||||
}
|
||||
else {// Proceed to extract the file
|
||||
std::ofstream output(outputPath, std::ios::binary);
|
||||
if (!output.is_open()) {
|
||||
zip_fclose(file);
|
||||
}
|
||||
else {
|
||||
const size_t buffer_size = 4096;
|
||||
unsigned char buffer[buffer_size];
|
||||
zip_int64_t bytesRead;
|
||||
while ((bytesRead = zip_fread(file, buffer, buffer_size)) > 0) {
|
||||
output.write(reinterpret_cast<char*>(buffer), bytesRead);
|
||||
}
|
||||
zip_fclose(file);
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << "Error creating output file: " << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
zip_close(archive);
|
||||
return false;
|
||||
}
|
||||
zip_close(archive);
|
||||
return true;
|
||||
}
|
||||
|
||||
92
core/ANSLicensingSystem/Utility.h
Normal file
92
core/ANSLicensingSystem/Utility.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#pragma once
|
||||
#ifndef UTILITY_H
|
||||
#define UTILITY_H
|
||||
#include "ANSLicense.h"
|
||||
#include <boost/date_time.hpp>
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include "boost/property_tree/ptree.hpp"
|
||||
#include "boost/property_tree/json_parser.hpp"
|
||||
#include "boost/foreach.hpp"
|
||||
|
||||
#include <zlib.h>
|
||||
#include <zip.h>
|
||||
#include <filesystem>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <regex>
|
||||
#include <stdio.h>
|
||||
|
||||
//namespace logging = boost::log;
|
||||
//namespace attrs = boost::log::attributes;
|
||||
//namespace expr = boost::log::expressions;
|
||||
//namespace src = boost::log::sources;
|
||||
//namespace keywords = boost::log::keywords;
|
||||
//namespace sinks = boost::log::sinks;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) ((a) > (b) ? (b) : (a))
|
||||
#endif
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) ((a) < (b) ? (b) : (a))
|
||||
#endif
|
||||
#define DETECT_BUFFER_SIZE 0x9000
|
||||
|
||||
|
||||
ANSLICENSE_API std::string path_to_filename(std::string path);
|
||||
ANSLICENSE_API std::string GetMainFolderDir();
|
||||
ANSLICENSE_API std::string GetLoggerDir();
|
||||
ANSLICENSE_API std::string GetLicenseDir();
|
||||
// Convert file path to only the filename
|
||||
ANSLICENSE_API std::wstring String2WString(const std::string input);
|
||||
ANSLICENSE_API std::string WString2String(const std::wstring input);
|
||||
ANSLICENSE_API std::string Dash2Underscore(std::string text);
|
||||
ANSLICENSE_API std::string Underscore2Dash(std::string text);
|
||||
ANSLICENSE_API std::string Space2Underscore(std::string text);
|
||||
|
||||
[[nodiscard]] ANSLICENSE_API bool FileExist(const std::string& filePath);
|
||||
[[nodiscard]] ANSLICENSE_API bool FolderExist(const std::string& folderPath);
|
||||
[[nodiscard]] ANSLICENSE_API bool CreateDirectory(const std::string& folderPath);
|
||||
|
||||
[[nodiscard]] ANSLICENSE_API bool RenameFile(const std::string& oldFilePath, const std::string& newFilePath);
|
||||
[[nodiscard]] ANSLICENSE_API bool CopyFile(const std::string& sourceFilePath, const std::string& destinationFilePath);
|
||||
ANSLICENSE_API void CopyFiles(const std::string& sourceFolder, const std::string& destinationFolder);
|
||||
[[nodiscard]] ANSLICENSE_API bool DeleteFile(const std::string& filePath);
|
||||
[[nodiscard]] ANSLICENSE_API bool DeleteLicenseFile(const std::string& filePath);
|
||||
[[nodiscard]] ANSLICENSE_API std::vector<std::string> ListFilesInFolder(const std::string& folderPath);
|
||||
ANSLICENSE_API void DeleteFilesInFolderExcept(const std::string& folderPath, const std::vector<std::string>& filesToKeep);
|
||||
[[nodiscard]] ANSLICENSE_API bool DeleteFolder(const std::string& folderPath);
|
||||
ANSLICENSE_API void ToLowerCase(std::string& str);
|
||||
ANSLICENSE_API std::string toLower(const std::string& str);
|
||||
ANSLICENSE_API std::string GetFileExtension(const std::string& filePath);
|
||||
ANSLICENSE_API std::string GetFileNameWithoutExtension(const std::string& filePath);
|
||||
ANSLICENSE_API std::string FindFilePathInFileList(const std::vector<std::string>& fileList, const std::string& fileName);
|
||||
ANSLICENSE_API std::string ReadFileContent(std::string filePath);
|
||||
ANSLICENSE_API std::string ReadFileAsBinary(const std::string& filename);
|
||||
ANSLICENSE_API int ReadAllBytes(std::string filePath, std::vector<char>& allDataBytes);
|
||||
ANSLICENSE_API std::string ExtractFolderName(const std::string& filePath); // Function to extract the folder name from a file path or file name
|
||||
ANSLICENSE_API std::string GetParentFolder(const std::string& directoryPath);// Function to extract the folder name from a file path or file name
|
||||
ANSLICENSE_API std::string CreateFilePath(const std::string& folderName, const std::string& fileName);// Function to create a file path from a folder name and a file name
|
||||
ANSLICENSE_API std::filesystem::path GetSafeTempDirectory();
|
||||
ANSLICENSE_API std::string GenerateOutputFolder(std::string modelFilePath, std::string modelName, bool edgeDeviceModel=true);
|
||||
ANSLICENSE_API bool ExtractPasswordProtectedZip(const std::string& zipFileName, const std::string& password, const std::string& modelName, std::string& outputFolder, bool edgeDeviceModel = true);
|
||||
ANSLICENSE_API bool AddFileToZip(zip* archive, const char* filePath, const char* zipPath, const char* password);
|
||||
ANSLICENSE_API bool AddFolderContentsToZip(zip* archive, const char* folderPath, const char* zipPath, const char* password);
|
||||
ANSLICENSE_API bool ZipFolderWithPassword(const char* folderPath, const char* zipFilePath, const char* password);
|
||||
ANSLICENSE_API std::string VectorToCommaSeparatedString(const std::vector<std::string>& inputVector);
|
||||
ANSLICENSE_API std::string VectorToSeparatedString(const std::vector<std::string>& inputVector);
|
||||
ANSLICENSE_API std::vector<std::string> Split(const std::string str, const std::string regex_str);
|
||||
ANSLICENSE_API bool ReadLicenseKeyFile(std::string licenseKeyFilePath, std::string& licenseKey, std::string& activationKey, std::string& validationData);
|
||||
ANSLICENSE_API std::vector<std::string> GetTrialLicenseKeyFiles(std::string registrationName);
|
||||
ANSLICENSE_API std::string GetTrialLicenseKey(std::string registrationName);
|
||||
ANSLICENSE_API bool UpdateTrialLicenseKey(std::string trialLicenseKey, std::string registrationName);
|
||||
ANSLICENSE_API int GetExpirationDate(std::string licenseData, int& productId);
|
||||
ANSLICENSE_API bool RemoveTrialLicenseKey(std::string registrationName);
|
||||
ANSLICENSE_API std::string GetStringCurrentDateTime(); // Return current datetime in string format
|
||||
ANSLICENSE_API std::string GetDateTimeString(const std::string& format);
|
||||
// For training engine
|
||||
//bool ExtractPasswordProtectedZipForTrainingEgnine(const std::string& zipFileName, const std::string& password, const std::string& modelName, std::string& outputFolder, bool edgeDeviceModel = true);
|
||||
ANSLICENSE_API bool ExtractProtectedZipFile(const std::string& zipFileName,const std::string& password,const std::string& modelName,const std::string outputFolder);
|
||||
#endif
|
||||
554
core/ANSLicensingSystem/dllmain.cpp
Normal file
554
core/ANSLicensingSystem/dllmain.cpp
Normal file
@@ -0,0 +1,554 @@
|
||||
// dllmain.cpp : Defines the entry point for the DLL application.
|
||||
#include "pch.h"
|
||||
#include "ANSLicense.h"
|
||||
#include "Utility.h"
|
||||
|
||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int CreateANSLSHandle(ANSCENTER::ANSLSHelper * *Handle, const char* privateKey, const char* publicKey, const char* licenseServiceURL) {
|
||||
try {
|
||||
if (!Handle || !privateKey || !publicKey || !licenseServiceURL) return 0;
|
||||
std::string st_privateKey = privateKey;
|
||||
std::string st_publicKey = publicKey;
|
||||
std::string st_licenseServiceURL = licenseServiceURL;
|
||||
(*Handle) = new ANSCENTER::ANSLSHelper(st_privateKey, st_publicKey, st_licenseServiceURL);
|
||||
if (*Handle == nullptr) return 0;
|
||||
else return 1;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int Release(ANSCENTER::ANSLSHelper * *Handle) {
|
||||
try {
|
||||
if (!Handle || !(*Handle)) return 1; // already released
|
||||
delete* Handle;
|
||||
*Handle = nullptr;
|
||||
return 1;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) void SetLicenseServiceURL(ANSCENTER::ANSLSHelper * *Handle, const char* licenseServiceURL) {
|
||||
if (!Handle || !(*Handle) || !licenseServiceURL) return;
|
||||
(*Handle)->SetLicenseServiceURL(licenseServiceURL);
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GetLicenseData(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, LStrHandle licenseData) {
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !licenseKey) return 0;
|
||||
std::string st = (*Handle)->GetLicenseData(licenseKey);
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(licenseData, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*licenseData)->cnt = size;
|
||||
memcpy((*licenseData)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int LoadLicenseTemplate(ANSCENTER::ANSLSHelper * *Handle, const char* templateFilePath) {
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !templateFilePath) return 0;
|
||||
bool result = (*Handle)->LoadLicenseTemplate(templateFilePath);
|
||||
if (result == true) return 1;
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GetCurrentHardwareId(ANSCENTER::ANSLSHelper * *Handle, LStrHandle currentHwID) {
|
||||
try {
|
||||
if (!Handle || !(*Handle)) return 0;
|
||||
std::string st = (*Handle)->GetCurrentHardwareId();
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(currentHwID, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*currentHwID)->cnt = size;
|
||||
memcpy((*currentHwID)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int GenerateKey(ANSCENTER::ANSLSHelper * *Handle, int productId, const char* registrationName, int productFeature, int trialLicense, LStrHandle generatedKey) {
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !registrationName) return 0;
|
||||
bool enableTrialLicense = false;
|
||||
if (trialLicense > 0)enableTrialLicense = true;
|
||||
std::string st = (*Handle)->GenerateKey(productId, registrationName, productFeature, enableTrialLicense);
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(generatedKey, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*generatedKey)->cnt = size;
|
||||
memcpy((*generatedKey)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int GenerateKeyWithExpiredDate(ANSCENTER::ANSLSHelper * *Handle, int productId, const char* registrationName, int productFeature, int expiredYear, int expiredMonth, int expiredDate, LStrHandle generatedKey) {
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !registrationName) return 0;
|
||||
std::string st = (*Handle)->GenerateKey(productId, registrationName, productFeature, expiredYear, expiredMonth, expiredDate);
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(generatedKey, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*generatedKey)->cnt = size;
|
||||
memcpy((*generatedKey)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int CheckLicenseKey(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, int productId){ //, LStrHandle strEnableFeature) { // Check if the license key is valid
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !licenseKey || !registrationName) return -1;
|
||||
int enFeatures = 0;
|
||||
bool result = (*Handle)->CheckLicenseKey(licenseKey, registrationName, productId, enFeatures);
|
||||
if (result) return enFeatures;
|
||||
else return -1;
|
||||
}
|
||||
catch (...) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int ValidateLicense(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, const char* existingActivationKey,LStrHandle activationKey) {
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !licenseKey || !registrationName || !existingActivationKey) return UNKNOWN;
|
||||
std::string st = existingActivationKey;
|
||||
int result = (*Handle)->ValidateLicense(licenseKey, registrationName, st);
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(activationKey, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*activationKey)->cnt = size;
|
||||
memcpy((*activationKey)->str, st.c_str(), size);
|
||||
return result;
|
||||
}
|
||||
else return UNKNOWN;
|
||||
}
|
||||
else return INVALID_LICENSE_KEY;
|
||||
}
|
||||
catch (...) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
extern "C" __declspec(dllexport) int ActivateLicense(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, LStrHandle activationKey) { // Always activate the license (need internet connection)
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !licenseKey || !registrationName) return UNKNOWN;
|
||||
std::string st = "";
|
||||
int result = (*Handle)->ActivateLicense(licenseKey, registrationName, st);
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(activationKey, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*activationKey)->cnt = size;
|
||||
memcpy((*activationKey)->str, st.c_str(), size);
|
||||
return result;
|
||||
}
|
||||
else return UNKNOWN;
|
||||
}
|
||||
else return INVALID_LICENSE_KEY;
|
||||
}
|
||||
catch (...) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int ActivateLicenseWithCustomHWID(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, const char* hardwareId, LStrHandle activationKey) {
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !licenseKey || !registrationName || !hardwareId) return UNKNOWN;
|
||||
std::string st;
|
||||
int result = (*Handle)->ActivateLicenseWithCustomHWID(licenseKey, registrationName, hardwareId, st);
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(activationKey, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*activationKey)->cnt = size;
|
||||
memcpy((*activationKey)->str, st.c_str(), size);
|
||||
return result;
|
||||
}
|
||||
else return UNKNOWN;
|
||||
}
|
||||
else return INVALID_LICENSE_KEY;
|
||||
}
|
||||
catch (...) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}// Always activate the license (need internet connection)
|
||||
|
||||
extern "C" __declspec(dllexport) int IsLicenseKeyValid(ANSCENTER::ANSLSHelper **Handle, const char* licenseKey, const char * registrationName) { // Only check the license key with registration name and expiration date only. This is used when developer to use internal APIs called
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !licenseKey || !registrationName) return 0;
|
||||
bool result = (*Handle)->IsLicenseKeyValid(licenseKey, registrationName);
|
||||
if (result) return 1;
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern "C" __declspec(dllexport) int GenerateOfflineActivationData(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, LStrHandle offlineActivationData) {
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !licenseKey || !registrationName) return 0;
|
||||
std::string st = "";
|
||||
int result = (*Handle)->GenerateOfflineActivationData(licenseKey, registrationName, st);
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(offlineActivationData, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*offlineActivationData)->cnt = size;
|
||||
memcpy((*offlineActivationData)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int InstallOfflineLicense(ANSCENTER::ANSLSHelper * *Handle, const char* licenseKey, const char* registrationName, const char* activationKey) {
|
||||
try {
|
||||
if (!Handle || !(*Handle) || !licenseKey || !registrationName || !activationKey) return 0;
|
||||
return (*Handle)->InstallOfflineLicense(licenseKey, registrationName, activationKey);
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Utilities
|
||||
extern "C" __declspec(dllexport) int ExtractModelZipFile(const char* modelZipFile, const char* password, const char* modelName, LStrHandle extractedOutputFolder) {
|
||||
try {
|
||||
std::string st = "";
|
||||
int result = ANSCENTER::ANSLSHelper::ExtractModelZipFile(modelZipFile, password, modelName, st);
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(extractedOutputFolder, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*extractedOutputFolder)->cnt = size;
|
||||
memcpy((*extractedOutputFolder)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int ZipFolderToZipFile(const char* modelFolderSource, const char* modelZipFileDes, const char* password) {
|
||||
try {
|
||||
std::string stPass = password;
|
||||
if (stPass.empty()) password = "Sh7O7nUe7vJ/417W0gWX+dSdfcP9hUqtf/fEqJGqxYL3PedvHubJag==";
|
||||
bool result = ANSCENTER::ANSLSHelper::ZipFolerWithPassword(modelFolderSource, modelZipFileDes, password);
|
||||
if (result == true) return 1;
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int PrepareEdgeModel(const char* modelZipFile, const char* zipFilePassword, const char* edgePassword, const char* modelName, const char* edgeSerialNumber,LStrHandle pathArray) {
|
||||
try {
|
||||
std::string st_configFilePathName = "";
|
||||
std::string st_labelMapPathName = "";
|
||||
std::string st_zipFilePathName = "";
|
||||
int result = ANSCENTER::ANSLSHelper::PrepareEdgeModel(modelZipFile, zipFilePassword, edgePassword, modelName, edgeSerialNumber, st_configFilePathName, st_labelMapPathName, st_zipFilePathName);
|
||||
std::string st = st_configFilePathName + ";" + st_labelMapPathName + ";" + st_zipFilePathName;
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(pathArray, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*pathArray)->cnt = size;
|
||||
memcpy((*pathArray)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int GetSystemHardwareInformation(LStrHandle systemHardwareInformation) {
|
||||
try {
|
||||
std::string st = ANSCENTER::ANSLSHelper::GetSystemHardwareInformation();
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(systemHardwareInformation, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*systemHardwareInformation)->cnt = size;
|
||||
memcpy((*systemHardwareInformation)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int ReleaseLoggers() {
|
||||
try {
|
||||
bool result = ANSCENTER::ANSLSHelper::ReleaseLogger();
|
||||
if (result) return 1;
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int ListANSLicenses(std::string & listLicense) {
|
||||
try {
|
||||
listLicense = ANSCENTER::ANSLicenseHelper::ListLicenses();
|
||||
if (!listLicense.empty()) return 1;
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern "C" __declspec(dllexport) int ListANSLicenses_LV(LStrHandle ansProductLicenses) {
|
||||
try {
|
||||
std::string st = ANSCENTER::ANSLicenseHelper::ListLicenses();
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(ansProductLicenses, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*ansProductLicenses)->cnt = size;
|
||||
memcpy((*ansProductLicenses)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int ActivateTrialLicense(const char* productName) {
|
||||
return ANSCENTER::ANSLicenseHelper::ActivateTrialLicense(productName);
|
||||
}
|
||||
extern "C" __declspec(dllexport) int DeactivateLicense(const char* productName) {
|
||||
return ANSCENTER::ANSLicenseHelper::DeactivateLicense(productName);
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int ActivateProductLicense(const char* productName, const char* licenseKey) {
|
||||
return ANSCENTER::ANSLicenseHelper::ActivateLicense(productName,licenseKey);
|
||||
}
|
||||
extern "C" __declspec(dllexport) int ActivateProductLicenseWithCustomHWID(const char* productName, const char* licenseKey, const char* hwid, LStrHandle lvActivationKey) {
|
||||
try {
|
||||
std::string st;
|
||||
int result = ANSCENTER::ANSLicenseHelper::ActivateLicenseWithCustomHWID(productName, licenseKey, hwid, st);
|
||||
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(lvActivationKey, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*lvActivationKey)->cnt = size;
|
||||
memcpy((*lvActivationKey)->str, st.c_str(), size);
|
||||
return result;
|
||||
}
|
||||
else return LicenseKeyStatus::UNKNOWN;
|
||||
}
|
||||
else return LicenseKeyStatus::INVALID_LICENSE_KEY;
|
||||
}
|
||||
catch (...) {
|
||||
return LicenseKeyStatus::UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int GetRegistrationName(const char* validationData, LStrHandle registrationName) {
|
||||
try {
|
||||
std::string st = ANSCENTER::ANSLicenseHelper::DecodeValidationData(validationData);
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(registrationName, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*registrationName)->cnt = size;
|
||||
memcpy((*registrationName)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern "C" __declspec(dllexport) int GenerateActivationKeyData(const char* activationKey, const char* licenseKey, const char* hardwareId, const char* validationData, LStrHandle activationData) {
|
||||
try {
|
||||
std::string st = ANSCENTER::ANSLicenseHelper::GenerateActivationDataFile(activationKey, licenseKey, hardwareId, validationData);
|
||||
int size = (int)st.length();
|
||||
if (size > 0) {
|
||||
MgErr error;
|
||||
error = DSSetHandleSize(activationData, sizeof(int32) + size * sizeof(uChar));
|
||||
if (error == noErr)
|
||||
{
|
||||
(*activationData)->cnt = size;
|
||||
memcpy((*activationData)->str, st.c_str(), size);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) int ANSLicenseVerification(const char* licenseKey, int productId, const char* registrationName) {
|
||||
try{
|
||||
bool result = ANSCENTER::ANSLicenseHelper::LicenseVerification(licenseKey, productId, registrationName);
|
||||
if (result)return 1;
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern "C" __declspec(dllexport) int ANSModelConversion(const char* zipModelFile, const char* zipModelPassword) {
|
||||
try {
|
||||
//1. Uzip the model file to a temp location
|
||||
std::string parentFolder = GetParentFolder(zipModelFile);
|
||||
if (parentFolder.empty()) {
|
||||
return -1; // or handle error appropriately
|
||||
}
|
||||
std::string modelName = GetFileNameWithoutExtension(zipModelFile) + "_converted";
|
||||
const std::string outputFolder = GenerateOutputFolder(zipModelFile, modelName, true);
|
||||
if (!FolderExist(outputFolder)) fs::create_directory(outputFolder);
|
||||
bool extractedResult = ExtractProtectedZipFile(zipModelFile, zipModelPassword, modelName, outputFolder);
|
||||
if (!extractedResult) return 0;
|
||||
//2. Zip the model file to a temp location
|
||||
std::string newModelZipFile = CreateFilePath(parentFolder, modelName + ".zip");
|
||||
std::string newModelZipPassword = "Sh7O7nUe7vJ/417W0gWX+dSdfcP9hUqtf/fEqJGqxYL3PedvHubJag==";
|
||||
//3. Read names of classes from the label map file
|
||||
std::string labelMapFile = CreateFilePath(outputFolder, "classes.names");
|
||||
if (labelMapFile.empty()) return 0;
|
||||
std::vector<std::string> classesNames = Split(ReadFileContent(labelMapFile), "\n");
|
||||
// 4. Create Categories folder
|
||||
std::string categoriesFolder = outputFolder + "\\Categories";
|
||||
if (FolderExist(categoriesFolder))DeleteFolder(categoriesFolder);
|
||||
fs::create_directory(categoriesFolder);
|
||||
for (size_t i = 0; i < classesNames.size(); ++i) {
|
||||
std::ofstream outFile(categoriesFolder + "/" + classesNames[i] + "." + std::to_string(i + 1));
|
||||
outFile.close();
|
||||
}
|
||||
bool zipResult = ZipFolderWithPassword(outputFolder.c_str(), newModelZipFile.c_str(), newModelZipPassword.c_str());
|
||||
if (zipResult) {
|
||||
DeleteFolder(outputFolder);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
extern "C" __declspec(dllexport) int DeletePathRecursively(const char* pathTobeDeleted) {
|
||||
try {
|
||||
bool result = ANSCENTER::ANSLicenseHelper::DeleleteRecursively(pathTobeDeleted);
|
||||
if (result) return 1;
|
||||
else return 0;
|
||||
}
|
||||
catch (...) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
7
core/ANSLicensingSystem/framework.h
Normal file
7
core/ANSLicensingSystem/framework.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#define NOMINMAX // Prevent windows.h from defining min/max macros
|
||||
// which break std::min / std::max (C2589)
|
||||
// Windows Header Files
|
||||
#include <windows.h>
|
||||
5
core/ANSLicensingSystem/pch.cpp
Normal file
5
core/ANSLicensingSystem/pch.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// pch.cpp: source file corresponding to the pre-compiled header
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
|
||||
13
core/ANSLicensingSystem/pch.h
Normal file
13
core/ANSLicensingSystem/pch.h
Normal file
@@ -0,0 +1,13 @@
|
||||
// pch.h: This is a precompiled header file.
|
||||
// Files listed below are compiled only once, improving build performance for future builds.
|
||||
// This also affects IntelliSense performance, including code completion and many code browsing features.
|
||||
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
|
||||
// Do not add files here that you will be updating frequently as this negates the performance advantage.
|
||||
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
// add headers that you want to pre-compile here
|
||||
#include "framework.h"
|
||||
|
||||
#endif //PCH_H
|
||||
Reference in New Issue
Block a user