├── po ├── LINGUAS ├── meson.build ├── POTFILES └── nxdumpclient.pot ├── vapi ├── gusb.deps └── gusb.vapi ├── .gitignore ├── subprojects ├── .gitignore └── blueprint-compiler.wrap ├── data ├── screenshot-1.png ├── org.v1993.NXDumpClient.service.in ├── icons │ └── hicolor │ │ ├── 256x256 │ │ └── apps │ │ │ └── org.v1993.NXDumpClient.png │ │ └── scalable │ │ └── apps │ │ └── org.v1993.NXDumpClient.svg ├── 71-nxdumptool.rules ├── org.v1993.NXDumpClient.autostart.desktop.in.in ├── org.v1993.NXDumpClient.desktop.in.in ├── org.v1993.NXDumpClient.gschema.xml ├── meson.build └── org.v1993.NXDumpClient.appdata.xml.in ├── src ├── nxdumptool_icon.jpg ├── config.vapi ├── widgets │ ├── FileRow.blp │ ├── DeviceStatusRow.blp │ ├── FileRow.vala │ └── DeviceStatusRow.vala ├── gtk │ └── help-overlay.blp ├── nxdumpclient.gresource.xml ├── UdevRulesDialog.blp ├── main.vala ├── UsbDeviceOpener.vala ├── Window.blp ├── UdevRulesDialog.vala ├── PreferencesDialog.blp ├── UsbContext.vala ├── meson.build ├── Utils.vala ├── Window.vala ├── PreferencesDialog.vala ├── Application.vala └── UsbDeviceClient.vala ├── .git-blame-ignore-revs ├── .gitmodules ├── meson.build ├── meson_options.txt ├── .github ├── PKGBUILD.in └── workflows │ ├── release-flatpakref.yml │ ├── aur-publish.yml │ └── flatpak.yml ├── README-MSYS2.md ├── flatpak └── org.v1993.NXDumpClient.yml ├── README.md └── LICENSE /po/LINGUAS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vapi/gusb.deps: -------------------------------------------------------------------------------- 1 | gio-2.0 2 | json-glib-1.0 3 | -------------------------------------------------------------------------------- /po/meson.build: -------------------------------------------------------------------------------- 1 | i18n.gettext('nxdumpclient', preset: 'glib') 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .flatpak-builder/ 2 | .flatpak/ 3 | .vscode/ 4 | .buildconfig 5 | -------------------------------------------------------------------------------- /subprojects/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | 3 | !.gitignore 4 | !packagefiles/** 5 | !*.wrap 6 | -------------------------------------------------------------------------------- /data/screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/v1993/nxdumpclient/HEAD/data/screenshot-1.png -------------------------------------------------------------------------------- /src/nxdumptool_icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/v1993/nxdumpclient/HEAD/src/nxdumptool_icon.jpg -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Replace remaining spaces with tabs 2 | 830db8341cad3f3f09a8c314cbe250f63d5f5db4 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "flatpak/shared-modules"] 2 | path = flatpak/shared-modules 3 | url = https://github.com/flathub/shared-modules.git 4 | -------------------------------------------------------------------------------- /data/org.v1993.NXDumpClient.service.in: -------------------------------------------------------------------------------- 1 | [D-BUS Service] 2 | Name=org.v1993.NXDumpClient 3 | Exec=@bindir@/nxdumpclient --gapplication-service 4 | -------------------------------------------------------------------------------- /data/icons/hicolor/256x256/apps/org.v1993.NXDumpClient.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/v1993/nxdumpclient/HEAD/data/icons/hicolor/256x256/apps/org.v1993.NXDumpClient.png -------------------------------------------------------------------------------- /data/71-nxdumptool.rules: -------------------------------------------------------------------------------- 1 | # Nintendo SDK debugger, which nxdumptool presents itself as 2 | SUBSYSTEM=="usb", ATTRS{idVendor}=="057e", ATTRS{idProduct}=="3000", TAG+="uaccess" 3 | -------------------------------------------------------------------------------- /data/org.v1993.NXDumpClient.autostart.desktop.in.in: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=NX Dump Client (background launch) 3 | GenericName=Dump over USB with nxdumptool 4 | Exec=@bindir@/nxdumpclient --background 5 | Icon=org.v1993.NXDumpClient 6 | Terminal=false 7 | Type=Application 8 | Categories=GTK;Utility; 9 | X-GNOME-UsesNotifications=true 10 | -------------------------------------------------------------------------------- /subprojects/blueprint-compiler.wrap: -------------------------------------------------------------------------------- 1 | [wrap-file] 2 | directory = blueprint-compiler-v0.18.0 3 | source_url = http://gitlab.gnome.org/jwestman/blueprint-compiler/-/archive/v0.18.0/blueprint-compiler-v0.18.0.tar.gz 4 | source_filename = blueprint-compiler-v0.18.0.tar.gz 5 | source_hash = 703c7ccd23cb6f77a8fe9c8cae0f91de9274910ca953de77135b6e79dbff1fc3 6 | 7 | [provide] 8 | program_names = blueprint-compiler 9 | -------------------------------------------------------------------------------- /data/org.v1993.NXDumpClient.desktop.in.in: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=NX Dump Client 3 | GenericName=Dump over USB with nxdumptool 4 | Exec=@bindir@/nxdumpclient 5 | Icon=org.v1993.NXDumpClient 6 | Terminal=false 7 | Type=Application 8 | Categories=GTK;Utility; 9 | Keywords=nxdumpclient;nxdumptool; 10 | StartupNotify=true 11 | StartupWMClass=nxdumpclient 12 | DBusActivatable=true 13 | X-GNOME-UsesNotifications=true 14 | -------------------------------------------------------------------------------- /src/config.vapi: -------------------------------------------------------------------------------- 1 | // Passed via c_args 2 | [CCode (cprefix = "", lower_case_cprefix = "")] 3 | namespace BuildCArgs { 4 | public const string GETTEXT_PACKAGE; 5 | public const string G_LOG_DOMAIN; 6 | } 7 | 8 | // Defined in config.h generated by meson 9 | // lower_case_cprefix is required even if unused in practice 10 | [CCode (cprefix = "NXDC_", lower_case_cprefix = "nxdc_", cheader_filename = "config.h")] 11 | namespace BuildConfig { 12 | public const string VERSION; 13 | public const string LOCALE_DIR; 14 | public const string EXECUTABLE; 15 | } 16 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project('nxdumpclient', ['c', 'vala'], 2 | version: '1.1.3', 3 | meson_version: '>= 1.4.0', 4 | default_options: [ 'warning_level=1', 'werror=false', ], 5 | ) 6 | 7 | i18n = import('i18n') 8 | gnome = import('gnome') 9 | 10 | extra_vapi_dir = meson.current_source_dir() / 'vapi' 11 | add_project_arguments(['--vapidir', extra_vapi_dir], language: 'vala') 12 | 13 | subdir('data') 14 | subdir('src') 15 | subdir('po') 16 | 17 | gnome.post_install( 18 | glib_compile_schemas: true, 19 | gtk_update_icon_cache: true, 20 | update_desktop_database: true, 21 | ) 22 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option( 2 | 'libportal', 3 | type: 'feature', 4 | value: 'auto', 5 | description: 'Use libportal; required to support autostart' 6 | ) 7 | 8 | option( 9 | 'udev_rules', 10 | type: 'combo', 11 | choices: ['install', 'prompt', 'ignore'], 12 | value: 'install', 13 | description: 'How to handle udev rules required for access to Switch:\n' + 14 | '[install] Normal installation; suitable for traditional packaging\n' + 15 | '[prompt] Instruct user how to manually install udevs rule at first launch; suitable for non-system installations\n' + 16 | '[ignore] Do not worry about udev rules\n' 17 | ) 18 | -------------------------------------------------------------------------------- /src/widgets/FileRow.blp: -------------------------------------------------------------------------------- 1 | using Gtk 4.0; 2 | using Adw 1; 3 | 4 | template $NXDumpClientFileRow: Adw.ActionRow { 5 | activatable-widget: button; 6 | 7 | Box { 8 | orientation: horizontal; 9 | spacing: 0; 10 | 11 | Button reset_button { 12 | styles ["flat"] 13 | visible: bind template.allow_reset; // Note: adding `as ` causes a critical after button is clicked. May be a GTK bug. 14 | icon-name: "edit-delete-symbolic"; 15 | tooltip-text: C_("FileRow button", "Reset to default"); 16 | clicked => $emit_reset(); 17 | } 18 | 19 | Button button { 20 | styles ["flat"] 21 | clicked => $select_file(); 22 | focusable: false; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/gtk/help-overlay.blp: -------------------------------------------------------------------------------- 1 | using Gtk 4.0; 2 | 3 | ShortcutsWindow help_overlay { 4 | modal: true; 5 | 6 | ShortcutsSection { 7 | section-name: "shortcuts"; 8 | max-height: 10; 9 | 10 | ShortcutsGroup { 11 | title: C_("shortcut window", "General"); 12 | 13 | ShortcutsShortcut { 14 | title: C_("shortcut window", "Show Shortcuts"); 15 | action-name: "win.show-help-overlay"; 16 | } 17 | 18 | ShortcutsShortcut { 19 | title: C_("shortcut window", "Open Preferences"); 20 | action-name: "app.preferences"; 21 | } 22 | 23 | ShortcutsShortcut { 24 | title: C_("shortcut window", "Quit"); 25 | action-name: "app.quit"; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.github/PKGBUILD.in: -------------------------------------------------------------------------------- 1 | # Maintainer: Valeri Ochinski 2 | 3 | pkgname=nxdumpclient 4 | pkgver=${PKGBUILD_VERSION} 5 | pkgrel=0 6 | pkgdesc="Client program for dumping over USB with nxdumptool" 7 | arch=('x86_64' 'aarch64') 8 | url="https://github.com/v1993/nxdumpclient" 9 | license=('GPL3') 10 | groups=() 11 | depends=('glib2' 'gtk4' 'libadwaita' 'libgusb') 12 | makedepends=('meson' 'vala' 'blueprint-compiler') 13 | source=('https://github.com/v1993/nxdumpclient/archive/${PKGBUILD_REF}.tar.gz') 14 | sha256sums=('AUTOFILL') 15 | 16 | build() { 17 | arch-meson -Dlibportal=disabled "$srcdir/${pkgname}-${pkgver}" build 18 | meson compile -C build 19 | } 20 | 21 | package() { 22 | meson install -C build --destdir "$pkgdir" 23 | } 24 | -------------------------------------------------------------------------------- /.github/workflows/release-flatpakref.yml: -------------------------------------------------------------------------------- 1 | name: Upload .flatpakref to release 2 | 3 | on: 4 | release: 5 | types: published 6 | 7 | jobs: 8 | release: 9 | runs-on: ubuntu-latest 10 | if: startsWith(github.ref, 'refs/tags/') 11 | 12 | permissions: 13 | contents: write 14 | 15 | steps: 16 | - name: Download .flatpakref from Flathub 17 | uses: suisei-cn/actions-download-file@v1.4.0 18 | with: 19 | url: "https://dl.flathub.org/repo/appstream/org.v1993.NXDumpClient.flatpakref" 20 | target: release/ 21 | retry-times: 10 22 | 23 | - name: Upload files to GitHub release 24 | uses: softprops/action-gh-release@v1 25 | with: 26 | files: release/* 27 | -------------------------------------------------------------------------------- /po/POTFILES: -------------------------------------------------------------------------------- 1 | data/org.v1993.NXDumpClient.desktop.in.in 2 | data/org.v1993.NXDumpClient.autostart.desktop.in.in 3 | data/org.v1993.NXDumpClient.appdata.xml.in 4 | data/org.v1993.NXDumpClient.gschema.xml 5 | 6 | # Generate with 7 | # find src/ -type f \( -name '*.vala' -or -name '*.blp' \) | sort 8 | src/Application.vala 9 | src/gtk/help-overlay.blp 10 | src/main.vala 11 | src/PreferencesDialog.blp 12 | src/PreferencesDialog.vala 13 | src/UdevRulesDialog.blp 14 | src/UdevRulesDialog.vala 15 | src/UsbContext.vala 16 | src/UsbDeviceClient.vala 17 | src/UsbDeviceOpener.vala 18 | src/Utils.vala 19 | src/widgets/DeviceStatusRow.blp 20 | src/widgets/DeviceStatusRow.vala 21 | src/widgets/FileRow.blp 22 | src/widgets/FileRow.vala 23 | src/Window.blp 24 | src/Window.vala 25 | -------------------------------------------------------------------------------- /src/nxdumpclient.gresource.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Window.ui 5 | PreferencesDialog.ui 6 | UdevRulesDialog.ui 7 | 8 | gtk/help-overlay.ui 9 | widgets/DeviceStatusRow.ui 10 | widgets/FileRow.ui 11 | 12 | nxdumptool_icon.jpg 13 | 14 | org.v1993.NXDumpClient.appdata.xml 15 | org.v1993.NXDumpClient.autostart.desktop 16 | 71-nxdumptool.rules 17 | 18 | 19 | -------------------------------------------------------------------------------- /.github/workflows/aur-publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish release to AUR 2 | 3 | on: 4 | release: 5 | types: published 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v4 13 | 14 | - name: Preprocess PKGBUILD 15 | shell: bash 16 | run: | 17 | set -a 18 | PKGBUILD_VERSION="$(printf '%s' ${GITHUB_REF_NAME} | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g')" 19 | PKGBUILD_REF="${GITHUB_REF}" 20 | envsubst '$PKGBUILD_VERSION,$PKGBUILD_REF' < .github/PKGBUILD.in > PKGBUILD 21 | 22 | - name: Upload to AUR 23 | uses: KSXGitHub/github-actions-deploy-aur@v3 24 | with: 25 | pkgname: nxdumpclient 26 | pkgbuild: ./PKGBUILD 27 | updpkgsums: true 28 | commit_username: ${{ secrets.AUR_USERNAME }} 29 | commit_email: ${{ secrets.AUR_EMAIL }} 30 | ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }} 31 | commit_message: "[GitHub Action] Release ${{ github.ref_name }}" 32 | -------------------------------------------------------------------------------- /README-MSYS2.md: -------------------------------------------------------------------------------- 1 | # Remarks for those brave and foolish enough to try and build in MSYS2 environment 2 | 3 | **Building in MSYS2 is currently not officially supported. Please do not open issues if it does not work. Creating a redistributable package is a task on its own.** 4 | 5 | ## Use UCRT64 environment 6 | 7 | It will give you the sanest results overall. CLANG64 also should work. 8 | 9 | Install *everything* but stuff like `git` with the environment-specific prefix. This includes meson and python! 10 | 11 | ## Required packages 12 | 13 | *This list may be out-of-date since I'll probably forget about it by the time I'll decide to add a new dependency* 14 | 15 | ```bash 16 | git 17 | ${MINGW_PACKAGE_PREFIX}-desktop-file-utils 18 | ${MINGW_PACKAGE_PREFIX}-gtk4 19 | ${MINGW_PACKAGE_PREFIX}-libadwaita 20 | ${MINGW_PACKAGE_PREFIX}-libgusb 21 | ${MINGW_PACKAGE_PREFIX}-meson 22 | ${MINGW_PACKAGE_PREFIX}-toolchain 23 | ${MINGW_PACKAGE_PREFIX}-vala 24 | ``` 25 | 26 | ## Set environment variable `PYTHONUTF8=1` 27 | 28 | Otherwise, `blueprint-compiler` will fail with `UnicodeDecodeError`. 29 | -------------------------------------------------------------------------------- /src/UdevRulesDialog.blp: -------------------------------------------------------------------------------- 1 | using Gtk 4.0; 2 | using Adw 1; 3 | 4 | template $NXDumpClientUdevRulesDialog: Adw.Dialog { 5 | title: _("Udev rules installation"); 6 | 7 | child: Adw.ToolbarView { 8 | [top] 9 | Adw.HeaderBar { 10 | } 11 | 12 | content: Box { 13 | margin-start: 5; 14 | margin-end: 5; 15 | margin-bottom: 5; 16 | spacing: 20; 17 | orientation: vertical; 18 | 19 | Label { 20 | styles [ "title-4" ] 21 | halign: center; 22 | justify: center; 23 | wrap: true; 24 | label: _("Udev rules must be installed for this program to work. Please exectute the following command to do so:"); 25 | } 26 | 27 | Gtk.ScrolledWindow { 28 | child: Label { 29 | halign: center; 30 | justify: center; 31 | selectable: true; 32 | label: bind template.command_line_for_installation; 33 | }; 34 | } 35 | 36 | CheckButton checkbox { 37 | halign: center; 38 | label: _("I have installed the rules; do not show me this dialog again"); 39 | } 40 | 41 | Button { 42 | styles ["suggested-action"] 43 | sensitive: bind checkbox.active; 44 | halign: center; 45 | label: _("Confirm"); 46 | clicked => $confirmed(); 47 | } 48 | }; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /src/main.vala: -------------------------------------------------------------------------------- 1 | /* main.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | internal string argv0; 22 | 23 | int main(string[] args) { 24 | argv0 = args[0] ?? "nxdumpclient"; 25 | 26 | Intl.setlocale(); 27 | Intl.bindtextdomain(BuildCArgs.GETTEXT_PACKAGE, BuildConfig.LOCALE_DIR); 28 | Intl.bind_textdomain_codeset(BuildCArgs.GETTEXT_PACKAGE, "UTF-8"); 29 | Intl.textdomain(BuildCArgs.GETTEXT_PACKAGE); 30 | 31 | var app = new NXDumpClient.Application(); 32 | return app.run(args); 33 | } 34 | -------------------------------------------------------------------------------- /src/UsbDeviceOpener.vala: -------------------------------------------------------------------------------- 1 | /* UsbDeviceOpener.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | namespace NXDumpClient { 22 | /** 23 | * A helper class to keep track of device use in RAII manner. 24 | */ 25 | class UsbDeviceOpener: Object { 26 | public GUsb.Device dev { get; construct; default = null; } 27 | 28 | public UsbDeviceOpener(owned GUsb.Device dev_) throws Error { 29 | dev_.open(); 30 | Object(dev: (owned)dev_); 31 | } 32 | 33 | ~UsbDeviceOpener() { 34 | try { 35 | if (dev != null) { 36 | dev.close(); 37 | } 38 | } catch(Error e) { 39 | critical("Failed to close a device: %s", e.message); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Window.blp: -------------------------------------------------------------------------------- 1 | using Gtk 4.0; 2 | using Adw 1; 3 | 4 | template $NXDumpClientWindow: Adw.ApplicationWindow { 5 | default-width: 600; 6 | default-height: 500; 7 | title: _("NX Dump Client"); 8 | close-request => $on_close_request(); 9 | 10 | Box { 11 | orientation: vertical; 12 | 13 | Adw.HeaderBar { 14 | [end] 15 | MenuButton { 16 | icon-name: "open-menu-symbolic"; 17 | menu-model: primary_menu; 18 | } 19 | } 20 | 21 | Adw.ToastOverlay toast_overlay { 22 | Stack content_selector { 23 | StackPage { 24 | name: "placeholder"; 25 | child: Adw.StatusPage { 26 | icon-name: "edit-find"; 27 | title: _("No Devices Connected"); 28 | description: _("Connect your Switch and start nxdumptool to proceed"); 29 | }; 30 | } 31 | 32 | StackPage { 33 | name: "devlist"; 34 | child: ListView list_view { 35 | vexpand: true; 36 | model: bind template.devices_model; 37 | 38 | factory: SignalListItemFactory { 39 | setup => $setup_element(); 40 | teardown => $teardown_element(); 41 | bind => $bind_element(); 42 | unbind => $unbind_element(); 43 | }; 44 | }; 45 | } 46 | } 47 | } 48 | } 49 | } 50 | 51 | menu primary_menu { 52 | section { 53 | item (_("_Preferences"), "app.preferences") 54 | item (_("_Keyboard Shortcuts"), "win.show-help-overlay") 55 | item (_("_About NX Dump Client"), "app.about") 56 | } 57 | section { 58 | item (_("_Quit"), "app.quit") 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/UdevRulesDialog.vala: -------------------------------------------------------------------------------- 1 | /* UdevRulesDialog.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | #if PROMPT_FOR_UDEV_RULES 22 | namespace NXDumpClient { 23 | [GtkTemplate (ui = "/org/v1993/NXDumpClient/UdevRulesDialog.ui")] 24 | public class UdevRulesDialog: Adw.Dialog { 25 | protected string command_line_for_installation { 26 | owned get { 27 | var cmd = argv0; 28 | #if WITH_LIBPORTAL 29 | if (Xdp.Portal.running_under_flatpak()) { 30 | cmd = "flatpak run %s".printf(new Application().application_id); 31 | } 32 | #endif 33 | return "%s --print-udev-rules | sudo sh -c 'cat > %s/%s'".printf(cmd, UDEV_RULES_DIR, UDEV_RULES_FILENAME); 34 | } 35 | } 36 | 37 | [GtkCallback] 38 | void confirmed() { 39 | new Application().udev_rules_prompt_accepted(); 40 | close(); 41 | } 42 | } 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /.github/workflows/flatpak.yml: -------------------------------------------------------------------------------- 1 | name: Flatpak 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | release: 9 | types: published 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | arch: 19 | - x86_64 20 | - aarch64 21 | 22 | container: 23 | # Check for a new docker version too if you're updating this 24 | image: ghcr.io/flathub-infra/flatpak-github-actions:gnome-48 25 | options: --privileged 26 | 27 | steps: 28 | - uses: actions/checkout@v4 29 | with: 30 | submodules: recursive 31 | 32 | - name: Install deps 33 | if: ${{ matrix.arch != 'x86_64' }} 34 | run: | 35 | # No package manager available anymore, so grab the static binary. 36 | # Yes, this sucks. Yes, this is what official docs recommend. 37 | # `docker/setup-docker-action` would be really nice to use instead, but calls missing `sudo`. 38 | curl https://download.docker.com/linux/static/stable/x86_64/docker-28.3.2.tgz --output ./docker.tgz 39 | tar xzvf docker.tgz 40 | mv docker/* /usr/bin 41 | 42 | - name: Set up QEMU 43 | if: ${{ matrix.arch != 'x86_64' }} 44 | id: qemu 45 | uses: docker/setup-qemu-action@v3 46 | with: 47 | platforms: arm64 48 | 49 | - uses: flatpak/flatpak-github-actions/flatpak-builder@v6 50 | with: 51 | bundle: nxdumpclient.flatpak 52 | manifest-path: flatpak/org.v1993.NXDumpClient.yml 53 | cache-key: flatpak-builder-${{ github.sha }} 54 | arch: ${{ matrix.arch }} 55 | -------------------------------------------------------------------------------- /src/PreferencesDialog.blp: -------------------------------------------------------------------------------- 1 | using Gtk 4.0; 2 | using Adw 1; 3 | 4 | template $NXDumpClientPreferencesDialog: Adw.PreferencesDialog { 5 | Adw.PreferencesPage { 6 | title: _("General settings"); 7 | 8 | Adw.PreferencesGroup { 9 | title: C_("settings group", "Application"); 10 | 11 | Adw.SwitchRow allow_background_row { 12 | title: C_("setting", "Run in background"); 13 | subtitle: _("Do not exit when main window is closed (use menu to quit)"); 14 | } 15 | 16 | Adw.SwitchRow autostart_enabled_row { 17 | title: C_("setting", "Launch at boot"); 18 | subtitle: _("Automatically start in background on login"); 19 | sensitive: bind template.allow_background; 20 | } 21 | } 22 | 23 | Adw.PreferencesGroup { 24 | title: C_("settings group", "Dump output"); 25 | 26 | $NXDumpClientFileRow destination_directory { 27 | title: C_("setting", "Destination directory"); 28 | select-directory: true; 29 | allow-reset: true; 30 | reset => $reset_destination_directory(); 31 | 32 | file-dialog: FileDialog { 33 | title: C_("dialog title", "Dump destination directory"); 34 | }; 35 | } 36 | 37 | Adw.SwitchRow flatten_output { 38 | title: C_("setting", "Flatten dump directory"); 39 | subtitle: _("Avoid creating subfolders unless necessary"); 40 | } 41 | 42 | Adw.ComboRow nca_checksum_mode { 43 | title: C_("setting", "NSP/NCA checksum verification"); 44 | subtitle: _("“Strict” can catch errors earlier but will fail with certain dump settings"); 45 | 46 | model: StringList {strings [ 47 | C_("checksum mode setting", "Compatible"), 48 | C_("checksum mode setting", "Strict"), 49 | C_("checksum mode setting", "None") 50 | ]}; 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/widgets/DeviceStatusRow.blp: -------------------------------------------------------------------------------- 1 | using Gtk 4.0; 2 | using Adw 1; 3 | 4 | template $NXDumpClientDeviceStatusRow: Adw.Bin { 5 | Box { 6 | orientation: vertical; 7 | hexpand: true; 8 | 9 | Box { 10 | orientation: horizontal; 11 | 12 | Image { 13 | resource: "/org/v1993/NXDumpClient/nxdumptool_icon.jpg"; 14 | icon-size: large; 15 | } 16 | 17 | FlowBox { 18 | orientation: horizontal; 19 | hexpand: true; 20 | selection-mode: none; 21 | min-children-per-line: 2; 22 | 23 | FlowBoxChild { 24 | Box { 25 | orientation: vertical; 26 | width-request: 128; 27 | 28 | Label { 29 | styles ["title-2"] 30 | label: _("Status"); 31 | } 32 | 33 | Label status_text { 34 | use-markup: true; 35 | label: bind template.status_text; 36 | } 37 | } 38 | } 39 | 40 | FlowBoxChild { 41 | Box { 42 | orientation: vertical; 43 | Label { 44 | styles ["title-2"] 45 | label: _("Connection"); 46 | } 47 | 48 | Label { 49 | use-markup: true; 50 | label: bind template.connection_speed_text; 51 | } 52 | } 53 | } 54 | 55 | FlowBoxChild { 56 | Box { 57 | orientation: vertical; 58 | width-request: 128; 59 | 60 | Label { 61 | styles ["title-2"] 62 | label: C_("nxdumptool version", "Version"); 63 | } 64 | 65 | Label { 66 | label: bind template.version_text; 67 | } 68 | } 69 | } 70 | } 71 | } 72 | 73 | Box progress_box { 74 | orientation: vertical; 75 | hexpand: true; 76 | sensitive: false; 77 | 78 | Label { 79 | styles ["title-2"] 80 | label: _("Transfer progress"); 81 | } 82 | 83 | ProgressBar progress_bar { 84 | show-text: true; 85 | fraction: bind template.transfer_fraction; 86 | text: bind template.transfer_text; 87 | } 88 | 89 | Label { 90 | styles ["heading"] 91 | ellipsize: start; 92 | label: bind template.file_name; 93 | } 94 | 95 | Label { 96 | styles ["body"] 97 | ellipsize: end; 98 | label: bind template.file_name_inner; 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /flatpak/org.v1993.NXDumpClient.yml: -------------------------------------------------------------------------------- 1 | app-id: org.v1993.NXDumpClient 2 | runtime: org.gnome.Platform 3 | # Remember to update CI image as well 4 | runtime-version: '48' 5 | sdk: org.gnome.Sdk 6 | command: nxdumpclient 7 | finish-args: 8 | - --share=ipc 9 | - --socket=fallback-x11 10 | - --socket=wayland 11 | # Switch USB access 12 | - --device=all 13 | # Required for hotplug 14 | - --share=network 15 | # Default dump destination 16 | - --filesystem=xdg-download 17 | 18 | cleanup: 19 | - /include 20 | - /lib/pkgconfig 21 | - /lib/girepository-1.0 22 | - /share/gir-1.0 23 | - /share/vala 24 | 25 | modules: 26 | - shared-modules/libusb/libusb.json 27 | 28 | - name: blueprint-compiler 29 | buildsystem: meson 30 | cleanup: 31 | - '*' 32 | sources: 33 | - type: git 34 | url: https://gitlab.gnome.org/jwestman/blueprint-compiler.git 35 | tag: v0.18.0 36 | commit: 07c9c9df9cd1b6b4454ecba21ee58211e9144a4b 37 | x-checker-data: 38 | type: git 39 | tag-pattern: ^v([\d.]+)$ 40 | version-scheme: semantic 41 | 42 | - name: libgusb 43 | buildsystem: meson 44 | config-opts: 45 | - -Ddocs=false 46 | - -Dtests=false 47 | cleanup: 48 | - /bin 49 | sources: 50 | - type: archive 51 | url: https://github.com/hughsie/libgusb/releases/download/0.4.9/libgusb-0.4.9.tar.xz 52 | sha256: 9df5ef301d6a4b361002aa52cce1165a87a89744055879bdbab31e7e86f1e846 53 | x-checker-data: 54 | type: json 55 | url: https://api.github.com/repos/hughsie/libgusb/releases/latest 56 | version-query: .tag_name 57 | url-query: .assets[] | select(.name=="libgusb-" + $version + ".tar.xz") 58 | | .browser_download_url 59 | 60 | - name: libportal 61 | buildsystem: meson 62 | config-opts: 63 | - -Dauto_features=disabled 64 | - -Dbackend-gtk4=enabled 65 | - -Ddocs=false 66 | - -Dtests=false 67 | sources: 68 | - type: archive 69 | url: https://github.com/flatpak/libportal/releases/download/0.8.1/libportal-0.8.1.tar.xz 70 | sha256: 281e54e4f8561125a65d20658f1462ab932b2b1258c376fed2137718441825ac 71 | x-checker-data: 72 | type: json 73 | url: https://api.github.com/repos/flatpak/libportal/releases/latest 74 | version-query: .tag_name 75 | url-query: .assets[] | select(.name=="libportal-" + $version + ".tar.xz") 76 | | .browser_download_url 77 | 78 | - name: nxdumpclient 79 | buildsystem: meson 80 | builddir: true 81 | config-opts: 82 | - -Dudev_rules=prompt 83 | - -Dlibportal=enabled 84 | sources: 85 | - type: dir 86 | path: .. 87 | skip: 88 | - flatpak/ 89 | - .git/ 90 | -------------------------------------------------------------------------------- /data/org.v1993.NXDumpClient.gschema.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | b"" 6 | Path to the output folder 7 | 8 | Path to the directory where dumps are stored. 9 | Empty value corresponds to using default path. 10 | 11 | 12 | 13 | false 14 | Output directly into dump destination directory 15 | 16 | By default, subfolders are always created when requested by nxdumptool. 17 | This options forces nxdumpclient to always output single-file dumps into 18 | dump directory and reduces nesting for multi-file dumps. 19 | 20 | 21 | 22 | 23 | 0 24 | Checksum verification mode for NCA/NSP files (enumeration) 25 | 26 | (0) Compatible mode parses NSP header, which makes it work with non-standard dump options but delays verification until the end and disables it for standalone NCAs. 27 | (1) Strict mode takes checksums from NCA filenames, which allows to abort dump early in case of a mismatch. 28 | (2) None disables checksum verification completely. 29 | Yes, I know that GSettings support real enumerations, but they are more annoying to use and provide little benefit in my case. 30 | 31 | 32 | 33 | false 34 | Has user closed udev rules prompt 35 | 36 | This is only used in cases where udev rules must me manually installed. 37 | 38 | 39 | 40 | false 41 | If application should continue running in background without a window 42 | 43 | Desktop notifications are used to communicate status in this case. Pass `--background` when this option is enabled 44 | to launch without a window. 45 | 46 | 47 | 48 | false 49 | Status of application's autostart capability 50 | 51 | If application is expected to be launched at boot. 52 | Modifying this option manually will do nothing but confuse the application. 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/UsbContext.vala: -------------------------------------------------------------------------------- 1 | /* UsbContext.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | namespace NXDumpClient { 22 | class UsbContext: GUsb.Context { 23 | private const uint16 TARGET_VID = 0x057E; 24 | private const uint16 TARGET_PID = 0x3000; 25 | private const string TARGET_MANUFACTURER = "DarkMatterCore"; 26 | private const string TARGET_PRODUCT = "nxdumptool"; 27 | private const string TARGET_PRODUCT_DEV = "nxdt_rw_poc"; // TODO: remove once rewrite is un-re-branded 28 | 29 | public UsbContext() throws Error { 30 | Object(); 31 | init(); 32 | } 33 | 34 | public override void device_added(GUsb.Device dev) { 35 | try { 36 | if (dev.get_vid() != TARGET_VID || dev.get_pid() != TARGET_PID) { 37 | return; 38 | } 39 | 40 | var opener = new UsbDeviceOpener(dev); 41 | var manufacturer = opener.dev.get_string_descriptor(dev.get_manufacturer_index()); 42 | var product = opener.dev.get_string_descriptor(dev.get_product_index()); 43 | 44 | if (manufacturer != TARGET_MANUFACTURER || (product != TARGET_PRODUCT && product != TARGET_PRODUCT_DEV)) { 45 | return; 46 | } 47 | 48 | debug("Detected a suitable device! Product string: %s", dev.get_string_descriptor(dev.get_product_index())); 49 | var app = new Application(); 50 | var client = new UsbDeviceClient((owned)opener, app.cancellable); 51 | app.device_list.append(client); 52 | app.device_added(client); 53 | } catch(GUsb.DeviceError.NO_DEVICE e) { 54 | // Not really a problem - device was disconnected during setup 55 | } catch(Error e) { 56 | report_error(_("Error handling a new device"), e.message); 57 | } 58 | } 59 | 60 | public override void device_removed(GUsb.Device dev) { 61 | var devlist = new Application().device_list; 62 | for(uint i = 0; i < devlist.n_items;) { 63 | var list_dev = (UsbDeviceClient) devlist.get_object(i); 64 | if (dev == list_dev.dev) { 65 | devlist.remove(i); 66 | new Application().device_removed(dev); 67 | } else { 68 | ++i; 69 | } 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /data/meson.build: -------------------------------------------------------------------------------- 1 | desktopconf = configuration_data() 2 | desktopconf.set('bindir', get_option('prefix') / get_option('bindir')) 3 | 4 | desktop_file_in = configure_file( 5 | input: 'org.v1993.NXDumpClient.desktop.in.in', 6 | output: 'org.v1993.NXDumpClient.desktop.in', 7 | configuration: desktopconf 8 | ) 9 | 10 | autostart_desktop_file_in = configure_file( 11 | input: 'org.v1993.NXDumpClient.autostart.desktop.in.in', 12 | output: 'org.v1993.NXDumpClient.autostart.desktop.in', 13 | configuration: desktopconf 14 | ) 15 | 16 | desktop_file = i18n.merge_file( 17 | input: desktop_file_in, 18 | output: 'org.v1993.NXDumpClient.desktop', 19 | type: 'desktop', 20 | po_dir: '../po', 21 | install: true, 22 | install_dir: get_option('datadir') / 'applications' 23 | ) 24 | 25 | # Packed into resources 26 | autostart_desktop_file = i18n.merge_file( 27 | input: autostart_desktop_file_in, 28 | output: 'org.v1993.NXDumpClient.autostart.desktop', 29 | type: 'desktop', 30 | po_dir: '../po', 31 | ) 32 | 33 | desktop_utils = find_program('desktop-file-validate', required: false) 34 | if desktop_utils.found() 35 | test('Validate desktop file', desktop_utils, args: [desktop_file]) 36 | endif 37 | 38 | appstream_file = i18n.merge_file( 39 | input: 'org.v1993.NXDumpClient.appdata.xml.in', 40 | output: 'org.v1993.NXDumpClient.appdata.xml', 41 | po_dir: '../po', 42 | install: true, 43 | install_dir: get_option('datadir') / 'appdata' 44 | ) 45 | 46 | appstream_util = find_program('appstream-util', required: false) 47 | if appstream_util.found() 48 | # Use --nonet to suppress pointless warnings about screenshot 49 | test('Validate appstream file', appstream_util, args: ['validate', '--nonet', appstream_file]) 50 | endif 51 | 52 | install_data('org.v1993.NXDumpClient.gschema.xml', 53 | install_dir: get_option('datadir') / 'glib-2.0' / 'schemas' 54 | ) 55 | 56 | compile_schemas = find_program('glib-compile-schemas', required: false) 57 | if compile_schemas.found() 58 | test('Validate schema file', 59 | compile_schemas, 60 | args: ['--strict', '--dry-run', meson.current_source_dir()]) 61 | endif 62 | 63 | dbusconf = configuration_data() 64 | dbusconf.set('bindir', get_option('prefix') / get_option('bindir')) 65 | configure_file( 66 | input: 'org.v1993.NXDumpClient.service.in', 67 | output: 'org.v1993.NXDumpClient.service', 68 | configuration: dbusconf, 69 | install: true, 70 | install_dir: get_option('datadir') / 'dbus-1' / 'services', 71 | ) 72 | 73 | 74 | if get_option('udev_rules') == 'install' 75 | install_data('71-nxdumptool.rules', 76 | install_dir: 'lib' / 'udev' / 'rules.d' 77 | ) 78 | endif 79 | 80 | install_data( 81 | 'icons/hicolor/scalable/apps/org.v1993.NXDumpClient.svg', 82 | 'icons/hicolor/256x256/apps/org.v1993.NXDumpClient.png', 83 | 84 | install_dir: get_option('datadir'), 85 | preserve_path: true 86 | ) 87 | -------------------------------------------------------------------------------- /src/meson.build: -------------------------------------------------------------------------------- 1 | nxdc_sources = [ 2 | 'main.vala', 3 | 'config.vapi', 4 | 5 | 'Application.vala', 6 | 'Window.vala', 7 | 'PreferencesDialog.vala', 8 | 'UdevRulesDialog.vala', 9 | 'UsbContext.vala', 10 | 'UsbDeviceClient.vala', 11 | 'UsbDeviceOpener.vala', 12 | 'Utils.vala', 13 | 14 | 'widgets/DeviceStatusRow.vala', 15 | 'widgets/FileRow.vala', 16 | ] 17 | 18 | nxdc_blueprints = files( 19 | 'Window.blp', 20 | 'PreferencesDialog.blp', 21 | 'UdevRulesDialog.blp', 22 | 23 | 'gtk/help-overlay.blp', 24 | 'widgets/DeviceStatusRow.blp', 25 | 'widgets/FileRow.blp', 26 | ) 27 | 28 | extra_vala_args = [] 29 | 30 | nxdc_deps = [ 31 | dependency('glib-2.0', version: '>=2.76'), 32 | dependency('gio-2.0'), 33 | dependency('gtk4', version: '>=4.13'), 34 | dependency('libadwaita-1', version: '>= 1.5'), 35 | 36 | dependency('gusb'), 37 | ] 38 | 39 | libportal = dependency('libportal', required: get_option('libportal')) 40 | libportal_gtk4 = dependency('libportal-gtk4', required: get_option('libportal')) 41 | 42 | if (libportal.found() and libportal_gtk4.found()) 43 | nxdc_deps += [libportal, libportal_gtk4] 44 | extra_vala_args += ['-D', 'WITH_LIBPORTAL'] 45 | endif 46 | 47 | if get_option('udev_rules') == 'prompt' 48 | extra_vala_args += ['-D', 'PROMPT_FOR_UDEV_RULES'] 49 | endif 50 | 51 | nxdc_blueprint_genlist = generator( 52 | find_program('blueprint-compiler'), 53 | output: '@BASENAME@.ui', 54 | arguments: ['compile', '--output', '@OUTPUT@', '@INPUT@'] 55 | ).process( 56 | nxdc_blueprints, 57 | preserve_path_from: meson.current_source_dir() 58 | ) 59 | 60 | # Ugly, ugly hack, see https://github.com/mesonbuild/meson/issues/12336 61 | nxdc_blueprint_tgt = custom_target( 62 | 'nxdc-blueprints', 63 | command: ['true'], 64 | capture: true, 65 | output: 'nxdc-blueprints.dummy', 66 | input: nxdc_blueprint_genlist 67 | ) 68 | 69 | nxdc_blueprints_build_dir = nxdc_blueprint_tgt.full_path() + '.p' 70 | 71 | nxdc_sources += gnome.compile_resources('nxdumpclient-resources', 72 | 'nxdumpclient.gresource.xml', 73 | c_name: 'nxdumpclient', 74 | dependencies: [ nxdc_blueprint_tgt, appstream_file, autostart_desktop_file ], 75 | source_dir: [ nxdc_blueprints_build_dir, '..' / 'data' ] 76 | ) 77 | 78 | conf_data = configuration_data() 79 | 80 | conf_data.set_quoted('NXDC_VERSION', meson.project_version()) 81 | conf_data.set_quoted('NXDC_LOCALE_DIR', get_option('prefix') / get_option('localedir')) 82 | conf_data.set_quoted('NXDC_EXECUTABLE', get_option('prefix') / get_option('bindir') / 'nxdumpclient') 83 | 84 | configure_file( 85 | output: 'config.h', 86 | configuration: conf_data 87 | ) 88 | 89 | executable('nxdumpclient', nxdc_sources, 90 | dependencies: nxdc_deps, 91 | vala_args: extra_vala_args, 92 | install: true, 93 | 94 | c_args: [ 95 | # These must be defined before GLib includes 96 | '-DGETTEXT_PACKAGE="nxdumpclient"', 97 | '-DG_LOG_DOMAIN="nxdumpclient"', 98 | ], 99 | win_subsystem: 'windows', 100 | ) 101 | -------------------------------------------------------------------------------- /src/Utils.vala: -------------------------------------------------------------------------------- 1 | /* Utils.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | namespace NXDumpClient { 22 | internal const string UDEV_RULES_DIR = "/etc/udev/rules.d"; 23 | internal const string UDEV_RULES_FILENAME = "71-nxdumptool.rules"; 24 | 25 | string get_default_dump_path() { 26 | return Environment.get_user_special_dir(DOWNLOAD) ?? Environment.get_home_dir(); 27 | } 28 | 29 | /// Note: does not throw if target already exists 30 | async void create_directory_with_parents_async(File file, Cancellable? cancellable = null) throws Error { 31 | var to_create = new File[0]; 32 | var? current_target = file; 33 | while(current_target != null) { 34 | try { 35 | yield current_target.make_directory_async(Priority.DEFAULT, cancellable); 36 | break; 37 | } catch(IOError.EXISTS e) { 38 | break; 39 | } catch(IOError.NOT_FOUND e) { 40 | to_create += current_target; 41 | current_target = current_target.get_parent(); 42 | } 43 | } 44 | 45 | for (int i = to_create.length - 1; i >= 0; --i) { 46 | try { 47 | yield to_create[i].make_directory_async(Priority.DEFAULT, cancellable); 48 | } catch(IOError.EXISTS e) { 49 | // Created by another process 50 | } 51 | } 52 | } 53 | 54 | string format_usb_abi(uint8 abi) { 55 | return @"%hhu.%hhu".printf(abi >> 4, abi & 0xF); 56 | } 57 | 58 | namespace FileSettingUtils { 59 | [CCode (has_target = false)] 60 | delegate string DefaultPathFunc(); 61 | 62 | /// A DefaultPathFunc **MUST** be passed as user_data 63 | 64 | bool @get(Value value, Variant variant, void* user_data) 65 | requires(variant.is_of_type(VariantType.BYTESTRING)) 66 | requires(user_data != null) 67 | { 68 | unowned var uri = variant.get_bytestring(); 69 | File file; 70 | if (uri == null || uri.length == 0) { 71 | file = File.new_for_path(((DefaultPathFunc)user_data)()); 72 | } else { 73 | file = File.new_for_uri(uri); 74 | } 75 | value.take_object((owned)file); 76 | return true; 77 | } 78 | 79 | Variant @set(Value value, VariantType expected_type, void* user_data) 80 | requires(expected_type.equal(VariantType.BYTESTRING)) 81 | { 82 | var? file = value.get_object() as File; 83 | 84 | if (file == null) { 85 | return null; // Not a bug, a binding deficiency 86 | } 87 | 88 | return new Variant.bytestring(file.get_uri()); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /data/org.v1993.NXDumpClient.appdata.xml.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | NX Dump Client 4 | org.v1993.NXDumpClient 5 | v19930312 6 | Client for dumping over USB with nxdumptool 7 | CC0-1.0 8 | GPL-3.0-or-later 9 | nxdumpclient 10 | 11 | org.v1993.NXDumpClient.desktop 12 | https://github.com/v1993/nxdumpclient 13 | https://github.com/v1993/nxdumpclient/issues 14 | 15 |

Client for dumping over USB with nxdumptool.

16 |
17 | 18 | nxdumpclient 19 | nxdumptool 20 | 21 | 22 | 23 | NX Dump Tool receiving a file 24 | https://raw.githubusercontent.com/v1993/nxdumpclient/main/data/screenshot-1.png 25 | 26 | 27 | 28 | 29 | 30 |

A maintenance release before 1.2.0.

31 |
32 |
33 | 34 | 35 |

Release highlights:

36 |
    37 |
  • Add initial support for USB ABI 1.2
  • 38 |
39 |
40 |
41 | 42 | 43 |

Release highlights:

44 |
    45 |
  • Add basic speed and remaining time estimation
  • 46 |
47 |
48 |
49 | 50 | 51 |

Release highlights:

52 |
    53 |
  • Improve checksum verification - support non-standard dump options by default
  • 54 |
55 |
56 |
57 | 58 | 59 |

Fixes:

60 |
    61 |
  • Fix StartupNotify functionality under flatpak
  • 62 |
63 |
64 |
65 | 66 | 67 |

First stable release.

68 |

Release highlights:

69 |
    70 |
  • Support for running in background and autostart
  • 71 |
  • Confirm exit if file transfer is in progress
  • 72 |
73 |
74 |
75 | 76 | 77 |

Initial release.

78 |
79 |
80 |
81 | 82 | offline-only 83 | 84 | 85 | usb:v057Ep3000d0100dc00dsc00dp00icFFiscFFipFFin00 86 | 87 | 88 | Utility 89 | 90 |
91 | -------------------------------------------------------------------------------- /src/widgets/FileRow.vala: -------------------------------------------------------------------------------- 1 | /* FileRow.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | private bool transform_file_to_path(Binding bin, Value from, out Value to) { 22 | unowned var? file = from.get_object() as File; 23 | to = Value(Type.STRING); 24 | if (file != null) { 25 | to.set_string(file.get_parse_name()); 26 | } else { 27 | to.set_string(_("(unset)")); 28 | } 29 | return true; 30 | } 31 | 32 | private bool transform_select_directory_to_icon(Binding bin, Value from, out Value to) { 33 | var is_directory = from.get_boolean(); 34 | to = Value(Type.STRING); 35 | to.set_string(is_directory ? "folder-open-symbolic" : "document-open-symbolic"); 36 | return true; 37 | } 38 | 39 | private bool transform_select_directory_to_tooltip(Binding bin, Value from, out Value to) { 40 | var is_directory = from.get_boolean(); 41 | to = Value(Type.STRING); 42 | to.set_string(is_directory ? _("Select directory") : _("Select file")); 43 | return true; 44 | } 45 | 46 | namespace NXDumpClient { 47 | [GtkTemplate (ui = "/org/v1993/NXDumpClient/widgets/FileRow.ui")] 48 | public class FileRow: Adw.ActionRow { 49 | public File? file { get; set; default = null; } 50 | public bool select_directory { get; set; default = false; } 51 | public bool allow_reset { get; set; default = false; } 52 | public Gtk.FileDialog file_dialog { get; set; default = new Gtk.FileDialog(); } 53 | 54 | public Cancellable? cancellable { get; set; default = null; } 55 | 56 | public signal void reset(); 57 | 58 | [GtkChild] 59 | private unowned Gtk.Button button; 60 | 61 | // See https://gitlab.gnome.org/GNOME/vala/-/issues/1493 62 | [GtkCallback] 63 | private void emit_reset() { 64 | reset.emit(); 65 | } 66 | 67 | construct { 68 | bind_property("file", this, "subtitle", SYNC_CREATE, transform_file_to_path, null); 69 | bind_property("select-directory", button, "icon-name", SYNC_CREATE, transform_select_directory_to_icon, null); 70 | bind_property("select-directory", button, "tooltip-text", SYNC_CREATE, transform_select_directory_to_tooltip, null); 71 | } 72 | 73 | [GtkCallback] 74 | private async void select_file() { 75 | try { 76 | File? new_file; 77 | var root = get_root() as Gtk.Window; 78 | if (select_directory) { 79 | new_file = yield file_dialog.select_folder(root, cancellable); 80 | } else { 81 | new_file = yield file_dialog.open(root, cancellable); 82 | } 83 | 84 | if (new_file != null) { 85 | file = new_file; 86 | } 87 | } catch(IOError.CANCELLED e) { 88 | } catch(Gtk.DialogError.CANCELLED e) { 89 | } catch(Gtk.DialogError.DISMISSED e) { 90 | } catch(Error e) { 91 | critical("Unhandled error: %s", e.message); 92 | } 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Window.vala: -------------------------------------------------------------------------------- 1 | /* Window.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | namespace NXDumpClient { 22 | [GtkTemplate (ui = "/org/v1993/NXDumpClient/Window.ui")] 23 | public class Window: Adw.ApplicationWindow { 24 | [GtkChild] 25 | private unowned Adw.ToastOverlay toast_overlay; 26 | [GtkChild] 27 | private unowned Gtk.Stack content_selector; 28 | 29 | public Gtk.SelectionModel devices_model { get; construct; } 30 | 31 | private bool close_confirmed = false; 32 | 33 | public Window(Gtk.Application app) { 34 | Object( 35 | application: app 36 | ); 37 | } 38 | 39 | ~Window() { 40 | debug("Window finalized"); 41 | } 42 | 43 | private void select_child(ListModel model, uint position, uint removed, uint added) 44 | requires(model is ListStore) 45 | { 46 | content_selector.set_visible_child_name(((ListStore)model).n_items == 0 ? "placeholder" : "devlist"); 47 | } 48 | 49 | construct { 50 | unowned var devlist = new Application().device_list; 51 | devlist.items_changed.connect(this.select_child); 52 | select_child(devlist, 0, 0, 0); 53 | devices_model = new Gtk.NoSelection(devlist); 54 | } 55 | 56 | public void show_toast(owned Adw.Toast toast) { 57 | toast_overlay.add_toast((owned)toast); 58 | } 59 | 60 | [GtkCallback] 61 | private bool on_close_request() { 62 | // Return true to NOT close, false to CLOSE 63 | if (close_confirmed) { 64 | return false; // Close, queried the user and was allowed to 65 | } 66 | 67 | if (FileTransferInhibitor.current_count == 0) { 68 | return false; // Close, nothing is running in background 69 | } 70 | 71 | var app = new Application(); 72 | if (app.hold_background_reference) { 73 | return false; // Close, application will keep running 74 | } 75 | 76 | query_for_close.begin(); 77 | return true; // Do not close; present a query 78 | } 79 | 80 | private async void query_for_close() { 81 | var result = yield new Application().query_app_exit(); 82 | if (result) { 83 | close_confirmed = true; 84 | close(); 85 | close_confirmed = false; 86 | } 87 | } 88 | 89 | [GtkCallback] 90 | private void setup_element(Gtk.SignalListItemFactory factory, Object o) { 91 | var litem = (Gtk.ListItem)o; 92 | litem.child = new DeviceStatusRow(); 93 | } 94 | 95 | [GtkCallback] 96 | private void teardown_element(Gtk.SignalListItemFactory factory, Object o) { 97 | } 98 | 99 | [GtkCallback] 100 | private void bind_element(Gtk.SignalListItemFactory factory, Object o) { 101 | var litem = (Gtk.ListItem)o; 102 | var child = (DeviceStatusRow)litem.child; 103 | child.bind((UsbDeviceClient)litem.item); 104 | } 105 | 106 | [GtkCallback] 107 | private void unbind_element(Gtk.SignalListItemFactory factory, Object o) { 108 | var litem = (Gtk.ListItem)o; 109 | var child = (DeviceStatusRow)litem.child; 110 | child.unbind(); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NX Dump Client 2 | 3 | ## A client for dumping over USB with [nxdumptool](https://github.com/DarkMatterCore/nxdumptool) 4 | 5 | ![GitHub Actions - Build Status](https://img.shields.io/github/actions/workflow/status/v1993/nxdumpclient/flatpak.yml) 6 | 7 | [![AUR release package](https://img.shields.io/badge/aur-nxdumpclient-blue)](https://aur.archlinux.org/packages/nxdumpclient) 8 | [![AUR git package](https://img.shields.io/badge/aur-nxdumpclient--git-blue)](https://aur.archlinux.org/packages/nxdumpclient-git) 9 | 10 | [![Flathub Badge](https://dl.flathub.org/assets/badges/flathub-badge-i-en.png)](https://flathub.org/apps/org.v1993.NXDumpClient) 11 | 12 | ![screenshot](data/screenshot-1.png) 13 | 14 | Not much to say, really - it just works! You can enable autostart in settings and leave it running in background if you so desire. 15 | 16 | ### Official nxdumptool discord server where I and other helpful people can be found: https://discord.gg/SCbbcQx 17 | 18 | ## Frequently asked questions 19 | 20 | ### What is the preferred installation method? 21 | 22 | Short version: AUR (stable) package if you're on Arch-based distro, flatpak from Flathub otherwise. Installing flatpaks from CI is normally heavily discouraged since those won't be automatically updated - please install from Flathub if possible instead. 23 | 24 | Long version: Manual building or using unofficial packages may be viable options in non-Arch environments, but Arch's/GNOME Flatpak SDK's (whichever is less up-to-date at the moment) is what ultimately determines what is the highest library version features from which I'll consider using. While I'm willing to support more distros natively, I won't be going out of my way to do so (a few tweaks to build system are fine, having to manually implement a feature present in newer version of a library/tool is not). 25 | 26 | ### Where are the dumps stored? 27 | 28 | By default in your Downloads folder. You can change path (and a couple of other handy settings) in preferences. 29 | 30 | ### Why are there different NSP/NCA checksum modes and which one should I use? 31 | 32 | A fragment of NCA's SHA256 checksum is contained within its filename, allowing to verify its contents. Among other possible file types, NSPs typically contain multiple NCAs as well as a list of filenames in their header (which is sent last during transfer). When dumping, the original name of NCA is sent with it, although it might not check out with its contents if certain dump options that modify them are enabled. However, nxdumptool later sends adjusted NCA names within NSP header. 33 | 34 | * Compatible mode uses filenames from NSP header, so it will work correctly if NCAs are modified by nxdumptool, but can only detect errors after the transfer has finished. 35 | * Strict mode uses original NCA filenames, so it can detect errors as soon as the NCA is transferred, but will erroneously fail if NCA was modified by nxdumptool. 36 | * None, as its name implies, completely disables checksum computation and verification. 37 | 38 | As a result, strict mode is recommended, but only if you do not use nxdumptool settings that mess with NCA contents -- which is almost everything save for "remove console specific data" and "generate authoringtool data". Compatible mode should be used if you, for whatever reason, want to use these options (hint: you probably don't). "None" should only be used in unorthodox cases like a badly named NCA file in a RomFS dump - files are hashed during transfer (i.e. never read back from drive) and checksum computation is very unlikely to have any meaningful impact on transfer speed. 39 | 40 | P.S.: standalone NCAs are never tampered with, so strict mode check is used for them in both checksum modes. XCIs do not support additional verification. 41 | 42 | ### I get permissions error. Why? 43 | 44 | Installing special udev rules is required for user access to device. You should have been prompted to do so interactively on first launch if using flatpak; system-wide installation installs rules automatically. Please report an issue if you think udev rules should have been installed by now - make sure to mention installation method in your report. 45 | 46 | ### Why does flatpak version require network access, anyways? 47 | 48 | Because of how udev events are communicated on Linux. You can manually revoke it if you so desire, but that will break support for device hotplug - i.e. you'll have to always connect your switch before starting the program. 49 | 50 | ## Building manually 51 | 52 | Please note that a fairly recent distro is required - see dependencies section below. 53 | 54 | ```bash 55 | git clone https://github.com/v1993/nxdumpclient.git 56 | cd nxdumpclient 57 | meson setup --buildtype=debugoptimized -Db_lto=true --prefix=/usr build 58 | meson compile -C build 59 | meson install -C build 60 | ``` 61 | 62 | An alternative to direct installation is to use flatpak manifest stored at `flatpak/org.v1993.NXDumpClient.yml` (please note that building with flatpak requires initializing git submodules; they are not used otherwise). Use of `flatpak-builder` is out-of-scope for this document - download pre-built package from Flathub if you just want to use the flatpak version. 63 | 64 | ### Updating 65 | 66 | ```bash 67 | cd nxdumpclient 68 | git pull 69 | meson subprojects update 70 | meson compile -C build 71 | meson install -C build 72 | ``` 73 | 74 | Note for those using `flatpak-builder`: you'll want to update git submodules as well, but can skip updating meson subprojects. 75 | 76 | ### Dependencies 77 | 78 | * GTK >= 4.13 79 | * libadwaita >= 1.5 80 | * GLib >= 2.76 81 | * GUsb (reasonably new) 82 | * libportal (optional for non-sandbox builds) 83 | * blueprint-compiler >= 0.10 (build-only; automatically fetched by meson if not available) 84 | -------------------------------------------------------------------------------- /data/icons/hicolor/scalable/apps/org.v1993.NXDumpClient.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 36 | 38 | 44 | 50 | 56 | 62 | 63 | 68 | 76 | 87 | 96 | 97 | 102 | 107 | 112 | 117 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/widgets/DeviceStatusRow.vala: -------------------------------------------------------------------------------- 1 | /* DeviceStatusRow.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | namespace NXDumpClient { 22 | private const uint32 MIN_TRANSFER_SPEED_SIZE = BLOCK_SIZE * 5; 23 | 24 | [GtkTemplate (ui = "/org/v1993/NXDumpClient/widgets/DeviceStatusRow.ui")] 25 | class DeviceStatusRow: Adw.Bin { 26 | protected UsbDeviceClient? device { get; set; default = null; } 27 | 28 | private ulong[] device_signals = {}; 29 | 30 | public void bind(UsbDeviceClient dev_) { 31 | device = dev_; 32 | update_status(); 33 | device_signals += device.notify["status"].connect(this.on_status_changed); 34 | update_connection_speed(); // Does not need to be tracked 35 | update_version(); 36 | device_signals += device.notify["version-string"].connect(this.on_version_changed); 37 | setup_progress(); 38 | device_signals += device.transfer_started.connect(this.transfer_started_cb); 39 | // Empty files are not watched for 40 | device_signals += device.transfer_next_inner_file.connect(this.update_filenames_cb); 41 | device_signals += device.transfer_progress.connect(this.update_progress_cb); 42 | device_signals += device.transfer_complete.connect(this.transfer_complete_cb); 43 | device_signals += device.transfer_failed.connect(this.transfer_failed_cb); 44 | } 45 | 46 | public void unbind() { 47 | unregister_sginals(); 48 | device = null; 49 | } 50 | 51 | ~DeviceStatusRow() { 52 | unregister_sginals(); 53 | } 54 | 55 | private void unregister_sginals() { 56 | foreach(var handler_id in device_signals) { 57 | device.disconnect(handler_id); 58 | } 59 | 60 | device_signals = {}; 61 | } 62 | 63 | private void on_status_changed(Object client, ParamSpec pspec) { 64 | update_status(); 65 | } 66 | 67 | private void on_version_changed(Object client, ParamSpec pspec) { 68 | update_version(); 69 | } 70 | 71 | protected string status_text { get; set; default = ""; } 72 | protected string connection_speed_text { get; set; default = ""; } 73 | protected string version_text { get; set; default = ""; } 74 | 75 | protected double transfer_fraction { get; set; default = 0.0; } 76 | protected string transfer_text { get; set; default = ""; } 77 | protected string file_name { get; set; default = ""; } 78 | protected string file_name_inner { get; set; default = ""; } 79 | 80 | [GtkChild] 81 | unowned Gtk.Box progress_box; 82 | 83 | private void update_status() 84 | requires(device != null) 85 | { 86 | switch (device.status) { 87 | case UNINITIALIZED: 88 | status_text = C_("status", "Uninitialized"); 89 | break; 90 | case CONNECTED: 91 | status_text = C_("status", "Connected"); 92 | break; 93 | case TRANSFER: 94 | status_text = C_("status", "Transferring file"); 95 | break; 96 | case FATAL_ERROR: 97 | status_text = "" + C_("status", "Fatal error") + ""; 98 | break; 99 | } 100 | 101 | progress_box.sensitive = (device.status == TRANSFER); 102 | } 103 | 104 | private void setup_progress() 105 | requires(device != null) 106 | { 107 | if (device.status != TRANSFER) { 108 | reset_transfer_view(); 109 | } else { 110 | update_filenames(); 111 | update_progress(); 112 | } 113 | } 114 | 115 | private void update_progress_cb(UsbDeviceClient client) { 116 | update_progress(); 117 | } 118 | 119 | private void update_progress() 120 | requires(device != null) 121 | { 122 | transfer_fraction = ((double)device.transfer_current_bytes) / ((double)device.transfer_total_bytes); 123 | // TODO: use StringBuilder.take on GLib >= 2.78 124 | var builder = new StringBuilder(C_("file transfer progress", "%s / %s").printf( 125 | format_size(device.transfer_current_bytes), 126 | format_size(device.transfer_total_bytes) 127 | )); 128 | 129 | if (device.transfer_total_bytes >= MIN_TRANSFER_SPEED_SIZE) { 130 | var time_passed = get_monotonic_time() - device.transfer_started_time; 131 | // Time is measured after the first transfer, so skip it 132 | var current_bytes_adjusted = device.transfer_current_bytes - BLOCK_SIZE; 133 | builder.append_c(' '); 134 | if (current_bytes_adjusted > 0 && time_passed > 0) { 135 | var bytes_remaining = device.transfer_total_bytes - device.transfer_current_bytes; 136 | var time_remaining = time_passed * bytes_remaining / current_bytes_adjusted / 1000000; 137 | var bytes_per_second = current_bytes_adjusted * 1000000 / time_passed; 138 | builder.append_printf(C_("file transfer speed and min:sec remaining", "(%s/s, %02lld:%02lld remaining)"), 139 | format_size(bytes_per_second), 140 | time_remaining / 60, 141 | time_remaining % 60 142 | ); 143 | } else { 144 | builder.append(C_("file transfer speed and min:sec placeholder", "(-- B/s, --:-- remaining)")); 145 | } 146 | } 147 | 148 | transfer_text = builder.free_and_steal(); 149 | } 150 | 151 | private void transfer_started_cb(UsbDeviceClient client, File file, bool mass_transfer) { 152 | update_filenames(); 153 | } 154 | 155 | private void update_filenames_cb(UsbDeviceClient client) { 156 | update_filenames(); 157 | } 158 | 159 | private void update_filenames() 160 | requires(device != null) 161 | { 162 | file_name = device.transfer_file_name; 163 | file_name_inner = device.transfer_file_name_inner; 164 | } 165 | 166 | private void transfer_failed_cb(UsbDeviceClient client, File file, bool cancelled) { 167 | reset_transfer_view(); 168 | } 169 | 170 | private void transfer_complete_cb(UsbDeviceClient client, File file, bool mass_transfer) { 171 | reset_transfer_view(); 172 | } 173 | 174 | private void reset_transfer_view() { 175 | transfer_fraction = 0.0; 176 | transfer_text = ""; 177 | file_name = ""; 178 | file_name_inner = ""; 179 | } 180 | 181 | private void update_connection_speed() 182 | requires(device != null) 183 | { 184 | switch (device.max_packet_size) { 185 | case 64: 186 | connection_speed_text = _("USB 1.1"); 187 | break; 188 | case 512: 189 | connection_speed_text = _("USB 2.0"); 190 | break; 191 | case 1024: 192 | connection_speed_text = _("USB 3.0"); 193 | break; 194 | default: 195 | connection_speed_text = C_("speed string", "N/A"); 196 | break; 197 | } 198 | } 199 | 200 | private void update_version() 201 | requires(device != null) 202 | { 203 | version_text = device.version_string ?? C_("version string", "N/A"); 204 | } 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /src/PreferencesDialog.vala: -------------------------------------------------------------------------------- 1 | /* PreferencesDialog.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | // Debug option to use libportal even out of sandbox. 22 | // This is theoretically safe to have always on, but may hit bugs in portal backends. 23 | private const bool FORCE_LIBPORTAL = false; 24 | 25 | public enum NcaChecksumMode { 26 | COMPATIBLE, 27 | STRICT, 28 | NONE 29 | } 30 | 31 | namespace NXDumpClient { 32 | [GtkTemplate (ui = "/org/v1993/NXDumpClient/PreferencesDialog.ui")] 33 | class PreferencesDialog: Adw.PreferencesDialog { 34 | [GtkChild] 35 | private unowned FileRow destination_directory; 36 | [GtkChild] 37 | private unowned Adw.SwitchRow flatten_output; 38 | [GtkChild] 39 | private unowned Adw.ComboRow nca_checksum_mode; 40 | [GtkChild] 41 | private unowned Adw.SwitchRow allow_background_row; 42 | [GtkChild] 43 | private unowned Adw.SwitchRow autostart_enabled_row; 44 | 45 | private Cancellable? cancellable = null; 46 | 47 | public bool allow_background { get; protected set; } 48 | public bool autostart_enabled { get; protected set; } 49 | 50 | static construct { 51 | typeof(NXDumpClient.FileRow).ensure(); 52 | } 53 | 54 | private void on_unrealized() { 55 | cancellable.cancel(); 56 | } 57 | 58 | private void background_changed() { 59 | if (!allow_background) { 60 | // Ensure this since settings binding seem to miss it in some cases 61 | autostart_enabled_row.active = false; 62 | autostart_enabled = false; 63 | } 64 | } 65 | 66 | // Cancel previous requests; get a new cancellable for us 67 | private void new_background_access_request() { 68 | ((!)cancellable).cancel(); 69 | cancellable = new Cancellable(); 70 | // Old cancellable is disconnected automatically 71 | new Application().cancellable.connect(cancellable.cancel); 72 | } 73 | 74 | construct { 75 | var app = new Application(); 76 | cancellable = new Cancellable(); 77 | app.cancellable.connect(cancellable.cancel); 78 | // Cancel all pending operations once this dialog is closed to avoid references sticking around 79 | ((Gtk.Widget)this).unrealize.connect(this.on_unrealized); 80 | 81 | notify["allow-background"].connect(this.background_changed); 82 | 83 | app.settings.bind_with_mapping( 84 | "dump-path", 85 | destination_directory, "file", 86 | DEFAULT, 87 | FileSettingUtils.get, FileSettingUtils.set, (void*)get_default_dump_path, null 88 | ); 89 | 90 | app.settings.bind( 91 | "flatten-output", 92 | flatten_output, "active", 93 | DEFAULT 94 | ); 95 | 96 | app.settings.bind( 97 | "nca-checksum-mode", 98 | nca_checksum_mode, "selected", 99 | DEFAULT 100 | ); 101 | 102 | app.settings.bind( 103 | "allow-background", 104 | this, "allow-background", 105 | DEFAULT 106 | ); 107 | 108 | #if WITH_LIBPORTAL 109 | if (FORCE_LIBPORTAL || Xdp.Portal.running_under_sandbox()) { 110 | app.settings.bind( 111 | "allow-background", 112 | allow_background_row, "active", 113 | GET 114 | ); 115 | 116 | allow_background_row.notify["active"].connect(this.request_background); 117 | } else 118 | #endif 119 | { 120 | // No verification is needed; just bind directly 121 | app.settings.bind( 122 | "allow-background", 123 | allow_background_row, "active", 124 | DEFAULT 125 | ); 126 | } 127 | 128 | app.settings.bind( 129 | "autostart-enabled", 130 | this, "autostart-enabled", 131 | DEFAULT 132 | ); 133 | 134 | // Special handling is needed on native backend too 135 | app.settings.bind( 136 | "autostart-enabled", 137 | autostart_enabled_row, "active", 138 | GET | NO_SENSITIVITY // TODO: account for setting writablitiy manually 139 | ); 140 | 141 | #if WITH_LIBPORTAL 142 | if (FORCE_LIBPORTAL || Xdp.Portal.running_under_sandbox()) { 143 | autostart_enabled_row.notify["active"].connect(this.request_background); 144 | } else 145 | #endif 146 | { 147 | autostart_enabled_row.notify["active"].connect(this.set_autostart_native); 148 | } 149 | } 150 | 151 | [GtkCallback] 152 | private void reset_destination_directory() { 153 | new Application().settings.reset("dump-path"); 154 | } 155 | 156 | #if WITH_LIBPORTAL 157 | private Xdp.Parent? make_xdp_parent() { 158 | var? toplevel = get_root() as Gtk.Window; 159 | if (toplevel == null) { 160 | // This is unexpected, but not critical 161 | warning("Failed to find root window for preferences dialog"); 162 | return null; 163 | } 164 | 165 | return Xdp.parent_new_gtk(toplevel); 166 | } 167 | 168 | private async void request_background() { 169 | /* 170 | * The following cases require us to make a request: 171 | * !allow_background -> allow_background -- always (enable background) 172 | * !autostart_enabled -> autostart_enabled -- always (enable autostart) 173 | * autostart_enabled -> !autostart_enabled -- always (disable autostart) 174 | */ 175 | bool should_request = false; 176 | bool need_autostart = autostart_enabled_row.active; 177 | should_request |= allow_background_row.active && !allow_background; 178 | should_request |= autostart_enabled_row.active != autostart_enabled; 179 | 180 | if (!should_request) { 181 | debug("Not querying for new background settings"); 182 | allow_background = allow_background_row.active; 183 | autostart_enabled = autostart_enabled_row.active; 184 | return; 185 | } 186 | 187 | bool authorized = false; 188 | 189 | try { 190 | new_background_access_request(); 191 | var? portal = new Application().portal; 192 | if (portal == null) { 193 | // It's hopeless 194 | return; 195 | } 196 | 197 | var autostart_cmd = new GenericArray(2); 198 | autostart_cmd.add(BuildConfig.EXECUTABLE); 199 | autostart_cmd.add("--background"); 200 | // D-Bus activation is not an option because of having to pass a flag 201 | var flags = need_autostart ? Xdp.BackgroundFlags.AUTOSTART : Xdp.BackgroundFlags.NONE; 202 | debug("Requesting background, autostart: %s", need_autostart.to_string()); 203 | authorized = yield portal.request_background( 204 | make_xdp_parent(), 205 | C_("reason for background activity", "Dumping applications without interaction"), 206 | autostart_cmd, 207 | flags, 208 | cancellable 209 | ); 210 | } catch(IOError.CANCELLED e) { 211 | } catch(Error e) { 212 | var toast = new Adw.Toast.format(_("Permission request failed: %s"), e.message); 213 | add_toast((owned)toast); 214 | } finally { 215 | debug("Background request result: %s", authorized.to_string()); 216 | var background_result = allow_background_row.active && authorized; 217 | var autostart_result = need_autostart && authorized; 218 | allow_background = background_result; 219 | autostart_enabled = autostart_result; 220 | allow_background_row.active = background_result; 221 | autostart_enabled_row.active = autostart_result; 222 | } 223 | } 224 | #endif 225 | 226 | private async void set_autostart_native() { 227 | bool need_autostart = autostart_enabled_row.active; 228 | if (need_autostart == autostart_enabled) { 229 | return; 230 | } 231 | 232 | bool autostart_new_status = autostart_enabled; 233 | 234 | try { 235 | new_background_access_request(); 236 | debug("Using native implementation to set autostart status to %s", need_autostart.to_string()); 237 | var autostart_directory = File.new_build_filename(Environment.get_user_config_dir(), "autostart"); 238 | var autostart_file = autostart_directory.get_child("org.v1993.NXDumpClient.desktop"); 239 | 240 | if (need_autostart) { 241 | yield create_directory_with_parents_async(autostart_directory, cancellable); 242 | var contents = resources_lookup_data("/org/v1993/NXDumpClient/org.v1993.NXDumpClient.autostart.desktop", NONE); 243 | yield autostart_file.replace_contents_bytes_async(contents, null, false, NONE, cancellable, null); 244 | } else { 245 | try { 246 | yield autostart_file.delete_async(Priority.DEFAULT, cancellable); 247 | } catch(IOError.NOT_FOUND e) { 248 | // We're good 249 | } 250 | } 251 | 252 | autostart_new_status = need_autostart; 253 | } catch(IOError.CANCELLED e) { 254 | } catch(Error e) { 255 | var toast = new Adw.Toast.format(_("Failed to toggle autostart: %s"), e.message); 256 | add_toast((owned)toast); 257 | } finally { 258 | autostart_enabled = autostart_new_status; 259 | autostart_enabled_row.active = autostart_new_status; 260 | } 261 | } 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /po/nxdumpclient.pot: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the nxdumpclient package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: nxdumpclient\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2024-08-31 20:46+0300\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | 20 | #: data/org.v1993.NXDumpClient.desktop.in.in:3 21 | #: data/org.v1993.NXDumpClient.appdata.xml.in:3 src/Window.blp:7 22 | msgid "NX Dump Client" 23 | msgstr "" 24 | 25 | #: data/org.v1993.NXDumpClient.desktop.in.in:4 26 | #: data/org.v1993.NXDumpClient.autostart.desktop.in.in:4 27 | msgid "Dump over USB with nxdumptool" 28 | msgstr "" 29 | 30 | #: data/org.v1993.NXDumpClient.desktop.in.in:10 31 | msgid "nxdumpclient;nxdumptool;" 32 | msgstr "" 33 | 34 | #: data/org.v1993.NXDumpClient.autostart.desktop.in.in:3 35 | msgid "NX Dump Client (background launch)" 36 | msgstr "" 37 | 38 | #: data/org.v1993.NXDumpClient.appdata.xml.in:5 39 | msgid "v19930312" 40 | msgstr "" 41 | 42 | #: data/org.v1993.NXDumpClient.appdata.xml.in:6 43 | msgid "Client for dumping over USB with nxdumptool" 44 | msgstr "" 45 | 46 | #: data/org.v1993.NXDumpClient.appdata.xml.in:15 src/Application.vala:236 47 | msgid "Client for dumping over USB with nxdumptool." 48 | msgstr "" 49 | 50 | #: data/org.v1993.NXDumpClient.appdata.xml.in:18 51 | msgid "nxdumpclient" 52 | msgstr "" 53 | 54 | #: data/org.v1993.NXDumpClient.appdata.xml.in:19 55 | msgid "nxdumptool" 56 | msgstr "" 57 | 58 | #: data/org.v1993.NXDumpClient.appdata.xml.in:23 59 | msgid "NX Dump Tool receiving a file" 60 | msgstr "" 61 | 62 | #: data/org.v1993.NXDumpClient.appdata.xml.in:30 63 | msgid "A maintenance release before 1.2.0" 64 | msgstr "" 65 | 66 | #: data/org.v1993.NXDumpClient.appdata.xml.in:35 67 | #: data/org.v1993.NXDumpClient.appdata.xml.in:43 68 | #: data/org.v1993.NXDumpClient.appdata.xml.in:51 69 | #: data/org.v1993.NXDumpClient.appdata.xml.in:68 70 | msgid "Release highlights:" 71 | msgstr "" 72 | 73 | #: data/org.v1993.NXDumpClient.appdata.xml.in:37 74 | msgid "Add initial support for USB ABI 1.2" 75 | msgstr "" 76 | 77 | #: data/org.v1993.NXDumpClient.appdata.xml.in:45 78 | msgid "Add basic speed and remaining time estimation" 79 | msgstr "" 80 | 81 | #: data/org.v1993.NXDumpClient.appdata.xml.in:53 82 | msgid "" 83 | "Improve checksum verification - support non-standard dump options by default" 84 | msgstr "" 85 | 86 | #: data/org.v1993.NXDumpClient.appdata.xml.in:59 87 | msgid "Fixes:" 88 | msgstr "" 89 | 90 | #: data/org.v1993.NXDumpClient.appdata.xml.in:61 91 | msgid "Fix StartupNotify functionality under flatpak" 92 | msgstr "" 93 | 94 | #: data/org.v1993.NXDumpClient.appdata.xml.in:67 95 | msgid "First stable release." 96 | msgstr "" 97 | 98 | #: data/org.v1993.NXDumpClient.appdata.xml.in:70 99 | msgid "Support for running in background and autostart" 100 | msgstr "" 101 | 102 | #: data/org.v1993.NXDumpClient.appdata.xml.in:71 103 | msgid "Confirm exit if file transfer is in progress" 104 | msgstr "" 105 | 106 | #: data/org.v1993.NXDumpClient.appdata.xml.in:77 107 | msgid "Initial release." 108 | msgstr "" 109 | 110 | #: data/org.v1993.NXDumpClient.gschema.xml:6 111 | msgid "Path to the output folder" 112 | msgstr "" 113 | 114 | #: data/org.v1993.NXDumpClient.gschema.xml:7 115 | msgid "" 116 | "Path to the directory where dumps are stored. Empty value corresponds to " 117 | "using default path." 118 | msgstr "" 119 | 120 | #: data/org.v1993.NXDumpClient.gschema.xml:14 121 | msgid "Output directly into dump destination directory" 122 | msgstr "" 123 | 124 | #: data/org.v1993.NXDumpClient.gschema.xml:15 125 | msgid "" 126 | "By default, subfolders are always created when requested by nxdumptool. This " 127 | "options forces nxdumpclient to always output single-file dumps into dump " 128 | "directory and reduces nesting for multi-file dumps." 129 | msgstr "" 130 | 131 | #: data/org.v1993.NXDumpClient.gschema.xml:24 132 | msgid "Checksum verification mode for NCA/NSP files (enumeration)" 133 | msgstr "" 134 | 135 | #: data/org.v1993.NXDumpClient.gschema.xml:25 136 | msgid "" 137 | "(0) Compatible mode parses NSP header, which makes it work with non-standard " 138 | "dump options but delays verification until the end and disables it for " 139 | "standalone NCAs. (1) Strict mode takes checksums from NCA filenames, which " 140 | "allows to abort dump early in case of a mismatch. (2) None disables checksum " 141 | "verification completely. Yes, I know that GSettings support real " 142 | "enumerations, but they are more annoying to use and provide little benefit " 143 | "in my case." 144 | msgstr "" 145 | 146 | #: data/org.v1993.NXDumpClient.gschema.xml:34 147 | msgid "Has user closed udev rules prompt" 148 | msgstr "" 149 | 150 | #: data/org.v1993.NXDumpClient.gschema.xml:35 151 | msgid "This is only used in cases where udev rules must me manually installed." 152 | msgstr "" 153 | 154 | #: data/org.v1993.NXDumpClient.gschema.xml:41 155 | msgid "If application should continue running in background without a window" 156 | msgstr "" 157 | 158 | #: data/org.v1993.NXDumpClient.gschema.xml:42 159 | msgid "" 160 | "Desktop notifications are used to communicate status in this case. Pass `--" 161 | "background` when this option is enabled to launch without a window." 162 | msgstr "" 163 | 164 | #: data/org.v1993.NXDumpClient.gschema.xml:49 165 | msgid "Status of application's autostart capability" 166 | msgstr "" 167 | 168 | #: data/org.v1993.NXDumpClient.gschema.xml:50 169 | msgid "" 170 | "If application is expected to be launched at boot. Modifying this option " 171 | "manually will do nothing but confuse the application." 172 | msgstr "" 173 | 174 | #: src/Application.vala:33 175 | msgid "File transfer is in progres" 176 | msgstr "" 177 | 178 | #: src/Application.vala:102 179 | msgid "Confirm exit" 180 | msgstr "" 181 | 182 | #: src/Application.vala:102 183 | msgid "" 184 | "A file transfer is currently in progress.\n" 185 | "Are you sure you want to quit?" 186 | msgstr "" 187 | 188 | #: src/Application.vala:107 189 | msgctxt "deny app exit" 190 | msgid "Cancel" 191 | msgstr "" 192 | 193 | #: src/Application.vala:108 194 | msgctxt "confirm app exit" 195 | msgid "Confirm exit" 196 | msgstr "" 197 | 198 | #: src/Application.vala:139 199 | msgid "nxdumptool device connected" 200 | msgstr "" 201 | 202 | #: src/Application.vala:147 203 | msgid "nxdumptool device disconnected" 204 | msgstr "" 205 | 206 | #: src/Application.vala:160 207 | msgid "File transfer started" 208 | msgstr "" 209 | 210 | #: src/Application.vala:182 211 | msgid "File transfer complete" 212 | msgstr "" 213 | 214 | #: src/Application.vala:185 src/Application.vala:191 215 | msgid "Show in folder" 216 | msgstr "" 217 | 218 | #: src/Application.vala:190 219 | #, c-format 220 | msgid "Transfer of file “%s” complete" 221 | msgstr "" 222 | 223 | #: src/Application.vala:209 224 | msgid "File transfer canceled" 225 | msgstr "" 226 | 227 | #: src/Application.vala:209 228 | msgid "File transfer failed" 229 | msgstr "" 230 | 231 | #: src/Application.vala:216 232 | #, c-format 233 | msgid "Transfer of file “%s” canceled" 234 | msgstr "" 235 | 236 | #: src/Application.vala:216 237 | #, c-format 238 | msgid "Transfer of file “%s” failed" 239 | msgstr "" 240 | 241 | #: src/Application.vala:229 242 | msgid "" 243 | "Launch without a visible window if allowed to in settings, exit otherwise" 244 | msgstr "" 245 | 246 | #: src/Application.vala:230 247 | msgid "Print udev rules required for USB access and exit" 248 | msgstr "" 249 | 250 | #: src/Application.vala:231 251 | msgid "Print application version and exit" 252 | msgstr "" 253 | 254 | #: src/Application.vala:355 255 | #, c-format 256 | msgid "Failed to initialize USB context: %s\n" 257 | msgstr "" 258 | 259 | #: src/Application.vala:412 260 | msgid "translator-credits" 261 | msgstr "" 262 | 263 | #: src/Application.vala:419 264 | msgctxt "credits section header" 265 | msgid "nxdumptool team" 266 | msgstr "" 267 | 268 | #: src/gtk/help-overlay.blp:11 269 | msgctxt "shortcut window" 270 | msgid "General" 271 | msgstr "" 272 | 273 | #: src/gtk/help-overlay.blp:14 274 | msgctxt "shortcut window" 275 | msgid "Show Shortcuts" 276 | msgstr "" 277 | 278 | #: src/gtk/help-overlay.blp:19 279 | msgctxt "shortcut window" 280 | msgid "Open Preferences" 281 | msgstr "" 282 | 283 | #: src/gtk/help-overlay.blp:24 284 | msgctxt "shortcut window" 285 | msgid "Quit" 286 | msgstr "" 287 | 288 | #: src/PreferencesDialog.blp:6 289 | msgid "General settings" 290 | msgstr "" 291 | 292 | #: src/PreferencesDialog.blp:9 293 | msgctxt "settings group" 294 | msgid "Application" 295 | msgstr "" 296 | 297 | #: src/PreferencesDialog.blp:12 298 | msgctxt "setting" 299 | msgid "Run in background" 300 | msgstr "" 301 | 302 | #: src/PreferencesDialog.blp:13 303 | msgid "Do not exit when main window is closed (use menu to quit)" 304 | msgstr "" 305 | 306 | #: src/PreferencesDialog.blp:17 307 | msgctxt "setting" 308 | msgid "Launch at boot" 309 | msgstr "" 310 | 311 | #: src/PreferencesDialog.blp:18 312 | msgid "Automatically start in background on login" 313 | msgstr "" 314 | 315 | #: src/PreferencesDialog.blp:24 316 | msgctxt "settings group" 317 | msgid "Dump output" 318 | msgstr "" 319 | 320 | #: src/PreferencesDialog.blp:27 321 | msgctxt "setting" 322 | msgid "Destination directory" 323 | msgstr "" 324 | 325 | #: src/PreferencesDialog.blp:33 326 | msgctxt "dialog title" 327 | msgid "Dump destination directory" 328 | msgstr "" 329 | 330 | #: src/PreferencesDialog.blp:38 331 | msgctxt "setting" 332 | msgid "Flatten dump directory" 333 | msgstr "" 334 | 335 | #: src/PreferencesDialog.blp:39 336 | msgid "Avoid creating subfolders unless necessary" 337 | msgstr "" 338 | 339 | #: src/PreferencesDialog.blp:43 340 | msgctxt "setting" 341 | msgid "NSP/NCA checksum verification" 342 | msgstr "" 343 | 344 | #: src/PreferencesDialog.blp:44 345 | msgid "" 346 | "“Strict” can catch errors earlier but will fail with certain dump settings" 347 | msgstr "" 348 | 349 | #: src/PreferencesDialog.blp:47 350 | msgctxt "checksum mode setting" 351 | msgid "Compatible" 352 | msgstr "" 353 | 354 | #: src/PreferencesDialog.blp:48 355 | msgctxt "checksum mode setting" 356 | msgid "Strict" 357 | msgstr "" 358 | 359 | #: src/PreferencesDialog.blp:49 360 | msgctxt "checksum mode setting" 361 | msgid "None" 362 | msgstr "" 363 | 364 | #: src/PreferencesDialog.vala:205 365 | msgctxt "reason for background activity" 366 | msgid "Dumping applications without interaction" 367 | msgstr "" 368 | 369 | #: src/PreferencesDialog.vala:212 370 | #, c-format 371 | msgid "Permission request failed: %s" 372 | msgstr "" 373 | 374 | #: src/PreferencesDialog.vala:255 375 | #, c-format 376 | msgid "Failed to toggle autostart: %s" 377 | msgstr "" 378 | 379 | #: src/UdevRulesDialog.blp:5 380 | msgid "Udev rules installation" 381 | msgstr "" 382 | 383 | #: src/UdevRulesDialog.blp:24 384 | msgid "" 385 | "Udev rules must be installed for this program to work. Please exectute the " 386 | "following command to do so:" 387 | msgstr "" 388 | 389 | #: src/UdevRulesDialog.blp:38 390 | msgid "I have installed the rules; do not show me this dialog again" 391 | msgstr "" 392 | 393 | #: src/UdevRulesDialog.blp:45 394 | msgid "Confirm" 395 | msgstr "" 396 | 397 | #. Not really a problem - device was disconnected during setup 398 | #: src/UsbContext.vala:56 399 | msgid "Error handling a new device" 400 | msgstr "" 401 | 402 | #: src/UsbDeviceClient.vala:170 403 | #, c-format 404 | msgid "Not enough space for dump (%s required)" 405 | msgstr "" 406 | 407 | #: src/UsbDeviceClient.vala:611 408 | msgid "NCA checksum verification failed (non-standard dump options?)" 409 | msgstr "" 410 | 411 | #: src/UsbDeviceClient.vala:660 412 | msgid "NSP header" 413 | msgstr "" 414 | 415 | #: src/UsbDeviceClient.vala:720 416 | msgid "NCA checksum verification failed" 417 | msgstr "" 418 | 419 | #: src/widgets/DeviceStatusRow.blp:30 420 | msgid "Status" 421 | msgstr "" 422 | 423 | #: src/widgets/DeviceStatusRow.blp:45 424 | msgid "Connection" 425 | msgstr "" 426 | 427 | #: src/widgets/DeviceStatusRow.blp:62 428 | msgctxt "nxdumptool version" 429 | msgid "Version" 430 | msgstr "" 431 | 432 | #: src/widgets/DeviceStatusRow.blp:80 433 | msgid "Transfer progress" 434 | msgstr "" 435 | 436 | #: src/widgets/DeviceStatusRow.vala:88 437 | msgctxt "status" 438 | msgid "Uninitialized" 439 | msgstr "" 440 | 441 | #: src/widgets/DeviceStatusRow.vala:91 442 | msgctxt "status" 443 | msgid "Connected" 444 | msgstr "" 445 | 446 | #: src/widgets/DeviceStatusRow.vala:94 447 | msgctxt "status" 448 | msgid "Transferring file" 449 | msgstr "" 450 | 451 | #: src/widgets/DeviceStatusRow.vala:97 452 | msgctxt "status" 453 | msgid "Fatal error" 454 | msgstr "" 455 | 456 | #. TODO: use StringBuilder.take on GLib >= 2.78 457 | #: src/widgets/DeviceStatusRow.vala:124 458 | #, c-format 459 | msgctxt "file transfer progress" 460 | msgid "%s / %s" 461 | msgstr "" 462 | 463 | #: src/widgets/DeviceStatusRow.vala:138 464 | #, c-format 465 | msgctxt "file transfer speed and min:sec remaining" 466 | msgid "(%s/s, %02lld:%02lld remaining)" 467 | msgstr "" 468 | 469 | #: src/widgets/DeviceStatusRow.vala:144 470 | msgctxt "file transfer speed and min:sec placeholder" 471 | msgid "(-- B/s, --:-- remaining)" 472 | msgstr "" 473 | 474 | #: src/widgets/DeviceStatusRow.vala:186 475 | msgid "USB 1.1" 476 | msgstr "" 477 | 478 | #: src/widgets/DeviceStatusRow.vala:189 479 | msgid "USB 2.0" 480 | msgstr "" 481 | 482 | #: src/widgets/DeviceStatusRow.vala:192 483 | msgid "USB 3.0" 484 | msgstr "" 485 | 486 | #: src/widgets/DeviceStatusRow.vala:195 487 | msgctxt "speed string" 488 | msgid "N/A" 489 | msgstr "" 490 | 491 | #: src/widgets/DeviceStatusRow.vala:203 492 | msgctxt "version string" 493 | msgid "N/A" 494 | msgstr "" 495 | 496 | #: src/widgets/FileRow.blp:15 497 | msgctxt "FileRow button" 498 | msgid "Reset to default" 499 | msgstr "" 500 | 501 | #: src/widgets/FileRow.vala:27 502 | msgid "(unset)" 503 | msgstr "" 504 | 505 | #: src/widgets/FileRow.vala:42 506 | msgid "Select directory" 507 | msgstr "" 508 | 509 | #: src/widgets/FileRow.vala:42 510 | msgid "Select file" 511 | msgstr "" 512 | 513 | #: src/Window.blp:27 514 | msgid "No Devices Connected" 515 | msgstr "" 516 | 517 | #: src/Window.blp:28 518 | msgid "Connect your Switch and start nxdumptool to proceed" 519 | msgstr "" 520 | 521 | #: src/Window.blp:53 522 | msgid "_Preferences" 523 | msgstr "" 524 | 525 | #: src/Window.blp:54 526 | msgid "_Keyboard Shortcuts" 527 | msgstr "" 528 | 529 | #: src/Window.blp:55 530 | msgid "_About NX Dump Client" 531 | msgstr "" 532 | 533 | #: src/Window.blp:58 534 | msgid "_Quit" 535 | msgstr "" 536 | -------------------------------------------------------------------------------- /src/Application.vala: -------------------------------------------------------------------------------- 1 | /* Application.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | namespace NXDumpClient { 22 | /// A convenience method to show errors to user 23 | internal void report_error(string desc, string message) { 24 | new Application().show_error(desc, message); 25 | } 26 | 27 | internal class FileTransferInhibitor: Object { 28 | public static uint current_count { get; private set; } 29 | 30 | private uint cookie = 0; 31 | 32 | construct { 33 | cookie = new Application().inhibit(null, LOGOUT | SUSPEND, _("File transfer is in progres")); 34 | ++current_count; 35 | debug("Inhibited, cookie: %u, active inhibitors: %u", cookie, current_count); 36 | } 37 | 38 | ~FileTransferInhibitor() { 39 | var app = new Application(); 40 | // May be false during app shutdown 41 | if (app.is_registered) { 42 | app.uninhibit(cookie); 43 | } 44 | --current_count; 45 | debug("Uninhibited, cookie: %u, active inhibitors: %u", cookie, current_count); 46 | } 47 | } 48 | 49 | [SingleInstance] 50 | public class Application: Adw.Application { 51 | // Settings object and corresponding fields 52 | public Settings settings { get; private set; } 53 | public File destination_directory { get; protected set; } 54 | public bool flatten_output { get; protected set; } 55 | public NcaChecksumMode nca_checksum_mode { get; protected set; } 56 | 57 | protected uint nca_checksum_mode_proxy { set { nca_checksum_mode = (NcaChecksumMode)value; } } 58 | 59 | private bool hold_background_reference_ = false; 60 | public bool hold_background_reference { 61 | get { 62 | return hold_background_reference_; 63 | } 64 | protected set { 65 | if (value && !hold_background_reference_) { 66 | hold(); 67 | } else if (!value && hold_background_reference_) { 68 | release(); 69 | } 70 | 71 | hold_background_reference_ = value; 72 | } 73 | } 74 | 75 | public ListStore device_list { get; private set; } 76 | public Cancellable cancellable { get; private set; default = new Cancellable(); } 77 | 78 | #if WITH_LIBPORTAL 79 | public Xdp.Portal? portal { get; private set; default = null; } 80 | #endif 81 | #if PROMPT_FOR_UDEV_RULES 82 | protected bool prompted_for_udev_rules { get; protected set; default = false; } 83 | 84 | public void udev_rules_prompt_accepted() { 85 | prompted_for_udev_rules = true; 86 | } 87 | #endif 88 | 89 | private bool background_bound = false; 90 | private UsbContext usb_ctx; 91 | private Window? main_window = null; 92 | 93 | private bool should_show_desktop_notification() { 94 | return !cancellable.is_cancelled() && (main_window == null || !main_window.is_active); 95 | } 96 | 97 | private bool should_show_toast() { 98 | return !cancellable.is_cancelled() && main_window != null; 99 | } 100 | 101 | public async bool query_app_exit() { 102 | var dialog = new Adw.AlertDialog(_("Confirm exit"), _("A file transfer is currently in progress.\nAre you sure you want to quit?")) { 103 | close_response = "cancel", 104 | default_response = "confirm", 105 | 106 | }; 107 | dialog.add_response("cancel", C_("deny app exit", "Cancel")); 108 | dialog.add_response("confirm", C_("confirm app exit", "Confirm exit")); 109 | dialog.set_response_appearance("confirm", DESTRUCTIVE); 110 | var res = yield dialog.choose(main_window, cancellable); 111 | return res == "confirm"; 112 | } 113 | 114 | public void show_error(string desc, string message) { 115 | if (should_show_toast()) { 116 | var toast = new Adw.Toast.format("%s: %s", desc, message) { 117 | timeout = 5, 118 | priority = HIGH 119 | }; 120 | main_window.show_toast((owned)toast); 121 | } 122 | 123 | if (should_show_desktop_notification()) { 124 | var notif = new Notification(desc); 125 | notif.set_body(message); 126 | notif.set_category("device.error"); 127 | notif.set_priority(HIGH); 128 | notif.set_icon(new ThemedIcon("dialog-error")); 129 | send_notification(null, notif); 130 | } 131 | } 132 | 133 | internal void device_added(UsbDeviceClient client) { 134 | client.transfer_started.connect(this.file_transfer_started); 135 | client.transfer_got_empty_file.connect(this.file_transfer_complete); 136 | client.transfer_complete.connect(this.file_transfer_complete); 137 | client.transfer_failed.connect(this.file_transfer_failed); 138 | if (should_show_desktop_notification()) { 139 | var notif = new Notification(_( "nxdumptool device connected")); 140 | notif.set_category("device.added"); 141 | send_notification(@"nxdc-device-$(client.dev.get_bus())-$(client.dev.get_address())", notif); 142 | } 143 | } 144 | 145 | internal void device_removed(GUsb.Device dev) { 146 | if (should_show_desktop_notification()) { 147 | var notif = new Notification(_("nxdumptool device disconnected")); 148 | notif.set_category("device.removed"); 149 | send_notification(@"nxdc-device-$(dev.get_bus())-$(dev.get_address())", notif); 150 | } 151 | } 152 | 153 | private async void file_transfer_started(UsbDeviceClient dev, File file, bool mass_transfer) { 154 | try { 155 | if (mass_transfer) { 156 | return; 157 | } 158 | 159 | if (should_show_desktop_notification()) { 160 | var notif = new Notification(_("File transfer started")); 161 | var info = file.query_info(FileAttribute.STANDARD_DISPLAY_NAME, NONE, cancellable); 162 | notif.set_body(info.get_display_name()); 163 | notif.set_category("device"); 164 | send_notification(@"nxdc-file-$(file.get_uri())", notif); 165 | } 166 | } catch(IOError.CANCELLED e) { 167 | } catch(Error e) { 168 | warning("Error sending notification: %s", e.message); 169 | } 170 | } 171 | 172 | private async void file_transfer_complete(UsbDeviceClient dev, File file, bool mass_transfer) { 173 | try { 174 | if (mass_transfer) { 175 | return; 176 | } 177 | 178 | var info = file.query_info(FileAttribute.STANDARD_DISPLAY_NAME, NONE, cancellable); 179 | var fname = info.get_display_name(); 180 | 181 | if (should_show_desktop_notification()) { 182 | var notif = new Notification(_("File transfer complete")); 183 | notif.set_body(fname); 184 | notif.set_category("device"); 185 | notif.add_button_with_target_value(_("Show in folder"), "app.show-file", new Variant.take_string(file.get_uri())); 186 | send_notification(@"nxdc-file-$(file.get_uri())", notif); 187 | } 188 | 189 | if (should_show_toast()) { 190 | var toast = new Adw.Toast.format(_("Transfer of file “%s” complete"), fname) { 191 | button_label = _("Show in folder"), 192 | action_name = "app.show-file", 193 | action_target = new Variant.take_string(file.get_uri()), 194 | }; 195 | main_window.show_toast((owned)toast); 196 | } 197 | } catch(IOError.CANCELLED e) { 198 | } catch(Error e) { 199 | warning("Error sending notification: %s", e.message); 200 | } 201 | } 202 | 203 | private async void file_transfer_failed(UsbDeviceClient dev, File file, bool cancelled) { 204 | try { 205 | var info = file.query_info(FileAttribute.STANDARD_DISPLAY_NAME, NONE, cancellable); 206 | var fname = info.get_display_name(); 207 | 208 | if (should_show_desktop_notification()) { 209 | var notif = new Notification(cancelled ? _("File transfer canceled") : _("File transfer failed")); 210 | notif.set_body(fname); 211 | notif.set_category("device"); 212 | send_notification(@"nxdc-file-$(file.get_uri())", notif); 213 | } 214 | 215 | if (should_show_toast()) { 216 | var toast = new Adw.Toast.format(cancelled ? _("Transfer of file “%s” canceled") : _("Transfer of file “%s” failed"), fname); 217 | main_window.show_toast((owned)toast); 218 | } 219 | } catch(Error e) { 220 | warning("Error sending notification: %s", e.message); 221 | } 222 | } 223 | 224 | construct { 225 | application_id = "org.v1993.NXDumpClient"; 226 | flags = HANDLES_COMMAND_LINE; 227 | 228 | OptionEntry[] options = { 229 | { "background", '\0', NONE, NONE, null, _("Launch without a visible window if allowed to in settings, exit otherwise") }, 230 | { "print-udev-rules", '\0', NONE, NONE, null, _("Print udev rules required for USB access and exit") }, 231 | { "version", 'v', NONE, NONE, null, _("Print application version and exit") }, 232 | {null} 233 | }; 234 | 235 | add_main_option_entries(options); 236 | set_option_context_summary(_("Client for dumping over USB with nxdumptool.")); 237 | 238 | ActionEntry[] action_entries = { 239 | // In-app only 240 | { "about", this.on_about_action }, 241 | { "preferences", this.on_preferences_action }, 242 | { "quit", this.on_quit_with_confirmation_action }, 243 | 244 | // May be invoked externally (e.g. from a notification) 245 | { "show-file", this.on_show_file_action, "s" } 246 | }; 247 | 248 | add_action_entries(action_entries, this); 249 | set_accels_for_action("app.preferences", {"p"}); 250 | set_accels_for_action("app.quit", {"q"}); 251 | } 252 | 253 | public override int handle_local_options(VariantDict opt) { 254 | if (opt.lookup("version", "b", null)) { 255 | print("nxdumpclient %s\n", BuildConfig.VERSION); 256 | return 0; 257 | } 258 | 259 | if (opt.lookup("print-udev-rules", "b", null)) { 260 | try { 261 | var contents = resources_lookup_data("/org/v1993/NXDumpClient/" + UDEV_RULES_FILENAME, NONE); 262 | //var rule_path = Path.build_filename(UDEV_RULES_DIR, UDEV_RULES_FILENAME); 263 | print("%s", (string)contents.get_data()); 264 | } catch(Error e) { 265 | printerr("Failed to print udev rules: %s\n", e.message); 266 | return 1; 267 | } 268 | return 0; 269 | } 270 | 271 | return -1; 272 | } 273 | 274 | public override void startup() { 275 | base.startup(); 276 | 277 | settings = new GLib.Settings(application_id); 278 | settings.bind_with_mapping("dump-path", 279 | this, "destination-directory", 280 | NO_SENSITIVITY | GET, 281 | FileSettingUtils.get, FileSettingUtils.set, (void*)get_default_dump_path, null 282 | ); 283 | 284 | settings.bind("flatten-output", 285 | this, "flatten-output", 286 | NO_SENSITIVITY | GET 287 | ); 288 | 289 | settings.bind("nca-checksum-mode", 290 | this, "nca-checksum-mode-proxy", 291 | NO_SENSITIVITY | GET 292 | ); 293 | 294 | // allow-background is bound in bind_background. 295 | // This is done to avoid making one-shot invocations (mainly actions) 296 | // from sticking around. 297 | 298 | #if PROMPT_FOR_UDEV_RULES 299 | settings.bind("prompted-for-udev-rules", 300 | this, "prompted-for-udev-rules", 301 | NO_SENSITIVITY | GET | SET 302 | ); 303 | #endif 304 | 305 | device_list = new ListStore(typeof(UsbDeviceClient)); 306 | 307 | #if WITH_LIBPORTAL 308 | try { 309 | portal = new Xdp.Portal.initable_new(); 310 | } catch(Error e) { 311 | warning("Failed to initialize libportal: %s", e.message); 312 | } 313 | #endif 314 | } 315 | 316 | private void unset_main_window(Gtk.Widget win) { 317 | // Catch nasty typing problems 318 | assert(win is Window && (Window)win == main_window); 319 | main_window = null; 320 | } 321 | 322 | // Call only if you're fine with current instance running in background if allowed so by settings 323 | private void bind_background() { 324 | if (background_bound) { 325 | return; 326 | } 327 | 328 | settings.bind("allow-background", 329 | this, "hold-background-reference", 330 | NO_SENSITIVITY 331 | ); 332 | 333 | background_bound = true; 334 | } 335 | 336 | private void initialize_usb() { 337 | if (usb_ctx != null) { 338 | return; 339 | } 340 | 341 | try { 342 | usb_ctx = new UsbContext(); 343 | 344 | // Allow window to show up first 345 | Idle.add_once(() => { 346 | usb_ctx.enumerate(); 347 | }); 348 | } catch(Error e) { 349 | printerr(_("Failed to initialize USB context: %s\n"), e.message); 350 | Process.exit(1); 351 | } 352 | } 353 | 354 | public override int command_line(ApplicationCommandLine command_line) { 355 | debug("command_line() invoked, is_remote: %s", command_line.is_remote.to_string()); 356 | if (command_line.get_options_dict().contains("background")) { 357 | if (command_line.is_remote) { 358 | command_line.print("Ignoring background launch - primary instance already running\n"); 359 | return 0; 360 | } 361 | 362 | // This will acquire a reference if enabled in settings 363 | bind_background(); 364 | if (!hold_background_reference) { 365 | // Background mode disabled in settings - just exit 366 | return 0; 367 | } 368 | 369 | initialize_usb(); 370 | return 0; 371 | } else { 372 | activate(); 373 | return 0; 374 | } 375 | } 376 | 377 | public override void activate() { 378 | base.activate(); 379 | bind_background(); 380 | initialize_usb(); 381 | 382 | if (main_window == null) { 383 | main_window = new Window(this); 384 | // Typing hiccups prevent syntax sugar from doing its job nicely here. 385 | ((Gtk.Widget)main_window).unrealize.connect(this.unset_main_window); 386 | } 387 | main_window.present(); 388 | #if PROMPT_FOR_UDEV_RULES 389 | if (!prompted_for_udev_rules) { 390 | var udev_dialog = new UdevRulesDialog(); 391 | udev_dialog.present(main_window); 392 | } 393 | #endif 394 | } 395 | 396 | public override void shutdown() { 397 | // Cancel pending operations 398 | cancellable.cancel(); 399 | // Let async handlers that registered themselves at the previous step run 400 | MainContext.default().iteration(false); 401 | base.shutdown(); 402 | } 403 | 404 | private void on_about_action() { 405 | var about = new Adw.AboutDialog.from_appdata("/org/v1993/NXDumpClient/appdata.xml", BuildConfig.VERSION) { 406 | translator_credits = _("translator-credits"), 407 | developers = { 408 | "v19930312" 409 | }, 410 | copyright = "© 2023 v19930312" 411 | }; 412 | 413 | about.add_credit_section(C_("credits section header", "nxdumptool team"), 414 | { 415 | "DarkMatterCore", 416 | "Whovian9369", 417 | "shchmue" 418 | } 419 | ); 420 | 421 | about.present(main_window); 422 | } 423 | 424 | private void on_preferences_action() { 425 | var preferences = new PreferencesDialog(); 426 | 427 | preferences.present(main_window); 428 | } 429 | 430 | private void on_show_file_action(SimpleAction action, Variant? param) 431 | requires(param != null && param.is_of_type(VariantType.STRING)) 432 | { 433 | show_file.begin(File.new_for_uri(param.get_string())); 434 | } 435 | 436 | private void on_quit_with_confirmation_action() { 437 | // Do not test if background is enabled - app exit bypasses that 438 | if (FileTransferInhibitor.current_count == 0) { 439 | quit(); 440 | } else { 441 | quit_with_confirmation.begin(); 442 | } 443 | } 444 | 445 | private async void quit_with_confirmation() { 446 | var res = yield query_app_exit(); 447 | if (res) { 448 | quit(); 449 | } 450 | } 451 | 452 | private async void show_file(File file) { 453 | hold(); // Ensure that we won't exit if invoked without activation 454 | try { 455 | var launcher = new Gtk.FileLauncher(file); 456 | yield launcher.open_containing_folder(main_window, cancellable); 457 | } catch(IOError.CANCELLED e) { 458 | } catch(Error e) { 459 | warning("Failed to show file in directory: %s", e.message); 460 | } finally { 461 | release(); 462 | } 463 | } 464 | } 465 | } 466 | -------------------------------------------------------------------------------- /vapi/gusb.vapi: -------------------------------------------------------------------------------- 1 | /* gusb.vapi generated by vapigen, definitely do modify. */ 2 | 3 | /* 4 | * Manually edited to work around https://github.com/hughsie/libgusb/issues/109 5 | * Original comes from GUsb release 0.4.6 6 | */ 7 | 8 | [CCode (cprefix = "GUsb", gir_namespace = "GUsb", gir_version = "1.0", lower_case_cprefix = "g_usb_")] 9 | namespace GUsb { 10 | [CCode (cheader_filename = "gusb.h", type_id = "g_usb_bos_descriptor_get_type ()")] 11 | public class BosDescriptor : GLib.Object { 12 | [CCode (has_construct_function = false)] 13 | protected BosDescriptor (); 14 | [Version (since = "0.4.0")] 15 | public uint8 get_capability (); 16 | [Version (since = "0.4.0")] 17 | public unowned GLib.Bytes get_extra (); 18 | } 19 | [CCode (cheader_filename = "gusb.h", type_id = "g_usb_context_get_type ()")] 20 | public class Context : GLib.Object, GLib.Initable { 21 | [CCode (has_construct_function = false)] 22 | [Version (since = "0.1.0")] 23 | public Context () throws GLib.Error; 24 | [Version (since = "0.2.2")] 25 | public void enumerate (); 26 | [Version (since = "0.1.0")] 27 | public static GLib.Quark error_quark (); 28 | [Version (since = "0.2.2")] 29 | public GUsb.Device find_by_bus_address (uint8 bus, uint8 address) throws GLib.Error; 30 | [Version (since = "0.2.4")] 31 | public GUsb.Device find_by_platform_id (string platform_id) throws GLib.Error; 32 | [Version (since = "0.2.2")] 33 | public GUsb.Device find_by_vid_pid (uint16 vid, uint16 pid) throws GLib.Error; 34 | [Version (since = "0.2.2")] 35 | public GLib.GenericArray get_devices (); 36 | [Version (since = "0.2.11")] 37 | public GUsb.ContextFlags get_flags (); 38 | [Version (since = "0.3.10")] 39 | public uint get_hotplug_poll_interval (); 40 | [Version (since = "0.2.5")] 41 | public unowned GLib.MainContext get_main_context (); 42 | [Version (since = "0.1.0")] 43 | public unowned GUsb.Source get_source (GLib.MainContext main_ctx); 44 | [Version (since = "0.4.0")] 45 | public bool load (Json.Object json_object) throws GLib.Error; 46 | [Version (since = "0.4.1")] 47 | public bool load_with_tag (Json.Object json_object, string tag) throws GLib.Error; 48 | [Version (since = "0.4.0")] 49 | public bool save (Json.Builder json_builder) throws GLib.Error; 50 | [Version (since = "0.4.1")] 51 | public bool save_with_tag (Json.Builder json_builder, string tag) throws GLib.Error; 52 | [Version (since = "0.1.0")] 53 | public void set_debug (GLib.LogLevelFlags flags); 54 | [Version (since = "0.2.11")] 55 | public void set_flags (GUsb.ContextFlags flags); 56 | [Version (since = "0.3.10")] 57 | public void set_hotplug_poll_interval (uint hotplug_poll_interval); 58 | [Version (since = "0.2.5")] 59 | public void set_main_context (GLib.MainContext main_ctx); 60 | [Version (since = "0.2.9")] 61 | public GUsb.Device wait_for_replug (GUsb.Device device, uint timeout_ms) throws GLib.Error; 62 | [NoAccessorMethod] 63 | public int debug_level { get; set; } 64 | [NoAccessorMethod] 65 | public void* libusb_context { get; } 66 | public virtual signal void device_added (GUsb.Device device); 67 | public virtual signal void device_changed (GUsb.Device device); 68 | public virtual signal void device_removed (GUsb.Device device); 69 | } 70 | [CCode (cheader_filename = "gusb.h", type_id = "g_usb_device_get_type ()")] 71 | public class Device : GLib.Object, GLib.Initable { 72 | [CCode (has_construct_function = false)] 73 | protected Device (); 74 | [Version (since = "0.4.1")] 75 | public void add_tag (string tag); 76 | [Version (since = "0.1.0")] 77 | public bool bulk_transfer (uint8 endpoint, [CCode (array_length_cname = "length", array_length_pos = 2.5, array_length_type = "gsize")] uint8[] data, out size_t actual_length, uint timeout, GLib.Cancellable? cancellable = null) throws GLib.Error; 78 | [Version (since = "0.1.0")] 79 | public async ssize_t bulk_transfer_async (uint8 endpoint, [CCode (array_length_cname = "length", array_length_pos = 2.5, array_length_type = "gsize")] uint8[] data, uint timeout, GLib.Cancellable? cancellable) throws GLib.Error; 80 | [Version (since = "0.1.0")] 81 | public bool claim_interface (int @interface, GUsb.DeviceClaimInterfaceFlags flags) throws GLib.Error; 82 | [Version (since = "0.4.4")] 83 | public void clear_events (); 84 | [Version (since = "0.1.0")] 85 | public bool close () throws GLib.Error; 86 | [Version (since = "0.1.0")] 87 | public bool control_transfer (GUsb.DeviceDirection direction, GUsb.DeviceRequestType request_type, GUsb.DeviceRecipient recipient, uint8 request, uint16 value, uint16 idx, [CCode (array_length_cname = "length", array_length_pos = 7.5, array_length_type = "gsize")] uint8[] data, out size_t actual_length, uint timeout, GLib.Cancellable? cancellable = null) throws GLib.Error; 88 | [Version (since = "0.1.0")] 89 | public async ssize_t control_transfer_async (GUsb.DeviceDirection direction, GUsb.DeviceRequestType request_type, GUsb.DeviceRecipient recipient, uint8 request, uint16 value, uint16 idx, [CCode (array_length_cname = "length", array_length_pos = 7.5, array_length_type = "gsize")] uint8[] data, uint timeout, GLib.Cancellable? cancellable) throws GLib.Error; 90 | [Version (since = "0.1.0")] 91 | public static GLib.Quark error_quark (); 92 | [Version (since = "0.1.0")] 93 | public uint8 get_address (); 94 | [Version (since = "0.4.0")] 95 | public GUsb.BosDescriptor get_bos_descriptor (uint8 capability) throws GLib.Error; 96 | [Version (since = "0.4.0")] 97 | public GLib.GenericArray get_bos_descriptors () throws GLib.Error; 98 | [Version (since = "0.1.0")] 99 | public uint8 get_bus (); 100 | [Version (since = "0.2.4")] 101 | public GLib.GenericArray get_children (); 102 | [Version (since = "0.1.0")] 103 | public int get_configuration () throws GLib.Error; 104 | [Version (since = "0.3.5")] 105 | public uint8 get_configuration_index (); 106 | [Version (since = "0.4.5")] 107 | public unowned GLib.DateTime get_created (); 108 | [Version (since = "0.2.5")] 109 | public uint8 get_custom_index (uint8 class_id, uint8 subclass_id, uint8 protocol_id) throws GLib.Error; 110 | [Version (since = "0.1.7")] 111 | public uint8 get_device_class (); 112 | [Version (since = "0.2.4")] 113 | public uint8 get_device_protocol (); 114 | [Version (since = "0.2.4")] 115 | public uint8 get_device_subclass (); 116 | [Version (since = "0.4.0")] 117 | public GLib.GenericArray get_events (); 118 | [Version (since = "0.2.8")] 119 | public GUsb.Interface get_interface (uint8 class_id, uint8 subclass_id, uint8 protocol_id) throws GLib.Error; 120 | [Version (since = "0.2.8")] 121 | public GLib.GenericArray get_interfaces () throws GLib.Error; 122 | [Version (since = "0.1.0")] 123 | public uint8 get_manufacturer_index (); 124 | [Version (since = "0.2.4")] 125 | public GUsb.Device get_parent (); 126 | [Version (since = "0.1.0")] 127 | public uint16 get_pid (); 128 | [Version (since = "0.2.4")] 129 | public unowned string get_pid_as_str (); 130 | [Version (since = "0.1.1")] 131 | public unowned string get_platform_id (); 132 | [Version (since = "0.2.4")] 133 | public uint8 get_port_number (); 134 | [Version (since = "0.1.0")] 135 | public uint8 get_product_index (); 136 | [Version (since = "0.2.8")] 137 | public uint16 get_release (); 138 | [Version (since = "0.1.0")] 139 | public uint8 get_serial_number_index (); 140 | [Version (since = "0.3.1")] 141 | public uint16 get_spec (); 142 | [Version (since = "0.1.0")] 143 | public string get_string_descriptor (uint8 desc_index) throws GLib.Error; 144 | [Version (since = "0.3.6")] 145 | public GLib.Bytes get_string_descriptor_bytes (uint8 desc_index, uint16 langid) throws GLib.Error; 146 | [Version (since = "0.3.8")] 147 | public GLib.Bytes get_string_descriptor_bytes_full (uint8 desc_index, uint16 langid, size_t length) throws GLib.Error; 148 | [Version (since = "0.4.4")] 149 | public GLib.GenericArray get_tags (); 150 | [Version (since = "0.1.0")] 151 | public uint16 get_vid (); 152 | [Version (since = "0.2.4")] 153 | public unowned string get_vid_as_str (); 154 | [Version (since = "0.4.3")] 155 | public bool has_tag (string tag); 156 | [Version (since = "0.1.0")] 157 | public bool interrupt_transfer (uint8 endpoint, [CCode (array_length_cname = "length", array_length_pos = 2.5, array_length_type = "gsize")] uint8[] data, out size_t actual_length, uint timeout, GLib.Cancellable? cancellable = null) throws GLib.Error; 158 | [Version (since = "0.1.0")] 159 | public async ssize_t interrupt_transfer_async (uint8 endpoint, [CCode (array_length_cname = "length", array_length_pos = 2.5, array_length_type = "gsize")] uint8[] data, uint timeout, GLib.Cancellable? cancellable) throws GLib.Error; 160 | [Version (since = "0.4.0")] 161 | public void invalidate (); 162 | [Version (since = "0.4.4")] 163 | public bool is_emulated (); 164 | [Version (since = "0.1.0")] 165 | public bool open () throws GLib.Error; 166 | [Version (since = "0.1.0")] 167 | public bool release_interface (int @interface, GUsb.DeviceClaimInterfaceFlags flags) throws GLib.Error; 168 | [Version (since = "0.4.4")] 169 | public void remove_tag (string tag); 170 | [Version (since = "0.1.0")] 171 | public bool reset () throws GLib.Error; 172 | [Version (since = "0.1.0")] 173 | public bool set_configuration (int configuration) throws GLib.Error; 174 | [Version (since = "0.2.8")] 175 | public bool set_interface_alt (int @interface, uint8 alt) throws GLib.Error; 176 | [NoAccessorMethod] 177 | public GUsb.Context context { construct; } 178 | [NoAccessorMethod] 179 | public void* libusb_device { get; construct; } 180 | [NoAccessorMethod] 181 | public string platform_id { construct; } 182 | } 183 | [CCode (cheader_filename = "gusb.h", type_id = "g_usb_device_event_get_type ()")] 184 | public class DeviceEvent : GLib.Object { 185 | [CCode (has_construct_function = false)] 186 | protected DeviceEvent (); 187 | [Version (since = "0.4.0")] 188 | public unowned GLib.Bytes get_bytes (); 189 | [Version (since = "0.4.0")] 190 | public unowned string get_id (); 191 | [Version (since = "0.4.5")] 192 | public int get_rc (); 193 | [Version (since = "0.4.0")] 194 | public int get_status (); 195 | [Version (since = "0.4.0")] 196 | public void set_bytes (GLib.Bytes bytes); 197 | } 198 | [CCode (cheader_filename = "gusb.h", type_id = "g_usb_device_list_get_type ()")] 199 | public class DeviceList : GLib.Object { 200 | [CCode (has_construct_function = false)] 201 | [Version (since = "0.1.0")] 202 | public DeviceList (GUsb.Context context); 203 | [Version (since = "0.1.0")] 204 | public void coldplug (); 205 | [Version (since = "0.1.0")] 206 | public GUsb.Device find_by_bus_address (uint8 bus, uint8 address) throws GLib.Error; 207 | [Version (since = "0.1.0")] 208 | public GUsb.Device find_by_vid_pid (uint16 vid, uint16 pid) throws GLib.Error; 209 | [Version (since = "0.1.0")] 210 | public GLib.GenericArray get_devices (); 211 | [NoAccessorMethod] 212 | public GUsb.Context context { owned get; construct; } 213 | public virtual signal void device_added (GUsb.Device device); 214 | public virtual signal void device_removed (GUsb.Device device); 215 | } 216 | [CCode (cheader_filename = "gusb.h", type_id = "g_usb_endpoint_get_type ()")] 217 | public class Endpoint : GLib.Object { 218 | [CCode (has_construct_function = false)] 219 | protected Endpoint (); 220 | [Version (since = "0.3.3")] 221 | public uint8 get_address (); 222 | [Version (since = "0.3.3")] 223 | public GUsb.DeviceDirection get_direction (); 224 | [Version (since = "0.3.3")] 225 | public unowned GLib.Bytes get_extra (); 226 | [Version (since = "0.3.3")] 227 | public uint8 get_kind (); 228 | [Version (since = "0.3.3")] 229 | public uint16 get_maximum_packet_size (); 230 | [Version (since = "0.3.3")] 231 | public uint8 get_number (); 232 | [Version (since = "0.3.3")] 233 | public uint8 get_polling_interval (); 234 | [Version (since = "0.3.3")] 235 | public uint8 get_refresh (); 236 | [Version (since = "0.3.3")] 237 | public uint8 get_synch_address (); 238 | } 239 | [CCode (cheader_filename = "gusb.h", type_id = "g_usb_interface_get_type ()")] 240 | public class Interface : GLib.Object { 241 | [CCode (has_construct_function = false)] 242 | protected Interface (); 243 | [Version (since = "0.2.8")] 244 | public uint8 get_alternate (); 245 | [Version (since = "0.2.8")] 246 | public uint8 get_class (); 247 | [Version (since = "0.3.3")] 248 | public GLib.GenericArray get_endpoints (); 249 | [Version (since = "0.2.8")] 250 | public unowned GLib.Bytes get_extra (); 251 | [Version (since = "0.2.8")] 252 | public uint8 get_index (); 253 | [Version (since = "0.2.8")] 254 | public uint8 get_kind (); 255 | [Version (since = "0.2.8")] 256 | public uint8 get_length (); 257 | [Version (since = "0.2.8")] 258 | public uint8 get_number (); 259 | [Version (since = "0.2.8")] 260 | public uint8 get_protocol (); 261 | [Version (since = "0.2.8")] 262 | public uint8 get_subclass (); 263 | } 264 | [CCode (cheader_filename = "gusb.h", has_type_id = false)] 265 | [Compact] 266 | public class Source { 267 | [Version (since = "0.1.0")] 268 | public static GLib.Quark error_quark (); 269 | [Version (since = "0.1.0")] 270 | public void set_callback (owned GLib.SourceFunc func); 271 | } 272 | [CCode (cheader_filename = "gusb.h", cprefix = "G_USB_CONTEXT_ERROR_", has_type_id = false)] 273 | public errordomain ContextError { 274 | [CCode (cname = "G_USB_CONTEXT_ERROR_INTERNAL")] 275 | CONTEXT_ERROR_INTERNAL 276 | } 277 | [CCode (cheader_filename = "gusb.h", cprefix = "G_USB_CONTEXT_FLAGS_", has_type_id = false)] 278 | [Flags] 279 | public enum ContextFlags { 280 | NONE, 281 | AUTO_OPEN_DEVICES, 282 | SAVE_EVENTS, 283 | SAVE_REMOVED_DEVICES, 284 | DEBUG 285 | } 286 | [CCode (cheader_filename = "gusb.h", cprefix = "G_USB_DEVICE_CLAIM_INTERFACE_", has_type_id = false)] 287 | [Flags] 288 | public enum DeviceClaimInterfaceFlags { 289 | NONE, 290 | BIND_KERNEL_DRIVER 291 | } 292 | [CCode (cheader_filename = "gusb.h", cprefix = "G_USB_DEVICE_CLASS_", has_type_id = false)] 293 | public enum DeviceClassCode { 294 | INTERFACE_DESC, 295 | AUDIO, 296 | COMMUNICATIONS, 297 | HID, 298 | PHYSICAL, 299 | IMAGE, 300 | PRINTER, 301 | MASS_STORAGE, 302 | HUB, 303 | CDC_DATA, 304 | SMART_CARD, 305 | CONTENT_SECURITY, 306 | VIDEO, 307 | PERSONAL_HEALTHCARE, 308 | AUDIO_VIDEO, 309 | BILLBOARD, 310 | DIAGNOSTIC, 311 | WIRELESS_CONTROLLER, 312 | MISCELLANEOUS, 313 | APPLICATION_SPECIFIC, 314 | VENDOR_SPECIFIC 315 | } 316 | [CCode (cheader_filename = "gusb.h", cprefix = "G_USB_DEVICE_DIRECTION_", has_type_id = false)] 317 | public enum DeviceDirection { 318 | DEVICE_TO_HOST, 319 | HOST_TO_DEVICE 320 | } 321 | [CCode (cheader_filename = "gusb.h", cprefix = "G_USB_DEVICE_ERROR_", has_type_id = false)] 322 | public errordomain DeviceError { 323 | INTERNAL, 324 | IO, 325 | TIMED_OUT, 326 | NOT_SUPPORTED, 327 | NO_DEVICE, 328 | NOT_OPEN, 329 | ALREADY_OPEN, 330 | CANCELLED, 331 | FAILED, 332 | PERMISSION_DENIED, 333 | LAST 334 | } 335 | [CCode (cheader_filename = "gusb.h", cprefix = "G_USB_DEVICE_LANGID_", has_type_id = false)] 336 | public enum DeviceLangid { 337 | INVALID, 338 | ENGLISH_UNITED_STATES 339 | } 340 | [CCode (cheader_filename = "gusb.h", cprefix = "G_USB_DEVICE_RECIPIENT_", has_type_id = false)] 341 | public enum DeviceRecipient { 342 | DEVICE, 343 | INTERFACE, 344 | ENDPOINT, 345 | OTHER 346 | } 347 | [CCode (cheader_filename = "gusb.h", cprefix = "G_USB_DEVICE_REQUEST_TYPE_", has_type_id = false)] 348 | public enum DeviceRequestType { 349 | STANDARD, 350 | CLASS, 351 | VENDOR, 352 | RESERVED 353 | } 354 | [CCode (cheader_filename = "gusb.h", cprefix = "G_USB_SOURCE_ERROR_", has_type_id = false)] 355 | public errordomain SourceError { 356 | [CCode (cname = "G_USB_SOURCE_ERROR_INTERNAL")] 357 | SOURCE_ERROR_INTERNAL; 358 | [Version (replacement = "Source.error_quark", since = "0.1.0")] 359 | public static GLib.Quark quark (); 360 | } 361 | [CCode (cheader_filename = "gusb.h", cname = "G_USB_MAJOR_VERSION")] 362 | public const int MAJOR_VERSION; 363 | [CCode (cheader_filename = "gusb.h", cname = "G_USB_MICRO_VERSION")] 364 | public const int MICRO_VERSION; 365 | [CCode (cheader_filename = "gusb.h", cname = "G_USB_MINOR_VERSION")] 366 | public const int MINOR_VERSION; 367 | [CCode (cheader_filename = "gusb.h")] 368 | [Version (since = "0.1.0")] 369 | public static unowned string strerror (int error_code); 370 | [CCode (cheader_filename = "gusb.h")] 371 | [Version (since = "0.3.1")] 372 | public static unowned string version_string (); 373 | } 374 | -------------------------------------------------------------------------------- /src/UsbDeviceClient.vala: -------------------------------------------------------------------------------- 1 | /* UsbDeviceClent.vala 2 | * 3 | * Copyright 2023 v1993 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * SPDX-License-Identifier: GPL-3.0-or-later 19 | */ 20 | 21 | namespace NXDumpClient { 22 | enum UsbDeviceClientStatus { 23 | UNINITIALIZED, 24 | CONNECTED, 25 | TRANSFER, 26 | FATAL_ERROR 27 | } 28 | 29 | errordomain UsbDeviceClientError { 30 | FAILED 31 | } 32 | 33 | private enum UsbCommands { 34 | START_SESSION, 35 | SEND_FILE_PROPERTIES, 36 | CANCEL_FILE_TRANSFER, 37 | SEND_NSP_HEADER, 38 | END_SESSION, 39 | START_EXTRACTED_FS_DUMP, 40 | END_EXTRACTED_FS_DUMP, 41 | } 42 | 43 | // Error codes directly map to responses 44 | private errordomain UsbDeviceProtocolError { 45 | INVALID_MAGIC_WORD = 4, 46 | UNSUPPORTED_COMMAND = 5, 47 | UNSUPPORTED_ABI_VERSION = 6, 48 | MALFORMED_COMMAND = 7, 49 | IO_ERROR = 8 50 | } 51 | 52 | private struct NspDumpStatus { 53 | int64 total_size; ///< With header 54 | int64 transferred_size; ///< Without header 55 | int64 header_size; 56 | File file; 57 | FileOutputStream ostream; 58 | FileTransferInhibitor inhibitor; 59 | GenericArray? nca_checksums; // Prefixes for NCA files 60 | } 61 | 62 | /** 63 | * This is intended for breaking changes or new fields in existing commands. 64 | * New commands/possible invocations of commands are added without version checks. 65 | */ 66 | [Flags] 67 | private enum ClientFeatures { 68 | NONE = 0, 69 | } 70 | 71 | private const string COMMAND_MAGIC = "NXDT"; 72 | private const uint32 HEADER_SIZE = 0x10; 73 | private const uint32 RESPONSE_SIZE = 0x10; 74 | private const uint DEFAULT_TIMEOUT = 5000; 75 | private const uint32 STATUS_SUCCESS = 0x0; 76 | internal const uint32 BLOCK_SIZE = 0x800000; 77 | 78 | private const string NSP_MAGIC = "PFS0"; 79 | 80 | // Throw errors that are not fatal to device as UsbDeviceProtocolError 81 | private Error error_to_recoverable(Error err) { 82 | try { 83 | throw err; 84 | } catch(UsbDeviceProtocolError e) { 85 | // Preserve error code 86 | return e; 87 | } catch(GUsb.DeviceError e) { 88 | // UBS stack errors are not recoverable 89 | return e; 90 | } catch(IOError.CANCELLED e) { 91 | // Cancellation must not be silenced 92 | return e; 93 | } catch(Error e) { 94 | return new UsbDeviceProtocolError.IO_ERROR(e.message); 95 | } 96 | } 97 | 98 | // TODO: utilize new ABI commands instead of guessing from prefixes 99 | private bool is_mass_transfer_path(string path) { 100 | const string[] PATHS = { 101 | "/NCA FS/User/Extracted", 102 | "/NCA FS/System/Extracted", 103 | "/atmosphere/contents", 104 | }; 105 | 106 | foreach(unowned var prefix in PATHS) { 107 | if (path.has_prefix(prefix)) { 108 | return true; 109 | } 110 | } 111 | 112 | return false; 113 | } 114 | 115 | /** 116 | * Convert path from device to one that can be used as relative to output directory. 117 | */ 118 | private string device_to_relative_path(owned string path) throws ConvertError 119 | ensures(!Path.is_absolute(result)) 120 | { 121 | if (new Application().flatten_output) { 122 | /* 123 | * Completely flattening these dumps is a bad idea. 124 | * However, it's possible to strip long prefixes and thus avoid extra nesting. 125 | */ 126 | const string[] STRIP_AND_PRESERVE = { 127 | "/NCA FS/User/Extracted", 128 | "/NCA FS/System/Extracted", 129 | "/NCA FS/User/Raw", 130 | "/NCA FS/System/Raw", 131 | "/NCA/User", 132 | "/NCA/System", 133 | "/HFS/Extracted", 134 | "/HFS/Raw", 135 | "/atmosphere/contents", 136 | }; 137 | 138 | bool preserve_path = false; 139 | 140 | foreach(unowned var prefix in STRIP_AND_PRESERVE) { 141 | if (path.has_prefix(prefix)) { 142 | path = path[prefix.length:]; 143 | preserve_path = true; 144 | break; 145 | } 146 | } 147 | 148 | if (!preserve_path) { 149 | path = Path.get_basename(path); 150 | } 151 | } 152 | 153 | return Path.skip_root(path) ?? path; 154 | } 155 | 156 | private async File get_dump_target(string filepath_utf8, int64 file_size, Cancellable? cancellable = null) throws Error { 157 | var main_dir = new Application().destination_directory; 158 | var filepath = device_to_relative_path(Filename.from_utf8(filepath_utf8, -1, null, null)); 159 | 160 | var dest_file = main_dir.resolve_relative_path(filepath); 161 | var dest_dir = dest_file.get_parent(); 162 | yield create_directory_with_parents_async(dest_dir, cancellable); 163 | 164 | var info = yield dest_dir.query_filesystem_info_async(FileAttribute.FILESYSTEM_FREE, Priority.DEFAULT, cancellable); 165 | 166 | if (info.has_attribute(FileAttribute.FILESYSTEM_FREE)) { 167 | var free_space = info.get_attribute_uint64(FileAttribute.FILESYSTEM_FREE); 168 | debug("Required space: %s, free space: %s", format_size(file_size), format_size(free_space)); 169 | if (free_space < file_size) { 170 | throw new IOError.NO_SPACE(_("Not enough space for dump (%s required)"), format_size(file_size)); 171 | } 172 | } else { 173 | debug("Can't query free space"); 174 | } 175 | 176 | return dest_file; 177 | } 178 | 179 | /** 180 | * The class that handles actual communication with device. 181 | */ 182 | class UsbDeviceClient: Object { 183 | public UsbDeviceOpener devopener { private get; construct; } 184 | public GUsb.Device dev { get { return devopener.dev; } } 185 | public Cancellable? cancellable { get; construct; } 186 | public UsbDeviceClientStatus status { get; private set; default = UNINITIALIZED; } 187 | public string? version_string { get; private set; default = null; } 188 | 189 | // User-visible, so in NSP mode they reflect status of the whole NSP 190 | public string transfer_file_name { get; private set; default = ""; } 191 | public string transfer_file_name_inner { get; private set; default = ""; } // Used in NSP mode 192 | public int64 transfer_total_bytes { get; private set; default = 0; } 193 | public int64 transfer_current_bytes { get; private set; default = 0; } 194 | public int64 transfer_started_time { get; private set; default = 0; } 195 | 196 | public uint16 max_packet_size { get { 197 | if (endpoint_input != null) { 198 | return endpoint_input.get_maximum_packet_size(); 199 | } else { 200 | return 0; 201 | } 202 | } } 203 | 204 | public signal void transfer_started(File file, bool mass_transfer); 205 | public signal void transfer_got_empty_file(File file, bool mass_transfer); 206 | public signal void transfer_next_inner_file(); // Used in NSP mode 207 | public signal void transfer_progress(); 208 | public virtual signal void transfer_complete(File file, bool mass_transfer) { 209 | nsp_dump_status = null; 210 | status = CONNECTED; 211 | } 212 | // MAY be issued without prior `transfer_started` if creating empty file failed 213 | public virtual signal void transfer_failed(File file, bool cancelled) { 214 | nsp_dump_status = null; 215 | status = CONNECTED; 216 | } 217 | 218 | private static GenericSet supported_abis = new GenericSet(null, null); 219 | 220 | private static uint8 make_abi_version(uint8 major, uint8 minor) 221 | requires (major < 16 && minor < 16) { 222 | return major << 4 | minor; 223 | } 224 | 225 | static construct { 226 | supported_abis.add(make_abi_version(1, 1)); 227 | supported_abis.add(make_abi_version(1, 2)); 228 | } 229 | 230 | private GUsb.Interface iface = null; 231 | private GUsb.Endpoint endpoint_input = null; 232 | private GUsb.Endpoint endpoint_output = null; 233 | private NspDumpStatus? nsp_dump_status = null; 234 | private ClientFeatures features = NONE; 235 | 236 | public UsbDeviceClient(owned UsbDeviceOpener devopener_, Cancellable? cancellable_ = null) throws Error { 237 | Object(devopener: (owned)devopener_, cancellable: cancellable_); 238 | setup(); 239 | } 240 | 241 | public void setup() throws Error 242 | requires (status == UNINITIALIZED || status == FATAL_ERROR) 243 | { 244 | dev.reset(); // Seems to be a recommended thing to do; does not incur delays 245 | status = UNINITIALIZED; 246 | nsp_dump_status = null; 247 | version_string = null; 248 | 249 | iface = dev.get_interface(0xFF, 0xFF, 0xFF); 250 | if (iface == null) { 251 | throw new UsbDeviceClientError.FAILED("Unable to find expected device interface"); 252 | } 253 | dev.claim_interface(iface.get_index(), BIND_KERNEL_DRIVER); 254 | 255 | foreach(unowned var endpoint in iface.get_endpoints()) { 256 | if (endpoint.get_direction() == DEVICE_TO_HOST) { 257 | endpoint_input = endpoint; 258 | } else { 259 | endpoint_output = endpoint; 260 | } 261 | } 262 | 263 | if (endpoint_input == null || endpoint_output == null) { 264 | throw new UsbDeviceClientError.FAILED("Unable to find endpoints"); 265 | } 266 | 267 | usb_handler.begin(); 268 | } 269 | 270 | private async void usb_handler() { 271 | try { 272 | while (true) { 273 | try { 274 | uint8 header_buf[HEADER_SIZE]; 275 | debug("Waiting for command header"); 276 | var bytes_read = yield dev.bulk_transfer_async(endpoint_input.get_address(), header_buf, 0, cancellable); 277 | debug("Got command header"); 278 | if (bytes_read != HEADER_SIZE) { 279 | throw new UsbDeviceClientError.FAILED("Failed to read command header"); 280 | } 281 | 282 | var header_istream = make_input_stream(header_buf); 283 | if (header_istream.read_bytes(COMMAND_MAGIC.length, cancellable).compare(new Bytes.static(COMMAND_MAGIC.data)) != 0) { 284 | throw new UsbDeviceProtocolError.INVALID_MAGIC_WORD("Invalid header magic"); 285 | } 286 | 287 | var command_id = header_istream.read_uint32(cancellable); 288 | var command_block_size = header_istream.read_uint32(cancellable); 289 | var command_block_buf = new uint8[command_block_size]; 290 | 291 | if (command_block_size > 0) { 292 | bytes_read = yield dev.bulk_transfer_async( 293 | endpoint_input.get_address(), 294 | command_block_buf[:adjust_length_for_zlt(command_block_size)], 295 | DEFAULT_TIMEOUT, 296 | cancellable 297 | ); 298 | 299 | if (bytes_read != command_block_size) { 300 | throw new UsbDeviceClientError.FAILED("Failed to read command block"); 301 | } 302 | } 303 | 304 | switch(command_id) { 305 | case UsbCommands.START_SESSION: 306 | yield start_session(command_block_buf); 307 | break; 308 | case UsbCommands.END_SESSION: 309 | yield end_session(command_block_buf); 310 | break; 311 | 312 | case UsbCommands.SEND_FILE_PROPERTIES: 313 | yield file_transfer(command_block_buf); 314 | break; 315 | case UsbCommands.CANCEL_FILE_TRANSFER: 316 | yield standalone_cancel(command_block_buf); 317 | break; 318 | case UsbCommands.SEND_NSP_HEADER: 319 | yield nsp_header(command_block_buf); 320 | break; 321 | 322 | case UsbCommands.START_EXTRACTED_FS_DUMP: 323 | yield start_extracted_fs_dump(command_block_buf); 324 | break; 325 | case UsbCommands.END_EXTRACTED_FS_DUMP: 326 | yield end_extracted_fs_dump(command_block_buf); 327 | break; 328 | default: 329 | throw new UsbDeviceProtocolError.UNSUPPORTED_COMMAND("Unsupported command 0x%X", command_id); 330 | } 331 | } catch(UsbDeviceProtocolError e) { 332 | // Explicitly designed to translate to status codes 1:1 333 | report_error("Error during device communication", e.message); 334 | yield send_status_response(e.code); 335 | } 336 | } 337 | } catch(GUsb.DeviceError.CANCELLED e) { 338 | } catch(IOError.CANCELLED e) { 339 | } catch(GUsb.DeviceError.NO_DEVICE e) { 340 | // Expected on device disconnect 341 | } catch(Error e) { 342 | if (nsp_dump_status != null) { 343 | transfer_failed.emit(nsp_dump_status.file, false); 344 | } 345 | 346 | report_error("Error during device communication", e.message); 347 | status = FATAL_ERROR; 348 | return; 349 | } finally { 350 | version_string = null; 351 | } 352 | status = UNINITIALIZED; 353 | debug("Normal exit from device loop"); 354 | } 355 | 356 | private async void start_session(uint8[] command) throws Error { 357 | debug("Starting session"); 358 | if (command.length != 0x10) { 359 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("StartSession command with invalid length 0x%X", command.length); 360 | } 361 | var istream = make_input_stream(command); 362 | 363 | // NXDT version 364 | var ver_major = istream.read_byte(cancellable); 365 | var ver_minor = istream.read_byte(cancellable); 366 | var ver_micro = istream.read_byte(cancellable); 367 | 368 | var abi_ver = istream.read_byte(cancellable); 369 | if (!(abi_ver in supported_abis)) { 370 | throw new UsbDeviceProtocolError.UNSUPPORTED_ABI_VERSION("Unsupported USB ABI version %s", format_usb_abi(abi_ver)); 371 | } 372 | 373 | { 374 | features = NONE; 375 | 376 | // Put feature selection code here 377 | } 378 | 379 | var git_hash = (string)istream.read_bytes(8, cancellable).get_data(); 380 | version_string = @"v$(ver_major).$(ver_minor).$(ver_micro) ($(git_hash))"; 381 | yield send_status_success(); 382 | 383 | status = CONNECTED; 384 | nsp_dump_status = null; 385 | debug("Device initialized"); 386 | } 387 | 388 | private async void end_session(uint8[] command) throws Error { 389 | try { 390 | if (command.length != 0x0) { 391 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("EndSession command with invalid length 0x%X", command.length); 392 | } 393 | 394 | if (nsp_dump_status != null) { 395 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("EndSession in the middle of an NSP transfer"); 396 | } 397 | } finally { 398 | debug("Device deinitialized"); 399 | status = UNINITIALIZED; 400 | nsp_dump_status = null; 401 | } 402 | 403 | yield send_status_success(); 404 | } 405 | 406 | private async void file_transfer(uint8[] command) throws Error { 407 | if (command.length != 0x320) { 408 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("SendFileProperties command with invalid length 0x%X", command.length); 409 | } 410 | var checksum_mode = new Application().nca_checksum_mode; 411 | var istream = make_input_stream(command); 412 | 413 | var file_size = istream.read_int64(cancellable); 414 | /*var filename_len = */istream.read_uint32(cancellable); 415 | var nsp_header_size = istream.read_uint32(cancellable); 416 | 417 | if (status != CONNECTED && (status != TRANSFER || nsp_dump_status == null)) { 418 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("SendFileProperties requires prior connection"); 419 | } 420 | 421 | var filename = (string)istream.read_bytes(0x301, cancellable).get_data(); 422 | File file; 423 | FileOutputStream ostream; 424 | FileTransferInhibitor inhibitor; 425 | 426 | try { 427 | if (nsp_dump_status == null) { 428 | file = yield get_dump_target(filename, file_size, cancellable); 429 | ostream = yield file.replace_async(null, false, REPLACE_DESTINATION, Priority.DEFAULT, cancellable); 430 | inhibitor = new FileTransferInhibitor(); 431 | } else { 432 | file = nsp_dump_status.file; 433 | ostream = nsp_dump_status.ostream; 434 | inhibitor = nsp_dump_status.inhibitor; 435 | } 436 | } catch(Error e) { 437 | throw error_to_recoverable(e); 438 | } 439 | 440 | if (nsp_header_size > 0) { 441 | if (nsp_dump_status != null) { 442 | transfer_failed.emit(nsp_dump_status.file, false); 443 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("Unexpected NSP start command"); 444 | } 445 | 446 | if (file_size < nsp_header_size) { 447 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("NSP file size smaller than header"); 448 | } 449 | 450 | ostream.seek(nsp_header_size, SET, cancellable); 451 | 452 | freeze_notify(); 453 | try { 454 | transfer_file_name = filename; 455 | transfer_file_name_inner = ""; 456 | transfer_total_bytes = file_size; 457 | transfer_current_bytes = 0; 458 | transfer_started_time = 0; 459 | status = TRANSFER; 460 | } finally { 461 | thaw_notify(); 462 | } 463 | 464 | nsp_dump_status = NspDumpStatus() { 465 | total_size = file_size, 466 | transferred_size = 0, 467 | header_size = nsp_header_size, 468 | file = file, 469 | ostream = ostream, 470 | inhibitor = inhibitor, 471 | nca_checksums = checksum_mode == COMPATIBLE ? new GenericArray() : null, 472 | }; 473 | 474 | yield send_status_success(); 475 | transfer_started.emit(file, false); 476 | debug("Entered NSP mode"); 477 | return; 478 | } 479 | 480 | if (file_size == 0) { 481 | try { 482 | if (nsp_dump_status == null) { 483 | yield ostream.close_async(Priority.DEFAULT, cancellable); 484 | transfer_got_empty_file.emit(file, is_mass_transfer_path(filename)); 485 | } 486 | yield send_status_success(); 487 | return; 488 | } catch(Error e) { 489 | transfer_failed.emit(file, false); 490 | throw error_to_recoverable(e); 491 | } 492 | } 493 | 494 | // Enter file transfer mode 495 | yield send_status_success(); 496 | status = TRANSFER; 497 | if (nsp_dump_status == null) { 498 | freeze_notify(); 499 | try { 500 | transfer_file_name = filename; 501 | transfer_file_name_inner = ""; 502 | transfer_total_bytes = file_size; 503 | transfer_current_bytes = 0; 504 | transfer_started_time = 0; 505 | } finally { 506 | thaw_notify(); 507 | } 508 | 509 | transfer_started.emit(file, is_mass_transfer_path(filename)); 510 | } else { 511 | transfer_file_name_inner = filename; 512 | transfer_next_inner_file.emit(); 513 | } 514 | 515 | Checksum? checksum = null; 516 | if (filename.has_suffix(".nca")) { 517 | if (checksum_mode != NONE || nsp_dump_status?.nca_checksums != null) { 518 | checksum = new Checksum(SHA256); 519 | } 520 | } 521 | 522 | debug("Transfer of file %s started", filename); 523 | 524 | /* 525 | * We're in file transfer mode now. As implemented currently, it means we must not report errors to console, 526 | * but instead throw a critical error and let it time out. Might change in future ABI revision. 527 | */ 528 | 529 | try { 530 | var read_buffer = new uint8[BLOCK_SIZE]; 531 | var read_size = BLOCK_SIZE; 532 | int64 bytes_transferred = 0; 533 | 534 | while(bytes_transferred < file_size) { 535 | var bytes_remaining = file_size - bytes_transferred; 536 | if (bytes_remaining <= BLOCK_SIZE) { 537 | read_size = adjust_length_for_zlt(read_size); 538 | } 539 | 540 | var bytes_read = yield dev.bulk_transfer_async( 541 | endpoint_input.get_address(), 542 | read_buffer[:read_size], 543 | DEFAULT_TIMEOUT, 544 | cancellable 545 | ); 546 | 547 | unowned var incoming_data = read_buffer[:bytes_read]; 548 | 549 | if (bytes_read == HEADER_SIZE) { 550 | // Check if it's a transfer canceling message 551 | var header_istream = make_input_stream(incoming_data); 552 | if (header_istream.read_bytes(COMMAND_MAGIC.length, cancellable).compare(new Bytes.static(COMMAND_MAGIC.data)) == 0 && 553 | header_istream.read_uint32(cancellable) == UsbCommands.CANCEL_FILE_TRANSFER 554 | ) { 555 | // Transfer canceled 556 | debug("Transfer canceled"); 557 | yield ostream.close_async(Priority.DEFAULT, cancellable); 558 | transfer_failed.emit(file, true); 559 | yield send_status_success(); 560 | return; 561 | } 562 | } 563 | 564 | yield ostream.write_all_async(incoming_data, Priority.DEFAULT, cancellable, null); 565 | bytes_transferred += bytes_read; 566 | transfer_current_bytes += bytes_read; 567 | if (nsp_dump_status != null) { 568 | nsp_dump_status.transferred_size += bytes_read; 569 | } 570 | 571 | if (checksum != null) { 572 | checksum.update(incoming_data, incoming_data.length); 573 | } 574 | 575 | if (transfer_started_time == 0) { 576 | transfer_started_time = get_monotonic_time(); 577 | } 578 | 579 | transfer_progress.emit(); 580 | } 581 | 582 | debug("File transfer finished"); 583 | } catch(Error e) { 584 | transfer_failed.emit(file, false); 585 | throw e; 586 | } 587 | 588 | try { 589 | if (nsp_dump_status == null) { 590 | transfer_current_bytes = transfer_total_bytes; 591 | transfer_progress.emit(); 592 | yield ostream.close_async(Priority.DEFAULT, cancellable); 593 | // In NSP mode it is emitted from nsp_header 594 | transfer_complete.emit(file, is_mass_transfer_path(filename)); 595 | } else { 596 | transfer_file_name_inner = ""; 597 | transfer_next_inner_file.emit(); 598 | } 599 | 600 | if (checksum != null) { 601 | var checksum_string_abridged = checksum.get_string()[:32]; 602 | // Strict mode or standalone (thus unmodified) NCA 603 | if (checksum_mode == STRICT || (checksum_mode == COMPATIBLE && nsp_dump_status == null)) { 604 | var basename = Path.get_basename(filename); 605 | if (!basename.has_prefix(checksum_string_abridged)) { 606 | if (!ostream.is_closed()) { 607 | // Avoid synchronous closing in destructor 608 | yield ostream.close_async(Priority.DEFAULT, cancellable); 609 | } 610 | 611 | throw new UsbDeviceProtocolError.IO_ERROR(_("NCA checksum verification failed (non-standard dump options?)")); 612 | } else { 613 | debug("Checksum verification passed"); 614 | } 615 | } 616 | // Always check for this so that messing with settings during the transfer will not make it fail 617 | if (nsp_dump_status?.nca_checksums != null) { 618 | nsp_dump_status.nca_checksums.add((owned)checksum_string_abridged); 619 | debug("Checksum pushed into queue"); 620 | } 621 | } 622 | 623 | yield send_status_success(); 624 | } catch(Error e) { 625 | // Status is expected at the end of transmission, so we can make errors recoverable at this point 626 | transfer_failed.emit(file, false); 627 | throw error_to_recoverable(e); 628 | } 629 | } 630 | 631 | private async void standalone_cancel(uint8[] header) throws Error { 632 | if (nsp_dump_status == null) { 633 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("Cancellation command without an ongoing transfer"); 634 | } 635 | 636 | try { 637 | yield nsp_dump_status.ostream.close_async(Priority.DEFAULT, cancellable); 638 | yield send_status_success(); 639 | } catch(Error e) { 640 | throw error_to_recoverable(e); 641 | } finally { 642 | transfer_failed.emit(nsp_dump_status.file, true); 643 | } 644 | } 645 | 646 | private async void nsp_header(uint8[] header) throws Error { 647 | try { 648 | if (nsp_dump_status == null) { 649 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("NSP header outside of NSP transfer"); 650 | } 651 | 652 | if (nsp_dump_status.header_size != header.length) { 653 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("NSP header size mismatch"); 654 | } 655 | 656 | if ((nsp_dump_status.transferred_size + nsp_dump_status.header_size) != nsp_dump_status.total_size) { 657 | throw new UsbDeviceProtocolError.MALFORMED_COMMAND("NSP header before transfer completion"); 658 | } 659 | 660 | transfer_file_name_inner = _("NSP header"); 661 | transfer_next_inner_file.emit(); 662 | 663 | if (nsp_dump_status.nca_checksums != null) { 664 | verify_nsp_checksums(header, nsp_dump_status.nca_checksums); 665 | } 666 | 667 | var ostream = nsp_dump_status.ostream; 668 | ostream.seek(0, SET, cancellable); 669 | debug("Writing header"); 670 | yield ostream.write_all_async(header, Priority.DEFAULT, cancellable, null); 671 | transfer_current_bytes = transfer_total_bytes; 672 | transfer_progress.emit(); 673 | debug("Closing file"); 674 | yield ostream.close_async(Priority.DEFAULT, cancellable); 675 | debug("File closed"); 676 | 677 | yield send_status_success(); 678 | transfer_complete.emit(nsp_dump_status.file, false); 679 | } catch(Error e) { 680 | transfer_failed.emit(nsp_dump_status.file, false); 681 | throw error_to_recoverable(e); 682 | } 683 | } 684 | 685 | private async void start_extracted_fs_dump(uint8[] header) throws Error { 686 | debug("start_extracted_fs_dump called"); 687 | yield send_status_success(); 688 | } 689 | 690 | private async void end_extracted_fs_dump(uint8[] header) throws Error { 691 | debug("end_extracted_fs_dump called"); 692 | yield send_status_success(); 693 | } 694 | 695 | private void verify_nsp_checksums(uint8[] header, GenericArray checksums) throws Error { 696 | var istream = make_input_stream(header); 697 | if (istream.read_bytes(NSP_MAGIC.length, cancellable).compare(new Bytes.static(NSP_MAGIC.data)) != 0) { 698 | throw new UsbDeviceProtocolError.IO_ERROR("NSP header has invalid magic"); 699 | } 700 | 701 | var entry_count = istream.read_uint32(cancellable); 702 | if (checksums.length > entry_count) { 703 | throw new UsbDeviceProtocolError.IO_ERROR("NSP header has less entries than there are checksummed files"); 704 | } 705 | 706 | /*var string_table_size =*/ istream.read_uint32(cancellable); 707 | istream.seek(0x4, CUR, cancellable); // Reserved 708 | istream.seek(0x18 * entry_count, CUR, cancellable); // PartitionEntry table 709 | int checksums_idx = 0; 710 | 711 | for (int i = 0; i < entry_count; ++i) { 712 | var fname = istream.read_upto("\0", 1, null, cancellable); 713 | if ((i + 1) != entry_count) { 714 | istream.read_byte(cancellable); 715 | } 716 | 717 | if (fname.has_suffix(".nca")) { 718 | var checksum = checksums[checksums_idx++]; 719 | if (!fname.has_prefix(checksum)) { 720 | throw new UsbDeviceProtocolError.IO_ERROR(_("NCA checksum verification failed")); 721 | } 722 | 723 | debug("Delayed checksum verification for file %s passed", fname); 724 | } 725 | } 726 | 727 | if (checksums_idx != checksums.length) { 728 | throw new UsbDeviceProtocolError.IO_ERROR("NCA checksum count mismatch"); 729 | } 730 | } 731 | 732 | private DataInputStream make_input_stream(uint8[] data) { 733 | // Note: sadly, this creates a copy of data 734 | return new DataInputStream(new MemoryInputStream.from_data(data)) { 735 | byte_order = LITTLE_ENDIAN 736 | }; 737 | } 738 | 739 | private DataOutputStream make_output_stream(uint8[] data) { 740 | return new DataOutputStream(MemoryOutputStream.with_data(data)) { 741 | byte_order = LITTLE_ENDIAN 742 | }; 743 | } 744 | 745 | private async void send_status_success() throws Error { 746 | yield send_status_response(STATUS_SUCCESS); 747 | } 748 | 749 | private uint32 adjust_length_for_zlt(uint32 orig_length) { 750 | if (orig_length != 0 && (orig_length & (endpoint_input.get_maximum_packet_size() - 1)) == 0) { 751 | return orig_length + 1; 752 | } else { 753 | return orig_length; 754 | } 755 | } 756 | 757 | private async void send_status_response(uint32 code) throws Error { 758 | uint8 response[RESPONSE_SIZE]; 759 | var ostream = make_output_stream(response); 760 | ostream.put_string(COMMAND_MAGIC, cancellable); 761 | ostream.put_uint32(code, cancellable); 762 | ostream.put_uint16(endpoint_input.get_maximum_packet_size(), cancellable); 763 | ostream.flush(cancellable); 764 | var bytes_sent = yield dev.bulk_transfer_async(endpoint_output.get_address(), response, DEFAULT_TIMEOUT, cancellable); 765 | if (bytes_sent != RESPONSE_SIZE) { 766 | throw new UsbDeviceClientError.FAILED("Failed to send status"); 767 | } 768 | } 769 | } 770 | } 771 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | --------------------------------------------------------------------------------