mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-17 09:34:34 +01:00
Fix os error 123 while reading key files
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::fs::File;
|
use std::{fs, fs::File, fs::OpenOptions, io::Read, io::Write};
|
||||||
use std::fs::OpenOptions;
|
|
||||||
use std::io::Read;
|
|
||||||
use std::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" {
|
||||||
@@ -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 {
|
fn replace_rsa_key(old_data: &str, to_replace: &str, file_name: &str) -> String {
|
||||||
// Read dispatch key file
|
// Read dispatch key file
|
||||||
unsafe {
|
unsafe {
|
||||||
// Get key folder from exe path
|
// Get key path from current directory
|
||||||
let mut exe_path = std::env::current_exe().unwrap();
|
let key_file_path = std::env::current_dir().unwrap().join("keys").join(file_name);
|
||||||
exe_path.pop();
|
|
||||||
|
|
||||||
let key_folder = exe_path.to_str().unwrap().to_string();
|
let key_data = match fs::read(&key_file_path) {
|
||||||
let mut new_key_file = match File::open(format!("{}/keys/{}", key_folder, file_name)) {
|
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed to open keys/{}: {}", file_name, e);
|
println!("Failed to open {}: {}", key_file_path.to_str().unwrap(), e);
|
||||||
return String::new();
|
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());
|
let new_key = String::from_utf8_unchecked(key_data.to_vec());
|
||||||
|
|
||||||
// Replace old key with new key
|
// Replace old key with new key
|
||||||
|
|||||||
Reference in New Issue
Block a user