Skip to content

Commit

Permalink
v0.0.9
Browse files Browse the repository at this point in the history
- Implement Winch config options in the settings menu
- Update Winch uninstall logic for version 0.3.1
- Fixed sidebar width changing, reload info when changing pages
  • Loading branch information
xen-42 authored Dec 27, 2023
2 parents 0377fbf + 9aa2c63 commit c923888
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dredge_mod_manager",
"private": true,
"version": "0.0.8",
"version": "0.0.9",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dredge_mod_manager"
version = "0.0.8"
version = "0.0.9"
description = "Mod manager application for DREDGE"
authors = ["xen-42"]
license = "MIT"
Expand Down
31 changes: 28 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use tauri::{Manager, PhysicalSize};
mod database;
mod mods;
mod files;
mod winch_config;

#[derive(serde::Serialize)]
#[serde(rename_all(serialize = "PascalCase"))]
Expand All @@ -25,7 +26,9 @@ struct InitialInfo {
mods : HashMap<String, mods::ModInfo>,
database: Vec<database::ModDatabaseInfo>,
#[serde(serialize_with = "serialize_mod_info_option")]
winch_mod_info : Option<mods::ModInfo>
winch_mod_info : Option<mods::ModInfo>,
#[serde(serialize_with = "serialize_winch_config_option")]
winch_config : Option<winch_config::WinchConfig>
}

fn serialize_mod_info_option<S>(maybe_mod_info : &Option<mods::ModInfo>, serializer : S) -> Result<S::Ok, S::Error> where S : Serializer {
Expand All @@ -35,6 +38,13 @@ fn serialize_mod_info_option<S>(maybe_mod_info : &Option<mods::ModInfo>, seriali
}
}

fn serialize_winch_config_option<S>(maybe_winch_config : &Option<winch_config::WinchConfig>, serializer : S) -> Result<S::Ok, S::Error> where S : Serializer {
match maybe_winch_config {
Some(winch_config) => serializer.serialize_some(winch_config),
None => serializer.serialize_none()
}
}

#[derive(serde::Serialize)]
struct InitialInfoError {
error_code : ErrorCode,
Expand Down Expand Up @@ -132,7 +142,13 @@ fn load(dredge_path : String) -> Result<InitialInfo, InitialInfoError> {
Err(_) => None
};

Ok(InitialInfo {enabled_mods, mods, database, winch_mod_info})
// Get Winch config
let winch_config = match winch_config::load_winch_config(dredge_path) {
Ok(config) => Some(config),
Err(_) => None
};

Ok(InitialInfo {enabled_mods, mods, database, winch_mod_info, winch_config})
}

fn check_enabled_mods(enabled_mods_path : String) -> HashMap<String, bool> {
Expand Down Expand Up @@ -255,6 +271,14 @@ fn open_dir(path : String) -> Result<(), String> {
}
}

