Finished prism install and changed modpack structure

This commit is contained in:
Samuel Walker 2024-06-22 20:30:23 -06:00
parent ae5d60340d
commit affd3f0a47
6 changed files with 105 additions and 8 deletions

View File

@ -15,6 +15,11 @@ tauri = { version = "1", features = ["shell-open"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
suppaftp = { version = "6.0.1", features = ["native-tls"] }
tar = "0.4.41"
flate2 = "1.0.30"
zip-extract = "0.1.3"
dirs = "5.0.1"
gethostname = "0.4.3"
[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!

View File

@ -0,0 +1,47 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::collections::{HashMap, HashSet};
use std::{io::Cursor, path::PathBuf};
use std::io::Seek;
use serde_json::{Map, Result, Value};
mod ftp;
mod java;
mod prism;
mod system_dirs;
mod util;
mod modpack;
struct ModpackEntry{
name: String,
id: u8
}
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
#[tauri::command]
fn get_modpacks() -> Vec<ModpackEntry> {
let mut buf = Cursor::new(vec![]);
ftp::ftp_retr(PathBuf::new().join("modpacks.json"), &mut buf, |_| return);
buf.rewind();
let v: Value = serde_json::from_reader(buf).unwrap();
println!("{}", v[0]["name"]);
let mut packs: Vec<ModpackEntry> = Vec::new();
for pack in v.as_array().unwrap() {
packs.push(ModpackEntry{name: pack["name"].as_str().unwrap().to_string(), id: pack["id"].into()});
}
return packs;
}
fn main() {
prism::install_prism();
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, get_modpacks])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -1,11 +1,25 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::collections::{HashMap, HashSet};
use std::{io::Cursor, path::PathBuf};
use std::io::Seek;
use serde_json::{Result, Value};
use serde_json::{Map, Result, Value};
use serde::Serialize;
use serde::Deserialize;
mod ftp;
mod java;
mod prism;
mod system_dirs;
mod util;
mod modpack;
#[derive(Serialize, Deserialize)]
struct ModpackEntry{
name: String,
id: String
}
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
@ -14,20 +28,21 @@ fn greet(name: &str) -> String {
}
#[tauri::command]
fn get_modpacks() -> Vec<String> {
fn get_modpacks() -> Vec<ModpackEntry> {
let mut buf = Cursor::new(vec![]);
ftp::ftp_retr(PathBuf::new().join("modpacks.json"), &mut buf, |_| return);
buf.rewind();
let v: Value = serde_json::from_reader(buf).unwrap();
println!("{}", v[0]["name"]);
let mut packs: Vec<String> = Vec::new();
let mut packs: Vec<ModpackEntry> = Vec::new();
for pack in v.as_array().unwrap() {
packs.push(pack["name"].as_str().unwrap().to_string());
packs.push(ModpackEntry{name: pack["name"].as_str().unwrap().to_string(), id: pack["id"].as_str().unwrap().to_string()});
}
return packs;
}
fn main() {
prism::install_prism();
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, get_modpacks])
.run(tauri::generate_context!())

View File

@ -0,0 +1,2 @@

View File

@ -1,6 +1,7 @@
use std::{env, io::{Cursor, Seek}, path::PathBuf};
use std::{env, fs::File, io::{BufRead, Cursor, Seek, Write}, path::PathBuf, str::FromStr};
use flate2::read::GzDecoder;
use tar::Archive;
use tauri::api::file;
use crate::{ftp, java, system_dirs::get_local_data_directory};
@ -37,8 +38,23 @@ pub fn install_prism() -> Result<(), Box<dyn std::error::Error>>{
}
}
let buff = Cursor::new(vec![]);
ftp::ftp_retr(PathBuf, writer, callback)
let mut buff = Cursor::new(vec![]);
ftp::ftp_retr(PathBuf::new().join("prism").join("prismlauncher.cfg"), &mut buff, |_| return).unwrap();
buff.rewind();
let mut file = File::create(get_local_data_directory().join("prism").join("prismlauncher.cfg")).unwrap();
loop {
let mut buf = String::new();
let count = buff.read_line(&mut buf).unwrap();
if count == 0 {
break;
}
if buf.starts_with("JavaPath") {
buf = format!("JavaPath={}/java/java-21-{}\n", get_local_data_directory().to_str().unwrap().replace("\\", "/"), if env::consts::OS == "windows" { "win" } else { "lin" });
}else if buf.starts_with("LastHostname") {
buf = format!("LastHostname={}\n", gethostname::gethostname().to_str().unwrap());
}
file.write_all(buf.as_bytes());
}
Ok(())

View File

@ -2,7 +2,19 @@ use std::{env, path::{Path, PathBuf}};
use dirs::home_dir;
pub fn get_local_data_directory() -> PathBuf {
dirs::data_local_dir().unwrap().join("FCLauncher")
}
pub fn get_data_directory() -> PathBuf {
dirs::data_dir().unwrap().join("FCLauncher")
}
pub fn get_java_executable() -> String {
return format!("java{}", if env::consts::OS == "windows" { ".exe" } else { "" })
}
pub fn get_prism_executable() -> String {
return format!("{}", if env::consts::OS == "windows" { "prismlauncher.exe" } else { "PrismLauncher" })
}