style: apply rustfmt
This commit is contained in:
1 parent
7723716e18
commit
a58e6fb76d
20 files changed
+114
-83
No files matched your search
@@ -6,11 +6,11 @@ pub mod resource_packs;
|
||||
pub mod shaders;
|
||||
pub mod worlds;
|
||||
|
||||
pub use mods::{ContentEntry, scan_mods, toggle_entry};
|
||||
pub use mods::scan_one_mod;
|
||||
pub use resource_packs::{scan_resource_packs, scan_one_resource_pack};
|
||||
pub use shaders::{scan_shaders, scan_one_shader};
|
||||
pub use worlds::{scan_worlds, scan_one_world};
|
||||
pub use mods::{ContentEntry, scan_mods, toggle_entry};
|
||||
pub use resource_packs::{scan_one_resource_pack, scan_resource_packs};
|
||||
pub use shaders::{scan_one_shader, scan_shaders};
|
||||
pub use worlds::{scan_one_world, scan_worlds};
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
|
||||
@@ -742,7 +742,8 @@ description = "A neoforge mod"
|
||||
fn scan_mods_prefers_neoforge_toml_over_forge_toml() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let dir = setup_mods_dir(tmp.path(), "inst");
|
||||
let neoforge = "[[mods]]\ndisplayName = \"NeoForge Name\"\ndescription = \"neoforge desc\"\n";
|
||||
let neoforge =
|
||||
"[[mods]]\ndisplayName = \"NeoForge Name\"\ndescription = \"neoforge desc\"\n";
|
||||
let forge = "[[mods]]\ndisplayName = \"Forge Name\"\ndescription = \"forge desc\"\n";
|
||||
make_jar(
|
||||
&dir,
|
||||
|
||||
@@ -89,4 +89,3 @@ fn read_shader_metadata_from_dir(dir: &Path) -> (String, Option<Vec<u8>>) {
|
||||
|
||||
(description, icon_bytes)
|
||||
}
|
||||
|
||||
@@ -134,4 +134,3 @@ fn format_size(bytes: u64) -> String {
|
||||
format!("{:.2} GB", bytes as f64 / (1024.0 * 1024.0 * 1024.0))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,11 +154,7 @@ mod tests {
|
||||
#[test]
|
||||
fn detect_format_recognises_mrpack() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let path = make_pack_zip(
|
||||
tmp.path(),
|
||||
"pack.mrpack",
|
||||
&[("modrinth.index.json", b"{}")],
|
||||
);
|
||||
let path = make_pack_zip(tmp.path(), "pack.mrpack", &[("modrinth.index.json", b"{}")]);
|
||||
assert_eq!(detect_format(&path), Ok(PackFormat::Mrpack));
|
||||
}
|
||||
|
||||
@@ -176,11 +172,7 @@ mod tests {
|
||||
// mmc-pack.json one directory deep - the more common layout where
|
||||
// the archive wraps everything in a named directory.
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let path = make_pack_zip(
|
||||
tmp.path(),
|
||||
"pack.zip",
|
||||
&[("MyPack/mmc-pack.json", b"{}")],
|
||||
);
|
||||
let path = make_pack_zip(tmp.path(), "pack.zip", &[("MyPack/mmc-pack.json", b"{}")]);
|
||||
assert_eq!(detect_format(&path), Ok(PackFormat::Mmc));
|
||||
}
|
||||
|
||||
@@ -192,10 +184,7 @@ mod tests {
|
||||
let path = make_pack_zip(
|
||||
tmp.path(),
|
||||
"weird.zip",
|
||||
&[
|
||||
("modrinth.index.json", b"{}"),
|
||||
("mmc-pack.json", b"{}"),
|
||||
],
|
||||
&[("modrinth.index.json", b"{}"), ("mmc-pack.json", b"{}")],
|
||||
);
|
||||
assert_eq!(detect_format(&path), Ok(PackFormat::Mrpack));
|
||||
}
|
||||
|
||||
@@ -383,8 +383,13 @@ mod tests {
|
||||
#[test]
|
||||
fn parse_add_opens_extracts_module_args() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let manifest = b"Manifest-Version: 1.0\nAdd-Opens: java.base/java.lang java.base/java.util\n";
|
||||
let zip_path = make_zip(tmp.path(), "patches.zip", &[("META-INF/MANIFEST.MF", manifest)]);
|
||||
let manifest =
|
||||
b"Manifest-Version: 1.0\nAdd-Opens: java.base/java.lang java.base/java.util\n";
|
||||
let zip_path = make_zip(
|
||||
tmp.path(),
|
||||
"patches.zip",
|
||||
&[("META-INF/MANIFEST.MF", manifest)],
|
||||
);
|
||||
let args = parse_add_opens(&zip_path).expect("parsed");
|
||||
assert_eq!(
|
||||
args,
|
||||
|
||||
@@ -468,7 +468,9 @@ mod tests {
|
||||
|
||||
manager.touch_last_played("ticker").expect("touch");
|
||||
let reloaded = manager.load_one("ticker").unwrap();
|
||||
let stamp = reloaded.last_played.expect("last_played should be Some now");
|
||||
let stamp = reloaded
|
||||
.last_played
|
||||
.expect("last_played should be Some now");
|
||||
let age = chrono::Utc::now() - stamp;
|
||||
assert!(
|
||||
age.num_seconds().abs() < 5,
|
||||
|
||||
+2
-5
@@ -11,11 +11,8 @@ pub mod models;
|
||||
pub mod screenshots;
|
||||
|
||||
pub use content::{
|
||||
ContentEntry, toggle_entry,
|
||||
scan_mods, scan_one_mod,
|
||||
scan_resource_packs, scan_one_resource_pack,
|
||||
scan_shaders, scan_one_shader,
|
||||
scan_worlds, scan_one_world,
|
||||
ContentEntry, scan_mods, scan_one_mod, scan_one_resource_pack, scan_one_shader, scan_one_world,
|
||||
scan_resource_packs, scan_shaders, scan_worlds, toggle_entry,
|
||||
};
|
||||
pub use launch::LaunchError;
|
||||
pub use loader::{GameVersion, ModLoaderInstaller, VanillaInstaller, get_installer};
|
||||
|
||||
@@ -45,4 +45,3 @@ pub fn scan_screenshots(instances_dir: &Path, instance_name: &str) -> Vec<Screen
|
||||
entries.sort_by(|a, b| b.name.cmp(&a.name));
|
||||
entries
|
||||
}
|
||||
|
||||
@@ -113,7 +113,10 @@ fn os_version_matches(pattern: &str, host_version: &str) -> bool {
|
||||
fn features_match(required: &FeatureSet, current: &FeatureSet) -> bool {
|
||||
let pairs = [
|
||||
(required.is_demo_user, current.is_demo_user),
|
||||
(required.has_custom_resolution, current.has_custom_resolution),
|
||||
(
|
||||
required.has_custom_resolution,
|
||||
current.has_custom_resolution,
|
||||
),
|
||||
(
|
||||
required.has_quick_plays_support,
|
||||
current.has_quick_plays_support,
|
||||
|
||||
@@ -165,7 +165,10 @@ mod tests {
|
||||
#[case::unclosed_placeholder("--prefix ${unclosed", "--prefix ${unclosed")]
|
||||
#[case::dollar_without_brace("$$ literal $5 $", "$$ literal $5 $")]
|
||||
#[case::multiple("${version_name}-${auth_player_name}", "1.20.1-Player")]
|
||||
#[case::path("-DlibraryDirectory=${library_directory}", "-DlibraryDirectory=/m/libraries")]
|
||||
#[case::path(
|
||||
"-DlibraryDirectory=${library_directory}",
|
||||
"-DlibraryDirectory=/m/libraries"
|
||||
)]
|
||||
#[case::empty_input("", "")]
|
||||
fn substitute_handles(#[case] input: &str, #[case] expected: &str) {
|
||||
let fx = Fixture::unix();
|
||||
@@ -178,7 +181,10 @@ mod tests {
|
||||
// pattern. it should NOT trigger another substitution pass.
|
||||
let mut fx = Fixture::unix();
|
||||
fx.user_properties = "${version_name}".to_string();
|
||||
assert_eq!(substitute("${user_properties}", &fx.ctx()), "${version_name}");
|
||||
assert_eq!(
|
||||
substitute("${user_properties}", &fx.ctx()),
|
||||
"${version_name}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+5
-1
@@ -39,7 +39,11 @@ fn rename_top_level(old: &Path, new: &Path) {
|
||||
return;
|
||||
}
|
||||
match fs::rename(old, new) {
|
||||
Ok(_) => eprintln!("rmcl migration: moved {} -> {}", old.display(), new.display()),
|
||||
Ok(_) => eprintln!(
|
||||
"rmcl migration: moved {} -> {}",
|
||||
old.display(),
|
||||
new.display()
|
||||
),
|
||||
Err(e) if e.kind() == io::ErrorKind::CrossesDevices => {
|
||||
if let Err(e2) = copy_dir_recursive(old, new) {
|
||||
eprintln!(
|
||||
|
||||
+1
-2
@@ -113,8 +113,7 @@ pub async fn fetch_fabric_profile_with_raw(
|
||||
game_version: &str,
|
||||
loader_version: &str,
|
||||
) -> Result<(FabricProfile, Vec<u8>), NetError> {
|
||||
fetch_fabric_profile_with_raw_from(client, FABRIC_META_BASE, game_version, loader_version)
|
||||
.await
|
||||
fetch_fabric_profile_with_raw_from(client, FABRIC_META_BASE, game_version, loader_version).await
|
||||
}
|
||||
|
||||
pub async fn fetch_fabric_profile_with_raw_from(
|
||||
|
||||
@@ -297,5 +297,4 @@ mod tests {
|
||||
fn maven_empty_string() {
|
||||
assert_eq!(maven_coord_to_path(""), None);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -92,9 +92,7 @@ impl ContentListState {
|
||||
received = true;
|
||||
let pos = self
|
||||
.entries
|
||||
.binary_search_by(|e| {
|
||||
e.name.to_lowercase().cmp(&entry.name.to_lowercase())
|
||||
})
|
||||
.binary_search_by(|e| e.name.to_lowercase().cmp(&entry.name.to_lowercase()))
|
||||
.unwrap_or_else(|i| i);
|
||||
self.entries.insert(pos, entry);
|
||||
}
|
||||
@@ -160,8 +158,7 @@ impl ContentListState {
|
||||
if self.entries.is_empty() {
|
||||
self.list_state.selected = None;
|
||||
} else {
|
||||
self.list_state.selected =
|
||||
Some(sel.min(self.entries.len().saturating_sub(1)));
|
||||
self.list_state.selected = Some(sel.min(self.entries.len().saturating_sub(1)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,11 +232,7 @@ impl ContentListState {
|
||||
for (stem, (old_path, old_enabled)) in known_map.iter() {
|
||||
if let Some((disk_path, disk_enabled)) = on_disk.get(stem) {
|
||||
if *disk_enabled != *old_enabled || *disk_path != *old_path {
|
||||
toggled.push((
|
||||
stem.clone(),
|
||||
*disk_enabled,
|
||||
disk_path.clone(),
|
||||
));
|
||||
toggled.push((stem.clone(), *disk_enabled, disk_path.clone()));
|
||||
}
|
||||
} else {
|
||||
removed.push(stem.clone());
|
||||
@@ -366,16 +359,16 @@ impl ContentListState {
|
||||
continue;
|
||||
};
|
||||
|
||||
let (enabled, file_stem) =
|
||||
if let Some(stem) = fname.strip_suffix(&disabled_ext) {
|
||||
(false, stem.to_owned())
|
||||
} else if let Some(stem) = fname.strip_suffix(ext) {
|
||||
(true, stem.to_owned())
|
||||
} else if path.is_dir() {
|
||||
crate::instance::content::parse_enabled_stem_dir(fname)
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
let (enabled, file_stem) = if let Some(stem) = fname.strip_suffix(&disabled_ext)
|
||||
{
|
||||
(false, stem.to_owned())
|
||||
} else if let Some(stem) = fname.strip_suffix(ext) {
|
||||
(true, stem.to_owned())
|
||||
} else if path.is_dir() {
|
||||
crate::instance::content::parse_enabled_stem_dir(fname)
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let entry = scan_one_fn(&path, &file_stem, enabled);
|
||||
if tx.send(entry).is_err() {
|
||||
@@ -879,10 +872,7 @@ fn icon_spans(icon_pixels: Option<&Vec<Vec<IconCell>>>, row: usize) -> Vec<Span<
|
||||
// used both by watch_dir to initialize known state and by the watcher
|
||||
// thread to detect changes. when ext is empty (worlds), only directories
|
||||
// are included.
|
||||
fn read_dir_stems(
|
||||
dir: &std::path::Path,
|
||||
ext: &str,
|
||||
) -> HashMap<String, (std::path::PathBuf, bool)> {
|
||||
fn read_dir_stems(dir: &std::path::Path, ext: &str) -> HashMap<String, (std::path::PathBuf, bool)> {
|
||||
let mut map = HashMap::new();
|
||||
let Ok(read_dir) = std::fs::read_dir(dir) else {
|
||||
return map;
|
||||
|
||||
@@ -215,8 +215,16 @@ pub fn render(
|
||||
ContentTab::Mods => {
|
||||
if let Some(instance) = instance {
|
||||
if mods_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("mods");
|
||||
mods_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_mod, ".jar");
|
||||
let content_dir = instances_dir
|
||||
.join(&instance.name)
|
||||
.join(".minecraft")
|
||||
.join("mods");
|
||||
mods_state.start_load(
|
||||
&content_dir,
|
||||
&instance.name,
|
||||
crate::instance::scan_one_mod,
|
||||
".jar",
|
||||
);
|
||||
mods_state.watch_dir(content_dir);
|
||||
}
|
||||
super::list::render(
|
||||
@@ -238,8 +246,16 @@ pub fn render(
|
||||
ContentTab::ResourcePacks => {
|
||||
if let Some(instance) = instance {
|
||||
if resource_packs_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("resourcepacks");
|
||||
resource_packs_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_resource_pack, ".zip");
|
||||
let content_dir = instances_dir
|
||||
.join(&instance.name)
|
||||
.join(".minecraft")
|
||||
.join("resourcepacks");
|
||||
resource_packs_state.start_load(
|
||||
&content_dir,
|
||||
&instance.name,
|
||||
crate::instance::scan_one_resource_pack,
|
||||
".zip",
|
||||
);
|
||||
resource_packs_state.watch_dir(content_dir);
|
||||
}
|
||||
super::list::render(
|
||||
@@ -261,8 +277,16 @@ pub fn render(
|
||||
ContentTab::Shaders => {
|
||||
if let Some(instance) = instance {
|
||||
if shaders_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("shaderpacks");
|
||||
shaders_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_shader, ".zip");
|
||||
let content_dir = instances_dir
|
||||
.join(&instance.name)
|
||||
.join(".minecraft")
|
||||
.join("shaderpacks");
|
||||
shaders_state.start_load(
|
||||
&content_dir,
|
||||
&instance.name,
|
||||
crate::instance::scan_one_shader,
|
||||
".zip",
|
||||
);
|
||||
shaders_state.watch_dir(content_dir);
|
||||
}
|
||||
super::list::render(
|
||||
@@ -322,8 +346,16 @@ pub fn render(
|
||||
ContentTab::Worlds => {
|
||||
if let Some(instance) = instance {
|
||||
if worlds_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("saves");
|
||||
worlds_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_world, "");
|
||||
let content_dir = instances_dir
|
||||
.join(&instance.name)
|
||||
.join(".minecraft")
|
||||
.join("saves");
|
||||
worlds_state.start_load(
|
||||
&content_dir,
|
||||
&instance.name,
|
||||
crate::instance::scan_one_world,
|
||||
"",
|
||||
);
|
||||
worlds_state.watch_dir(content_dir);
|
||||
}
|
||||
super::list::render(
|
||||
|
||||
@@ -9,12 +9,12 @@ use ratatui::{
|
||||
|
||||
pub mod account;
|
||||
pub mod content;
|
||||
pub mod settings;
|
||||
pub mod instances;
|
||||
pub mod logs_viewer;
|
||||
pub mod popups;
|
||||
pub mod screenshots_grid;
|
||||
pub mod search;
|
||||
pub mod settings;
|
||||
pub mod status;
|
||||
|
||||
// highlight the first character of a title with the accent color,
|
||||
|
||||
@@ -426,11 +426,8 @@ mod tests {
|
||||
id: "1.20.1".into(),
|
||||
stable: true,
|
||||
}]);
|
||||
guard.loader_versions = LoadState::Loaded(vec![
|
||||
"47.2.0".into(),
|
||||
"47.1.0".into(),
|
||||
"47.0.50".into(),
|
||||
]);
|
||||
guard.loader_versions =
|
||||
LoadState::Loaded(vec!["47.2.0".into(), "47.1.0".into(), "47.0.50".into()]);
|
||||
}
|
||||
|
||||
let backend = TestBackend::new(60, 14);
|
||||
|
||||
@@ -9,7 +9,10 @@ use ratatui::{
|
||||
widgets::{Block, Borders, Paragraph},
|
||||
};
|
||||
|
||||
use crate::config::{SETTINGS, theme::{BORDER_STYLE, THEME}};
|
||||
use crate::config::{
|
||||
SETTINGS,
|
||||
theme::{BORDER_STYLE, THEME},
|
||||
};
|
||||
use crate::instance::models::InstanceConfig;
|
||||
use crate::tui::app::FocusedArea;
|
||||
|
||||
@@ -66,8 +69,14 @@ pub fn render(
|
||||
.add_modifier(Modifier::BOLD);
|
||||
let dim_style = Style::default().fg(theme.text_dim());
|
||||
|
||||
let memory_min = inst.memory_min.as_deref().unwrap_or(&SETTINGS.defaults.memory_min);
|
||||
let memory_max = inst.memory_max.as_deref().unwrap_or(&SETTINGS.defaults.memory_max);
|
||||
let memory_min = inst
|
||||
.memory_min
|
||||
.as_deref()
|
||||
.unwrap_or(&SETTINGS.defaults.memory_min);
|
||||
let memory_max = inst
|
||||
.memory_max
|
||||
.as_deref()
|
||||
.unwrap_or(&SETTINGS.defaults.memory_max);
|
||||
let java_path = inst
|
||||
.java_path
|
||||
.as_deref()
|
||||
|
||||
+6
-5
@@ -10,7 +10,7 @@ use wiremock::{Mock, MockServer, ResponseTemplate};
|
||||
|
||||
use rmcl::net::HttpClient;
|
||||
use rmcl::net::mojang::{
|
||||
AssetIndex, Artifact, Download, JavaVersion, Library, LibraryDownloads, VersionDownloads,
|
||||
Artifact, AssetIndex, Download, JavaVersion, Library, LibraryDownloads, VersionDownloads,
|
||||
VersionEntry, VersionMeta, download_assets, download_assets_from, download_libraries,
|
||||
fetch_version_manifest_from, fetch_version_meta_with_raw,
|
||||
};
|
||||
@@ -226,9 +226,7 @@ async fn download_assets_from_writes_index_and_assets() {
|
||||
.await;
|
||||
// asset hash starts with "ab" so the per-asset URL is /<base>/ab/<hash>.
|
||||
Mock::given(method("GET"))
|
||||
.and(path(
|
||||
"/cdn/ab/ab1234567890abcdef1234567890abcdef123456",
|
||||
))
|
||||
.and(path("/cdn/ab/ab1234567890abcdef1234567890abcdef123456"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_bytes(b"asset-bytes".to_vec()))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
@@ -272,7 +270,10 @@ async fn download_assets_writes_index_when_objects_is_empty() {
|
||||
.expect("download_assets index-only");
|
||||
|
||||
let index_path = tmp.path().join("assets/indexes/5.json");
|
||||
assert!(index_path.exists(), "expected asset index at {index_path:?}");
|
||||
assert!(
|
||||
index_path.exists(),
|
||||
"expected asset index at {index_path:?}"
|
||||
);
|
||||
let body: serde_json::Value =
|
||||
serde_json::from_slice(&std::fs::read(&index_path).unwrap()).unwrap();
|
||||
assert!(body.get("objects").is_some());
|
||||
|
||||
Reference in new issue
Block a user