fixed error
This commit is contained in:
parent
9daf0d1fdb
commit
4ffaf29645
@ -27,24 +27,11 @@ fn greet(name: &str) -> String {
|
|||||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
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"].as_str().unwrap().to_string()});
|
|
||||||
}
|
|
||||||
return packs;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
prism::install_prism();
|
prism::install_prism();
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.invoke_handler(tauri::generate_handler![greet, get_modpacks])
|
.invoke_handler(tauri::generate_handler![greet, modpack::get_modpacks])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,100 @@
|
|||||||
|
|
||||||
|
use crate::ftp;
|
||||||
|
use crate::system_dirs::get_local_data_directory;
|
||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::{io::Cursor, path::PathBuf};
|
||||||
|
use std::io::{Read, Seek};
|
||||||
|
use serde_json::Value;
|
||||||
|
use serde::Serialize;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct ModpackEntry{
|
||||||
|
name: String,
|
||||||
|
id: String
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct VersionEntry{
|
||||||
|
version: String,
|
||||||
|
file: String,
|
||||||
|
date: String
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_modpack_name(id: String) -> String {
|
||||||
|
let modpacks = get_modpacks();
|
||||||
|
let mut instance_name = String::new();
|
||||||
|
for pack in modpacks {
|
||||||
|
if pack.id == id {
|
||||||
|
instance_name = pack.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn check_modpack_needs_update(id: String) -> bool{
|
||||||
|
let mut instance_name = get_modpack_name(id.clone());
|
||||||
|
if !get_local_data_directory().join("prism").join("instances").join(&mut instance_name).exists() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let versions = get_versions(id);
|
||||||
|
let latest = versions[versions.len()-1].version.clone();
|
||||||
|
|
||||||
|
let mut file = File::open(get_local_data_directory().join("prism").join("instances").join(instance_name).join(".minecraft").join("version.txt")).unwrap();
|
||||||
|
let mut current = String::new();
|
||||||
|
file.read_to_string(&mut current);
|
||||||
|
|
||||||
|
if latest != current {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn launch_modpack(id: String){
|
||||||
|
if check_modpack_needs_update(id.clone()) {
|
||||||
|
install_modpack(id.clone());
|
||||||
|
}
|
||||||
|
// Launch
|
||||||
|
}
|
||||||
|
|
||||||
|
fn install_modpack(id: String){
|
||||||
|
let mut file = File::create(env::temp_dir().join(format!("{}.mrpack", get_modpack_name(id)))).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn get_modpacks() -> Vec<ModpackEntry> {
|
||||||
|
unsafe{
|
||||||
|
static mut modpacks: Vec<ModpackEntry> = Vec::new();
|
||||||
|
if modpacks.is_empty() {
|
||||||
|
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"]);
|
||||||
|
for pack in v.as_array().unwrap() {
|
||||||
|
modpacks.push(ModpackEntry{name: pack["name"].as_str().unwrap().to_string(), id: pack["id"].as_str().unwrap().to_string()});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return modpacks.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_versions(id: String) -> Vec<VersionEntry> {
|
||||||
|
let mut versions: Vec<VersionEntry> = Vec::new();
|
||||||
|
let mut buf = Cursor::new(vec![]);
|
||||||
|
ftp::ftp_retr(PathBuf::new().join(id).join("versions.json"), &mut buf, |_| return);
|
||||||
|
buf.rewind();
|
||||||
|
let v: Value = serde_json::from_reader(buf).unwrap();
|
||||||
|
for version in v.as_array().unwrap() {
|
||||||
|
versions.push(VersionEntry{version: version["Version"].to_string(), file: version["File"].to_string(), date: version["Date"].to_string()});
|
||||||
|
}
|
||||||
|
return versions.clone();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user