Stop popping the directory when we need it later

This commit is contained in:
Benj
2022-08-31 18:11:57 +08:00
parent a7188828fa
commit ff8f35c52a
2 changed files with 13 additions and 4 deletions

View File

@@ -63,7 +63,7 @@ pub fn copy_file(path: String, new_path: String) -> bool {
let path_buf = std::path::PathBuf::from(&path);
// 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();
}
@@ -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);
// 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) {
Ok(_) => {}
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
match std::fs::copy(&path_buf, format!("{}/{}", new_path, new_name)) {
match std::fs::copy(&path_buf, &new_path_buf) {
Ok(_) => true,
Err(e) => {
println!("Failed to copy file: {}", e);

View File

@@ -1,5 +1,5 @@
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.
extern "C" {
@@ -10,6 +10,12 @@ extern "C" {
#[tauri::command]
pub fn patch_metadata(metadata_folder: &str) -> bool {
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);
let decrypted = decrypt_metadata(metadata_file);
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> {
let mut data = old_data.to_vec();
let success = unsafe { encrypt_global_metadata(data.as_mut_ptr(), data.len()) } == 0;
if success {
println!("Successfully encrypted global-metadata");