mirror of
https://github.com/ihaveamac/custom-install.git
synced 2026-01-21 14:06:02 +00:00
Compare commits
61 Commits
module-new
...
v2.1b4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d7be0812e | ||
|
|
8c60eecec5 | ||
|
|
653569093d | ||
|
|
adccac9ee7 | ||
|
|
8629cbee8e | ||
|
|
740844e57a | ||
|
|
d847043045 | ||
|
|
217a508bf3 | ||
|
|
42ec2d760a | ||
|
|
938d8fd6aa | ||
|
|
ac0be9d61d | ||
|
|
d231e9c043 | ||
|
|
9c3c4ce5f9 | ||
|
|
6a324b9388 | ||
|
|
647e56cf05 | ||
|
|
643e4e4976 | ||
|
|
09ed0093df | ||
|
|
9b7346c919 | ||
|
|
38f5e2b0e6 | ||
|
|
f48e177604 | ||
|
|
4ca2c59b5a | ||
|
|
7a68b23365 | ||
|
|
1dec5175ea | ||
|
|
4d223ed931 | ||
|
|
46a0d985a7 | ||
|
|
37112682a0 | ||
|
|
9c777adf26 | ||
|
|
b3eae08f27 | ||
|
|
5f49493dfb | ||
|
|
fbc553f5c7 | ||
|
|
68d9026524 | ||
|
|
46ac9cd809 | ||
|
|
40a8d2d684 | ||
|
|
4ec5bce712 | ||
|
|
d27e181c40 | ||
|
|
8ed6ca54cc | ||
|
|
0dcaaedda7 | ||
|
|
f904049c06 | ||
|
|
7b121f5212 | ||
|
|
1b2b0d06db | ||
|
|
6623ffb439 | ||
|
|
4733997132 | ||
|
|
9fc509489f | ||
|
|
2636c5923c | ||
|
|
cfa46abea5 | ||
|
|
d91c567fc5 | ||
|
|
188be9b9d6 | ||
|
|
616f9031b2 | ||
|
|
b8bd9371dd | ||
|
|
b69dfb0a46 | ||
|
|
e0573809bb | ||
|
|
46ce6ab76c | ||
|
|
fcf47e0564 | ||
|
|
a529ecf760 | ||
|
|
793d923240 | ||
|
|
918111dedf | ||
|
|
47f22313b4 | ||
|
|
5d60715d94 | ||
|
|
aad1accca3 | ||
|
|
945b0a377b | ||
|
|
707b852db3 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -18,3 +18,6 @@ venv/
|
|||||||
=======
|
=======
|
||||||
|
|
||||||
*.pyc
|
*.pyc
|
||||||
|
/build/
|
||||||
|
/dist/
|
||||||
|
/custom-install-finalize.3dsx
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2019 Ian Burgwin
|
Copyright (c) 2019-2021 Ian Burgwin
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[]() 
|
[]() 
|
||||||
|
|
||||||
# custom-install
|
# custom-install
|
||||||
Experimental script to automate the process of a manual title install for Nintendo 3DS. Originally created late June 2019.
|
Installs a title directly to an SD card for the Nintendo 3DS. Originally created late June 2019.
|
||||||
|
|
||||||
## Summary
|
## Summary
|
||||||
|
|
||||||
|
|||||||
443
ci-gui.py
443
ci-gui.py
@@ -5,7 +5,7 @@
|
|||||||
# You can find the full license text in LICENSE.md in the root of this project.
|
# You can find the full license text in LICENSE.md in the root of this project.
|
||||||
|
|
||||||
from os import environ, scandir
|
from os import environ, scandir
|
||||||
from os.path import abspath, join, isfile, dirname
|
from os.path import abspath, basename, dirname, join, isfile
|
||||||
from sys import exc_info, platform
|
from sys import exc_info, platform
|
||||||
from threading import Thread, Lock
|
from threading import Thread, Lock
|
||||||
from time import strftime
|
from time import strftime
|
||||||
@@ -16,13 +16,18 @@ import tkinter.filedialog as fd
|
|||||||
import tkinter.messagebox as mb
|
import tkinter.messagebox as mb
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from pyctr.crypto import MissingSeedError, CryptoEngine, load_seeddb
|
||||||
from pyctr.crypto.engine import b9_paths
|
from pyctr.crypto.engine import b9_paths
|
||||||
from pyctr.util import config_dirs
|
from pyctr.util import config_dirs
|
||||||
|
from pyctr.type.cdn import CDNError
|
||||||
|
from pyctr.type.cia import CIAError
|
||||||
|
from pyctr.type.tmd import TitleMetadataError
|
||||||
|
|
||||||
from custominstall import CustomInstall
|
from custominstall import CustomInstall, CI_VERSION, load_cifinish, InvalidCIFinishError, InstallStatus
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import List
|
from os import PathLike
|
||||||
|
from typing import Dict, List, Union
|
||||||
|
|
||||||
is_windows = platform == 'win32'
|
is_windows = platform == 'win32'
|
||||||
taskbar = None
|
taskbar = None
|
||||||
@@ -52,6 +57,10 @@ except KeyError:
|
|||||||
seeddb_paths.insert(0, join(file_parent, 'seeddb.bin'))
|
seeddb_paths.insert(0, join(file_parent, 'seeddb.bin'))
|
||||||
|
|
||||||
|
|
||||||
|
def clamp(n, smallest, largest):
|
||||||
|
return max(smallest, min(n, largest))
|
||||||
|
|
||||||
|
|
||||||
def find_first_file(paths):
|
def find_first_file(paths):
|
||||||
for p in paths:
|
for p in paths:
|
||||||
if isfile(p):
|
if isfile(p):
|
||||||
@@ -63,6 +72,18 @@ default_b9_path = find_first_file(b9_paths)
|
|||||||
default_seeddb_path = find_first_file(seeddb_paths)
|
default_seeddb_path = find_first_file(seeddb_paths)
|
||||||
default_movable_sed_path = find_first_file([join(file_parent, 'movable.sed')])
|
default_movable_sed_path = find_first_file([join(file_parent, 'movable.sed')])
|
||||||
|
|
||||||
|
if default_seeddb_path:
|
||||||
|
load_seeddb(default_seeddb_path)
|
||||||
|
|
||||||
|
statuses = {
|
||||||
|
InstallStatus.Waiting: 'Waiting',
|
||||||
|
InstallStatus.Starting: 'Starting',
|
||||||
|
InstallStatus.Writing: 'Writing',
|
||||||
|
InstallStatus.Finishing: 'Finishing',
|
||||||
|
InstallStatus.Done: 'Done',
|
||||||
|
InstallStatus.Failed: 'Failed',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConsoleFrame(ttk.Frame):
|
class ConsoleFrame(ttk.Frame):
|
||||||
def __init__(self, parent: tk.BaseWidget = None, starting_lines: 'List[str]' = None):
|
def __init__(self, parent: tk.BaseWidget = None, starting_lines: 'List[str]' = None):
|
||||||
@@ -94,13 +115,155 @@ class ConsoleFrame(ttk.Frame):
|
|||||||
self.text.configure(state=tk.DISABLED)
|
self.text.configure(state=tk.DISABLED)
|
||||||
|
|
||||||
|
|
||||||
|
def simple_listbox_frame(parent, title: 'str', items: 'List[str]'):
|
||||||
|
frame = ttk.LabelFrame(parent, text=title)
|
||||||
|
frame.rowconfigure(0, weight=1)
|
||||||
|
frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL)
|
||||||
|
scrollbar.grid(row=0, column=1, sticky=tk.NSEW)
|
||||||
|
|
||||||
|
box = tk.Listbox(frame, highlightthickness=0, yscrollcommand=scrollbar.set, selectmode=tk.EXTENDED)
|
||||||
|
box.grid(row=0, column=0, sticky=tk.NSEW)
|
||||||
|
scrollbar.config(command=box.yview)
|
||||||
|
|
||||||
|
box.insert(tk.END, *items)
|
||||||
|
|
||||||
|
box.config(height=clamp(len(items), 3, 10))
|
||||||
|
|
||||||
|
return frame
|
||||||
|
|
||||||
|
|
||||||
|
class TitleReadFailResults(tk.Toplevel):
|
||||||
|
def __init__(self, parent: tk.Tk = None, *, failed: 'Dict[str, str]'):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.parent = parent
|
||||||
|
|
||||||
|
self.wm_withdraw()
|
||||||
|
self.wm_transient(self.parent)
|
||||||
|
self.grab_set()
|
||||||
|
self.wm_title('Failed to add titles')
|
||||||
|
|
||||||
|
self.rowconfigure(0, weight=1)
|
||||||
|
self.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
outer_container = ttk.Frame(self)
|
||||||
|
outer_container.grid(sticky=tk.NSEW)
|
||||||
|
outer_container.rowconfigure(0, weight=0)
|
||||||
|
outer_container.rowconfigure(1, weight=1)
|
||||||
|
outer_container.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
message_label = ttk.Label(outer_container, text="Some titles couldn't be added.")
|
||||||
|
message_label.grid(row=0, column=0, sticky=tk.NSEW, padx=10, pady=10)
|
||||||
|
|
||||||
|
treeview_frame = ttk.Frame(outer_container)
|
||||||
|
treeview_frame.grid(row=1, column=0, sticky=tk.NSEW)
|
||||||
|
treeview_frame.rowconfigure(0, weight=1)
|
||||||
|
treeview_frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
treeview_scrollbar = ttk.Scrollbar(treeview_frame, orient=tk.VERTICAL)
|
||||||
|
treeview_scrollbar.grid(row=0, column=1, sticky=tk.NSEW)
|
||||||
|
|
||||||
|
treeview = ttk.Treeview(treeview_frame, yscrollcommand=treeview_scrollbar.set)
|
||||||
|
treeview.grid(row=0, column=0, sticky=tk.NSEW, padx=10, pady=(0, 10))
|
||||||
|
treeview.configure(columns=('filepath', 'reason'), show='headings')
|
||||||
|
|
||||||
|
treeview.column('filepath', width=200, anchor=tk.W)
|
||||||
|
treeview.heading('filepath', text='File path')
|
||||||
|
treeview.column('reason', width=400, anchor=tk.W)
|
||||||
|
treeview.heading('reason', text='Reason')
|
||||||
|
|
||||||
|
treeview_scrollbar.configure(command=treeview.yview)
|
||||||
|
|
||||||
|
for path, reason in failed.items():
|
||||||
|
treeview.insert('', tk.END, text=path, iid=path, values=(basename(path), reason))
|
||||||
|
|
||||||
|
ok_frame = ttk.Frame(outer_container)
|
||||||
|
ok_frame.grid(row=2, column=0, sticky=tk.NSEW, padx=10, pady=(0, 10))
|
||||||
|
ok_frame.rowconfigure(0, weight=1)
|
||||||
|
ok_frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
ok_button = ttk.Button(ok_frame, text='OK', command=self.destroy)
|
||||||
|
ok_button.grid(row=0, column=0)
|
||||||
|
|
||||||
|
self.wm_deiconify()
|
||||||
|
|
||||||
|
|
||||||
|
class InstallResults(tk.Toplevel):
|
||||||
|
def __init__(self, parent: tk.Tk = None, *, install_state: 'Dict[str, List[str]]', copied_3dsx: bool,
|
||||||
|
application_count: int):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.parent = parent
|
||||||
|
|
||||||
|
self.wm_withdraw()
|
||||||
|
self.wm_transient(self.parent)
|
||||||
|
self.grab_set()
|
||||||
|
self.wm_title('Install results')
|
||||||
|
|
||||||
|
self.rowconfigure(0, weight=1)
|
||||||
|
self.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
outer_container = ttk.Frame(self)
|
||||||
|
outer_container.grid(sticky=tk.NSEW)
|
||||||
|
outer_container.rowconfigure(0, weight=0)
|
||||||
|
outer_container.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
if install_state['failed'] and install_state['installed']:
|
||||||
|
# some failed and some worked
|
||||||
|
message = ('Some titles were installed, some failed. Please check the output for more details.\n'
|
||||||
|
'The ones that were installed can be finished with custom-install-finalize.')
|
||||||
|
elif install_state['failed'] and not install_state['installed']:
|
||||||
|
# all failed
|
||||||
|
message = 'All titles failed to install. Please check the output for more details.'
|
||||||
|
elif install_state['installed'] and not install_state['failed']:
|
||||||
|
# all worked
|
||||||
|
message = 'All titles were installed.'
|
||||||
|
else:
|
||||||
|
message = 'Nothing was installed.'
|
||||||
|
|
||||||
|
if install_state['installed'] and copied_3dsx:
|
||||||
|
message += '\n\ncustom-install-finalize has been copied to the SD card.'
|
||||||
|
|
||||||
|
if application_count >= 300:
|
||||||
|
message += (f'\n\nWarning: {application_count} installed applications were detected.\n'
|
||||||
|
f'The HOME Menu will only show 300 icons.\n'
|
||||||
|
f'Some applications (not updates or DLC) will need to be deleted.')
|
||||||
|
|
||||||
|
message_label = ttk.Label(outer_container, text=message)
|
||||||
|
message_label.grid(row=0, column=0, sticky=tk.NSEW, padx=10, pady=10)
|
||||||
|
|
||||||
|
if install_state['installed']:
|
||||||
|
outer_container.rowconfigure(1, weight=1)
|
||||||
|
frame = simple_listbox_frame(outer_container, 'Installed', install_state['installed'])
|
||||||
|
frame.grid(row=1, column=0, sticky=tk.NSEW, padx=10, pady=(0, 10))
|
||||||
|
|
||||||
|
if install_state['failed']:
|
||||||
|
outer_container.rowconfigure(2, weight=1)
|
||||||
|
frame = simple_listbox_frame(outer_container, 'Failed', install_state['failed'])
|
||||||
|
frame.grid(row=2, column=0, sticky=tk.NSEW, padx=10, pady=(0, 10))
|
||||||
|
|
||||||
|
ok_frame = ttk.Frame(outer_container)
|
||||||
|
ok_frame.grid(row=3, column=0, sticky=tk.NSEW, padx=10, pady=(0, 10))
|
||||||
|
ok_frame.rowconfigure(0, weight=1)
|
||||||
|
ok_frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
ok_button = ttk.Button(ok_frame, text='OK', command=self.destroy)
|
||||||
|
ok_button.grid(row=0, column=0)
|
||||||
|
|
||||||
|
self.wm_deiconify()
|
||||||
|
|
||||||
|
|
||||||
class CustomInstallGUI(ttk.Frame):
|
class CustomInstallGUI(ttk.Frame):
|
||||||
console = None
|
console = None
|
||||||
|
b9_loaded = False
|
||||||
|
|
||||||
def __init__(self, parent: tk.Tk = None):
|
def __init__(self, parent: tk.Tk = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
||||||
|
# readers to give to CustomInstall at the install
|
||||||
|
self.readers = {}
|
||||||
|
|
||||||
self.lock = Lock()
|
self.lock = Lock()
|
||||||
|
|
||||||
self.log_messages = []
|
self.log_messages = []
|
||||||
@@ -130,15 +293,27 @@ class CustomInstallGUI(ttk.Frame):
|
|||||||
f = fd.askdirectory(parent=parent, title='Select SD root (the directory or drive that contains '
|
f = fd.askdirectory(parent=parent, title='Select SD root (the directory or drive that contains '
|
||||||
'"Nintendo 3DS")', initialdir=file_parent, mustexist=True)
|
'"Nintendo 3DS")', initialdir=file_parent, mustexist=True)
|
||||||
if f:
|
if f:
|
||||||
|
cifinish_path = join(f, 'cifinish.bin')
|
||||||
|
try:
|
||||||
|
load_cifinish(cifinish_path)
|
||||||
|
except InvalidCIFinishError:
|
||||||
|
self.show_error(f'{cifinish_path} was corrupt!\n\n'
|
||||||
|
f'This could mean an issue with the SD card or the filesystem. Please check it for errors.\n'
|
||||||
|
f'It is also possible, though less likely, to be an issue with custom-install.\n\n'
|
||||||
|
f'Stopping now to prevent possible issues. If you want to try again, delete cifinish.bin from the SD card and re-run custom-install.')
|
||||||
|
return
|
||||||
|
|
||||||
sd_selected.delete('1.0', tk.END)
|
sd_selected.delete('1.0', tk.END)
|
||||||
sd_selected.insert(tk.END, f)
|
sd_selected.insert(tk.END, f)
|
||||||
|
|
||||||
sd_msed_path = find_first_file([join(f, 'gm9', 'out', 'movable.sed'), join(f, 'movable.sed')])
|
for filename in ['boot9.bin', 'seeddb.bin', 'movable.sed']:
|
||||||
if sd_msed_path:
|
path = auto_input_filename(self, f, filename)
|
||||||
self.log('Found movable.sed on SD card at ' + sd_msed_path)
|
if filename == 'boot9.bin':
|
||||||
box = self.file_picker_textboxes['movable.sed']
|
self.check_b9_loaded()
|
||||||
box.delete('1.0', tk.END)
|
self.enable_buttons()
|
||||||
box.insert(tk.END, sd_msed_path)
|
if filename == 'seeddb.bin':
|
||||||
|
load_seeddb(path)
|
||||||
|
|
||||||
|
|
||||||
sd_type_label = ttk.Label(file_pickers, text='SD root')
|
sd_type_label = ttk.Label(file_pickers, text='SD root')
|
||||||
sd_type_label.grid(row=0, column=0)
|
sd_type_label.grid(row=0, column=0)
|
||||||
@@ -151,14 +326,25 @@ class CustomInstallGUI(ttk.Frame):
|
|||||||
|
|
||||||
self.file_picker_textboxes['sd'] = sd_selected
|
self.file_picker_textboxes['sd'] = sd_selected
|
||||||
|
|
||||||
|
def auto_input_filename(self, f, filename):
|
||||||
|
sd_msed_path = find_first_file([join(f, 'gm9', 'out', filename), join(f, filename)])
|
||||||
|
if sd_msed_path:
|
||||||
|
self.log('Found ' + filename + ' on SD card at ' + sd_msed_path)
|
||||||
|
if filename.endswith('bin'):
|
||||||
|
filename = filename.split('.')[0]
|
||||||
|
box = self.file_picker_textboxes[filename]
|
||||||
|
box.delete('1.0', tk.END)
|
||||||
|
box.insert(tk.END, sd_msed_path)
|
||||||
|
return sd_msed_path
|
||||||
# This feels so wrong.
|
# This feels so wrong.
|
||||||
def create_required_file_picker(type_name, types, default, row):
|
def create_required_file_picker(type_name, types, default, row, callback=lambda filename: None):
|
||||||
def internal_callback():
|
def internal_callback():
|
||||||
f = fd.askopenfilename(parent=parent, title='Select ' + type_name, filetypes=types,
|
f = fd.askopenfilename(parent=parent, title='Select ' + type_name, filetypes=types,
|
||||||
initialdir=file_parent)
|
initialdir=file_parent)
|
||||||
if f:
|
if f:
|
||||||
selected.delete('1.0', tk.END)
|
selected.delete('1.0', tk.END)
|
||||||
selected.insert(tk.END, f)
|
selected.insert(tk.END, f)
|
||||||
|
callback(f)
|
||||||
|
|
||||||
type_label = ttk.Label(file_pickers, text=type_name)
|
type_label = ttk.Label(file_pickers, text=type_name)
|
||||||
type_label.grid(row=row, column=0)
|
type_label.grid(row=row, column=0)
|
||||||
@@ -173,71 +359,104 @@ class CustomInstallGUI(ttk.Frame):
|
|||||||
|
|
||||||
self.file_picker_textboxes[type_name] = selected
|
self.file_picker_textboxes[type_name] = selected
|
||||||
|
|
||||||
create_required_file_picker('boot9', [('boot9 file', '*.bin')], default_b9_path, 1)
|
def b9_callback(path: 'Union[PathLike, bytes, str]'):
|
||||||
create_required_file_picker('seeddb', [('seeddb file', '*.bin')], default_seeddb_path, 2)
|
self.check_b9_loaded()
|
||||||
|
self.enable_buttons()
|
||||||
|
|
||||||
|
def seeddb_callback(path: 'Union[PathLike, bytes, str]'):
|
||||||
|
load_seeddb(path)
|
||||||
|
|
||||||
|
create_required_file_picker('boot9', [('boot9 file', '*.bin')], default_b9_path, 1, b9_callback)
|
||||||
|
create_required_file_picker('seeddb', [('seeddb file', '*.bin')], default_seeddb_path, 2, seeddb_callback)
|
||||||
create_required_file_picker('movable.sed', [('movable.sed file', '*.sed')], default_movable_sed_path, 3)
|
create_required_file_picker('movable.sed', [('movable.sed file', '*.sed')], default_movable_sed_path, 3)
|
||||||
|
|
||||||
# ---------------------------------------------------------------- #
|
# ---------------------------------------------------------------- #
|
||||||
# create buttons to add cias
|
# create buttons to add cias
|
||||||
listbox_buttons = ttk.Frame(self)
|
titlelist_buttons = ttk.Frame(self)
|
||||||
listbox_buttons.grid(row=1, column=0)
|
titlelist_buttons.grid(row=1, column=0)
|
||||||
|
|
||||||
def add_cias_callback():
|
def add_cias_callback():
|
||||||
files = fd.askopenfilenames(parent=parent, title='Select CIA files', filetypes=[('CIA files', '*.cia')],
|
files = fd.askopenfilenames(parent=parent, title='Select CIA files', filetypes=[('CIA files', '*.cia')],
|
||||||
initialdir=file_parent)
|
initialdir=file_parent)
|
||||||
|
results = {}
|
||||||
for f in files:
|
for f in files:
|
||||||
self.add_cia(f)
|
success, reason = self.add_cia(f)
|
||||||
|
if not success:
|
||||||
|
results[f] = reason
|
||||||
|
|
||||||
add_cias = ttk.Button(listbox_buttons, text='Add CIAs', command=add_cias_callback)
|
if results:
|
||||||
|
title_read_fail_window = TitleReadFailResults(self.parent, failed=results)
|
||||||
|
title_read_fail_window.focus()
|
||||||
|
self.sort_treeview()
|
||||||
|
|
||||||
|
add_cias = ttk.Button(titlelist_buttons, text='Add CIAs', command=add_cias_callback)
|
||||||
add_cias.grid(row=0, column=0)
|
add_cias.grid(row=0, column=0)
|
||||||
|
|
||||||
def add_cias_callback():
|
def add_cdn_callback():
|
||||||
d = fd.askdirectory(parent=parent, title='Select folder containing title contents in CDN format',
|
d = fd.askdirectory(parent=parent, title='Select folder containing title contents in CDN format',
|
||||||
initialdir=file_parent)
|
initialdir=file_parent)
|
||||||
if d:
|
if d:
|
||||||
if isfile(join(d, 'tmd')):
|
if isfile(join(d, 'tmd')):
|
||||||
self.add_cia(d)
|
success, reason = self.add_cia(d)
|
||||||
|
if not success:
|
||||||
|
self.show_error(f"Couldn't add {basename(d)}: {reason}")
|
||||||
|
else:
|
||||||
|
self.sort_treeview()
|
||||||
else:
|
else:
|
||||||
self.show_error('tmd file not found in the CDN directory:\n' + d)
|
self.show_error('tmd file not found in the CDN directory:\n' + d)
|
||||||
|
|
||||||
add_cias = ttk.Button(listbox_buttons, text='Add CDN title folder', command=add_cias_callback)
|
add_cdn = ttk.Button(titlelist_buttons, text='Add CDN title folder', command=add_cdn_callback)
|
||||||
add_cias.grid(row=0, column=1)
|
add_cdn.grid(row=0, column=1)
|
||||||
|
|
||||||
def add_dirs_callback():
|
def add_dirs_callback():
|
||||||
d = fd.askdirectory(parent=parent, title='Select folder containing CIA files', initialdir=file_parent)
|
d = fd.askdirectory(parent=parent, title='Select folder containing CIA files', initialdir=file_parent)
|
||||||
if d:
|
if d:
|
||||||
|
results = {}
|
||||||
for f in scandir(d):
|
for f in scandir(d):
|
||||||
if f.name.lower().endswith('.cia'):
|
if f.name.lower().endswith('.cia'):
|
||||||
self.add_cia(f.path)
|
success, reason = self.add_cia(f.path)
|
||||||
|
if not success:
|
||||||
|
results[f] = reason
|
||||||
|
|
||||||
add_dirs = ttk.Button(listbox_buttons, text='Add folder', command=add_dirs_callback)
|
if results:
|
||||||
|
title_read_fail_window = TitleReadFailResults(self.parent, failed=results)
|
||||||
|
title_read_fail_window.focus()
|
||||||
|
self.sort_treeview()
|
||||||
|
|
||||||
|
add_dirs = ttk.Button(titlelist_buttons, text='Add folder', command=add_dirs_callback)
|
||||||
add_dirs.grid(row=0, column=2)
|
add_dirs.grid(row=0, column=2)
|
||||||
|
|
||||||
def remove_selected_callback():
|
def remove_selected_callback():
|
||||||
indexes = self.cia_listbox.curselection()
|
for entry in self.treeview.selection():
|
||||||
n = 0
|
self.remove_cia(entry)
|
||||||
for i in indexes:
|
|
||||||
self.cia_listbox.delete(i - n)
|
|
||||||
n += 1
|
|
||||||
|
|
||||||
remove_selected = ttk.Button(listbox_buttons, text='Remove selected', command=remove_selected_callback)
|
remove_selected = ttk.Button(titlelist_buttons, text='Remove selected', command=remove_selected_callback)
|
||||||
remove_selected.grid(row=0, column=3)
|
remove_selected.grid(row=0, column=3)
|
||||||
|
|
||||||
# ---------------------------------------------------------------- #
|
# ---------------------------------------------------------------- #
|
||||||
# create listbox
|
# create treeview
|
||||||
listbox_frame = ttk.Frame(self)
|
treeview_frame = ttk.Frame(self)
|
||||||
listbox_frame.grid(row=2, column=0, sticky=tk.NSEW)
|
treeview_frame.grid(row=2, column=0, sticky=tk.NSEW)
|
||||||
listbox_frame.rowconfigure(0, weight=1)
|
treeview_frame.rowconfigure(0, weight=1)
|
||||||
listbox_frame.columnconfigure(0, weight=1)
|
treeview_frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
cia_listbox_scrollbar = ttk.Scrollbar(listbox_frame, orient=tk.VERTICAL)
|
treeview_scrollbar = ttk.Scrollbar(treeview_frame, orient=tk.VERTICAL)
|
||||||
cia_listbox_scrollbar.grid(row=0, column=1, sticky=tk.NSEW)
|
treeview_scrollbar.grid(row=0, column=1, sticky=tk.NSEW)
|
||||||
|
|
||||||
self.cia_listbox = tk.Listbox(listbox_frame, highlightthickness=0, yscrollcommand=cia_listbox_scrollbar.set,
|
self.treeview = ttk.Treeview(treeview_frame, yscrollcommand=treeview_scrollbar.set)
|
||||||
selectmode=tk.EXTENDED)
|
self.treeview.grid(row=0, column=0, sticky=tk.NSEW)
|
||||||
self.cia_listbox.grid(row=0, column=0, sticky=tk.NSEW)
|
self.treeview.configure(columns=('filepath', 'titleid', 'titlename', 'status'), show='headings')
|
||||||
|
|
||||||
cia_listbox_scrollbar.config(command=self.cia_listbox.yview)
|
self.treeview.column('filepath', width=200, anchor=tk.W)
|
||||||
|
self.treeview.heading('filepath', text='File path')
|
||||||
|
self.treeview.column('titleid', width=70, anchor=tk.W)
|
||||||
|
self.treeview.heading('titleid', text='Title ID')
|
||||||
|
self.treeview.column('titlename', width=150, anchor=tk.W)
|
||||||
|
self.treeview.heading('titlename', text='Title name')
|
||||||
|
self.treeview.column('status', width=20, anchor=tk.W)
|
||||||
|
self.treeview.heading('status', text='Status')
|
||||||
|
|
||||||
|
treeview_scrollbar.configure(command=self.treeview.yview)
|
||||||
|
|
||||||
# ---------------------------------------------------------------- #
|
# ---------------------------------------------------------------- #
|
||||||
# create progressbar
|
# create progressbar
|
||||||
@@ -270,8 +489,7 @@ class CustomInstallGUI(ttk.Frame):
|
|||||||
self.status_label = ttk.Label(self, text='Waiting...')
|
self.status_label = ttk.Label(self, text='Waiting...')
|
||||||
self.status_label.grid(row=5, column=0, sticky=tk.NSEW)
|
self.status_label.grid(row=5, column=0, sticky=tk.NSEW)
|
||||||
|
|
||||||
self.log('custom-install by ihaveamac', status=False)
|
self.log(f'custom-install {CI_VERSION} - https://github.com/ihaveamac/custom-install', status=False)
|
||||||
self.log('https://github.com/ihaveamac/custom-install', status=False)
|
|
||||||
|
|
||||||
if is_windows and not taskbar:
|
if is_windows and not taskbar:
|
||||||
self.log('Note: comtypes module not found.')
|
self.log('Note: comtypes module not found.')
|
||||||
@@ -279,11 +497,65 @@ class CustomInstallGUI(ttk.Frame):
|
|||||||
|
|
||||||
self.log('Ready.')
|
self.log('Ready.')
|
||||||
|
|
||||||
self.disable_during_install = (add_cias, add_dirs, remove_selected, start, *self.file_picker_textboxes.values())
|
self.require_boot9 = (add_cias, add_cdn, add_dirs, remove_selected, start)
|
||||||
|
|
||||||
|
self.disable_buttons()
|
||||||
|
self.check_b9_loaded()
|
||||||
|
self.enable_buttons()
|
||||||
|
if not self.b9_loaded:
|
||||||
|
self.log('Note: boot9 was not auto-detected. Please choose it before adding any titles.')
|
||||||
|
|
||||||
|
def sort_treeview(self):
|
||||||
|
l = [(self.treeview.set(k, 'titlename'), k) for k in self.treeview.get_children()]
|
||||||
|
# sort by title name
|
||||||
|
l.sort(key=lambda x: x[0].lower())
|
||||||
|
|
||||||
|
for idx, pair in enumerate(l):
|
||||||
|
self.treeview.move(pair[1], '', idx)
|
||||||
|
|
||||||
|
def check_b9_loaded(self):
|
||||||
|
if not self.b9_loaded:
|
||||||
|
boot9 = self.file_picker_textboxes['boot9'].get('1.0', tk.END).strip()
|
||||||
|
try:
|
||||||
|
tmp_crypto = CryptoEngine(boot9=boot9)
|
||||||
|
self.b9_loaded = tmp_crypto.b9_keys_set
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
return self.b9_loaded
|
||||||
|
|
||||||
|
def update_status(self, path: 'Union[PathLike, bytes, str]', status: InstallStatus):
|
||||||
|
self.treeview.set(path, 'status', statuses[status])
|
||||||
|
|
||||||
def add_cia(self, path):
|
def add_cia(self, path):
|
||||||
|
if not self.check_b9_loaded():
|
||||||
|
# this shouldn't happen
|
||||||
|
return False, 'Please choose boot9 first'
|
||||||
path = abspath(path)
|
path = abspath(path)
|
||||||
self.cia_listbox.insert(tk.END, path)
|
if path in self.readers:
|
||||||
|
return False, 'File already in list'
|
||||||
|
try:
|
||||||
|
reader = CustomInstall.get_reader(path)
|
||||||
|
except (CIAError, CDNError, TitleMetadataError):
|
||||||
|
return False, 'Failed to read as a CIA or CDN title, probably corrupt'
|
||||||
|
except MissingSeedError:
|
||||||
|
return False, 'Latest seeddb.bin is required, check the README for details'
|
||||||
|
except Exception as e:
|
||||||
|
return False, f'Exception occurred: {type(e).__name__}: {e}'
|
||||||
|
|
||||||
|
if reader.tmd.title_id.startswith('00048'):
|
||||||
|
return False, 'DSiWare is not supported'
|
||||||
|
try:
|
||||||
|
title_name = reader.contents[0].exefs.icon.get_app_title().short_desc
|
||||||
|
except:
|
||||||
|
title_name = '(No title)'
|
||||||
|
self.treeview.insert('', tk.END, text=path, iid=path,
|
||||||
|
values=(path, reader.tmd.title_id, title_name, statuses[InstallStatus.Waiting]))
|
||||||
|
self.readers[path] = reader
|
||||||
|
return True, ''
|
||||||
|
|
||||||
|
def remove_cia(self, path):
|
||||||
|
self.treeview.delete(path)
|
||||||
|
del self.readers[path]
|
||||||
|
|
||||||
def open_console(self):
|
def open_console(self):
|
||||||
if self.console:
|
if self.console:
|
||||||
@@ -328,25 +600,26 @@ class CustomInstallGUI(ttk.Frame):
|
|||||||
mb.showinfo('Info', message, parent=self.parent)
|
mb.showinfo('Info', message, parent=self.parent)
|
||||||
|
|
||||||
def disable_buttons(self):
|
def disable_buttons(self):
|
||||||
for b in self.disable_during_install:
|
for b in self.require_boot9:
|
||||||
|
b.config(state=tk.DISABLED)
|
||||||
|
for b in self.file_picker_textboxes.values():
|
||||||
b.config(state=tk.DISABLED)
|
b.config(state=tk.DISABLED)
|
||||||
|
|
||||||
def enable_buttons(self):
|
def enable_buttons(self):
|
||||||
for b in self.disable_during_install:
|
if self.b9_loaded:
|
||||||
|
for b in self.require_boot9:
|
||||||
|
b.config(state=tk.NORMAL)
|
||||||
|
for b in self.file_picker_textboxes.values():
|
||||||
b.config(state=tk.NORMAL)
|
b.config(state=tk.NORMAL)
|
||||||
|
|
||||||
def start_install(self):
|
def start_install(self):
|
||||||
sd_root = self.file_picker_textboxes['sd'].get('1.0', tk.END).strip()
|
sd_root = self.file_picker_textboxes['sd'].get('1.0', tk.END).strip()
|
||||||
boot9 = self.file_picker_textboxes['boot9'].get('1.0', tk.END).strip()
|
|
||||||
seeddb = self.file_picker_textboxes['seeddb'].get('1.0', tk.END).strip()
|
seeddb = self.file_picker_textboxes['seeddb'].get('1.0', tk.END).strip()
|
||||||
movable_sed = self.file_picker_textboxes['movable.sed'].get('1.0', tk.END).strip()
|
movable_sed = self.file_picker_textboxes['movable.sed'].get('1.0', tk.END).strip()
|
||||||
|
|
||||||
if not sd_root:
|
if not sd_root:
|
||||||
self.show_error('SD root is not specified.')
|
self.show_error('SD root is not specified.')
|
||||||
return
|
return
|
||||||
if not boot9:
|
|
||||||
self.show_error('boot9 is not specified.')
|
|
||||||
return
|
|
||||||
if not movable_sed:
|
if not movable_sed:
|
||||||
self.show_error('movable.sed is not specified.')
|
self.show_error('movable.sed is not specified.')
|
||||||
return
|
return
|
||||||
@@ -356,23 +629,33 @@ class CustomInstallGUI(ttk.Frame):
|
|||||||
'Continue?'):
|
'Continue?'):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.disable_buttons()
|
if not len(self.readers):
|
||||||
self.log('Starting install...')
|
|
||||||
|
|
||||||
cias = self.cia_listbox.get(0, tk.END)
|
|
||||||
if not len(cias):
|
|
||||||
self.show_error('There are no titles added to install.')
|
self.show_error('There are no titles added to install.')
|
||||||
return
|
return
|
||||||
|
|
||||||
installer = CustomInstall(boot9=boot9,
|
for path in self.readers.keys():
|
||||||
seeddb=seeddb,
|
self.update_status(path, InstallStatus.Waiting)
|
||||||
movable=movable_sed,
|
self.disable_buttons()
|
||||||
|
self.log('Starting install...')
|
||||||
|
|
||||||
|
if taskbar:
|
||||||
|
taskbar.SetProgressState(self.hwnd, tbl.TBPF_NORMAL)
|
||||||
|
|
||||||
|
installer = CustomInstall(movable=movable_sed,
|
||||||
sd=sd_root,
|
sd=sd_root,
|
||||||
skip_contents=self.skip_contents_var.get() == 1,
|
skip_contents=self.skip_contents_var.get() == 1,
|
||||||
overwrite_saves=self.overwrite_saves_var.get() == 1)
|
overwrite_saves=self.overwrite_saves_var.get() == 1)
|
||||||
|
|
||||||
|
# use the treeview which has been sorted alphabetically
|
||||||
|
readers_final = []
|
||||||
|
for k in self.treeview.get_children():
|
||||||
|
filepath = self.treeview.set(k, 'filepath')
|
||||||
|
readers_final.append((self.readers[filepath], filepath))
|
||||||
|
|
||||||
|
installer.readers = readers_final
|
||||||
|
|
||||||
finished_percent = 0
|
finished_percent = 0
|
||||||
max_percentage = 100 * len(cias)
|
max_percentage = 100 * len(self.readers)
|
||||||
self.progressbar.config(maximum=max_percentage)
|
self.progressbar.config(maximum=max_percentage)
|
||||||
|
|
||||||
def ci_on_log_msg(message, *args, **kwargs):
|
def ci_on_log_msg(message, *args, **kwargs):
|
||||||
@@ -403,33 +686,29 @@ class CustomInstallGUI(ttk.Frame):
|
|||||||
installer.event.update_percentage += ci_update_percentage
|
installer.event.update_percentage += ci_update_percentage
|
||||||
installer.event.on_error += ci_on_error
|
installer.event.on_error += ci_on_error
|
||||||
installer.event.on_cia_start += ci_on_cia_start
|
installer.event.on_cia_start += ci_on_cia_start
|
||||||
|
installer.event.update_status += self.update_status
|
||||||
|
|
||||||
try:
|
if self.skip_contents_var.get() != 1:
|
||||||
installer.prepare_titles(cias)
|
total_size, free_space = installer.check_size()
|
||||||
except Exception as e:
|
if total_size > free_space:
|
||||||
for line in format_exception(*exc_info()):
|
self.show_error(f'Not enough free space.\n'
|
||||||
for line2 in line.split('\n')[:-1]:
|
f'Combined title install size: {total_size / (1024 * 1024):0.2f} MiB\n'
|
||||||
installer.log(line2)
|
f'Free space: {free_space / (1024 * 1024):0.2f} MiB')
|
||||||
self.show_error('An error occurred when trying to read the files.')
|
self.enable_buttons()
|
||||||
self.open_console()
|
return
|
||||||
|
|
||||||
if taskbar:
|
|
||||||
taskbar.SetProgressState(self.hwnd, tbl.TBPF_NORMAL)
|
|
||||||
|
|
||||||
def install():
|
def install():
|
||||||
try:
|
try:
|
||||||
result, copied_3dsx = installer.start()
|
result, copied_3dsx, application_count = installer.start()
|
||||||
if result is True:
|
if result:
|
||||||
self.log('Done!')
|
result_window = InstallResults(self.parent,
|
||||||
if copied_3dsx:
|
install_state=result,
|
||||||
self.show_info('custom-install-finalize has been copied to the SD card.\n'
|
copied_3dsx=copied_3dsx,
|
||||||
'To finish the install, run this on the console through the homebrew launcher.\n'
|
application_count=application_count)
|
||||||
'This will install a ticket and seed if required.')
|
result_window.focus()
|
||||||
else:
|
elif result is None:
|
||||||
self.show_info('To finish the install, run custom-install-finalize on the console.\n'
|
self.show_error("An error occurred when trying to run save3ds_fuse.\n"
|
||||||
'This will install a ticket and seed if required.')
|
"Either title.db doesn't exist, or save3ds_fuse couldn't be run.")
|
||||||
elif result is False:
|
|
||||||
self.show_error('An error occurred when trying to run save3ds_fuse.')
|
|
||||||
self.open_console()
|
self.open_console()
|
||||||
except:
|
except:
|
||||||
installer.event.on_error(exc_info())
|
installer.event.on_error(exc_info())
|
||||||
@@ -440,7 +719,7 @@ class CustomInstallGUI(ttk.Frame):
|
|||||||
|
|
||||||
|
|
||||||
window = tk.Tk()
|
window = tk.Tk()
|
||||||
window.title('custom-install')
|
window.title(f'custom-install {CI_VERSION}')
|
||||||
frame = CustomInstallGUI(window)
|
frame = CustomInstallGUI(window)
|
||||||
frame.pack(fill=tk.BOTH, expand=True)
|
frame.pack(fill=tk.BOTH, expand=True)
|
||||||
window.mainloop()
|
window.mainloop()
|
||||||
|
|||||||
696
custominstall.py
696
custominstall.py
@@ -5,13 +5,15 @@
|
|||||||
# You can find the full license text in LICENSE.md in the root of this project.
|
# You can find the full license text in LICENSE.md in the root of this project.
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from os import makedirs, scandir
|
from enum import Enum
|
||||||
|
from glob import glob
|
||||||
|
import gzip
|
||||||
|
from os import makedirs, rename, scandir
|
||||||
from os.path import dirname, join, isdir, isfile
|
from os.path import dirname, join, isdir, isfile
|
||||||
from random import randint
|
from random import randint
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from locale import getpreferredencoding
|
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from shutil import copyfile
|
from shutil import copyfile, copy2, rmtree
|
||||||
import sys
|
import sys
|
||||||
from sys import platform, executable
|
from sys import platform, executable
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
@@ -21,21 +23,29 @@ import subprocess
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from os import PathLike
|
from os import PathLike
|
||||||
from typing import List, Union
|
from typing import List, Union, Tuple
|
||||||
|
|
||||||
from events import Events
|
from events import Events
|
||||||
|
|
||||||
from pyctr.crypto import CryptoEngine, Keyslot, load_seeddb, get_seed
|
from pyctr.crypto import CryptoEngine, Keyslot, load_seeddb, get_seed
|
||||||
from pyctr.type.cdn import CDNReader
|
from pyctr.type.cdn import CDNReader, CDNError
|
||||||
from pyctr.type.cia import CIAReader, CIAError
|
from pyctr.type.cia import CIAReader, CIAError
|
||||||
from pyctr.type.ncch import NCCHSection
|
from pyctr.type.ncch import NCCHSection
|
||||||
|
from pyctr.type.tmd import TitleMetadataError
|
||||||
from pyctr.util import roundup
|
from pyctr.util import roundup
|
||||||
|
|
||||||
is_windows = platform == 'win32'
|
|
||||||
|
|
||||||
if platform == 'msys':
|
if platform == 'msys':
|
||||||
platform = 'win32'
|
platform = 'win32'
|
||||||
|
|
||||||
|
is_windows = platform == 'win32'
|
||||||
|
|
||||||
|
if is_windows:
|
||||||
|
from ctypes import c_wchar_p, pointer, c_ulonglong, windll
|
||||||
|
else:
|
||||||
|
from os import statvfs
|
||||||
|
|
||||||
|
CI_VERSION = '2.1b4'
|
||||||
|
|
||||||
# used to run the save3ds_fuse binary next to the script
|
# used to run the save3ds_fuse binary next to the script
|
||||||
frozen = getattr(sys, 'frozen', False)
|
frozen = getattr(sys, 'frozen', False)
|
||||||
script_dir: str
|
script_dir: str
|
||||||
@@ -66,6 +76,35 @@ class InvalidCIFinishError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InstallStatus(Enum):
|
||||||
|
Waiting = 0
|
||||||
|
Starting = 1
|
||||||
|
Writing = 2
|
||||||
|
Finishing = 3
|
||||||
|
Done = 4
|
||||||
|
Failed = 5
|
||||||
|
|
||||||
|
|
||||||
|
def get_free_space(path: 'Union[PathLike, bytes, str]'):
|
||||||
|
if is_windows:
|
||||||
|
lpSectorsPerCluster = c_ulonglong(0)
|
||||||
|
lpBytesPerSector = c_ulonglong(0)
|
||||||
|
lpNumberOfFreeClusters = c_ulonglong(0)
|
||||||
|
lpTotalNumberOfClusters = c_ulonglong(0)
|
||||||
|
ret = windll.kernel32.GetDiskFreeSpaceW(c_wchar_p(path), pointer(lpSectorsPerCluster),
|
||||||
|
pointer(lpBytesPerSector),
|
||||||
|
pointer(lpNumberOfFreeClusters),
|
||||||
|
pointer(lpTotalNumberOfClusters))
|
||||||
|
if not ret:
|
||||||
|
raise WindowsError
|
||||||
|
free_blocks = lpNumberOfFreeClusters.value * lpSectorsPerCluster.value
|
||||||
|
free_bytes = free_blocks * lpBytesPerSector.value
|
||||||
|
else:
|
||||||
|
stv = statvfs(path)
|
||||||
|
free_bytes = stv.f_bavail * stv.f_frsize
|
||||||
|
return free_bytes
|
||||||
|
|
||||||
|
|
||||||
def load_cifinish(path: 'Union[PathLike, bytes, str]'):
|
def load_cifinish(path: 'Union[PathLike, bytes, str]'):
|
||||||
try:
|
try:
|
||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
@@ -146,16 +185,32 @@ def save_cifinish(path: 'Union[PathLike, bytes, str]', data: dict):
|
|||||||
out.write(b''.join(finalize_entry_data))
|
out.write(b''.join(finalize_entry_data))
|
||||||
|
|
||||||
|
|
||||||
|
def get_install_size(title: 'Union[CIAReader, CDNReader]'):
|
||||||
|
sizes = [1] * 5
|
||||||
|
|
||||||
|
if title.tmd.save_size:
|
||||||
|
# one for the data directory, one for the 00000001.sav file
|
||||||
|
sizes.extend((1, title.tmd.save_size))
|
||||||
|
|
||||||
|
for record in title.content_info:
|
||||||
|
sizes.append(record.size)
|
||||||
|
|
||||||
|
# this calculates the size to put in the Title Info Entry
|
||||||
|
title_size = sum(roundup(x, TITLE_ALIGN_SIZE) for x in sizes)
|
||||||
|
|
||||||
|
return title_size
|
||||||
|
|
||||||
|
|
||||||
class CustomInstall:
|
class CustomInstall:
|
||||||
def __init__(self, boot9, seeddb, movable, sd, cifinish_out=None,
|
def __init__(self, *, movable, sd, cifinish_out=None, overwrite_saves=False, skip_contents=False,
|
||||||
overwrite_saves=False, skip_contents=False):
|
boot9=None, seeddb=None):
|
||||||
self.event = Events()
|
self.event = Events()
|
||||||
self.log_lines = [] # Stores all info messages for user to view
|
self.log_lines = [] # Stores all info messages for user to view
|
||||||
|
|
||||||
self.crypto = CryptoEngine(boot9=boot9)
|
self.crypto = CryptoEngine(boot9=boot9)
|
||||||
self.crypto.setup_sd_key_from_file(movable)
|
self.crypto.setup_sd_key_from_file(movable)
|
||||||
self.seeddb = seeddb
|
self.seeddb = seeddb
|
||||||
self.readers: 'List[Union[CDNReader, CIAReader]]' = []
|
self.readers: 'List[Tuple[Union[CDNReader, CIAReader], Union[PathLike, bytes, str]]]' = []
|
||||||
self.sd = sd
|
self.sd = sd
|
||||||
self.skip_contents = skip_contents
|
self.skip_contents = skip_contents
|
||||||
self.overwrite_saves = overwrite_saves
|
self.overwrite_saves = overwrite_saves
|
||||||
@@ -165,33 +220,57 @@ class CustomInstall:
|
|||||||
def copy_with_progress(self, src: BinaryIO, dst: BinaryIO, size: int, path: str, fire_event: bool = True):
|
def copy_with_progress(self, src: BinaryIO, dst: BinaryIO, size: int, path: str, fire_event: bool = True):
|
||||||
left = size
|
left = size
|
||||||
cipher = self.crypto.create_ctr_cipher(Keyslot.SD, self.crypto.sd_path_to_iv(path))
|
cipher = self.crypto.create_ctr_cipher(Keyslot.SD, self.crypto.sd_path_to_iv(path))
|
||||||
|
hasher = sha256()
|
||||||
while left > 0:
|
while left > 0:
|
||||||
to_read = min(READ_SIZE, left)
|
to_read = min(READ_SIZE, left)
|
||||||
data = cipher.encrypt(src.read(READ_SIZE))
|
data = src.read(READ_SIZE)
|
||||||
dst.write(data)
|
hasher.update(data)
|
||||||
|
dst.write(cipher.encrypt(data))
|
||||||
left -= to_read
|
left -= to_read
|
||||||
total_read = size - left
|
total_read = size - left
|
||||||
if fire_event:
|
if fire_event:
|
||||||
self.event.update_percentage((total_read / size) * 100, total_read / 1048576, size / 1048576)
|
self.event.update_percentage((total_read / size) * 100, total_read / 1048576, size / 1048576)
|
||||||
|
|
||||||
|
return hasher.digest()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_reader(path: 'Union[PathLike, bytes, str]'):
|
||||||
|
if isdir(path):
|
||||||
|
# try the default tmd file
|
||||||
|
reader = CDNReader(join(path, 'tmd'))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
reader = CIAReader(path)
|
||||||
|
except CIAError:
|
||||||
|
# if there was an error with parsing the CIA header,
|
||||||
|
# the file would be tried in CDNReader next (assuming it's a tmd)
|
||||||
|
# any other error should be propagated to the caller
|
||||||
|
reader = CDNReader(path)
|
||||||
|
return reader
|
||||||
|
|
||||||
def prepare_titles(self, paths: 'List[PathLike]'):
|
def prepare_titles(self, paths: 'List[PathLike]'):
|
||||||
readers = []
|
readers = []
|
||||||
for path in paths:
|
for path in paths:
|
||||||
self.log(f'Reading {path}')
|
self.log(f'Reading {path}')
|
||||||
if isdir(path):
|
try:
|
||||||
# try the default tmd file
|
reader = self.get_reader(path)
|
||||||
reader = CDNReader(join(path, 'tmd'))
|
except (CIAError, CDNError, TitleMetadataError):
|
||||||
else:
|
self.log(f"Couldn't read {path}, likely corrupt or not a CIA or CDN title")
|
||||||
try:
|
continue
|
||||||
reader = CIAReader(path)
|
if reader.tmd.title_id.startswith('00048'): # DSiWare
|
||||||
except CIAError:
|
self.log(f'Skipping {reader.tmd.title_id} - DSiWare is not supported')
|
||||||
# if there was an error with parsing the CIA header,
|
continue
|
||||||
# the file would be tried in CDNReader next (assuming it's a tmd)
|
readers.append((reader, path))
|
||||||
# any other error should be propagated to the caller
|
|
||||||
reader = CDNReader(path)
|
|
||||||
readers.append(reader)
|
|
||||||
self.readers = readers
|
self.readers = readers
|
||||||
|
|
||||||
|
def check_size(self):
|
||||||
|
total_size = 0
|
||||||
|
for r, _ in self.readers:
|
||||||
|
total_size += get_install_size(r)
|
||||||
|
|
||||||
|
free_space = get_free_space(self.sd)
|
||||||
|
return total_size, free_space
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if frozen:
|
if frozen:
|
||||||
save3ds_fuse_path = join(script_dir, 'bin', 'save3ds_fuse')
|
save3ds_fuse_path = join(script_dir, 'bin', 'save3ds_fuse')
|
||||||
@@ -201,7 +280,7 @@ class CustomInstall:
|
|||||||
save3ds_fuse_path += '.exe'
|
save3ds_fuse_path += '.exe'
|
||||||
if not isfile(save3ds_fuse_path):
|
if not isfile(save3ds_fuse_path):
|
||||||
self.log("Couldn't find " + save3ds_fuse_path, 2)
|
self.log("Couldn't find " + save3ds_fuse_path, 2)
|
||||||
return None, False
|
return None, False, 0
|
||||||
|
|
||||||
crypto = self.crypto
|
crypto = self.crypto
|
||||||
# TODO: Move a lot of these into their own methods
|
# TODO: Move a lot of these into their own methods
|
||||||
@@ -212,257 +291,321 @@ class CustomInstall:
|
|||||||
f'please remove extra directories')
|
f'please remove extra directories')
|
||||||
elif len(id1s) == 0:
|
elif len(id1s) == 0:
|
||||||
raise SDPathError(f'Could not find a suitable id1 directory for id0 {crypto.id0.hex()}')
|
raise SDPathError(f'Could not find a suitable id1 directory for id0 {crypto.id0.hex()}')
|
||||||
|
id1 = id1s[0]
|
||||||
|
sd_path = join(sd_path, id1)
|
||||||
|
|
||||||
if self.cifinish_out:
|
if self.cifinish_out:
|
||||||
cifinish_path = self.cifinish_out
|
cifinish_path = self.cifinish_out
|
||||||
else:
|
else:
|
||||||
cifinish_path = join(self.sd, 'cifinish.bin')
|
cifinish_path = join(self.sd, 'cifinish.bin')
|
||||||
sd_path = join(sd_path, id1s[0])
|
|
||||||
title_info_entries = {}
|
|
||||||
cifinish_data = load_cifinish(cifinish_path)
|
|
||||||
|
|
||||||
load_seeddb(self.seeddb)
|
try:
|
||||||
|
cifinish_data = load_cifinish(cifinish_path)
|
||||||
|
except InvalidCIFinishError as e:
|
||||||
|
self.log(f'{type(e).__qualname__}: {e}')
|
||||||
|
self.log(f'{cifinish_path} was corrupt!\n'
|
||||||
|
f'This could mean an issue with the SD card or the filesystem. Please check it for errors.\n'
|
||||||
|
f'It is also possible, though less likely, to be an issue with custom-install.\n'
|
||||||
|
f'Exiting now to prevent possible issues. If you want to try again, delete cifinish.bin from the SD card and re-run custom-install.')
|
||||||
|
return None, False, 0
|
||||||
|
|
||||||
# Now loop through all provided cia files
|
db_path = join(sd_path, 'dbs')
|
||||||
|
titledb_path = join(db_path, 'title.db')
|
||||||
for idx, cia in enumerate(self.readers):
|
importdb_path = join(db_path, 'import.db')
|
||||||
|
if not isfile(titledb_path):
|
||||||
|
makedirs(db_path, exist_ok=True)
|
||||||
|
with gzip.open(join(script_dir, 'title.db.gz')) as f:
|
||||||
|
tdb = f.read()
|
||||||
|
|
||||||
self.event.on_cia_start(idx)
|
self.log(f'Creating title.db...')
|
||||||
|
with open(titledb_path, 'wb') as o:
|
||||||
|
with self.crypto.create_ctr_io(Keyslot.SD, o, self.crypto.sd_path_to_iv('/dbs/title.db')) as e:
|
||||||
|
e.write(tdb)
|
||||||
|
|
||||||
tid_parts = (cia.tmd.title_id[0:8], cia.tmd.title_id[8:16])
|
cmac = crypto.create_cmac_object(Keyslot.CMACSDNAND)
|
||||||
|
cmac_data = [b'CTR-9DB0', 0x2.to_bytes(4, 'little'), tdb[0x100:0x200]]
|
||||||
|
cmac.update(sha256(b''.join(cmac_data)).digest())
|
||||||
|
|
||||||
try:
|
e.seek(0)
|
||||||
self.log(f'Installing {cia.contents[0].exefs.icon.get_app_title().short_desc}...')
|
e.write(cmac.digest())
|
||||||
except:
|
|
||||||
self.log('Installing...')
|
|
||||||
|
|
||||||
sizes = [1] * 5
|
|
||||||
|
|
||||||
if cia.tmd.save_size:
|
self.log(f'Creating import.db...')
|
||||||
# one for the data directory, one for the 00000001.sav file
|
with open(importdb_path, 'wb') as o:
|
||||||
sizes.extend((1, cia.tmd.save_size))
|
with self.crypto.create_ctr_io(Keyslot.SD, o, self.crypto.sd_path_to_iv('/dbs/import.db')) as e:
|
||||||
|
e.write(tdb)
|
||||||
for record in cia.content_info:
|
|
||||||
sizes.append(record.size)
|
|
||||||
|
|
||||||
# this calculates the size to put in the Title Info Entry
|
|
||||||
title_size = sum(roundup(x, TITLE_ALIGN_SIZE) for x in sizes)
|
|
||||||
|
|
||||||
# checks if this is dlc, which has some differences
|
cmac = crypto.create_cmac_object(Keyslot.CMACSDNAND)
|
||||||
is_dlc = tid_parts[0] == '0004008c'
|
cmac_data = [b'CTR-9DB0', 0x3.to_bytes(4, 'little'), tdb[0x100:0x200]]
|
||||||
|
cmac.update(sha256(b''.join(cmac_data)).digest())
|
||||||
|
|
||||||
# this checks if it has a manual (index 1) and is not DLC
|
e.seek(0)
|
||||||
has_manual = (not is_dlc) and (1 in cia.contents)
|
e.write(cmac.digest())
|
||||||
|
|
||||||
# this gets the extdata id from the extheader, stored in the storage info area
|
del tdb
|
||||||
try:
|
|
||||||
with cia.contents[0].open_raw_section(NCCHSection.ExtendedHeader) as e:
|
|
||||||
e.seek(0x200 + 0x30)
|
|
||||||
extdata_id = e.read(8)
|
|
||||||
except KeyError:
|
|
||||||
# not an executable title
|
|
||||||
extdata_id = b'\0' * 8
|
|
||||||
|
|
||||||
# cmd content id, starts with 1 for non-dlc contents
|
with TemporaryDirectory(suffix='-custom-install') as tempdir:
|
||||||
cmd_id = len(cia.content_info) if is_dlc else 1
|
# set up the common arguments for the two times we call save3ds_fuse
|
||||||
cmd_filename = f'{cmd_id:08x}.cmd'
|
save3ds_fuse_common_args = [
|
||||||
|
save3ds_fuse_path,
|
||||||
# get the title root where all the contents will be
|
'-b', crypto.b9_path,
|
||||||
title_root = join(sd_path, 'title', *tid_parts)
|
'-m', self.movable,
|
||||||
content_root = join(title_root, 'content')
|
'--sd', self.sd,
|
||||||
# generate the path used for the IV
|
'--db', 'sdtitle',
|
||||||
title_root_cmd = f'/title/{"/".join(tid_parts)}'
|
tempdir
|
||||||
content_root_cmd = title_root_cmd + '/content'
|
|
||||||
|
|
||||||
if not self.skip_contents:
|
|
||||||
makedirs(join(content_root, 'cmd'), exist_ok=True)
|
|
||||||
if cia.tmd.save_size:
|
|
||||||
makedirs(join(title_root, 'data'), exist_ok=True)
|
|
||||||
if is_dlc:
|
|
||||||
# create the separate directories for every 256 contents
|
|
||||||
for x in range(((len(cia.content_info) - 1) // 256) + 1):
|
|
||||||
makedirs(join(content_root, f'{x:08x}'), exist_ok=True)
|
|
||||||
|
|
||||||
# maybe this will be changed in the future
|
|
||||||
tmd_id = 0
|
|
||||||
|
|
||||||
tmd_filename = f'{tmd_id:08x}.tmd'
|
|
||||||
|
|
||||||
# write the tmd
|
|
||||||
enc_path = content_root_cmd + '/' + tmd_filename
|
|
||||||
self.log(f'Writing {enc_path}...')
|
|
||||||
with open(join(content_root, tmd_filename), 'wb') as o:
|
|
||||||
with self.crypto.create_ctr_io(Keyslot.SD, o, self.crypto.sd_path_to_iv(enc_path)) as e:
|
|
||||||
e.write(bytes(cia.tmd))
|
|
||||||
|
|
||||||
# write each content
|
|
||||||
for co in cia.content_info:
|
|
||||||
content_filename = co.id + '.app'
|
|
||||||
if is_dlc:
|
|
||||||
dir_index = format((co.cindex // 256), '08x')
|
|
||||||
enc_path = content_root_cmd + f'/{dir_index}/{content_filename}'
|
|
||||||
out_path = join(content_root, dir_index, content_filename)
|
|
||||||
else:
|
|
||||||
enc_path = content_root_cmd + '/' + content_filename
|
|
||||||
out_path = join(content_root, content_filename)
|
|
||||||
self.log(f'Writing {enc_path}...')
|
|
||||||
with cia.open_raw_section(co.cindex) as s, open(out_path, 'wb') as o:
|
|
||||||
self.copy_with_progress(s, o, co.size, enc_path)
|
|
||||||
|
|
||||||
# generate a blank save
|
|
||||||
if cia.tmd.save_size:
|
|
||||||
enc_path = title_root_cmd + '/data/00000001.sav'
|
|
||||||
out_path = join(title_root, 'data', '00000001.sav')
|
|
||||||
if self.overwrite_saves or not isfile(out_path):
|
|
||||||
cipher = crypto.create_ctr_cipher(Keyslot.SD, crypto.sd_path_to_iv(enc_path))
|
|
||||||
# in a new save, the first 0x20 are all 00s. the rest can be random
|
|
||||||
data = cipher.encrypt(b'\0' * 0x20)
|
|
||||||
self.log(f'Generating blank save at {enc_path}...')
|
|
||||||
with open(out_path, 'wb') as o:
|
|
||||||
o.write(data)
|
|
||||||
o.write(b'\0' * (cia.tmd.save_size - 0x20))
|
|
||||||
else:
|
|
||||||
self.log(f'Not overwriting existing save at {enc_path}')
|
|
||||||
|
|
||||||
# generate and write cmd
|
|
||||||
enc_path = content_root_cmd + '/cmd/' + cmd_filename
|
|
||||||
out_path = join(content_root, 'cmd', cmd_filename)
|
|
||||||
self.log(f'Generating {enc_path}')
|
|
||||||
highest_index = 0
|
|
||||||
content_ids = {}
|
|
||||||
|
|
||||||
for record in cia.content_info:
|
|
||||||
highest_index = record.cindex
|
|
||||||
with cia.open_raw_section(record.cindex) as s:
|
|
||||||
s.seek(0x100)
|
|
||||||
cmac_data = s.read(0x100)
|
|
||||||
|
|
||||||
id_bytes = bytes.fromhex(record.id)[::-1]
|
|
||||||
cmac_data += record.cindex.to_bytes(4, 'little') + id_bytes
|
|
||||||
|
|
||||||
cmac_ncch = crypto.create_cmac_object(Keyslot.CMACSDNAND)
|
|
||||||
cmac_ncch.update(sha256(cmac_data).digest())
|
|
||||||
content_ids[record.cindex] = (id_bytes, cmac_ncch.digest())
|
|
||||||
|
|
||||||
# add content IDs up to the last one
|
|
||||||
ids_by_index = [CMD_MISSING] * (highest_index + 1)
|
|
||||||
installed_ids = []
|
|
||||||
cmacs = []
|
|
||||||
for x in range(len(ids_by_index)):
|
|
||||||
try:
|
|
||||||
info = content_ids[x]
|
|
||||||
except KeyError:
|
|
||||||
# "MISSING CONTENT!"
|
|
||||||
# The 3DS does generate a cmac for missing contents, but I don't know how it works.
|
|
||||||
# It doesn't matter anyway, the title seems to be fully functional.
|
|
||||||
cmacs.append(bytes.fromhex('4D495353494E4720434F4E54454E5421'))
|
|
||||||
else:
|
|
||||||
ids_by_index[x] = info[0]
|
|
||||||
cmacs.append(info[1])
|
|
||||||
installed_ids.append(info[0])
|
|
||||||
installed_ids.sort(key=lambda x: int.from_bytes(x, 'little'))
|
|
||||||
|
|
||||||
final = (cmd_id.to_bytes(4, 'little')
|
|
||||||
+ len(ids_by_index).to_bytes(4, 'little')
|
|
||||||
+ len(installed_ids).to_bytes(4, 'little')
|
|
||||||
+ (1).to_bytes(4, 'little'))
|
|
||||||
cmac_cmd_header = crypto.create_cmac_object(Keyslot.CMACSDNAND)
|
|
||||||
cmac_cmd_header.update(final)
|
|
||||||
final += cmac_cmd_header.digest()
|
|
||||||
|
|
||||||
final += b''.join(ids_by_index)
|
|
||||||
final += b''.join(installed_ids)
|
|
||||||
final += b''.join(cmacs)
|
|
||||||
|
|
||||||
cipher = crypto.create_ctr_cipher(Keyslot.SD, crypto.sd_path_to_iv(enc_path))
|
|
||||||
self.log(f'Writing {enc_path}')
|
|
||||||
with open(out_path, 'wb') as o:
|
|
||||||
o.write(cipher.encrypt(final))
|
|
||||||
|
|
||||||
# this starts building the title info entry
|
|
||||||
title_info_entry_data = [
|
|
||||||
# title size
|
|
||||||
title_size.to_bytes(8, 'little'),
|
|
||||||
# title type, seems to usually be 0x40
|
|
||||||
0x40.to_bytes(4, 'little'),
|
|
||||||
# title version
|
|
||||||
int(cia.tmd.title_version).to_bytes(2, 'little'),
|
|
||||||
# ncch version
|
|
||||||
cia.contents[0].version.to_bytes(2, 'little'),
|
|
||||||
# flags_0, only checking if there is a manual
|
|
||||||
(1 if has_manual else 0).to_bytes(4, 'little'),
|
|
||||||
# tmd content id, always starting with 0
|
|
||||||
(0).to_bytes(4, 'little'),
|
|
||||||
# cmd content id
|
|
||||||
cmd_id.to_bytes(4, 'little'),
|
|
||||||
# flags_1, only checking save data
|
|
||||||
(1 if cia.tmd.save_size else 0).to_bytes(4, 'little'),
|
|
||||||
# extdataid low
|
|
||||||
extdata_id[0:4],
|
|
||||||
# reserved
|
|
||||||
b'\0' * 4,
|
|
||||||
# flags_2, only using a common value
|
|
||||||
0x100000000.to_bytes(8, 'little'),
|
|
||||||
# product code
|
|
||||||
cia.contents[0].product_code.encode('ascii').ljust(0x10, b'\0'),
|
|
||||||
# reserved
|
|
||||||
b'\0' * 0x10,
|
|
||||||
# unknown
|
|
||||||
randint(0, 0xFFFFFFFF).to_bytes(4, 'little'),
|
|
||||||
# reserved
|
|
||||||
b'\0' * 0x2c
|
|
||||||
]
|
]
|
||||||
|
|
||||||
title_info_entries[cia.tmd.title_id] = b''.join(title_info_entry_data)
|
extra_kwargs = {}
|
||||||
|
if is_windows:
|
||||||
|
# hide console window
|
||||||
|
extra_kwargs['creationflags'] = 0x08000000 # CREATE_NO_WINDOW
|
||||||
|
|
||||||
cifinish_data[int(cia.tmd.title_id, 16)] = {'seed': (get_seed(cia.contents[0].program_id) if cia.contents[0].flags.uses_seed else None)}
|
# extract the title database to add our own entry to
|
||||||
|
self.log('Extracting Title Database...')
|
||||||
|
out = subprocess.run(save3ds_fuse_common_args + ['-x'],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
encoding='utf-8',
|
||||||
|
**extra_kwargs)
|
||||||
|
if out.returncode:
|
||||||
|
for l in out.stdout.split('\n'):
|
||||||
|
self.log(l)
|
||||||
|
self.log('Command line:')
|
||||||
|
for l in pformat(out.args).split('\n'):
|
||||||
|
self.log(l)
|
||||||
|
return None, False, 0
|
||||||
|
|
||||||
# This is saved regardless if any titles were installed, so the file can be upgraded just in case.
|
if self.seeddb:
|
||||||
save_cifinish(cifinish_path, cifinish_data)
|
load_seeddb(self.seeddb)
|
||||||
|
|
||||||
if title_info_entries:
|
install_state = {'installed': [], 'failed': []}
|
||||||
with TemporaryDirectory(suffix='-custom-install') as tempdir:
|
|
||||||
# set up the common arguments for the two times we call save3ds_fuse
|
# Now loop through all provided cia files
|
||||||
save3ds_fuse_common_args = [
|
for idx, info in enumerate(self.readers):
|
||||||
save3ds_fuse_path,
|
cia, path = info
|
||||||
'-b', crypto.b9_path,
|
|
||||||
'-m', self.movable,
|
self.event.on_cia_start(idx)
|
||||||
'--sd', self.sd,
|
self.event.update_status(path, InstallStatus.Starting)
|
||||||
'--db', 'sdtitle',
|
|
||||||
tempdir
|
temp_title_root = join(self.sd, f'ci-install-temp-{cia.tmd.title_id}-{randint(0, 0xFFFFFFFF):08x}')
|
||||||
|
makedirs(temp_title_root, exist_ok=True)
|
||||||
|
|
||||||
|
tid_parts = (cia.tmd.title_id[0:8], cia.tmd.title_id[8:16])
|
||||||
|
|
||||||
|
try:
|
||||||
|
display_title = f'{cia.contents[0].exefs.icon.get_app_title().short_desc} - {cia.tmd.title_id}'
|
||||||
|
except:
|
||||||
|
display_title = cia.tmd.title_id
|
||||||
|
self.log(f'Installing {display_title}...')
|
||||||
|
|
||||||
|
title_size = get_install_size(cia)
|
||||||
|
|
||||||
|
# checks if this is dlc, which has some differences
|
||||||
|
is_dlc = tid_parts[0] == '0004008c'
|
||||||
|
|
||||||
|
# this checks if it has a manual (index 1) and is not DLC
|
||||||
|
has_manual = (not is_dlc) and (1 in cia.contents)
|
||||||
|
|
||||||
|
# this gets the extdata id from the extheader, stored in the storage info area
|
||||||
|
try:
|
||||||
|
with cia.contents[0].open_raw_section(NCCHSection.ExtendedHeader) as e:
|
||||||
|
e.seek(0x200 + 0x30)
|
||||||
|
extdata_id = e.read(8)
|
||||||
|
except KeyError:
|
||||||
|
# not an executable title
|
||||||
|
extdata_id = b'\0' * 8
|
||||||
|
|
||||||
|
# cmd content id, starts with 1 for non-dlc contents
|
||||||
|
cmd_id = len(cia.content_info) if is_dlc else 1
|
||||||
|
cmd_filename = f'{cmd_id:08x}.cmd'
|
||||||
|
|
||||||
|
# this is where the final directory will be moved
|
||||||
|
tidhigh_root = join(sd_path, 'title', tid_parts[0])
|
||||||
|
|
||||||
|
# get the title root where all the contents will be
|
||||||
|
title_root = join(sd_path, 'title', *tid_parts)
|
||||||
|
content_root = join(title_root, 'content')
|
||||||
|
# generate the path used for the IV
|
||||||
|
title_root_cmd = f'/title/{"/".join(tid_parts)}'
|
||||||
|
content_root_cmd = title_root_cmd + '/content'
|
||||||
|
|
||||||
|
temp_content_root = join(temp_title_root, 'content')
|
||||||
|
|
||||||
|
if not self.skip_contents:
|
||||||
|
self.event.update_status(path, InstallStatus.Writing)
|
||||||
|
makedirs(join(temp_content_root, 'cmd'), exist_ok=True)
|
||||||
|
if cia.tmd.save_size:
|
||||||
|
makedirs(join(temp_title_root, 'data'), exist_ok=True)
|
||||||
|
if is_dlc:
|
||||||
|
# create the separate directories for every 256 contents
|
||||||
|
for x in range(((len(cia.content_info) - 1) // 256) + 1):
|
||||||
|
makedirs(join(temp_content_root, f'{x:08x}'), exist_ok=True)
|
||||||
|
|
||||||
|
# maybe this will be changed in the future
|
||||||
|
tmd_id = 0
|
||||||
|
|
||||||
|
tmd_filename = f'{tmd_id:08x}.tmd'
|
||||||
|
|
||||||
|
# write the tmd
|
||||||
|
tmd_enc_path = content_root_cmd + '/' + tmd_filename
|
||||||
|
self.log(f'Writing {tmd_enc_path}...')
|
||||||
|
with open(join(temp_content_root, tmd_filename), 'wb') as o:
|
||||||
|
with self.crypto.create_ctr_io(Keyslot.SD, o, self.crypto.sd_path_to_iv(tmd_enc_path)) as e:
|
||||||
|
e.write(bytes(cia.tmd))
|
||||||
|
|
||||||
|
# in case the contents are corrupted
|
||||||
|
do_continue = False
|
||||||
|
# write each content
|
||||||
|
for co in cia.content_info:
|
||||||
|
content_filename = co.id + '.app'
|
||||||
|
if is_dlc:
|
||||||
|
dir_index = format((co.cindex // 256), '08x')
|
||||||
|
content_enc_path = content_root_cmd + f'/{dir_index}/{content_filename}'
|
||||||
|
content_out_path = join(temp_content_root, dir_index, content_filename)
|
||||||
|
else:
|
||||||
|
content_enc_path = content_root_cmd + '/' + content_filename
|
||||||
|
content_out_path = join(temp_content_root, content_filename)
|
||||||
|
self.log(f'Writing {content_enc_path}...')
|
||||||
|
with cia.open_raw_section(co.cindex) as s, open(content_out_path, 'wb') as o:
|
||||||
|
result_hash = self.copy_with_progress(s, o, co.size, content_enc_path)
|
||||||
|
if result_hash != co.hash:
|
||||||
|
self.log(f'WARNING: Hash does not match for {content_enc_path}!')
|
||||||
|
install_state['failed'].append(display_title)
|
||||||
|
rename(temp_title_root, temp_title_root + '-corrupted')
|
||||||
|
do_continue = True
|
||||||
|
self.event.update_status(path, InstallStatus.Failed)
|
||||||
|
break
|
||||||
|
|
||||||
|
if do_continue:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# generate a blank save
|
||||||
|
if cia.tmd.save_size:
|
||||||
|
sav_enc_path = title_root_cmd + '/data/00000001.sav'
|
||||||
|
tmp_sav_out_path = join(temp_title_root, 'data', '00000001.sav')
|
||||||
|
sav_out_path = join(title_root, 'data', '00000001.sav')
|
||||||
|
if self.overwrite_saves or not isfile(sav_out_path):
|
||||||
|
cipher = crypto.create_ctr_cipher(Keyslot.SD, crypto.sd_path_to_iv(sav_enc_path))
|
||||||
|
# in a new save, the first 0x20 are all 00s. the rest can be random
|
||||||
|
data = cipher.encrypt(b'\0' * 0x20)
|
||||||
|
self.log(f'Generating blank save at {sav_enc_path}...')
|
||||||
|
with open(tmp_sav_out_path, 'wb') as o:
|
||||||
|
o.write(data)
|
||||||
|
o.write(b'\0' * (cia.tmd.save_size - 0x20))
|
||||||
|
else:
|
||||||
|
self.log(f'Copying original save file from {sav_enc_path}...')
|
||||||
|
copy2(sav_out_path, tmp_sav_out_path)
|
||||||
|
|
||||||
|
# generate and write cmd
|
||||||
|
cmd_enc_path = content_root_cmd + '/cmd/' + cmd_filename
|
||||||
|
cmd_out_path = join(temp_content_root, 'cmd', cmd_filename)
|
||||||
|
self.log(f'Generating {cmd_enc_path}')
|
||||||
|
highest_index = 0
|
||||||
|
content_ids = {}
|
||||||
|
|
||||||
|
for record in cia.content_info:
|
||||||
|
highest_index = record.cindex
|
||||||
|
with cia.open_raw_section(record.cindex) as s:
|
||||||
|
s.seek(0x100)
|
||||||
|
cmac_data = s.read(0x100)
|
||||||
|
|
||||||
|
id_bytes = bytes.fromhex(record.id)[::-1]
|
||||||
|
cmac_data += record.cindex.to_bytes(4, 'little') + id_bytes
|
||||||
|
|
||||||
|
cmac_ncch = crypto.create_cmac_object(Keyslot.CMACSDNAND)
|
||||||
|
cmac_ncch.update(sha256(cmac_data).digest())
|
||||||
|
content_ids[record.cindex] = (id_bytes, cmac_ncch.digest())
|
||||||
|
|
||||||
|
# add content IDs up to the last one
|
||||||
|
ids_by_index = [CMD_MISSING] * (highest_index + 1)
|
||||||
|
installed_ids = []
|
||||||
|
cmacs = []
|
||||||
|
for x in range(len(ids_by_index)):
|
||||||
|
try:
|
||||||
|
info = content_ids[x]
|
||||||
|
except KeyError:
|
||||||
|
# "MISSING CONTENT!"
|
||||||
|
# The 3DS does generate a cmac for missing contents, but I don't know how it works.
|
||||||
|
# It doesn't matter anyway, the title seems to be fully functional.
|
||||||
|
cmacs.append(bytes.fromhex('4D495353494E4720434F4E54454E5421'))
|
||||||
|
else:
|
||||||
|
ids_by_index[x] = info[0]
|
||||||
|
cmacs.append(info[1])
|
||||||
|
installed_ids.append(info[0])
|
||||||
|
installed_ids.sort(key=lambda x: int.from_bytes(x, 'little'))
|
||||||
|
|
||||||
|
final = (cmd_id.to_bytes(4, 'little')
|
||||||
|
+ len(ids_by_index).to_bytes(4, 'little')
|
||||||
|
+ len(installed_ids).to_bytes(4, 'little')
|
||||||
|
+ (1).to_bytes(4, 'little'))
|
||||||
|
cmac_cmd_header = crypto.create_cmac_object(Keyslot.CMACSDNAND)
|
||||||
|
cmac_cmd_header.update(final)
|
||||||
|
final += cmac_cmd_header.digest()
|
||||||
|
|
||||||
|
final += b''.join(ids_by_index)
|
||||||
|
final += b''.join(installed_ids)
|
||||||
|
final += b''.join(cmacs)
|
||||||
|
|
||||||
|
cipher = crypto.create_ctr_cipher(Keyslot.SD, crypto.sd_path_to_iv(cmd_enc_path))
|
||||||
|
self.log(f'Writing {cmd_enc_path}')
|
||||||
|
with open(cmd_out_path, 'wb') as o:
|
||||||
|
o.write(cipher.encrypt(final))
|
||||||
|
|
||||||
|
# this starts building the title info entry
|
||||||
|
title_info_entry_data = [
|
||||||
|
# title size
|
||||||
|
title_size.to_bytes(8, 'little'),
|
||||||
|
# title type, seems to usually be 0x40
|
||||||
|
0x40.to_bytes(4, 'little'),
|
||||||
|
# title version
|
||||||
|
int(cia.tmd.title_version).to_bytes(2, 'little'),
|
||||||
|
# ncch version
|
||||||
|
cia.contents[0].version.to_bytes(2, 'little'),
|
||||||
|
# flags_0, only checking if there is a manual
|
||||||
|
(1 if has_manual else 0).to_bytes(4, 'little'),
|
||||||
|
# tmd content id, always starting with 0
|
||||||
|
(0).to_bytes(4, 'little'),
|
||||||
|
# cmd content id
|
||||||
|
cmd_id.to_bytes(4, 'little'),
|
||||||
|
# flags_1, only checking save data
|
||||||
|
(1 if cia.tmd.save_size else 0).to_bytes(4, 'little'),
|
||||||
|
# extdataid low
|
||||||
|
extdata_id[0:4],
|
||||||
|
# reserved
|
||||||
|
b'\0' * 4,
|
||||||
|
# flags_2, only using a common value
|
||||||
|
0x100000000.to_bytes(8, 'little'),
|
||||||
|
# product code
|
||||||
|
cia.contents[0].product_code.encode('ascii').ljust(0x10, b'\0'),
|
||||||
|
# reserved
|
||||||
|
b'\0' * 0x10,
|
||||||
|
# unknown
|
||||||
|
randint(0, 0xFFFFFFFF).to_bytes(4, 'little'),
|
||||||
|
# reserved
|
||||||
|
b'\0' * 0x2c
|
||||||
]
|
]
|
||||||
|
|
||||||
extra_kwargs = {}
|
self.event.update_status(path, InstallStatus.Finishing)
|
||||||
if is_windows:
|
if isdir(title_root):
|
||||||
# hide console window
|
self.log(f'Removing original install at {title_root}...')
|
||||||
extra_kwargs['creationflags'] = 0x08000000 # CREATE_NO_WINDOW
|
rmtree(title_root)
|
||||||
|
|
||||||
# extract the title database to add our own entry to
|
makedirs(tidhigh_root, exist_ok=True)
|
||||||
self.log('Extracting Title Database...')
|
rename(temp_title_root, title_root)
|
||||||
out = subprocess.run(save3ds_fuse_common_args + ['-x'],
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
encoding=getpreferredencoding(),
|
|
||||||
**extra_kwargs)
|
|
||||||
if out.returncode:
|
|
||||||
for l in out.stdout.split('\n'):
|
|
||||||
self.log(l)
|
|
||||||
self.log('Command line:')
|
|
||||||
for l in pformat(out.args).split('\n'):
|
|
||||||
self.log(l)
|
|
||||||
return False, False
|
|
||||||
|
|
||||||
for title_id, entry in title_info_entries.items():
|
cifinish_data[int(cia.tmd.title_id, 16)] = {'seed': (get_seed(cia.contents[0].program_id) if cia.contents[0].flags.uses_seed else None)}
|
||||||
# write the title info entry to the temp directory
|
|
||||||
with open(join(tempdir, title_id), 'wb') as o:
|
# This is saved regardless if any titles were installed, so the file can be upgraded just in case.
|
||||||
o.write(entry)
|
save_cifinish(cifinish_path, cifinish_data)
|
||||||
|
|
||||||
|
with open(join(tempdir, cia.tmd.title_id), 'wb') as o:
|
||||||
|
o.write(b''.join(title_info_entry_data))
|
||||||
|
|
||||||
# import the directory, now including our title
|
# import the directory, now including our title
|
||||||
self.log('Importing into Title Database...')
|
self.log('Importing into Title Database...')
|
||||||
out = subprocess.run(save3ds_fuse_common_args + ['-i'],
|
out = subprocess.run(save3ds_fuse_common_args + ['-i'],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
encoding=getpreferredencoding(),
|
encoding='utf-8',
|
||||||
**extra_kwargs)
|
**extra_kwargs)
|
||||||
if out.returncode:
|
if out.returncode:
|
||||||
for l in out.stdout.split('\n'):
|
for l in out.stdout.split('\n'):
|
||||||
@@ -470,28 +613,36 @@ class CustomInstall:
|
|||||||
self.log('Command line:')
|
self.log('Command line:')
|
||||||
for l in pformat(out.args).split('\n'):
|
for l in pformat(out.args).split('\n'):
|
||||||
self.log(l)
|
self.log(l)
|
||||||
return False, False
|
install_state['failed'].append(display_title)
|
||||||
|
self.event.update_status(path, InstallStatus.Failed)
|
||||||
|
else:
|
||||||
|
install_state['installed'].append(display_title)
|
||||||
|
self.event.update_status(path, InstallStatus.Done)
|
||||||
|
|
||||||
finalize_3dsx_orig_path = join(script_dir, 'custom-install-finalize.3dsx')
|
|
||||||
hb_dir = join(self.sd, '3ds')
|
|
||||||
finalize_3dsx_path = join(hb_dir, 'custom-install-finalize.3dsx')
|
|
||||||
copied = False
|
copied = False
|
||||||
if isfile(finalize_3dsx_orig_path):
|
# launchable applications, not DLC or update data
|
||||||
self.log('Copying finalize program to ' + finalize_3dsx_path)
|
application_count = len(glob(join(tempdir, '00040000*')))
|
||||||
makedirs(hb_dir, exist_ok=True)
|
if install_state['installed']:
|
||||||
copyfile(finalize_3dsx_orig_path, finalize_3dsx_path)
|
if application_count >= 300:
|
||||||
copied = True
|
self.log(f'{application_count} installed applications were detected.', 1)
|
||||||
|
self.log('The HOME Menu will only show 300 icons.', 1)
|
||||||
|
self.log('Some applications (not updates or DLC) will need to be deleted.', 1)
|
||||||
|
finalize_3dsx_orig_path = join(script_dir, 'custom-install-finalize.3dsx')
|
||||||
|
hb_dir = join(self.sd, '3ds')
|
||||||
|
finalize_3dsx_path = join(hb_dir, 'custom-install-finalize.3dsx')
|
||||||
|
if isfile(finalize_3dsx_orig_path):
|
||||||
|
self.log('Copying finalize program to ' + finalize_3dsx_path)
|
||||||
|
makedirs(hb_dir, exist_ok=True)
|
||||||
|
copyfile(finalize_3dsx_orig_path, finalize_3dsx_path)
|
||||||
|
copied = True
|
||||||
|
|
||||||
self.log('FINAL STEP:')
|
self.log('FINAL STEP:')
|
||||||
self.log('Run custom-install-finalize through homebrew launcher.')
|
self.log('Run custom-install-finalize through homebrew launcher.')
|
||||||
self.log('This will install a ticket and seed if required.')
|
self.log('This will install a ticket and seed if required.')
|
||||||
if copied:
|
if copied:
|
||||||
self.log('custom-install-finalize has been copied to the SD card.')
|
self.log('custom-install-finalize has been copied to the SD card.')
|
||||||
return True, copied
|
|
||||||
|
|
||||||
else:
|
return install_state, copied, application_count
|
||||||
self.log('Did not install any titles.', 2)
|
|
||||||
return None, False
|
|
||||||
|
|
||||||
def get_sd_path(self):
|
def get_sd_path(self):
|
||||||
sd_path = join(self.sd, 'Nintendo 3DS', self.crypto.id0.hex())
|
sd_path = join(self.sd, 'Nintendo 3DS', self.crypto.id0.hex())
|
||||||
@@ -536,7 +687,7 @@ class CustomInstall:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = ArgumentParser(description='Manually install a CIA to the SD card for a Nintendo 3DS system.')
|
parser = ArgumentParser(description='Install a CIA to the SD card for a Nintendo 3DS system.')
|
||||||
parser.add_argument('cia', help='CIA files', nargs='+')
|
parser.add_argument('cia', help='CIA files', nargs='+')
|
||||||
parser.add_argument('-m', '--movable', help='movable.sed file', required=True)
|
parser.add_argument('-m', '--movable', help='movable.sed file', required=True)
|
||||||
parser.add_argument('-b', '--boot9', help='boot9 file')
|
parser.add_argument('-b', '--boot9', help='boot9 file')
|
||||||
@@ -546,6 +697,7 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument('--overwrite-saves', help='overwrite existing save files', action='store_true')
|
parser.add_argument('--overwrite-saves', help='overwrite existing save files', action='store_true')
|
||||||
parser.add_argument('--cifinish-out', help='path for cifinish.bin file, defaults to (SD root)/cifinish.bin')
|
parser.add_argument('--cifinish-out', help='path for cifinish.bin file, defaults to (SD root)/cifinish.bin')
|
||||||
|
|
||||||
|
print(f'custom-install {CI_VERSION} - https://github.com/ihaveamac/custom-install')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
installer = CustomInstall(boot9=args.boot9,
|
installer = CustomInstall(boot9=args.boot9,
|
||||||
@@ -573,7 +725,19 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
installer.prepare_titles(args.cia)
|
installer.prepare_titles(args.cia)
|
||||||
|
|
||||||
result, copied_3dsx = installer.start()
|
if not args.skip_contents:
|
||||||
|
total_size, free_space = installer.check_size()
|
||||||
|
if total_size > free_space:
|
||||||
|
installer.event.on_log_msg(f'Not enough free space.\n'
|
||||||
|
f'Combined title install size: {total_size / (1024 * 1024):0.2f} MiB\n'
|
||||||
|
f'Free space: {free_space / (1024 * 1024):0.2f} MiB')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
result, copied_3dsx, application_count = installer.start()
|
||||||
if result is False:
|
if result is False:
|
||||||
# save3ds_fuse failed
|
# save3ds_fuse failed
|
||||||
installer.log('NOTE: Once save3ds_fuse is fixed, run the same command again with --skip-contents')
|
installer.log('NOTE: Once save3ds_fuse is fixed, run the same command again with --skip-contents')
|
||||||
|
if application_count >= 300:
|
||||||
|
installer.log(f'\n\nWarning: {application_count} installed applications were detected.\n'
|
||||||
|
f'The HOME Menu will only show 300 icons.\n'
|
||||||
|
f'Some applications (not updates or DLC) will need to be deleted.')
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ int load_cifinish(char* path, struct finish_db_entry_final **entries)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
return header.title_count;
|
return header.title_count;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
@@ -196,34 +197,99 @@ fail:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result check_title_exist(u64 title_id, u64 *ticket_ids, u32 ticket_ids_length, u64 *title_ids, u32 title_ids_length)
|
||||||
|
{
|
||||||
|
Result ret = -2;
|
||||||
|
|
||||||
|
for (u32 i = 0; i < ticket_ids_length; i++)
|
||||||
|
{
|
||||||
|
if (ticket_ids[i] == title_id)
|
||||||
|
{
|
||||||
|
ret++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (u32 i = 0; i < title_ids_length; i++)
|
||||||
|
{
|
||||||
|
if (title_ids[i] == title_id)
|
||||||
|
{
|
||||||
|
ret++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void finalize_install(void)
|
void finalize_install(void)
|
||||||
{
|
{
|
||||||
Result res;
|
Result res;
|
||||||
Handle ticketHandle;
|
Handle ticketHandle;
|
||||||
struct ticket_dumb ticket_buf;
|
struct ticket_dumb ticket_buf;
|
||||||
struct finish_db_entry_final *entries;
|
struct finish_db_entry_final *entries = NULL;
|
||||||
int title_count;
|
int title_count;
|
||||||
|
|
||||||
|
u32 titles_read;
|
||||||
|
u32 tickets_read;
|
||||||
|
|
||||||
|
res = AM_GetTitleCount(MEDIATYPE_SD, &titles_read);
|
||||||
|
|
||||||
|
if (R_FAILED(res))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = AM_GetTicketCount(&tickets_read);
|
||||||
|
|
||||||
|
if (R_FAILED(res))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 *installed_ticket_ids = malloc(sizeof(u64) * tickets_read );
|
||||||
|
u64 *installed_title_ids = malloc(sizeof(u64) * titles_read );
|
||||||
|
|
||||||
|
res = AM_GetTitleList(&titles_read, MEDIATYPE_SD, titles_read, installed_title_ids);
|
||||||
|
|
||||||
|
if (R_FAILED(res))
|
||||||
|
{
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = AM_GetTicketList(&tickets_read, tickets_read, 0, installed_ticket_ids);
|
||||||
|
|
||||||
|
if (R_FAILED(res))
|
||||||
|
{
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
title_count = load_cifinish(CIFINISH_PATH, &entries);
|
title_count = load_cifinish(CIFINISH_PATH, &entries);
|
||||||
|
|
||||||
if (title_count == -1)
|
if (title_count == -1)
|
||||||
{
|
{
|
||||||
free(entries);
|
goto exit;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (title_count == 0)
|
else if (title_count == 0)
|
||||||
{
|
{
|
||||||
printf("No titles to finalize.\n");
|
printf("No titles to finalize.\n");
|
||||||
free(entries);
|
goto exit;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("Deleting %s...\n", CIFINISH_PATH);
|
|
||||||
//unlink(CIFINISH_PATH);
|
|
||||||
|
|
||||||
memcpy(&ticket_buf, basetik_bin, basetik_bin_size);
|
memcpy(&ticket_buf, basetik_bin, basetik_bin_size);
|
||||||
|
|
||||||
|
Result exist_res = 0;
|
||||||
|
|
||||||
for (int i = 0; i < title_count; ++i)
|
for (int i = 0; i < title_count; ++i)
|
||||||
{
|
{
|
||||||
|
exist_res = check_title_exist(entries[i].title_id, installed_ticket_ids, tickets_read, installed_title_ids, titles_read);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(exist_res))
|
||||||
|
{
|
||||||
|
printf("No need to finalize %016llx, skipping...\n", entries[i].title_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
printf("Finalizing %016llx...\n", entries[i].title_id);
|
printf("Finalizing %016llx...\n", entries[i].title_id);
|
||||||
|
|
||||||
ticket_buf.title_id_be = __builtin_bswap64(entries[i].title_id);
|
ticket_buf.title_id_be = __builtin_bswap64(entries[i].title_id);
|
||||||
@@ -233,8 +299,7 @@ void finalize_install(void)
|
|||||||
{
|
{
|
||||||
printf("Failed to begin ticket install: %08lx\n", res);
|
printf("Failed to begin ticket install: %08lx\n", res);
|
||||||
AM_InstallTicketAbort(ticketHandle);
|
AM_InstallTicketAbort(ticketHandle);
|
||||||
free(entries);
|
goto exit;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = FSFILE_Write(ticketHandle, NULL, 0, &ticket_buf, sizeof(struct ticket_dumb), 0);
|
res = FSFILE_Write(ticketHandle, NULL, 0, &ticket_buf, sizeof(struct ticket_dumb), 0);
|
||||||
@@ -242,8 +307,7 @@ void finalize_install(void)
|
|||||||
{
|
{
|
||||||
printf("Failed to write ticket: %08lx\n", res);
|
printf("Failed to write ticket: %08lx\n", res);
|
||||||
AM_InstallTicketAbort(ticketHandle);
|
AM_InstallTicketAbort(ticketHandle);
|
||||||
free(entries);
|
goto exit;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = AM_InstallTicketFinish(ticketHandle);
|
res = AM_InstallTicketFinish(ticketHandle);
|
||||||
@@ -251,8 +315,7 @@ void finalize_install(void)
|
|||||||
{
|
{
|
||||||
printf("Failed to finish ticket install: %08lx\n", res);
|
printf("Failed to finish ticket install: %08lx\n", res);
|
||||||
AM_InstallTicketAbort(ticketHandle);
|
AM_InstallTicketAbort(ticketHandle);
|
||||||
free(entries);
|
goto exit;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entries[i].has_seed)
|
if (entries[i].has_seed)
|
||||||
@@ -266,7 +329,15 @@ void finalize_install(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("Deleting %s...\n", CIFINISH_PATH);
|
||||||
|
unlink(CIFINISH_PATH);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
|
||||||
free(entries);
|
free(entries);
|
||||||
|
free(installed_ticket_ids);
|
||||||
|
free(installed_title_ids);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
@@ -275,7 +346,7 @@ int main(int argc, char* argv[])
|
|||||||
gfxInitDefault();
|
gfxInitDefault();
|
||||||
consoleInit(GFX_TOP, NULL);
|
consoleInit(GFX_TOP, NULL);
|
||||||
|
|
||||||
printf("custom-install-finalize v1.4\n");
|
printf("custom-install-finalize v1.6\n");
|
||||||
|
|
||||||
finalize_install();
|
finalize_install();
|
||||||
// print this at the end in case it gets pushed off the screen
|
// print this at the end in case it gets pushed off the screen
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ copy TaskbarLib.tlb build\custom-install-standalone
|
|||||||
copy bin\win32\save3ds_fuse.exe build\custom-install-standalone\bin
|
copy bin\win32\save3ds_fuse.exe build\custom-install-standalone\bin
|
||||||
copy bin\README build\custom-install-standalone\bin
|
copy bin\README build\custom-install-standalone\bin
|
||||||
copy custom-install-finalize.3dsx build\custom-install-standalone
|
copy custom-install-finalize.3dsx build\custom-install-standalone
|
||||||
|
copy title.db.gz build\custom-install-standalone
|
||||||
copy extras\windows-quickstart.txt build\custom-install-standalone
|
copy extras\windows-quickstart.txt build\custom-install-standalone
|
||||||
copy LICENSE.md build\custom-install-standalone
|
copy LICENSE.md build\custom-install-standalone
|
||||||
python -m zipfile -c dist\custom-install-standalone.zip build\custom-install-standalone
|
python -m zipfile -c dist\custom-install-standalone.zip build\custom-install-standalone
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
-r requirements.txt
|
-r requirements.txt
|
||||||
comtypes==1.1.7
|
comtypes==1.1.10
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
pycryptodomex==3.9.8
|
events==0.4
|
||||||
events==0.3
|
pyctr>=0.4,<0.6
|
||||||
pyctr==0.4.3
|
|
||||||
|
|||||||
BIN
title.db.gz
Normal file
BIN
title.db.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user