Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file copying on Windows and installation by rules.txt #224

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ product-icon = "assets/ukmm.ico"
[dependencies]
anyhow = { workspace = true }
anyhow_ext = { workspace = true }
dircpy = { workspace = true }
dirs2 = { workspace = true }
eframe = { workspace = true, features = ["glow"] }
env_logger = "0.11.3"
Expand Down Expand Up @@ -92,7 +91,6 @@ version = "0.15.0"
anyhow = "1"
anyhow_ext = "0.2.1"
dashmap = "6"
dircpy = "0.3.12"
dirs2 = "3"
eframe = { version = "0.28", default-features = false }
flume = "0.11.0"
Expand Down
1 change: 0 additions & 1 deletion crates/uk-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ version.workspace = true
anyhow = { workspace = true }
anyhow_ext = { workspace = true }
dashmap = { workspace = true, features = ["rayon"] }
dircpy = { workspace = true }
dirs2 = { workspace = true }
fs-err = { workspace = true }
join_str = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/uk-manager/src/bnp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ impl BnpConverter {
pub fn unpack_bnp(core: &crate::core::Manager, path: &Path) -> Result<PathBuf> {
let tempdir = crate::util::get_temp_folder();
if path.is_dir() {
dircpy::copy_dir(path, tempdir.as_path()).context("Failed to copy files to temp folder")?;
crate::util::copy_dir(path, tempdir.as_path())
.context("Failed to copy files to temp folder")?;
} else {
log::info!("Extracting BNP…");
extract_7z(path, &tempdir).context("Failed to extract BNP")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/uk-manager/src/mods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Manager {
if mod_path.is_file() {
fs::copy(mod_path, &stored_path).context("Failed to copy mod to storage folder")?;
} else {
dircpy::copy_dir(mod_path, &stored_path)
util::copy_dir(mod_path, &stored_path)
.context("Failed to copy mod to storage folder")?;
}
}
Expand Down
13 changes: 13 additions & 0 deletions crates/uk-manager/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ use anyhow_ext::Context;
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard};
pub use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};

pub fn copy_dir<T: AsRef<Path>, U: AsRef<Path>>(src: T, dst: U) -> anyhow_ext::Result<()> {
for p in jwalk::WalkDir::new(&src) {
let from = p?.path();
let to = dst.as_ref().join(from.strip_prefix(&src)?);
if from.is_dir() && !to.exists() {
std::fs::create_dir(to)?;
} else if from.is_file() {
std::fs::copy(from, to)?;
}
}
Ok(())
}

pub fn remove_dir_all(dir: impl AsRef<std::path::Path>) -> anyhow_ext::Result<()> {
fn inner(dir: &Path) -> anyhow_ext::Result<()> {
#[cfg(windows)]
Expand Down
19 changes: 10 additions & 9 deletions src/gui/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ mod handlers;
pub use handlers::register_handlers;

fn is_probably_a_mod_and_has_meta(path: &Path) -> (bool, bool) {
if path
.file_name()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
== "rules.txt"
{
return (true, true);
}
let ext = path
.extension()
.and_then(|e| e.to_str().map(|e| e.to_lowercase()))
Expand All @@ -42,14 +51,6 @@ fn is_probably_a_mod_and_has_meta(path: &Path) -> (bool, bool) {
(false, false)
} else if ext == "7z" {
(true, false)
} else if path
.file_name()
.unwrap_or_default()
.to_str()
.unwrap_or_default()
== "rules.txt"
{
(true, true)
} else {
match fs::File::open(path)
.context("")
Expand Down Expand Up @@ -104,7 +105,7 @@ pub fn open_mod(core: &Manager, path: &Path, meta: Option<Meta>) -> Result<Messa
.filter(|(is_mod, _has_meta)| *is_mod)
.map(|(_, has_meta)| has_meta)
{
log::info!("Maybe it's not a UKMM mod, let's to convert it");
log::info!("Maybe it's not a UKMM mod, let's try to convert it");
if !has_meta && meta.is_none() {
log::info!("Mod has no meta info, requesting manual input");
return Ok(Message::RequestMeta(path.to_path_buf()));
Expand Down
6 changes: 3 additions & 3 deletions src/gui/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl App {
Message::DuplicateProfile(profile) => {
self.do_task(move |core| {
let profiles_dir = core.settings().profiles_dir();
dircpy::copy_dir(
uk_manager::util::copy_dir(
profiles_dir.join(&profile),
profiles_dir.join(profile + "_copy"),
)?;
Expand Down Expand Up @@ -230,10 +230,10 @@ impl App {
Message::SelectFile => {
if let Some(mut paths) = rfd::FileDialog::new()
.set_title("Select a Mod")
.add_filter("Any mod (*.zip, *.7z, *.bnp)", &["zip", "bnp", "7z"])
.add_filter("Any mod (*.zip, *.7z, *.bnp, rules.txt)", &["zip", "bnp", "7z", "txt"])
.add_filter("UKMM Mod (*.zip)", &["zip"])
.add_filter("BCML Mod (*.bnp)", &["bnp"])
.add_filter("Legacy Mod (*.zip, *.7z)", &["zip", "7z"])
.add_filter("Legacy Mod (*.zip, *.7z, rules.txt)", &["zip", "7z", "txt"])
.add_filter("All files (*.*)", &["*"])
.pick_files()
.filter(|p| !p.is_empty())
Expand Down
Loading