Skip to content

Commit 5d6da80

Browse files
committed
[Rust] Misc project module cleanup
1 parent c435e91 commit 5d6da80

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

rust/src/project.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
pub mod file;
2-
pub mod folder;
1+
//! Represents a collection of files and folders within Binary Ninja.
32
43
use std::ffi::c_void;
54
use std::fmt::Debug;
@@ -17,6 +16,9 @@ use crate::project::folder::ProjectFolder;
1716
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable};
1817
use crate::string::{BnString, IntoCStr};
1918

19+
pub mod file;
20+
pub mod folder;
21+
2022
pub struct Project {
2123
pub(crate) handle: NonNull<BNProject>,
2224
}
@@ -30,14 +32,14 @@ impl Project {
3032
Ref::new(Self { handle })
3133
}
3234

35+
/// All of the open [`Project`]s
3336
pub fn all_open() -> Array<Project> {
3437
let mut count = 0;
3538
let result = unsafe { BNGetOpenProjects(&mut count) };
3639
assert!(!result.is_null());
3740
unsafe { Array::new(result, count, ()) }
3841
}
3942

40-
// TODO: Path here is actually local path?
4143
/// Create a new project
4244
///
4345
/// * `path` - Path to the project directory (.bnpr)
@@ -49,7 +51,6 @@ impl Project {
4951
NonNull::new(handle).map(|h| unsafe { Self::ref_from_raw(h) })
5052
}
5153

52-
// TODO: Path here is actually local path?
5354
/// Open an existing project
5455
///
5556
/// * `path` - Path to the project directory (.bnpr) or project metadata file (.bnpm)
@@ -73,7 +74,7 @@ impl Project {
7374
}
7475
}
7576

76-
/// Close a open project
77+
/// Close an open project
7778
pub fn close(&self) -> Result<(), ()> {
7879
if unsafe { BNProjectClose(self.handle.as_ptr()) } {
7980
Ok(())
@@ -87,9 +88,10 @@ impl Project {
8788
unsafe { BnString::into_string(BNProjectGetId(self.handle.as_ptr())) }
8889
}
8990

90-
/// Get the path of the project
91-
pub fn path(&self) -> String {
92-
unsafe { BnString::into_string(BNProjectGetPath(self.handle.as_ptr())) }
91+
/// Get the path on disk for the project
92+
pub fn path(&self) -> PathBuf {
93+
let path_str = unsafe { BnString::into_string(BNProjectGetPath(self.handle.as_ptr())) };
94+
PathBuf::from(path_str)
9395
}
9496

9597
/// Get the name of the project
@@ -136,6 +138,7 @@ impl Project {
136138
unsafe { BNProjectRemoveMetadata(self.handle.as_ptr(), key_raw.as_ptr()) }
137139
}
138140

141+
/// Call this after updating the [`ProjectFolder`] to have the changes reflected in the database.
139142
pub fn push_folder(&self, file: &ProjectFolder) -> bool {
140143
unsafe { BNProjectPushFolder(self.handle.as_ptr(), file.handle.as_ptr()) }
141144
}
@@ -212,6 +215,7 @@ impl Project {
212215
}
213216
}
214217

218+
// TODO: Rename create_folder_with_id and comment about the id being unique
215219
/// Recursively create files and folders in the project from a path on disk
216220
///
217221
/// * `parent` - Parent folder in the project that will contain the new folder
@@ -289,6 +293,7 @@ impl Project {
289293
}
290294
}
291295

296+
/// Call this after updating the [`ProjectFile`] to have the changes reflected in the database.
292297
pub fn push_file(&self, file: &ProjectFile) -> bool {
293298
unsafe { BNProjectPushFile(self.handle.as_ptr(), file.handle.as_ptr()) }
294299
}

rust/tests/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn create_delete_empty() {
2626
let project_path_received = project.path();
2727
assert_eq!(
2828
canonicalize(&project_path).unwrap(),
29-
canonicalize(project_path_received.to_string()).unwrap()
29+
canonicalize(project_path_received).unwrap()
3030
);
3131
let project_name_received = project.name();
3232
assert_eq!(project_name, project_name_received.as_str());

0 commit comments

Comments
 (0)