From 8faaba2849a45040b38b507b490ec47a9fe1ac45 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Sat, 16 Jul 2022 14:43:29 -0700 Subject: [PATCH 1/2] Update README.md --- README.md | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 54488d6..8e68e97 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,12 @@ -# NOTICE -Yes! The Cultivation repository is **open**. This does **not** mean it has released.\ -Cultivation will be releasing at some point after opening this repo. - -**This also means you will not be provided explicit support for Cultivation.**\ -Consider Cultivation to be the bleeding-edge version of GrassClipper. - -During this open-beta testing period, **helpful issues are appreciated**, while unhelpful ones will be closed. - -## Fair Warning -Cultivation is **VERY MUCH IN BETA**. -There are **no official releases of Cultivation**. You are **required** to build the application from **scratch** unless you want to deal with the alpha state of the current builds. -Please do **NOT install, download, or use pre-compiled versions of Cultivation found elsewhere**. Only use releases from this GitHub repository. +# Cient Patching Notice +For game versions 2.8 and above, Cultivation automatically makes a small patch to your game client when launching using Grasscutter, and restores it upon closing the game. In theory, you should still be totally safe, however it would be dishonest to not explicitly state that **modifying the game client could, theoretically, lead to a ban if you connect to official servers with it**. It is extremely unlikely AND there are no instances known of it happening, but the possibility exists. # Cultivation A game launcher designed to easily proxy traffic from anime game to private servers. +While the Cultivation repository is **open**. This does **not** mean it has released. +Please do **NOT install, download, or use pre-compiled versions of Cultivation found elsewhere**. Only use releases from this GitHub repository. + # Table Of Contents * [Download](#download) * [Developer Quick-start](#developer-quickstart) From ffc37cc2039b15c0731cd8a55097a18da6e4e2af Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Sat, 16 Jul 2022 16:36:05 -0700 Subject: [PATCH 2/2] read and write server config via backend --- src-tauri/src/file_helpers.rs | 47 ++++++++++++++++++++++++++++++++++- src-tauri/src/main.rs | 2 ++ src/utils/server.ts | 12 ++++++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/file_helpers.rs b/src-tauri/src/file_helpers.rs index c63cda4..e72570b 100644 --- a/src-tauri/src/file_helpers.rs +++ b/src-tauri/src/file_helpers.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, io::{Read, Write}}; #[tauri::command] pub fn rename(path: String, new_name: String) { @@ -53,3 +53,48 @@ pub fn copy_file(path: String, new_path: String) -> bool { } } } + +#[tauri::command] +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; + } + } +} \ No newline at end of file diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7fc09be..614756c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -45,6 +45,8 @@ fn main() { file_helpers::dir_is_empty, file_helpers::dir_delete, file_helpers::copy_file, + file_helpers::read_file, + file_helpers::write_file, downloader::download_file, downloader::stop_download, lang::get_lang, diff --git a/src/utils/server.ts b/src/utils/server.ts index 763872c..f2fc6d5 100644 --- a/src/utils/server.ts +++ b/src/utils/server.ts @@ -1,10 +1,12 @@ -import { fs } from '@tauri-apps/api' +import { fs, invoke } from '@tauri-apps/api' export async function toggleEncryption(path: string) { let serverConf try { - serverConf = JSON.parse(await fs.readTextFile(path)) + serverConf = JSON.parse(await invoke('read_file', { + path, + })) } catch(e) { console.log(`Server config at ${path} not found or invalid`) return @@ -16,7 +18,7 @@ export async function toggleEncryption(path: string) { serverConf.server.http.encryption.useInRouting = !enabled // Write file - await fs.writeFile({ + await invoke('write_file', { path, contents: JSON.stringify(serverConf, null, 2), }) @@ -26,7 +28,9 @@ export async function encryptionEnabled(path: string) { let serverConf try { - serverConf = JSON.parse(await fs.readTextFile(path)) + serverConf = JSON.parse(await invoke('read_file', { + path, + })) } catch(e) { console.log(`Server config at ${path} not found or invalid`) return false