mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-10 04:22:13 +10:00
Game downloads from the client are working (multithreaded) by parsing in gameID, GameVersion, and maxThreads from FE (#1)
This commit is contained in:
@ -3,13 +3,16 @@
|
||||
<button class="w-full rounded-md p-4 bg-blue-600 text-white" @click="requestGameWrapper">
|
||||
Load Data
|
||||
</button>
|
||||
<button class="w-full rounded-md p-4 bg-blue-600 text-white" @click="requestGameWrapper">
|
||||
Download Game
|
||||
</button>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
async function requestGame() {
|
||||
console.log("Requested game from FE");
|
||||
await invoke("start_game_download", { gameId: "94b8ac10-a6fc-4a94-b519-e6df78018e26", gameVersion: "1.11.2", maxThreads: 4 });
|
||||
await invoke("start_game_download", { gameId: "328a276d-4777-4a47-97f1-15069c1e5f66", gameVersion: "1.11.2", maxThreads: 4 });
|
||||
}
|
||||
function requestGameWrapper() {
|
||||
console.log("Wrapper started");
|
||||
|
||||
@ -24,6 +24,7 @@ pub enum DatabaseGameStatus {
|
||||
Downloading,
|
||||
Installed,
|
||||
Updating,
|
||||
|
||||
Uninstalling,
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use log::info;
|
||||
use crate::auth::generate_authorization_header;
|
||||
use crate::DB;
|
||||
use crate::db::DatabaseImpls;
|
||||
@ -5,6 +6,7 @@ use crate::downloads::manifest::DropDownloadContext;
|
||||
|
||||
|
||||
pub fn download_game_chunk(ctx: DropDownloadContext) {
|
||||
info!("Downloading game chunk");
|
||||
let base_url = DB.fetch_base_url();
|
||||
|
||||
let index = ctx.index;
|
||||
@ -13,8 +15,8 @@ pub fn download_game_chunk(ctx: DropDownloadContext) {
|
||||
let client = reqwest::blocking::Client::new();
|
||||
let chunk_url = base_url.join(
|
||||
&format!(
|
||||
"/api/v1/client/user/library?gameId={}&versionName={}&filename={}&chunkIndex={}",
|
||||
chunk.ids[index],
|
||||
"/api/v1/client/chunk?id={}&version={}&name={}&chunk={}",
|
||||
ctx.game_id,
|
||||
ctx.version,
|
||||
ctx.file_name,
|
||||
index
|
||||
@ -27,6 +29,6 @@ pub fn download_game_chunk(ctx: DropDownloadContext) {
|
||||
.header("Authorization", header)
|
||||
.send()
|
||||
.unwrap();
|
||||
println!("{}", response.text().unwrap());
|
||||
println!("Response text: {}", response.text().unwrap());
|
||||
// Need to implement actual download logic
|
||||
}
|
||||
@ -32,9 +32,9 @@ pub enum GameDownloadState {
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
|
||||
pub enum GameDownloadError {
|
||||
ManifestDownloadError,
|
||||
StatusError(u16),
|
||||
SystemError(SystemError),
|
||||
ManifestDownload,
|
||||
Status(u16),
|
||||
System(SystemError),
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Debug)]
|
||||
pub enum SystemError {
|
||||
@ -103,13 +103,14 @@ impl GameDownload {
|
||||
|
||||
if response.status() != 200 {
|
||||
info!("Error status: {}", response.status());
|
||||
return Err(GameDownloadError::StatusError(response.status().as_u16()));
|
||||
return Err(GameDownloadError::Status(response.status().as_u16()));
|
||||
}
|
||||
|
||||
let manifest_download = response.json::<DropManifest>().await.unwrap();
|
||||
info!("{:?}", manifest_download);
|
||||
if let Ok(mut manifest) = self.manifest.lock() {
|
||||
*manifest = Some(manifest_download)
|
||||
} else { return Err(GameDownloadError::SystemError(SystemError::MutexLockFailed)); }
|
||||
} else { return Err(GameDownloadError::System(SystemError::MutexLockFailed)); }
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -119,7 +120,7 @@ impl GameDownload {
|
||||
*lock = state;
|
||||
}
|
||||
}
|
||||
pub fn to_contexts(manifest: &DropManifest, version: String) -> Vec<DropDownloadContext> {
|
||||
pub fn to_contexts(manifest: &DropManifest, version: String, game_id: String) -> Vec<DropDownloadContext> {
|
||||
let mut contexts = Vec::new();
|
||||
let mut counter = 0;
|
||||
let mut prev_key: String = String::new();
|
||||
@ -130,6 +131,7 @@ pub fn to_contexts(manifest: &DropManifest, version: String) -> Vec<DropDownload
|
||||
file_name: key.0.clone(),
|
||||
version: version.to_string(),
|
||||
index: counter,
|
||||
game_id: game_id.to_string(),
|
||||
});
|
||||
if prev_key == *key.0 {
|
||||
counter += 1;
|
||||
@ -150,17 +152,17 @@ pub async fn start_game_download(
|
||||
) -> Result<(), GameDownloadError> {
|
||||
info!("Triggered Game Download");
|
||||
|
||||
let download = Arc::new(GameDownload::new(game_id, game_version.clone()));
|
||||
let download = Arc::new(GameDownload::new(game_id.clone(), game_version.clone()));
|
||||
|
||||
|
||||
download.ensure_manifest_exists().await?;
|
||||
|
||||
let local_manifest = {
|
||||
let manifest = download.manifest.lock().unwrap();
|
||||
(*manifest).clone().unwrap()
|
||||
};
|
||||
|
||||
let manifest = download.manifest.lock().unwrap();
|
||||
let local_manifest = (*manifest).clone().unwrap();
|
||||
|
||||
|
||||
let contexts = to_contexts(&local_manifest, game_version.clone());
|
||||
let contexts = to_contexts(&local_manifest, game_version.clone(), game_id);
|
||||
|
||||
let _ = download.download(max_threads, contexts).await;
|
||||
|
||||
|
||||
@ -16,5 +16,6 @@ pub struct DropDownloadContext {
|
||||
pub file_chunk: Arc<DropChunk>,
|
||||
pub file_name: String,
|
||||
pub version: String,
|
||||
pub index: usize
|
||||
pub index: usize,
|
||||
pub game_id: String
|
||||
}
|
||||
@ -22,7 +22,7 @@ use std::{
|
||||
use std::sync::Arc;
|
||||
use tauri_plugin_deep_link::DeepLinkExt;
|
||||
use crate::db::DatabaseImpls;
|
||||
use crate::downloads::game_download::GameDownload;
|
||||
use crate::downloads::game_download::{start_game_download, GameDownload};
|
||||
|
||||
#[derive(Clone, Copy, Serialize)]
|
||||
pub enum AppStatus {
|
||||
@ -110,6 +110,8 @@ pub fn run() {
|
||||
// Library
|
||||
fetch_library,
|
||||
fetch_game,
|
||||
// Downloads
|
||||
start_game_download
|
||||
])
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.setup(|app| {
|
||||
|
||||
Reference in New Issue
Block a user