1
- use std:: ffi:: { OsStr , OsString } ;
1
+ use std:: ffi:: OsString ;
2
2
use std:: io:: Write ;
3
- use std:: fs:: { self , File } ;
4
- use std:: path:: { PathBuf } ;
3
+ use std:: fs;
4
+ use std:: path:: PathBuf ;
5
5
use std:: collections:: HashMap ;
6
6
use std:: thread;
7
7
use std:: time:: { Instant , Duration } ;
8
8
use std:: sync:: { mpsc, Arc , Mutex } ;
9
- use reqwest:: Url ;
10
9
use slint:: SharedString ;
11
10
use slint:: ComponentHandle ;
12
11
use tokio:: runtime:: Runtime ;
@@ -498,6 +497,9 @@ pub fn unpack_cold_clear(version: &str) -> Result<(), Box<dyn std::error::Error>
498
497
499
498
if let Err ( _) = zip_archive {
500
499
eprintln ! ( "ColdClear zip archive at '{zip_path:#?}' seems to be invalid. Redownloading." ) ;
500
+
501
+ fs:: remove_file ( zip_path) ?;
502
+
501
503
download_cold_clear ( version) ?;
502
504
503
505
zip_archive = ZipArchive :: new ( & zip_file) ;
@@ -522,44 +524,50 @@ pub fn unpack_cold_clear(version: &str) -> Result<(), Box<dyn std::error::Error>
522
524
return Ok ( ( ) ) ;
523
525
}
524
526
525
- pub fn get_available_offline_versions ( ) -> Result < Vec < String > , std:: io:: Error > {
526
- let path = paths:: get_cold_clear_download_path ( "" )
527
- . parent ( ) ?;
527
+ pub fn get_available_offline_versions ( ) -> Vec < String > {
528
+ let path = paths:: get_cold_clear_download_path ( "" ) ;
529
+ let path = path
530
+ . parent ( ) ;
531
+ if path. is_none ( ) {
532
+ return vec ! [ ] ;
533
+ }
534
+ let path = path. unwrap ( ) ;
528
535
529
- let entries = fs:: read_dir ( path) ?;
536
+ let entries = fs:: read_dir ( path) ;
537
+ if entries. is_err ( ) {
538
+ return vec ! [ ] ;
539
+ }
540
+ let entries = entries. unwrap ( ) ;
530
541
531
542
let mut versions: Vec < String > = Vec :: new ( ) ;
532
543
533
544
for entry in entries {
534
- let entry = entry? ;
535
-
545
+ if entry. is_err ( ) { continue ; }
546
+ let entry = entry . unwrap ( ) ;
536
547
let path = entry. path ( ) ;
537
- if !path. is_file ( ) {
538
- continue ;
539
- }
548
+ if !path. is_file ( ) { continue ; }
540
549
541
550
let name = path. file_name ( ) ;
542
- if name. is_none ( ) {
543
- continue ;
544
- }
551
+ if name. is_none ( ) { continue ; }
545
552
let name = name. unwrap ( )
546
- . to_str ( )
547
- . expect ( "Failed to get UTF-8 string from OsStr" ) ;
548
-
549
- if !name. ends_with ( ".zip" ) {
550
- continue ;
551
- }
553
+ . to_str ( ) ;
554
+ if name. is_none ( ) { continue ; }
555
+ let name = name. unwrap ( ) ;
556
+ if !name. ends_with ( ".zip" ) { continue ; }
552
557
553
558
let version = name
554
559
. replace ( ".zip" , "" ) ;
555
560
556
561
versions. push ( version) ;
557
562
}
558
563
559
- return Ok ( versions) ;
564
+ return versions;
560
565
}
561
566
562
- pub fn get_available_versions ( ) -> Result < Vec < String > , Box < dyn std:: error:: Error > > {
567
+ /// BLOCKING FUNCTION
568
+ /// This calls the GitHub API.
569
+ /// It shouldn't take *too* long, but you should wrap this in a separate thread if you can.
570
+ pub fn get_available_online_versions ( ) -> Result < Vec < String > , Box < dyn std:: error:: Error > > {
563
571
let api_url = paths:: COLD_CLEAR_RELEASES_API_URL ;
564
572
565
573
let response = reqwest:: blocking:: get ( api_url) ?;
@@ -585,4 +593,27 @@ pub fn get_available_versions() -> Result<Vec<String>, Box<dyn std::error::Error
585
593
}
586
594
587
595
return Ok ( versions) ;
596
+ }
597
+
598
+ /// BLOCKING FUNCTION
599
+ /// This calls the GitHub API.
600
+ /// It shouldn't take *too* long, but you should wrap this in a separate thread if you can.
601
+ pub fn get_available_versions ( ) -> Vec < String > {
602
+ let mut versions = get_available_offline_versions ( ) ;
603
+ let online_versions = get_available_online_versions ( ) ;
604
+
605
+ if let Err ( e) = online_versions {
606
+ eprintln ! ( "Failed to get ColdClear online version list: {:#?}" , e) ;
607
+ return versions;
608
+ }
609
+
610
+ let online_versions = online_versions. unwrap ( ) ;
611
+
612
+ for online_version in online_versions {
613
+ if !versions. contains ( & online_version) {
614
+ versions. push ( online_version) ;
615
+ }
616
+ }
617
+
618
+ return versions;
588
619
}
0 commit comments