mirror of
https://github.com/ihaveamac/custom-install.git
synced 2026-01-21 14:06:02 +00:00
Compare commits
118 Commits
module-rew
...
v2.1b1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
794eb8750f | ||
|
|
b34bba2543 | ||
|
|
40cfd955cc | ||
|
|
bbcfb6fef1 | ||
|
|
1e3e15c969 | ||
|
|
48f92579ce | ||
|
|
06f70e37dc | ||
|
|
44787ebc87 | ||
|
|
399bb97238 | ||
|
|
6da2ed3343 | ||
|
|
00202c473e | ||
|
|
c45c082bfb | ||
|
|
49fb0f832f | ||
|
|
a725d876de | ||
|
|
a26579ec69 | ||
|
|
4296bf3ea6 | ||
|
|
3006989fc6 | ||
|
|
19045d8b87 | ||
|
|
20a829904b | ||
|
|
0741e4b5eb | ||
|
|
bc7f20361c | ||
|
|
d176d1f0ee | ||
|
|
449ee90311 | ||
|
|
10c0d9a23a | ||
|
|
034458b3fc | ||
|
|
2dd6caf128 | ||
|
|
7ee6999725 | ||
|
|
609a0de18b | ||
|
|
8aa4fa4ddc | ||
|
|
bd9150ed66 | ||
|
|
cd86713d17 | ||
|
|
bea3c3c082 | ||
|
|
9fc04a490e | ||
|
|
7707a67048 | ||
|
|
88520570af | ||
|
|
53fd45790f | ||
|
|
56747d36eb | ||
|
|
4522c009c3 | ||
|
|
a58bfa4ae1 | ||
|
|
187e27fc95 | ||
|
|
ed7fc99ff1 | ||
|
|
3a5f554b58 | ||
|
|
ba5c5f19a7 | ||
|
|
c344ce3e7b | ||
|
|
13f706a0dc | ||
|
|
3c99c7a9d9 | ||
|
|
238b7400e0 | ||
|
|
2319819bfa | ||
|
|
cb52b38ea7 | ||
|
|
3dcee32145 | ||
|
|
647f21d32b | ||
|
|
58237a0ebe | ||
|
|
9f69a2195c | ||
|
|
91e0fa24ad | ||
|
|
b3365c47bd | ||
|
|
a515ca7e61 | ||
|
|
167a80ff11 | ||
|
|
272cc544cd | ||
|
|
443498d706 | ||
|
|
17404231d3 | ||
|
|
393fd03da1 | ||
|
|
26c21137ec | ||
|
|
9c1709922a | ||
|
|
43ae023000 | ||
|
|
e7c6ff7344 | ||
|
|
5c41f03784 | ||
|
|
4693935d87 | ||
|
|
11cbbcdf1e | ||
|
|
8f4b3d1134 | ||
|
|
d5a4cbd8f8 | ||
|
|
625f1f9db5 | ||
|
|
61b27f33ed | ||
|
|
13d0cbd796 | ||
|
|
14e5692cac | ||
|
|
b799e3af1a | ||
|
|
e8787a2d9a | ||
|
|
a08654160a | ||
|
|
6922c0d209 | ||
|
|
29e17bec6d | ||
|
|
8ee248c793 | ||
|
|
12d59cad5d | ||
|
|
ff196a667d | ||
|
|
f21b63f9dd | ||
|
|
c0e1d45054 | ||
|
|
0195ea75d4 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -15,3 +15,6 @@ venv/
|
||||
|
||||
# JetBrains
|
||||
.idea/
|
||||
=======
|
||||
|
||||
*.pyc
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
58
README.md
58
README.md
@@ -1,17 +1,30 @@
|
||||
[]() 
|
||||
|
||||
# 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
|
||||
|
||||
### Windows standalone
|
||||
|
||||
1. [Dump boot9.bin and movable.sed](https://ihaveamac.github.io/dump.html) from a 3DS system.
|
||||
2. Install the packages:
|
||||
* Windows: `py -3 -m pip install --user -r requirements.txt`
|
||||
2. Download the [latest releases](https://github.com/ihaveamac/custom-install/releases).
|
||||
3. Extract and run ci-gui. Read `windows-quickstart.txt`.
|
||||
|
||||
### With installed Python
|
||||
Note for Windows users: Enabling "Add Python 3.X to PATH" is **NOT** required! Python is installed with the `py` launcher by default.
|
||||
|
||||
1. [Dump boot9.bin and movable.sed](https://ihaveamac.github.io/dump.html) from a 3DS system.
|
||||
2. Download the repo ([zip link](https://github.com/ihaveamac/custom-install/archive/module-newer-gui.zip) or `git clone`)
|
||||
3. Install the packages:
|
||||
* Windows: Double-click `windows-install-dependencies.py`
|
||||
* Alternate manual method: `py -3 -m pip install --user -r requirements-win32.txt`
|
||||
* macOS/Linux: `python3 -m pip install --user -r requirements.txt`
|
||||
3. Download the repo ([zip link](https://github.com/ihaveamac/custom-install/archive/master.zip) or `git clone`)
|
||||
4. Run `custominstall.py` with boot9.bin, movable.sed, path to the SD root, and CIA files to install (see Usage section).
|
||||
5. Download and use [custom-install-finalize](https://github.com/ihaveamac/custom-install/releases) on the 3DS system to finish the install.
|
||||
|
||||
## Setup
|
||||
Linux users must build [wwylele/save3ds](https://github.com/wwylele/save3ds) and place `save3ds_fuse` in `bin/linux`. Just install [rust using rustup](https://www.rust-lang.org/tools/install), then compile with: `cargo build`. Your compiled binary is located in `target/debug/save3ds_fuse`, copy it to `bin/linux`.
|
||||
Linux users must build [wwylele/save3ds](https://github.com/wwylele/save3ds) and place `save3ds_fuse` in `bin/linux`. Install [rust using rustup](https://www.rust-lang.org/tools/install), then compile with: `cargo build`. The compiled binary is located in `target/debug/save3ds_fuse`, copy it to `bin/linux`.
|
||||
|
||||
movable.sed is required and can be provided with `-m` or `--movable`.
|
||||
|
||||
@@ -25,7 +38,7 @@ boot9 is needed:
|
||||
|
||||
A [SeedDB](https://github.com/ihaveamac/3DS-rom-tools/wiki/SeedDB-list) is needed for newer games (2015+) that use seeds.
|
||||
SeedDB is checked in order of:
|
||||
* `--seeddb` argument (if set)
|
||||
* `-s` or `--seeddb` argument (if set)
|
||||
* `SEEDDB_PATH` environment variable (if set)
|
||||
* `%APPDATA%\3ds\seeddb.bin` (Windows-specific)
|
||||
* `~/Library/Application Support/3ds/seeddb.bin` (macOS-specific)
|
||||
@@ -47,9 +60,38 @@ python3 custominstall.py -b boot9.bin -m movable.sed --sd /Volumes/GM9SD file.ci
|
||||
python3 custominstall.py -b boot9.bin -m movable.sed --sd /media/GM9SD file.cia file2.cia
|
||||
```
|
||||
|
||||
## License/Credits
|
||||
`pyctr/` is from [ninfs `795373d`](https://github.com/ihaveamac/ninfs/tree/795373db07be0cacd60215d8eccf16fe03535984/ninfs/pyctr).
|
||||
## GUI
|
||||
A GUI is provided to make the process easier.
|
||||
|
||||
### GUI Setup
|
||||
Linux users may need to install a Tk package:
|
||||
- Ubuntu/Debian: `sudo apt install python3-tk`
|
||||
- Manjaro/Arch: `sudo pacman -S tk`
|
||||
|
||||
Install the requirements listed in "Summary", then run `ci-gui.py`.
|
||||
|
||||
## Development
|
||||
|
||||
### Building Windows standalone
|
||||
|
||||
Using a 32-bit version of Python is recommended to build a version to be distributed.
|
||||
|
||||
A [virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment) is recommended to isolate the packages from system directories. The build script `make-standalone.bat` assumes that the dependencies are in PATH.
|
||||
|
||||
Install the dependencies, plus cx-Freeze. In a virtual environment, the specific Python version doesn't need to be requested.
|
||||
```batch
|
||||
pip install cx-freeze -r requirements-win32.txt
|
||||
```
|
||||
|
||||
Copy `custom-install-finalize.3dsx` to the project root, this will be copied to the build directory and included in the final archive.
|
||||
|
||||
Run `make-standalone.bat`. This will run cxfreeze and make a standalone version at `dist\custom-install-standalone.zip`
|
||||
|
||||
## License/Credits
|
||||
[save3ds by wwylele](https://github.com/wwylele/save3ds) is used to interact with the Title Database (details in `bin/README`).
|
||||
|
||||
Thanks to @nek0bit for redesigning `custominstall.py` to work as a module, and for implementing an earlier GUI.
|
||||
|
||||
Thanks to @LyfeOnEdge from the [brewtools Discord](https://brewtools.dev) for designing the second version of the GUI. Special thanks to CrafterPika and archbox for testing.
|
||||
|
||||
Thanks to @BpyH64 for [researching how to generate the cmacs](https://github.com/d0k3/GodMode9/issues/340#issuecomment-487916606).
|
||||
|
||||
BIN
TaskbarLib.tlb
Normal file
BIN
TaskbarLib.tlb
Normal file
Binary file not shown.
653
ci-gui.py
Normal file
653
ci-gui.py
Normal file
@@ -0,0 +1,653 @@
|
||||
# This file is a part of custom-install.py.
|
||||
#
|
||||
# custom-install is copyright (c) 2019-2020 Ian Burgwin
|
||||
# This file is licensed under The MIT License (MIT).
|
||||
# You can find the full license text in LICENSE.md in the root of this project.
|
||||
|
||||
from os import environ, scandir
|
||||
from os.path import abspath, basename, dirname, join, isfile
|
||||
from sys import exc_info, platform
|
||||
from threading import Thread, Lock
|
||||
from time import strftime
|
||||
from traceback import format_exception
|
||||
import tkinter as tk
|
||||
import tkinter.ttk as ttk
|
||||
import tkinter.filedialog as fd
|
||||
import tkinter.messagebox as mb
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pyctr.crypto.engine import b9_paths
|
||||
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, CI_VERSION, load_cifinish, InvalidCIFinishError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Dict, List
|
||||
|
||||
is_windows = platform == 'win32'
|
||||
taskbar = None
|
||||
if is_windows:
|
||||
try:
|
||||
import comtypes.client as cc
|
||||
|
||||
tbl = cc.GetModule('TaskbarLib.tlb')
|
||||
|
||||
taskbar = cc.CreateObject('{56FDF344-FD6D-11D0-958A-006097C9A090}', interface=tbl.ITaskbarList3)
|
||||
taskbar.HrInit()
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
file_parent = dirname(abspath(__file__))
|
||||
|
||||
# automatically load boot9 if it's in the current directory
|
||||
b9_paths.insert(0, join(file_parent, 'boot9.bin'))
|
||||
b9_paths.insert(0, join(file_parent, 'boot9_prot.bin'))
|
||||
|
||||
seeddb_paths = [join(x, 'seeddb.bin') for x in config_dirs]
|
||||
try:
|
||||
seeddb_paths.insert(0, environ['SEEDDB_PATH'])
|
||||
except KeyError:
|
||||
pass
|
||||
# automatically load seeddb if it's in the current directory
|
||||
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):
|
||||
for p in paths:
|
||||
if isfile(p):
|
||||
return p
|
||||
|
||||
|
||||
# find boot9, seeddb, and movable.sed to auto-select in the gui
|
||||
default_b9_path = find_first_file(b9_paths)
|
||||
default_seeddb_path = find_first_file(seeddb_paths)
|
||||
default_movable_sed_path = find_first_file([join(file_parent, 'movable.sed')])
|
||||
|
||||
|
||||
class ConsoleFrame(ttk.Frame):
|
||||
def __init__(self, parent: tk.BaseWidget = None, starting_lines: 'List[str]' = None):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
|
||||
self.rowconfigure(0, weight=1)
|
||||
self.columnconfigure(0, weight=1)
|
||||
|
||||
scrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL)
|
||||
scrollbar.grid(row=0, column=1, sticky=tk.NSEW)
|
||||
|
||||
self.text = tk.Text(self, highlightthickness=0, wrap='word', yscrollcommand=scrollbar.set)
|
||||
self.text.grid(row=0, column=0, sticky=tk.NSEW)
|
||||
|
||||
scrollbar.config(command=self.text.yview)
|
||||
|
||||
if starting_lines:
|
||||
for l in starting_lines:
|
||||
self.text.insert(tk.END, l + '\n')
|
||||
|
||||
self.text.see(tk.END)
|
||||
self.text.configure(state=tk.DISABLED)
|
||||
|
||||
def log(self, *message, end='\n', sep=' '):
|
||||
self.text.configure(state=tk.NORMAL)
|
||||
self.text.insert(tk.END, sep.join(message) + end)
|
||||
self.text.see(tk.END)
|
||||
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):
|
||||
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.'
|
||||
|
||||
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):
|
||||
console = None
|
||||
|
||||
def __init__(self, parent: tk.Tk = None):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
|
||||
# readers to give to CustomInstall at the install
|
||||
self.readers = {}
|
||||
|
||||
self.lock = Lock()
|
||||
|
||||
self.log_messages = []
|
||||
|
||||
self.hwnd = None # will be set later
|
||||
|
||||
self.rowconfigure(2, weight=1)
|
||||
self.columnconfigure(0, weight=1)
|
||||
|
||||
if taskbar:
|
||||
# this is so progress can be shown in the taskbar
|
||||
def setup_tab():
|
||||
self.hwnd = int(parent.wm_frame(), 16)
|
||||
taskbar.ActivateTab(self.hwnd)
|
||||
|
||||
self.after(100, setup_tab)
|
||||
|
||||
# ---------------------------------------------------------------- #
|
||||
# create file pickers for base files
|
||||
file_pickers = ttk.Frame(self)
|
||||
file_pickers.grid(row=0, column=0, sticky=tk.EW)
|
||||
file_pickers.columnconfigure(1, weight=1)
|
||||
|
||||
self.file_picker_textboxes = {}
|
||||
|
||||
def sd_callback():
|
||||
f = fd.askdirectory(parent=parent, title='Select SD root (the directory or drive that contains '
|
||||
'"Nintendo 3DS")', initialdir=file_parent, mustexist=True)
|
||||
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.insert(tk.END, f)
|
||||
|
||||
sd_msed_path = find_first_file([join(f, 'gm9', 'out', 'movable.sed'), join(f, 'movable.sed')])
|
||||
if sd_msed_path:
|
||||
self.log('Found movable.sed on SD card at ' + sd_msed_path)
|
||||
box = self.file_picker_textboxes['movable.sed']
|
||||
box.delete('1.0', tk.END)
|
||||
box.insert(tk.END, sd_msed_path)
|
||||
|
||||
sd_type_label = ttk.Label(file_pickers, text='SD root')
|
||||
sd_type_label.grid(row=0, column=0)
|
||||
|
||||
sd_selected = tk.Text(file_pickers, wrap='none', height=1)
|
||||
sd_selected.grid(row=0, column=1, sticky=tk.EW)
|
||||
|
||||
sd_button = ttk.Button(file_pickers, text='...', command=sd_callback)
|
||||
sd_button.grid(row=0, column=2)
|
||||
|
||||
self.file_picker_textboxes['sd'] = sd_selected
|
||||
|
||||
# This feels so wrong.
|
||||
def create_required_file_picker(type_name, types, default, row):
|
||||
def internal_callback():
|
||||
f = fd.askopenfilename(parent=parent, title='Select ' + type_name, filetypes=types,
|
||||
initialdir=file_parent)
|
||||
if f:
|
||||
selected.delete('1.0', tk.END)
|
||||
selected.insert(tk.END, f)
|
||||
|
||||
type_label = ttk.Label(file_pickers, text=type_name)
|
||||
type_label.grid(row=row, column=0)
|
||||
|
||||
selected = tk.Text(file_pickers, wrap='none', height=1)
|
||||
selected.grid(row=row, column=1, sticky=tk.EW)
|
||||
if default:
|
||||
selected.insert(tk.END, default)
|
||||
|
||||
button = ttk.Button(file_pickers, text='...', command=internal_callback)
|
||||
button.grid(row=row, column=2)
|
||||
|
||||
self.file_picker_textboxes[type_name] = selected
|
||||
|
||||
create_required_file_picker('boot9', [('boot9 file', '*.bin')], default_b9_path, 1)
|
||||
create_required_file_picker('seeddb', [('seeddb file', '*.bin')], default_seeddb_path, 2)
|
||||
create_required_file_picker('movable.sed', [('movable.sed file', '*.sed')], default_movable_sed_path, 3)
|
||||
|
||||
# ---------------------------------------------------------------- #
|
||||
# create buttons to add cias
|
||||
titlelist_buttons = ttk.Frame(self)
|
||||
titlelist_buttons.grid(row=1, column=0)
|
||||
|
||||
def add_cias_callback():
|
||||
files = fd.askopenfilenames(parent=parent, title='Select CIA files', filetypes=[('CIA files', '*.cia')],
|
||||
initialdir=file_parent)
|
||||
results = {}
|
||||
for f in files:
|
||||
success, reason = self.add_cia(f)
|
||||
if not success:
|
||||
results[f] = reason
|
||||
|
||||
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)
|
||||
|
||||
def add_cdn_callback():
|
||||
d = fd.askdirectory(parent=parent, title='Select folder containing title contents in CDN format',
|
||||
initialdir=file_parent)
|
||||
if d:
|
||||
if isfile(join(d, 'tmd')):
|
||||
success, reason = self.add_cia(d)
|
||||
if not success:
|
||||
self.show_error(f"Couldn't add {basename(d)}: {reason}")
|
||||
else:
|
||||
self.sort_treeview()
|
||||
else:
|
||||
self.show_error('tmd file not found in the CDN directory:\n' + d)
|
||||
|
||||
add_cdn = ttk.Button(titlelist_buttons, text='Add CDN title folder', command=add_cdn_callback)
|
||||
add_cdn.grid(row=0, column=1)
|
||||
|
||||
def add_dirs_callback():
|
||||
d = fd.askdirectory(parent=parent, title='Select folder containing CIA files', initialdir=file_parent)
|
||||
if d:
|
||||
results = {}
|
||||
for f in scandir(d):
|
||||
if f.name.lower().endswith('.cia'):
|
||||
success, reason = self.add_cia(f.path)
|
||||
if not success:
|
||||
results[f] = reason
|
||||
|
||||
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)
|
||||
|
||||
def remove_selected_callback():
|
||||
for entry in self.treeview.selection():
|
||||
self.remove_cia(entry)
|
||||
|
||||
remove_selected = ttk.Button(titlelist_buttons, text='Remove selected', command=remove_selected_callback)
|
||||
remove_selected.grid(row=0, column=3)
|
||||
|
||||
# ---------------------------------------------------------------- #
|
||||
# create treeview
|
||||
treeview_frame = ttk.Frame(self)
|
||||
treeview_frame.grid(row=2, 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)
|
||||
|
||||
self.treeview = ttk.Treeview(treeview_frame, yscrollcommand=treeview_scrollbar.set)
|
||||
self.treeview.grid(row=0, column=0, sticky=tk.NSEW)
|
||||
self.treeview.configure(columns=('filepath', 'titleid', 'titlename'), show='headings')
|
||||
|
||||
self.treeview.column('filepath', width=200, anchor=tk.W)
|
||||
self.treeview.heading('filepath', text='File path')
|
||||
self.treeview.column('titleid', width=50, 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')
|
||||
|
||||
treeview_scrollbar.configure(command=self.treeview.yview)
|
||||
|
||||
# ---------------------------------------------------------------- #
|
||||
# create progressbar
|
||||
|
||||
self.progressbar = ttk.Progressbar(self, orient=tk.HORIZONTAL, mode='determinate')
|
||||
self.progressbar.grid(row=3, column=0, sticky=tk.NSEW)
|
||||
|
||||
# ---------------------------------------------------------------- #
|
||||
# create start and console buttons
|
||||
|
||||
control_frame = ttk.Frame(self)
|
||||
control_frame.grid(row=4, column=0)
|
||||
|
||||
self.skip_contents_var = tk.IntVar()
|
||||
skip_contents_checkbox = ttk.Checkbutton(control_frame, text='Skip contents (only add to title database)',
|
||||
variable=self.skip_contents_var)
|
||||
skip_contents_checkbox.grid(row=0, column=0)
|
||||
|
||||
self.overwrite_saves_var = tk.IntVar()
|
||||
overwrite_saves_checkbox = ttk.Checkbutton(control_frame, text='Overwrite existing saves',
|
||||
variable=self.overwrite_saves_var)
|
||||
overwrite_saves_checkbox.grid(row=0, column=1)
|
||||
|
||||
show_console = ttk.Button(control_frame, text='Show console', command=self.open_console)
|
||||
show_console.grid(row=0, column=2)
|
||||
|
||||
start = ttk.Button(control_frame, text='Start install', command=self.start_install)
|
||||
start.grid(row=0, column=3)
|
||||
|
||||
self.status_label = ttk.Label(self, text='Waiting...')
|
||||
self.status_label.grid(row=5, column=0, sticky=tk.NSEW)
|
||||
|
||||
self.log(f'custom-install {CI_VERSION} - https://github.com/ihaveamac/custom-install', status=False)
|
||||
|
||||
if is_windows and not taskbar:
|
||||
self.log('Note: comtypes module not found.')
|
||||
self.log('Note: Progress will not be shown in the Windows taskbar.')
|
||||
|
||||
self.log('Ready.')
|
||||
|
||||
self.disable_during_install = (add_cias, add_dirs, remove_selected, start, *self.file_picker_textboxes.values())
|
||||
|
||||
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 add_cia(self, path):
|
||||
path = abspath(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 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))
|
||||
self.readers[path] = reader
|
||||
return True, ''
|
||||
|
||||
def remove_cia(self, path):
|
||||
self.treeview.delete(path)
|
||||
del self.readers[path]
|
||||
|
||||
def open_console(self):
|
||||
if self.console:
|
||||
self.console.parent.lift()
|
||||
self.console.focus()
|
||||
else:
|
||||
console_window = tk.Toplevel()
|
||||
console_window.title('custom-install Console')
|
||||
|
||||
self.console = ConsoleFrame(console_window, self.log_messages)
|
||||
self.console.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
def close():
|
||||
with self.lock:
|
||||
try:
|
||||
console_window.destroy()
|
||||
except:
|
||||
pass
|
||||
self.console = None
|
||||
|
||||
console_window.focus()
|
||||
|
||||
console_window.protocol('WM_DELETE_WINDOW', close)
|
||||
|
||||
def log(self, line, status=True):
|
||||
with self.lock:
|
||||
log_msg = f"{strftime('%H:%M:%S')} - {line}"
|
||||
self.log_messages.append(log_msg)
|
||||
if self.console:
|
||||
self.console.log(log_msg)
|
||||
|
||||
if status:
|
||||
self.status_label.config(text=line)
|
||||
|
||||
def show_error(self, message):
|
||||
mb.showerror('Error', message, parent=self.parent)
|
||||
|
||||
def ask_warning(self, message):
|
||||
return mb.askokcancel('Warning', message, parent=self.parent)
|
||||
|
||||
def show_info(self, message):
|
||||
mb.showinfo('Info', message, parent=self.parent)
|
||||
|
||||
def disable_buttons(self):
|
||||
for b in self.disable_during_install:
|
||||
b.config(state=tk.DISABLED)
|
||||
|
||||
def enable_buttons(self):
|
||||
for b in self.disable_during_install:
|
||||
b.config(state=tk.NORMAL)
|
||||
|
||||
def start_install(self):
|
||||
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()
|
||||
movable_sed = self.file_picker_textboxes['movable.sed'].get('1.0', tk.END).strip()
|
||||
|
||||
if not sd_root:
|
||||
self.show_error('SD root is not specified.')
|
||||
return
|
||||
if not boot9:
|
||||
self.show_error('boot9 is not specified.')
|
||||
return
|
||||
if not movable_sed:
|
||||
self.show_error('movable.sed is not specified.')
|
||||
return
|
||||
|
||||
if not seeddb:
|
||||
if not self.ask_warning('seeddb was not specified. Titles that require it will fail to install.\n'
|
||||
'Continue?'):
|
||||
return
|
||||
|
||||
self.disable_buttons()
|
||||
|
||||
if not len(self.readers):
|
||||
self.show_error('There are no titles added to install.')
|
||||
return
|
||||
|
||||
self.log('Starting install...')
|
||||
|
||||
if taskbar:
|
||||
taskbar.SetProgressState(self.hwnd, tbl.TBPF_NORMAL)
|
||||
|
||||
installer = CustomInstall(boot9=boot9,
|
||||
seeddb=seeddb,
|
||||
movable=movable_sed,
|
||||
sd=sd_root,
|
||||
skip_contents=self.skip_contents_var.get() == 1,
|
||||
overwrite_saves=self.overwrite_saves_var.get() == 1)
|
||||
|
||||
# use the treeview which has been sorted alphabetically
|
||||
#installer.readers = self.readers.values()
|
||||
readers_final = []
|
||||
for k in self.treeview.get_children():
|
||||
readers_final.append(self.readers[self.treeview.set(k, 'filepath')])
|
||||
|
||||
installer.readers = readers_final
|
||||
|
||||
finished_percent = 0
|
||||
max_percentage = 100 * len(self.readers)
|
||||
self.progressbar.config(maximum=max_percentage)
|
||||
|
||||
def ci_on_log_msg(message, *args, **kwargs):
|
||||
# ignoring end
|
||||
self.log(message)
|
||||
|
||||
def ci_update_percentage(total_percent, total_read, size):
|
||||
self.progressbar.config(value=total_percent + finished_percent)
|
||||
if taskbar:
|
||||
taskbar.SetProgressValue(self.hwnd, int(total_percent + finished_percent), max_percentage)
|
||||
|
||||
def ci_on_error(exc):
|
||||
if taskbar:
|
||||
taskbar.SetProgressState(self.hwnd, tbl.TBPF_ERROR)
|
||||
for line in format_exception(*exc):
|
||||
for line2 in line.split('\n')[:-1]:
|
||||
installer.log(line2)
|
||||
self.show_error('An error occurred during installation.')
|
||||
self.open_console()
|
||||
|
||||
def ci_on_cia_start(idx):
|
||||
nonlocal finished_percent
|
||||
finished_percent = idx * 100
|
||||
if taskbar:
|
||||
taskbar.SetProgressValue(self.hwnd, finished_percent, max_percentage)
|
||||
|
||||
installer.event.on_log_msg += ci_on_log_msg
|
||||
installer.event.update_percentage += ci_update_percentage
|
||||
installer.event.on_error += ci_on_error
|
||||
installer.event.on_cia_start += ci_on_cia_start
|
||||
|
||||
if self.skip_contents_var.get() != 1:
|
||||
total_size, free_space = installer.check_size()
|
||||
if total_size > free_space:
|
||||
self.show_error(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')
|
||||
self.enable_buttons()
|
||||
return
|
||||
|
||||
def install():
|
||||
try:
|
||||
result, copied_3dsx = installer.start()
|
||||
if result:
|
||||
result_window = InstallResults(self.parent, install_state=result, copied_3dsx=copied_3dsx)
|
||||
result_window.focus()
|
||||
elif result is None:
|
||||
self.show_error("An error occurred when trying to run save3ds_fuse.\n"
|
||||
"Either title.db doesn't exist, or save3ds_fuse couldn't be run.")
|
||||
self.open_console()
|
||||
except:
|
||||
installer.event.on_error(exc_info())
|
||||
finally:
|
||||
self.enable_buttons()
|
||||
|
||||
Thread(target=install).start()
|
||||
|
||||
|
||||
window = tk.Tk()
|
||||
window.title(f'custom-install {CI_VERSION}')
|
||||
frame = CustomInstallGUI(window)
|
||||
frame.pack(fill=tk.BOTH, expand=True)
|
||||
window.mainloop()
|
||||
694
custominstall.py
694
custominstall.py
@@ -1,32 +1,56 @@
|
||||
# This file is a part of custom-install.py.
|
||||
#
|
||||
# Copyright (c) 2019-2020 Ian Burgwin
|
||||
# custom-install is copyright (c) 2019-2020 Ian Burgwin
|
||||
# This file is licensed under The MIT License (MIT).
|
||||
# You can find the full license text in LICENSE.md in the root of this project.
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from os import makedirs, scandir
|
||||
from os.path import dirname, join
|
||||
from os import makedirs, rename, scandir
|
||||
from os.path import dirname, join, isdir, isfile
|
||||
from random import randint
|
||||
from hashlib import sha256
|
||||
from sys import platform
|
||||
from locale import getpreferredencoding
|
||||
from pprint import pformat
|
||||
from shutil import copyfile, copy2, rmtree
|
||||
import sys
|
||||
from sys import platform, executable
|
||||
from tempfile import TemporaryDirectory
|
||||
from traceback import format_exception
|
||||
from typing import BinaryIO, TYPE_CHECKING
|
||||
import subprocess
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from os import PathLike
|
||||
from typing import Union
|
||||
from typing import List, Union
|
||||
|
||||
from events import Events
|
||||
|
||||
from pyctr.crypto import CryptoEngine, Keyslot
|
||||
from pyctr.type.cia import CIAReader, CIASection
|
||||
from pyctr.crypto import CryptoEngine, Keyslot, load_seeddb, get_seed
|
||||
from pyctr.type.cdn import CDNReader, CDNError
|
||||
from pyctr.type.cia import CIAReader, CIAError
|
||||
from pyctr.type.ncch import NCCHSection
|
||||
from pyctr.type.tmd import TitleMetadataError
|
||||
from pyctr.util import roundup
|
||||
|
||||
if platform == 'msys':
|
||||
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.1b1'
|
||||
|
||||
# used to run the save3ds_fuse binary next to the script
|
||||
script_dir: str = dirname(__file__)
|
||||
frozen = getattr(sys, 'frozen', False)
|
||||
script_dir: str
|
||||
if frozen:
|
||||
script_dir = dirname(executable)
|
||||
else:
|
||||
script_dir = dirname(__file__)
|
||||
|
||||
# missing contents are replaced with 0xFFFFFFFF in the cmd file
|
||||
CMD_MISSING = b'\xff\xff\xff\xff'
|
||||
@@ -50,6 +74,26 @@ class InvalidCIFinishError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
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]'):
|
||||
try:
|
||||
with open(path, 'rb') as f:
|
||||
@@ -130,248 +174,132 @@ def save_cifinish(path: 'Union[PathLike, bytes, str]', data: dict):
|
||||
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:
|
||||
def __init__(self, boot9, movable, cias, sd, skip_contents=False):
|
||||
def __init__(self, boot9, seeddb, movable, sd, cifinish_out=None,
|
||||
overwrite_saves=False, skip_contents=False):
|
||||
self.event = Events()
|
||||
self.log_lines = [] # Stores all info messages for user to view
|
||||
|
||||
self.crypto = CryptoEngine(boot9=boot9)
|
||||
self.crypto.setup_sd_key_from_file(movable)
|
||||
self.cias = cias
|
||||
self.seeddb = seeddb
|
||||
self.readers: 'List[Union[CDNReader, CIAReader]]' = []
|
||||
self.sd = sd
|
||||
self.skip_contents = skip_contents
|
||||
self.overwrite_saves = overwrite_saves
|
||||
self.cifinish_out = cifinish_out
|
||||
self.movable = movable
|
||||
|
||||
def copy_with_progress(self, src: BinaryIO, dst: BinaryIO, size: int, path: str):
|
||||
def copy_with_progress(self, src: BinaryIO, dst: BinaryIO, size: int, path: str, fire_event: bool = True):
|
||||
left = size
|
||||
cipher = self.crypto.create_ctr_cipher(Keyslot.SD, self.crypto.sd_path_to_iv(path))
|
||||
hasher = sha256()
|
||||
while left > 0:
|
||||
to_read = min(READ_SIZE, left)
|
||||
data = cipher.encrypt(src.read(READ_SIZE))
|
||||
dst.write(data)
|
||||
data = src.read(READ_SIZE)
|
||||
hasher.update(data)
|
||||
dst.write(cipher.encrypt(data))
|
||||
left -= to_read
|
||||
total_read = size - left
|
||||
# self.log(f' {(total_read / size) * 100:>5.1f}% {total_read / 1048576:>.1f} MiB / {size / 1048576:.1f} MiB')
|
||||
self.event.update_percentage((total_read / size) * 100, total_read / 1048576, size / 1048576)
|
||||
|
||||
if fire_event:
|
||||
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]'):
|
||||
readers = []
|
||||
for path in paths:
|
||||
self.log(f'Reading {path}')
|
||||
try:
|
||||
reader = self.get_reader(path)
|
||||
except (CIAError, CDNError, TitleMetadataError):
|
||||
self.log(f"Couldn't read {path}, likely corrupt or not a CIA or CDN title")
|
||||
continue
|
||||
if reader.tmd.title_id.startswith('00048'): # DSiWare
|
||||
self.log(f'Skipping {reader.tmd.title_id} - DSiWare is not supported')
|
||||
continue
|
||||
readers.append(reader)
|
||||
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):
|
||||
if frozen:
|
||||
save3ds_fuse_path = join(script_dir, 'bin', 'save3ds_fuse')
|
||||
else:
|
||||
save3ds_fuse_path = join(script_dir, 'bin', platform, 'save3ds_fuse')
|
||||
if is_windows:
|
||||
save3ds_fuse_path += '.exe'
|
||||
if not isfile(save3ds_fuse_path):
|
||||
self.log("Couldn't find " + save3ds_fuse_path, 2)
|
||||
return None, False
|
||||
|
||||
crypto = self.crypto
|
||||
# TODO: Move a lot of these into their own methods
|
||||
self.log("Finding path to install to...")
|
||||
[sd_path, id1s] = self.get_sd_path()
|
||||
if len(id1s) > 1:
|
||||
raise SDPathError(f'There are multiple id1 directories for id0 {crypto.id0.hex()}, '
|
||||
f'please remove extra directories')
|
||||
elif len(id1s) == 0:
|
||||
raise SDPathError(f'Could not find a suitable id1 directory for id0 {crypto.id0.hex()}')
|
||||
|
||||
if self.cifinish_out:
|
||||
cifinish_path = self.cifinish_out
|
||||
else:
|
||||
cifinish_path = join(self.sd, 'cifinish.bin')
|
||||
|
||||
try:
|
||||
if len(id1s) > 1:
|
||||
raise SDPathError(f'There are multiple id1 directories for id0 {crypto.id0.hex()}, '
|
||||
f'please remove extra directories')
|
||||
elif len(id1s) == 0:
|
||||
raise SDPathError(f'Could not find a suitable id1 directory for id0 {crypto.id0.hex()}')
|
||||
except SDPathError:
|
||||
self.log("")
|
||||
|
||||
cifinish_path = join(self.sd, 'cifinish.bin')
|
||||
sd_path = join(sd_path, id1s[0])
|
||||
title_info_entries = {}
|
||||
cifinish_data = load_cifinish(cifinish_path)
|
||||
|
||||
# Now loop through all provided cia files
|
||||
|
||||
for c in self.cias:
|
||||
self.log('Reading ' + c)
|
||||
|
||||
cia = CIAReader(c)
|
||||
self.cia = cia
|
||||
|
||||
tid_parts = (cia.tmd.title_id[0:8], cia.tmd.title_id[8:16])
|
||||
|
||||
try:
|
||||
self.log(f'Installing {cia.contents[0].exefs.icon.get_app_title().short_desc}...')
|
||||
except:
|
||||
self.log('Installing...')
|
||||
|
||||
sizes = [1] * 5
|
||||
|
||||
if cia.tmd.save_size:
|
||||
# one for the data directory, one for the 00000001.sav file
|
||||
sizes.extend((1, cia.tmd.save_size))
|
||||
|
||||
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
|
||||
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'
|
||||
|
||||
# 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'
|
||||
|
||||
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}'))
|
||||
|
||||
# maybe this will be changed in the future
|
||||
tmd_id = 0
|
||||
|
||||
tmd_filename = f'{tmd_id:08x}.tmd'
|
||||
|
||||
if not self.skip_contents:
|
||||
# write the tmd
|
||||
enc_path = content_root_cmd + '/' + tmd_filename
|
||||
self.log(f'Writing {enc_path}...')
|
||||
with cia.open_raw_section(CIASection.TitleMetadata) as s:
|
||||
with open(join(content_root, tmd_filename), 'wb') as o:
|
||||
self.copy_with_progress(s, o, cia.sections[CIASection.TitleMetadata].size, enc_path)
|
||||
|
||||
# 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')
|
||||
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))
|
||||
|
||||
# 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)
|
||||
|
||||
cifinish_data[int(cia.tmd.title_id, 16)] = {'seed': (cia.contents[0].seed if cia.contents[0].flags.uses_seed else None)}
|
||||
|
||||
save_cifinish(cifinish_path, cifinish_data)
|
||||
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
|
||||
|
||||
with TemporaryDirectory(suffix='-custom-install') as tempdir:
|
||||
# set up the common arguments for the two times we call save3ds_fuse
|
||||
save3ds_fuse_common_args = [
|
||||
join(script_dir, 'bin', platform, 'save3ds_fuse'),
|
||||
save3ds_fuse_path,
|
||||
'-b', crypto.b9_path,
|
||||
'-m', self.movable,
|
||||
'--sd', self.sd,
|
||||
@@ -379,21 +307,283 @@ class CustomInstall:
|
||||
tempdir
|
||||
]
|
||||
|
||||
extra_kwargs = {}
|
||||
if is_windows:
|
||||
# hide console window
|
||||
extra_kwargs['creationflags'] = 0x08000000 # CREATE_NO_WINDOW
|
||||
|
||||
# extract the title database to add our own entry to
|
||||
self.log('Extracting Title Database...')
|
||||
subprocess.run(save3ds_fuse_common_args + ['-x'])
|
||||
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 None, False
|
||||
|
||||
for title_id, entry in title_info_entries.items():
|
||||
# write the title info entry to the temp directory
|
||||
with open(join(tempdir, title_id), 'wb') as o:
|
||||
o.write(entry)
|
||||
sd_path = join(sd_path, id1s[0])
|
||||
|
||||
# import the directory, now including our title
|
||||
self.log('Importing into Title Database...')
|
||||
subprocess.run(save3ds_fuse_common_args + ['-i'])
|
||||
load_seeddb(self.seeddb)
|
||||
|
||||
self.log('FINAL STEP:\nRun custom-install-finalize through homebrew launcher.')
|
||||
self.log('This will install a ticket and seed if required.')
|
||||
install_state = {'installed': [], 'failed': []}
|
||||
|
||||
# Now loop through all provided cia files
|
||||
for idx, cia in enumerate(self.readers):
|
||||
|
||||
self.event.on_cia_start(idx)
|
||||
|
||||
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:
|
||||
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
|
||||
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
|
||||
]
|
||||
|
||||
if isdir(title_root):
|
||||
self.log(f'Removing original install at {title_root}...')
|
||||
rmtree(title_root)
|
||||
|
||||
makedirs(tidhigh_root, exist_ok=True)
|
||||
rename(temp_title_root, title_root)
|
||||
|
||||
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)}
|
||||
|
||||
# This is saved regardless if any titles were installed, so the file can be upgraded just in case.
|
||||
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
|
||||
self.log('Importing into Title Database...')
|
||||
out = subprocess.run(save3ds_fuse_common_args + ['-i'],
|
||||
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)
|
||||
install_state['failed'].append(display_title)
|
||||
|
||||
install_state['installed'].append(display_title)
|
||||
|
||||
copied = False
|
||||
if install_state['installed']:
|
||||
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('Run custom-install-finalize through homebrew launcher.')
|
||||
self.log('This will install a ticket and seed if required.')
|
||||
if copied:
|
||||
self.log('custom-install-finalize has been copied to the SD card.')
|
||||
|
||||
return install_state, copied
|
||||
|
||||
def get_sd_path(self):
|
||||
sd_path = join(self.sd, 'Nintendo 3DS', self.crypto.id0.hex())
|
||||
@@ -401,8 +591,9 @@ class CustomInstall:
|
||||
for d in scandir(sd_path):
|
||||
if d.is_dir() and len(d.name) == 32:
|
||||
try:
|
||||
# id1_tmp = bytes.fromhex(d.name)
|
||||
pass
|
||||
# check if the name can be converted to hex
|
||||
# I'm not sure what the 3DS does if there is a folder that is not a 32-char hex string.
|
||||
bytes.fromhex(d.name)
|
||||
except ValueError:
|
||||
continue
|
||||
else:
|
||||
@@ -437,19 +628,25 @@ class CustomInstall:
|
||||
|
||||
|
||||
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('-m', '--movable', help='movable.sed file', required=True)
|
||||
parser.add_argument('-b', '--boot9', help='boot9 file')
|
||||
parser.add_argument('-s', '--seeddb', help='seeddb file')
|
||||
parser.add_argument('--sd', help='path to SD root', required=True)
|
||||
parser.add_argument('--skip-contents', help="don't add contents, only add title info entry", 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')
|
||||
|
||||
print(f'custom-install {CI_VERSION} - https://github.com/ihaveamac/custom-install')
|
||||
args = parser.parse_args()
|
||||
|
||||
installer = CustomInstall(boot9=args.boot9,
|
||||
cias=args.cia,
|
||||
seeddb=args.seeddb,
|
||||
movable=args.movable,
|
||||
sd=args.sd,
|
||||
overwrite_saves=args.overwrite_saves,
|
||||
cifinish_out=args.cifinish_out,
|
||||
skip_contents=(args.skip_contents or False))
|
||||
|
||||
def log_handle(msg, end='\n'):
|
||||
@@ -458,7 +655,26 @@ if __name__ == "__main__":
|
||||
def percent_handle(total_percent, total_read, size):
|
||||
installer.log(f' {total_percent:>5.1f}% {total_read:>.1f} MiB / {size:.1f} MiB\r', end='')
|
||||
|
||||
def error(exc):
|
||||
for line in format_exception(*exc):
|
||||
for line2 in line.split('\n')[:-1]:
|
||||
installer.log(line2)
|
||||
|
||||
installer.event.on_log_msg += log_handle
|
||||
installer.event.update_percentage += percent_handle
|
||||
installer.event.on_error += error
|
||||
|
||||
installer.start()
|
||||
installer.prepare_titles(args.cia)
|
||||
|
||||
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 = installer.start()
|
||||
if result is False:
|
||||
# save3ds_fuse failed
|
||||
installer.log('NOTE: Once save3ds_fuse is fixed, run the same command again with --skip-contents')
|
||||
|
||||
7
extras/windows-quickstart.txt
Normal file
7
extras/windows-quickstart.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
Run ci-gui to bring up the custom-install gui.
|
||||
Select your SD card root, boot9, seeddb, and movable.sed files.
|
||||
In some cases these will be automatically selected for you.
|
||||
|
||||
Add the CIA files and click "Start install".
|
||||
|
||||
Once it's finished, start up the homebrew launcher and run custom-install-finalize to finish the process.
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "basetik_bin.h"
|
||||
|
||||
#define CIFINISH_PATH "/cifinish.bin"
|
||||
#define REQUIRED_VERSION 3
|
||||
|
||||
// 0x10
|
||||
struct finish_db_header {
|
||||
@@ -16,8 +15,30 @@ struct finish_db_header {
|
||||
u32 title_count;
|
||||
};
|
||||
|
||||
// 0x30
|
||||
struct finish_db_entry_v1 {
|
||||
u64 title_id;
|
||||
u8 common_key_index; // unused by this program
|
||||
bool has_seed;
|
||||
u8 magic[6]; // "TITLE" and a null byte
|
||||
u8 title_key[0x10]; // unused by this program
|
||||
u8 seed[0x10];
|
||||
};
|
||||
|
||||
// 0x20
|
||||
struct finish_db_entry {
|
||||
// this one was accidential since I mixed up the order of the members in the script
|
||||
// and the finalize program, but a lot of users probably used the bad one so I need
|
||||
// to support this anyway.
|
||||
struct finish_db_entry_v2 {
|
||||
u8 magic[6]; // "TITLE" and a null byte
|
||||
u64 title_id;
|
||||
bool has_seed;
|
||||
u8 padding;
|
||||
u8 seed[0x10];
|
||||
} __attribute__((packed));
|
||||
|
||||
// 0x20
|
||||
struct finish_db_entry_v3 {
|
||||
u8 magic[6]; // "TITLE" and a null byte
|
||||
bool has_seed;
|
||||
u64 title_id;
|
||||
@@ -31,6 +52,13 @@ struct ticket_dumb {
|
||||
u8 unused2[0x16C];
|
||||
} __attribute__((packed));
|
||||
|
||||
// the 3 versions are put into this struct
|
||||
struct finish_db_entry_final {
|
||||
bool has_seed;
|
||||
u64 title_id;
|
||||
u8 seed[0x10];
|
||||
};
|
||||
|
||||
// from FBI:
|
||||
// https://github.com/Steveice10/FBI/blob/6e3a28e4b674e0d7a6f234b0419c530b358957db/source/core/http.c#L440-L453
|
||||
static Result FSUSER_AddSeed(u64 titleId, const void* seed) {
|
||||
@@ -48,66 +76,152 @@ static Result FSUSER_AddSeed(u64 titleId, const void* seed) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int load_cifinish(char* path, struct finish_db_entry_final **entries)
|
||||
{
|
||||
FILE *fp;
|
||||
struct finish_db_header header;
|
||||
|
||||
struct finish_db_entry_v1 v1;
|
||||
struct finish_db_entry_v2 v2;
|
||||
struct finish_db_entry_v3 v3;
|
||||
|
||||
struct finish_db_entry_final *tmp;
|
||||
|
||||
int i;
|
||||
size_t read;
|
||||
|
||||
printf("Reading %s...\n", path);
|
||||
fp = fopen(path, "rb");
|
||||
if (!fp)
|
||||
{
|
||||
printf("Failed to open file. Does it exist?\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fread(&header, sizeof(header), 1, fp);
|
||||
|
||||
if (memcmp(header.magic, "CIFINISH", 8))
|
||||
{
|
||||
printf("CIFINISH magic not found.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
printf("CIFINISH version: %lu\n", header.version);
|
||||
|
||||
if (header.version > 3)
|
||||
{
|
||||
printf("This version of custom-install-finalize is\n");
|
||||
printf(" too old. Please update to a new release.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
*entries = calloc(header.title_count, sizeof(struct finish_db_entry_final));
|
||||
if (!*entries) {
|
||||
printf("Couldn't allocate memory.\n");
|
||||
printf("This should never happen.\n");
|
||||
goto fail;
|
||||
}
|
||||
tmp = *entries;
|
||||
|
||||
if (header.version == 1)
|
||||
{
|
||||
for (i = 0; i < header.title_count; i++)
|
||||
{
|
||||
read = fread(&v1, sizeof(v1), 1, fp);
|
||||
if (read != 1)
|
||||
{
|
||||
printf("Couldn't read a full entry.\n");
|
||||
printf(" Is the file corrupt?\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (memcmp(v1.magic, "TITLE", 6))
|
||||
{
|
||||
printf("Couldn't find TITLE magic for entry.\n");
|
||||
printf(" Is the file corrupt?\n");
|
||||
goto fail;
|
||||
}
|
||||
tmp[i].has_seed = v1.has_seed;
|
||||
tmp[i].title_id = v1.title_id;
|
||||
memcpy(tmp[i].seed, v1.seed, 16);
|
||||
}
|
||||
} else if (header.version == 2) {
|
||||
for (i = 0; i < header.title_count; i++)
|
||||
{
|
||||
read = fread(&v2, sizeof(v2), 1, fp);
|
||||
if (read != 1)
|
||||
{
|
||||
printf("Couldn't read a full entry.\n");
|
||||
printf(" Is the file corrupt?\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (memcmp(v2.magic, "TITLE", 6))
|
||||
{
|
||||
printf("Couldn't find TITLE magic for entry.\n");
|
||||
printf(" Is the file corrupt?\n");
|
||||
goto fail;
|
||||
}
|
||||
tmp[i].has_seed = v2.has_seed;
|
||||
tmp[i].title_id = v2.title_id;
|
||||
memcpy(tmp[i].seed, v2.seed, 16);
|
||||
}
|
||||
} else if (header.version == 3) {
|
||||
for (i = 0; i < header.title_count; i++)
|
||||
{
|
||||
read = fread(&v3, sizeof(v3), 1, fp);
|
||||
if (read != 1)
|
||||
{
|
||||
printf("Couldn't read a full entry.\n");
|
||||
printf(" Is the file corrupt?\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (memcmp(v3.magic, "TITLE", 6))
|
||||
{
|
||||
printf("Couldn't find TITLE magic for entry.\n");
|
||||
printf(" Is the file corrupt?\n");
|
||||
goto fail;
|
||||
}
|
||||
tmp[i].has_seed = v3.has_seed;
|
||||
tmp[i].title_id = v3.title_id;
|
||||
memcpy(tmp[i].seed, v3.seed, 16);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return header.title_count;
|
||||
|
||||
fail:
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void finalize_install(void)
|
||||
{
|
||||
Result res;
|
||||
Handle ticketHandle;
|
||||
struct ticket_dumb ticket_buf;
|
||||
FILE *fp;
|
||||
struct finish_db_entry_final *entries;
|
||||
int title_count;
|
||||
|
||||
struct finish_db_header header;
|
||||
struct finish_db_entry *entries;
|
||||
title_count = load_cifinish(CIFINISH_PATH, &entries);
|
||||
if (title_count == -1)
|
||||
{
|
||||
free(entries);
|
||||
return;
|
||||
}
|
||||
if (title_count == 0)
|
||||
{
|
||||
printf("No titles to finalize.\n");
|
||||
free(entries);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&ticket_buf, basetik_bin, basetik_bin_size);
|
||||
|
||||
printf("Reading %s...\n", CIFINISH_PATH);
|
||||
fp = fopen(CIFINISH_PATH, "rb");
|
||||
if (!fp)
|
||||
for (int i = 0; i < title_count; ++i)
|
||||
{
|
||||
puts("Failed to open file.");
|
||||
return;
|
||||
}
|
||||
|
||||
fread(&header, sizeof(struct finish_db_header), 1, fp);
|
||||
|
||||
if (memcmp(header.magic, "CIFINISH", 8))
|
||||
{
|
||||
printf("CIFINISH magic not found in %s.\n", CIFINISH_PATH);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (header.version != REQUIRED_VERSION)
|
||||
{
|
||||
printf("\n%s was created with a different\n", CIFINISH_PATH);
|
||||
printf(" version of custom-install than this one\n");
|
||||
printf(" supports.\n\n");
|
||||
printf("Make sure you are using the latest version of\n");
|
||||
printf(" custom-install and custom-install-finalize\n");
|
||||
printf(" from the repository on GitHub.\n\n");
|
||||
printf("When you run the script again, you can use\n");
|
||||
printf(" --skip-contents to avoid re-writing the title\n");
|
||||
printf(" contents, so only the Title Database and\n");
|
||||
printf(" cifinish.bin will be modified.\n\n");
|
||||
printf("Expected version %i, got %li\n", REQUIRED_VERSION, header.version);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
entries = calloc(header.title_count, sizeof(struct finish_db_entry));
|
||||
fread(entries, sizeof(struct finish_db_entry), header.title_count, fp);
|
||||
fclose(fp);
|
||||
printf("Deleting %s...\n", CIFINISH_PATH);
|
||||
unlink(CIFINISH_PATH);
|
||||
|
||||
for (int i = 0; i < header.title_count; ++i)
|
||||
{
|
||||
// this includes the null byte
|
||||
if (memcmp(entries[i].magic, "TITLE", 6))
|
||||
{
|
||||
puts("Couldn't find TITLE magic for entry, skipping.");
|
||||
continue;
|
||||
}
|
||||
printf("Finalizing %016llx...\n", entries[i].title_id);
|
||||
|
||||
ticket_buf.title_id_be = __builtin_bswap64(entries[i].title_id);
|
||||
@@ -150,20 +264,25 @@ void finalize_install(void)
|
||||
}
|
||||
}
|
||||
|
||||
printf("Deleting %s...\n", CIFINISH_PATH);
|
||||
unlink(CIFINISH_PATH);
|
||||
|
||||
free(entries);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
amInit();
|
||||
sdmcInit();
|
||||
gfxInitDefault();
|
||||
consoleInit(GFX_TOP, NULL);
|
||||
|
||||
puts("custom-install-finalize v1.2");
|
||||
printf("custom-install-finalize v1.5\n");
|
||||
|
||||
finalize_install();
|
||||
puts("\nPress START or B to exit.");
|
||||
// print this at the end in case it gets pushed off the screen
|
||||
printf("\nRepository:\n");
|
||||
printf(" https://github.com/ihaveamac/custom-install\n");
|
||||
printf("\nPress START or B to exit.\n");
|
||||
|
||||
// Main loop
|
||||
while (aptMainLoop())
|
||||
@@ -179,7 +298,6 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
gfxExit();
|
||||
sdmcExit();
|
||||
amExit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
from custominstall import CustomInstall
|
||||
import tkinter as tk
|
||||
from tkinter.filedialog import askopenfilenames
|
||||
from tkinter.ttk import Progressbar
|
||||
import os
|
||||
import datetime
|
||||
import threading
|
||||
import queue
|
||||
|
||||
|
||||
class CustomInstallGui(tk.Frame):
|
||||
def __init__(self, master=None):
|
||||
tk.Frame.__init__(self, master)
|
||||
self.master = master
|
||||
|
||||
# Title name for window
|
||||
self.window_title = "Custom-Install GUI"
|
||||
|
||||
# Config
|
||||
self.skip_contents = False
|
||||
self.cias = []
|
||||
self.boot9 = None
|
||||
self.movable = None
|
||||
self.sd = None
|
||||
self.skip_cont_var = tk.IntVar(self)
|
||||
|
||||
for x in range(8):
|
||||
tk.Grid.rowconfigure(self, x, weight=1)
|
||||
for x in range(1):
|
||||
tk.Grid.columnconfigure(self, x, weight=1)
|
||||
|
||||
def set_cias(self, filename):
|
||||
self.cias = filename
|
||||
|
||||
def set_boot9(self, filename):
|
||||
self.boot9 = filename
|
||||
|
||||
def set_movable(self, filename):
|
||||
self.movable = filename
|
||||
|
||||
def set_sd(self, directory):
|
||||
self.sd = directory
|
||||
|
||||
def start_install(self, event):
|
||||
self.progress['value'] = 0
|
||||
error = False
|
||||
|
||||
# Checks
|
||||
if len(self.cias) == 0:
|
||||
self.add_log_msg("Error: Please select CIA file(s)")
|
||||
error = True
|
||||
if self.boot9 == None:
|
||||
self.add_log_msg("Error: Please add your boot9 file")
|
||||
error = True
|
||||
if self.movable == None:
|
||||
self.add_log_msg("Error: Please add your movable file")
|
||||
if self.sd == None:
|
||||
self.add_log_msg("Error: Please locate your SD card directory")
|
||||
self.add_log_msg("Note: Linux usually mounts to /media/")
|
||||
if error:
|
||||
self.add_log_msg("--- Errors occured, aborting ---")
|
||||
return False
|
||||
|
||||
# Start the job
|
||||
if self.skip_cont_var.get() == 1: self.skip_contents = True
|
||||
else: self.skip_contents = False
|
||||
|
||||
print(f'{self.cias}\n{self.boot9}\n{self.movable}\n{self.skip_contents}')
|
||||
self.log.insert(tk.END, "Starting install...\n")
|
||||
|
||||
installer = CustomInstall(boot9=self.boot9,
|
||||
movable=self.movable,
|
||||
cias=self.cias,
|
||||
sd=self.sd,
|
||||
skip_contents=self.skip_contents)
|
||||
|
||||
|
||||
# DEBUG
|
||||
# self.debug_values()
|
||||
|
||||
def start_install():
|
||||
def log_handle(message, end=None): self.add_log_msg(message)
|
||||
def percentage_handle(percent, total_read, size): self.progress['value'] = percent
|
||||
|
||||
installer.event.on_log_msg += log_handle
|
||||
installer.event.update_percentage += percentage_handle
|
||||
installer.start()
|
||||
print('--- Script is done ---')
|
||||
|
||||
t = threading.Thread(target=start_install)
|
||||
t.start()
|
||||
|
||||
|
||||
|
||||
|
||||
def debug_values(self):
|
||||
self.add_log_msg(self.boot9)
|
||||
self.add_log_msg(self.movable)
|
||||
self.add_log_msg(self.cias)
|
||||
self.add_log_msg(self.sd)
|
||||
self.add_log_msg(self.skip_contents)
|
||||
|
||||
def start(self):
|
||||
self.master.title(self.window_title)
|
||||
self.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
self.log = tk.Text(self, height=10, width=40)
|
||||
install = tk.Button(self, text="Install CIA")
|
||||
skip_checkbox = tk.Checkbutton(self, text="Skip Contents", variable=self.skip_cont_var)
|
||||
|
||||
self.progress = Progressbar(self, orient=tk.HORIZONTAL, length=100, mode='determinate')
|
||||
|
||||
# File pickers
|
||||
cia_picker = self.filepicker_option("CIA file(s)", True, self.set_cias)
|
||||
boot9_picker = self.filepicker_option("Select boot9.bin...", False, self.set_boot9)
|
||||
movable_picker = self.filepicker_option("Select movable.sed...", False, self.set_movable)
|
||||
sd_picker = self.filepicker_option("Select SD card...", False, self.set_sd, True)
|
||||
|
||||
# Place widgets
|
||||
self.log.grid(column=0, row=0, sticky=tk.N+tk.E+tk.W)
|
||||
self.progress.grid(column=0, row=1, sticky=tk.E+tk.W)
|
||||
sd_picker.grid(column=0, row=2, sticky=tk.E+tk.W)
|
||||
boot9_picker.grid(column=0, row=3, sticky=tk.E+tk.W)
|
||||
movable_picker.grid(column=0, row=4, sticky=tk.E+tk.W)
|
||||
cia_picker.grid(column=0, row=5, sticky=tk.E+tk.W)
|
||||
skip_checkbox.grid(column=0, row=6, sticky=tk.E+tk.W)
|
||||
install.grid(column=0, row=7, sticky=tk.S+tk.E+tk.W)
|
||||
|
||||
|
||||
# Events
|
||||
install.bind('<Button-1>', self.start_install)
|
||||
|
||||
# Just a greeting :)
|
||||
now = datetime.datetime.now()
|
||||
time_short = "day!"
|
||||
if now.hour < 12: time_short = "morning!"
|
||||
elif now.hour > 12: time_short = "afternoon!"
|
||||
self.add_log_msg(f'Good {time_short} Please pick your boot9, movable.sed, SD, and CIA file(s).\n---\nPress "Install CIA" when ready!')
|
||||
|
||||
def add_log_msg(self, message):
|
||||
self.log.insert(tk.END, str(message)+"\n")
|
||||
self.log.see(tk.END)
|
||||
|
||||
def filepicker_option(self, title, multiple_files, on_file_add, dir_only=False):
|
||||
frame = tk.Frame(self)
|
||||
|
||||
browse_button = tk.Button(frame, text="Pick file")
|
||||
filename_label = tk.Label(frame, text=title, wraplength=200)
|
||||
|
||||
browse_button.grid(column=0, row=0)
|
||||
filename_label.grid(column=1, row=0)
|
||||
|
||||
# Wrapper for event
|
||||
def file_add(event):
|
||||
if dir_only:
|
||||
folder = tk.filedialog.askdirectory()
|
||||
if not folder:
|
||||
return False
|
||||
|
||||
dir = os.path.basename(folder)
|
||||
filename_label.config(text="SD => "+dir)
|
||||
|
||||
on_file_add(folder)
|
||||
return True
|
||||
# Returns multiple files in a tuple
|
||||
filename = (tk.filedialog.askopenfilenames()
|
||||
if multiple_files else
|
||||
tk.filedialog.askopenfilename())
|
||||
|
||||
# User may select "cancel"
|
||||
if not filename:
|
||||
return False
|
||||
|
||||
|
||||
if multiple_files:
|
||||
basename = os.path.basename(filename[0])
|
||||
if len(filename) <= 1:
|
||||
more = ""
|
||||
elif len(filename) > 1:
|
||||
more = " + "+str(len(filename))+" more"
|
||||
else:
|
||||
basename = os.path.basename(filename)
|
||||
more = ""
|
||||
|
||||
filename_label.config(text=basename+more)
|
||||
|
||||
# Runs callback provided
|
||||
on_file_add(filename)
|
||||
|
||||
browse_button.bind('<Button-1>', file_add)
|
||||
|
||||
return frame
|
||||
|
||||
|
||||
root = tk.Tk()
|
||||
app = CustomInstallGui(root)
|
||||
app.start()
|
||||
|
||||
root.mainloop()
|
||||
11
make-standalone.bat
Normal file
11
make-standalone.bat
Normal file
@@ -0,0 +1,11 @@
|
||||
mkdir build
|
||||
mkdir dist
|
||||
cxfreeze ci-gui.py --target-dir=build\custom-install-standalone --base-name=Win32GUI
|
||||
mkdir build\custom-install-standalone\bin
|
||||
copy TaskbarLib.tlb build\custom-install-standalone
|
||||
copy bin\win32\save3ds_fuse.exe build\custom-install-standalone\bin
|
||||
copy bin\README build\custom-install-standalone\bin
|
||||
copy custom-install-finalize.3dsx build\custom-install-standalone
|
||||
copy extras\windows-quickstart.txt build\custom-install-standalone
|
||||
copy LICENSE.md build\custom-install-standalone
|
||||
python -m zipfile -c dist\custom-install-standalone.zip build\custom-install-standalone
|
||||
2
requirements-win32.txt
Normal file
2
requirements-win32.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
-r requirements.txt
|
||||
comtypes==1.1.7
|
||||
@@ -1,3 +1,2 @@
|
||||
pycryptodomex==3.9.4
|
||||
events==0.3
|
||||
pyctr==0.1.0
|
||||
events==0.4
|
||||
pyctr==0.4.5
|
||||
|
||||
13
windows-install-dependencies.py
Normal file
13
windows-install-dependencies.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# This is meant to be double-clicked from File Explorer.
|
||||
|
||||
# This doesn't import pip as a module in case the way it's executed changes, which it has in the past.
|
||||
# Instead we call it like we would in the command line.
|
||||
|
||||
from subprocess import run
|
||||
from os.path import dirname, join
|
||||
from sys import executable
|
||||
|
||||
root_dir = dirname(__file__)
|
||||
|
||||
run([executable, '-m', 'pip', 'install', '--user', '-r', join(root_dir, 'requirements-win32.txt')])
|
||||
input('Press enter to close')
|
||||
Reference in New Issue
Block a user