Skip to content

Commit 573b03c

Browse files
committed
Improve error handling in project apis
1 parent ba282a4 commit 573b03c

File tree

5 files changed

+60
-60
lines changed

5 files changed

+60
-60
lines changed

binaryninjaapi.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,10 +3640,10 @@ namespace BinaryNinja {
36403640
std::string GetId() const;
36413641
std::string GetName() const;
36423642
std::string GetDescription() const;
3643-
void SetName(const std::string& name);
3644-
void SetDescription(const std::string& description);
3643+
bool SetName(const std::string& name);
3644+
bool SetDescription(const std::string& description);
36453645
Ref<ProjectFolder> GetParent() const;
3646-
void SetParent(Ref<ProjectFolder> parent);
3646+
bool SetParent(Ref<ProjectFolder> parent);
36473647
bool Export(const std::string& destination, const ProgressFunction& progressCallback = {}) const;
36483648
};
36493649

@@ -3662,11 +3662,11 @@ namespace BinaryNinja {
36623662
bool ExistsOnDisk() const;
36633663
std::string GetName() const;
36643664
std::string GetDescription() const;
3665-
void SetName(const std::string& name);
3666-
void SetDescription(const std::string& description);
3665+
bool SetName(const std::string& name);
3666+
bool SetDescription(const std::string& description);
36673667
std::string GetId() const;
36683668
Ref<ProjectFolder> GetFolder() const;
3669-
void SetFolder(Ref<ProjectFolder> folder);
3669+
bool SetFolder(Ref<ProjectFolder> folder);
36703670
bool Export(const std::string& destination) const;
36713671
int64_t GetCreationTimestamp() const;
36723672
};
@@ -3696,21 +3696,21 @@ namespace BinaryNinja {
36963696
std::string GetPath() const;
36973697
std::string GetFilePathInProject(const Ref<ProjectFile>& file) const;
36983698
std::string GetName() const;
3699-
void SetName(const std::string& name);
3699+
bool SetName(const std::string& name);
37003700
std::string GetDescription() const;
3701-
void SetDescription(const std::string& description);
3701+
bool SetDescription(const std::string& description);
37023702

37033703
Ref<Metadata> QueryMetadata(const std::string& key);
37043704
bool StoreMetadata(const std::string& key, Ref<Metadata> value);
3705-
void RemoveMetadata(const std::string& key);
3705+
bool RemoveMetadata(const std::string& key);
37063706

37073707
Ref<ProjectFolder> CreateFolderFromPath(const std::string& path, Ref<ProjectFolder> parent, const std::string& description,
37083708
const ProgressFunction& progressCallback = {});
37093709
Ref<ProjectFolder> CreateFolder(Ref<ProjectFolder> parent, const std::string& name, const std::string& description);
37103710
Ref<ProjectFolder> CreateFolderUnsafe(Ref<ProjectFolder> parent, const std::string& name, const std::string& description, const std::string& id);
37113711
std::vector<Ref<ProjectFolder>> GetFolders() const;
37123712
Ref<ProjectFolder> GetFolderById(const std::string& id) const;
3713-
void PushFolder(Ref<ProjectFolder> folder);
3713+
bool PushFolder(Ref<ProjectFolder> folder);
37143714
bool DeleteFolder(Ref<ProjectFolder> folder, const ProgressFunction& progressCallback = {});
37153715

37163716
Ref<ProjectFile> CreateFileFromPath(const std::string& path, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const ProgressFunction& progressCallback = {});
@@ -3721,14 +3721,14 @@ namespace BinaryNinja {
37213721
Ref<ProjectFile> GetFileById(const std::string& id) const;
37223722
Ref<ProjectFile> GetFileByPathOnDisk(const std::string& path) const;
37233723
std::vector<Ref<ProjectFile>> GetFilesByPathInProject(const std::string& path) const;
3724-
void PushFile(Ref<ProjectFile> file);
3724+
bool PushFile(Ref<ProjectFile> file);
37253725
bool DeleteFile_(Ref<ProjectFile> file);
37263726

37273727
void RegisterNotification(ProjectNotification* notify);
37283728
void UnregisterNotification(ProjectNotification* notify);
37293729

3730-
void BeginBulkOperation();
3731-
void EndBulkOperation();
3730+
bool BeginBulkOperation();
3731+
bool EndBulkOperation();
37323732

37333733
Ref<Collaboration::RemoteProject> GetRemoteProject();
37343734
};

binaryninjacore.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4090,13 +4090,13 @@ extern "C"
40904090
BINARYNINJACOREAPI char* BNProjectGetPath(BNProject* project);
40914091
BINARYNINJACOREAPI char* BNProjectGetFilePathInProject(BNProject* project, BNProjectFile* file);
40924092
BINARYNINJACOREAPI char* BNProjectGetName(BNProject* project);
4093-
BINARYNINJACOREAPI void BNProjectSetName(BNProject* project, const char* name);
4093+
BINARYNINJACOREAPI bool BNProjectSetName(BNProject* project, const char* name);
40944094
BINARYNINJACOREAPI char* BNProjectGetDescription(BNProject* project);
4095-
BINARYNINJACOREAPI void BNProjectSetDescription(BNProject* project, const char* description);
4095+
BINARYNINJACOREAPI bool BNProjectSetDescription(BNProject* project, const char* description);
40964096

40974097
BINARYNINJACOREAPI BNMetadata* BNProjectQueryMetadata(BNProject* project, const char* key);
40984098
BINARYNINJACOREAPI bool BNProjectStoreMetadata(BNProject* project, const char* key, BNMetadata* value);
4099-
BINARYNINJACOREAPI void BNProjectRemoveMetadata(BNProject* project, const char* key);
4099+
BINARYNINJACOREAPI bool BNProjectRemoveMetadata(BNProject* project, const char* key);
41004100

41014101
BINARYNINJACOREAPI BNProjectFile* BNProjectCreateFileFromPath(BNProject* project, const char* path, BNProjectFolder* folder, const char* name, const char* description, void* ctxt,
41024102
BNProgressFunction progress);
@@ -4111,7 +4111,7 @@ extern "C"
41114111
BINARYNINJACOREAPI BNProjectFile* BNProjectGetFileByPathOnDisk(BNProject* project, const char* path);
41124112
BINARYNINJACOREAPI BNProjectFile** BNProjectGetFilesByPathInProject(BNProject* project, const char* path, size_t* count);
41134113

4114-
BINARYNINJACOREAPI void BNProjectPushFile(BNProject* project, BNProjectFile* file);
4114+
BINARYNINJACOREAPI bool BNProjectPushFile(BNProject* project, BNProjectFile* file);
41154115
BINARYNINJACOREAPI bool BNProjectDeleteFile(BNProject* project, BNProjectFile* file);
41164116

41174117
BINARYNINJACOREAPI BNProjectFolder* BNProjectCreateFolderFromPath(BNProject* project, const char* path, BNProjectFolder* parent, const char* description, void* ctxt,
@@ -4120,12 +4120,12 @@ extern "C"
41204120
BINARYNINJACOREAPI BNProjectFolder* BNProjectCreateFolderUnsafe(BNProject* project, BNProjectFolder* parent, const char* name, const char* description, const char* id);
41214121
BINARYNINJACOREAPI BNProjectFolder** BNProjectGetFolders(BNProject* project, size_t* count);
41224122
BINARYNINJACOREAPI BNProjectFolder* BNProjectGetFolderById(BNProject* project, const char* id);
4123-
BINARYNINJACOREAPI void BNProjectPushFolder(BNProject* project, BNProjectFolder* folder);
4123+
BINARYNINJACOREAPI bool BNProjectPushFolder(BNProject* project, BNProjectFolder* folder);
41244124
BINARYNINJACOREAPI bool BNProjectDeleteFolder(BNProject* project, BNProjectFolder* folder, void* ctxt,
41254125
BNProgressFunction progress);
41264126

4127-
BINARYNINJACOREAPI void BNProjectBeginBulkOperation(BNProject* project);
4128-
BINARYNINJACOREAPI void BNProjectEndBulkOperation(BNProject* project);
4127+
BINARYNINJACOREAPI bool BNProjectBeginBulkOperation(BNProject* project);
4128+
BINARYNINJACOREAPI bool BNProjectEndBulkOperation(BNProject* project);
41294129

41304130
BINARYNINJACOREAPI BNRemoteProject* BNProjectGetRemoteProject(BNProject* project);
41314131

project.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ std::string Project::GetName() const
304304
}
305305

306306

307-
void Project::SetName(const std::string& name)
307+
bool Project::SetName(const std::string& name)
308308
{
309-
BNProjectSetName(m_object, name.c_str());
309+
return BNProjectSetName(m_object, name.c_str());
310310
}
311311

312312

@@ -319,9 +319,9 @@ std::string Project::GetDescription() const
319319
}
320320

