mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
fix: declare alloc_c_string before use in c++ wrapper
This commit is contained in:
@@ -31,12 +31,6 @@ static inline std::optional<std::string> to_cpp_string(const char* psz)
|
|||||||
return psz == nullptr ? std::optional<std::string>("") : std::optional<std::string>(psz);
|
return psz == nullptr ? std::optional<std::string>("") : std::optional<std::string>(psz);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char* alloc_c_string(const std::optional<std::string>& str)
|
|
||||||
{
|
|
||||||
if (!str.has_value()) { return nullptr; }
|
|
||||||
return alloc_c_string(str.value());
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline char* alloc_c_string(const std::string& str)
|
static inline char* alloc_c_string(const std::string& str)
|
||||||
{
|
{
|
||||||
char* result = new char[str.size() + 1]; // +1 for null-terminator
|
char* result = new char[str.size() + 1]; // +1 for null-terminator
|
||||||
@@ -49,6 +43,12 @@ static inline char* alloc_c_string(const std::string& str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline char* alloc_c_string(const std::optional<std::string>& str)
|
||||||
|
{
|
||||||
|
if (!str.has_value()) { return nullptr; }
|
||||||
|
return alloc_c_string(str.value());
|
||||||
|
}
|
||||||
|
|
||||||
static inline void free_c_string(char* str)
|
static inline void free_c_string(char* str)
|
||||||
{
|
{
|
||||||
delete[] str;
|
delete[] str;
|
||||||
@@ -165,7 +165,7 @@ static inline void free_c_VelopackLocatorConfig(vpkc_locator_config_t* obj) {
|
|||||||
free_c_string(obj->PackagesDir);
|
free_c_string(obj->PackagesDir);
|
||||||
free_c_string(obj->ManifestPath);
|
free_c_string(obj->ManifestPath);
|
||||||
free_c_string(obj->CurrentBinaryDir);
|
free_c_string(obj->CurrentBinaryDir);
|
||||||
|
|
||||||
delete obj;
|
delete obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ static inline void free_c_VelopackAsset(vpkc_asset_t* obj) {
|
|||||||
free_c_string(obj->FileName);
|
free_c_string(obj->FileName);
|
||||||
free_c_string(obj->SHA1);
|
free_c_string(obj->SHA1);
|
||||||
free_c_string(obj->SHA256);
|
free_c_string(obj->SHA256);
|
||||||
|
|
||||||
free_c_string(obj->NotesMarkdown);
|
free_c_string(obj->NotesMarkdown);
|
||||||
free_c_string(obj->NotesHtml);
|
free_c_string(obj->NotesHtml);
|
||||||
delete obj;
|
delete obj;
|
||||||
@@ -354,7 +354,7 @@ static inline void free_c_UpdateInfo(vpkc_update_info_t* obj) {
|
|||||||
free_c_VelopackAsset(obj->TargetFullRelease);
|
free_c_VelopackAsset(obj->TargetFullRelease);
|
||||||
free_c_VelopackAsset(obj->BaseRelease);
|
free_c_VelopackAsset(obj->BaseRelease);
|
||||||
free_c_VelopackAsset_vec(obj->DeltasToTarget, obj->DeltasToTargetCount);
|
free_c_VelopackAsset_vec(obj->DeltasToTarget, obj->DeltasToTargetCount);
|
||||||
|
|
||||||
delete obj;
|
delete obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,9 +443,9 @@ static inline vpkc_update_options_t** alloc_c_UpdateOptions_vec(const std::vecto
|
|||||||
|
|
||||||
static inline void free_c_UpdateOptions(vpkc_update_options_t* obj) {
|
static inline void free_c_UpdateOptions(vpkc_update_options_t* obj) {
|
||||||
if (obj == nullptr) { return; }
|
if (obj == nullptr) { return; }
|
||||||
|
|
||||||
free_c_string(obj->ExplicitChannel);
|
free_c_string(obj->ExplicitChannel);
|
||||||
|
|
||||||
delete obj;
|
delete obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,7 +458,7 @@ static inline void free_c_UpdateOptions_vec(vpkc_update_options_t** arr, size_t
|
|||||||
}
|
}
|
||||||
// !! AUTO-GENERATED-END CPP_TYPES
|
// !! AUTO-GENERATED-END CPP_TYPES
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VelopackApp helps you to handle app activation events correctly.
|
* VelopackApp helps you to handle app activation events correctly.
|
||||||
* This should be used as early as possible in your application startup code.
|
* This should be used as early as possible in your application startup code.
|
||||||
* (eg. the beginning of main() or wherever your entry point is)
|
* (eg. the beginning of main() or wherever your entry point is)
|
||||||
@@ -470,8 +470,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Build a new VelopackApp instance.
|
* Build a new VelopackApp instance.
|
||||||
*/
|
*/
|
||||||
static VelopackApp Build() {
|
static VelopackApp Build() {
|
||||||
return VelopackApp();
|
return VelopackApp();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -586,7 +586,7 @@ public:
|
|||||||
typedef std::function<void(int16_t)> vpkc_progress_send_t;
|
typedef std::function<void(int16_t)> vpkc_progress_send_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class for retrieving release feeds and downloading assets. You should subclass this and
|
* Abstract class for retrieving release feeds and downloading assets. You should subclass this and
|
||||||
* implement/override the GetReleaseFeed and DownloadReleaseEntry methods.
|
* implement/override the GetReleaseFeed and DownloadReleaseEntry methods.
|
||||||
* This class is used by the UpdateManager to fetch release feeds and download assets in a custom way.
|
* This class is used by the UpdateManager to fetch release feeds and download assets in a custom way.
|
||||||
* SAFETY: It is your responsibility to ensure that a derived class instance is thread-safe,
|
* SAFETY: It is your responsibility to ensure that a derived class instance is thread-safe,
|
||||||
@@ -596,7 +596,7 @@ class IUpdateSource {
|
|||||||
friend class UpdateManager;
|
friend class UpdateManager;
|
||||||
friend class FileSource;
|
friend class FileSource;
|
||||||
friend class HttpSource;
|
friend class HttpSource;
|
||||||
private:
|
private:
|
||||||
IUpdateSource(vpkc_update_source_t* pSource) : m_pSource(pSource) {}
|
IUpdateSource(vpkc_update_source_t* pSource) : m_pSource(pSource) {}
|
||||||
vpkc_update_source_t* m_pSource = 0;
|
vpkc_update_source_t* m_pSource = 0;
|
||||||
public:
|
public:
|
||||||
@@ -609,7 +609,7 @@ public:
|
|||||||
IUpdateSource* source = reinterpret_cast<IUpdateSource*>(userData);
|
IUpdateSource* source = reinterpret_cast<IUpdateSource*>(userData);
|
||||||
std::string json = source->GetReleaseFeed(releasesName);
|
std::string json = source->GetReleaseFeed(releasesName);
|
||||||
return alloc_c_string(json);
|
return alloc_c_string(json);
|
||||||
},
|
},
|
||||||
[](void* userData, char* pszFeed) {
|
[](void* userData, char* pszFeed) {
|
||||||
free_c_string(pszFeed);
|
free_c_string(pszFeed);
|
||||||
},
|
},
|
||||||
@@ -642,11 +642,11 @@ public:
|
|||||||
class FileSource : public IUpdateSource {
|
class FileSource : public IUpdateSource {
|
||||||
public:
|
public:
|
||||||
FileSource(const std::string& filePath) : IUpdateSource(vpkc_new_source_file(filePath.c_str())) { }
|
FileSource(const std::string& filePath) : IUpdateSource(vpkc_new_source_file(filePath.c_str())) { }
|
||||||
const std::string GetReleaseFeed(const std::string releasesName) override {
|
const std::string GetReleaseFeed(const std::string releasesName) override {
|
||||||
throw std::runtime_error("Not implemented");
|
throw std::runtime_error("Not implemented");
|
||||||
}
|
}
|
||||||
bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) override {
|
bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) override {
|
||||||
throw std::runtime_error("Not implemented");
|
throw std::runtime_error("Not implemented");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -656,11 +656,11 @@ public:
|
|||||||
class HttpSource : public IUpdateSource {
|
class HttpSource : public IUpdateSource {
|
||||||
public:
|
public:
|
||||||
HttpSource(const std::string& httpUrl) : IUpdateSource(vpkc_new_source_http_url(httpUrl.c_str())) { }
|
HttpSource(const std::string& httpUrl) : IUpdateSource(vpkc_new_source_http_url(httpUrl.c_str())) { }
|
||||||
const std::string GetReleaseFeed(const std::string releasesName) override {
|
const std::string GetReleaseFeed(const std::string releasesName) override {
|
||||||
throw std::runtime_error("Not implemented");
|
throw std::runtime_error("Not implemented");
|
||||||
}
|
}
|
||||||
bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) override {
|
bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) override {
|
||||||
throw std::runtime_error("Not implemented");
|
throw std::runtime_error("Not implemented");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -829,7 +829,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This will launch the Velopack updater and optionally wait for a program to exit gracefully.
|
* This will launch the Velopack updater and optionally wait for a program to exit gracefully.
|
||||||
* This method is unsafe because it does not necessarily wait for any / the correct process to exit
|
* This method is unsafe because it does not necessarily wait for any / the correct process to exit
|
||||||
* before applying updates. The `WaitExitThenApplyUpdates` method is recommended for most use cases.
|
* before applying updates. The `WaitExitThenApplyUpdates` method is recommended for most use cases.
|
||||||
* If waitPid is 0, the updater will not wait for any process to exit before applying updates (Not Recommended).
|
* If waitPid is 0, the updater will not wait for any process to exit before applying updates (Not Recommended).
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user