Compare commits

..

15 Commits

Author SHA1 Message Date
Magix
cbd05d2c42 Fix startup crash & file loading
Merge pull request #3 from Seeker14491/fix-windows
2022-07-02 11:31:07 -04:00
Brian Bowman
f6b80e1fac Fix Windows path issues 2022-07-02 02:12:12 -05:00
KingRainbow44
241b2b07bd Merge remote-tracking branch 'origin/main' 2022-07-01 16:26:22 -04:00
KingRainbow44
ec2f0f3ff8 Add debug mode as a config setting 2022-07-01 16:26:06 -04:00
KingRainbow44
578d17764c Change logic for command invoking 2022-07-01 16:25:52 -04:00
KingRainbow44
63f2a3a573 Add allowed http URLs 2022-07-01 16:25:38 -04:00
KingRainbow44
b034c73c72 Change to api.grasscutter.io 2022-07-01 16:25:18 -04:00
KingRainbow44
3b99b9137a Add duct as a dependency 2022-07-01 16:24:02 -04:00
Magix
39376aed8c Add the 'zh-CN'
Add Simplified Chinese translation
2022-06-30 12:41:50 -04:00
Tesutarin
4e1053761f Update chs.json 2022-06-30 16:47:55 +08:00
Tesutarin
8f648c16da Add Simplified Chinese translation 2022-06-30 10:56:25 +08:00
SpikeHD
68fb7dd36a Merge pull request #1 from Kimi898246/patch-1
Traditional Chinese | Translation JSON
2022-06-29 18:07:06 -07:00
Kimi
1327c077a7 Update cht.json 2022-06-30 05:37:59 +08:00
Kimi
12305c0dc9 Update cht.json 2022-06-30 04:48:24 +08:00
Kimi
15d53273d0 Traditional Chinese | Translation JSON
I think the title is self-explanatory enough..
2022-06-30 04:32:13 +08:00
14 changed files with 236 additions and 50 deletions

View File

@@ -3,6 +3,38 @@
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="HtmlUnknownBooleanAttribute" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="HttpUrlsUsage" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredUrls">
<list>
<option value="http://localhost" />
<option value="http://127.0.0.1" />
<option value="http://0.0.0.0" />
<option value="http://www.w3.org/" />
<option value="http://json-schema.org/draft" />
<option value="http://java.sun.com/" />
<option value="http://xmlns.jcp.org/" />
<option value="http://javafx.com/javafx/" />
<option value="http://javafx.com/fxml" />
<option value="http://maven.apache.org/xsd/" />
<option value="http://maven.apache.org/POM/" />
<option value="http://www.springframework.org/schema/" />
<option value="http://www.springframework.org/tags" />
<option value="http://www.springframework.org/security/tags" />
<option value="http://www.thymeleaf.org" />
<option value="http://www.jboss.org/j2ee/schema/" />
<option value="http://www.jboss.com/xml/ns/" />
<option value="http://www.ibm.com/webservices/xsd" />
<option value="http://activemq.apache.org/schema/" />
<option value="http://schema.cloudfoundry.org/spring/" />
<option value="http://schemas.xmlsoap.org/" />
<option value="http://cxf.apache.org/schemas/" />
<option value="http://primefaces.org/ui" />
<option value="http://tiles.apache.org/" />
<option value="http://api.grasscutter.io" />
<option value="http://api.grasscutters.xyz" />
</list>
</option>
</inspection_tool>
<inspection_tool class="JSIgnoredPromiseFromCall" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
</profile>
</component>

37
src-tauri/Cargo.lock generated
View File

