Added Offline Functionality
This commit is contained in:
parent
8b88dffd84
commit
d5ce6e4fc8
@ -18,9 +18,7 @@ pub fn test_cred(username: &str, password: &str) -> bool{
|
|||||||
|
|
||||||
|
|
||||||
fn ftp_connection(username: &str, password: &str) -> Result<NativeTlsFtpStream, FtpError>{
|
fn ftp_connection(username: &str, password: &str) -> Result<NativeTlsFtpStream, FtpError>{
|
||||||
let ftp_stream = NativeTlsFtpStream::connect("gitea.piwalker.net:21").unwrap_or_else(|err|
|
let ftp_stream = NativeTlsFtpStream::connect("gitea.piwalker.net:21")?;
|
||||||
panic!("{}", err)
|
|
||||||
);
|
|
||||||
let cert = include_bytes!("../res/vsftpd.crt");
|
let cert = include_bytes!("../res/vsftpd.crt");
|
||||||
let cert = Certificate::from_pem(cert).unwrap();
|
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();
|
let mut ftp_stream = ftp_stream.into_secure(NativeTlsConnector::from(TlsConnector::builder().add_root_certificate(cert).build().unwrap()), "gitea.piwalker.net").unwrap();
|
||||||
@ -32,7 +30,7 @@ fn ftp_connection(username: &str, password: &str) -> Result<NativeTlsFtpStream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn ftp_retr(window: Option<tauri::Window>, file: PathBuf , mut writer: impl Write, mut callback: impl FnMut(Option<tauri::Window>, usize, usize)) -> Result<bool, FtpError> {
|
pub fn ftp_retr(window: Option<tauri::Window>, file: PathBuf , mut writer: impl Write, mut callback: impl FnMut(Option<tauri::Window>, usize, usize)) -> Result<bool, FtpError> {
|
||||||
let mut ftp_stream = ftp_connection_anonymous().unwrap();
|
let mut ftp_stream = ftp_connection_anonymous()?;
|
||||||
let file = file.to_str().unwrap().replace("\\", "/");
|
let file = file.to_str().unwrap().replace("\\", "/");
|
||||||
let size = ftp_stream.size(&file)?;
|
let size = ftp_stream.size(&file)?;
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
|
@ -7,10 +7,12 @@ use std::fs::File;
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::{io::Cursor, path::PathBuf};
|
use std::{io::Cursor, path::PathBuf};
|
||||||
use std::io::{Read, Seek, Write};
|
use std::io::{Read, Seek, Write};
|
||||||
|
use serde::de::value::Error;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -47,6 +49,10 @@ fn check_modpack_needs_update(id: String) -> bool{
|
|||||||
}
|
}
|
||||||
|
|
||||||
let versions = get_versions(id);
|
let versions = get_versions(id);
|
||||||
|
if !versions.is_ok() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let versions = versions.unwrap();
|
||||||
let latest = versions[versions.len()-1].version.clone();
|
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 file = File::open(get_local_data_directory().join("prism").join("instances").join(instance_name).join(".minecraft").join("version.txt")).unwrap();
|
||||||
@ -72,7 +78,7 @@ pub async fn launch_modpack(window: tauri::Window, id: String){
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn install_modpack(window: tauri::Window, id: String){
|
fn install_modpack(window: tauri::Window, id: String){
|
||||||
let versions = get_versions(id.clone());
|
let versions = get_versions(id.clone()).unwrap();
|
||||||
let path = env::temp_dir().join(format!("{}.mrpack", get_modpack_name(id.clone())));
|
let path = env::temp_dir().join(format!("{}.mrpack", get_modpack_name(id.clone())));
|
||||||
let mut file = File::create(path.clone()).unwrap();
|
let mut file = File::create(path.clone()).unwrap();
|
||||||
let ftp_path = PathBuf::new().join(id.clone()).join(versions[versions.len()-1].file.clone().as_str());
|
let ftp_path = PathBuf::new().join(id.clone()).join(versions[versions.len()-1].file.clone().as_str());
|
||||||
@ -135,7 +141,24 @@ pub fn get_modpacks() -> Vec<ModpackEntry> {
|
|||||||
let mut buf = Cursor::new(vec![]);
|
let mut buf = Cursor::new(vec![]);
|
||||||
ftp::ftp_retr(None, PathBuf::new().join("modpacks.json"), &mut buf, |_, _, _| return);
|
ftp::ftp_retr(None, PathBuf::new().join("modpacks.json"), &mut buf, |_, _, _| return);
|
||||||
buf.rewind();
|
buf.rewind();
|
||||||
let v: Value = serde_json::from_reader(buf).unwrap();
|
let res = serde_json::from_reader(buf);
|
||||||
|
if !res.is_ok() {
|
||||||
|
let paths = fs::read_dir(get_local_data_directory().join("prism").join("instances")).unwrap();
|
||||||
|
for path in paths {
|
||||||
|
let path = path.unwrap();
|
||||||
|
if fs::metadata(path.path()).unwrap().is_file() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let name = path.file_name().into_string().unwrap();
|
||||||
|
if name.starts_with(".") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modpacks.push(ModpackEntry{name: name.clone(), id: name})
|
||||||
|
}
|
||||||
|
return modpacks.clone()
|
||||||
|
}
|
||||||
|
let v: Value = res.unwrap();
|
||||||
println!("{}", v[0]["name"]);
|
println!("{}", v[0]["name"]);
|
||||||
for pack in v.as_array().unwrap() {
|
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()});
|
modpacks.push(ModpackEntry{name: pack["name"].as_str().unwrap().to_string(), id: pack["id"].as_str().unwrap().to_string()});
|
||||||
@ -145,16 +168,16 @@ pub fn get_modpacks() -> Vec<ModpackEntry> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_versions(id: String) -> Vec<VersionEntry> {
|
fn get_versions(id: String) -> Result<Vec<VersionEntry>,Box<dyn std::error::Error>> {
|
||||||
let mut versions: Vec<VersionEntry> = Vec::new();
|
let mut versions: Vec<VersionEntry> = Vec::new();
|
||||||
let mut buf = Cursor::new(vec![]);
|
let mut buf = Cursor::new(vec![]);
|
||||||
ftp::ftp_retr(None, PathBuf::new().join(id).join("versions.json"), &mut buf, |_, _, _| return);
|
ftp::ftp_retr(None, PathBuf::new().join(id).join("versions.json"), &mut buf, |_, _, _| return);
|
||||||
buf.rewind();
|
buf.rewind();
|
||||||
let v: Value = serde_json::from_reader(buf).unwrap();
|
let v: Value = serde_json::from_reader(buf)?;
|
||||||
for version in v.as_array().unwrap() {
|
for version in v.as_array().unwrap() {
|
||||||
versions.push(VersionEntry{version: version["Version"].as_str().unwrap().to_string(), file: version["File"].as_str().unwrap().to_string(), date: version["Date"].as_str().unwrap().to_string()});
|
versions.push(VersionEntry{version: version["Version"].as_str().unwrap().to_string(), file: version["File"].as_str().unwrap().to_string(), date: version["Date"].as_str().unwrap().to_string()});
|
||||||
}
|
}
|
||||||
return versions.clone();
|
return Ok(versions.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_java_version(mc_version: &str) -> u8{
|
fn get_java_version(mc_version: &str) -> u8{
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "FCLauncher",
|
"productName": "FCLauncher",
|
||||||
"version": "0.0.0"
|
"version": "1.0.1"
|
||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
|
Loading…
Reference in New Issue
Block a user