diff options
| author | Rusty Wagner <rusty@vector35.com> | 2015-10-27 01:28:15 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2015-10-27 01:28:39 -0400 |
| commit | 9fabf9157240d57470f9eb38448a329e5a31ec30 (patch) | |
| tree | 20d3f5c41dfa973280eb6696e2e1f39064939bb8 /update.cpp | |
| parent | 21f0f2d62247bcc45c07af0a363c7e39208f4110 (diff) | |
Implement update API (no UI yet)
Diffstat (limited to 'update.cpp')
| -rw-r--r-- | update.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
@@ -4,6 +4,21 @@ using namespace BinaryNinja; using namespace std; +namespace BinaryNinja +{ + struct UpdateProgress + { + function<void(uint64_t progress, uint64_t total)> func; + + static void UpdateCallback(void* ctxt, uint64_t progress, uint64_t total) + { + UpdateProgress* self = (UpdateProgress*)ctxt; + self->func(progress, total); + } + }; +} + + vector<UpdateChannel> UpdateChannel::GetList() { size_t count; @@ -32,6 +47,74 @@ vector<UpdateChannel> UpdateChannel::GetList() } +bool UpdateChannel::AreUpdatesAvailable() +{ + char* errors; + bool result = BNAreUpdatesAvailable(name.c_str(), &errors); + + if (errors) + { + string errorStr = errors; + BNFreeString(errors); + throw UpdateException(errorStr); + } + + return result; +} + + +BNUpdateResult UpdateChannel::UpdateToVersion(const string& version) +{ + return UpdateToVersion(version, [](uint64_t, uint64_t){}); +} + + +BNUpdateResult UpdateChannel::UpdateToVersion(const string& version, + const function<void(uint64_t progress, uint64_t total)>& progress) +{ + UpdateProgress up; + up.func = progress; + + char* errors; + BNUpdateResult result = BNUpdateToVersion(name.c_str(), version.c_str(), &errors, + UpdateProgress::UpdateCallback, &up); + + if (errors) + { + string errorStr = errors; + BNFreeString(errors); + throw UpdateException(errorStr); + } + + return result; +} + + +BNUpdateResult UpdateChannel::UpdateToLatestVersion() +{ + return UpdateToLatestVersion([](uint64_t, uint64_t){}); +} + + +BNUpdateResult UpdateChannel::UpdateToLatestVersion(const function<void(uint64_t progress, uint64_t total)>& progress) +{ + UpdateProgress up; + up.func = progress; + + char* errors; + BNUpdateResult result = BNUpdateToLatestVersion(name.c_str(), &errors, UpdateProgress::UpdateCallback, &up); + + if (errors) + { + string errorStr = errors; + BNFreeString(errors); + throw UpdateException(errorStr); + } + + return result; +} + + vector<UpdateVersion> UpdateVersion::GetChannelVersions(const string& channel) { size_t count; |
