diff --git a/owmods_core/src/analytics.rs b/owmods_core/src/analytics.rs index 57fd6a558..639ad9c9f 100644 --- a/owmods_core/src/analytics.rs +++ b/owmods_core/src/analytics.rs @@ -71,7 +71,7 @@ impl AnalyticsPayload { // Note how this function doesn't return a result, it shouldn't. We want to simply move on if we can't // send an event because it's not the end of the world. -/// Send an analytics event with the given `event_name` for the given mod's `unique_name` +/// Send an analytics event with the given [AnalyticsEventName] for the given mod's `unique_name` /// /// **Please note that unless an `ANALYTICS_API_KEY` env variable is specified at build time this function does nothing.** pub async fn send_analytics_event(event_name: AnalyticsEventName, unique_name: &str) { diff --git a/owmods_core/src/config.rs b/owmods_core/src/config.rs index 4152d053a..bcd62f21a 100644 --- a/owmods_core/src/config.rs +++ b/owmods_core/src/config.rs @@ -75,6 +75,7 @@ impl Config { } /// Set that a specific mod's warning was shown. + /// (Doesn't save the config, you have to do that yourself) pub fn set_warning_shown(&mut self, unique_name: &str) { self.viewed_alerts.push(unique_name.to_string()); } @@ -98,7 +99,7 @@ impl Config { /// /// ## Returns /// - /// The newly created or loaded config. + /// The newly created or loaded [Config]. /// /// ## Errors /// diff --git a/owmods_core/src/download.rs b/owmods_core/src/download.rs index 7734e318d..dcb2de012 100644 --- a/owmods_core/src/download.rs +++ b/owmods_core/src/download.rs @@ -207,7 +207,7 @@ fn extract_mod_zip( } } -/// Downloads and install OWML to the path specified in config.owml_path +/// Downloads and installs OWML to the path specified in `config.owml_path` /// /// ## Errors /// @@ -249,7 +249,7 @@ pub async fn download_and_install_owml( /// /// ## Returns /// -/// The newly installed LocalMod +/// The newly installed [LocalMod] /// /// ## Errors /// @@ -320,7 +320,7 @@ pub fn install_mod_from_zip( /// /// ## Returns /// -/// The newly installed local mod +/// The newly installed [LocalMod] /// /// ## Errors /// @@ -357,7 +357,7 @@ pub async fn install_mod_from_url( /// /// ## Errors /// -/// If __any__ mod fails to install from the list +/// If **any** mod fails to install from the list /// pub async fn install_mods_parallel( unique_names: Vec, @@ -396,7 +396,7 @@ pub async fn install_mods_parallel( /// /// - If you requested a prerelease and the mod doesn't have one. /// - If we can't install the target mod for any reason. -/// - If we can't install __any__ dependencies for any reason. +/// - If we can't install **any** dependencies for any reason. /// pub async fn install_mod_from_db( unique_name: &String, @@ -406,7 +406,13 @@ pub async fn install_mod_from_db( recursive: bool, prerelease: bool, ) -> Result<()> { - let already_installed = local_db.get_mod(unique_name).is_some(); + let existing_mod = local_db.get_mod(unique_name); + + let already_installed = existing_mod.is_some(); + let existing_version = existing_mod + .as_ref() + .map(|m| m.manifest.version.clone()) + .unwrap_or_default(); let remote_mod = remote_db .get_mod(unique_name) @@ -489,7 +495,11 @@ pub async fn install_mod_from_db( let mod_event = if prerelease { AnalyticsEventName::ModPrereleaseInstall } else if already_installed { - AnalyticsEventName::ModReinstall + if existing_version == new_mod.manifest.version { + AnalyticsEventName::ModReinstall + } else { + AnalyticsEventName::ModUpdate + } } else { AnalyticsEventName::ModInstall }; diff --git a/owmods_core/src/game.rs b/owmods_core/src/game.rs index 00f33e2e6..d196811a7 100644 --- a/owmods_core/src/game.rs +++ b/owmods_core/src/game.rs @@ -10,6 +10,11 @@ use crate::{config::Config, constants::OWML_EXE_NAME, owml::OWMLConfig}; /// If no port is given, the output of OWML.Launcher.exe will be written to stdout. /// You can set `open_in_new_window` to `true` to make the command open in a new cmd window (**Windows Only**). /// On Linux there's no reliable way to open a new terminal window, so it's recommended you disallow that arg to be false on linux. +/// +/// ## Errors +/// +/// If we can't launch the game/OWML, if we can't start a log server, or if we can't read the config. +/// pub async fn launch_game( config: &Config, open_in_new_window: bool, diff --git a/owmods_core/src/io.rs b/owmods_core/src/io.rs index 0fce8629d..4a6dbf8a6 100644 --- a/owmods_core/src/io.rs +++ b/owmods_core/src/io.rs @@ -26,9 +26,9 @@ pub fn export_mods(db: &LocalDatabase) -> Result { Ok(result) } -/// Import mods from a JSON file that contains an array or unique name (like the one exported by `export_mods`). +/// Import mods from a JSON file that contains an array or unique name (like the one exported by [export_mods]). /// Mods that aren't in the remote database will be ignored and will only log a warning. -/// Optionally this can also disable all current mods not found in this list as well. +/// Optionally, this can also disable all current mods not found in this list. /// /// ## Errors /// diff --git a/owmods_core/src/mods/local.rs b/owmods_core/src/mods/local.rs index 67cf28576..b0c9e15d8 100644 --- a/owmods_core/src/mods/local.rs +++ b/owmods_core/src/mods/local.rs @@ -97,6 +97,7 @@ impl UnsafeLocalMod { } /// Gets the path for a mod + /// This is the same for [UnsafeLocalMod::Valid] and [UnsafeLocalMod::Invalid] pub fn get_path(&self) -> &str { match self { Self::Invalid(m) => &m.mod_path, diff --git a/owmods_core/src/open.rs b/owmods_core/src/open.rs index 360466942..9cd8e2378 100644 --- a/owmods_core/src/open.rs +++ b/owmods_core/src/open.rs @@ -44,7 +44,7 @@ pub fn open_shortcut(identifier: &str, conf: &Config, local_db: &LocalDatabase) /// /// ## Errors /// -/// If the unique name provided is not an installed mod +/// If the unique name provided is not an installed mod or we can't open the browser. /// pub fn open_readme(unique_name: &str, db: &RemoteDatabase) -> Result<()> { let remote_mod = db diff --git a/owmods_core/src/owml.rs b/owmods_core/src/owml.rs index d49d0bb00..6f498fc1a 100644 --- a/owmods_core/src/owml.rs +++ b/owmods_core/src/owml.rs @@ -18,7 +18,7 @@ use crate::{ #[typeshare] #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -#[allow(non_snake_case)] // Have to allow non_snake_case here because OWML's config uses incrementalGC, which isn't proper camelCase +#[allow(non_snake_case)] // Have to allow non_snake_case here because OWML's config uses "incrementalGC", which isn't proper camelCase pub struct OWMLConfig { pub game_path: String, debug_mode: bool, @@ -65,6 +65,12 @@ impl OWMLConfig { serialize_to_json(self, path, true) } + /// Get the default OWML config (OWML.DefaultConfig.json) + /// + /// ## Errors + /// + /// If we can't read the default config or can't get the user data dir. (Linux only) + /// #[cfg(not(windows))] pub fn default(config: &Config) -> Result { use anyhow::anyhow; @@ -84,6 +90,12 @@ impl OWMLConfig { Ok(conf) } + /// Get the default OWML config (OWML.DefaultConfig.json) + /// + /// ## Errors + /// + /// If we can't read the default config or can't get the user data dir. (Linux only) + /// #[cfg(windows)] pub fn default(config: &Config) -> Result { deserialize_from_json(&Path::new(&config.owml_path).join(OWML_DEFAULT_CONFIG_NAME)) diff --git a/owmods_core/src/remove.rs b/owmods_core/src/remove.rs index 3e46067fb..ea9445c05 100644 --- a/owmods_core/src/remove.rs +++ b/owmods_core/src/remove.rs @@ -16,7 +16,8 @@ use crate::{ /// /// ## Returns /// -/// A `Vec` of mods that have pre-patchers and need to have a warning shown to the user +/// A `Vec` of mods that have pre-patchers +/// and thus **should have a warning shown to the user telling them to check the mod's README for instructions** /// /// ## Errors /// @@ -55,7 +56,7 @@ pub fn remove_mod( /// /// ## Errors /// -/// If we can't delete the folder +/// If we can't delete the folder the mod was in. /// pub fn remove_failed_mod(failed_mod: &FailedMod) -> Result<()> { remove_dir_all(PathBuf::from(&failed_mod.mod_path))?; @@ -63,6 +64,13 @@ pub fn remove_failed_mod(failed_mod: &FailedMod) -> Result<()> { } /// Removes all files not specified in `pathsToPreserve` +/// +/// See [get_paths_to_preserve] to see implicit paths to preserve +/// +/// ## Errors +/// +/// If we can't delete the files +/// pub fn remove_old_mod_files(local_mod: &LocalMod) -> Result<()> { let glob_matches = glob( PathBuf::from(&local_mod.mod_path) diff --git a/owmods_core/src/search.rs b/owmods_core/src/search.rs index 8e0c6d855..b2f6d8fd9 100644 --- a/owmods_core/src/search.rs +++ b/owmods_core/src/search.rs @@ -1,7 +1,18 @@ +/// Represents an object that can be searched pub trait Searchable { + /// Get the values that can be searched + /// Each value will be weighted based on its position in the list (first is most important) fn get_values(&self) -> Vec; } +/// Search a list of [Searchable] for a string +/// This will return a list of the items that match the search, sorted by relevance +/// Relevance is determined like so: +/// - If the search is an exact match for a value, that value will be weighted 2x +/// - If the search is contained in a value, that value will be weighted 1x +/// - If the search is not contained in a value, that value will be weighted 0x +/// The score is then also weighted by the position of the value in the list the [Searchable] (first is most important) +/// These scores are then summed and the list is sorted by the total score of each item pub fn search_list<'a, T>(source_list: Vec<&'a T>, filter: &str) -> Vec<&'a T> where T: Searchable, diff --git a/owmods_core/src/socket.rs b/owmods_core/src/socket.rs index 329016336..8f15e4014 100644 --- a/owmods_core/src/socket.rs +++ b/owmods_core/src/socket.rs @@ -89,7 +89,7 @@ impl LogServer { /// /// ## Returns /// - /// A new log server that's bound to the given port, **but not ready to listen to logs**. + /// A new log server that's bound to the given port, **but not ready to listen to** logs. /// /// ## Errors /// @@ -156,7 +156,7 @@ impl LogServer { // Loop that runs on start, listens for clients to connect // Makes a new client_loop for each client - pub async fn server_loop( + async fn server_loop( &self, tx: &LogServerSender, shutdown_sender: mpsc::Sender<()>, diff --git a/owmods_core/src/validate.rs b/owmods_core/src/validate.rs index f74de80cc..6aa7bbcb2 100644 --- a/owmods_core/src/validate.rs +++ b/owmods_core/src/validate.rs @@ -76,10 +76,8 @@ fn check_mod_conflicts(local_mod: &LocalMod, db: &LocalDatabase) -> Vec