Skip to content

Commit

Permalink
Merge pull request #344 from PSP-Archive/mmcfixes
Browse files Browse the repository at this point in the history
MMC fixes
  • Loading branch information
Yoti authored Apr 21, 2024
2 parents ad967a9 + 9123026 commit fb5d2e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 44 deletions.
65 changes: 24 additions & 41 deletions contrib/PC/MagicMemoryCreator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
disk_check = tk.StringVar(m)
disk_check.set(0)



if ostype.lower() != 'linux' and ostype.lower() != 'darwin':
import wmi
import psutil
Expand All @@ -53,7 +51,6 @@
if 'removable' in part.opts:
windows_disk_letter[f'disk{str(drive.Index)}'] = part.mountpoint.split(':')[0]


elif ostype.lower() == 'linux':
out = subprocess.Popen(["lsblk | awk '{if ($3 == 1 && $1 ~ /^[a-zA-Z]+$/) {print $1}}'"], shell=True, stdout=subprocess.PIPE)
out = out.stdout.read().decode().splitlines()
Expand All @@ -79,7 +76,7 @@ def refresh():
m.destroy()
p = sys.executable
os.execl(p, p, *sys.argv)

def fmt_ms():

if ostype.lower() != 'linux':
Expand All @@ -103,8 +100,6 @@ def force_ss_func():
newWindow.destroy()
newWindow.update()



# Detect Memory Stick Size
if ostype.lower() == 'linux':
size = subprocess.Popen([f"fdisk --bytes -l /dev/{var.get()} | awk '{{print $5}}' | head -n 1"], shell=True, stdout=subprocess.PIPE)
Expand All @@ -113,7 +108,7 @@ def force_ss_func():
os.system(f'sudo umount /dev/{var.get()}1')
time.sleep(3)
os.system(f'sudo dd if=/dev/zero of=/dev/{var.get()} bs=512 count=4')

if size < 4294967296: # less than 4GB format to fat16, works best also Sony already does this as well.
os.system(f'echo -e "rm 1\nmklabel msdos\nmkpart primary fat16 61s 100%\ntoggle 1 lba\ntoggle 1 boot\nq" | sudo parted /dev/{var.get()}')
else: # 4GB or greater format to fat32, optional sector size to start at 2048 if issue occur with > 2048. This can cause the PSP (VSH) to think something is wrong
Expand All @@ -131,7 +126,6 @@ def force_ss_func():

newWindow.wait_window()


if force_ss:
os.system(f'echo -e "o\nn\np\n1\n2048\n\n\nt\n0b\na\nw" | sudo fdisk /dev/{var.get()}')
else:
Expand All @@ -150,11 +144,10 @@ def force_ss_func():
legacy['state'] = 'disabled'
go_check['state'] = 'disabled'
ipl_inject_only['state'] = 'disabled'
status.config(text='Formatting Memory Stick\nSelected!')
status.config(text='Formatting Memory Stick\nSelected!')
b.config(text='Format', command=fmt)
m.update()


def disable_go_check():
if check.get():
go_check['state'] = 'disabled'
Expand All @@ -164,13 +157,12 @@ def disable_go_check():
go_check['state'] = 'normal'
check.set(0)


def cleanup() -> None:
global go
if go:
shutil.rmtree("661_GO")
os.remove('661_GO.PBP')
os.remove('661_GO.PBP.dec')
shutil.rmtree("661GO")
os.remove('661GO.PBP')
os.remove('661GO.PBP.dec')
else:
shutil.rmtree("661")
os.remove('661.PBP')
Expand Down Expand Up @@ -198,13 +190,13 @@ def toggle_run(toggle) -> None:
format_ms.grid_remove()

def run() -> None:
b['state'] = "disabled"
x['state'] = "disabled"
b['text'] = "Please Wait..."
b['state'] = 'disabled'
x['state'] = 'disabled'
b['text'] = 'Please Wait...'
go_check['state'] = 'disabled'
legacy['state'] = 'disabled'
format_ms['state'] = 'disabled'
ipl_inject_only['state'] = "disabled"
ipl_inject_only['state'] = 'disabled'
global go

if not ipl_only.get():
Expand All @@ -218,7 +210,7 @@ def run() -> None:
with ZipFile('pspdecrypt-1.0-linux.zip', 'r') as zObject:
zObject.extractall(path=f'{os.getcwd()}/')
os.system('chmod 755 pspdecrypt')
x['state'] = "normal"
x['state'] = 'normal'
elif ostype == 'Windows':
resp = requests.get('https://github.com/John-K/pspdecrypt/releases/download/1.0/pspdecrypt-1.0-windows.zip', timeout=10, verify=False)
with open('pspdecrypt-1.0-windows.zip', 'wb') as f:
Expand All @@ -227,7 +219,7 @@ def run() -> None:
with ZipFile('pspdecrypt-1.0-windows.zip', 'r') as zObject:
zObject.extractall(path=f'{os.getcwd()}\\')
os.system('oschmod 755 pspdecrypt.exe')
x['state'] = "normal"
x['state'] = 'normal'
elif ostype == 'Darwin':
resp = requests.get('https://github.com/John-K/pspdecrypt/releases/download/1.0/pspdecrypt-1.0-macos.zip', timeout=10, verify=False)
with open('pspdecrypt-1.0-macos.zip', 'wb') as f:
Expand All @@ -236,7 +228,7 @@ def run() -> None:
with ZipFile('pspdecrypt-1.0-macos.zip', 'r') as zObject:
zObject.extractall(path=f'{os.getcwd()}/')
os.system('oschmod 755 pspdecrypt')
x['state'] = "normal"
x['state'] = 'normal'
else:
print('\nERR: unsupported platform...\n')
return
Expand All @@ -245,7 +237,7 @@ def run() -> None:
if go:
resp = requests.get('http://du01.psp.update.playstation.org/update/psp/image2/us/2014_1212_fd0f7d0798b4f6e6d32ef95836740527/EBOOT.PBP', timeout=10, verify=False)
if resp:
with open('661_GO.PBP', 'wb') as f:
with open('661GO.PBP', 'wb') as f:
f.write(resp.content)
resp.close()
else:
Expand All @@ -261,18 +253,18 @@ def run() -> None:

