Added check to not use files under 128KiB
This commit is contained in:
13
README.md
13
README.md
@@ -1,6 +1,7 @@
|
|||||||
## Drastic to MelonDS
|
## Drastic to MelonDS
|
||||||
|
|
||||||
This script will convert the dsv save from drastic emulator to a melonDS save file
|
This script will convert the dsv save from drastic emulator to a melonDS save file
|
||||||
|
This also works for desmume to MelonDS save files since desmume also seems to add padding to the end of the file.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
@@ -17,6 +18,16 @@ optional arguments:
|
|||||||
-f, --force Overwrite the output file if it exists
|
-f, --force Overwrite the output file if it exists
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Install
|
||||||
|
|
||||||
|
Add it to a folder in your $PATH
|
||||||
|
|
||||||
|
```bash
|
||||||
|
install -Dm755 dr2mds.py ~/.local/bin/dr2mds
|
||||||
|
```
|
||||||
|
|
||||||
|
_For windows users just run the script from the folder_
|
||||||
|
|
||||||
### How to use
|
### How to use
|
||||||
|
|
||||||
You need python 3 installed.
|
You need python 3 installed.
|
||||||
@@ -33,7 +44,7 @@ You can also specify the output like
|
|||||||
./dr2mds.py "Pokemon Black.dsv" -o "PKMN.sav"
|
./dr2mds.py "Pokemon Black.dsv" -o "PKMN.sav"
|
||||||
```
|
```
|
||||||
|
|
||||||
### How does this works ?
|
### How does this work ?
|
||||||
|
|
||||||
MelonDS determines the type of save using exact byte count in the save file
|
MelonDS determines the type of save using exact byte count in the save file
|
||||||
|
|
||||||
|
|||||||
15
dr2mds.py
15
dr2mds.py
@@ -9,6 +9,16 @@ import os
|
|||||||
sys.tracebacklimit = 0
|
sys.tracebacklimit = 0
|
||||||
|
|
||||||
|
|
||||||
|
class SaveFileTooSmallError(Exception):
|
||||||
|
def __init__(self, size, message="Save file is smaller than 128KiB"):
|
||||||
|
self.size = size
|
||||||
|
self.message = message
|
||||||
|
super().__init__(self.message)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.size} is smaller than 131072 or 128KiB"
|
||||||
|
|
||||||
|
|
||||||
def closest2pow(n):
|
def closest2pow(n):
|
||||||
# int always returns the floor of the float
|
# int always returns the floor of the float
|
||||||
# log(n)/log(2) gives log base 2 of n
|
# log(n)/log(2) gives log base 2 of n
|
||||||
@@ -18,6 +28,11 @@ def closest2pow(n):
|
|||||||
def drastic2melonds(infile, outfile):
|
def drastic2melonds(infile, outfile):
|
||||||
with open(infile, "rb") as inf, open(outfile, "wb") as ouf:
|
with open(infile, "rb") as inf, open(outfile, "wb") as ouf:
|
||||||
in_bytes = os.stat(infile).st_size
|
in_bytes = os.stat(infile).st_size
|
||||||
|
if in_bytes < 131072:
|
||||||
|
print(f"The file {infile} seems to be smaller than 128KiB"
|
||||||
|
" and not a valid save file", file=sys.stderr)
|
||||||
|
raise SaveFileTooSmallError(in_bytes)
|
||||||
|
|
||||||
out_bytes = closest2pow(in_bytes)
|
out_bytes = closest2pow(in_bytes)
|
||||||
print(f"Reading {in_bytes} bytes from {infile}", file=sys.stderr)
|
print(f"Reading {in_bytes} bytes from {infile}", file=sys.stderr)
|
||||||
print(f"Writing {out_bytes} bytes to {outfile}", file=sys.stderr)
|
print(f"Writing {out_bytes} bytes to {outfile}", file=sys.stderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user