Skip to content

Commit

Permalink
Bump version and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
theRookieCoder committed Feb 22, 2024
1 parent 6aa3fe7 commit 841c446
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 23 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Changelog for Libium

## `1.26.0`
### 22.02.2024

- Replace `Option<bool>` with `bool` for whether or not to check game version or mod loader
- Added `ModIdentifierRef` and `ModIdentifier.as_ref()` for comparing mod identifiers without cloning
- Replaced many procedural loops with functional alternatives
- Added `Profile.get_version(check_game_version)` and `Profile.get_loader(check_mod_loader)` to replace this common pattern:
```rs
if check_(game_version | mod_loader) {
Some(&profile.(game_version | mod_loader))
} else {
None
}
```
- Use the `game_versions` and `loaders` specified in the Modrinth `Project` struct instead of using version resolution
- Only use `.to_string()` instead of `.into<String>()` when converting a value to a `String`
- Replace `config::file_path()` with `DEFAULT_CONFIG_PATH` which uses `Lazy`
- Extract the file opening to `open_config_file()`
- Move `config::read_file()` to `read_wrapper()` since it is not specific to the `config` module
- Derive and use `Default` for the `config::Config` when creating an empty config
- Skip serialising the active index and profiles/modpacks vectors if they're zero or empty
- Remove the `Option` in `check_game_version` and `check_mod_loader` fields for `Mod`
- Replace `TryFrom<&str>` with `FromStr` for `ModLoader`
- Derive `Copy` for `ModLoader`
- Determine `get_minecraft_dir()` at compile-time
- Set the UNIX permissions when compressing a directory
- Replace `curseforge::read_manifest_file()` and `modrinth::read_metadata_file()` with `read_file_from_zip()`
- Refactor `upgrade::check` to make it more readable
- Remove the subdirectory classification done when converting to a `Downloadable`, modpack installers can do this manually

