Form for extractor html
This commit is contained in:
@@ -17,6 +17,7 @@ serde_json = "1"
|
||||
toml = "0.5"
|
||||
tokio = "1.38.0"
|
||||
serde-wasm-bindgen = "0.4"
|
||||
walkdir = "2"
|
||||
|
||||
[features]
|
||||
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
|
||||
|
||||
68
src-tauri/src/extractor.rs
Normal file
68
src-tauri/src/extractor.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::process::ExitStatus;
|
||||
use serde::de::value::Error;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use walkdir::WalkDir;
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::config_settings;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Champion {
|
||||
name: String,
|
||||
location: String,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn load_champions() -> Vec<Champion> {
|
||||
|
||||
let config = config_settings::load_config().await;
|
||||
|
||||
let champions: Vec<Champion> = WalkDir::new(&config.wad_dir)
|
||||
.into_iter()
|
||||
.filter_map(|entry| entry.ok())
|
||||
.filter_map(|entry| {
|
||||
let path = entry.path();
|
||||
let file_name = path.file_name().and_then(|name| name.to_str())?;
|
||||
let extension = path.extension().and_then(|ext| ext.to_str())?;
|
||||
if extension == "client" &&
|
||||
file_name.ends_with(".wad.client") &&
|
||||
file_name.split('.').count() == 3
|
||||
{
|
||||
let name = file_name.split('.').next().unwrap_or("").to_string();
|
||||
let location = path.to_str().unwrap_or("").to_string();
|
||||
Some(Champion {
|
||||
name,
|
||||
location,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
champions
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn extract_wad(champion: Champion) {
|
||||
let config = config_settings::load_config().await;
|
||||
|
||||
|
||||
let current_dir = env::current_dir().expect("Failed to get current directory");
|
||||
let extraction_path = current_dir.join("champions").join(champion.name);
|
||||
let bat_path = PathBuf::from(config.cslol_dir).join("cslol-tools\\wad-extract.exe");
|
||||
|
||||
if !extraction_path.exists() {
|
||||
fs::create_dir_all(&extraction_path).expect("Failed to create extraction folder");
|
||||
}
|
||||
|
||||
let _status = Command::new(&bat_path)
|
||||
.arg(&champion.location)
|
||||
.arg(&extraction_path)
|
||||
.status().unwrap();
|
||||
}
|
||||
@@ -2,7 +2,10 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
mod config_settings;
|
||||
mod extractor;
|
||||
|
||||
use config_settings::*;
|
||||
use extractor::*;
|
||||
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
@@ -11,7 +14,7 @@ fn greet(name: &str) -> String {
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![greet, init_config, load_config, write_config])
|
||||
.invoke_handler(tauri::generate_handler![greet, init_config, load_config, write_config, extract_wad, load_champions])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user