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 } ;
9
2
10
3
use msfs:: { commbus:: * , sys:: sGaugeDrawData, MSFSEvent } ;
11
4
use navigation_database:: {
@@ -108,7 +101,7 @@ impl<'a> Dispatcher<'a> {
108
101
fn list_packages ( & self , sort : bool , filter : bool ) -> Vec < PackageInfo > {
109
102
let navigation_data_path = Path :: new ( consts:: NAVIGATION_DATA_WORK_LOCATION ) ;
110
103
111
- if !Path :: exists ( navigation_data_path) {
104
+ if !util :: path_exists ( navigation_data_path) {
112
105
fs:: create_dir ( navigation_data_path) . unwrap ( ) ;
113
106
}
114
107
@@ -152,6 +145,12 @@ impl<'a> Dispatcher<'a> {
152
145
}
153
146
154
147
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
+
155
154
let base_path = Path :: new ( consts:: NAVIGATION_DATA_WORK_LOCATION ) ;
156
155
157
156
let active_path = base_path. join ( "active" ) ;
@@ -191,6 +190,8 @@ impl<'a> Dispatcher<'a> {
191
190
192
191
// Check for format change and updates the used interface
193
192
if package_info. cycle . format != self . database . borrow ( ) . get_database_type ( ) . as_str ( ) {
193
+ println ! ( "Changing to: {}" , package_info. cycle. format) ;
194
+
194
195
let new_format = InterfaceFormat :: from ( & package_info. cycle . format ) ;
195
196
196
197
self . database . replace ( match new_format {
@@ -281,7 +282,7 @@ impl<'a> Dispatcher<'a> {
281
282
282
283
let cycle_path = file. path ( ) . join ( "cycle.json" ) ;
283
284
284
- if !Path :: exists ( & cycle_path) {
285
+ if !path_exists ( & cycle_path) {
285
286
println ! (
286
287
"[NAVIGRAPH]: Can't find cycle.json in {}" ,
287
288
file. path( ) . to_string_lossy( )
@@ -312,8 +313,8 @@ impl<'a> Dispatcher<'a> {
312
313
fn copy_old_data ( & self ) -> Result < ( ) , Box < dyn Error > > {
313
314
let old_path = Path :: new ( consts:: NAVIGATION_DATA_OLD_WORK_LOCATION ) ;
314
315
315
- if !util :: path_exists ( old_path) {
316
- return Ok ( ( ) )
316
+ if !path_exists ( old_path) {
317
+ return Ok ( ( ) ) ;
317
318
}
318
319
319
320
let new_path = Path :: new ( consts:: NAVIGATION_DATA_WORK_LOCATION ) ;
@@ -328,7 +329,7 @@ impl<'a> Dispatcher<'a> {
328
329
. collect ( ) ;
329
330
330
331
if uuid_list. contains ( & old_uuid) {
331
- return Ok ( ( ) )
332
+ return Ok ( ( ) ) ;
332
333
}
333
334
334
335
let fix_file = old_path. join ( "filethatfixeseverything" ) ;
@@ -337,20 +338,35 @@ impl<'a> Dispatcher<'a> {
337
338
fs:: File :: create ( fix_file) ?;
338
339
}
339
340
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) ) ?;
341
342
342
343
util:: delete_folder_recursively ( old_path, None ) ?;
343
344
344
345
Ok ( ( ) )
345
346
}
346
347
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
+
348
355
let package_path = Path :: new ( consts:: NAVIGATION_DATA_WORK_LOCATION ) . join ( uuid) ;
349
356
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
+ }
351
361
}
352
362
353
363
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
+
354
370
let bundle_path = Path :: new ( consts:: NAVIGATION_DATA_DEFAULT_LOCATION ) ;
355
371
356
372
let mut bundle_ids = vec ! [ ] ;
0 commit comments