diff options
5 files changed, 18 insertions, 17 deletions
diff --git a/src/com/sneed/pkrandom/ctr/NCCH.java b/src/com/sneed/pkrandom/ctr/NCCH.java index ccf735c..8db5a4e 100644 --- a/src/com/sneed/pkrandom/ctr/NCCH.java +++ b/src/com/sneed/pkrandom/ctr/NCCH.java @@ -251,11 +251,7 @@ public class NCCH { this.reopenROM(); // Initialize new ROM - File file = new File(filename); - if (!file.canWrite()) { - throw new CannotWriteToLocationException("The randomizer cannot write to this location: " + filename); - } - RandomAccessFile fNew = new RandomAccessFile(file, "rw"); + RandomAccessFile fNew = new RandomAccessFile(filename, "rw"); // Read the header and exheader and write it to the output ROM byte[] header = new byte[header_and_exheader_size]; diff --git a/src/com/sneed/pkrandom/newnds/NDSRom.java b/src/com/sneed/pkrandom/newnds/NDSRom.java index 1828b10..61e6dee 100755 --- a/src/com/sneed/pkrandom/newnds/NDSRom.java +++ b/src/com/sneed/pkrandom/newnds/NDSRom.java @@ -231,10 +231,6 @@ public class NDSRom { this.reopenROM(); // Initialize new ROM - File file = new File(filename); - if (!file.canWrite()) { - throw new CannotWriteToLocationException("The randomizer cannot write to this location: " + filename); - } RandomAccessFile fNew = new RandomAccessFile(filename, "rw"); int headersize = readFromFile(this.baseRom, 0x84, 4); 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; } } |