summaryrefslogtreecommitdiff
path: root/update.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2015-10-27 01:28:15 -0400
committerRusty Wagner <rusty@vector35.com>2015-10-27 01:28:39 -0400
commit9fabf9157240d57470f9eb38448a329e5a31ec30 (patch)
tree20d3f5c41dfa973280eb6696e2e1f39064939bb8 /update.cpp
parent21f0f2d62247bcc45c07af0a363c7e39208f4110 (diff)
Implement update API (no UI yet)
Diffstat (limited to 'update.cpp')
-rw-r--r--update.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/update.cpp b/update.cpp
index 545305b0..90e3477b 100644
--- a/update.cpp
+++ b/update.cpp
@@ -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;