Skip to content

Commit

Permalink
Add support for reading Starfield_<language>.INI
Browse files Browse the repository at this point in the history
The Windows language support is untested because I can't get MS Store
Starfield to use any language other than English.
  • Loading branch information
Ortham committed Sep 28, 2023
1 parent 424c2d1 commit 3f78bbe
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ regex = "1.0.0"
unicase = "2.0.0"
rayon = "1.0.0"
rust-ini = { version = "0.19.0", features = ["case-insensitive"] }
keyvalues-parser = "0.1.0"

[target.'cfg(windows)'.dependencies]
dirs = "5.0"
windows = { version = "0.51.1", features = ["Foundation_Collections", "System_UserProfile"] }

[dev-dependencies]
criterion = "0.5.1"
Expand Down
6 changes: 5 additions & 1 deletion ffi/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@ pub static LIBLO_ERROR_PANICKED: c_uint = 20;
#[no_mangle]
pub static LIBLO_ERROR_PATH_ENCODE_FAIL: c_uint = 21;

/// An unknown operating system error occurred.
#[no_mangle]
pub static LIBLO_ERROR_SYSTEM_ERROR: c_uint = 22;

/// Matches the value of the highest-numbered return code.
///
/// Provided in case clients wish to incorporate additional return codes in their implementation
/// and desire some method of avoiding value conflicts.
#[no_mangle]
pub static LIBLO_RETURN_MAX: c_uint = 21;
pub static LIBLO_RETURN_MAX: c_uint = 22;

/// The game handle is using the timestamp-based load order system. Morrowind, Oblivion, Fallout 3
/// and Fallout: New Vegas all use this system.
Expand Down
2 changes: 2 additions & 0 deletions ffi/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ fn map_error(err: &Error) -> c_uint {
UnrepresentedHoist { .. } => LIBLO_ERROR_INVALID_ARGS,
InstalledPlugin(_) => LIBLO_ERROR_INVALID_ARGS,
IniParsingError { .. } => LIBLO_ERROR_FILE_PARSE_FAIL,
VdfParsingError(_) => LIBLO_ERROR_FILE_PARSE_FAIL,
SystemError(_, _) => LIBLO_ERROR_SYSTEM_ERROR,
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use std::borrow::Cow;
use std::convert::From;
use std::error;
use std::ffi::OsString;
use std::fmt;
use std::io;
use std::path::PathBuf;
Expand Down Expand Up @@ -108,6 +109,8 @@ pub enum Error {
column: usize,
message: String,
},
VdfParsingError(String),
SystemError(i32, OsString),
}

impl From<io::Error> for Error {
Expand Down Expand Up @@ -166,6 +169,24 @@ impl From<ini::ParseError> for Error {
}
}

impl From<keyvalues_parser::error::Error> for Error {
fn from(error: keyvalues_parser::error::Error) -> Self {
match error {
keyvalues_parser::error::Error::ParseError(e) => Error::VdfParsingError(e.to_string()),
keyvalues_parser::error::Error::InvalidTokenStream(c) => {
Error::VdfParsingError(c.to_string())
}
}
}
}

#[cfg(windows)]
impl From<windows::core::Error> for Error {
fn from(error: windows::core::Error) -> Self {
Error::SystemError(error.code().0, error.message().to_os_string())
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Expand Down Expand Up @@ -231,6 +252,8 @@ impl fmt::Display for Error {
"Failed to parse ini file, error at line {}, column {}: {}",
line, column, message
),
Error::VdfParsingError(ref message) => write!(f, "Failed to parse VDF file: {}", message),
Error::SystemError(code, ref message) => write!(f, "Error returned by the operating system, code {}: {:?}", code, message),
}
}
}
Expand Down
Loading

0 comments on commit 3f78bbe

Please sign in to comment.