Skip to content

Commit a0ab88e

Browse files
committed
🐛 Fix handling of URL-ish paths on Windows; Resolves #335
1 parent f16b438 commit a0ab88e

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/main/java/dev/ebullient/convert/qute/ImageRef.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public String url() {
151151
}
152152

153153
public static class Builder {
154-
private Path sourcePath;
154+
private String sourcePath;
155155
private Path relativeTarget;
156156
private String title = "";
157157
private Integer width;
@@ -162,12 +162,17 @@ public static class Builder {
162162
private String url;
163163

164164
public Builder setSourcePath(Path sourcePath) {
165+
this.sourcePath = sourcePath.toString();
166+
return this;
167+
}
168+
169+
public Builder setInternalPath(String sourcePath) {
165170
this.sourcePath = sourcePath;
166171
return this;
167172
}
168173

169174
public Builder setStreamSource(String glyph) {
170-
this.sourcePath = Path.of("stream", glyph);
175+
this.sourcePath = "stream/" + glyph;
171176
return this;
172177
}
173178

@@ -207,11 +212,12 @@ public ImageRef build() {
207212
if (url != null && !imageRoot.copyExternalToVault()) {
208213
// leave external images alone (referenced as url)
209214
return new ImageRef(url, null, null, title, null, width);
210-
} else if (url == null && sourcePath == null) {
215+
}
216+
217+
if (url == null && sourcePath == null) {
211218
Tui.instance().errorf("ImageRef build for internal image called without url or sourcePath set");
212219
return null;
213220
}
214-
215221
if (relativeTarget == null || vaultRoot == null || rootFilePath == null) {
216222
Tui.instance().errorf("ImageRef build called without target paths set");
217223
return null;

src/main/java/dev/ebullient/convert/tools/dnd5e/Json2QuteCommon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ ImageRef getToken() {
746746
return null;
747747
}
748748

749-
return getSources().buildTokenImageRef(index, Path.of(sourcePath), targetFile, true);
749+
return getSources().buildTokenImageRef(index, sourcePath, targetFile, true);
750750
}
751751

752752
String collectImmunities(JsonNode fromNode, VulnerabilityFields field) {

src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eSources.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ public Optional<String> uaSource() {
218218
return source.map(TtrpgConfig::sourceToAbbreviation);
219219
}
220220

221-
public ImageRef buildTokenImageRef(Tools5eIndex index, Path sourcePath, Path target, boolean useCompendium) {
221+
public ImageRef buildTokenImageRef(Tools5eIndex index, String sourcePath, Path target, boolean useCompendium) {
222222
String key = sourcePath.toString();
223223
ImageRef imageRef = new ImageRef.Builder()
224224
.setRelativePath(target)
225-
.setSourcePath(sourcePath)
225+
.setInternalPath(sourcePath)
226226
.setRootFilepath(useCompendium ? index.compendiumFilePath() : index.rulesFilePath())
227227
.setVaultRoot(useCompendium ? index.compendiumVaultRoot() : index.rulesVaultRoot())
228228
.build(imageSourceToRef.get(key));
@@ -246,17 +246,19 @@ public ImageRef buildImageRef(Tools5eIndex index, JsonMediaHref mediaHref, Strin
246246
return imageRef;
247247
}
248248

249-
String fileName = external
250-
? Path.of(mediaHref.href.url).getFileName().toString()
251-
: Path.of(mediaHref.href.path).getFileName().toString();
249+
String fullPath = external
250+
? mediaHref.href.url
251+
: mediaHref.href.path.replace("\\", "/");
252+
int pos = fullPath.lastIndexOf('/');
253+
String fileName = fullPath.substring(pos + 1);
252254

253255
if (type == Tools5eIndexType.deity || type == Tools5eIndexType.note || type == Tools5eIndexType.variantrule) {
254256
fileName = primarySource() + "-" + fileName;
255257
}
256258

257259
int x = fileName.lastIndexOf('.');
258260
fileName = x < 0
259-
? fileName
261+
? index.slugify(fileName)
260262
: index.slugify(fileName.substring(0, x)) + fileName.substring(x);
261263
Path target = Path.of(imageBasePath, "img", fileName);
262264

@@ -270,7 +272,7 @@ public ImageRef buildImageRef(Tools5eIndex index, JsonMediaHref mediaHref, Strin
270272
if (external) {
271273
builder.setUrl(mediaHref.href.url);
272274
} else {
273-
builder.setSourcePath(Path.of(mediaHref.href.path));
275+
builder.setInternalPath(mediaHref.href.path);
274276
}
275277

276278
ImageRef imageRef = builder.build(imageSourceToRef.get(key));

0 commit comments

Comments
 (0)