1- use std:: {
2- cell:: RefCell ,
3- error:: Error ,
4- fs,
5- io:: { self } ,
6- path:: Path ,
7- rc:: Rc ,
8- } ;
1+ use std:: { cell:: RefCell , error:: Error , fs, path:: Path , rc:: Rc } ;
92
103use msfs:: { commbus:: * , sys:: sGaugeDrawData, MSFSEvent } ;
114use navigation_database:: {
@@ -108,7 +101,7 @@ impl<'a> Dispatcher<'a> {
108101 fn list_packages ( & self , sort : bool , filter : bool ) -> Vec < PackageInfo > {
109102 let navigation_data_path = Path :: new ( consts:: NAVIGATION_DATA_WORK_LOCATION ) ;
110103
111- if !Path :: exists ( navigation_data_path) {
104+ if !util :: path_exists ( navigation_data_path) {
112105 fs:: create_dir ( navigation_data_path) . unwrap ( ) ;
113106 }
114107
@@ -152,6 +145,12 @@ impl<'a> Dispatcher<'a> {
152145 }
153146
154147 fn set_package ( & self , uuid : String ) -> Result < bool , Box < dyn Error > > {
148+ let download_status = self . downloader . download_status . borrow ( ) . clone ( ) ;
149+
150+ if download_status == DownloadStatus :: Downloading {
151+ return Err ( "Cannot do operations while downloading!" . into ( ) ) ;
152+ }
153+
155154 let base_path = Path :: new ( consts:: NAVIGATION_DATA_WORK_LOCATION ) ;
156155
157156 let active_path = base_path. join ( "active" ) ;
@@ -191,6 +190,8 @@ impl<'a> Dispatcher<'a> {
191190
192191 // Check for format change and updates the used interface
193192 if package_info. cycle . format != self . database . borrow ( ) . get_database_type ( ) . as_str ( ) {
193+ println ! ( "Changing to: {}" , package_info. cycle. format) ;
194+
194195 let new_format = InterfaceFormat :: from ( & package_info. cycle . format ) ;
195196
196197 self . database . replace ( match new_format {
@@ -281,7 +282,7 @@ impl<'a> Dispatcher<'a> {
281282
282283 let cycle_path = file. path ( ) . join ( "cycle.json" ) ;
283284
284- if !Path :: exists ( & cycle_path) {
285+ if !path_exists ( & cycle_path) {
285286 println ! (
286287 "[NAVIGRAPH]: Can't find cycle.json in {}" ,
287288 file. path( ) . to_string_lossy( )
@@ -312,8 +313,8 @@ impl<'a> Dispatcher<'a> {
312313 fn copy_old_data ( & self ) -> Result < ( ) , Box < dyn Error > > {
313314 let old_path = Path :: new ( consts:: NAVIGATION_DATA_OLD_WORK_LOCATION ) ;
314315
315- if !util :: path_exists ( old_path) {
316- return Ok ( ( ) )
316+ if !path_exists ( old_path) {
317+ return Ok ( ( ) ) ;
317318 }
318319
319320 let new_path = Path :: new ( consts:: NAVIGATION_DATA_WORK_LOCATION ) ;
@@ -328,7 +329,7 @@ impl<'a> Dispatcher<'a> {
328329 . collect ( ) ;
329330
330331 if uuid_list. contains ( & old_uuid) {
331- return Ok ( ( ) )
332+ return Ok ( ( ) ) ;
332333 }
333334
334335 let fix_file = old_path. join ( "filethatfixeseverything" ) ;
@@ -337,20 +338,35 @@ impl<'a> Dispatcher<'a> {
337338 fs:: File :: create ( fix_file) ?;
338339 }
339340
340- util:: copy_files_to_folder ( & old_path, & new_path. join ( old_uuid) ) ?;
341+ util:: copy_files_to_folder ( old_path, & new_path. join ( old_uuid) ) ?;
341342
342343 util:: delete_folder_recursively ( old_path, None ) ?;
343344
344345 Ok ( ( ) )
345346 }
346347
347- fn delete_package ( & self , uuid : String ) -> io:: Result < ( ) > {
348+ fn delete_package ( & self , uuid : String ) -> Result < ( ) , Box < dyn Error > > {
349+ let download_status = self . downloader . download_status . borrow ( ) . clone ( ) ;
350+
351+ if download_status == DownloadStatus :: Downloading {
352+ return Err ( "Cannot do operations while downloading!" . into ( ) ) ;
353+ }
354+
348355 let package_path = Path :: new ( consts:: NAVIGATION_DATA_WORK_LOCATION ) . join ( uuid) ;
349356
350- util:: delete_folder_recursively ( & package_path, None )
357+ match util:: delete_folder_recursively ( & package_path, None ) {
358+ Err ( err) => Err ( err. into ( ) ) ,
359+ Ok ( _) => Ok ( ( ) ) ,
360+ }
351361 }
352362
353363 fn clean_up_packages ( & self , count_max : Option < i32 > ) -> Result < ( ) , Box < dyn Error > > {
364+ let download_status = self . downloader . download_status . borrow ( ) . clone ( ) ;
365+
366+ if download_status == DownloadStatus :: Downloading {
367+ return Err ( "Cannot do operations while downloading!" . into ( ) ) ;
368+ }
369+
354370 let bundle_path = Path :: new ( consts:: NAVIGATION_DATA_DEFAULT_LOCATION ) ;
355371
356372 let mut bundle_ids = vec ! [ ] ;
0 commit comments