1- use crate :: cache:: container:: add_cached_container;
1+ use crate :: cache:: container:: { add_cached_container, for_cached_containers } ;
22use crate :: container:: disk:: { DiskContainer , DiskContainerSource } ;
33use crate :: container:: { ContainerError , SourcePath } ;
44use crate :: convert:: platform_to_target;
@@ -12,6 +12,7 @@ use binaryninja::interaction::{
1212use binaryninja:: rc:: Ref ;
1313use std:: collections:: HashMap ;
1414use std:: path:: PathBuf ;
15+ use std:: sync:: atomic:: AtomicBool ;
1516use std:: thread;
1617use warp:: WarpFile ;
1718
@@ -125,6 +126,7 @@ impl LoadSignatureFile {
125126 let rerun_matcher = RunMatcherField :: from_form ( & form) . unwrap_or ( false ) ;
126127
127128 let source_file_path = SourcePath :: new ( file_path. clone ( ) ) ;
129+ let source_file_id = source_file_path. to_source_id ( ) ;
128130
129131 let file = match LoadSignatureFile :: read_file ( & view, source_file_path. clone ( ) ) {
130132 Ok ( file) => file,
@@ -134,6 +136,26 @@ impl LoadSignatureFile {
134136 }
135137 } ;
136138
139+ // Verify we have not already loaded the file.
140+ let already_exists = AtomicBool :: new ( false ) ;
141+ for_cached_containers ( |c| {
142+ if let Ok ( _) = c. source_path ( & source_file_id) {
143+ // TODO: What happens if path differs? Warn?
144+ already_exists. store ( true , std:: sync:: atomic:: Ordering :: SeqCst ) ;
145+ }
146+ } ) ;
147+ if already_exists. load ( std:: sync:: atomic:: Ordering :: SeqCst ) {
148+ let res = show_message_box (
149+ "Load again?" ,
150+ "File already loaded, would you like to load it again?" ,
151+ MessageBoxButtonSet :: YesNoButtonSet ,
152+ MessageBoxIcon :: WarningIcon ,
153+ ) ;
154+ if res != MessageBoxButtonResult :: YesButton {
155+ return ;
156+ }
157+ }
158+
137159 let container_source = DiskContainerSource :: new ( source_file_path. clone ( ) , file) ;
138160 log:: info!( "Loading container source: '{}'" , container_source. path) ;
139161 let mut map = HashMap :: new ( ) ;
0 commit comments