Conversation
to prompt to "update" mod
No clue how that even worked in the first place
according to clippy
|
So this is working now in testing. The code is a bit messy and partially duplicated but as I mentioned before I'm time limited and this works fine for the release. Once players start transitioning over to packages we can clean up a bunch of things 👀 |
|
Also in the "upgrade to packages" part I should probably also add a sort of exception for mod settings where in the upgrade process mod settings gets skipped so it just gets deleted instead as it's not in the game anyway. |
|
Also I'd say the release that has everything packages related merged should be a 2.0 ^^ |
also deletes old version of legacy package if installed
catornot
left a comment
There was a problem hiding this comment.
I just like to complain about rust code.
also pls pls just actually use the result enum instead of unwrapping everything.
| let mut has_mods = false; | ||
| let mut mod_json_exists = false; | ||
|
|
||
| // Checks for `mods/*/mod.json` | ||
| for i in 0..archive.len() { | ||
| let file = match archive.by_index(i) { | ||
| Ok(file) => file, | ||
| Err(_) => continue, | ||
| }; | ||
| let file_path = file.mangled_name(); | ||
| if file_path.starts_with("mods/") { | ||
| has_mods = true; | ||
| if let Some(name) = file_path.file_name() { | ||
| if name == "mod.json" { | ||
| let parent_path = file_path.parent().unwrap(); | ||
| if parent_path.parent().unwrap().to_str().unwrap() == "mods" { | ||
| mod_json_exists = true; | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
this is literately the perfect use for a iterator.
no mutability :)
There was a problem hiding this comment.
Uh, I'm dumb, can I have an example? ^^
There was a problem hiding this comment.
smth like this
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=93be605e794e1939f0deeaeebb767575
it might not compile but it shouldn't be hard to fix stuff in it I think.
| for directory in directories { | ||
| let folder_name = directory.file_name().unwrap().to_str().unwrap(); | ||
| let ts_mod_string_from_folder: ParsedThunderstoreModString = match folder_name.parse() { | ||
| Ok(res) => res, | ||
| Err(err) => { | ||
| log::warn!("{err}"); | ||
| continue; | ||
| } | ||
| }; | ||
| // Check which match `AUTHOR-MOD` and do NOT match `AUTHOR-MOD-VERSION` | ||
| if ts_mod_string_from_folder.author_name == thunderstore_mod_string.author_name | ||
| && ts_mod_string_from_folder.mod_name == thunderstore_mod_string.mod_name | ||
| && ts_mod_string_from_folder.version != thunderstore_mod_string.version | ||
| { | ||
| delete_package_folder(&directory.display().to_string())?; | ||
| } | ||
| } |
There was a problem hiding this comment.
a iterator would also be better here although you can probably keep it and just move all these if cases into filters.
There was a problem hiding this comment.
Yeah so I kinda merged #426 before seeing your comments on here. Will do some refactoring to change update to your feedback though ^^
| for legacy_mod in found_installed_legacy_mods { | ||
| if legacy_mod.thunderstore_mod_string.is_none() { | ||
| continue; // Not a thunderstore mod | ||
| } | ||
|
|
||
| let current_mod_ts_string: ParsedThunderstoreModString = legacy_mod | ||
| .clone() | ||
| .thunderstore_mod_string | ||
| .unwrap() | ||
| .parse() | ||
| .unwrap(); | ||
|
|
||
| if thunderstore_mod_string.author_name == current_mod_ts_string.author_name | ||
| && thunderstore_mod_string.mod_name == current_mod_ts_string.mod_name | ||
| { | ||
| // They match, delete | ||
| delete_mod_folder(&legacy_mod.directory)?; | ||
| } | ||
| } |
There was a problem hiding this comment.
a iterator would also be better here although you can probably keep it and just move all these if cases into filters.
| }; | ||
|
|
||
| // Successful package install | ||
| match legacy::delete_legacy_package_install(thunderstore_mod_string, game_install) { |
There was a problem hiding this comment.
consider using a if let here
| } | ||
| }; | ||
|
|
||
| match delete_older_versions(thunderstore_mod_string, game_install) { |
| for path in paths { | ||
| let my_path = path.unwrap().path(); | ||
|
|
||
| let md = std::fs::metadata(my_path.clone()).unwrap(); | ||
| if md.is_dir() { | ||
| directories.push(my_path); | ||
| } | ||
| } |
There was a problem hiding this comment.
for loop found, use a iterator instead in this case. ( I hate for loops ).
| // This is a stupid way to show a legacy installed mod as outdated by simply giving back a wrong version number | ||
| if thunderstore_mod_string.is_some() { | ||
| // Parse the string | ||
| let mut parsed_string: ParsedThunderstoreModString = | ||
| thunderstore_mod_string.clone().unwrap().parse().unwrap(); | ||
| // Set version number to `0.0.0` | ||
| parsed_string.version = "0.0.0".to_string(); | ||
| // And store new string back in original variable | ||
| thunderstore_mod_string = Some(parsed_string.to_string()) | ||
| } |
There was a problem hiding this comment.
perhaps just move this into the match case above ;)
There was a problem hiding this comment.
Wouldn't I have to duplicate the code then? Cause the match matches for like two cases
- checking if it's in
mods.json - checking if it there's a
manifest.jsonand athunderstore_author.txt
The difference is simply the removed deprecation notice
if parsing folder name to Thunderstore mod string failed.
This PR is just to see the diff between all missing
packagesrelated changes andmainIt contains
packagesdirectory #417As such this PR should stay draft and not be merged on its own but rather to be used as a PoC and see overall progress of implementing the
packagesformat.