Skip to content

Commit

Permalink
Make Project::Delete{File,Folder} return bool
Browse files Browse the repository at this point in the history
  • Loading branch information
negasora committed Feb 14, 2024
1 parent aa3c029 commit 3f38812
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions binaryninjaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2674,7 +2674,7 @@ namespace BinaryNinja {
std::vector<Ref<ProjectFolder>> GetFolders() const;
Ref<ProjectFolder> GetFolderById(const std::string& id) const;
void PushFolder(Ref<ProjectFolder> folder);
void DeleteFolder(Ref<ProjectFolder> folder, const std::function<bool(size_t progress, size_t total)>& progressCallback = {});
bool DeleteFolder(Ref<ProjectFolder> folder, const std::function<bool(size_t progress, size_t total)>& progressCallback = {});

Ref<ProjectFile> CreateFileFromPath(const std::string& path, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const std::function<bool(size_t progress, size_t total)>& progressCallback = {});
Ref<ProjectFile> CreateFileFromPathUnsafe(const std::string& path, Ref<ProjectFolder> folder, const std::string& name, const std::string& description, const std::string& id, int64_t creationTimestamp, const std::function<bool(size_t progress, size_t total)>& progressCallback = {});
Expand All @@ -2684,7 +2684,7 @@ namespace BinaryNinja {
Ref<ProjectFile> GetFileById(const std::string& id) const;
Ref<ProjectFile> GetFileByPathOnDisk(const std::string& path);
void PushFile(Ref<ProjectFile> file);
void DeleteFile_(Ref<ProjectFile> file);
bool DeleteFile_(Ref<ProjectFile> file);

void RegisterNotification(ProjectNotification* notify);
void UnregisterNotification(ProjectNotification* notify);
Expand Down
8 changes: 4 additions & 4 deletions binaryninjacore.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
// Current ABI version for linking to the core. This is incremented any time
// there are changes to the API that affect linking, including new functions,
// new types, or modifications to existing functions or types.
#define BN_CURRENT_CORE_ABI_VERSION 52
#define BN_CURRENT_CORE_ABI_VERSION 53

// Minimum ABI version that is supported for loading of plugins. Plugins that
// are linked to an ABI version less than this will not be able to load and
// will require rebuilding. The minimum version is increased when there are
// incompatible changes that break binary compatibility, such as changes to
// existing types or functions.
#define BN_MINIMUM_CORE_ABI_VERSION 52
#define BN_MINIMUM_CORE_ABI_VERSION 53

#ifdef __GNUC__
#ifdef BINARYNINJACORE_LIBRARY
Expand Down Expand Up @@ -3405,7 +3405,7 @@ extern "C"
BINARYNINJACOREAPI BNProjectFile* BNProjectGetFileByPathOnDisk(BNProject* project, const char* path);

BINARYNINJACOREAPI void BNProjectPushFile(BNProject* project, BNProjectFile* file);
BINARYNINJACOREAPI void BNProjectDeleteFile(BNProject* project, BNProjectFile* file);
BINARYNINJACOREAPI bool BNProjectDeleteFile(BNProject* project, BNProjectFile* file);

BINARYNINJACOREAPI BNProjectFolder* BNProjectCreateFolderFromPath(BNProject* project, const char* path, BNProjectFolder* parent, const char* description, void* ctxt,
bool (*progress)(void* ctxt, size_t progress, size_t total));
Expand All @@ -3414,7 +3414,7 @@ extern "C"
BINARYNINJACOREAPI BNProjectFolder** BNProjectGetFolders(BNProject* project, size_t* count);
BINARYNINJACOREAPI BNProjectFolder* BNProjectGetFolderById(BNProject* project, const char* id);
BINARYNINJACOREAPI void BNProjectPushFolder(BNProject* project, BNProjectFolder* folder);
BINARYNINJACOREAPI void BNProjectDeleteFolder(BNProject* project, BNProjectFolder* folder, void* ctxt,
BINARYNINJACOREAPI bool BNProjectDeleteFolder(BNProject* project, BNProjectFolder* folder, void* ctxt,
bool (*progress)(void* ctxt, size_t progress, size_t total));

BINARYNINJACOREAPI void BNProjectBeginBulkOperation(BNProject* project);
Expand Down
8 changes: 4 additions & 4 deletions project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,11 @@ void Project::PushFolder(Ref<ProjectFolder> folder)
}


void Project::DeleteFolder(Ref<ProjectFolder> folder, const std::function<bool(size_t progress, size_t total)>& progressCallback)
bool Project::DeleteFolder(Ref<ProjectFolder> folder, const std::function<bool(size_t progress, size_t total)>& progressCallback)
{
ProgressContext cb;
cb.callback = progressCallback;
BNProjectDeleteFolder(m_object, folder->m_object, &cb, ProgressCallback);
return BNProjectDeleteFolder(m_object, folder->m_object, &cb, ProgressCallback);
}


Expand Down Expand Up @@ -492,9 +492,9 @@ void Project::PushFile(Ref<ProjectFile> file)
}


void Project::DeleteFile_(Ref<ProjectFile> file)
bool Project::DeleteFile_(Ref<ProjectFile> file)
{
BNProjectDeleteFile(m_object, file->m_object);
return BNProjectDeleteFile(m_object, file->m_object);
}


Expand Down
10 changes: 6 additions & 4 deletions python/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,15 @@ def get_folder_by_id(self, id: str) -> Optional[ProjectFolder]:
folder = ProjectFolder(handle)
return folder

def delete_folder(self, folder: ProjectFolder, progress_func: ProgressFuncType = _nop):
def delete_folder(self, folder: ProjectFolder, progress_func: ProgressFuncType = _nop) -> bool:
"""
Recursively delete a folder from the project
:param folder: Folder to delete recursively
:param progress_func: Progress function that will be called as objects get deleted
:return: True if the folder was deleted, False otherwise
"""
core.BNProjectDeleteFolder(self._handle, folder._handle, None, _wrap_progress(progress_func))
return core.BNProjectDeleteFolder(self._handle, folder._handle, None, _wrap_progress(progress_func))

def create_file_from_path(self, path: AsPath, folder: Optional[ProjectFile], name: str, description: str = "", progress_func: ProgressFuncType = _nop) -> ProjectFile:
"""
Expand Down Expand Up @@ -646,13 +647,14 @@ def get_file_by_id(self, id: str) -> Optional[ProjectFile]:
file = ProjectFile(handle)
return file

def delete_file(self, file: ProjectFile):
def delete_file(self, file: ProjectFile) -> bool:
"""
Delete a file from the project
:param file: File to delete
:return: True if the file was deleted, False otherwise
"""
core.BNProjectDeleteFile(self._handle, file._handle)
return core.BNProjectDeleteFile(self._handle, file._handle)

@contextmanager
def bulk_operation(self):
Expand Down

0 comments on commit 3f38812

Please sign in to comment.