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} ;
@@ -15,36 +13,20 @@ use std::ptr::NonNull;
1513/// file coherent with the plugins that are installed/uninstalled enabled/disabled
1614#[ repr( transparent) ]
1715pub struct RepositoryManager {
18- handle : NonNull < BNRepositoryManager > ,
1916}
2017
2118impl 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 ( ) ) }
36- }
3719
3820 /// Check for updates for all managed [`Repository`] objects
3921 pub fn check_for_updates ( & self ) -> bool {
40- unsafe { BNRepositoryManagerCheckForUpdates ( self . handle . as_ptr ( ) ) }
22+ unsafe { BNRepositoryManagerCheckForUpdates ( ) }
4123 }
4224
4325 /// List of [`Repository`] objects being managed
4426 pub fn repositories ( & self ) -> Array < Repository > {
4527 let mut count = 0 ;
4628 let result =
47- unsafe { BNRepositoryManagerGetRepositories ( self . handle . as_ptr ( ) , & mut count) } ;
29+ unsafe { BNRepositoryManagerGetRepositories ( & mut count) } ;
4830 assert ! ( !result. is_null( ) ) ;
4931 unsafe { Array :: new ( result, count, ( ) ) }
5032 }
@@ -64,20 +46,20 @@ impl RepositoryManager {
6446 let url = url. to_cstr ( ) ;
6547 let repo_path = repository_path. to_cstr ( ) ;
6648 unsafe {
67- BNRepositoryManagerAddRepository ( self . handle . as_ptr ( ) , url. as_ptr ( ) , repo_path. as_ptr ( ) )
49+ BNRepositoryManagerAddRepository ( url. as_ptr ( ) , repo_path. as_ptr ( ) )
6850 }
6951 }
7052
7153 pub fn repository_by_path ( & self , path : & Path ) -> Option < Repository > {
7254 let path = path. to_cstr ( ) ;
7355 let result =
74- unsafe { BNRepositoryGetRepositoryByPath ( self . handle . as_ptr ( ) , path. as_ptr ( ) ) } ;
56+ unsafe { BNRepositoryGetRepositoryByPath ( path. as_ptr ( ) ) } ;
7557 NonNull :: new ( result) . map ( |raw| unsafe { Repository :: from_raw ( raw) } )
7658 }
7759
7860 /// Gets the default [`Repository`]
7961 pub fn default_repository ( & self ) -> Ref < Repository > {
80- let result = unsafe { BNRepositoryManagerGetDefaultRepository ( self . handle . as_ptr ( ) ) } ;
62+ let result = unsafe { BNRepositoryManagerGetDefaultRepository ( ) } ;
8163 assert ! ( !result. is_null( ) ) ;
8264 unsafe { Repository :: ref_from_raw ( NonNull :: new ( result) . unwrap ( ) ) }
8365 }
@@ -90,23 +72,3 @@ impl Debug for RepositoryManager {
9072 . finish ( )
9173 }
9274}
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