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