In order to run the game with an emulator called Redream, I had to decompress the compressed file for each directory, so I made a batch.
Install the package to unzip the 7z file. Install 7z with the following command:
sudo apt-get install -y p7zip-full
Create the following Python code and save it in a batch.py file.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import io
import os
import glob
arr = glob.glob("*7z")
#print(arr)
path_w = '7z.sh'
with open(path_w, mode='w') as f:
for str in arr:
dir = str.replace("[GDI] ","").replace("[CDI] ","").replace(".7z","").replace("'","")
tmpstr = str.replace("'","").replace(",","")
os.rename("./" + str , "./" + tmpstr)
try:
if not os.path.exists(dir):
cmds = "7z x '" + tmpstr + "' -o'" + dir + "'\n"
dels = "rm -rf '" + tmpstr + "'\n"
#print(cmds)
#print(dels)
f.write(cmds)
f.write(dels)
except OSError:
print("Error: " + dir)
I didn't write a comment on the source, so I'd like to explain it here.
#!/usr/bin/python
# -*- coding: utf-8 -*-
#This is the part that declares the package to use the provided methods.
import io
import os
import glob
#Only save files with the extension "7z" in the current directory to the array.
arr = glob.glob("*7z")
#The following Print is the code to check the contents of the saved array.
# print(arr)
#Unzip and delete the compressed file into a shell script file
#Specifies the name of the shell script file where the command is saved.
path_w = '7z.sh'
#Open shell script file to write mode
with open(path_w, mode='w') as f:
#Create a decompression / deletion command for each "7z" file.
for str in arr:
#Create the directory name to decompress from the compressed file name.
#Delete unnecessary character strings in the directory name.
dir = str.replace("[GDI] ","").replace("[CDI] ","").replace(".7z","").replace("'","")
#If the file name and directory name have the following character strings, the answer will fail, so
#Delete the character. And replace the file name as well.
tmpstr = str.replace("'","").replace(",","")
os.rename("./" + str , "./" + tmpstr)
try:
#If the directory name does not exist, do the following:
if not os.path.exists(dir):
#This command decompresses the compressed file.
cmds = "7z x '" + tmpstr + "' -o'" + dir + "'\n"
#This command deletes the unzipped files.
dels = "rm -rf '" + tmpstr + "'\n"
#This is the code to confirm the command.
#print(cmds)
#print(dels)
#Save the command in a shell script file.
f.write(cmds)
f.write(dels)
except OSError:
#Output when a directory-related error occurs.
print("Error: " + dir)
Run the Python code with the following command: When executed, a "7z.sh" file will be generated.
pi@raspberrypi:~/Downloads/redream/rom $ python batch.py
Check the contents of the file with the following command. You can see that the decompression / deletion command is generated for each compressed file name.
pi@raspberrypi:~/Downloads/redream/rom $ cat 7z.sh
7z x '[GDI] XXXXXXXX.7z' -o'XXXXXXXX'
rm -rf '[GDI] XXXXXXXX.7z'
7z x '[CDI] XXXXXXXX.7z' -o'XXXXXXXX'
rm -rf '[CDI] XXXXXXXX.7z'
Run the shell script file with the following command: When executed, the screen to decompress the compressed file is displayed. When the execution is finished, you can see that all the compressed files have been deleted. If it is possible that the file name is stopped due to an unexpected character string error, In that case, add replacement to the processing of file name / directory name. Then you should be able to solve it without any problems.
pi@raspberrypi:~/Downloads/redream/rom $ sh 7z.sh
If the capacity of the SD card is insufficient, the decompression of the file may fail, so be careful. (Lol)
With this, it was easy to put the game in Retropie OS, but Next, the specification of GDI / CDI and preview image file remains in game.xml. When running on Raspbian, it is not necessary to specify the above game.xml. It was troublesome to compress and decompress manually, so I made it. Was it useful? Exception handling is a little lacking, but please add it if necessary.
Recommended Posts