#[tauri::command]
fn update_winch_config(json : String, dredge_path : String) -> Result<(), String> {
match winch_config::write_winch_config(json, dredge_path) {
Ok(_) => return Ok(()),
Err(error) => return Err(error)
}
}

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
Expand All @@ -265,7 +289,8 @@ fn main() {
start_game,
uninstall_mod,
install_mod,
open_dir
open_dir,
update_winch_config
])
.setup(|app| {
let main_window: tauri::Window = app.get_window("main").unwrap();
Expand Down
23 changes: 17 additions & 6 deletions src-tauri/src/mods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,23 @@ pub fn uninstall_mod(mod_meta_path : String) -> () {
let dir = Path::new(&mod_meta_path).parent().unwrap();

if mod_meta.mod_guid == "hacktix.winch" {
fs::remove_file(format!("{}/0Harmony.dll", dir.display().to_string())).unwrap();
fs::remove_file(format!("{}/doorstop_config.ini", dir.display().to_string())).unwrap();
fs::remove_file(&mod_meta_path).unwrap();
fs::remove_file(format!("{}/Winch.dll", dir.display().to_string())).unwrap();
fs::remove_file(format!("{}/winhttp.dll", dir.display().to_string())).unwrap();
fs::remove_file(format!("{}/asset_update_date.txt", dir.display().to_string())).unwrap();
// using "let _ =" allows us to ignore any errors
let _ = fs::remove_file(format!("{}/0Harmony.dll", dir.display().to_string()));
let _ = fs::remove_file(format!("{}/doorstop_config.ini", dir.display().to_string()));
let _ = fs::remove_file(&mod_meta_path);

let _ = fs::remove_file(format!("{}/Winch.dll", dir.display().to_string()));
let _ = fs::remove_file(format!("{}/Winch.pdb", dir.display().to_string()));

let _ = fs::remove_file(format!("{}/WinchCommon.dll", dir.display().to_string()));
let _ = fs::remove_file(format!("{}/WinchCommon.pdb", dir.display().to_string()));

let _ = fs::remove_file(format!("{}/WinchConsole.exe", dir.display().to_string()));
let _ = fs::remove_file(format!("{}/WinchConsole.exe.config", dir.display().to_string()));
let _ = fs::remove_file(format!("{}/WinchConsole.pdb", dir.display().to_string()));

let _ = fs::remove_file(format!("{}/winhttp.dll", dir.display().to_string()));
let _ = fs::remove_file(format!("{}/asset_update_date.txt", dir.display().to_string()));
}
else {
if dir.is_dir() && dir.is_absolute() && dir.parent().unwrap().display().to_string().ends_with("Mods") {
Expand Down
64 changes: 64 additions & 0 deletions src-tauri/src/winch_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::fs;
use serde_json::Result as SerdeResult;

#[derive(serde::Serialize, serde::Deserialize)]
#[serde(rename_all(serialize = "UPPERCASE"))]
#[derive(Default)]
pub enum LogLevel {
UNITY,
DEBUG,
#[default]
INFO,
WARN,
ERROR
}

#[derive(serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct WinchConfig {
#[serde(default)]
pub write_logs_to_file : bool,

#[serde(default)]
pub write_logs_to_console : bool,

#[serde(default)]
pub logs_folder : String,

#[serde(default)]
pub log_level : LogLevel,

#[serde(default)]
pub detailed_log_sources : bool,

#[serde(default)]
pub enable_developer_console : bool,

#[serde(default)]
pub max_log_files : i32,

#[serde(default)]
pub log_port : String
}

pub fn load_winch_config(dredge_folder : String) -> Result<WinchConfig, String> {
let file = format!("{}/WinchConfig.json", dredge_folder);
let winch_config_string = match fs::read_to_string(&file) {
Ok(v) => v,
Err(_) => return Err(format!("Couldn't find WinchConfig at {}", file).to_string())
};
let json = match serde_json::from_str(&winch_config_string) as SerdeResult<WinchConfig> {
Ok(v) => v,
Err(e) => return Err(format!("Couldn't load mod WinchConfig at {} - {}", file, e.to_string()).to_string())
};

Ok(json)
}

pub fn write_winch_config(json : String, dredge_folder : String) -> Result<(), String> {
let file = format!("{}/WinchConfig.json", dredge_folder);
match fs::write(file.to_string(), json.to_string()) {
Ok(_) => return Ok(()),
Err(_) => return Err(format!("Couldn't save WinchConfig at {} with settings {}", file, json).to_string())
};
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "Dredge Mod Manager",
"version": "0.0.8"
"version": "0.0.9"
},
"tauri": {
"allowlist": {
Expand Down
11 changes: 11 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { debounce } from "lodash";

import { Sidebar, Content } from './components';
import { ModInfo, AppProvider, AppContext } from './components';
import { WinchConfig } from "./components/winchconfig";


export interface IAppState extends React.PropsWithChildren{
pathCorrect: boolean | undefined; // no clue
dredgePath: string | undefined;
winchInfo: ModInfo | undefined;
winchConfig : WinchConfig | undefined;
availableMods: [] | undefined; // All mods in database
enabledMods: IEnabledStruct | undefined; // All mods enabled
modInfos: Map<string, ModInfo> | undefined; // All installed mods
Expand All @@ -38,6 +40,7 @@ class App extends Component<{}, IAppState>
pathCorrect: undefined,
dredgePath: undefined,
winchInfo: undefined,
winchConfig : undefined,
availableMods: [],
enabledMods: undefined,
modInfos: new Map(),
Expand Down Expand Up @@ -98,6 +101,7 @@ class App extends Component<{}, IAppState>
modInfos: new Map(Object.entries(fetch.mods)),
availableMods: fetch.database.map((mod : ModInfo) => mod.ModGUID).filter((modGUID: string) => !fetch.mods.hasOwnProperty(modGUID)),
winchInfo: fetch.winch_mod_info,
winchConfig: fetch.winch_config,
pathCorrect: true,
}, () => {console.log(this.state); return});

Expand Down Expand Up @@ -170,6 +174,12 @@ class App extends Component<{}, IAppState>
.catch((e) => alert(e.toString()))
}

update_winch_config() {
console.log(this.state.winchConfig);
invoke("update_winch_config", {"json": JSON.stringify(this.state.winchConfig, null, 2), dredgePath: this.state.dredgePath})
.then(this.reload_mods)
.catch((error : any) => alert(error.toString()));
}

// Inbuilt React

Expand Down Expand Up @@ -210,6 +220,7 @@ class App extends Component<{}, IAppState>

set_page_choice(choice: string) {
this.setState({pageChoice: choice});
this.reload_mods();
}


Expand Down
76 changes: 74 additions & 2 deletions src/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import App from '../App'
import { debounce } from 'lodash';

import { getVersion } from '@tauri-apps/api/app';
import { WinchConfig } from './winchconfig'
const appVersion = await getVersion();

interface ISettingsState {
Expand All @@ -28,6 +29,16 @@ export default class Settings extends Component<{path_correct: boolean | undefin
this.debounce_on_path_update = this.debounce_on_path_update.bind(this);
this.on_update = this.on_update.bind(this);
this.handle_path_button = this.handle_path_button.bind(this);
this.onUpdateWinchConfig = this.onUpdateWinchConfig.bind(this);
}

onUpdateWinchConfig(prop : string, state : any) {
// Unsafe but oh well
var config : any = (this.context as App).state.winchConfig;

config[prop] = state;

(this.context as App).update_winch_config();
}

componentDidMount() {
Expand Down Expand Up @@ -78,12 +89,71 @@ export default class Settings extends Component<{path_correct: boolean | undefin
dredgeFolderButton = "";
}

var config:WinchConfig|undefined = (this.context as App).state.winchConfig;

var configOptions:JSX.Element | string;
if (config) {
configOptions = <div className="w-100">
<h5 className="d-flex justify-content-center">
Winch Modloader Settings
</h5>
<div className="w-100">

<input
id="enable-developer-console"
name="enable-developer-console"
type="checkbox"
checked={config.EnableDeveloperConsole}
onChange={(e) => {this.onUpdateWinchConfig("EnableDeveloperConsole", e.target.checked)}}
/>
<label htmlFor="enable-developer-console">Enable In-Game Developer Console</label>

<br/>

<input
id="detailed-log-sources"
name="detailed-log-sources"
type="checkbox"
checked={config.DetailedLogSources}
onChange={(e) => {this.onUpdateWinchConfig("DetailedLogSources", e.target.checked)}}
/>
<label htmlFor="detailed-log-sources">Use Detailed Log Sources</label>

<br/>

<input
id="write-logs-to-file"
name="write-logs-to-file"
type="checkbox"
checked={config.WriteLogsToFile}
onChange={(e) => {this.onUpdateWinchConfig("WriteLogsToFile", e.target.checked)}}
/>
<label htmlFor="write-logs-to-file">Write Logs to File</label>

<br/>

<input
id="write-logs-to-console"
name="write-logs-to-console"
type="checkbox"
checked={config.WriteLogsToConsole}
onChange={(e) => {this.onUpdateWinchConfig("WriteLogsToConsole", e.target.checked)}}
/>
<label htmlFor="write-logs-to-console">Write Logs to Console</label>

</div>
</div>
}
else {
configOptions = "";
}

return (
<div className="settings-container">
<div className="setting d-flex h-100">
<label>
<h5>
DREDGE Install Location
</label>
</h5>
<div className="path">
<input
id="setting-path-input"
Expand All @@ -96,6 +166,8 @@ export default class Settings extends Component<{path_correct: boolean | undefin
</div>
{pathWarning}
{dredgeFolderButton}
<br/>
{configOptions}

<div className="flex-fill"></div>

Expand Down
18 changes: 18 additions & 0 deletions src/components/winchconfig.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export enum LogLevel {
UNITY,
DEBUG,
INFO,
WARN,
ERROR
}

export interface WinchConfig {
WriteLogsToFile : boolean,
WriteLogsToConsole : boolean,
LogLevel : LogLevel,
LogsFolder : string,
DetailedLogSources : boolean,
EnableDeveloperConsole : boolean,
MaxLogFiles : number,
LogPort: string
}
Loading

0 comments on commit c923888

Please sign in to comment.