From 514672af63491cc9c32a537563e826a5ba6b8aa2 Mon Sep 17 00:00:00 2001 From: WildEgo Date: Sun, 4 Jan 2026 14:11:04 +0000 Subject: [PATCH] add: License and tweaked path building. --- license | 11 +++++++++++ src-tauri/src/lib.rs | 30 ++++++++++++++---------------- 2 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 license diff --git a/license b/license new file mode 100644 index 0000000..c094f87 --- /dev/null +++ b/license @@ -0,0 +1,11 @@ +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + +Version 2, December 2004 + +Copyright (C) 2004 Sam Hocevar [sam@hocevar.net] + +Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. + +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. You just DO WHAT THE FUCK YOU WANT TO. \ No newline at end of file diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1dcbc6c..e68aa6b 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use std::{fs, fs::File, sync::Mutex}; +use std::{fs, fs::File, sync::Mutex, env}; use std::path::PathBuf; use std::collections::HashMap; use tokio::io::AsyncWriteExt; @@ -10,20 +10,10 @@ use rayon::prelude::*; use memmap2::Mmap; use walkdir::WalkDir; -pub const DIR: &str = if cfg!(debug_assertions) { - if cfg!(target_os = "windows") { - "C:\\Users\\Ego\\Desktop\\test\\" - } else { - "/home/ego/Documents/metin2/client/dist/" - } -} else { - "./" -}; - // TODO HANDLE ERRORS PROPERLY // TODO SUPPORT REGEX // TODO SUPPORT ALL FILE MOVES -pub const SERVER: &str = "http://192.168.31.60:8080"; +pub const SERVER: &str = "http://127.0.0.1"; #[derive(Debug, Serialize, Deserialize)] pub struct Config { @@ -304,7 +294,8 @@ fn close(app: AppHandle) { } pub fn pack_hash(app: AppHandle) -> std::io::Result> { - let entries: Vec = WalkDir::new(DIR) + let base = base_dir(&app); + let entries: Vec = WalkDir::new(&base) .into_iter() .filter_map(|e| e.ok()) .filter(|e| e.path().is_file()) @@ -315,7 +306,7 @@ pub fn pack_hash(app: AppHandle) -> std::io::Result> { entries.par_iter().try_for_each(|path| -> std::io::Result<()> { // Relative path to DIR - let rel_path = path.strip_prefix(DIR) + let rel_path = path.strip_prefix(&base) .unwrap() .to_string_lossy() .replace("\\", "/"); // normalize @@ -497,6 +488,12 @@ fn open_config(app: AppHandle) -> Result<(), String> { Ok(()) } +fn base_dir(_app: &AppHandle) -> PathBuf { + std::env::current_exe() + .expect("failed to get current executable") + .to_path_buf() +} + pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_opener::init()) @@ -511,7 +508,8 @@ pub fn run() { .setup(|app| { let app_handle = app.handle().clone(); - let _ = fs::create_dir_all(DIR); + let base = base_dir(&app_handle); + let _ = fs::create_dir_all(&base); tauri::async_runtime::spawn(async move { let _ = app_handle.emit("status", Status::Fetching).unwrap(); @@ -566,7 +564,7 @@ pub fn run() { for (file, _hash) in &updatable { let url = format!("{}/{}", SERVER, file); - let mut dest_path = PathBuf::from(DIR); + let mut dest_path = base.clone(); dest_path.push(file); if let Some(parent) = dest_path.parent() {