mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-15 16:44:43 +01:00
Stop popping the directory when we need it later
This commit is contained in:
@@ -63,7 +63,7 @@ pub fn copy_file(path: String, new_path: String) -> bool {
|
|||||||
let path_buf = std::path::PathBuf::from(&path);
|
let path_buf = std::path::PathBuf::from(&path);
|
||||||
|
|
||||||
// If the new path doesn't exist, create it.
|
// If the new path doesn't exist, create it.
|
||||||
if !dir_exists(new_path_buf.pop().to_string().as_str()) {
|
if !dir_exists(std::path::PathBuf::from(&new_path).pop().to_string().as_str()) {
|
||||||
std::fs::create_dir_all(&new_path).unwrap();
|
std::fs::create_dir_all(&new_path).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ pub fn copy_file_with_new_name(path: String, new_path: String, new_name: String)
|
|||||||
let path_buf = std::path::PathBuf::from(&path);
|
let path_buf = std::path::PathBuf::from(&path);
|
||||||
|
|
||||||
// If the new path doesn't exist, create it.
|
// If the new path doesn't exist, create it.
|
||||||
if !dir_exists(new_path_buf.pop().to_string().as_str()) {
|
if !dir_exists(std::path::PathBuf::from(&new_path).pop().to_string().as_str()) {
|
||||||
match std::fs::create_dir_all(&new_path) {
|
match std::fs::create_dir_all(&new_path) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -95,8 +95,10 @@ pub fn copy_file_with_new_name(path: String, new_path: String, new_name: String)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new_path_buf.push(new_name);
|
||||||
|
|
||||||
// Copy old to new
|
// Copy old to new
|
||||||
match std::fs::copy(&path_buf, format!("{}/{}", new_path, new_name)) {
|
match std::fs::copy(&path_buf, &new_path_buf) {
|
||||||
Ok(_) => true,
|
Ok(_) => true,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed to copy file: {}", e);
|
println!("Failed to copy file: {}", e);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::{fs, fs::File, fs::OpenOptions, io::Read, io::Write};
|
use std::{fs, path::Path, fs::File, fs::OpenOptions, io::Read, io::Write};
|
||||||
|
|
||||||
// For these two functions, a non-zero return value indicates failure.
|
// For these two functions, a non-zero return value indicates failure.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -10,6 +10,12 @@ extern "C" {
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn patch_metadata(metadata_folder: &str) -> bool {
|
pub fn patch_metadata(metadata_folder: &str) -> bool {
|
||||||
let metadata_file = &(metadata_folder.to_owned() + "\\global-metadata-unpatched.dat");
|
let metadata_file = &(metadata_folder.to_owned() + "\\global-metadata-unpatched.dat");
|
||||||
|
// check if metadata_file exists
|
||||||
|
if !Path::new(metadata_file).exists() {
|
||||||
|
println!("Metadata file not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
println!("Patching metadata file: {}", metadata_file);
|
println!("Patching metadata file: {}", metadata_file);
|
||||||
let decrypted = decrypt_metadata(metadata_file);
|
let decrypted = decrypt_metadata(metadata_file);
|
||||||
if do_vecs_match(&decrypted, &Vec::new()) {
|
if do_vecs_match(&decrypted, &Vec::new()) {
|
||||||
@@ -128,6 +134,7 @@ fn replace_rsa_key(old_data: &str, to_replace: &str, file_name: &str) -> String
|
|||||||
|
|
||||||
fn encrypt_metadata(old_data: &[u8]) -> Vec<u8> {
|
fn encrypt_metadata(old_data: &[u8]) -> Vec<u8> {
|
||||||
let mut data = old_data.to_vec();
|
let mut data = old_data.to_vec();
|
||||||
|
|
||||||
let success = unsafe { encrypt_global_metadata(data.as_mut_ptr(), data.len()) } == 0;
|
let success = unsafe { encrypt_global_metadata(data.as_mut_ptr(), data.len()) } == 0;
|
||||||
if success {
|
if success {
|
||||||
println!("Successfully encrypted global-metadata");
|
println!("Successfully encrypted global-metadata");
|
||||||
|
|||||||
Reference in New Issue
Block a user