## `1.25.0`
### 07.02.2024

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libium"
version = "1.25.0"
version = "1.26.0"
edition = "2021"
authors = [
"Ilesh Thiada (theRookieCoder) <ileshkt@gmail.com>",
Expand Down
9 changes: 4 additions & 5 deletions src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,11 @@ pub async fn modrinth(
Err(Error::NotAMod)

// Check if the project is compatible
} else if perform_checks
&& game_version_check(
} else if !perform_checks // Short circuit if the checks should not be performed
|| (game_version_check(
profile.get_version(check_game_version),
&project.game_versions,
)
&& mod_loader_check(profile.get_loader(check_mod_loader), &project.loaders)
) && mod_loader_check(profile.get_loader(check_mod_loader), &project.loaders))
{
// Add it to the profile
profile.mods.push(Mod {
Expand Down Expand Up @@ -214,7 +213,7 @@ pub async fn curseforge(

// Add it to the profile
profile.mods.push(Mod {
name: project.name.trim().into(),
name: project.name.trim().to_string(),
identifier: ModIdentifier::CurseForgeProject(project.id),
check_game_version,
check_mod_loader,
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub static DEFAULT_CONFIG_PATH: Lazy<PathBuf> = Lazy::new(|| {
.join("config.json")
});

pub async fn open_config_file(path: &Path) -> Result<File> {
async fn open_config_file(path: &Path) -> Result<File> {
OpenOptions::new()
.read(true)
.write(true)
Expand Down
2 changes: 2 additions & 0 deletions src/config/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct Profile {
}

impl Profile {
// Return the profile's `game_version` in `Some` if `check_game_version` is true
pub fn get_version(&self, check_game_version: bool) -> Option<&str> {
if check_game_version {
Some(&self.game_version)
Expand All @@ -62,6 +63,7 @@ impl Profile {
}
}

// Return the profile's `mod_loader` in a `Some` only if `check_mod_loader` is true
pub fn get_loader(&self, check_mod_loader: bool) -> Option<ModLoader> {
if check_mod_loader {
Some(self.mod_loader)
Expand Down
8 changes: 6 additions & 2 deletions src/modpack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use async_zip::{
tokio::{read::seek::ZipFileReader, write::ZipFileWriter},
Compression, ZipEntryBuilder,
};
use std::{fs::read_dir, os::unix::fs::MetadataExt, path::Path};
use std::{fs::read_dir, path::Path};
use tokio::{
fs::{canonicalize, create_dir_all, metadata, read, File},
io::{copy, AsyncRead, AsyncSeek, AsyncWrite},
Expand Down Expand Up @@ -77,7 +77,11 @@ pub async fn compress_dir<W: AsyncWrite + AsyncSeek + Unpin + Send, P: AsRef<Pat
);
#[cfg(unix)]
{
entry_builder = entry_builder.unix_permissions(meta.mode().try_into().unwrap());
entry_builder = entry_builder.unix_permissions(
std::os::unix::fs::MetadataExt::mode(&meta)
.try_into()
.unwrap(),
);
}
writer
.write_entry_whole(entry_builder, &read(entry).await?)
Expand Down
5 changes: 2 additions & 3 deletions src/upgrade/check.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::cmp::Reverse;

use crate::{config::structs::ModLoader, version_ext::VersionExt};
use ferinth::structures::version::{Version, VersionFile};
use furse::structures::file_structs::File;
use octocrab::models::repos::{Asset, Release};
use std::cmp::Reverse;

pub(crate) fn game_version_check<S: AsRef<str>>(
game_version_to_check: Option<&str>,
Expand Down Expand Up @@ -41,7 +40,7 @@ pub fn curseforge<'a>(
game_version_to_check: Option<&str>,
mod_loader_to_check: Option<ModLoader>,
) -> Option<&'a File> {
// Sort files to make the latest files come first
// Sort files to make the latest ones come first
files.sort_unstable_by_key(|file1| Reverse(file1.file_date));

// Immediately select the newest file if check is disabled, i.e. *_to_check is None
Expand Down
22 changes: 12 additions & 10 deletions src/upgrade/mod_downloadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,30 @@ pub(crate) fn get_latest_compatible_file(
}
}

/// Get the latest compatible asset of the provided `repo_handler`.
/// Also returns whether Fabric backwards compatibility was used
pub(crate) fn get_latest_compatible_asset(
releases: &[Release],
/// Get the latest compatible asset of the provided `repo_handler`
///
/// Also returns whether Fabric backwards compatibility for Quilt was used.
pub(crate) fn get_latest_compatible_asset<'a>(
releases: &'a [Release],
game_version_to_check: Option<&str>,
mod_loader_to_check: Option<ModLoader>,
) -> Option<(Asset, bool)> {
) -> Option<(&'a Asset, bool)> {
match check::github(releases, game_version_to_check, mod_loader_to_check) {
Some(some) => Some((some.clone(), false)),
Some(some) => Some((some, false)),
None => {
if mod_loader_to_check == Some(ModLoader::Quilt) {
check::github(releases, game_version_to_check, Some(ModLoader::Fabric))
.map(|some| (some.clone(), true))
.map(|some| (some, true))
} else {
None
}
}
}
}

/// Get the latest compatible downloadable from the `mod_` provided.
/// Also returns whether fabric backwards compatibility was used
/// Get the latest compatible downloadable from the `mod_` provided
///
/// Also returns whether Fabric backwards compatibility for Quilt was used.
pub async fn get_latest_compatible_downloadable(
modrinth: &Ferinth,
curseforge: &Furse,
Expand Down Expand Up @@ -137,7 +139,7 @@ pub async fn get_latest_compatible_downloadable(
)
.map_or_else(
|| Err(Error::NoCompatibleFile),
|ok| Ok((ok.0.into(), ok.1)),
|ok| Ok((ok.0.clone().into(), ok.1)),
),
}
}
2 changes: 1 addition & 1 deletion src/upgrade/modpack_downloadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum Error {
"The developer of this modpack has denied third party applications from downloading it"
)]
/// The user can manually download the modpack zip file and place it in `~/.config/ferium/.cache/` to mitigate this.
/// However, they will have to manually update the modpack file if it is updated.
/// However, they will have to manually update the modpack file.
DistributionDenied(#[from] DistributionDeniedError),
ModrinthError(#[from] ferinth::Error),
CurseForgeError(#[from] furse::Error),
Expand Down

0 comments on commit 841c446

Please sign in to comment.