From d7c91093e808731bbe4fafd67daccb8776d5710e Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Mon, 16 Mar 2026 11:48:46 -0700 Subject: [Rust] Misc project module cleanup --- rust/src/project.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'rust/src') diff --git a/rust/src/project.rs b/rust/src/project.rs index fc750bcb..7188ed59 100644 --- a/rust/src/project.rs +++ b/rust/src/project.rs @@ -1,5 +1,4 @@ -pub mod file; -pub mod folder; +//! Represents a collection of files and folders within Binary Ninja. use std::ffi::c_void; use std::fmt::Debug; @@ -17,6 +16,9 @@ use crate::project::folder::ProjectFolder; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; use crate::string::{BnString, IntoCStr}; +pub mod file; +pub mod folder; + pub struct Project { pub(crate) handle: NonNull, } @@ -30,6 +32,7 @@ impl Project { Ref::new(Self { handle }) } + /// All of the open [`Project`]s pub fn all_open() -> Array { let mut count = 0; let result = unsafe { BNGetOpenProjects(&mut count) }; @@ -37,7 +40,6 @@ impl Project { unsafe { Array::new(result, count, ()) } } - // TODO: Path here is actually local path? /// Create a new project /// /// * `path` - Path to the project directory (.bnpr) @@ -49,7 +51,6 @@ impl Project { NonNull::new(handle).map(|h| unsafe { Self::ref_from_raw(h) }) } - // TODO: Path here is actually local path? /// Open an existing project /// /// * `path` - Path to the project directory (.bnpr) or project metadata file (.bnpm) @@ -73,7 +74,7 @@ impl Project { } } - /// Close a open project + /// Close an open project pub fn close(&self) -> Result<(), ()> { if unsafe { BNProjectClose(self.handle.as_ptr()) } { Ok(()) @@ -87,9 +88,10 @@ impl Project { unsafe { BnString::into_string(BNProjectGetId(self.handle.as_ptr())) } } - /// Get the path of the project - pub fn path(&self) -> String { - unsafe { BnString::into_string(BNProjectGetPath(self.handle.as_ptr())) } + /// Get the path on disk for the project + pub fn path(&self) -> PathBuf { + let path_str = unsafe { BnString::into_string(BNProjectGetPath(self.handle.as_ptr())) }; + PathBuf::from(path_str) } /// Get the name of the project @@ -136,6 +138,7 @@ impl Project { unsafe { BNProjectRemoveMetadata(self.handle.as_ptr(), key_raw.as_ptr()) } } + /// Call this after updating the [`ProjectFolder`] to have the changes reflected in the database. pub fn push_folder(&self, file: &ProjectFolder) -> bool { unsafe { BNProjectPushFolder(self.handle.as_ptr(), file.handle.as_ptr()) } } @@ -212,6 +215,7 @@ impl Project { } } + // TODO: Rename create_folder_with_id and comment about the id being unique /// Recursively create files and folders in the project from a path on disk /// /// * `parent` - Parent folder in the project that will contain the new folder @@ -289,6 +293,7 @@ impl Project { } } + /// Call this after updating the [`ProjectFile`] to have the changes reflected in the database. pub fn push_file(&self, file: &ProjectFile) -> bool { unsafe { BNProjectPushFile(self.handle.as_ptr(), file.handle.as_ptr()) } } -- cgit v1.3.1