Skip to content

Commit

Permalink
Fix: remove ':' and other illegal chars from filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
twanvl committed Sep 12, 2018
1 parent 8bdf9b6 commit d4c8fa1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 0.3.1
* Fix mod pages on case sensitive file systems
* Fix invalid characters in filenames (issue #1)

### 0.3.0
* Use BaseMod.customMonsters to also export custom monsters
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/sts_exporter/CardExportData.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,11 @@ public CardExportData(AbstractCard card, String imageDir, String smallImageDir,
}

private void exportImageToDir(String imageDir, String smallImageDir) {
String safename = this.name;
safename = safename.replace(" ","");
safename = safename.replace("/","");
safename = safename.replace("+","Plus");
this.image = safename + ".png";
this.absImage = imageDir + "/" + safename + ".png";
this.relImage = "card-images/" + safename + ".png";
this.absSmallImage = smallImageDir + "/" + safename + ".png";
this.relSmallImage = "small-card-images/" + safename + ".png";
this.image = Exporter.makeFilename(this.name) + ".png";
this.absImage = imageDir + "/" + this.image;
this.relImage = "card-images/" + this.image;
this.absSmallImage = smallImageDir + "/" + this.image;
this.relSmallImage = "small-card-images/" + this.image;
exportImageToFile(this.absImage, this.absSmallImage);
}

Expand Down
8 changes: 1 addition & 7 deletions src/main/java/sts_exporter/CreatureExportData.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ public CreatureExportData(AbstractCreature creature, String imageDir) {
}

private void exportImageToDir(String imageDir) {
String safename = creature.getClass().getSimpleName();
if (creature.id != null) {
safename = creature.id;
}
safename = safename.replace(" ","");
safename = safename.replace("/","");
this.image = safename + ".png";
this.image = Exporter.makeFilename(creature.id != null ? creature.id : creature.getClass().getSimpleName()) + ".png";
this.absImage = imageDir + "/" + this.image;
this.relImage = "creatures/" + this.image;
exportImageToFile(this.absImage);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/sts_exporter/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ static void mkdir(String dir) {
f.mkdir();
}

static String makeFilename(String id) {
id = id.replaceAll(":","-");
id = id.replace("+","Plus");
id = id.replace("*","Star");
return id.replaceAll("[\\s\\\\/:*?\"\'<>|+%]", "");
}

public static void exportAll(String outdir) {
logger.info("Exporting all cards to " + outdir);
mkdir(outdir);
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/sts_exporter/PotionExportData.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ class PotionExportData implements Comparable<PotionExportData> {
}

private void exportImageToDir(String imageDir) {
String safename = id;
safename = safename.replace(" ","");
safename = safename.replace("/","");
this.image = safename + ".png";
this.absImage = imageDir + "/" + safename + ".png";
this.relImage = "potions/" + safename + ".png";
this.image = Exporter.makeFilename(this.name) + ".png";
this.absImage = imageDir + "/" + this.image;
this.relImage = "potions/" + this.image;
exportImageToFile(this.absImage);
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/sts_exporter/RelicExportData.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class RelicExportData implements Comparable<RelicExportData> {
}

private void exportImageToDir(String imageDir) {
String safename = relic.relicId;
safename = safename.replace(" ","");
safename = safename.replace("/","");
String safename = Exporter.makeFilename(relic.relicId);
this.image = safename + ".png";
this.absImage = imageDir + "/" + this.image;
this.relImage = "relics/" + this.image;
Expand Down

0 comments on commit d4c8fa1

Please sign in to comment.