321321

322-
void Project::SetDescription(const std::string& description)
322+
bool Project::SetDescription(const std::string& description)
323323
{
324-
BNProjectSetDescription(m_object, description.c_str());
324+
return BNProjectSetDescription(m_object, description.c_str());
325325
}
326326

327327

@@ -340,9 +340,9 @@ bool Project::StoreMetadata(const std::string& key, Ref<Metadata> value)
340340
}
341341

342342

343-
void Project::RemoveMetadata(const std::string& key)
343+
bool Project::RemoveMetadata(const std::string& key)
344344
{
345-
BNProjectRemoveMetadata(m_object, key.c_str());
345+
return BNProjectRemoveMetadata(m_object, key.c_str());
346346
}
347347

348348

@@ -402,9 +402,9 @@ Ref<ProjectFolder> Project::GetFolderById(const std::string& id) const
402402
}
403403

404404

405-
void Project::PushFolder(Ref<ProjectFolder> folder)
405+
bool Project::PushFolder(Ref<ProjectFolder> folder)
406406
{
407-
BNProjectPushFolder(m_object, folder->m_object);
407+
return BNProjectPushFolder(m_object, folder->m_object);
408408
}
409409

410410

@@ -514,9 +514,9 @@ std::vector<Ref<ProjectFile>> Project::GetFilesByPathInProject(
514514
}
515515

