Skip to content

Commit

Permalink
Fix warnings, remove unused deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Raytwo committed Oct 4, 2024
1 parent c2961d7 commit e14b588
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 103 deletions.
4 changes: 1 addition & 3 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.5.11"
log = "0.4.19"
smash-arc = { git = "https://github.com/jam1garner/smash-arc" }
smash-arc = { git = "https://github.com/jam1garner/smash-arc", default-features = false}
skyline = { git = "https://github.com/Raytwo/skyline-rs", branch="preview" }
skyline-config = { git = "https://github.com/skyline-rs/skyline-config" }
walkdir = "2.3.3"
thiserror = "1.0.43"
semver = { version = "1", features = ["serde"] }
camino = "1"
lazysimd = { git = "https://github.com/Raytwo/lazysimd" }
29 changes: 0 additions & 29 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use semver::Version;
use skyline::nn;
use skyline_config::*;
use smash_arc::{Hash40, Region};
use walkdir::WalkDir;

use crate::utils::env::get_arcropolis_version;

Expand Down Expand Up @@ -63,34 +62,6 @@ fn generate_default_config<CS: ConfigStorage>(storage: &mut StorageHolder<CS>) -
storage.set_field("workspace", "Default")
}

fn convert_legacy_to_presets() -> HashSet<Hash40> {
let mut presets: HashSet<Hash40> = HashSet::new();

// TODO: Turn this into a map and use Collect
for entry in WalkDir::new(crate::utils::paths::mods()).max_depth(1).into_iter().flatten() {
let path = entry.path();

// If the mod isn't disabled, add it to the preset
if path
.file_name()
.and_then(|name| name.to_str())
.map(|name| !name.starts_with('.'))
.unwrap_or(false)
{
presets.insert(Hash40::from(path.to_str().unwrap()));
} else {
// TODO: Check if the destination already exists, because it'll definitely happen, and when someone opens an issue about it and you'll realize you knew ahead of time, you'll feel dumb. But right this moment, you decided not to do anything.
std::fs::rename(
path,
format!("{}/{}", crate::utils::paths::mods(), &path.file_name().unwrap().to_str().unwrap()[1..]),
)
.unwrap();
}
}

presets
}

pub fn auto_update_enabled() -> bool {
GLOBAL_CONFIG.lock().unwrap().get_flag("auto_update")
}
Expand Down
66 changes: 1 addition & 65 deletions crates/config/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,80 +1,16 @@
use skyline::nn;

pub mod env {
use semver::Version;
use std::{str::FromStr, sync::LazyLock};

use super::*;

#[non_exhaustive]
pub enum RunEnvironment {
Switch,
Emulator,
}

static PLATFORM: LazyLock<RunEnvironment> = LazyLock::new(|| {
let base_addr = unsafe { skyline::hooks::getRegionAddress(skyline::hooks::Region::Text) as u64 };

if base_addr == 0x8004000 || base_addr == 0x8504000 {
RunEnvironment::Emulator
} else {
RunEnvironment::Switch
}
});

pub fn get_running_env() -> &'static RunEnvironment {
&PLATFORM
}

pub fn is_hardware() -> bool {
matches!(get_running_env(), RunEnvironment::Switch)
}

pub fn is_emulator() -> bool {
matches!(get_running_env(), RunEnvironment::Emulator)
}

/// Wrapper function for getting the version string of the game from nnSdk
pub fn get_game_version() -> Version {
unsafe {
// TODO: Implement this in nnsdk-rs
let mut version_string = nn::oe::DisplayVersion { name: [0x00; 16] };
nn::oe::GetDisplayVersion(&mut version_string);
Version::from_str(&skyline::from_c_str(version_string.name.as_ptr())).expect("Smash's version should parse as a proper semver.")
}
}
use std::str::FromStr;

pub fn get_arcropolis_version() -> Version {
Version::from_str(env!("CARGO_PKG_VERSION")).expect("ARCropolis' version should follow proper semver.")
}
}

pub mod paths {
use super::env::get_game_version;
use camino::Utf8PathBuf;
use std::io;

pub fn ensure_paths_exist() -> io::Result<()> {
std::fs::create_dir_all(mods())?;
std::fs::create_dir_all(config())?;
std::fs::create_dir_all(logs())?;
std::fs::create_dir_all(cache())?;
Ok(())
}

pub fn mods() -> Utf8PathBuf {
Utf8PathBuf::from("sd:/ultimate/mods")
}

pub fn config() -> Utf8PathBuf {
Utf8PathBuf::from("sd:/ultimate/arcropolis/config")
}

pub fn logs() -> Utf8PathBuf {
Utf8PathBuf::from("sd:/ultimate/arcropolis/logs")
}

pub fn cache() -> Utf8PathBuf {
Utf8PathBuf::from("sd:/ultimate/arcropolis/cache").join(get_game_version().to_string())
}
}
4 changes: 0 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ pub mod utils;
pub mod lua;

pub use callback::*;
pub use event::*;
pub use file::*;
pub use utils::*;
pub use lua::*;

#[repr(C)]
pub struct ApiVersion {
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::{
collections::HashMap, fmt, io::{BufWriter, Write}, path::{Path, PathBuf}, str::FromStr, sync::{LazyLock, RwLock}
};

use api::file;
use arcropolis_api::Event;
use log::LevelFilter;
use thiserror::Error;
Expand Down
2 changes: 1 addition & 1 deletion src/replacement/addition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ pub fn add_dir_info_with_base(ctx: &mut AdditionContext, path: &Path, base: &Pat
let base_dir_info = *ctx.get_dir_info_from_hash_ctx(base_dir_info_path.path.hash40()).unwrap();

// Get the newly added dirinfo
let mut dir_info = ctx.get_dir_info_from_hash_ctx_mut(dir_info_path.path.hash40()).unwrap();
let dir_info = ctx.get_dir_info_from_hash_ctx_mut(dir_info_path.path.hash40()).unwrap();

// Set dir_info values to the base dirinfo
dir_info.path.set_index(base_dir_info.path.index());
Expand Down

0 comments on commit e14b588

Please sign in to comment.