if ostype == 'Linux' or ostype == 'Darwin':
if go:
os.system('./pspdecrypt -e 661_GO.PBP')
shutil.copytree("661_GO/F0", "TM/DCARK", dirs_exist_ok=True)
shutil.copytree("661_GO/F1", "TM/DCARK", dirs_exist_ok=True)
os.system('./pspdecrypt -e 661GO.PBP')
shutil.copytree("661GO/F0", "TM/DCARK", dirs_exist_ok=True)
shutil.copytree("661GO/F1", "TM/DCARK", dirs_exist_ok=True)
else:
os.system('./pspdecrypt -e 661.PBP')
shutil.copytree("661/F0", "TM/DCARK", dirs_exist_ok=True)
shutil.copytree("661/F1", "TM/DCARK", dirs_exist_ok=True)
else:
if go:
os.system('.\\pspdecrypt.exe -e 661_GO.PBP')
shutil.copytree("661_GO\\F0\\", "TM\\DCARK\\", dirs_exist_ok=True)
shutil.copytree("661_GO\\F1\\", "TM\\DCARK\\", dirs_exist_ok=True)
os.system('.\\pspdecrypt.exe -e 661GO.PBP')
shutil.copytree("661GO\\F0\\", "TM\\DCARK\\", dirs_exist_ok=True)
shutil.copytree("661GO\\F1\\", "TM\\DCARK\\", dirs_exist_ok=True)
else:
os.system('.\\pspdecrypt.exe -e 661.PBP')
shutil.copytree("661\\F0\\", "TM\\DCARK\\", dirs_exist_ok=True)
Expand Down Expand Up @@ -332,9 +324,8 @@ def run() -> None:
msipl_installer.main(msipl_installer.Args(f'{int(deviceID[var.get()][-1])}', False, 'msipl.bin', False, False ))
status.config(fg='green', text="DONE!")


b['text'] = "DONE!"
x['state'] = "normal"
b['text'] = 'DONE!'
x['state'] = 'normal'

if not ipl_only.get():
cleanup()
Expand All @@ -348,7 +339,6 @@ def run() -> None:
print('\nSorry this needs to run as root/admin!\n')
sys.exit(1)


# Setup
m.minsize(320, 230)

Expand All @@ -361,25 +351,19 @@ def run() -> None:
#internal=tk.Checkbutton(m, text='Show Internal Disk', variable=disk_check, onvalue=1, offvalue=0)
#internal.grid(row=3, column=1)



go_check=tk.Checkbutton(m, text='PSP GO Model (ONLY!)', command=go_update)
go_check=tk.Checkbutton(m, text='PSP Go Model (ONLY!)', command=go_update)
go_check.grid(sticky="W", row=3, column=0)

legacy=tk.Checkbutton(m, text="Legacy IPL ( 1000s and early 2000s ONLY )", variable=check, command=disable_go_check)
legacy=tk.Checkbutton(m, text="Legacy IPL (1000s and early 2000s ONLY!)", variable=check, command=disable_go_check)
legacy.grid(row=4, column=0)



format_ms=tk.Checkbutton(m, text='Format Memory Stick', variable=format_ms_check, command=fmt_ms)


b=tk.Button(m, text='Run', command=run)
b.grid(row=1,column=1)
r=tk.Button(m, text='Refresh', command=refresh)
r.grid(row=6, column=0, sticky='S')


x=tk.Button(m, text='Exit', command=m.destroy)
x.grid(row=2,column=1)

Expand All @@ -390,4 +374,3 @@ def run() -> None:
ipl_inject_only.grid(row=2, column=0, sticky='W')

m.mainloop()

2 changes: 0 additions & 2 deletions contrib/PC/MagicMemoryCreator/msipl_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __init__(self, data):

(self.boot_signature,) = struct.unpack('<H', data[510:])


def main(args):
if is_windows:
diskID = f'\\\\.\\PHYSICALDRIVE{args.pdisk}'
Expand Down Expand Up @@ -86,7 +85,6 @@ def checkDiskType():
def openDisk():
return open(diskID, 'rb+')


else:
diskID = f'/dev/{args.devname}'

Expand Down
2 changes: 1 addition & 1 deletion contrib/PC/MagicMemoryCreator/run_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ fltmc >nul 2>&1 || (
goto :eof
)
cd /d %~dp0
pythonw.exe main.py
start pythonw.exe main.py

0 comments on commit fb5d2e7

Please sign in to comment.