@@ -743,6 +743,7 @@ name = "cultivation"
version = "0.1.0"
dependencies = [
"base64",
"duct",
"futures-util",
"http",
"hudsucker",
@@ -964,6 +965,18 @@ dependencies = [
"dtoa",
]
[[package]]
name = "duct"
version = "0.13.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fc6a0a59ed0888e0041cf708e66357b7ae1a82f1c67247e1f93b5e0818f7d8d"
dependencies = [
"libc",
"once_cell",
"os_pipe 0.9.2",
"shared_child 0.3.5",
]
[[package]]
name = "either"
version = "1.6.1"
@@ -2472,6 +2485,16 @@ dependencies = [
"winapi",
]
[[package]]
name = "os_pipe"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb233f06c2307e1f5ce2ecad9f8121cffbbee2c95428f44ea85222e460d0d213"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "os_pipe"
version = "1.0.1"
@@ -3520,6 +3543,16 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "shared_child"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6be9f7d5565b1483af3e72975e2dee33879b3b86bd48c0929fccf6585d79e65a"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "shared_child"
version = "1.0.0"
@@ -3880,7 +3913,7 @@ dependencies = [
"once_cell",
"open",
"os_info",
"os_pipe",
"os_pipe 1.0.1",
"percent-encoding",
"rand 0.8.5",
"raw-window-handle",
@@ -3891,7 +3924,7 @@ dependencies = [
"serde_json",
"serde_repr",
"serialize-to-javascript",
"shared_child",
"shared_child 1.0.0",
"state",
"tar",
"tauri-macros",

View File

@@ -33,6 +33,7 @@ registry = "1.2.1"
# Program opener.
open = "2.1.2"
duct = "0.13.5"
# Serialization.
serde_json = "1"

58
src-tauri/lang/chs.json Normal file
View File

@@ -0,0 +1,58 @@
{
"lang_name": "简体中文",
"main": {
"title": "Cultivation",
"launch_button": "启动",
"gc_enable": "以 Grasscutter 模式连接",
"https_enable": "使用 HTTPS",
"ip_placeholder": "IP 地址...",
"port_placeholder": "端口...",
"files_downloading": "文件下载中:",
"files_extracting": "文件解压中:"
},
"options": {
"game_exec": "选择游戏可执行文件",
"grasscutter_jar": "选择 Grasscutter JAR 文件",
"java_path": "设置自定义 Java 路径",
"grasscutter_with_game": "随游戏自动启动 Grasscutter",
"language": "语言",
"background": "设置自定义背景(链接或文件)",
"theme": "设置主题"
},
"downloads": {
"grasscutter_stable_data": "下载 Grasscutter 稳定版数据",
"grasscutter_latest_data": "下载 Grasscutter 开发版数据",
"grasscutter_stable_data_update": "更新 Grasscutter 稳定版数据",
"grasscutter_latest_data_update": "更新 Grasscutter 开发版数据",
"grasscutter_stable": "下载 Grasscutter 稳定版",
"grasscutter_latest": "下载 Grasscutter 开发版",
"grasscutter_stable_update": "更新 Grasscutter 稳定版",
"grasscutter_latest_update": "更新 Grasscutter 开发版",
"resources": "下载 Grasscutter 资源"
},
"download_status": {
"downloading": "下载中",
"extracting": "解压中",
"error": "错误",
"finished": "已完成",
"stopped": "已暂停"
},
"components": {
"select_file": "选择文件或文件夹...",
"select_folder": "选择文件夹...",
"download": "下载"
},
"news": {
"latest_commits": "最近的PR",
"latest_version": "最新版本"
},
"help": {
"port_help_text": "确保这是 Dispatch 服务器端口,而不是游戏服务器端口。大部分服务器的端口都是 443。",
"game_help_text": "你不需要另外的游戏备份来使用 Grasscutter。这是给想要降级到 2.6 或没有安装游戏的人使用的。",
"gc_stable_jar": "下载当前的 Grasscutter 稳定版,包括 JAR 文件和数据。",
"gc_dev_jar": "下载最新的 Grasscutter 开发版,包括 JAR 文件和数据。",
"gc_stable_data": "下载当前的 Grasscutter 稳定版数据,不包括 JAR 文件。此选项在更新时有帮助。",
"gc_dev_data": "下载最新的 Grasscutter 开发版数据,不包括 JAR 文件。此选项在更新时有帮助。",
"resources": "资源文件在运行 Grasscutter 服务器时是必要的。此选项在已经存在资源文件时不可选。"
}
}

58
src-tauri/lang/cht.json Normal file
View File

@@ -0,0 +1,58 @@
{
"lang_name": "繁體中文",
"main": {
"title": "Cultivation",
"launch_button": "啟動",
"gc_enable": "以Grasscutter模式連接",
"https_enable": "使用 HTTPS",
"ip_placeholder": "IP地址...",
"port_placeholder": "通訊埠...",
"files_downloading": "檔案下載中:",
"files_extracting": "檔案解壓縮中:"
},
"options": {
"game_exec": "選擇遊戲執行檔",
"grasscutter_jar": "選擇伺服器JAR檔案",
"java_path": "設置自定義Java路徑",
"grasscutter_with_game": "伴隨遊戲一起啟動Grasscutter",
"language": "語言",
"background": "設置自定義背景(網址或檔案)",
"theme": "設置主題"
},
"downloads": {
"grasscutter_stable_data": "下載Grasscutter穩定版數據Data",
"grasscutter_latest_data": "下載Grasscutter開發板數據Data",
"grasscutter_stable_data_update": "更新Grasscutter穩定版數據Data",
"grasscutter_latest_data_update": "更新Grasscutter開發板數據Data",
"grasscutter_stable": "下載Grasscutter穩定版",
"grasscutter_latest": "下載Grasscutter開發板",
"grasscutter_stable_update": "更新Grasscutter穩定版",
"grasscutter_latest_update": "更新Grasscutter開發板",
"resources": "下載Grasscutter資源Resources"
},
"download_status": {
"downloading": "下載中",
"extracting": "解壓縮中",
"error": "錯誤",
"finished": "已完成",
"stopped": "暫停"
},
"components": {
"select_file": "選擇檔案或資料夾...",
"select_folder": "選擇資料夾...",
"download": "下載"
},
"news": {
"latest_commits": "最近的PR",
"latest_version": "最新版本"
},
"help": {
"port_help_text": "確保這是Dispatch伺服器端口不是遊戲伺服器端口。 大部分伺服器的端口都是443。",
"game_help_text": "你不需要另外一個遊戲備份來使用Grasscutter。這是給想要降級到2.6或者還沒安裝遊戲的人使用的。",
"gc_stable_jar": "下載當前的Grasscutter穩定版本包括JAR答案還有資料文件。",
"gc_dev_jar": "下載當前的Grasscutter穩定版本資料文件其中不會附帶JAR文件。這個選項在更新時很有用。",
"gc_stable_data": "下載當前最新的Grasscutter開發版本資料文件其中不會附帶JAR文件。這個選項在更新時很有用。",
"gc_dev_data": "下載當前最新的Grasscutter開發版本的資料文件其中不會附帶JAR文件。這個選項在更新時很有用。",
"resources": "資源文件在架設一個Grasscutter伺服器時是必要的。 這個選項會在你已經有裡面有檔案的資源資料夾時不可選。"
}
}

View File

@@ -1,3 +1,4 @@
use std::path::{Path, PathBuf};
use crate::system_helpers::*;
#[tauri::command]
@@ -5,7 +6,8 @@ pub async fn get_lang(window: tauri::Window, lang: String) -> String {
let lang = lang.to_lowercase();
// Send contents of language file back
let contents = match std::fs::read_to_string(format!("{}/lang/{}.json", install_location(), lang)) {
let lang_path: PathBuf = [&install_location(), "lang", &format!("{}.json", lang)].iter().collect();
let contents = match std::fs::read_to_string(&lang_path) {
Ok(x) => x,
Err(e) => {
emit_lang_err(window, format!("Failed to read language file: {}", e));
@@ -21,14 +23,14 @@ pub async fn get_languages() -> std::collections::HashMap<String, String> {
// for each lang file, set the key as the filename and the value as the lang_name contained in the file
let mut languages = std::collections::HashMap::new();
let mut lang_files = std::fs::read_dir(format!("{}/lang", install_location())).unwrap();
let mut lang_files = std::fs::read_dir(Path::new(&install_location()).join("lang")).unwrap();
while let Some(entry) = lang_files.next() {
let entry = entry.unwrap();
let path = entry.path();
let filename = path.file_name().unwrap().to_str().unwrap();
let content = match std::fs::read_to_string(path.to_str().unwrap()) {
let content = match std::fs::read_to_string(&path) {
Ok(x) => x,
Err(e) => {
println!("Failed to read language file: {}", e);

View File

@@ -5,6 +5,7 @@ windows_subsystem = "windows"
use lazy_static::lazy_static;
use std::{sync::Mutex, collections::HashMap};
use std::path::PathBuf;
use std::thread;
use sysinfo::{System, SystemExt};
@@ -31,10 +32,8 @@ fn main() {
process_watcher();
// Make BG folder if it doesn't exist.
let bg_folder = format!("{}/bg", system_helpers::install_location());
if !std::path::Path::new(&bg_folder).exists() {
std::fs::create_dir_all(&bg_folder).unwrap();
}
let bg_folder: PathBuf = [&system_helpers::install_location(), "bg"].iter().collect();
std::fs::create_dir_all(&bg_folder).unwrap();
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
@@ -186,9 +185,10 @@ async fn get_theme_list(data_dir: String) -> Vec<HashMap<String, String>> {
}
#[tauri::command]
// TODO: Replace with downloading the background file & saving it.
async fn get_bg_file(bg_path: String, appdata: String) -> String {
let copy_loc = appdata;
let query = web::query("https://api.grasscutters.xyz/cultivation/query").await;
let query = web::query("https://api.grasscutter.io/cultivation/query").await;
let response_data: APIQuery = match serde_json::from_str(&query) {
Ok(data) => data,
Err(e) => {

View File

@@ -16,6 +16,7 @@ use hudsucker::{
use std::fs;
use std::net::SocketAddr;
use std::path::Path;
use registry::{Hive, Data, Security};
use rustls_pemfile as pemfile;
@@ -145,7 +146,7 @@ pub fn disconnect_from_proxy() {
* Source: https://github.com/zu1k/good-mitm/raw/master/src/ca/gen.rs
*/
#[tauri::command]
pub fn generate_ca_files(path: &str) {
pub fn generate_ca_files(path: &Path) {
let mut params = CertificateParams::default();
let mut details = DistinguishedName::new();
@@ -166,14 +167,13 @@ pub fn generate_ca_files(path: &str) {
];
// Create certificate.
let cert_path = format!("{}\\ca", path);
let cert = Certificate::from_params(params).unwrap();
let cert_crt = cert.serialize_pem().unwrap();
let private_key = cert.serialize_private_key_pem();
// Make certificate directory.
match fs::create_dir(&cert_path) {
let cert_dir = path.join("ca");
match fs::create_dir(&cert_dir) {
Ok(_) => {},
Err(e) => {
println!("{}", e);
@@ -181,29 +181,31 @@ pub fn generate_ca_files(path: &str) {
};
// Write the certificate to a file.
match fs::write(format!("{}\\cert.crt", &cert_path), cert_crt) {
Ok(_) => println!("Wrote certificate to {}", &cert_path),
Err(e) => println!("Error writing certificate to {}: {}", &cert_path, e),
let cert_path = cert_dir.join("cert.crt");
match fs::write(&cert_path, cert_crt) {
Ok(_) => println!("Wrote certificate to {}", cert_path.to_str().unwrap()),
Err(e) => println!("Error writing certificate to {}: {}", cert_path.to_str().unwrap(), e),
}
// Write the private key to a file.
match fs::write(format!("{}\\private.key", &cert_path), private_key) {
Ok(_) => println!("Wrote private key to {}", &cert_path),
Err(e) => println!("Error writing private key to {}: {}", &cert_path, e),
let private_key_path = cert_dir.join("private.key");
match fs::write(&private_key_path, private_key) {
Ok(_) => println!("Wrote private key to {}", private_key_path.to_str().unwrap()),
Err(e) => println!("Error writing private key to {}: {}", private_key_path.to_str().unwrap(), e),
}
// Install certificate into the system's Root CA store.
install_ca_files(path);
install_ca_files(&cert_path);
}
/*
* Attempts to install the certificate authority's certificate into the Root CA store.
*/
pub fn install_ca_files(path: &str) {
pub fn install_ca_files(cert_path: &Path) {
if cfg!(target_os = "windows") {
run_command(format!("certutil -user -addstore \"Root\" {}\\ca\\cert.crt", path).to_string());
run_command("certutil", vec!["-user", "-addstore", "Root", cert_path.to_str().unwrap()]);
} else {
run_command(format!("security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain {}/ca/cert.crt", path).to_string());
run_command("security", vec!["add-trusted-cert", "-d", "-r", "trustRoot", "-k", "/Library/Keychains/System.keychain", cert_path.to_str().unwrap()]);
}
println!("Installed certificate.");

View File

@@ -1,8 +1,8 @@
use std::thread;
use std::process::Command;
use tauri;
use open;
use duct::cmd;
use crate::file_helpers;
@@ -17,20 +17,9 @@ pub fn run_program(path: String) {
}
#[tauri::command]
pub fn run_command(command: String) {
// Run the specified command.
if cfg!(target_os = "windows") {
Command::new("cmd")
.args(["/C", command.as_str()])
.output()
.expect("failed to execute process")
} else {
Command::new("sh")
.arg("-c")
.arg(command.as_str())
.output()
.expect("failed to execute process")
};
pub fn run_command(program: &str, args: Vec<&str>) {
cmd(program, args).run()
.expect("Failed to run command");
}
#[tauri::command]

View File

@@ -75,7 +75,8 @@
"active": true,
"dialog": true,
"endpoints": [
"https://api.grasscutters.xyz/cultivation/update?version={{current_version}}"
"https://api.grasscutter.io/cultivation/updater?version={{current_version}}",
"https://api.grasscutters.xyz/cultivation/updater?version={{current_version}}"
],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEIyM0MzMzk0NkM4OTQzNQpSV1ExbE1oR09jTWpDNFJ4NURsaS9mdHpDWmpBM3JNVHkrdER4bS9KdHFCQnNVSWs0ZjZTU295WAo="
},

View File

@@ -3,20 +3,27 @@ import ReactDOM from 'react-dom/client'
import './index.css'
import App from './ui/App'
// import Debug from './ui/Debug'
import Debug from './ui/Debug'
import { getConfigOption } from './utils/configuration'
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
)
let isDebug = false;
(async() => {
isDebug = await getConfigOption('debug_enabled')
})
root.render(
<React.StrictMode>
<App />
{
isDebug ? <Debug /> : <App />
}
</React.StrictMode>
)
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
import reportWebVitals from './utils/reportWebVitals'
reportWebVitals(console.log)
isDebug && reportWebVitals(console.log)

View File

@@ -36,7 +36,7 @@ interface IState {
bgFile: string;
}
const DEFAULT_BG = 'https://api.grasscutters.xyz/content/bgfile'
const DEFAULT_BG = 'https://api.grasscutter.io/cultivation/bgfile'
const downloadHandler = new DownloadHandler()

View File

@@ -42,7 +42,7 @@ export default class NewsSection extends React.Component<IProps, IState> {
async showLatestCommits() {
if (!this.state.commitList) {
const commits: string = await invoke('req_get', { url: 'https://api.grasscutters.xyz/cultivation/query' })
const commits: string = await invoke('req_get', { url: 'https://api.grasscutter.io/cultivation/query' })
let obj
try {

View File

@@ -20,6 +20,7 @@ let defaultConfig: Configuration
cert_generated: false,
theme: 'default',
https_enabled: false,
debug_enabled: false
}
})()
@@ -39,8 +40,9 @@ export interface Configuration {
language: string
customBackground: string
cert_generated: boolean
theme: string;
theme: string
https_enabled: boolean
debug_enabled: boolean
}
export async function setConfigOption(key: string, value: any): Promise<void> {
@@ -52,8 +54,9 @@ export async function setConfigOption(key: string, value: any): Promise<void> {
export async function getConfigOption(key: string): Promise<any> {
const config: any = await getConfig()
const defaults: any = defaultConfig
return config[key] || null
return config[key] || defaults[key]
}
export async function getConfig() {