mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 16:14:48 +01:00
Fix os error 123 while reading key files
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
use regex::Regex;
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::{fs, fs::File, fs::OpenOptions, io::Read, io::Write};
|
||||
|
||||
// For these two functions, a non-zero return value indicates failure.
|
||||
extern "C" {
|
||||
@@ -111,20 +108,17 @@ fn replace_keys(data: &[u8]) -> Vec<u8> {
|
||||
fn replace_rsa_key(old_data: &str, to_replace: &str, file_name: &str) -> String {
|
||||
// Read dispatch key file
|
||||
unsafe {
|
||||
// Get key folder from exe path
|
||||
let mut exe_path = std::env::current_exe().unwrap();
|
||||
exe_path.pop();
|
||||
// Get key path from current directory
|
||||
let key_file_path = std::env::current_dir().unwrap().join("keys").join(file_name);
|
||||
|
||||
let key_folder = exe_path.to_str().unwrap().to_string();
|
||||
let mut new_key_file = match File::open(format!("{}/keys/{}", key_folder, file_name)) {
|
||||
let key_data = match fs::read(&key_file_path) {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
println!("Failed to open keys/{}: {}", file_name, e);
|
||||
println!("Failed to open {}: {}", key_file_path.to_str().unwrap(), e);
|
||||
return String::new();
|
||||
}
|
||||
};
|
||||
let mut key_data = Vec::new();
|
||||
new_key_file.read_to_end(&mut key_data).unwrap();
|
||||
|
||||
let new_key = String::from_utf8_unchecked(key_data.to_vec());
|
||||
|
||||
// Replace old key with new key
|
||||
|
||||
Reference in New Issue
Block a user