Skip to content

Commit b348b12

Browse files
committed
Fix get_mod_info not returning fully resolved URL
1 parent 98b7b58 commit b348b12

File tree

10 files changed

+120
-53
lines changed

10 files changed

+120
-53
lines changed

Cargo.lock

+69-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mint_lib/src/mod_info.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ impl ModSpecification {
7777
/// Points to a specific version of a specific mod
7878
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd, Hash, Serialize, Deserialize)]
7979
pub struct ModResolution {
80-
pub url: String,
80+
pub url: ModIdentifier,
8181
pub status: ResolvableStatus,
8282
}
8383

8484
impl ModResolution {
85-
pub fn resolvable(url: String) -> Self {
85+
pub fn resolvable(url: ModIdentifier) -> Self {
8686
Self {
8787
url,
8888
status: ResolvableStatus::Resolvable,
8989
}
9090
}
91-
pub fn unresolvable(url: String, name: String) -> Self {
91+
pub fn unresolvable(url: ModIdentifier, name: String) -> Self {
9292
Self {
9393
url,
9494
status: ResolvableStatus::Unresolvable(name),
@@ -97,19 +97,29 @@ impl ModResolution {
9797
/// Used to get the URL if resolvable or just return the mod name if not
9898
pub fn get_resolvable_url_or_name(&self) -> &str {
9999
match &self.status {
100-
ResolvableStatus::Resolvable => &self.url,
100+
ResolvableStatus::Resolvable => &self.url.0,
101101
ResolvableStatus::Unresolvable(name) => name,
102102
}
103103
}
104104
}
105105

106106
/// Mod identifier used for tracking gameplay affecting status.
107-
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
108-
pub struct ModIdentifier(String);
107+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
108+
pub struct ModIdentifier(pub String);
109109

110110
impl ModIdentifier {
111-
pub fn new(s: &str) -> Self {
112-
Self(s.to_string())
111+
pub fn new(s: String) -> Self {
112+
Self(s)
113+
}
114+
}
115+
impl From<String> for ModIdentifier {
116+
fn from(value: String) -> Self {
117+
Self::new(value)
118+
}
119+
}
120+
impl From<&str> for ModIdentifier {
121+
fn from(value: &str) -> Self {
122+
Self::new(value.to_owned())
113123
}
114124
}
115125

src/gui/message.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ use crate::{
2424
state::ModConfig,
2525
};
2626

27-
use mint_lib::mod_info::ModIdentifier;
28-
2927
use super::SelfUpdateProgress;
3028
use super::{
3129
request_counter::{RequestCounter, RequestID},
@@ -220,7 +218,7 @@ impl Integrate {
220218
for (res, stat) in resolution_gameplay_affecting_map {
221219
app.state
222220
.store
223-
.update_gameplay_affecting_status(ModIdentifier::new(&res.url), *stat);
221+
.update_gameplay_affecting_status(res.url, *stat);
224222
}
225223

226224
info!("integration complete");

src/gui/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl App {
560560
}
561561

562562
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
563-
if let Some(status) = self.state.store.get_gameplay_affecting_status(&ModIdentifier::new(&info.resolution.url)) {
563+
if let Some(status) = self.state.store.get_gameplay_affecting_status(&info.resolution.url) {
564564
match status {
565565
GameplayAffecting::Yes => {
566566
mk_searchable_tag(

src/integrate.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io::{self, BufReader, BufWriter, Cursor, ErrorKind, Read, Seek};
55
use std::path::{Path, PathBuf};
66

77
use anyhow::{Context, Result};
8-
use mint_lib::mod_info::{ApprovalStatus, Meta, MetaMod, ModResolution, SemverVersion};
8+
use mint_lib::mod_info::{ApprovalStatus, Meta, MetaMod, SemverVersion};
99
use mint_lib::DRGInstallation;
1010
use repak::PakWriter;
1111
use serde::Deserialize;
@@ -412,24 +412,7 @@ pub fn integrate<P: AsRef<Path>>(
412412

413413
debug!(?mod_info, ?gameplay_affecting);
414414

415-
// HACK: if a url is like mod.io/mod-name#mod-id/mod-file-id we split right to get rid of
416-
// the mod-file-id.
417-
let resolution_hack = if let Some((left, _)) = mod_info.resolution.url.rsplit_once('/') {
418-
ModResolution {
419-
status: mod_info.resolution.status.clone(),
420-
url: left.to_owned(),
421-
}
422-
} else {
423-
mod_info.resolution.clone()
424-
};
425-
426-
gameplay_affecting_results.insert(
427-
ModInfo {
428-
resolution: resolution_hack,
429-
..mod_info.clone()
430-
},
431-
gameplay_affecting,
432-
);
415+
gameplay_affecting_results.insert(mod_info.clone(), gameplay_affecting);
433416

434417
let mount = Path::new(pak.mount_point());
435418

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub async fn resolve_unordered_and_integrate<P: AsRef<Path>>(
111111

112112
let mods_set = mod_specs
113113
.iter()
114-
.flat_map(|m| [&mods[m].spec.url, &mods[m].resolution.url])
114+
.flat_map(|m| [&mods[m].spec.url, &mods[m].resolution.url.0])
115115
.collect::<HashSet<_>>();
116116

117117
// TODO need more rebust way of detecting whether dependencies are missing
@@ -162,7 +162,7 @@ async fn resolve_into_urls<'b>(
162162

163163
let mods_set = mod_specs
164164
.iter()
165-
.flat_map(|m| [&mods[m].spec.url, &mods[m].resolution.url])
165+
.flat_map(|m| [&mods[m].spec.url, &mods[m].resolution.url.0])
166166
.collect::<HashSet<_>>();
167167

168168
// TODO need more rebust way of detecting whether dependencies are missing

src/providers/file.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ModProvider for FileProvider {
5252
spec: spec.clone(),
5353
versions: vec![],
5454
resolution: ModResolution::unresolvable(
55-
path.to_string_lossy().to_string(),
55+
path.to_string_lossy().as_ref().into(),
5656
path.file_name()
5757
.map(|p| p.to_string_lossy().to_string())
5858
.unwrap_or_else(|| "unknown".to_string()),
@@ -79,7 +79,7 @@ impl ModProvider for FileProvider {
7979
.await
8080
.unwrap();
8181
}
82-
Ok(PathBuf::from(&res.url))
82+
Ok(PathBuf::from(&res.url.0))
8383
}
8484

8585
async fn update_cache(&self, _cache: ProviderCache) -> Result<()> {
@@ -102,7 +102,7 @@ impl ModProvider for FileProvider {
102102
spec: spec.clone(),
103103
versions: vec![],
104104
resolution: ModResolution::unresolvable(
105-
path.to_string_lossy().to_string(),
105+
path.to_string_lossy().as_ref().into(),
106106
path.file_name()
107107
.map(|p| p.to_string_lossy().to_string())
108108
.unwrap_or_else(|| "unknown".to_string()),

src/providers/http.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl ModProvider for HttpProvider {
8888
name,
8989
spec: spec.clone(),
9090
versions: vec![],
91-
resolution: ModResolution::resolvable(spec.url.to_owned()),
91+
resolution: ModResolution::resolvable(spec.url.as_str().into()),
9292
suggested_require: false,
9393
suggested_dependencies: vec![],
9494
modio_tags: None,
@@ -113,7 +113,7 @@ impl ModProvider for HttpProvider {
113113
.read()
114114
.unwrap()
115115
.get::<HttpProviderCache>(HTTP_PROVIDER_ID)
116-
.and_then(|c| c.url_blobs.get(url))
116+
.and_then(|c| c.url_blobs.get(&url.0))
117117
.and_then(|r| blob_cache.get_path(r))
118118
} {
119119
if let Some(tx) = tx {
@@ -125,8 +125,8 @@ impl ModProvider for HttpProvider {
125125
}
126126
path
127127
} else {
128-
info!("downloading mod {url}...");
129-
let response = self.client.get(url).send().await?.error_for_status()?;
128+
info!("downloading mod {url:?}...");
129+
let response = self.client.get(&url.0).send().await?.error_for_status()?;
130130
let size = response.content_length(); // TODO will be incorrect if compressed
131131
if let Some(mime) = response
132132
.headers()
@@ -165,7 +165,7 @@ impl ModProvider for HttpProvider {
165165
.unwrap()
166166
.get_mut::<HttpProviderCache>(HTTP_PROVIDER_ID)
167167
.url_blobs
168-
.insert(url.to_owned(), blob);
168+
.insert(url.0.to_owned(), blob);
169169

170170
if let Some(tx) = tx {
171171
tx.send(FetchProgress::Complete {
@@ -198,7 +198,7 @@ impl ModProvider for HttpProvider {
198198
name,
199199
spec: spec.clone(),
200200
versions: vec![],
201-
resolution: ModResolution::resolvable(spec.url.to_owned()),
201+
resolution: ModResolution::resolvable(spec.url.as_str().into()),
202202
suggested_require: false,
203203
suggested_dependencies: vec![],
204204
modio_tags: None,

src/providers/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl ModStore {
275275
update: bool,
276276
tx: Option<Sender<FetchProgress>>,
277277
) -> Result<PathBuf> {
278-
self.get_provider(&res.url)?
278+
self.get_provider(&res.url.0)?
279279
.fetch_mod(
280280
res,
281281
update,

0 commit comments

Comments
 (0)