1- use crate :: rc:: { Array , Ref , RefCountable } ;
1+ use crate :: rc:: { Array , Ref } ;
22use crate :: repository:: Repository ;
33use crate :: string:: IntoCStr ;
4- use binaryninjacore_sys:: {
5- BNCreateRepositoryManager , BNFreeRepositoryManager , BNGetRepositoryManager ,
6- BNNewRepositoryManagerReference , BNRepositoryGetRepositoryByPath , BNRepositoryManager ,
4+ use binaryninjacore_sys:: { BNRepositoryGetRepositoryByPath ,
75 BNRepositoryManagerAddRepository , BNRepositoryManagerCheckForUpdates ,
86 BNRepositoryManagerGetDefaultRepository , BNRepositoryManagerGetRepositories ,
97} ;
@@ -13,38 +11,24 @@ use std::ptr::NonNull;
1311
1412/// Keeps track of all the repositories and keeps the `enabled_plugins.json`
1513/// file coherent with the plugins that are installed/uninstalled enabled/disabled
16- #[ repr( transparent) ]
1714pub struct RepositoryManager {
18- handle : NonNull < BNRepositoryManager > ,
1915}
2016
2117impl RepositoryManager {
22- #[ allow( clippy:: should_implement_trait) ]
23- pub fn default ( ) -> Ref < Self > {
24- let result = unsafe { BNGetRepositoryManager ( ) } ;
25- unsafe { Self :: ref_from_raw ( NonNull :: new ( result) . unwrap ( ) ) }
26- }
27-
28- pub ( crate ) unsafe fn ref_from_raw ( handle : NonNull < BNRepositoryManager > ) -> Ref < Self > {
29- Ref :: new ( Self { handle } )
30- }
31-
32- pub fn new ( plugins_path : & str ) -> Ref < Self > {
33- let plugins_path = plugins_path. to_cstr ( ) ;
34- let result = unsafe { BNCreateRepositoryManager ( plugins_path. as_ptr ( ) ) } ;
35- unsafe { Self :: ref_from_raw ( NonNull :: new ( result) . unwrap ( ) ) }
18+ pub fn new ( ) -> Self {
19+ Self { }
3620 }
3721
3822 /// Check for updates for all managed [`Repository`] objects
3923 pub fn check_for_updates ( & self ) -> bool {
40- unsafe { BNRepositoryManagerCheckForUpdates ( self . handle . as_ptr ( ) ) }
24+ unsafe { BNRepositoryManagerCheckForUpdates ( ) }
4125 }
4226
4327 /// List of [`Repository`] objects being managed
4428 pub fn repositories ( & self ) -> Array < Repository > {
4529 let mut count = 0 ;
4630 let result =
47- unsafe { BNRepositoryManagerGetRepositories ( self . handle . as_ptr ( ) , & mut count) } ;
31+ unsafe { BNRepositoryManagerGetRepositories ( & mut count) } ;
4832 assert ! ( !result. is_null( ) ) ;
4933 unsafe { Array :: new ( result, count, ( ) ) }
5034 }
@@ -64,20 +48,20 @@ impl RepositoryManager {
6448 let url = url. to_cstr ( ) ;
6549 let repo_path = repository_path. to_cstr ( ) ;
6650 unsafe {
67- BNRepositoryManagerAddRepository ( self . handle . as_ptr ( ) , url. as_ptr ( ) , repo_path. as_ptr ( ) )
51+ BNRepositoryManagerAddRepository ( url. as_ptr ( ) , repo_path. as_ptr ( ) )
6852 }
6953 }
7054
7155 pub fn repository_by_path ( & self , path : & Path ) -> Option < Repository > {
7256 let path = path. to_cstr ( ) ;
7357 let result =
74- unsafe { BNRepositoryGetRepositoryByPath ( self . handle . as_ptr ( ) , path. as_ptr ( ) ) } ;
58+ unsafe { BNRepositoryGetRepositoryByPath ( path. as_ptr ( ) ) } ;
7559 NonNull :: new ( result) . map ( |raw| unsafe { Repository :: from_raw ( raw) } )
7660 }
7761
7862 /// Gets the default [`Repository`]
7963 pub fn default_repository ( & self ) -> Ref < Repository > {
80- let result = unsafe { BNRepositoryManagerGetDefaultRepository ( self . handle . as_ptr ( ) ) } ;
64+ let result = unsafe { BNRepositoryManagerGetDefaultRepository ( ) } ;
8165 assert ! ( !result. is_null( ) ) ;
8266 unsafe { Repository :: ref_from_raw ( NonNull :: new ( result) . unwrap ( ) ) }
8367 }
@@ -90,23 +74,3 @@ impl Debug for RepositoryManager {
9074 . finish ( )
9175 }
9276}
93-
94- impl ToOwned for RepositoryManager {
95- type Owned = Ref < Self > ;
96-
97- fn to_owned ( & self ) -> Self :: Owned {
98- unsafe { RefCountable :: inc_ref ( self ) }
99- }
100- }
101-
102- unsafe impl RefCountable for RepositoryManager {
103- unsafe fn inc_ref ( handle : & Self ) -> Ref < Self > {
104- Self :: ref_from_raw (
105- NonNull :: new ( BNNewRepositoryManagerReference ( handle. handle . as_ptr ( ) ) ) . unwrap ( ) ,
106- )
107- }
108-
109- unsafe fn dec_ref ( handle : & Self ) {
110- BNFreeRepositoryManager ( handle. handle . as_ptr ( ) )
111- }
112- }
0 commit comments