Merge branch 'main' into patching

This commit is contained in:
SpikeHD
2022-07-16 16:38:54 -07:00
4 changed files with 60 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
use std::fs;
use file_diff::diff;
use std::{fs, io::{Read, Write}};
#[tauri::command]
pub fn rename(path: String, new_name: String) {
@@ -96,4 +97,48 @@ pub fn delete_file(path: String) -> bool {
};
false
}
pub fn read_file(path: String) -> String {
let mut file = match fs::File::open(path) {
Ok(file) => file,
Err(e) => {
println!("Failed to open file: {}", e);
return String::new();
}
};
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();
contents
}
#[tauri::command]
pub fn write_file(path: String, contents: String) {
// Create file if it exists, otherwise just open and rewrite
let mut file = match fs::File::open(&path) {
Ok(file) => file,
Err(e) => {
println!("Failed to open file: {}", e);
// attempt to create file. otherwise return
match fs::File::create(&path) {
Ok(file) => file,
Err(e) => {
println!("Failed to create file: {}", e);
return;
}
}
}
};
// Write contents to file
match file.write_all(contents.as_bytes()) {
Ok(_) => (),
Err(e) => {
println!("Failed to write to file: {}", e);
return;
}
}
}

View File

@@ -49,6 +49,8 @@ fn main() {
file_helpers::copy_file_with_new_name,
file_helpers::delete_file,
file_helpers::are_files_identical,
file_helpers::read_file,
file_helpers::write_file,
downloader::download_file,
downloader::stop_download,
lang::get_lang,