516516

517-
void Project::PushFile(Ref<ProjectFile> file)
517+
bool Project::PushFile(Ref<ProjectFile> file)
518518
{
519-
BNProjectPushFile(m_object, file->m_object);
519+
return BNProjectPushFile(m_object, file->m_object);
520520
}
521521

522522

@@ -538,15 +538,15 @@ void Project::UnregisterNotification(ProjectNotification* notify)
538538
}
539539

540540

541-
void Project::BeginBulkOperation()
541+
bool Project::BeginBulkOperation()
542542
{
543-
BNProjectBeginBulkOperation(m_object);
543+
return BNProjectBeginBulkOperation(m_object);
544544
}
545545

546546

547-
void Project::EndBulkOperation()
547+
bool Project::EndBulkOperation()
548548
{
549-
BNProjectEndBulkOperation(m_object);
549+
return BNProjectEndBulkOperation(m_object);
550550
}
551551

552552

@@ -613,15 +613,15 @@ std::string ProjectFile::GetDescription() const
613613
}
614614

615615

616-
void ProjectFile::SetName(const std::string& name)
616+
bool ProjectFile::SetName(const std::string& name)
617617
{
618-
BNProjectFileSetName(m_object, name.c_str());
618+
return BNProjectFileSetName(m_object, name.c_str());
619619
}
620620

621621

622-
void ProjectFile::SetDescription(const std::string& description)
622+
bool ProjectFile::SetDescription(const std::string& description)
623623
{
624-
BNProjectFileSetDescription(m_object, description.c_str());
624+
return BNProjectFileSetDescription(m_object, description.c_str());
625625
}
626626

627627

@@ -643,9 +643,9 @@ Ref<ProjectFolder> ProjectFile::GetFolder() const
643643
}
644644

645645

646-
void ProjectFile::SetFolder(Ref<ProjectFolder> folder)
646+
bool ProjectFile::SetFolder(Ref<ProjectFolder> folder)
647647
{
648-
BNProjectFileSetFolder(m_object, folder ? folder->m_object : nullptr);
648+
return BNProjectFileSetFolder(m_object, folder ? folder->m_object : nullptr);
649649
}
650650

651651

@@ -700,15 +700,15 @@ std::string ProjectFolder::GetDescription() const
700700
}
701701

702702

703-
void ProjectFolder::SetName(const std::string& name)
703+
bool ProjectFolder::SetName(const std::string& name)
704704
{
705-
BNProjectFolderSetName(m_object, name.c_str());
705+
return BNProjectFolderSetName(m_object, name.c_str());
706706
}
707707

708708

709-
void ProjectFolder::SetDescription(const std::string& description)
709+
bool ProjectFolder::SetDescription(const std::string& description)
710710
{
711-
BNProjectFolderSetDescription(m_object, description.c_str());
711+
return BNProjectFolderSetDescription(m_object, description.c_str());
712712
}
713713

714714

@@ -721,9 +721,9 @@ Ref<ProjectFolder> ProjectFolder::GetParent() const
721721
}
722722

723723

724-
void ProjectFolder::SetParent(Ref<ProjectFolder> parent)
724+
bool ProjectFolder::SetParent(Ref<ProjectFolder> parent)
725725
{
726-
BNProjectFolderSetParent(m_object, parent ? parent->m_object : nullptr);
726+
return BNProjectFolderSetParent(m_object, parent ? parent->m_object : nullptr);
727727
}
728728

729729

