diff --git a/src-tauri/src/utils/hosts.rs b/src-tauri/src/utils/hosts.rs index d45a014..494c460 100644 --- a/src-tauri/src/utils/hosts.rs +++ b/src-tauri/src/utils/hosts.rs @@ -1,16 +1,23 @@ -use std::sync::{Arc, Mutex}; +use std::env; -use anyhow::{bail, Result}; +use anyhow::{bail, Context, Result}; +use tokio::fs; -const HOSTS_PATH: &str = "C:\\Windows\\System32\\drivers\\etc\\hosts"; -const HOSTS: [&str; 3] = ["mojang.com", "minecraft.net", "liquidbounce.net"]; +const HOSTS_PATH: &str = "Windows\\System32\\drivers\\etc\\hosts"; +const HOSTS: [&str; 4] = ["mojang.com", "minecraft.net", "liquidbounce.net", "ccbluex.net"]; /// We have noticed many user have modified the hosts file to block the Minecraft authentication server. /// This is likely by using a third-party program. Because LiquidLauncher requires access to the authentication server, we have to modify the hosts file to allow access. /// we need to check the hosts file and alert the user if it has been modified. pub async fn check_hosts_file() -> Result<()> { + // Get location of Windows hosts file dynamically + // "SystemDrive" env, if not assigned default to C: + let system_drive = env::var("SystemDrive").unwrap_or("C:".to_string()); + let hosts_path = format!("{}\\{}", system_drive, HOSTS_PATH); + // Check if the hosts file has been modified - let hosts_file = tokio::fs::read_to_string(HOSTS_PATH).await?; + let hosts_file = fs::read_to_string(&hosts_path).await + .context(format!("Failed to read hosts file at {}", hosts_path))?; let flagged_entries = hosts_file.lines() .filter(|line| { @@ -41,7 +48,7 @@ pub async fn check_hosts_file() -> Result<()> { The file is located at:\n\ {}", flagged_entries.join("\n"), - HOSTS_PATH + hosts_path ); }