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 | |
| parent | 21f0f2d62247bcc45c07af0a363c7e39208f4110 (diff) | |
Implement update API (no UI yet)
| -rw-r--r-- | binaryninjaapi.h | 8 | ||||
| -rw-r--r-- | update.cpp | 83 |
2 files changed, 91 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 27e2c565..46d675f2 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1355,6 +1355,14 @@ namespace BinaryNinja std::string latestVersion; static std::vector<UpdateChannel> GetList(); + + bool AreUpdatesAvailable(); + + BNUpdateResult UpdateToVersion(const std::string& version); + BNUpdateResult UpdateToVersion(const std::string& version, + const std::function<void(uint64_t progress, uint64_t total)>& progress); + BNUpdateResult UpdateToLatestVersion(); + BNUpdateResult UpdateToLatestVersion(const std::function<void(uint64_t progress, uint64_t total)>& progress); }; struct UpdateVersion @@ -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; |
