1
1
use std:: future:: Future ;
2
+ use std:: str:: FromStr ;
2
3
use std:: sync:: { Arc , Mutex } ;
3
4
use std:: sync:: atomic:: AtomicUsize ;
5
+ use log:: info;
4
6
use serde:: { Deserialize , Serialize } ;
5
7
use versions:: Version ;
6
- use crate :: AppState ;
8
+ use crate :: { AppState , DB } ;
9
+ use crate :: auth:: generate_authorization_header;
10
+ use crate :: db:: DatabaseImpls ;
7
11
use crate :: downloads:: progress:: ProgressChecker ;
8
12
9
13
#[ derive( Serialize , Deserialize ) ]
@@ -32,6 +36,7 @@ pub enum GameDownloadError {
32
36
ManifestAlreadyExists ,
33
37
ManifestDoesNotExist ,
34
38
ManifestDownloadError ,
39
+ StatusError ( u16 )
35
40
}
36
41
#[ derive( Serialize , Deserialize , Clone , Eq , PartialEq , Ord , PartialOrd ) ]
37
42
#[ serde( rename_all="camelCase" ) ]
@@ -72,7 +77,39 @@ impl GameDownload {
72
77
if self . manifest . is_some ( ) {
73
78
return Err ( GameDownloadError :: ManifestAlreadyExists ) ;
74
79
}
75
- todo ! ( ) // Need to actually download the manifest
80
+
81
+ info ! ( "Getting url components" ) ;
82
+ let base_url = DB . fetch_base_url ( ) ;
83
+ let manifest_url = base_url
84
+ . join (
85
+ format ! (
86
+ "/api/v1/client/metadata/manifest?id={}&version={}" ,
87
+ self . id,
88
+ self . version. to_string( )
89
+ )
90
+ . as_str ( )
91
+ )
92
+ . unwrap ( ) ;
93
+
94
+ info ! ( "Generating authorization header" ) ;
95
+ let header = generate_authorization_header ( ) ;
96
+
97
+ info ! ( "Generating & sending client" ) ;
98
+ let client = reqwest:: blocking:: Client :: new ( ) ;
99
+ let response = client
100
+ . get ( manifest_url. to_string ( ) )
101
+ . header ( "Authorization" , header)
102
+ . send ( )
103
+ . unwrap ( ) ;
104
+
105
+ info ! ( "Got status" ) ;
106
+ if response. status ( ) != 200 {
107
+ return Err ( GameDownloadError :: StatusError ( response. status ( ) . as_u16 ( ) ) ) ;
108
+ }
109
+
110
+ info ! ( "{:?}" , response. text( ) ) ;
111
+
112
+ Ok ( ( ) )
76
113
}
77
114
pub fn change_state ( & self , state : GameDownloadState ) {
78
115
let mut lock = self . state . lock ( ) . unwrap ( ) ;
@@ -92,16 +129,23 @@ fn download_game_chunk(ctx: GameChunkCtx) {
92
129
#[ tauri:: command]
93
130
pub async fn start_game_download (
94
131
game_id : String ,
95
- game_version : Version ,
132
+ game_version : String ,
96
133
max_threads : usize ,
97
134
state : tauri:: State < ' _ , Mutex < AppState > > ,
98
135
) -> Result < ( ) , GameDownloadError > {
99
- let mut download = Arc :: new ( GameDownload :: new ( game_id, game_version) ) ;
100
- let mut app_state = state. lock ( ) . unwrap ( ) ;
136
+
137
+ info ! ( "Triggered Game Download" ) ;
138
+
139
+ let mut download = Arc :: new ( GameDownload :: new ( game_id, Version :: from_str ( & * game_version) . unwrap ( ) ) ) ;
140
+ //let mut app_state = state.lock().unwrap();
101
141
102
142
let tmp = download. clone ( ) ;
103
- let manifest = & tmp. manifest ;
143
+ //let manifest = &tmp.manifest;
144
+
145
+ let res = download. download_manifest ( ) . await ;
104
146
147
+ res
148
+ /*
105
149
let Some(unlocked) = manifest else { return Err(GameDownloadError::ManifestDoesNotExist) };
106
150
let lock = unlocked.lock().unwrap();
107
151
@@ -119,5 +163,7 @@ pub async fn start_game_download(
119
163
120
164
app_state.game_downloads.push(download.clone());
121
165
download.download(max_threads, chunks).await
166
+
167
+ */
122
168
}
123
169
0 commit comments