add: License and tweaked path building.
parent
d0241a48b5
commit
514672af63
|
|
@ -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.
|
||||
|
|
@ -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<Vec<(String, u64)>> {
|
||||
let entries: Vec<PathBuf> = WalkDir::new(DIR)
|
||||
let base = base_dir(&app);
|
||||
let entries: Vec<PathBuf> = 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<Vec<(String, u64)>> {
|
|||
|
||||
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() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue