From 3ccedf668f63402834216aa0f2baa2bca6787202 Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Fri, 27 Sep 2024 15:17:23 -0600 Subject: [PATCH] removed old launcher --- launcher/Cargo.toml | 12 -------- launcher/res/vsftpd.crt | 24 ---------------- launcher/src/ftp.rs | 56 ------------------------------------- launcher/src/java.rs | 54 ----------------------------------- launcher/src/main.rs | 32 --------------------- launcher/src/prism.rs | 45 ----------------------------- launcher/src/system_dirs.rs | 8 ------ launcher/src/util.rs | 6 ---- 8 files changed, 237 deletions(-) delete mode 100644 launcher/Cargo.toml delete mode 100644 launcher/res/vsftpd.crt delete mode 100644 launcher/src/ftp.rs delete mode 100644 launcher/src/java.rs delete mode 100644 launcher/src/main.rs delete mode 100644 launcher/src/prism.rs delete mode 100644 launcher/src/system_dirs.rs delete mode 100644 launcher/src/util.rs diff --git a/launcher/Cargo.toml b/launcher/Cargo.toml deleted file mode 100644 index dfcd83b..0000000 --- a/launcher/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "launcher" -version = "0.1.0" -edition = "2021" - -[dependencies] -dirs = "5.0.1" -flate2 = "1.0.30" -serde_json = "1.0.117" -suppaftp = { version = "6.0.1", features = ["native-tls"] } -tar = "0.4.41" -zip-extract = "0.1.3" diff --git a/launcher/res/vsftpd.crt b/launcher/res/vsftpd.crt deleted file mode 100644 index 0116f2d..0000000 --- a/launcher/res/vsftpd.crt +++ /dev/null @@ -1,24 +0,0 @@ ------BEGIN CERTIFICATE----- -MIID8TCCAtmgAwIBAgIUeFYZmMrAiIFZ9/QFwUS636XZrJMwDQYJKoZIhvcNAQEL -BQAwgYcxCzAJBgNVBAYTAlVTMRAwDgYDVQQIDAdXeW9taW5nMREwDwYDVQQHDAhD -aGV5ZW5uZTERMA8GA1UECgwIUGVyc29uYWwxGzAZBgNVBAMMEmdpdGVhLnBpd2Fs -a2VyLm5ldDEjMCEGCSqGSIb3DQEJARYUc3dhbGtlckBwaXdhbGtlci5uZXQwHh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ujRoTSnndZsRVqfiNZaJbpvZoD/kY0aBXHo -SIh5Ff4= ------END CERTIFICATE----- diff --git a/launcher/src/ftp.rs b/launcher/src/ftp.rs deleted file mode 100644 index ea1d263..0000000 --- a/launcher/src/ftp.rs +++ /dev/null @@ -1,56 +0,0 @@ -use std::io::Write; -use std::path::PathBuf; - -use suppaftp::FtpError; -use suppaftp::NativeTlsFtpStream; -use suppaftp::NativeTlsConnector; -use suppaftp::native_tls::Certificate; -use suppaftp::native_tls::TlsConnector; - - -fn ftp_connection_anonymous() -> Result{ - ftp_connection("anonymous", "anonymous@") -} - - -fn ftp_connection(username: &str, password: &str) -> Result{ - let ftp_stream = NativeTlsFtpStream::connect("gitea.piwalker.net:21").unwrap_or_else(|err| - panic!("{}", err) - ); - let cert = include_bytes!("../res/vsftpd.crt"); - let cert = Certificate::from_pem(cert).unwrap(); - let mut ftp_stream = ftp_stream.into_secure(NativeTlsConnector::from(TlsConnector::builder().add_root_certificate(cert).build().unwrap()), "gitea.piwalker.net").unwrap(); - ftp_stream.login("anonymous", "anonymous@").map(|_| Ok(ftp_stream)).unwrap() -} - - -pub fn ftp_retr(file: PathBuf , mut writer: impl Write, mut callback: impl FnMut(usize)) -> Result { - let mut ftp_stream = ftp_connection_anonymous().unwrap(); - let file = file.to_str().unwrap().replace("\\", "/"); - let size = ftp_stream.size(&file)?; - let mut total = 0; - ftp_stream.retr(file.as_str(), |stream| { - let mut tx_bytes = [0u8; 1500]; - loop { - let bytes_read = stream.read(&mut tx_bytes).unwrap(); - writer.write_all(&mut tx_bytes.split_at(bytes_read).0).unwrap(); - total += bytes_read; - if total == size || bytes_read == 0 { - break; - }else{ - callback(bytes_read); - } - } - Ok(true) - })?; - Ok(true) - -} - -pub fn ftp_get_size(file: PathBuf) -> Result { - let mut stream = ftp_connection_anonymous()?; - stream.size(file.to_str().unwrap().replace("\\", "/")) -} - - - diff --git a/launcher/src/java.rs b/launcher/src/java.rs deleted file mode 100644 index 7c9be22..0000000 --- a/launcher/src/java.rs +++ /dev/null @@ -1,54 +0,0 @@ -use std::env; -use std::io::{Cursor, Seek, Read}; -use std::path::{Components, Path, PathBuf}; -use flate2::read::GzDecoder; -use tar::Archive; - - -use crate::system_dirs::get_local_data_directory; -use crate::ftp::{self, ftp_get_size}; -use crate::util; - -fn check_java(version: u8) -> bool { - let dir = get_local_data_directory().join("java").join(format!("java-{}-{}", version, if env::consts::OS == "windows" { "win" } else {"lin"})); - dir.exists() -} - -pub fn install_java(version: u8) { - if check_java(version) { - return; - } - let ftp_dir = PathBuf::new().join("java").join(format!("java-{}-{}", version, if env::consts::OS == "windows" { "win.zip" } else {"lin.tar.gz"})); - let mut buff = Cursor::new(vec![]); - let mut total: usize = 0; - let size = ftp_get_size(ftp_dir.clone()).unwrap(); - ftp::ftp_retr(ftp_dir, &mut buff, |data| util::download_callback(data, &mut total, size)).unwrap(); - - std::fs::create_dir_all(get_local_data_directory().join("java").join(format!("java-{}-{}", version, if env::consts::OS == "windows" { "win" } else {"lin"}))).unwrap(); - buff.rewind().unwrap(); - if env::consts::OS != "windows" { - let tar = GzDecoder::new(buff); - let mut archive = Archive::new(tar); - if !unpack_archive(archive, get_local_data_directory().join("java").join(format!("java-{}-lin", version))).is_ok() { - std::fs::remove_dir_all(get_local_data_directory().join("java").join(format!("java-{}-lin", version))).unwrap(); - } - } else { - if !zip_extract::extract(buff, get_local_data_directory().join("java").join(format!("java-{}-win", version)).as_path(), true).is_ok() { - std::fs::remove_dir_all(get_local_data_directory().join("java").join(format!("java-{}-win", version))).unwrap(); - } - } - -} - -fn unpack_archive(mut archive: Archive, dst: PathBuf) -> Result<(), Box> { - for file in archive.entries()? { - let path = PathBuf::new().join(dst.clone()); - let mut file = file?; - let file_path = file.path()?; - let mut file_path = file_path.components(); - let _ = file_path.next(); - let file_path = file_path.as_path(); - file.unpack(path.join(file_path))?; - } - Ok(()) -} diff --git a/launcher/src/main.rs b/launcher/src/main.rs deleted file mode 100644 index 2734a18..0000000 --- a/launcher/src/main.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::fs::File; -use std::io::{Cursor, Read, Seek, Write}; -use std::env::temp_dir; -use std::path::{Path, PathBuf}; -use serde_json::{Result, Value}; -use std::process::Command; -use std::process::Child; - -mod ftp; -mod prism; -mod system_dirs; -mod java; -mod util; - - -fn main() { - prism::install_prism().unwrap(); - //let mut data = Cursor::new(vec![]); - //ftp::ftpRetr(PathBuf::new().join("fcs7").join("versions.json"), &mut data, |_| return).unwrap(); - //data.seek(std::io::SeekFrom::Start(0)).unwrap(); - //let v: Value = serde_json::from_reader(data).unwrap(); - //println!("fcs7/{}",v[v.as_array().unwrap().len()-1]["File"].as_str().unwrap()); - //println!("{}", temp_dir().join("pack.mrpack").display()); - //let mut file = File::create(temp_dir().join("pack.mrpack")).unwrap(); - //ftp::ftpRetr(PathBuf::new().join("fcs7").join(v[v.as_array().unwrap().len()-1]["File"].as_str().unwrap()),file, |data| println!("Transferred {} Bytes", data)).unwrap(); - //let output = Command::new("prismlauncher").arg("-I").arg(temp_dir().join("pack.mrpack")).spawn(); - - - -} - -pub fn test(){} diff --git a/launcher/src/prism.rs b/launcher/src/prism.rs deleted file mode 100644 index 3772ca3..0000000 --- a/launcher/src/prism.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::{env, io::{Cursor, Seek}, path::PathBuf}; -use flate2::read::GzDecoder; -use tar::Archive; - -use crate::{ftp, java, system_dirs::get_local_data_directory}; - - -pub fn check_prism() -> bool { - let path = get_local_data_directory().join("prism"); - path.exists() -} - -pub fn install_prism() -> Result<(), Box>{ - if check_prism() { - return Ok(()); - } - java::install_java(21); - let path = PathBuf::new().join("prism").join(format!("prism-{}",if env::consts::OS == "windows" {"win.zip"} else {"lin.tar.gz"})); - let size = ftp::ftp_get_size(path.clone())?; - let mut buff = Cursor::new(vec![]); - let mut total = 0; - ftp::ftp_retr(path, &mut buff, |data| { - total += data; - println!("Downloading Prism: {}MB / {}MB", total/(1024*1024), size/(1024*1024)); - }).unwrap(); - std::fs::create_dir_all(get_local_data_directory().join("prism"))?; - buff.rewind()?; - if env::consts::OS != "windows" { - let tar = GzDecoder::new(buff); - let mut archive = Archive::new(tar); - if !archive.unpack(get_local_data_directory().join("prism")).is_ok() { - std::fs::remove_dir_all(get_local_data_directory().join("prism")); - } - } else { - if !zip_extract::extract(buff, get_local_data_directory().join("prism").as_path(), true).is_ok() { - std::fs::remove_dir_all(get_local_data_directory().join("prism")); - } - } - - let buff = Cursor::new(vec![]); - ftp::ftp_retr(PathBuf, writer, callback) - - - Ok(()) -} diff --git a/launcher/src/system_dirs.rs b/launcher/src/system_dirs.rs deleted file mode 100644 index ba67006..0000000 --- a/launcher/src/system_dirs.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::{env, path::{Path, PathBuf}}; -use dirs::home_dir; - - - -pub fn get_local_data_directory() -> PathBuf { - dirs::data_local_dir().unwrap().join("FCLauncher") -} diff --git a/launcher/src/util.rs b/launcher/src/util.rs deleted file mode 100644 index 3195d68..0000000 --- a/launcher/src/util.rs +++ /dev/null @@ -1,6 +0,0 @@ - -pub fn download_callback(count: usize, total: &mut usize, size: usize){ - *total += count; - println!("Downloading {}MB / {}MB", *total/(1024*1024), size/(1024*1024)); -} -