Skip to content

Commit

Permalink
0.1.5 (#69)
Browse files Browse the repository at this point in the history
- Added an option to run from EXE directly (fixes GOG issues)
- No longer have to run the game with Winch once to have default Winch
settings
  • Loading branch information
xen-42 authored Jan 5, 2025
2 parents b579d20 + fb0e81a commit 3dc4452
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 21 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.1.4",
"version": "0.1.5",
"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.1.4"
version = "0.1.5"
description = "Mod manager application for DREDGE"
authors = ["xen-42"]
license = "MIT"
Expand Down
58 changes: 51 additions & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap, path::PathBuf, path::Path};
use std::fs;
use std::process::Command;
use serde::Serializer;
use serde_json::Result as SerdeResult;
use tauri::{Manager, PhysicalSize};
use winch_config::{write_winch_config, WinchConfig};
mod database;
mod mods;
mod files;
Expand Down Expand Up @@ -66,6 +67,33 @@ fn load_dredge_path() -> Result<String, String> {
Ok(dredge_path)
}

#[tauri::command]
fn make_default_winch_config(dredge_path : String) -> WinchConfig {
match winch_config::load_winch_config(dredge_path.to_string()) {
Ok(config) => return config,
Err(_) => {
let new_winch_config: WinchConfig = WinchConfig {
write_logs_to_file: true,
write_logs_to_console: false,
log_level: winch_config::LogLevel::DEBUG,
logs_folder: "Logs".to_string(),
detailed_log_sources: false,
enable_developer_console: true,
max_log_files: 10,
log_port: "".to_string(),
run_exe: false
};
match serde_json::to_string_pretty(&new_winch_config) {
Ok(json) => {
let _ = winch_config::write_winch_config(json, dredge_path);
},
Err(_) => {}
};
return new_winch_config;
}
};
}

#[tauri::command]
fn load(dredge_path : String) -> Result<InitialInfo, InitialInfoError> {
// Validate that the folder path is correct
Expand Down Expand Up @@ -178,6 +206,7 @@ fn dredge_path_changed(path: String) -> Result<(), String> {

let folder: String = files::get_local_dir()?;
let file: String = format!("{}/data.txt", folder);

if !fs::metadata(&folder).is_ok() {
match fs::create_dir_all(&folder) {
Ok(_) => (),
Expand Down Expand Up @@ -231,15 +260,29 @@ fn write_enabled_mods(json : HashMap<String, bool>, enabled_mods_path : String)
fn start_game(dredge_path : String) -> Result<(), String> {
let is_windows = cfg!(windows);

let mut run_exe = false;
match winch_config::load_winch_config(dredge_path.to_string()) {
Ok(config) => run_exe = config.run_exe,
Err(_) => ()
};

if is_windows {
match Command::new(format!("{}/WinchLauncher.exe", dredge_path)).spawn() {
Ok(_) => return Ok(()),
// Fallback to just using the exe if it fails spectacularly
Err(_) => match Command::new(format!("{}/DREDGE.exe", dredge_path)).spawn() {
if Path::new(&format!("{}/WinchLauncher.exe", dredge_path)).exists() && !run_exe {
match Command::new(format!("{}/WinchLauncher.exe", dredge_path)).spawn() {
Ok(_) => return Ok(()),
// Fallback to just using the exe if it fails spectacularly
Err(_) => match Command::new(format!("{}/DREDGE.exe", dredge_path)).spawn() {
Ok(_) => return Ok(()),
Err(_) => return Err("Failed to start DREDGE.exe. Is the game directory correct?".to_string())
}
}
}
else {
match Command::new(format!("{}/DREDGE.exe", dredge_path)).spawn() {
Ok(_) => return Ok(()),
Err(_) => return Err("Failed to start DREDGE.exe. Is the game directory correct?".to_string())
}
}
}
}
else {
// TODO: Make linux work with WinchLauncher
Expand Down Expand Up @@ -304,7 +347,8 @@ fn main() {
uninstall_mod,
install_mod,
open_dir,
update_winch_config
update_winch_config,
make_default_winch_config
])
.setup(|app| {
let main_window: tauri::Window = app.get_window("main").unwrap();
Expand Down
5 changes: 4 additions & 1 deletion src-tauri/src/winch_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ pub struct WinchConfig {
pub max_log_files : i32,

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

#[serde(default)]
pub run_exe : bool
}

pub fn load_winch_config(dredge_folder : String) -> Result<WinchConfig, String> {
Expand Down
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.1.4"
"version": "0.1.5"
},
"tauri": {
"allowlist": {
Expand Down
10 changes: 9 additions & 1 deletion src/components/appcontext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {genericHandleError} from "../util/genericHandleError";
import {ModInfo} from "./modinfo";
import {open} from "@tauri-apps/api/dialog";
import {debounce} from "lodash";
import { WinchConfig } from './winchconfig';

interface IAppContextType { // see AppProvider for implementations, defaultContext for initialized defaults
state: IAppState;
Expand Down Expand Up @@ -99,13 +100,20 @@ export const AppProvider = (props: React.PropsWithChildren) => {
}
})

let winchConfig = fetch.winch_config;
if (winchConfig == undefined) {
invoke("make_default_winch_config", { dredgePath : state.dredgePath }).then((winch_config) => {
winchConfig = winch_config
}).catch();
}

setState({...state,
enabledMods: fetch.enabled_mods,
database: fetch.database,
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,
winchConfig: winchConfig,
pathCorrect: true
});
}).catch((error: { error_code : string, message : string }) => {
Expand Down
11 changes: 6 additions & 5 deletions src/components/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const Settings = (props: {path_correct?: boolean}) => {

const config = context!.state.winchConfig;

const configOptions = <div className={"w-100 flex-column"}>
const configOptions = !props.path_correct ? "" : <div className={"w-100 flex-column"}>
<h5 className="d-flex justify-content-center">
Winch Modloader Settings
</h5>
Expand All @@ -102,6 +102,10 @@ export const Settings = (props: {path_correct?: boolean}) => {
label={"Write logs to console"}
checked={config?.WriteLogsToConsole ?? false}
onUpdate={onConfigUpdate} />
<BooleanConfig id={"RunExe"}
label={"Run the exe directly instead of via Steam/Epic (might be required for GOG)"}
checked={config?.RunExe ?? false}
onUpdate={onConfigUpdate} />
</div>
</div>

Expand All @@ -126,10 +130,7 @@ export const Settings = (props: {path_correct?: boolean}) => {
{pathWarning}
{dredgeFolderButton}
<br/>
{config ? configOptions : <span>
<i className="fa-solid fa-triangle-exclamation warning"></i>
<i> Run DREDGE with the Winch modloader at least once to enable settings.</i>
</span>}
{configOptions}

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

Expand Down
3 changes: 2 additions & 1 deletion src/components/winchconfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export interface WinchConfig {
DetailedLogSources : boolean,
EnableDeveloperConsole : boolean,
MaxLogFiles : number,
LogPort: string
LogPort: string,
RunExe : boolean
}

0 comments on commit 3dc4452

Please sign in to comment.