python/project.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def export(self, dest: AsPath) -> bool:
193193
def get_path_on_disk(self) -> Optional[str]:
194194
"""
195195
Get this file's path on disk
196-
196+
197197
:return: The path on disk of the file or None
198198
"""
199199
return core.BNProjectFileGetPathOnDisk(self._handle)
@@ -427,13 +427,13 @@ def name(self) -> str:
427427
return core.BNProjectGetName(self._handle) # type: ignore
428428

429429
@name.setter
430-
def name(self, new_name: str):
430+
def name(self, new_name: str) -> bool:
431431
"""
432432
Set the name of the project
433433
434434
:param new_name: Desired name
435435
"""
436-
core.BNProjectSetName(self._handle, new_name)
436+
return core.BNProjectSetName(self._handle, new_name)
437437

438438
@property
439439
def description(self) -> str:
@@ -445,13 +445,13 @@ def description(self) -> str:
445445
return core.BNProjectGetDescription(self._handle) # type: ignore
446446

447447
@description.setter
448-
def description(self, new_description: str):
448+
def description(self, new_description: str) -> bool:
449449
"""
450450
Set the description of the project
451451
452452
:param new_description: Desired description
453453
"""
454-
core.BNProjectSetDescription(self._handle, new_description)
454+
return core.BNProjectSetDescription(self._handle, new_description)
455455

456456
def query_metadata(self, key: str) -> MetadataValueType:
457457
"""
@@ -464,7 +464,7 @@ def query_metadata(self, key: str) -> MetadataValueType:
464464
raise KeyError(key)
465465
return Metadata(handle=md_handle).value
466466

467-
def store_metadata(self, key: str, value: MetadataValueType):
467+
def store_metadata(self, key: str, value: MetadataValueType) -> bool:
468468
"""
469469
Stores metadata within the project
470470
@@ -474,15 +474,15 @@ def store_metadata(self, key: str, value: MetadataValueType):
474474
_val = value
475475
if not isinstance(_val, Metadata):
476476
_val = Metadata(_val)
477-
core.BNProjectStoreMetadata(self._handle, key, _val.handle)
477+
return core.BNProjectStoreMetadata(self._handle, key, _val.handle)
478478

479-
def remove_metadata(self, key: str):
479+
def remove_metadata(self, key: str) -> bool:
480480
"""
481481
Removes the metadata associated with this key from the project
482482
483483
:param str key: Key associated with the metadata object to remove
484484
"""
485-
core.BNProjectRemoveMetadata(self._handle, key)
485+
return core.BNProjectRemoveMetadata(self._handle, key)
486486

487487
def create_folder_from_path(self, path: Union[PathLike, str], parent: Optional[ProjectFolder] = None, description: str = "", progress_func: ProgressFuncType = _nop) -> ProjectFolder:
488488
"""

rust/src/project.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Project {
9797
}
9898

9999
/// Set the name of the project
100-
pub fn set_name(&self, value: &str) {
100+
pub fn set_name(&self, value: &str) -> bool {
101101
let value = value.to_cstr();
102102
unsafe { BNProjectSetName(self.handle.as_ptr(), value.as_ptr()) }
103103
}
@@ -108,7 +108,7 @@ impl Project {
108108
}
109109

110110
/// Set the description of the project
111-
pub fn set_description(&self, value: &str) {
111+
pub fn set_description(&self, value: &str) -> bool {
112112
let value = value.to_cstr();
113113
unsafe { BNProjectSetDescription(self.handle.as_ptr(), value.as_ptr()) }
114114
}
@@ -130,12 +130,12 @@ impl Project {
130130
}
131131

132132
/// Removes the metadata associated with this `key` from the project
133-
pub fn remove_metadata(&self, key: &str) {
133+
pub fn remove_metadata(&self, key: &str) -> bool {
134134
let key_raw = key.to_cstr();
135135
unsafe { BNProjectRemoveMetadata(self.handle.as_ptr(), key_raw.as_ptr()) }
136136
}
137137

138-
pub fn push_folder(&self, file: &ProjectFolder) {
138+
pub fn push_folder(&self, file: &ProjectFolder) -> bool {
139139
unsafe { BNProjectPushFolder(self.handle.as_ptr(), file.handle.as_ptr()) }
140140
}
141141

@@ -288,7 +288,7 @@ impl Project {
288288
}
289289
}
290290

291-
pub fn push_file(&self, file: &ProjectFile) {
291+
pub fn push_file(&self, file: &ProjectFile) -> bool {
292292
unsafe { BNProjectPushFile(self.handle.as_ptr(), file.handle.as_ptr()) }
293293
}
294294

0 commit comments

Comments
 (0)