[feat] read video config is ok
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -41,4 +41,5 @@ yarn-error.log*
|
||||
.env.*
|
||||
|
||||
temp/
|
||||
src-tauri/temp/
|
||||
log/
|
||||
2
src-tauri/.gitignore
vendored
2
src-tauri/.gitignore
vendored
@@ -1,3 +1,3 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
/target/
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::steam;
|
||||
use crate::tool::*;
|
||||
use crate::vdf::preset;
|
||||
use crate::vdf::preset::VideoConfig;
|
||||
use crate::wrap_err;
|
||||
use anyhow::Result;
|
||||
|
||||
@@ -81,6 +82,31 @@ pub fn set_auto_login_user(user: &str) -> Result<String, String> {
|
||||
Ok(format!("Set auto login user to {}", user))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_cs2_video_config(steam_dir: &str, steam_id32: u32) -> Result<VideoConfig, String> {
|
||||
let p = format!(
|
||||
"{}/userdata/{}/730/local/cfg/cs2_video.txt",
|
||||
steam_dir, steam_id32
|
||||
);
|
||||
let video = preset::get_cs2_video(p.as_str()).map_err(|e| e.to_string())?;
|
||||
Ok(video)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn set_cs2_video_config(
|
||||
steam_dir: &str,
|
||||
steam_id32: u32,
|
||||
video_config: VideoConfig,
|
||||
) -> Result<(), String> {
|
||||
let p = format!(
|
||||
"{}/userdata/{}/730/local/cfg/cs2_video.txt",
|
||||
steam_dir, steam_id32
|
||||
);
|
||||
preset::set_cs2_video(p.as_str(), video_config).map_err(|e| e.to_string())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn check_path(path: &str) -> Result<bool, String> {
|
||||
Ok(std::path::Path::new(&path).exists())
|
||||
|
||||
@@ -129,6 +129,8 @@ fn main() {
|
||||
cmds::set_powerplan,
|
||||
cmds::get_steam_users,
|
||||
cmds::set_auto_login_user,
|
||||
cmds::get_cs2_video_config,
|
||||
cmds::set_cs2_video_config,
|
||||
cmds::check_path,
|
||||
on_button_clicked
|
||||
])
|
||||
|
||||
@@ -18,7 +18,7 @@ pub fn kill(name: &str) -> String {
|
||||
|
||||
pub fn run_steam() -> std::io::Result<std::process::Output> {
|
||||
#[cfg(target_os = "windows")]
|
||||
Command::new("cmd")
|
||||
return Command::new("cmd")
|
||||
.args(&["/C", "start", "steam://run"])
|
||||
.creation_flags(CREATE_NO_WINDOW)
|
||||
.output();
|
||||
|
||||
@@ -48,55 +48,55 @@ pub fn to_vdf(json_data: &str) -> String {
|
||||
}
|
||||
|
||||
fn build_vdf(json_value: &serde_json::Value, vdf_data: &mut String, indent_level: usize) {
|
||||
match json_value {
|
||||
serde_json::Value::Object(obj) => {
|
||||
for (key, value) in obj {
|
||||
vdf_data.push_str(&"\t".repeat(indent_level));
|
||||
vdf_data.push_str(&format!("\"{}\"\n", key));
|
||||
vdf_data.push_str(&"\t".repeat(indent_level));
|
||||
vdf_data.push_str("{\n");
|
||||
build_vdf(value, vdf_data, indent_level + 1);
|
||||
vdf_data.push_str(&"\t".repeat(indent_level));
|
||||
vdf_data.push_str("}\n");
|
||||
}
|
||||
}
|
||||
serde_json::Value::String(s) => {
|
||||
vdf_data.push_str(&"\t".repeat(indent_level));
|
||||
vdf_data.push_str(&format!("\"{}\"\t\t\"{}\"\n", s, s));
|
||||
}
|
||||
_ => {
|
||||
vdf_data.push_str(&"\t".repeat(indent_level));
|
||||
vdf_data.push_str(&format!("\"{}\"\t\t\"{}\"\n", json_value, json_value));
|
||||
}
|
||||
}
|
||||
match json_value {
|
||||
serde_json::Value::Object(obj) => {
|
||||
for (key, value) in obj {
|
||||
vdf_data.push_str(&"\t".repeat(indent_level));
|
||||
vdf_data.push_str(&format!("\"{}\"\n", key));
|
||||
vdf_data.push_str(&"\t".repeat(indent_level));
|
||||
vdf_data.push_str("{\n");
|
||||
build_vdf(value, vdf_data, indent_level + 1);
|
||||
vdf_data.push_str(&"\t".repeat(indent_level));
|
||||
vdf_data.push_str("}\n");
|
||||
}
|
||||
}
|
||||
serde_json::Value::String(s) => {
|
||||
vdf_data.push_str(&"\t".repeat(indent_level));
|
||||
vdf_data.push_str(&format!("\"{}\"\t\t\"{}\"\n", s, s));
|
||||
}
|
||||
_ => {
|
||||
vdf_data.push_str(&"\t".repeat(indent_level));
|
||||
vdf_data.push_str(&format!("\"{}\"\t\t\"{}\"\n", json_value, json_value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
static VDF_DATA: &str = r#"\"users\"
|
||||
static VDF_DATA: &str = r#""users"
|
||||
{
|
||||
\"76561198315078806\"
|
||||
"76561198315078806"
|
||||
{
|
||||
\"AccountName\" \"_jerry_dota2\"
|
||||
\"PersonaName\" \"Rop紫(已黑化)\"
|
||||
\"RememberPassword\" \"1\"
|
||||
\"WantsOfflineMode\" \"0\"
|
||||
\"SkipOfflineModeWarning\" \"0\"
|
||||
\"AllowAutoLogin\" \"1\"
|
||||
\"MostRecent\" \"1\"
|
||||
\"Timestamp\" \"1742706884\"
|
||||
"AccountName" "_jerry_dota2"
|
||||
"PersonaName" "Rop紫(已黑化)"
|
||||
"RememberPassword" "1"
|
||||
"WantsOfflineMode" "0"
|
||||
"SkipOfflineModeWarning" "0"
|
||||
"AllowAutoLogin" "1"
|
||||
"MostRecent" "1"
|
||||
"Timestamp" "1742706884"
|
||||
}
|
||||
\"76561198107125441\"
|
||||
"76561198107125441"
|
||||
{
|
||||
\"AccountName\" \"_im_ai_\"
|
||||
\"PersonaName\" \"Buongiorno\"
|
||||
\"RememberPassword\" \"1\"
|
||||
\"WantsOfflineMode\" \"0\"
|
||||
\"SkipOfflineModeWarning\" \"0\"
|
||||
\"AllowAutoLogin\" \"1\"
|
||||
\"MostRecent\" \"0\"
|
||||
\"Timestamp\" \"1739093763\"
|
||||
"AccountName" "_im_ai_"
|
||||
"PersonaName" "Buongiorno"
|
||||
"RememberPassword" "1"
|
||||
"WantsOfflineMode" "0"
|
||||
"SkipOfflineModeWarning" "0"
|
||||
"AllowAutoLogin" "1"
|
||||
"MostRecent" "0"
|
||||
"Timestamp" "1739093763"
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
@@ -49,35 +49,74 @@ pub struct VideoConfig {
|
||||
version: String,
|
||||
vendor_id: String,
|
||||
device_id: String,
|
||||
setting_cpu_level: String,
|
||||
setting_gpu_mem_level: String,
|
||||
setting_gpu_level: String,
|
||||
setting_knowndevice: String,
|
||||
setting_defaultres: String,
|
||||
setting_defaultresheight: String,
|
||||
setting_refreshrate_numerator: String,
|
||||
setting_refreshrate_denominator: String,
|
||||
setting_fullscreen: String,
|
||||
setting_coop_fullscreen: String,
|
||||
setting_nowindowborder: String,
|
||||
setting_mat_vsync: String,
|
||||
setting_fullscreen_min_on_focus_loss: String,
|
||||
setting_high_dpi: String,
|
||||
cpu_level: String,
|
||||
gpu_mem_level: String,
|
||||
gpu_level: String,
|
||||
knowndevice: String,
|
||||
defaultres: String,
|
||||
defaultresheight: String,
|
||||
refreshrate_numerator: String,
|
||||
refreshrate_denominator: String,
|
||||
fullscreen: String,
|
||||
coop_fullscreen: String,
|
||||
nowindowborder: String,
|
||||
mat_vsync: String,
|
||||
fullscreen_min_on_focus_loss: String,
|
||||
high_dpi: String,
|
||||
auto_config: String,
|
||||
setting_shaderquality: String,
|
||||
setting_r_texturefilteringquality: String,
|
||||
setting_msaa_samples: String,
|
||||
setting_r_csgo_cmaa_enable: String,
|
||||
setting_videocfg_shadow_quality: String,
|
||||
setting_videocfg_dynamic_shadows: String,
|
||||
setting_videocfg_texture_detail: String,
|
||||
setting_videocfg_particle_detail: String,
|
||||
setting_videocfg_ao_detail: String,
|
||||
setting_videocfg_hdr_detail: String,
|
||||
setting_videocfg_fsr_detail: String,
|
||||
setting_monitor_index: String,
|
||||
setting_r_low_latency: String,
|
||||
setting_aspectratiomode: String,
|
||||
shaderquality: String,
|
||||
r_texturefilteringquality: String,
|
||||
msaa_samples: String,
|
||||
r_csgo_cmaa_enable: String,
|
||||
videocfg_shadow_quality: String,
|
||||
videocfg_dynamic_shadows: String,
|
||||
videocfg_texture_detail: String,
|
||||
videocfg_particle_detail: String,
|
||||
videocfg_ao_detail: String,
|
||||
videocfg_hdr_detail: String,
|
||||
videocfg_fsr_detail: String,
|
||||
monitor_index: String,
|
||||
r_low_latency: String,
|
||||
aspectratiomode: String,
|
||||
}
|
||||
|
||||
impl Default for VideoConfig {
|
||||
fn default() -> Self {
|
||||
VideoConfig {
|
||||
version: String::new(),
|
||||
vendor_id: String::new(),
|
||||
device_id: String::new(),
|
||||
cpu_level: String::new(),
|
||||
gpu_mem_level: String::new(),
|
||||
gpu_level: String::new(),
|
||||
knowndevice: String::new(),
|
||||
defaultres: String::new(),
|
||||
defaultresheight: String::new(),
|
||||
refreshrate_numerator: String::new(),
|
||||
refreshrate_denominator: String::new(),
|
||||
fullscreen: String::new(),
|
||||
coop_fullscreen: String::new(),
|
||||
nowindowborder: String::new(),
|
||||
mat_vsync: String::new(),
|
||||
fullscreen_min_on_focus_loss: String::new(),
|
||||
high_dpi: String::new(),
|
||||
auto_config: String::new(),
|
||||
shaderquality: String::new(),
|
||||
r_texturefilteringquality: String::new(),
|
||||
msaa_samples: String::new(),
|
||||
r_csgo_cmaa_enable: String::new(),
|
||||
videocfg_shadow_quality: String::new(),
|
||||
videocfg_dynamic_shadows: String::new(),
|
||||
videocfg_texture_detail: String::new(),
|
||||
videocfg_particle_detail: String::new(),
|
||||
videocfg_ao_detail: String::new(),
|
||||
videocfg_hdr_detail: String::new(),
|
||||
videocfg_fsr_detail: String::new(),
|
||||
monitor_index: String::new(),
|
||||
r_low_latency: String::new(),
|
||||
aspectratiomode: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_login_users(steam_dir: &str) -> Result<Vec<LoginUser>> {
|
||||
@@ -306,16 +345,234 @@ fn read_avatar(steam_dir: &str, steam_id64: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_cs2_video(file_path: &str) -> Result<HashMap<String, String>> {
|
||||
let data = fs::read_to_string(file_path)?;
|
||||
pub fn get_cs2_video(file_path: &str) -> Result<VideoConfig> {
|
||||
// TODO: no kv
|
||||
let data = fs::read_to_string(file_path)?;
|
||||
let json_data = super::parse::to_json(&data);
|
||||
let kv: HashMap<String, String> = serde_json::from_str(&json_data)?;
|
||||
Ok(kv)
|
||||
let video_config = VideoConfig {
|
||||
version: kv.get("version").unwrap_or(&"".to_string()).to_string(),
|
||||
vendor_id: kv.get("vendor_id").unwrap_or(&"".to_string()).to_string(),
|
||||
device_id: kv.get("device_id").unwrap_or(&"".to_string()).to_string(),
|
||||
cpu_level: kv
|
||||
.get("setting.cpu_level")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
gpu_mem_level: kv
|
||||
.get("setting.gpu_mem_level")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
gpu_level: kv
|
||||
.get("setting.gpu_level")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
knowndevice: kv
|
||||
.get("setting.knowndevice")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
defaultres: kv
|
||||
.get("setting.defaultres")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
defaultresheight: kv
|
||||
.get("setting.defaultresheight")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
refreshrate_numerator: kv
|
||||
.get("setting.refreshrate_numerator")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
refreshrate_denominator: kv
|
||||
.get("setting.refreshrate_denominator")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
fullscreen: kv
|
||||
.get("setting.fullscreen")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
coop_fullscreen: kv
|
||||
.get("setting.coop_fullscreen")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
nowindowborder: kv
|
||||
.get("setting.nowindowborder")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
mat_vsync: kv
|
||||
.get("setting.mat_vsync")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
fullscreen_min_on_focus_loss: kv
|
||||
.get("setting.fullscreen_min_on_focus_loss")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
high_dpi: kv
|
||||
.get("setting.high_dpi")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
auto_config: kv.get("auto_config").unwrap_or(&"".to_string()).to_string(),
|
||||
shaderquality: kv
|
||||
.get("setting.shaderquality")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
r_texturefilteringquality: kv
|
||||
.get("setting.r_texturefilteringquality")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
msaa_samples: kv
|
||||
.get("setting.msaa_samples")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
r_csgo_cmaa_enable: kv
|
||||
.get("setting.r_csgo_cmaa_enable")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
videocfg_shadow_quality: kv
|
||||
.get("setting.videocfg_shadow_quality")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
videocfg_dynamic_shadows: kv
|
||||
.get("setting.videocfg_dynamic_shadows")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
videocfg_texture_detail: kv
|
||||
.get("setting.videocfg_texture_detail")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
videocfg_particle_detail: kv
|
||||
.get("setting.videocfg_particle_detail")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
videocfg_ao_detail: kv
|
||||
.get("setting.videocfg_ao_detail")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
videocfg_hdr_detail: kv
|
||||
.get("setting.videocfg_hdr_detail")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
videocfg_fsr_detail: kv
|
||||
.get("setting.videocfg_fsr_detail")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
monitor_index: kv
|
||||
.get("setting.monitor_index")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
r_low_latency: kv
|
||||
.get("setting.r_low_latency")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
aspectratiomode: kv
|
||||
.get("setting.aspectratiomode")
|
||||
.unwrap_or(&"".to_string())
|
||||
.to_string(),
|
||||
};
|
||||
Ok(video_config)
|
||||
}
|
||||
|
||||
pub fn set_cs2_video(file_path: &str, data: HashMap<String, String>) -> Result<()> {
|
||||
let json_data = serde_json::to_string(&data)?;
|
||||
pub fn set_cs2_video(file_path: &str, data: VideoConfig) -> Result<()> {
|
||||
// TODO: no kv
|
||||
let mut kv = HashMap::new();
|
||||
kv.insert("version".to_string(), data.version);
|
||||
kv.insert("vendor_id".to_string(), data.vendor_id);
|
||||
kv.insert("device_id".to_string(), data.device_id);
|
||||
kv.insert("setting.cpu_level".to_string(), data.cpu_level);
|
||||
kv.insert(
|
||||
"setting.gpu_mem_level".to_string(),
|
||||
data.gpu_mem_level,
|
||||
);
|
||||
kv.insert("setting.gpu_level".to_string(), data.gpu_level);
|
||||
kv.insert("setting.knowndevice".to_string(), data.knowndevice);
|
||||
kv.insert("setting.defaultres".to_string(), data.defaultres);
|
||||
kv.insert(
|
||||
"setting.defaultresheight".to_string(),
|
||||
data.defaultresheight,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.refreshrate_numerator".to_string(),
|
||||
data.refreshrate_numerator,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.refreshrate_denominator".to_string(),
|
||||
data.refreshrate_denominator,
|
||||
);
|
||||
kv.insert("setting.fullscreen".to_string(), data.fullscreen);
|
||||
kv.insert(
|
||||
"setting.coop_fullscreen".to_string(),
|
||||
data.coop_fullscreen,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.nowindowborder".to_string(),
|
||||
data.nowindowborder,
|
||||
);
|
||||
kv.insert("setting.mat_vsync".to_string(), data.mat_vsync);
|
||||
kv.insert(
|
||||
"setting.fullscreen_min_on_focus_loss".to_string(),
|
||||
data.fullscreen_min_on_focus_loss,
|
||||
);
|
||||
kv.insert("setting.high_dpi".to_string(), data.high_dpi);
|
||||
kv.insert("auto_config".to_string(), data.auto_config);
|
||||
kv.insert(
|
||||
"setting.shaderquality".to_string(),
|
||||
data.shaderquality,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.r_texturefilteringquality".to_string(),
|
||||
data.r_texturefilteringquality,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.msaa_samples".to_string(),
|
||||
data.msaa_samples,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.r_csgo_cmaa_enable".to_string(),
|
||||
data.r_csgo_cmaa_enable,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.videocfg_shadow_quality".to_string(),
|
||||
data.videocfg_shadow_quality,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.videocfg_dynamic_shadows".to_string(),
|
||||
data.videocfg_dynamic_shadows,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.videocfg_texture_detail".to_string(),
|
||||
data.videocfg_texture_detail,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.videocfg_particle_detail".to_string(),
|
||||
data.videocfg_particle_detail,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.videocfg_ao_detail".to_string(),
|
||||
data.videocfg_ao_detail,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.videocfg_hdr_detail".to_string(),
|
||||
data.videocfg_hdr_detail,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.videocfg_fsr_detail".to_string(),
|
||||
data.videocfg_fsr_detail,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.monitor_index".to_string(),
|
||||
data.monitor_index,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.r_low_latency".to_string(),
|
||||
data.r_low_latency,
|
||||
);
|
||||
kv.insert(
|
||||
"setting.aspectratiomode".to_string(),
|
||||
data.aspectratiomode,
|
||||
);
|
||||
|
||||
let json_data = serde_json::to_string(&kv)?;
|
||||
let vdf_data = super::parse::to_vdf(&json_data);
|
||||
// println!("{}", vdf_data);
|
||||
fs::write(file_path, vdf_data)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -332,14 +589,17 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_cs2_video() {
|
||||
let video_config = get_cs2_video("src-tauri/src/vdf/tests/cs2_video.txt").unwrap();
|
||||
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
||||
let file_path = format!("{}/src/vdf/tests/cs2_video.txt", manifest_dir);
|
||||
let video_config = get_cs2_video(&file_path).unwrap();
|
||||
println!("{:?}", video_config);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_cs2_video() {
|
||||
let mut video_config = HashMap::new();
|
||||
video_config.insert("setting.fullscreen".to_string(), "0".to_string());
|
||||
set_cs2_video("temp/cs2_video.txt", video_config).unwrap();
|
||||
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
||||
let file_path = format!("{}/temp/cs2_video.txt", manifest_dir);
|
||||
let video_config = VideoConfig::default();
|
||||
set_cs2_video(&file_path, video_config).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { CloseSmall, Down, Edit, Plus, SettingConfig, Up } from "@icon-park/react"
|
||||
import { useState } from "react"
|
||||
import { useEffect, useState } from "react"
|
||||
import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card"
|
||||
import { ToolButton } from "../window/ToolButton"
|
||||
import { addToast, NumberInput, Tab, Tabs, Tooltip } from "@heroui/react"
|
||||
import { motion } from "framer-motion"
|
||||
import { useToolStore } from "@/store/tool"
|
||||
import { useSteamStore } from "@/store/steam"
|
||||
|
||||
const VideoSetting = () => {
|
||||
const [hide, setHide] = useState(false)
|
||||
const [edit, setEdit] = useState(false)
|
||||
const tool = useToolStore()
|
||||
const steam = useSteamStore()
|
||||
// const [launchOpt, setLaunchOpt] = useState(tool.state.VideoSettings[tool.state.launchIndex] || "")
|
||||
|
||||
// useEffect(() => {
|
||||
@@ -18,69 +20,173 @@ const VideoSetting = () => {
|
||||
|
||||
// 设置对应关系
|
||||
// TODO Value通过实际数值映射
|
||||
|
||||
const videoSettings = [
|
||||
{ type: "", title: "全屏", value: "全屏", options: ["窗口", "全屏"] },
|
||||
{ type: "", title: "垂直同步", value: "关闭", options: ["关闭", "开启"] },
|
||||
{ type: "", title: "低延迟模式", value: "关闭", options: ["关闭", "开启"] },
|
||||
{ type: "", title: "增强角色对比度", value: "禁用", options: ["禁用", "启用"] },
|
||||
{ type: "", title: "CMAA2抗锯齿", value: "关闭", options: ["关闭", "开启"] },
|
||||
{
|
||||
type: "",
|
||||
type: "fullscreen",
|
||||
title: "全屏",
|
||||
value: tool.state.videoSetting.fullscreen === "1" ? "全屏" : "窗口",
|
||||
options: ["窗口", "全屏"],
|
||||
},
|
||||
{
|
||||
type: "mat_vsync",
|
||||
title: "垂直同步",
|
||||
value: tool.state.videoSetting.mat_vsync === "1" ? "开启" : "关闭",
|
||||
options: ["关闭", "开启"],
|
||||
},
|
||||
{
|
||||
type: "r_low_latency",
|
||||
title: "低延迟模式",
|
||||
value: tool.state.videoSetting.r_low_latency === "1" ? "开启" : "关闭",
|
||||
options: ["关闭", "开启"],
|
||||
},
|
||||
{
|
||||
type: "r_csgo_cmaa_enable",
|
||||
title: "增强角色对比度",
|
||||
value: tool.state.videoSetting.r_csgo_cmaa_enable === "1" ? "启用" : "禁用",
|
||||
options: ["禁用", "启用"],
|
||||
},
|
||||
{
|
||||
type: "msaa_samples",
|
||||
title: "多重采样抗锯齿",
|
||||
value: "2X MSAA",
|
||||
value:
|
||||
{
|
||||
0: "无",
|
||||
2: "2X MSAA",
|
||||
4: "4X MSAA",
|
||||
8: "8X MSAA",
|
||||
}[parseInt(tool.state.videoSetting.msaa_samples)] || "无",
|
||||
options: ["无", "2X MSAA", "4X MSAA", "8X MSAA"],
|
||||
},
|
||||
{ type: "", title: "全局阴影效果", value: "低", options: ["低", "中", "高", "非常高"] },
|
||||
{ type: "", title: "动态阴影", value: "全部", options: ["仅限日光", "全部"] },
|
||||
{ type: "", title: "模型/贴图细节", value: "中", options: ["低", "中", "高"] },
|
||||
{
|
||||
type: "",
|
||||
type: "videocfg_shadow_quality",
|
||||
title: "全局阴影效果",
|
||||
value:
|
||||
["低", "中", "高", "非常高"][parseInt(tool.state.videoSetting.videocfg_shadow_quality)] ||
|
||||
"低",
|
||||
options: ["低", "中", "高", "非常高"],
|
||||
},
|
||||
{
|
||||
type: "videocfg_dynamic_shadows",
|
||||
title: "动态阴影",
|
||||
value:
|
||||
["仅限日光", "全部"][parseInt(tool.state.videoSetting.videocfg_dynamic_shadows)] ||
|
||||
"仅限日光",
|
||||
options: ["仅限日光", "全部"],
|
||||
},
|
||||
{
|
||||
type: "videocfg_texture_detail",
|
||||
title: "模型/贴图细节",
|
||||
value: ["低", "中", "高"][parseInt(tool.state.videoSetting.videocfg_texture_detail)] || "低",
|
||||
options: ["低", "中", "高"],
|
||||
},
|
||||
{
|
||||
type: "r_texturefilteringquality",
|
||||
title: "贴图过滤模式",
|
||||
value: "异向 4X",
|
||||
value:
|
||||
["双线性", "三线性", "异向 2X", "异向 4X", "异向 8X", "异向 16X"][
|
||||
parseInt(tool.state.videoSetting.r_texturefilteringquality)
|
||||
] || "双线性",
|
||||
options: ["双线性", "三线性", "异向 2X", "异向 4X", "异向 8X", "异向 16X"],
|
||||
},
|
||||
{ type: "", title: "光影细节", value: "低", options: ["低", "高"] },
|
||||
{ type: "", title: "粒子细节", value: "低", options: ["低", "中", "高", "非常高"] },
|
||||
{ type: "", title: "环境光遮蔽", value: "已禁用", options: ["已禁用", "中", "高"] },
|
||||
{ type: "", title: "高动态范围", value: "性能", options: ["性能", "品质"] },
|
||||
{
|
||||
type: "",
|
||||
type: "videocfg_hdr_detail",
|
||||
title: "光影细节",
|
||||
value: ["低", "高"][parseInt(tool.state.videoSetting.shaderquality)] || "低",
|
||||
options: ["低", "高"],
|
||||
},
|
||||
{
|
||||
type: "videocfg_particle_detail",
|
||||
title: "粒子细节",
|
||||
value:
|
||||
["低", "中", "高", "非常高"][parseInt(tool.state.videoSetting.videocfg_particle_detail)] ||
|
||||
"低",
|
||||
options: ["低", "中", "高", "非常高"],
|
||||
},
|
||||
{
|
||||
type: "videocfg_ao_detail",
|
||||
title: "环境光遮蔽",
|
||||
value:
|
||||
["已禁用", "中", "高"][parseInt(tool.state.videoSetting.videocfg_ao_detail)] || "已禁用",
|
||||
options: ["已禁用", "中", "高"],
|
||||
},
|
||||
{
|
||||
type: "videocfg_fsr_detail",
|
||||
title: "Fidelity FX 超级分辨率",
|
||||
value: "已禁用",
|
||||
value:
|
||||
["已禁用", "超高品质", "品质", "均衡", "性能"][
|
||||
parseInt(tool.state.videoSetting.videocfg_fsr_detail)
|
||||
] || "性能",
|
||||
options: ["性能", "均衡", "品质", "超高品质", "已禁用"],
|
||||
},
|
||||
]
|
||||
// const videoSettings = [
|
||||
// { type: "", title: "全屏", value: "全屏", options: ["窗口", "全屏"] },
|
||||
// { type: "", title: "垂直同步", value: "关闭", options: ["关闭", "开启"] },
|
||||
// { type: "", title: "低延迟模式", value: "关闭", options: ["关闭", "开启"] },
|
||||
// { type: "", title: "增强角色对比度", value: "禁用", options: ["禁用", "启用"] },
|
||||
// { type: "", title: "CMAA2抗锯齿", value: "关闭", options: ["关闭", "开启"] },
|
||||
// {
|
||||
// type: "",
|
||||
// title: "多重采样抗锯齿",
|
||||
// value: "2X MSAA",
|
||||
// options: ["无", "2X MSAA", "4X MSAA", "8X MSAA"],
|
||||
// },
|
||||
// { type: "", title: "全局阴影效果", value: "低", options: ["低", "中", "高", "非常高"] },
|
||||
// { type: "", title: "动态阴影", value: "全部", options: ["仅限日光", "全部"] },
|
||||
// { type: "", title: "模型/贴图细节", value: "中", options: ["低", "中", "高"] },
|
||||
// {
|
||||
// type: "",
|
||||
// title: "贴图过滤模式",
|
||||
// value: "异向 4X",
|
||||
// options: ["双线性", "三线性", "异向 2X", "异向 4X", "异向 8X", "异向 16X"],
|
||||
// },
|
||||
// { type: "", title: "光影细节", value: "低", options: ["低", "高"] },
|
||||
// { type: "", title: "粒子细节", value: "低", options: ["低", "中", "高", "非常高"] },
|
||||
// { type: "", title: "环境光遮蔽", value: "已禁用", options: ["已禁用", "中", "高"] },
|
||||
// { type: "", title: "高动态范围", value: "性能", options: ["性能", "品质"] },
|
||||
// {
|
||||
// type: "",
|
||||
// title: "Fidelity FX 超级分辨率",
|
||||
// value: "已禁用",
|
||||
// options: ["性能", "均衡", "品质", "超高品质", "已禁用"],
|
||||
// },
|
||||
// ]
|
||||
|
||||
// useEffect(() => {
|
||||
// void tool.getVideoConfig()
|
||||
// })
|
||||
|
||||
return (
|
||||
<Tooltip content="功能测试中,尚未实装" showArrow={true} delay={300}>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardIcon>
|
||||
<SettingConfig /> 视频设置
|
||||
</CardIcon>
|
||||
<CardTool>
|
||||
{/* {tool.state.VideoSettings.map((option, index) => (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardIcon>
|
||||
<SettingConfig /> 视频设置
|
||||
</CardIcon>
|
||||
<CardTool>
|
||||
{/* {tool.state.VideoSettings.map((option, index) => (
|
||||
<ToolButton key={index} onClick={() => tool.setLaunchIndex(index)}>
|
||||
{index + 1}
|
||||
</ToolButton>
|
||||
))} */}
|
||||
{edit && (
|
||||
<>
|
||||
<ToolButton>低</ToolButton>
|
||||
<ToolButton>中</ToolButton>
|
||||
<ToolButton>高</ToolButton>
|
||||
<ToolButton>非常高</ToolButton>
|
||||
<ToolButton>推荐</ToolButton>
|
||||
<ToolButton
|
||||
onClick={() => {
|
||||
addToast({ title: "测试中 功能完成后可应用设置到游戏" })
|
||||
}}
|
||||
>
|
||||
<Plus />
|
||||
应用
|
||||
</ToolButton>
|
||||
</>
|
||||
)}
|
||||
{edit && (
|
||||
<>
|
||||
<ToolButton>低</ToolButton>
|
||||
<ToolButton>中</ToolButton>
|
||||
<ToolButton>高</ToolButton>
|
||||
<ToolButton>非常高</ToolButton>
|
||||
<ToolButton>推荐</ToolButton>
|
||||
<ToolButton
|
||||
onClick={() => {
|
||||
addToast({ title: "测试中 功能完成后可应用设置到游戏" })
|
||||
}}
|
||||
>
|
||||
<Plus />
|
||||
应用
|
||||
</ToolButton>
|
||||
</>
|
||||
)}
|
||||
<Tooltip content="功能测试中,尚未实装" showArrow={true} delay={300}>
|
||||
<ToolButton onClick={() => setEdit(!edit)}>
|
||||
{edit ? (
|
||||
<>
|
||||
@@ -94,85 +200,93 @@ const VideoSetting = () => {
|
||||
</>
|
||||
)}
|
||||
</ToolButton>
|
||||
<ToolButton onClick={() => setHide(!hide)}>
|
||||
{hide ? (
|
||||
<>
|
||||
<Up />
|
||||
显示
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Down />
|
||||
隐藏
|
||||
</>
|
||||
)}
|
||||
</ToolButton>
|
||||
</CardTool>
|
||||
</CardHeader>
|
||||
{!hide && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={{ duration: 0.2 }}
|
||||
</Tooltip>
|
||||
|
||||
<ToolButton
|
||||
onClick={() =>
|
||||
void tool.getVideoConfig(steam.state.steamDir, steam.currentUser()?.steam_id32 || 0)
|
||||
}
|
||||
>
|
||||
<CardBody>
|
||||
<ul className="flex flex-wrap gap-3 mt-1">
|
||||
<li className="flex flex-col gap-1.5">
|
||||
<span className="ml-2">分辨率</span>
|
||||
<span className="flex gap-3">
|
||||
<NumberInput
|
||||
aria-label="width"
|
||||
value={tool.state.videoSetting.width}
|
||||
onValueChange={(value) => {
|
||||
tool.setVideoSetting({
|
||||
...tool.state.videoSetting,
|
||||
width: value,
|
||||
})
|
||||
}}
|
||||
radius="full"
|
||||
step={10}
|
||||
className="max-w-28"
|
||||
classNames={{ inputWrapper: "h-10" }}
|
||||
/>
|
||||
<NumberInput
|
||||
aria-label="height"
|
||||
value={tool.state.videoSetting.height}
|
||||
onValueChange={(value) => {
|
||||
tool.setVideoSetting({
|
||||
...tool.state.videoSetting,
|
||||
height: value,
|
||||
})
|
||||
}}
|
||||
radius="full"
|
||||
step={10}
|
||||
className="max-w-28"
|
||||
classNames={{ inputWrapper: "h-10" }}
|
||||
/>
|
||||
</span>
|
||||
读取
|
||||
</ToolButton>
|
||||
<ToolButton onClick={() => setHide(!hide)}>
|
||||
{hide ? (
|
||||
<>
|
||||
<Up />
|
||||
显示
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Down />
|
||||
隐藏
|
||||
</>
|
||||
)}
|
||||
</ToolButton>
|
||||
</CardTool>
|
||||
</CardHeader>
|
||||
{!hide && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={{ duration: 0.2 }}
|
||||
>
|
||||
<CardBody>
|
||||
<ul className="flex flex-wrap gap-3 mt-1">
|
||||
<li className="flex flex-col gap-1.5">
|
||||
<span className="ml-2">分辨率</span>
|
||||
<span className="flex gap-3">
|
||||
<NumberInput
|
||||
aria-label="width"
|
||||
value={parseInt(tool.state.videoSetting.defaultres, 10)}
|
||||
onValueChange={(value) => {
|
||||
tool.setVideoSetting({
|
||||
...tool.state.videoSetting,
|
||||
defaultres: value.toString(),
|
||||
})
|
||||
}}
|
||||
radius="full"
|
||||
step={10}
|
||||
className="max-w-28"
|
||||
classNames={{ inputWrapper: "h-10" }}
|
||||
/>
|
||||
<NumberInput
|
||||
aria-label="height"
|
||||
value={parseInt(tool.state.videoSetting.defaultresheight, 10)}
|
||||
onValueChange={(value) => {
|
||||
tool.setVideoSetting({
|
||||
...tool.state.videoSetting,
|
||||
defaultresheight: value.toString(),
|
||||
})
|
||||
}}
|
||||
radius="full"
|
||||
step={10}
|
||||
className="max-w-28"
|
||||
classNames={{ inputWrapper: "h-10" }}
|
||||
/>
|
||||
</span>
|
||||
</li>
|
||||
{videoSettings.map((vid, index) => (
|
||||
<li className="flex flex-col gap-1.5" key={index}>
|
||||
<span className="ml-2">{vid.title}</span>
|
||||
<Tabs
|
||||
selectedKey={vid.value}
|
||||
size="md"
|
||||
radius="full"
|
||||
className="min-w-36"
|
||||
fullWidth
|
||||
>
|
||||
{vid.options.map((opt, _) => (
|
||||
<Tab key={opt} title={opt} />
|
||||
))}
|
||||
</Tabs>
|
||||
</li>
|
||||
{videoSettings.map((vid, index) => (
|
||||
<li className="flex flex-col gap-1.5" key={index}>
|
||||
<span className="ml-2">{vid.title}</span>
|
||||
<Tabs
|
||||
selectedKey={vid.value}
|
||||
size="md"
|
||||
radius="full"
|
||||
className="min-w-36"
|
||||
fullWidth
|
||||
>
|
||||
{vid.options.map((opt, _) => (
|
||||
<Tab key={opt} title={opt} />
|
||||
))}
|
||||
</Tabs>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</CardBody>
|
||||
</motion.div>
|
||||
)}
|
||||
</Card>
|
||||
</Tooltip>
|
||||
))}
|
||||
</ul>
|
||||
</CardBody>
|
||||
</motion.div>
|
||||
)}
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ import { store } from "@tauri-store/valtio"
|
||||
import { useSnapshot } from "valtio"
|
||||
import { DEFAULT_STORE_CONFIG } from "./config"
|
||||
import { emit } from "@tauri-apps/api/event"
|
||||
import { send } from "process"
|
||||
import { invoke } from "@tauri-apps/api/core"
|
||||
import { steamStore, useSteamStore } from "./steam"
|
||||
|
||||
interface LaunchOption {
|
||||
option: string
|
||||
@@ -10,22 +11,38 @@ interface LaunchOption {
|
||||
}
|
||||
|
||||
export interface VideoSetting {
|
||||
width: number; // 分辨率宽度
|
||||
height: number; // 分辨率高度
|
||||
version: string; // 版本
|
||||
vendor_id: string; // 供应商ID
|
||||
device_id: string; // 设备ID
|
||||
cpu_level: string; // CPU等级
|
||||
gpu_mem_level: string; // GPU内存等级
|
||||
gpu_level: string; // GPU等级
|
||||
knowndevice: string; // 已知设备
|
||||
defaultres: string; // 默认分辨率宽度
|
||||
defaultresheight: string; // 默认分辨率高度
|
||||
refreshrate_numerator: string; // 刷新率分子
|
||||
refreshrate_denominator: string; // 刷新率分母
|
||||
fullscreen: string; // 全屏
|
||||
vsync: string; // 垂直同步
|
||||
enhanceCharacterContrast: string; // 增强角色对比度
|
||||
cmaa2AntiAliasing: string; // CMAA2抗锯齿
|
||||
msaaAntiAliasing: string; // 多重采样抗锯齿
|
||||
globalShadowQuality: string; // 全局阴影效果
|
||||
dynamicShadows: string; // 动态阴影
|
||||
modelTextureDetail: string; // 模型/贴图细节
|
||||
textureFilteringMode: string; // 贴图过滤模式
|
||||
lightShadowDetail: string; // 光影细节
|
||||
particleDetail: string; // 粒子细节
|
||||
ambientOcclusion: string; // 环境光遮蔽
|
||||
hdr: string; // 高动态范围
|
||||
fidelityFxSuperResolution: string; // Fidelity FX 超级分辨率
|
||||
coop_fullscreen: string; // 合作模式全屏
|
||||
nowindowborder: string; // 无窗口边框
|
||||
mat_vsync: string; // 垂直同步
|
||||
fullscreen_min_on_focus_loss: string; // 失去焦点时最小化全屏
|
||||
high_dpi: string; // 高DPI
|
||||
auto_config: string; // 自动配置
|
||||
shaderquality: string; // 着色器质量
|
||||
r_texturefilteringquality: string; // 纹理过滤质量
|
||||
msaa_samples: string; // 多重采样抗锯齿样本数
|
||||
r_csgo_cmaa_enable: string; // CMAA抗锯齿启用
|
||||
videocfg_shadow_quality: string; // 阴影质量
|
||||
videocfg_dynamic_shadows: string; // 动态阴影
|
||||
videocfg_texture_detail: string; // 纹理细节
|
||||
videocfg_particle_detail: string; // 粒子细节
|
||||
videocfg_ao_detail: string; // 环境光遮蔽细节
|
||||
videocfg_hdr_detail: string; // 高动态范围细节
|
||||
videocfg_fsr_detail: string; // FSR细节
|
||||
monitor_index: string; // 显示器索引
|
||||
r_low_latency: string; // 低延迟
|
||||
aspectratiomode: string; // 宽高比模式
|
||||
}
|
||||
|
||||
const defaultValue = {
|
||||
@@ -37,8 +54,38 @@ const defaultValue = {
|
||||
launchIndex: 0,
|
||||
powerPlan: 0,
|
||||
videoSetting: {
|
||||
width: 1920,
|
||||
height: 1080
|
||||
version: "1.0",
|
||||
vendor_id: "0x0000",
|
||||
device_id: "0x0000",
|
||||
cpu_level: "3",
|
||||
gpu_mem_level: "3",
|
||||
gpu_level: "3",
|
||||
knowndevice: "Unknown",
|
||||
defaultres: "1920",
|
||||
defaultresheight: "1080",
|
||||
refreshrate_numerator: "144",
|
||||
refreshrate_denominator: "1",
|
||||
fullscreen: "1",
|
||||
coop_fullscreen: "0",
|
||||
nowindowborder: "1",
|
||||
mat_vsync: "0",
|
||||
fullscreen_min_on_focus_loss: "1",
|
||||
high_dpi: "0",
|
||||
auto_config: "2",
|
||||
shaderquality: "0",
|
||||
r_texturefilteringquality: "3",
|
||||
msaa_samples: "2",
|
||||
r_csgo_cmaa_enable: "0",
|
||||
videocfg_shadow_quality: "0",
|
||||
videocfg_dynamic_shadows: "1",
|
||||
videocfg_texture_detail: "1",
|
||||
videocfg_particle_detail: "0",
|
||||
videocfg_ao_detail: "0",
|
||||
videocfg_hdr_detail: "3",
|
||||
videocfg_fsr_detail: "0",
|
||||
monitor_index: "0",
|
||||
r_low_latency: "1",
|
||||
aspectratiomode: "0",
|
||||
} as VideoSetting,
|
||||
}
|
||||
|
||||
@@ -67,6 +114,7 @@ export const useToolStore = () => {
|
||||
setLaunchIndex,
|
||||
setPowerPlan,
|
||||
setVideoSetting,
|
||||
getVideoConfig,
|
||||
addLaunchOption,
|
||||
resetToolStore,
|
||||
}
|
||||
@@ -104,6 +152,12 @@ const setVideoSetting = (setting: VideoSetting) => {
|
||||
toolStore.state.videoSetting = setting
|
||||
}
|
||||
|
||||
const getVideoConfig = async (steam_dir: string, steam_id32: number) => {
|
||||
const video = await invoke<VideoSetting>("get_cs2_video_config", { steamDir: steam_dir, steamId32: steam_id32 })
|
||||
// console.log(video)
|
||||
setVideoSetting(video)
|
||||
}
|
||||
|
||||
const addLaunchOption = (option: LaunchOption) => {
|
||||
// 限制最高10个
|
||||
if (toolStore.state.launchOptions.length >= 10) {
|
||||
|
||||
Reference in New Issue
Block a user