From 975eec96bea44b714b510de077ccb2ee2cccd49b Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Sat, 12 Apr 2025 15:42:02 -0300 Subject: [PATCH 1/4] feat: add force download option to http downloader --- rust_rpc/src/main.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/rust_rpc/src/main.rs b/rust_rpc/src/main.rs index 7d7f28f5..9a8b3d14 100644 --- a/rust_rpc/src/main.rs +++ b/rust_rpc/src/main.rs @@ -23,6 +23,7 @@ const DEFAULT_SILENT: bool = false; const DEFAULT_LOG: bool = false; const DEFAULT_FORCE_NEW: bool = false; const DEFAULT_RESUME_ONLY: bool = false; +const DEFAULT_FORCE_DOWNLOAD: bool = false; const HEADER_SIZE: usize = 4096; const MAGIC_NUMBER: &[u8; 5] = b"HYDRA"; const FORMAT_VERSION: u8 = 1; @@ -74,6 +75,10 @@ struct CliArgs { #[arg(short = 'r', long, default_value_t = DEFAULT_RESUME_ONLY)] resume_only: bool, + /// force download, ignore some verification checks + #[arg(short = 'F', long, default_value_t = DEFAULT_FORCE_DOWNLOAD)] + force_download: bool, + /// HTTP headers to send with request (format: "Key: Value") #[arg(short = 'H', long)] header: Vec, @@ -91,6 +96,7 @@ struct DownloadConfig { force_new: bool, resume_only: bool, headers: Vec, + force_download: bool, } impl DownloadConfig { @@ -473,6 +479,8 @@ impl Downloader { let pb_clone = progress.bar.clone(); let manager_clone = Arc::clone(&resume_manager); let headers = self.config.headers.clone(); + let force_download = self.config.force_download; + let should_log = self.config.should_log(); let chunk_size = self.config.chunk_size as u64; let chunk_index = (start / chunk_size) as usize; @@ -487,6 +495,8 @@ impl Downloader { pb_clone, DEFAULT_MAX_RETRIES, &headers, + force_download, + should_log, ) .await; @@ -554,6 +564,8 @@ impl Downloader { progress_bar: Option, max_retries: usize, headers: &[String], + force_download: bool, + should_log: bool, ) -> Result<()> { let mut retries = 0; loop { @@ -565,6 +577,8 @@ impl Downloader { file.clone(), progress_bar.clone(), headers, + force_download, + should_log, ) .await { @@ -591,6 +605,8 @@ impl Downloader { file: Arc>>, progress_bar: Option, headers: &[String], + force_download: bool, + should_log: bool, ) -> Result<()> { let mut req = client .get(&url) @@ -607,7 +623,11 @@ impl Downloader { let resp = req.send().await?; if resp.status() != StatusCode::PARTIAL_CONTENT && resp.status() != StatusCode::OK { - anyhow::bail!("Server does not support Range requests"); + if !force_download { + anyhow::bail!("Server does not support Range requests"); + } else if should_log { + println!("Server does not support Range requests, ignoring..."); + } } let mut stream = resp.bytes_stream(); @@ -677,9 +697,13 @@ impl Downloader { .await?; if range_check.status() != StatusCode::PARTIAL_CONTENT { - anyhow::bail!( - "Server does not support Range requests, cannot continue with parallel download" - ); + if !self.config.force_download { + anyhow::bail!( + "Server does not support Range requests, cannot continue with parallel download" + ); + } else if self.config.should_log() { + println!("Server does not support Range requests, ignoring..."); + } } } @@ -909,6 +933,7 @@ async fn main() -> Result<()> { force_new: args.force_new, resume_only: args.resume_only, headers: args.header, + force_download: args.force_download, }; if config.force_new && config.resume_only { From bd018399fb60934ce7c5cb801a6126623ee9d3ce Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Sat, 12 Apr 2025 15:52:18 -0300 Subject: [PATCH 2/4] fix: typo --- src/locales/en/translation.json | 2 +- src/locales/pt-BR/translation.json | 2 +- src/renderer/src/hooks/use-download.ts | 2 +- .../src/pages/settings/settings-behavior.tsx | 12 ++++++------ src/types/level.types.ts | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 57a43435..bfab174f 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -355,7 +355,7 @@ "common_redist_description": "Common redistributables are required to run some games. Installing them is recommended to avoid issues.", "install_common_redist": "Install", "installing_common_redist": "Installing…", - "show_download_speed_in_megabits": "Show download speed in megabits per second" + "show_download_speed_in_megabytes": "Show download speed in megabytes per second" }, "notifications": { "download_complete": "Download complete", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index 4f27bcf9..65a97dc3 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -342,7 +342,7 @@ "common_redist_description": "Componentes recomendados são necessários para executar alguns jogos. A instalação deles é recomendada para evitar problemas.", "install_common_redist": "Instalar", "installing_common_redist": "Instalando…", - "show_download_speed_in_megabits": "Exibir taxas de download em megabits por segundo" + "show_download_speed_in_megabytes": "Exibir taxas de download em megabytes por segundo" }, "notifications": { "download_complete": "Download concluído", diff --git a/src/renderer/src/hooks/use-download.ts b/src/renderer/src/hooks/use-download.ts index a3b655d1..f6cc071f 100644 --- a/src/renderer/src/hooks/use-download.ts +++ b/src/renderer/src/hooks/use-download.ts @@ -102,7 +102,7 @@ export function useDownload() { }; const formatDownloadSpeed = (downloadSpeed: number): string => { - return userPrefs?.showDownloadSpeedInMegabits + return userPrefs?.showDownloadSpeedInMegabytes ? `${formatBytes(downloadSpeed)}/s` : formatBytesToMbps(downloadSpeed); }; diff --git a/src/renderer/src/pages/settings/settings-behavior.tsx b/src/renderer/src/pages/settings/settings-behavior.tsx index 230bd065..0afbf5b6 100644 --- a/src/renderer/src/pages/settings/settings-behavior.tsx +++ b/src/renderer/src/pages/settings/settings-behavior.tsx @@ -23,7 +23,7 @@ export function SettingsBehavior() { enableAutoInstall: false, seedAfterDownloadComplete: false, showHiddenAchievementsDescription: false, - showDownloadSpeedInMegabits: false, + showDownloadSpeedInMegabytes: false, }); const { t } = useTranslation("settings"); @@ -41,8 +41,8 @@ export function SettingsBehavior() { userPreferences.seedAfterDownloadComplete ?? false, showHiddenAchievementsDescription: userPreferences.showHiddenAchievementsDescription ?? false, - showDownloadSpeedInMegabits: - userPreferences.showDownloadSpeedInMegabits ?? false, + showDownloadSpeedInMegabytes: + userPreferences.showDownloadSpeedInMegabytes ?? false, }); } }, [userPreferences]); @@ -144,11 +144,11 @@ export function SettingsBehavior() { /> handleChange({ - showDownloadSpeedInMegabits: !form.showDownloadSpeedInMegabits, + showDownloadSpeedInMegabytes: !form.showDownloadSpeedInMegabytes, }) } /> diff --git a/src/types/level.types.ts b/src/types/level.types.ts index cc5b1d8a..21836870 100644 --- a/src/types/level.types.ts +++ b/src/types/level.types.ts @@ -85,7 +85,7 @@ export interface UserPreferences { repackUpdatesNotificationsEnabled?: boolean; achievementNotificationsEnabled?: boolean; friendRequestNotificationsEnabled?: boolean; - showDownloadSpeedInMegabits?: boolean; + showDownloadSpeedInMegabytes?: boolean; } export interface ScreenState { From e3670f5b5a1cb4891e8954d0e06c029d00496970 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Sat, 12 Apr 2025 15:54:45 -0300 Subject: [PATCH 3/4] fix: add force download flag in httpdl args --- python_rpc/http_downloader.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python_rpc/http_downloader.py b/python_rpc/http_downloader.py index f1e00818..5c4a701a 100644 --- a/python_rpc/http_downloader.py +++ b/python_rpc/http_downloader.py @@ -16,6 +16,7 @@ class HttpDownloader: cmd.extend([ "--chunk-size", "10", "--buffer-size", "16", + "--force-download", "--log", "--silent" ]) From be232d88e45e234ffb5a21b7d03efa63b4a7bd9c Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Sat, 12 Apr 2025 15:55:59 -0300 Subject: [PATCH 4/4] fix: handle exception in http downloader by returning None --- python_rpc/http_downloader.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python_rpc/http_downloader.py b/python_rpc/http_downloader.py index 5c4a701a..a383a403 100644 --- a/python_rpc/http_downloader.py +++ b/python_rpc/http_downloader.py @@ -41,6 +41,7 @@ class HttpDownloader: ) except Exception as e: print(f"error running hydra-httpdl: {e}") + return None def get_download_status(self):