summaryrefslogtreecommitdiff
path: root/src/com/sneed/pkrandom/romhandlers
diff options
context:
space:
mode:
authortom-overton <tom.overton@outlook.com>2022-07-12 21:28:08 -0700
committerrafa_99 <raroma09@gmail.com>2022-07-14 01:22:14 +0100
commit551615aba7baa32ae714da0c367f0d729817c9c3 (patch)
tree0c561b80bab592b7e0cb8a27b764861707fcbe8f /src/com/sneed/pkrandom/romhandlers
parent50db76cfa89dbf7d6292800bc90f01208d5d3620 (diff)
Make the logic for not being able to write to a location actually work
Diffstat (limited to 'src/com/sneed/pkrandom/romhandlers')
-rw-r--r--src/com/sneed/pkrandom/romhandlers/Abstract3DSRomHandler.java7
-rwxr-xr-xsrc/com/sneed/pkrandom/romhandlers/AbstractDSRomHandler.java9
-rwxr-xr-xsrc/com/sneed/pkrandom/romhandlers/AbstractGBRomHandler.java9
3 files changed, 17 insertions, 8 deletions
diff --git a/src/com/sneed/pkrandom/romhandlers/Abstract3DSRomHandler.java b/src/com/sneed/pkrandom/romhandlers/Abstract3DSRomHandler.java
index b5cd9a2..5bd08f9 100644
--- a/src/com/sneed/pkrandom/romhandlers/Abstract3DSRomHandler.java
+++ b/src/com/sneed/pkrandom/romhandlers/Abstract3DSRomHandler.java
@@ -27,6 +27,7 @@ package com.sneed.pkrandom.romhandlers;
import com.sneed.pkrandom.FileFunctions;
import com.sneed.pkrandom.ctr.GARCArchive;
import com.sneed.pkrandom.ctr.NCCH;
+import com.sneed.pkrandom.exceptions.CannotWriteToLocationException;
import com.sneed.pkrandom.exceptions.EncryptedROMException;
import com.sneed.pkrandom.exceptions.RandomizerIOException;
import com.sneed.pkrandom.pokemon.Type;
@@ -88,7 +89,11 @@ public abstract class Abstract3DSRomHandler extends AbstractRomHandler {
savingROM();
baseRom.saveAsNCCH(filename, getGameAcronym(), seed);
} catch (IOException | NoSuchAlgorithmException e) {
- throw new RandomizerIOException(e);
+ if (e.getMessage().contains("Access is denied")) {
+ throw new CannotWriteToLocationException("The randomizer cannot write to this location: " + filename);
+ } else {
+ throw new RandomizerIOException(e);
+ }
}
return true;
}
diff --git a/src/com/sneed/pkrandom/romhandlers/AbstractDSRomHandler.java b/src/com/sneed/pkrandom/romhandlers/AbstractDSRomHandler.java
index 7ce0cbf..09be3d8 100755
--- a/src/com/sneed/pkrandom/romhandlers/AbstractDSRomHandler.java
+++ b/src/com/sneed/pkrandom/romhandlers/AbstractDSRomHandler.java
@@ -5,7 +5,7 @@ package com.sneed.pkrandom.romhandlers;
/*-- which standardises common DS functions. --*/
/*-- --*/
/*-- Part of "Universal Pokemon Randomizer ZX" by the UPR-ZX team --*/
-/*-- Originally part of "Universal Pokemon Randomizer" by sneed --*/
+/*-- Originally part of "Universal Pokemon Randomizer" by sneed --*/
/*-- Pokemon and any associated names and the like are --*/
/*-- trademark and (C) Nintendo 1996-2020. --*/
/*-- --*/
@@ -33,6 +33,7 @@ import java.util.Random;
import com.sneed.pkrandom.FileFunctions;
import com.sneed.pkrandom.RomFunctions;
+import com.sneed.pkrandom.exceptions.CannotWriteToLocationException;
import com.sneed.pkrandom.exceptions.RandomizerIOException;
import com.sneed.pkrandom.newnds.NARCArchive;
import com.sneed.pkrandom.newnds.NDSRom;
@@ -90,7 +91,11 @@ public abstract class AbstractDSRomHandler extends AbstractRomHandler {
try {
baseRom.saveTo(filename);
} catch (IOException e) {
- throw new RandomizerIOException(e);
+ if (e.getMessage().contains("Access is denied")) {
+ throw new CannotWriteToLocationException("The randomizer cannot write to this location: " + filename);
+ } else {
+ throw new RandomizerIOException(e);
+ }
}
return true;
}
diff --git a/src/com/sneed/pkrandom/romhandlers/AbstractGBRomHandler.java b/src/com/sneed/pkrandom/romhandlers/AbstractGBRomHandler.java
index 6d24f1f..a11cce5 100755
--- a/src/com/sneed/pkrandom/romhandlers/AbstractGBRomHandler.java
+++ b/src/com/sneed/pkrandom/romhandlers/AbstractGBRomHandler.java
@@ -71,15 +71,14 @@ public abstract class AbstractGBRomHandler extends AbstractRomHandler {
public boolean saveRomFile(String filename, long seed) {
savingRom();
try {
- File file = new File(filename);
- if (!file.canWrite()) {
- throw new CannotWriteToLocationException("The randomizer cannot write to this location: " + filename);
- }
- FileOutputStream fos = new FileOutputStream(file);
+ FileOutputStream fos = new FileOutputStream(filename);
fos.write(rom);
fos.close();
return true;
} catch (IOException ex) {
+ if (ex.getMessage().contains("Access is denied")) {
+ throw new CannotWriteToLocationException("The randomizer cannot write to this location: " + filename);
+ }
return false;
}
}