Compare commits
4 Commits
main
..
7bd6a90bde
| Author | SHA1 | Date | |
|---|---|---|---|
| 7bd6a90bde | |||
| dc65a4c8a9 | |||
| 895fee6235 | |||
| b5c506cf03 |
@@ -26,4 +26,3 @@ IncludeCategories:
|
|||||||
SpacesBeforeTrailingComments: 2
|
SpacesBeforeTrailingComments: 2
|
||||||
Cpp11BracedListStyle: true
|
Cpp11BracedListStyle: true
|
||||||
Standard: c++17
|
Standard: c++17
|
||||||
NamespaceIndentation: All
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
# Normalize line endings
|
# Normalize line endings
|
||||||
* text=auto eol=lf
|
* text=auto eol=lf
|
||||||
|
|
||||||
|
# Vendor: do not count toward language stats
|
||||||
|
lib/Plutonium/** linguist-vendored=true
|
||||||
|
deps/** linguist-vendored=true
|
||||||
|
|
||||||
# Binary assets
|
# Binary assets
|
||||||
*.png binary
|
*.png binary
|
||||||
*.jpg binary
|
*.jpg binary
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
nro:
|
|
||||||
name: Build NRO
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
AUTH_URL=$(echo "$GITHUB_SERVER_URL" | sed "s|://|://oauth2:${GITHUB_TOKEN}@|")
|
|
||||||
docker rm -f nxst-build 2>/dev/null || true
|
|
||||||
docker run --name nxst-build devkitpro/devkita64:latest \
|
|
||||||
bash -c "
|
|
||||||
git clone --recurse-submodules '${AUTH_URL}/${GITHUB_REPOSITORY}' /src &&
|
|
||||||
cd /src && git checkout '${GITHUB_SHA}' &&
|
|
||||||
cmake --preset switch &&
|
|
||||||
cmake --build build -j\$(nproc)
|
|
||||||
"
|
|
||||||
docker cp nxst-build:/src/build/NXST.nro ./NXST.nro
|
|
||||||
docker rm nxst-build
|
|
||||||
|
|
||||||
- name: Publish release
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
|
||||||
env:
|
|
||||||
GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
||||||
run: |
|
|
||||||
release_id=$(curl -sf -X POST "${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases" \
|
|
||||||
-H "Authorization: token $GITEA_TOKEN" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"tag_name\": \"${GITHUB_REF_NAME}\", \"name\": \"${GITHUB_REF_NAME}\"}" \
|
|
||||||
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
|
||||||
|
|
||||||
curl -sf -X POST "${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases/${release_id}/assets?name=NXST.nro" \
|
|
||||||
-H "Authorization: token $GITEA_TOKEN" \
|
|
||||||
-H "Content-Type: application/octet-stream" \
|
|
||||||
--data-binary @./NXST.nro
|
|
||||||
|
|
||||||
format:
|
|
||||||
name: Format check
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
run: |
|
|
||||||
AUTH_URL=$(echo "$GITHUB_SERVER_URL" | sed "s|://|://oauth2:${GITHUB_TOKEN}@|")
|
|
||||||
git clone "${AUTH_URL}/${GITHUB_REPOSITORY}" .
|
|
||||||
git checkout "$GITHUB_SHA"
|
|
||||||
|
|
||||||
- name: Install clang-format
|
|
||||||
run: |
|
|
||||||
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
|
||||||
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-22 main" | sudo tee /etc/apt/sources.list.d/llvm.list
|
|
||||||
sudo apt-get update && sudo apt-get install -y clang-format-22
|
|
||||||
sudo ln -sf /usr/bin/clang-format-22 /usr/local/bin/clang-format
|
|
||||||
|
|
||||||
- name: Check formatting
|
|
||||||
run: |
|
|
||||||
find src include \( -name '*.cpp' -o -name '*.hpp' \) \
|
|
||||||
| xargs clang-format --dry-run --Werror
|
|
||||||
|
|
||||||
layering:
|
|
||||||
name: Layering check
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
run: |
|
|
||||||
AUTH_URL=$(echo "$GITHUB_SERVER_URL" | sed "s|://|://oauth2:${GITHUB_TOKEN}@|")
|
|
||||||
git clone "${AUTH_URL}/${GITHUB_REPOSITORY}" .
|
|
||||||
git checkout "$GITHUB_SHA"
|
|
||||||
|
|
||||||
- name: UI must not include net/sys headers
|
|
||||||
run: |
|
|
||||||
! grep -rE '^#include\s*[<"](arpa/inet|sys/socket|pthread)' src/ui/
|
|
||||||
@@ -53,11 +53,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install clang-format
|
- name: Install clang-format
|
||||||
run: |
|
run: sudo apt-get install -y clang-format
|
||||||
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
|
||||||
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-22 main" | sudo tee /etc/apt/sources.list.d/llvm.list
|
|
||||||
sudo apt-get update && sudo apt-get install -y clang-format-22
|
|
||||||
sudo ln -sf /usr/bin/clang-format-22 /usr/local/bin/clang-format
|
|
||||||
|
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.serena
|
.serena
|
||||||
.idea/
|
|
||||||
|
|
||||||
# Prerequisites
|
# Prerequisites
|
||||||
*.d
|
*.d
|
||||||
@@ -50,4 +49,3 @@ CMakeCache.txt
|
|||||||
CMakeFiles/
|
CMakeFiles/
|
||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
.cache/
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "lib"]
|
||||||
|
path = lib
|
||||||
|
url = https://github.com/XorTroll/Plutonium.git
|
||||||
+11
-28
@@ -32,10 +32,17 @@ file(GLOB_RECURSE NXST_SOURCES
|
|||||||
src/ui/*.cpp
|
src/ui/*.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(NXST ${NXST_SOURCES})
|
file(GLOB_RECURSE PLUTONIUM_SOURCES
|
||||||
|
lib/Plutonium/source/*.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(NXST ${NXST_SOURCES} ${PLUTONIUM_SOURCES})
|
||||||
|
|
||||||
# ── Include paths ─────────────────────────────────────────────────────────────
|
# ── Include paths ─────────────────────────────────────────────────────────────
|
||||||
target_include_directories(NXST PRIVATE include)
|
target_include_directories(NXST PRIVATE
|
||||||
|
include
|
||||||
|
lib/Plutonium/include
|
||||||
|
)
|
||||||
|
|
||||||
# ── pkg-config (uses aarch64-none-elf-pkg-config set by Switch.cmake) ─────────
|
# ── pkg-config (uses aarch64-none-elf-pkg-config set by Switch.cmake) ─────────
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
@@ -49,37 +56,13 @@ pkg_check_modules(PORTLIBS REQUIRED IMPORTED_TARGET ${NXST_PKG_MODULES})
|
|||||||
|
|
||||||
target_include_directories(NXST PRIVATE ${PORTLIBS_INCLUDE_DIRS})
|
target_include_directories(NXST PRIVATE ${PORTLIBS_INCLUDE_DIRS})
|
||||||
|
|
||||||
# ── Plutonium ─────────────────────────────────────────────────────────────────
|
|
||||||
include(ExternalProject)
|
|
||||||
|
|
||||||
set(PLUTONIUM_SOURCE_DIR ${CMAKE_BINARY_DIR}/plutonium)
|
|
||||||
set(LIBPU_A ${PLUTONIUM_SOURCE_DIR}/Plutonium/lib/libpu.a)
|
|
||||||
|
|
||||||
ExternalProject_Add(plutonium_ep
|
|
||||||
GIT_REPOSITORY https://github.com/XorTroll/Plutonium.git
|
|
||||||
GIT_TAG b56564b70d038c59eef875f2c3cf436859c827f2
|
|
||||||
GIT_PROGRESS ON
|
|
||||||
SOURCE_DIR ${PLUTONIUM_SOURCE_DIR}
|
|
||||||
CONFIGURE_COMMAND ""
|
|
||||||
BUILD_COMMAND make -j -C ${PLUTONIUM_SOURCE_DIR}/Plutonium
|
|
||||||
INSTALL_COMMAND ""
|
|
||||||
BUILD_IN_SOURCE 1
|
|
||||||
BUILD_BYPRODUCTS ${LIBPU_A}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(plutonium STATIC IMPORTED GLOBAL)
|
|
||||||
add_dependencies(plutonium plutonium_ep)
|
|
||||||
set_target_properties(plutonium PROPERTIES
|
|
||||||
IMPORTED_LOCATION ${LIBPU_A}
|
|
||||||
)
|
|
||||||
target_include_directories(NXST PRIVATE ${PLUTONIUM_SOURCE_DIR}/Plutonium/include)
|
|
||||||
|
|
||||||
# ── Link libraries ────────────────────────────────────────────────────────────
|
# ── Link libraries ────────────────────────────────────────────────────────────
|
||||||
# Order matters for static linking: put most dependent libs first.
|
# Order matters for static linking: put most dependent libs first.
|
||||||
|
# libpu.a first (contains C wrappers not in Plutonium source).
|
||||||
# drm_nouveau, harfbuzz, freetype, z appended explicitly after pkg-config output
|
# drm_nouveau, harfbuzz, freetype, z appended explicitly after pkg-config output
|
||||||
# to fix the freetype→harfbuzz static link order (see build notes from libnx update).
|
# to fix the freetype→harfbuzz static link order (see build notes from libnx update).
|
||||||
target_link_libraries(NXST PRIVATE
|
target_link_libraries(NXST PRIVATE
|
||||||
plutonium
|
${CMAKE_SOURCE_DIR}/lib/Plutonium/lib/libpu.a
|
||||||
PkgConfig::PORTLIBS
|
PkgConfig::PORTLIBS
|
||||||
drm_nouveau
|
drm_nouveau
|
||||||
harfbuzz
|
harfbuzz
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ Logs are written to `/switch/NXST/log.log`.
|
|||||||
**Prerequisites:** [devkitPro](https://devkitpro.org/wiki/Getting_Started) with `switch-dev` and `switch-portlibs` packages, plus `cmake ≥ 3.20`.
|
**Prerequisites:** [devkitPro](https://devkitpro.org/wiki/Getting_Started) with `switch-dev` and `switch-portlibs` packages, plus `cmake ≥ 3.20`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Clone (Plutonium UI fetched automatically by CMake)
|
# Clone with submodules (Plutonium UI)
|
||||||
git clone https://github.com/your-username/NXST.git
|
git clone --recurse-submodules https://github.com/your-username/NXST.git
|
||||||
cd NXST
|
cd NXST
|
||||||
|
|
||||||
# Configure (once)
|
# Configure (once)
|
||||||
|
|||||||
Vendored
+37
@@ -0,0 +1,37 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "asprintf.h"
|
||||||
|
|
||||||
|
int vasprintf(char **strp, const char *fmt, va_list ap) {
|
||||||
|
int size, res;
|
||||||
|
|
||||||
|
va_list cp;
|
||||||
|
va_copy(cp, ap);
|
||||||
|
size = vsnprintf(NULL, 0, fmt, cp);
|
||||||
|
va_end(cp);
|
||||||
|
if (size < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
*strp = (char *)malloc(size + 1);
|
||||||
|
if (*strp == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
res = vsnprintf(*strp, size + 1, fmt, ap);
|
||||||
|
if (res < 0) {
|
||||||
|
free(*strp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int asprintf(char **s, const char *fmt, ...) {
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
ret = vasprintf(s, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef HAVE_ASPRINTF
|
||||||
|
#define HAVE_ASPRINTF 1
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
int vasprintf(char **strp, const char *fmt, va_list ap);
|
||||||
|
|
||||||
|
int asprintf(char **s, const char *fmt, ...);
|
||||||
|
|
||||||
|
#endif
|
||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "asprintf",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"repo": "Neved4/asprintf",
|
||||||
|
"description": "asprintf, vasprintf - print to allocated string",
|
||||||
|
"license": "MIT",
|
||||||
|
"keywords": ["asprintf", "sprintf", "alloc", "string"],
|
||||||
|
"src": ["asprintf.c", "asprintf.h"]
|
||||||
|
}
|
||||||
+3
-3
@@ -38,7 +38,7 @@ Sender polls in 100 ms slices for up to 3 seconds. Cancel is checked each slice.
|
|||||||
|-----------|-------|
|
|-----------|-------|
|
||||||
| Port | `8080` |
|
| Port | `8080` |
|
||||||
| Direction | sender connects → receiver listens |
|
| Direction | sender connects → receiver listens |
|
||||||
| Buffer size | 65 536 bytes (`proto::kBufSize`) |
|
| Buffer size | 65 536 bytes (`proto::BUF_SIZE`) |
|
||||||
|
|
||||||
**Connection:**
|
**Connection:**
|
||||||
|
|
||||||
@@ -64,14 +64,14 @@ Sender polls in 100 ms slices for up to 3 seconds. Cancel is checked each slice.
|
|||||||
Files are sent sequentially. The stream ends with a sentinel frame:
|
Files are sent sequentially. The stream ends with a sentinel frame:
|
||||||
|
|
||||||
```
|
```
|
||||||
filename_len == 0 (proto::kEofSentinel)
|
filename_len == 0 (proto::EOF_SENTINEL)
|
||||||
```
|
```
|
||||||
|
|
||||||
No `filename` or `file_size` field follows the sentinel.
|
No `filename` or `file_size` field follows the sentinel.
|
||||||
|
|
||||||
**Constraints:**
|
**Constraints:**
|
||||||
|
|
||||||
- `filename_len > proto::kMaxFilename` (4 096) is treated as a protocol error; the receiver aborts.
|
- `filename_len > proto::MAX_FILENAME` (4 096) is treated as a protocol error; the receiver aborts.
|
||||||
- Filenames are full paths as produced by `io::backup` (e.g. `/switch/NXST/<title>/<user>/...`).
|
- Filenames are full paths as produced by `io::backup` (e.g. `/switch/NXST/<title>/<user>/...`).
|
||||||
- On the receiver, the username path component is rewritten to match the local user's nickname before writing to disk.
|
- On the receiver, the username path component is rewritten to match the local user's nickname before writing to disk.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <nxst/ui/const.h>
|
||||||
|
#include <nxst/domain/account.hpp>
|
||||||
|
#include <nxst/domain/title.hpp>
|
||||||
|
#include <nxst/domain/util.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <switch.h>
|
||||||
|
#include <nxst/infra/sys/logger.hpp>
|
||||||
|
|
||||||
|
typedef enum { SORT_ALPHA, SORT_LAST_PLAYED, SORT_PLAY_TIME, SORT_MODES_COUNT } sort_t;
|
||||||
|
|
||||||
|
inline float g_currentTime = 0;
|
||||||
|
inline bool g_backupScrollEnabled = 0;
|
||||||
|
inline bool g_notificationLedAvailable = false;
|
||||||
|
inline bool g_shouldExitNetworkLoop = false;
|
||||||
|
inline std::string g_selectedCheatKey;
|
||||||
|
inline std::vector<std::string> g_selectedCheatCodes;
|
||||||
|
inline u32 g_username_dotsize;
|
||||||
|
inline sort_t g_sortMode = SORT_ALPHA;
|
||||||
|
inline std::string g_currentFile = "";
|
||||||
|
inline bool g_isTransferringFile = false;
|
||||||
|
inline const std::string g_emptySave = "New...";
|
||||||
|
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <pu/Plutonium>
|
#include <pu/Plutonium>
|
||||||
|
|
||||||
#include <nxst/service/transfer_service.hpp>
|
#include <nxst/service/transfer_service.hpp>
|
||||||
#include <nxst/ui/titles_layout.hpp>
|
|
||||||
#include <nxst/ui/users_layout.hpp>
|
#include <nxst/ui/users_layout.hpp>
|
||||||
|
#include <nxst/ui/titles_layout.hpp>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
@@ -20,4 +19,4 @@ namespace ui {
|
|||||||
TitlesLayout::Ref titles_layout;
|
TitlesLayout::Ref titles_layout;
|
||||||
nxst::TransferService transfer;
|
nxst::TransferService transfer;
|
||||||
};
|
};
|
||||||
} // namespace ui
|
}
|
||||||
@@ -1,25 +1,59 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <map>
|
||||||
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <switch.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <switch.h>
|
#define USER_ICON_SIZE 64
|
||||||
|
|
||||||
// Hash and comparison support for AccountUid as map/unordered_map key.
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template <> struct hash<AccountUid> {
|
template <>
|
||||||
size_t operator()(const AccountUid& a) const noexcept {
|
struct hash<AccountUid> {
|
||||||
return (hash<u64>()(a.uid[0]) ^ (hash<u64>()(a.uid[1]) << 1)) >> 1;
|
size_t operator()(const AccountUid& a) const { return ((hash<u64>()(a.uid[0]) ^ (hash<u64>()(a.uid[1]) << 1)) >> 1); }
|
||||||
}
|
|
||||||
};
|
};
|
||||||
} // namespace std
|
}
|
||||||
|
|
||||||
inline bool operator==(const AccountUid& x, const AccountUid& y) {
|
inline bool operator==(const AccountUid& x, const AccountUid& y)
|
||||||
|
{
|
||||||
return x.uid[0] == y.uid[0] && x.uid[1] == y.uid[1];
|
return x.uid[0] == y.uid[0] && x.uid[1] == y.uid[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator<(const AccountUid& x, const AccountUid& y) {
|
inline bool operator==(const AccountUid& x, u64 y)
|
||||||
return x.uid[0] != y.uid[0] ? x.uid[0] < y.uid[0] : x.uid[1] < y.uid[1];
|
{
|
||||||
|
return x.uid[0] == y && x.uid[1] == y;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator<(const AccountUid& x, const AccountUid& y)
|
||||||
|
{
|
||||||
|
if (x.uid[0] != y.uid[0]) return x.uid[0] < y.uid[0];
|
||||||
|
return x.uid[1] < y.uid[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
struct User {
|
struct User {
|
||||||
@@ -27,10 +61,13 @@ struct User {
|
|||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace account {
|
namespace Account {
|
||||||
Result init();
|
Result init(void);
|
||||||
void exit();
|
void exit(void);
|
||||||
std::vector<AccountUid> ids();
|
|
||||||
|
std::vector<AccountUid> ids(void);
|
||||||
|
AccountUid selectAccount(void);
|
||||||
std::string username(AccountUid id);
|
std::string username(AccountUid id);
|
||||||
std::string iconPath(AccountUid id);
|
std::string iconPath(AccountUid id);
|
||||||
} // namespace account
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <algorithm>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <codecvt>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <locale>
|
||||||
|
#include <memory>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define ATEXIT(func) atexit((void (*)())func)
|
||||||
|
|
||||||
|
namespace DateTime {
|
||||||
|
std::string timeStr(void);
|
||||||
|
std::string dateTimeStr(void);
|
||||||
|
std::string logDateTime(void);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace StringUtils {
|
||||||
|
bool containsInvalidChar(const std::string& str);
|
||||||
|
std::string escapeJson(const std::string& s);
|
||||||
|
std::string format(const std::string fmt_str, ...);
|
||||||
|
std::string removeForbiddenCharacters(std::string src);
|
||||||
|
std::string UTF16toUTF8(const std::u16string& src);
|
||||||
|
void ltrim(std::string& s);
|
||||||
|
void rtrim(std::string& s);
|
||||||
|
void trim(std::string& s);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* getConsoleIP(void);
|
||||||
|
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace proto {
|
namespace proto {
|
||||||
constexpr uint16_t kTcpPort = 8080;
|
constexpr uint16_t TCP_PORT = 8080;
|
||||||
constexpr uint16_t kMulticastPort = 8081;
|
constexpr uint16_t MULTICAST_PORT = 8081;
|
||||||
constexpr char kMulticastGroup[] = "239.0.0.1";
|
constexpr char MULTICAST_GROUP[] = "239.0.0.1";
|
||||||
constexpr size_t kBufSize = 65536;
|
constexpr size_t BUF_SIZE = 65536;
|
||||||
constexpr uint32_t kMaxFilename = 4096;
|
constexpr uint32_t MAX_FILENAME = 4096;
|
||||||
constexpr uint32_t kEofSentinel = 0;
|
constexpr uint32_t EOF_SENTINEL = 0;
|
||||||
|
|
||||||
// Wire layout per file:
|
// Wire layout per file:
|
||||||
// [filename_len : uint32_t LE] — 0 == end-of-stream
|
// [filename_len : uint32_t LE] — 0 == end-of-stream
|
||||||
// [filename : filename_len bytes]
|
// [filename : filename_len bytes]
|
||||||
// [file_size : uint64_t LE]
|
// [file_size : uint64_t LE]
|
||||||
// [file_data : file_size bytes]
|
// [file_data : file_size bytes]
|
||||||
} // namespace proto
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
namespace nxst {
|
namespace nxst {
|
||||||
|
|
||||||
template <class T, class E = std::string> class Result {
|
template <class T, class E = std::string>
|
||||||
|
class Result {
|
||||||
bool ok;
|
bool ok;
|
||||||
alignas(T) alignas(E) unsigned char storage[sizeof(T) > sizeof(E) ? sizeof(T) : sizeof(E)];
|
alignas(T) alignas(E) unsigned char storage[sizeof(T) > sizeof(E) ? sizeof(T) : sizeof(E)];
|
||||||
|
|
||||||
@@ -26,52 +27,37 @@ namespace nxst {
|
|||||||
}
|
}
|
||||||
|
|
||||||
~Result() {
|
~Result() {
|
||||||
if (ok)
|
if (ok) reinterpret_cast<T*>(storage)->~T();
|
||||||
reinterpret_cast<T*>(storage)->~T();
|
else reinterpret_cast<E*>(storage)->~E();
|
||||||
else
|
|
||||||
reinterpret_cast<E*>(storage)->~E();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result(const Result& other) : ok(other.ok) {
|
Result(const Result& other) : ok(other.ok) {
|
||||||
if (ok)
|
if (ok) new (storage) T(*reinterpret_cast<const T*>(other.storage));
|
||||||
new (storage) T(*reinterpret_cast<const T*>(other.storage));
|
else new (storage) E(*reinterpret_cast<const E*>(other.storage));
|
||||||
else
|
|
||||||
new (storage) E(*reinterpret_cast<const E*>(other.storage));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result(Result&& other) : ok(other.ok) {
|
Result(Result&& other) : ok(other.ok) {
|
||||||
if (ok)
|
if (ok) new (storage) T(std::move(*reinterpret_cast<T*>(other.storage)));
|
||||||
new (storage) T(std::move(*reinterpret_cast<T*>(other.storage)));
|
else new (storage) E(std::move(*reinterpret_cast<E*>(other.storage)));
|
||||||
else
|
|
||||||
new (storage) E(std::move(*reinterpret_cast<E*>(other.storage)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result& operator=(const Result&) = delete;
|
Result& operator=(const Result&) = delete;
|
||||||
|
|
||||||
bool isOk() const noexcept {
|
bool isOk() const noexcept { return ok; }
|
||||||
return ok;
|
const T& value() const { return *reinterpret_cast<const T*>(storage); }
|
||||||
}
|
const E& error() const { return *reinterpret_cast<const E*>(storage); }
|
||||||
const T& value() const {
|
|
||||||
return *reinterpret_cast<const T*>(storage);
|
|
||||||
}
|
|
||||||
const E& error() const {
|
|
||||||
return *reinterpret_cast<const E*>(storage);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Specialisation for Result<void>
|
// Specialisation for Result<void>
|
||||||
template <class E> class Result<void, E> {
|
template <class E>
|
||||||
|
class Result<void, E> {
|
||||||
bool ok;
|
bool ok;
|
||||||
alignas(E) unsigned char storage[sizeof(E)];
|
alignas(E) unsigned char storage[sizeof(E)];
|
||||||
|
|
||||||
Result() = default;
|
Result() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Result success() {
|
static Result success() { Result res; res.ok = true; return res; }
|
||||||
Result res;
|
|
||||||
res.ok = true;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Result failure(E err) {
|
static Result failure(E err) {
|
||||||
Result res;
|
Result res;
|
||||||
@@ -80,29 +66,20 @@ namespace nxst {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Result() {
|
~Result() { if (!ok) reinterpret_cast<E*>(storage)->~E(); }
|
||||||
if (!ok)
|
|
||||||
reinterpret_cast<E*>(storage)->~E();
|
|
||||||
}
|
|
||||||
|
|
||||||
Result(const Result& other) : ok(other.ok) {
|
Result(const Result& other) : ok(other.ok) {
|
||||||
if (!ok)
|
if (!ok) new (storage) E(*reinterpret_cast<const E*>(other.storage));
|
||||||
new (storage) E(*reinterpret_cast<const E*>(other.storage));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result(Result&& other) : ok(other.ok) {
|
Result(Result&& other) : ok(other.ok) {
|
||||||
if (!ok)
|
if (!ok) new (storage) E(std::move(*reinterpret_cast<E*>(other.storage)));
|
||||||
new (storage) E(std::move(*reinterpret_cast<E*>(other.storage)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result& operator=(const Result&) = delete;
|
Result& operator=(const Result&) = delete;
|
||||||
|
|
||||||
bool isOk() const noexcept {
|
bool isOk() const noexcept { return ok; }
|
||||||
return ok;
|
const E& error() const { return *reinterpret_cast<const E*>(storage); }
|
||||||
}
|
|
||||||
const E& error() const {
|
|
||||||
return *reinterpret_cast<const E*>(storage);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace nxst
|
} // namespace nxst
|
||||||
|
|||||||
@@ -1,58 +1,88 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <nxst/domain/account.hpp>
|
||||||
|
#include <nxst/infra/fs/filesystem.hpp>
|
||||||
|
#include <nxst/infra/fs/io.hpp>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <switch.h>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <switch.h>
|
|
||||||
|
|
||||||
class Title {
|
class Title {
|
||||||
public:
|
public:
|
||||||
void init(u8 save_data_type, u64 title_id, AccountUid uid, const std::string& name,
|
void init(u8 saveDataType, u64 titleid, AccountUid userID, const std::string& name, const std::string& author);
|
||||||
const std::string& author);
|
~Title() = default;
|
||||||
|
|
||||||
std::string author() const;
|
std::string author(void);
|
||||||
std::pair<std::string, std::string> displayName() const;
|
std::pair<std::string, std::string> displayName(void);
|
||||||
u64 id() const;
|
u64 id(void);
|
||||||
std::string name() const;
|
std::string name(void);
|
||||||
std::string path() const;
|
std::string path(void);
|
||||||
u64 playTimeNanoseconds() const;
|
u64 playTimeNanoseconds(void);
|
||||||
std::string playTime() const;
|
std::string playTime(void);
|
||||||
void playTimeNanoseconds(u64 ns);
|
void playTimeNanoseconds(u64 playTimeNanoseconds);
|
||||||
u32 lastPlayedTimestamp() const;
|
u32 lastPlayedTimestamp(void);
|
||||||
void lastPlayedTimestamp(u32 ts);
|
void lastPlayedTimestamp(u32 lastPlayedTimestamp);
|
||||||
std::string fullPath(size_t index) const;
|
std::string fullPath(size_t index);
|
||||||
void refreshDirectories();
|
void refreshDirectories(void);
|
||||||
u64 saveId() const;
|
u64 saveId();
|
||||||
void saveId(u64 id);
|
void saveId(u64 id);
|
||||||
std::vector<std::string> saves() const;
|
std::vector<std::string> saves(void);
|
||||||
u8 saveDataType() const;
|
u8 saveDataType(void);
|
||||||
AccountUid userId() const;
|
AccountUid userId(void);
|
||||||
std::string userName() const;
|
std::string userName(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u64 m_id{0};
|
u64 mId;
|
||||||
u64 m_save_id{0};
|
u64 mSaveId;
|
||||||
AccountUid m_uid{};
|
AccountUid mUserId;
|
||||||
std::string m_user_name;
|
std::string mUserName;
|
||||||
std::string m_name;
|
std::string mName;
|
||||||
std::string m_safe_name;
|
std::string mSafeName;
|
||||||
std::string m_author;
|
std::string mAuthor;
|
||||||
std::string m_path;
|
std::string mPath;
|
||||||
std::vector<std::string> m_saves;
|
std::vector<std::string> mSaves;
|
||||||
std::vector<std::string> m_full_save_paths;
|
std::vector<std::string> mFullSavePaths;
|
||||||
u8 m_save_data_type{0};
|
u8 mSaveDataType;
|
||||||
std::pair<std::string, std::string> m_display_name;
|
std::pair<std::string, std::string> mDisplayName;
|
||||||
u64 m_play_time_ns{0};
|
u64 mPlayTimeNanoseconds;
|
||||||
u32 m_last_played_ts{0};
|
u32 mLastPlayedTimestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool areTitlesLoaded();
|
|
||||||
void loadTitles();
|
|
||||||
void sortTitles();
|
|
||||||
void rotateSortMode();
|
|
||||||
void getTitle(Title& dst, AccountUid uid, size_t i);
|
void getTitle(Title& dst, AccountUid uid, size_t i);
|
||||||
size_t getTitleCount(AccountUid uid);
|
size_t getTitleCount(AccountUid uid);
|
||||||
|
void loadTitles(void);
|
||||||
|
bool areTitlesLoaded(void);
|
||||||
|
void sortTitles(void);
|
||||||
|
void rotateSortMode(void);
|
||||||
void refreshDirectories(u64 id);
|
void refreshDirectories(u64 id);
|
||||||
std::unordered_map<std::string, std::string> getCompleteTitleList();
|
std::unordered_map<std::string, std::string> getCompleteTitleList(void);
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,51 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <nxst/domain/account.hpp>
|
||||||
|
#include <nxst/domain/common.hpp>
|
||||||
|
#include <nxst/infra/fs/io.hpp>
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
void servicesExit();
|
// debug
|
||||||
Result servicesInit();
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/errno.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
void servicesExit(void);
|
||||||
|
Result servicesInit(void);
|
||||||
|
HidsysNotificationLedPattern blinkLedPattern(u8 times);
|
||||||
void blinkLed(u8 times);
|
void blinkLed(u8 times);
|
||||||
|
|
||||||
namespace string_utils {
|
namespace StringUtils {
|
||||||
bool containsInvalidChar(const std::string& str);
|
|
||||||
std::string format(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
|
||||||
std::string removeForbiddenCharacters(std::string src);
|
|
||||||
std::string UTF16toUTF8(const std::u16string& src);
|
|
||||||
void ltrim(std::string& s);
|
|
||||||
void rtrim(std::string& s);
|
|
||||||
void trim(std::string& s);
|
|
||||||
std::string removeAccents(std::string str);
|
std::string removeAccents(std::string str);
|
||||||
std::string removeNotAscii(std::string str);
|
std::string removeNotAscii(std::string str);
|
||||||
std::u16string UTF8toUTF16(const char* src);
|
std::u16string UTF8toUTF16(const char* src);
|
||||||
std::string elide(const std::string& s, size_t max_chars);
|
std::string elide(const std::string& s, size_t maxChars);
|
||||||
} // namespace string_utils
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +1,55 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <switch.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <switch.h>
|
struct DirectoryEntry {
|
||||||
|
std::string name;
|
||||||
|
bool directory;
|
||||||
|
};
|
||||||
|
|
||||||
class Directory {
|
class Directory {
|
||||||
public:
|
public:
|
||||||
explicit Directory(const std::string& path);
|
Directory(const std::string& root);
|
||||||
|
~Directory() = default;
|
||||||
|
|
||||||
bool good() const {
|
Result error(void);
|
||||||
return m_good;
|
std::string entry(size_t index);
|
||||||
}
|
bool folder(size_t index);
|
||||||
Result error() const {
|
bool good(void);
|
||||||
return m_error;
|
size_t size(void);
|
||||||
}
|
|
||||||
size_t size() const {
|
|
||||||
return m_entries.size();
|
|
||||||
}
|
|
||||||
std::string entry(size_t i) const;
|
|
||||||
bool folder(size_t i) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Entry {
|
std::vector<struct DirectoryEntry> mList;
|
||||||
std::string name;
|
Result mError;
|
||||||
bool is_dir;
|
bool mGood;
|
||||||
};
|
|
||||||
std::vector<Entry> m_entries;
|
|
||||||
Result m_error{0};
|
|
||||||
bool m_good{false};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,36 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <nxst/domain/account.hpp>
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
namespace file_system {
|
namespace FileSystem {
|
||||||
Result mount(FsFileSystem* fs, u64 title_id, AccountUid uid);
|
Result mount(FsFileSystem* fileSystem, u64 titleID, AccountUid userID);
|
||||||
int mount(FsFileSystem fs);
|
int mount(FsFileSystem fs);
|
||||||
void unmount();
|
void unmount(void);
|
||||||
} // namespace file_system
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
namespace nxst {
|
namespace nxst {
|
||||||
@@ -11,21 +10,14 @@ namespace nxst {
|
|||||||
bool valid{false};
|
bool valid{false};
|
||||||
|
|
||||||
FsFileSystemHandle() = default;
|
FsFileSystemHandle() = default;
|
||||||
~FsFileSystemHandle() {
|
~FsFileSystemHandle() { if (valid) fsFsClose(&fs); } // NOLINT(modernize-use-equals-default)
|
||||||
if (valid)
|
|
||||||
fsFsClose(&fs);
|
|
||||||
} // NOLINT(modernize-use-equals-default)
|
|
||||||
|
|
||||||
FsFileSystemHandle(const FsFileSystemHandle&) = delete;
|
FsFileSystemHandle(const FsFileSystemHandle&) = delete;
|
||||||
FsFileSystemHandle& operator=(const FsFileSystemHandle&) = delete;
|
FsFileSystemHandle& operator=(const FsFileSystemHandle&) = delete;
|
||||||
|
|
||||||
FsFileSystem* get() {
|
FsFileSystem* get() { return &fs; }
|
||||||
return &fs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void release() {
|
void release() { valid = false; } // transfer ownership to devfs
|
||||||
valid = false;
|
|
||||||
} // transfer ownership to devfs
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// RAII wrapper for FILE* — auto-fclose on destruction.
|
// RAII wrapper for FILE* — auto-fclose on destruction.
|
||||||
@@ -33,39 +25,13 @@ namespace nxst {
|
|||||||
FILE* ptr{nullptr};
|
FILE* ptr{nullptr};
|
||||||
|
|
||||||
explicit FileHandle(FILE* file) : ptr(file) {}
|
explicit FileHandle(FILE* file) : ptr(file) {}
|
||||||
~FileHandle() {
|
~FileHandle() { if (ptr != nullptr) fclose(ptr); } // NOLINT(modernize-use-equals-default)
|
||||||
if (ptr != nullptr)
|
|
||||||
fclose(ptr);
|
|
||||||
} // NOLINT(modernize-use-equals-default)
|
|
||||||
|
|
||||||
FileHandle(const FileHandle&) = delete;
|
FileHandle(const FileHandle&) = delete;
|
||||||
FileHandle& operator=(const FileHandle&) = delete;
|
FileHandle& operator=(const FileHandle&) = delete;
|
||||||
|
|
||||||
explicit operator bool() const {
|
explicit operator bool() const { return ptr != nullptr; }
|
||||||
return ptr != nullptr;
|
FILE* get() const { return ptr; }
|
||||||
}
|
|
||||||
FILE* get() const {
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// RAII wrapper for AccountProfile — auto-closes on destruction.
|
|
||||||
struct AccountProfileHandle {
|
|
||||||
AccountProfile profile{};
|
|
||||||
bool valid{false};
|
|
||||||
|
|
||||||
AccountProfileHandle() = default;
|
|
||||||
~AccountProfileHandle() {
|
|
||||||
if (valid)
|
|
||||||
accountProfileClose(&profile);
|
|
||||||
} // NOLINT(modernize-use-equals-default)
|
|
||||||
|
|
||||||
AccountProfileHandle(const AccountProfileHandle&) = delete;
|
|
||||||
AccountProfileHandle& operator=(const AccountProfileHandle&) = delete;
|
|
||||||
|
|
||||||
AccountProfile* get() {
|
|
||||||
return &profile;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace nxst
|
} // namespace nxst
|
||||||
|
|||||||
@@ -1,19 +1,51 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <nxst/domain/account.hpp>
|
||||||
|
|
||||||
#include <switch.h>
|
|
||||||
|
|
||||||
#include <nxst/domain/result.hpp>
|
#include <nxst/domain/result.hpp>
|
||||||
|
#include <nxst/infra/fs/directory.hpp>
|
||||||
|
#include <nxst/domain/title.hpp>
|
||||||
|
#include <nxst/domain/util.hpp>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <switch.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define BUFFER_SIZE 0x80000
|
||||||
|
|
||||||
namespace io {
|
namespace io {
|
||||||
nxst::Result<std::string> backup(size_t index, AccountUid uid);
|
nxst::Result<std::string> backup(size_t index, AccountUid uid);
|
||||||
nxst::Result<std::string> restore(size_t index, AccountUid uid, const std::string& title_name);
|
nxst::Result<std::string> restore(size_t index, AccountUid uid, size_t cellIndex, const std::string& nameFromCell);
|
||||||
|
|
||||||
Result copyDirectory(const std::string& src, const std::string& dst);
|
Result copyDirectory(const std::string& srcPath, const std::string& dstPath);
|
||||||
void copyFile(const std::string& src, const std::string& dst);
|
void copyFile(const std::string& srcPath, const std::string& dstPath);
|
||||||
Result createDirectory(const std::string& path);
|
Result createDirectory(const std::string& path);
|
||||||
Result deleteFolderRecursively(const std::string& path);
|
Result deleteFolderRecursively(const std::string& path);
|
||||||
bool directoryExists(const std::string& path);
|
bool directoryExists(const std::string& path);
|
||||||
bool fileExists(const std::string& path);
|
bool fileExists(const std::string& path);
|
||||||
} // namespace io
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,24 +6,13 @@ struct Socket {
|
|||||||
|
|
||||||
Socket() = default;
|
Socket() = default;
|
||||||
explicit Socket(int fd) : fd(fd) {}
|
explicit Socket(int fd) : fd(fd) {}
|
||||||
~Socket() {
|
~Socket() { if (fd >= 0) close(fd); }
|
||||||
if (fd >= 0)
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
Socket(const Socket&) = delete;
|
Socket(const Socket&) = delete;
|
||||||
Socket& operator=(const Socket&) = delete;
|
Socket& operator=(const Socket&) = delete;
|
||||||
Socket(Socket&& o) : fd(o.fd) {
|
Socket(Socket&& o) : fd(o.fd) { o.fd = -1; }
|
||||||
o.fd = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator int() const {
|
operator int() const { return fd; }
|
||||||
return fd;
|
bool valid() const { return fd >= 0; }
|
||||||
}
|
void release() { fd = -1; }
|
||||||
bool valid() const {
|
|
||||||
return fd >= 0;
|
|
||||||
}
|
|
||||||
void release() {
|
|
||||||
fd = -1;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
#pragma once
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
#pragma once
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
// New API — use these going forward.
|
// New API — use these going forward.
|
||||||
namespace nxst::log {
|
namespace nxst::log {
|
||||||
|
|
||||||
@@ -11,4 +14,42 @@ namespace nxst::log {
|
|||||||
void warn (const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
void warn (const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||||
void error(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
void error(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||||
|
|
||||||
|
// No-op: writes are immediate. Kept for source compatibility during migration.
|
||||||
|
inline void flush() {}
|
||||||
|
|
||||||
} // namespace nxst::log
|
} // namespace nxst::log
|
||||||
|
|
||||||
|
// Backward-compat shim — existing Logger::getInstance().log(...) call sites compile
|
||||||
|
// unchanged. Format args are dropped (same behavior as broken original). Migrate
|
||||||
|
// call sites to nxst::log::* in Phase 3.
|
||||||
|
struct Logger {
|
||||||
|
static Logger& getInstance()
|
||||||
|
{
|
||||||
|
static Logger instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clang-tidy naming suppressed: these must match existing call sites during migration.
|
||||||
|
static constexpr const char* INFO = "[INFO]"; // NOLINT(readability-identifier-naming)
|
||||||
|
static constexpr const char* DEBUG = "[DEBUG]"; // NOLINT(readability-identifier-naming)
|
||||||
|
static constexpr const char* ERROR = "[ERROR]"; // NOLINT(readability-identifier-naming)
|
||||||
|
static constexpr const char* WARN = "[WARN]"; // NOLINT(readability-identifier-naming)
|
||||||
|
|
||||||
|
static void flush() { nxst::log::flush(); }
|
||||||
|
|
||||||
|
// Args intentionally dropped — format string still logged for visibility.
|
||||||
|
template <typename... Args>
|
||||||
|
void log(const std::string& level, const std::string& fmt, Args&&... /*args*/)
|
||||||
|
{
|
||||||
|
if (level == ERROR) nxst::log::error("%s", fmt.c_str());
|
||||||
|
else if (level == WARN) nxst::log::warn("%s", fmt.c_str());
|
||||||
|
else if (level == DEBUG) nxst::log::debug("%s", fmt.c_str());
|
||||||
|
else nxst::log::info("%s", fmt.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger() = default;
|
||||||
|
~Logger() = default;
|
||||||
|
|
||||||
|
Logger(const Logger&) = delete; // NOLINT(modernize-use-equals-delete)
|
||||||
|
Logger& operator=(const Logger&) = delete; // NOLINT(modernize-use-equals-delete)
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
#include <nxst/domain/transfer_state.hpp>
|
#include <nxst/domain/transfer_state.hpp>
|
||||||
|
|
||||||
namespace nxst {
|
namespace nxst {
|
||||||
@@ -14,55 +12,27 @@ namespace nxst {
|
|||||||
int startSend(size_t title_index, AccountUid uid);
|
int startSend(size_t title_index, AccountUid uid);
|
||||||
void cancelSend();
|
void cancelSend();
|
||||||
|
|
||||||
bool isSendDone() const {
|
bool isSendDone() const { return sender_state.done.load(); }
|
||||||
return sender_state.done.load();
|
bool isSendCancelled() const { return sender_state.cancelled.load(); }
|
||||||
}
|
bool isSendConnectionFailed() const { return sender_state.connection_failed.load(); }
|
||||||
bool isSendCancelled() const {
|
bool isSendProgressKnown() const { return sender_state.bytes_total.load() > 0; }
|
||||||
return sender_state.cancelled.load();
|
bool isSendWorkersIdle() const { return !sender_active.load(); }
|
||||||
}
|
double sendProgress() const { return sender_state.progress(); }
|
||||||
bool isSendConnectionFailed() const {
|
std::string sendStatusText() const { return sender_state.getStatus(); }
|
||||||
return sender_state.connection_failed.load();
|
std::string sendFailReason() const { return sender_state.fail_reason; }
|
||||||
}
|
|
||||||
bool isSendProgressKnown() const {
|
|
||||||
return sender_state.bytes_total.load() > 0;
|
|
||||||
}
|
|
||||||
bool isSendWorkersIdle() const {
|
|
||||||
return !sender_active.load();
|
|
||||||
}
|
|
||||||
double sendProgress() const {
|
|
||||||
return sender_state.progress();
|
|
||||||
}
|
|
||||||
std::string sendStatusText() const {
|
|
||||||
return sender_state.getStatus();
|
|
||||||
}
|
|
||||||
std::string sendFailReason() const {
|
|
||||||
return sender_state.fail_reason;
|
|
||||||
}
|
|
||||||
|
|
||||||
int startReceive(size_t title_index, AccountUid uid, std::string title_name);
|
int startReceive(size_t title_index, AccountUid uid, std::string title_name);
|
||||||
void cancelReceive();
|
void cancelReceive();
|
||||||
|
|
||||||
bool isReceiveDone() const {
|
bool isReceiveDone() const { return receiver_state.done.load(); }
|
||||||
return receiver_state.done.load();
|
bool isReceiveCancelled() const { return receiver_state.cancelled.load(); }
|
||||||
}
|
|
||||||
bool isReceiveCancelled() const {
|
|
||||||
return receiver_state.cancelled.load();
|
|
||||||
}
|
|
||||||
bool isReceiveWorkersIdle() const {
|
bool isReceiveWorkersIdle() const {
|
||||||
return !receiver_accept_active.load() && !receiver_broadcast_active.load();
|
return !receiver_accept_active.load() && !receiver_broadcast_active.load();
|
||||||
}
|
}
|
||||||
double receiveProgress() const {
|
double receiveProgress() const { return receiver_state.progress(); }
|
||||||
return receiver_state.progress();
|
std::string receiveStatusText() const { return receiver_state.getStatus(); }
|
||||||
}
|
bool restoreSucceeded() const { return restore_ok; }
|
||||||
std::string receiveStatusText() const {
|
std::string restoreError() const { return restore_error; }
|
||||||
return receiver_state.getStatus();
|
|
||||||
}
|
|
||||||
bool restoreSucceeded() const {
|
|
||||||
return restore_ok;
|
|
||||||
}
|
|
||||||
std::string restoreError() const {
|
|
||||||
return restore_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Sender
|
// Sender
|
||||||
@@ -88,21 +58,14 @@ namespace nxst {
|
|||||||
std::string restore_error;
|
std::string restore_error;
|
||||||
|
|
||||||
// Sender thread
|
// Sender thread
|
||||||
struct SenderArgs {
|
struct SenderArgs { TransferService* svc; size_t title_index; AccountUid uid; };
|
||||||
TransferService* svc;
|
|
||||||
size_t title_index;
|
|
||||||
AccountUid uid;
|
|
||||||
};
|
|
||||||
static void* senderEntry(void* arg);
|
static void* senderEntry(void* arg);
|
||||||
void runSender(size_t title_index, AccountUid uid);
|
void runSender(size_t title_index, AccountUid uid);
|
||||||
void failSend(const std::string& reason);
|
void failSend(const std::string& reason);
|
||||||
int findServer(char* out_ip);
|
int findServer(char* out_ip);
|
||||||
|
|
||||||
// Receiver threads
|
// Receiver threads
|
||||||
struct AcceptArgs {
|
struct AcceptArgs { TransferService* svc; int server_fd; };
|
||||||
TransferService* svc;
|
|
||||||
int server_fd;
|
|
||||||
};
|
|
||||||
static void* broadcastEntry(void* arg);
|
static void* broadcastEntry(void* arg);
|
||||||
static void* acceptEntry(void* arg);
|
static void* acceptEntry(void* arg);
|
||||||
void runBroadcast();
|
void runBroadcast();
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <pu/Plutonium>
|
||||||
|
#include <nxst/ui/theme.hpp>
|
||||||
|
|
||||||
|
namespace ui {
|
||||||
|
|
||||||
|
class Card {
|
||||||
|
public:
|
||||||
|
pu::ui::elm::Rectangle::Ref bg;
|
||||||
|
|
||||||
|
Card(pu::ui::Layout* parent, int x, int y, int w, int h,
|
||||||
|
pu::ui::Color color = theme::color::BgSurface,
|
||||||
|
int rad = theme::radius::lg) {
|
||||||
|
bg = pu::ui::elm::Rectangle::New(x, y, w, h, color, rad);
|
||||||
|
parent->Add(bg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <nxst/ui/theme.hpp>
|
||||||
|
|
||||||
|
#define COLOR(hex) pu::ui::Color::FromHex(hex)
|
||||||
|
#define BACKGROUND_COLOR theme::color::BgBase
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <pu/Plutonium>
|
#include <pu/Plutonium>
|
||||||
|
|
||||||
#include <nxst/domain/account.hpp>
|
|
||||||
#include <nxst/ui/theme.hpp>
|
#include <nxst/ui/theme.hpp>
|
||||||
|
#include <nxst/ui/ui_context.hpp>
|
||||||
|
#include <nxst/domain/account.hpp>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
@@ -20,8 +20,10 @@ namespace ui {
|
|||||||
HeaderBar(pu::ui::Layout* parent, const std::string& sub = "Save Transfer") {
|
HeaderBar(pu::ui::Layout* parent, const std::string& sub = "Save Transfer") {
|
||||||
using namespace theme;
|
using namespace theme;
|
||||||
|
|
||||||
bg = pu::ui::elm::Rectangle::New(0, 0, layout::ScreenW, layout::HeaderH, color::BgSurface);
|
bg = pu::ui::elm::Rectangle::New(
|
||||||
divider = pu::ui::elm::Rectangle::New(0, layout::HeaderH - 1, layout::ScreenW, 1, color::Divider);
|
0, 0, layout::ScreenW, layout::HeaderH, color::BgSurface);
|
||||||
|
divider = pu::ui::elm::Rectangle::New(
|
||||||
|
0, layout::HeaderH - 1, layout::ScreenW, 1, color::Divider);
|
||||||
|
|
||||||
appName = pu::ui::elm::TextBlock::New(space::lg, 8, "NXST");
|
appName = pu::ui::elm::TextBlock::New(space::lg, 8, "NXST");
|
||||||
appName->SetFont(type::font(type::Title));
|
appName->SetFont(type::font(type::Title));
|
||||||
@@ -33,7 +35,9 @@ namespace ui {
|
|||||||
|
|
||||||
const int chipW = 280;
|
const int chipW = 280;
|
||||||
const int chipX = layout::ScreenW - chipW - space::lg;
|
const int chipX = layout::ScreenW - chipW - space::lg;
|
||||||
chipBg = pu::ui::elm::Rectangle::New(chipX, 16, chipW, 40, color::BgSurface2, radius::pill);
|
chipBg = pu::ui::elm::Rectangle::New(
|
||||||
|
chipX, 16, chipW, 40,
|
||||||
|
color::BgSurface2, radius::pill);
|
||||||
chipBg->SetVisible(false);
|
chipBg->SetVisible(false);
|
||||||
|
|
||||||
avatar = pu::ui::elm::Image::New(chipX + 4, 20, "");
|
avatar = pu::ui::elm::Image::New(chipX + 4, 20, "");
|
||||||
@@ -61,7 +65,7 @@ namespace ui {
|
|||||||
userName->SetVisible(show);
|
userName->SetVisible(show);
|
||||||
if (show) {
|
if (show) {
|
||||||
userName->SetText(name);
|
userName->SetText(name);
|
||||||
std::string path = account::iconPath(*uid);
|
std::string path = Account::iconPath(*uid);
|
||||||
if (!path.empty()) {
|
if (!path.empty()) {
|
||||||
avatar->SetImage(path);
|
avatar->SetImage(path);
|
||||||
avatar->SetWidth(32);
|
avatar->SetWidth(32);
|
||||||
@@ -79,4 +83,4 @@ namespace ui {
|
|||||||
subtitle->SetText(text);
|
subtitle->SetText(text);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace ui
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <pu/Plutonium>
|
#include <pu/Plutonium>
|
||||||
|
|
||||||
#include <nxst/ui/theme.hpp>
|
#include <nxst/ui/theme.hpp>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
@@ -23,18 +21,19 @@ namespace ui {
|
|||||||
public:
|
public:
|
||||||
HintBar(pu::ui::Layout* p) : parent(p) {
|
HintBar(pu::ui::Layout* p) : parent(p) {
|
||||||
using namespace theme;
|
using namespace theme;
|
||||||
bg = pu::ui::elm::Rectangle::New(0, layout::ScreenH - layout::HintH, layout::ScreenW,
|
bg = pu::ui::elm::Rectangle::New(
|
||||||
layout::HintH, color::BgSurface);
|
0, layout::ScreenH - layout::HintH,
|
||||||
divider = pu::ui::elm::Rectangle::New(0, layout::ScreenH - layout::HintH, layout::ScreenW, 1,
|
layout::ScreenW, layout::HintH, color::BgSurface);
|
||||||
color::Divider);
|
divider = pu::ui::elm::Rectangle::New(
|
||||||
|
0, layout::ScreenH - layout::HintH,
|
||||||
|
layout::ScreenW, 1, color::Divider);
|
||||||
parent->Add(bg);
|
parent->Add(bg);
|
||||||
parent->Add(divider);
|
parent->Add(divider);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHints(const std::vector<Hint>& hints) {
|
void SetHints(const std::vector<Hint>& hints) {
|
||||||
using namespace theme;
|
using namespace theme;
|
||||||
for (auto& l : labels)
|
for (auto& l : labels) l->SetVisible(false);
|
||||||
l->SetVisible(false);
|
|
||||||
labels.clear();
|
labels.clear();
|
||||||
|
|
||||||
int x = layout::ScreenW - space::lg;
|
int x = layout::ScreenW - space::lg;
|
||||||
@@ -53,4 +52,4 @@ namespace ui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace ui
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <pu/Plutonium>
|
#include <pu/Plutonium>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace theme {
|
namespace theme {
|
||||||
using pu::ui::Color;
|
using pu::ui::Color;
|
||||||
@@ -27,7 +26,7 @@ namespace theme {
|
|||||||
|
|
||||||
constexpr Color Divider{0x2A, 0x33, 0x42, 0xFF};
|
constexpr Color Divider{0x2A, 0x33, 0x42, 0xFF};
|
||||||
constexpr Color FocusRing{0xE2, 0x4B, 0x55, 0xFF};
|
constexpr Color FocusRing{0xE2, 0x4B, 0x55, 0xFF};
|
||||||
} // namespace color
|
}
|
||||||
|
|
||||||
namespace space {
|
namespace space {
|
||||||
constexpr int xs = 4;
|
constexpr int xs = 4;
|
||||||
@@ -36,14 +35,14 @@ namespace theme {
|
|||||||
constexpr int lg = 24;
|
constexpr int lg = 24;
|
||||||
constexpr int xl = 32;
|
constexpr int xl = 32;
|
||||||
constexpr int xxl = 48;
|
constexpr int xxl = 48;
|
||||||
} // namespace space
|
}
|
||||||
|
|
||||||
namespace radius {
|
namespace radius {
|
||||||
constexpr int sm = 6;
|
constexpr int sm = 6;
|
||||||
constexpr int md = 12;
|
constexpr int md = 12;
|
||||||
constexpr int lg = 20;
|
constexpr int lg = 20;
|
||||||
constexpr int pill = 9999;
|
constexpr int pill = 9999;
|
||||||
} // namespace radius
|
}
|
||||||
|
|
||||||
namespace type {
|
namespace type {
|
||||||
constexpr int Display = 38;
|
constexpr int Display = 38;
|
||||||
@@ -55,7 +54,7 @@ namespace theme {
|
|||||||
inline std::string font(int size) {
|
inline std::string font(int size) {
|
||||||
return "DefaultFont@" + std::to_string(size);
|
return "DefaultFont@" + std::to_string(size);
|
||||||
}
|
}
|
||||||
} // namespace type
|
}
|
||||||
|
|
||||||
namespace layout {
|
namespace layout {
|
||||||
constexpr int ScreenW = 1280;
|
constexpr int ScreenW = 1280;
|
||||||
@@ -64,16 +63,16 @@ namespace theme {
|
|||||||
constexpr int HintH = 56;
|
constexpr int HintH = 56;
|
||||||
constexpr int ContentTop = HeaderH;
|
constexpr int ContentTop = HeaderH;
|
||||||
constexpr int ContentH = ScreenH - HeaderH - HintH;
|
constexpr int ContentH = ScreenH - HeaderH - HintH;
|
||||||
} // namespace layout
|
}
|
||||||
|
|
||||||
namespace motion {
|
namespace motion {
|
||||||
constexpr int FadeFrames = 20;
|
constexpr int FadeFrames = 20;
|
||||||
constexpr int SlideFrames = 14;
|
constexpr int SlideFrames = 14;
|
||||||
constexpr int SpinnerFrames = 72;
|
constexpr int SpinnerFrames = 72;
|
||||||
} // namespace motion
|
}
|
||||||
|
|
||||||
namespace font {
|
namespace font {
|
||||||
constexpr const char* Default = "Inter";
|
constexpr const char* Default = "Inter";
|
||||||
constexpr const char* Medium = "InterMedium";
|
constexpr const char* Medium = "InterMedium";
|
||||||
} // namespace font
|
}
|
||||||
} // namespace theme
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <memory>
|
#include <pu/Plutonium>
|
||||||
|
#include <nxst/ui/const.h>
|
||||||
|
#include <nxst/domain/title.hpp>
|
||||||
|
#include <nxst/domain/account.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
#include <pu/Plutonium>
|
|
||||||
|
|
||||||
#include <nxst/domain/account.hpp>
|
|
||||||
#include <nxst/domain/title.hpp>
|
|
||||||
#include <nxst/ui/header_bar.hpp>
|
#include <nxst/ui/header_bar.hpp>
|
||||||
#include <nxst/ui/hint_bar.hpp>
|
#include <nxst/ui/hint_bar.hpp>
|
||||||
|
|
||||||
@@ -17,6 +16,7 @@ namespace ui {
|
|||||||
|
|
||||||
class TitlesLayout : public pu::ui::Layout {
|
class TitlesLayout : public pu::ui::Layout {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
pu::ui::elm::Menu::Ref titlesMenu;
|
pu::ui::elm::Menu::Ref titlesMenu;
|
||||||
std::unordered_map<AccountUid, std::vector<pu::ui::elm::MenuItem::Ref>> menuCache;
|
std::unordered_map<AccountUid, std::vector<pu::ui::elm::MenuItem::Ref>> menuCache;
|
||||||
bool m_inputLocked = false;
|
bool m_inputLocked = false;
|
||||||
@@ -46,17 +46,14 @@ namespace ui {
|
|||||||
void runReceive(int index, Title& title);
|
void runReceive(int index, Title& title);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TitlesLayout();
|
TitlesLayout();
|
||||||
void InitTitles(AccountUid uid);
|
void InitTitles(AccountUid uid);
|
||||||
void LockInput() {
|
void LockInput() { m_inputLocked = true; }
|
||||||
m_inputLocked = true;
|
void UnlockInput() { m_inputLocked = false; }
|
||||||
}
|
|
||||||
void UnlockInput() {
|
|
||||||
m_inputLocked = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint Pos);
|
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint Pos);
|
||||||
|
|
||||||
PU_SMART_CTOR(TitlesLayout)
|
PU_SMART_CTOR(TitlesLayout)
|
||||||
};
|
};
|
||||||
} // namespace ui
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <pu/Plutonium>
|
#include <pu/Plutonium>
|
||||||
|
|
||||||
#include <nxst/domain/util.hpp>
|
|
||||||
#include <nxst/ui/theme.hpp>
|
#include <nxst/ui/theme.hpp>
|
||||||
|
#include <nxst/domain/util.hpp>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
@@ -23,16 +22,22 @@ namespace ui {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
TransferOverlay(const std::string &title)
|
TransferOverlay(const std::string &title)
|
||||||
: Overlay(0, 0, theme::layout::ScreenW, theme::layout::ScreenH, theme::color::Scrim) {
|
: Overlay(0, 0, theme::layout::ScreenW, theme::layout::ScreenH, theme::color::Scrim)
|
||||||
|
{
|
||||||
using namespace theme;
|
using namespace theme;
|
||||||
|
|
||||||
card = pu::ui::elm::Rectangle::New(CardX, CardY, CardW, CardH, color::BgSurface, radius::lg);
|
card = pu::ui::elm::Rectangle::New(
|
||||||
|
CardX, CardY, CardW, CardH, color::BgSurface, radius::lg);
|
||||||
|
|
||||||
titleText = pu::ui::elm::TextBlock::New(CardX + space::lg, CardY + space::lg, title);
|
titleText = pu::ui::elm::TextBlock::New(
|
||||||
|
CardX + space::lg, CardY + space::lg, title);
|
||||||
titleText->SetFont(type::font(type::Title));
|
titleText->SetFont(type::font(type::Title));
|
||||||
titleText->SetColor(color::TextPrimary);
|
titleText->SetColor(color::TextPrimary);
|
||||||
|
|
||||||
statusText = pu::ui::elm::TextBlock::New(CardX + space::lg, CardY + space::lg + 56, "");
|
statusText = pu::ui::elm::TextBlock::New(
|
||||||
|
CardX + space::lg,
|
||||||
|
CardY + space::lg + 56,
|
||||||
|
"");
|
||||||
statusText->SetFont(type::font(type::Body));
|
statusText->SetFont(type::font(type::Body));
|
||||||
statusText->SetColor(color::TextSecondary);
|
statusText->SetColor(color::TextSecondary);
|
||||||
|
|
||||||
@@ -40,19 +45,24 @@ namespace ui {
|
|||||||
int barY = CardY + space::lg + 56 + 56;
|
int barY = CardY + space::lg + 56 + 56;
|
||||||
int barW = CardW - 2 * space::lg;
|
int barW = CardW - 2 * space::lg;
|
||||||
|
|
||||||
progressTrack = pu::ui::elm::Rectangle::New(barX, barY, barW, 8, color::Divider, radius::sm);
|
progressTrack = pu::ui::elm::Rectangle::New(
|
||||||
|
barX, barY, barW, 8, color::Divider, radius::sm);
|
||||||
|
|
||||||
progressBar = pu::ui::elm::ProgressBar::New(barX, barY, barW, 8, 100.0);
|
progressBar = pu::ui::elm::ProgressBar::New(
|
||||||
|
barX, barY, barW, 8, 100.0);
|
||||||
progressBar->SetProgressColor(color::Primary);
|
progressBar->SetProgressColor(color::Primary);
|
||||||
progressBar->SetBackgroundColor(color::Divider);
|
progressBar->SetBackgroundColor(color::Divider);
|
||||||
|
|
||||||
indeterminateText = pu::ui::elm::TextBlock::New(barX, barY - 4, "Preparing transfer...");
|
indeterminateText = pu::ui::elm::TextBlock::New(
|
||||||
|
barX, barY - 4, "Preparing transfer...");
|
||||||
indeterminateText->SetFont(type::font(type::Body));
|
indeterminateText->SetFont(type::font(type::Body));
|
||||||
indeterminateText->SetColor(color::TextMuted);
|
indeterminateText->SetColor(color::TextMuted);
|
||||||
indeterminateText->SetVisible(false);
|
indeterminateText->SetVisible(false);
|
||||||
|
|
||||||
hintText =
|
hintText = pu::ui::elm::TextBlock::New(
|
||||||
pu::ui::elm::TextBlock::New(CardX + space::lg, CardY + CardH - space::lg - 18, "B to cancel");
|
CardX + space::lg,
|
||||||
|
CardY + CardH - space::lg - 18,
|
||||||
|
"B to cancel");
|
||||||
hintText->SetFont(type::font(type::Caption));
|
hintText->SetFont(type::font(type::Caption));
|
||||||
hintText->SetColor(color::TextMuted);
|
hintText->SetColor(color::TextMuted);
|
||||||
|
|
||||||
@@ -67,7 +77,7 @@ namespace ui {
|
|||||||
PU_SMART_CTOR(TransferOverlay)
|
PU_SMART_CTOR(TransferOverlay)
|
||||||
|
|
||||||
void SetStatus(const std::string &status) {
|
void SetStatus(const std::string &status) {
|
||||||
statusText->SetText(string_utils::elide(status, 56));
|
statusText->SetText(StringUtils::elide(status, 56));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetProgress(double val) {
|
void SetProgress(double val) {
|
||||||
@@ -81,4 +91,4 @@ namespace ui {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ui
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
#include <switch.h>
|
||||||
|
#include <nxst/domain/account.hpp>
|
||||||
|
|
||||||
|
namespace ui {
|
||||||
|
struct UiContext {
|
||||||
|
std::optional<AccountUid> selectedUser;
|
||||||
|
std::string selectedUserName;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
#include <memory>
|
|
||||||
|
|
||||||
#include <pu/Plutonium>
|
#include <pu/Plutonium>
|
||||||
|
#include <nxst/ui/const.h>
|
||||||
#include <nxst/ui/header_bar.hpp>
|
#include <nxst/ui/header_bar.hpp>
|
||||||
#include <nxst/ui/hint_bar.hpp>
|
#include <nxst/ui/hint_bar.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
class UsersLayout : public pu::ui::Layout {
|
class UsersLayout : public pu::ui::Layout {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
pu::ui::elm::Menu::Ref usersMenu;
|
pu::ui::elm::Menu::Ref usersMenu;
|
||||||
pu::ui::elm::Rectangle::Ref loadingBg;
|
pu::ui::elm::Rectangle::Ref loadingBg;
|
||||||
pu::ui::elm::TextBlock::Ref loadingText;
|
pu::ui::elm::TextBlock::Ref loadingText;
|
||||||
@@ -16,6 +16,7 @@ namespace ui {
|
|||||||
std::unique_ptr<HintBar> hints;
|
std::unique_ptr<HintBar> hints;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
UsersLayout();
|
UsersLayout();
|
||||||
|
|
||||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint Pos);
|
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint Pos);
|
||||||
@@ -23,5 +24,6 @@ namespace ui {
|
|||||||
int32_t GetCurrentIndex();
|
int32_t GetCurrentIndex();
|
||||||
|
|
||||||
PU_SMART_CTOR(UsersLayout)
|
PU_SMART_CTOR(UsersLayout)
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace ui
|
}
|
||||||
|
|||||||
Submodule
+1
Submodule lib added at b56564b70d
+8
-10
@@ -1,11 +1,9 @@
|
|||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <nxst/app/main_application.hpp>
|
#include <nxst/app/main_application.hpp>
|
||||||
#include <nxst/domain/util.hpp>
|
#include <nxst/domain/util.hpp>
|
||||||
|
#include <nxst/app/main.hpp>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui { extern MainApplication* mainApp; }
|
||||||
extern MainApplication* mainApp;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int nxlink_sock = -1;
|
static int nxlink_sock = -1;
|
||||||
|
|
||||||
@@ -27,9 +25,9 @@ extern "C" void userAppExit() {
|
|||||||
if (ui::mainApp) {
|
if (ui::mainApp) {
|
||||||
ui::mainApp->transfer.cancelReceive();
|
ui::mainApp->transfer.cancelReceive();
|
||||||
ui::mainApp->transfer.cancelSend();
|
ui::mainApp->transfer.cancelSend();
|
||||||
for (int i = 0; i < 150 && (!ui::mainApp->transfer.isReceiveWorkersIdle() ||
|
for (int i = 0; i < 150 &&
|
||||||
!ui::mainApp->transfer.isSendWorkersIdle());
|
(!ui::mainApp->transfer.isReceiveWorkersIdle() ||
|
||||||
i++) {
|
!ui::mainApp->transfer.isSendWorkersIdle()); i++) {
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,8 +57,8 @@ int main() {
|
|||||||
|
|
||||||
// First create our renderer, where one can customize SDL or other stuff's
|
// First create our renderer, where one can customize SDL or other stuff's
|
||||||
// initialization.
|
// initialization.
|
||||||
auto renderer_opts =
|
auto renderer_opts = pu::ui::render::RendererInitOptions(
|
||||||
pu::ui::render::RendererInitOptions(SDL_INIT_EVERYTHING, pu::ui::render::RendererHardwareFlags);
|
SDL_INIT_EVERYTHING, pu::ui::render::RendererHardwareFlags);
|
||||||
renderer_opts.UseImage(pu::ui::render::IMGAllFlags);
|
renderer_opts.UseImage(pu::ui::render::IMGAllFlags);
|
||||||
renderer_opts.UseAudio(pu::ui::render::MixerAllFlags);
|
renderer_opts.UseAudio(pu::ui::render::MixerAllFlags);
|
||||||
renderer_opts.UseTTF();
|
renderer_opts.UseTTF();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
#include <string>
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
#include <switch/services/hid.h>
|
||||||
|
#include <vector>
|
||||||
#include <nxst/app/main_application.hpp>
|
#include <nxst/app/main_application.hpp>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
@@ -9,12 +11,11 @@ namespace ui {
|
|||||||
mainApp = this;
|
mainApp = this;
|
||||||
this->users_layout = UsersLayout::New();
|
this->users_layout = UsersLayout::New();
|
||||||
this->titles_layout = TitlesLayout::New();
|
this->titles_layout = TitlesLayout::New();
|
||||||
this->users_layout->SetOnInput(std::bind(&UsersLayout::onInput, this->users_layout,
|
this->users_layout->SetOnInput(
|
||||||
std::placeholders::_1, std::placeholders::_2,
|
std::bind(&UsersLayout::onInput, this->users_layout, std::placeholders::_1, std::placeholders::_2,
|
||||||
std::placeholders::_3, std::placeholders::_4));
|
std::placeholders::_3, std::placeholders::_4));
|
||||||
this->titles_layout->SetOnInput(std::bind(&TitlesLayout::onInput, this->titles_layout,
|
this->titles_layout->SetOnInput(std::bind(&TitlesLayout::onInput, this->titles_layout, std::placeholders::_1, std::placeholders::_2,
|
||||||
std::placeholders::_1, std::placeholders::_2,
|
|
||||||
std::placeholders::_3, std::placeholders::_4));
|
std::placeholders::_3, std::placeholders::_4));
|
||||||
this->LoadLayout(this->users_layout);
|
this->LoadLayout(this->users_layout);
|
||||||
}
|
}
|
||||||
} // namespace ui
|
}
|
||||||
+97
-51
@@ -1,95 +1,141 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
#include <cstdio>
|
* This file is part of Checkpoint
|
||||||
#include <cstring>
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
#include <map>
|
*
|
||||||
#include <sys/stat.h>
|
* This program is free software: you can redistribute it and/or modify
|
||||||
#include <vector>
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <nxst/domain/account.hpp>
|
#include <nxst/domain/account.hpp>
|
||||||
#include <nxst/infra/fs/handles.hpp>
|
#include <sys/stat.h>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
static std::map<AccountUid, User> s_users;
|
static std::map<AccountUid, User> mUsers;
|
||||||
|
|
||||||
Result account::init() {
|
Result Account::init(void)
|
||||||
|
{
|
||||||
Result res = accountInitialize(AccountServiceType_Application);
|
Result res = accountInitialize(AccountServiceType_Application);
|
||||||
if (R_FAILED(res))
|
if (R_FAILED(res)) return res;
|
||||||
return res;
|
|
||||||
|
|
||||||
AccountUid uids[8];
|
AccountUid uids[8];
|
||||||
s32 count = 0;
|
s32 count = 0;
|
||||||
accountListAllUsers(uids, 8, &count);
|
accountListAllUsers(uids, 8, &count);
|
||||||
for (s32 i = 0; i < count; ++i) {
|
for (s32 i = 0; i < count; i++) {
|
||||||
username(uids[i]); // populate cache
|
Account::username(uids[i]); // populates mUsers as side effect
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void account::exit() {
|
void Account::exit(void)
|
||||||
|
{
|
||||||
accountExit();
|
accountExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<AccountUid> account::ids() {
|
std::vector<AccountUid> Account::ids(void)
|
||||||
std::vector<AccountUid> result;
|
{
|
||||||
result.reserve(s_users.size());
|
std::vector<AccountUid> v;
|
||||||
for (const auto& pair : s_users) {
|
for (auto& value : mUsers) {
|
||||||
result.push_back(pair.second.id);
|
v.push_back(value.second.id);
|
||||||
}
|
}
|
||||||
return result;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static User fetchUser(AccountUid id) {
|
static User getUser(AccountUid id)
|
||||||
|
{
|
||||||
User user{id, ""};
|
User user{id, ""};
|
||||||
nxst::AccountProfileHandle profile;
|
AccountProfile profile;
|
||||||
AccountProfileBase base{};
|
AccountProfileBase profilebase;
|
||||||
|
memset(&profilebase, 0, sizeof(profilebase));
|
||||||
|
|
||||||
if (R_SUCCEEDED(accountGetProfile(profile.get(), id))) {
|
if (R_SUCCEEDED(accountGetProfile(&profile, id))) {
|
||||||
profile.valid = true;
|
if (R_SUCCEEDED(accountProfileGet(&profile, NULL, &profilebase))) {
|
||||||
if (R_SUCCEEDED(accountProfileGet(profile.get(), nullptr, &base))) {
|
user.name = std::string(profilebase.nickname);
|
||||||
user.name = std::string(base.nickname);
|
|
||||||
}
|
}
|
||||||
|
accountProfileClose(&profile);
|
||||||
}
|
}
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string account::username(AccountUid id) {
|
std::string Account::username(AccountUid id)
|
||||||
auto it = s_users.find(id);
|
{
|
||||||
if (it == s_users.end()) {
|
std::map<AccountUid, User>::const_iterator got = mUsers.find(id);
|
||||||
User user = fetchUser(id);
|
if (got == mUsers.end()) {
|
||||||
s_users.emplace(id, user);
|
User user = getUser(id);
|
||||||
|
mUsers.insert({id, user});
|
||||||
return user.name;
|
return user.name;
|
||||||
}
|
}
|
||||||
return it->second.name;
|
|
||||||
|
return got->second.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string account::iconPath(AccountUid id) {
|
std::string Account::iconPath(AccountUid id)
|
||||||
|
{
|
||||||
char path[128];
|
char path[128];
|
||||||
snprintf(path, sizeof(path), "sdmc:/switch/NXST/cache/%016lX%016lX.jpg", id.uid[0], id.uid[1]);
|
snprintf(path, sizeof(path), "sdmc:/switch/NXST/cache/%016lX%016lX.jpg",
|
||||||
|
id.uid[0], id.uid[1]);
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(path, &st) == 0 && st.st_size > 0)
|
if (stat(path, &st) == 0 && st.st_size > 0) return std::string(path);
|
||||||
return std::string(path);
|
|
||||||
|
|
||||||
mkdir("sdmc:/switch", 0755);
|
mkdir("sdmc:/switch", 0755);
|
||||||
mkdir("sdmc:/switch/NXST", 0755);
|
mkdir("sdmc:/switch/NXST", 0755);
|
||||||
mkdir("sdmc:/switch/NXST/cache", 0755);
|
mkdir("sdmc:/switch/NXST/cache", 0755);
|
||||||
|
|
||||||
nxst::AccountProfileHandle profile;
|
AccountProfile profile;
|
||||||
if (R_FAILED(accountGetProfile(profile.get(), id)))
|
if (R_FAILED(accountGetProfile(&profile, id))) return "";
|
||||||
return "";
|
|
||||||
profile.valid = true;
|
|
||||||
|
|
||||||
u32 img_size = 0;
|
u32 imgSize = 0;
|
||||||
if (R_FAILED(accountProfileGetImageSize(profile.get(), &img_size)) || img_size == 0)
|
if (R_FAILED(accountProfileGetImageSize(&profile, &imgSize)) || imgSize == 0) {
|
||||||
|
accountProfileClose(&profile);
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<u8> buf(img_size);
|
std::vector<u8> buf(imgSize);
|
||||||
u32 out_size = 0;
|
u32 outSize = 0;
|
||||||
if (R_FAILED(accountProfileLoadImage(profile.get(), buf.data(), img_size, &out_size)) || out_size == 0)
|
Result r = accountProfileLoadImage(&profile, buf.data(), imgSize, &outSize);
|
||||||
return "";
|
accountProfileClose(&profile);
|
||||||
|
if (R_FAILED(r) || outSize == 0) return "";
|
||||||
|
|
||||||
nxst::FileHandle f(fopen(path, "wb"));
|
FILE* f = fopen(path, "wb");
|
||||||
if (!f)
|
if (!f) return "";
|
||||||
return "";
|
fwrite(buf.data(), 1, outSize, f);
|
||||||
fwrite(buf.data(), 1, out_size, f.get());
|
fclose(f);
|
||||||
return std::string(path);
|
return std::string(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AccountUid Account::selectAccount(void)
|
||||||
|
{
|
||||||
|
LibAppletArgs args;
|
||||||
|
libappletArgsCreate(&args, 0x10000);
|
||||||
|
u8 st_in[0xA0] = {0};
|
||||||
|
u8 st_out[0x18] = {0};
|
||||||
|
size_t repsz;
|
||||||
|
|
||||||
|
Result res = libappletLaunch(AppletId_LibraryAppletPlayerSelect, &args, st_in, 0xA0, st_out, 0x18, &repsz);
|
||||||
|
if (R_SUCCEEDED(res)) {
|
||||||
|
u64 lres = *(u64*)st_out;
|
||||||
|
AccountUid uid = *(AccountUid*)&st_out[8];
|
||||||
|
if (lres == 0)
|
||||||
|
return uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return AccountUid{};
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <nxst/domain/common.hpp>
|
||||||
|
|
||||||
|
std::string DateTime::timeStr(void)
|
||||||
|
{
|
||||||
|
time_t unixTime;
|
||||||
|
struct tm timeStruct;
|
||||||
|
time(&unixTime);
|
||||||
|
localtime_r(&unixTime, &timeStruct);
|
||||||
|
return StringUtils::format("%02i:%02i:%02i", timeStruct.tm_hour, timeStruct.tm_min, timeStruct.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DateTime::dateTimeStr(void)
|
||||||
|
{
|
||||||
|
time_t unixTime;
|
||||||
|
struct tm timeStruct;
|
||||||
|
time(&unixTime);
|
||||||
|
localtime_r(&unixTime, &timeStruct);
|
||||||
|
return StringUtils::format("%04i%02i%02i-%02i%02i%02i", timeStruct.tm_year + 1900, timeStruct.tm_mon + 1, timeStruct.tm_mday, timeStruct.tm_hour,
|
||||||
|
timeStruct.tm_min, timeStruct.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DateTime::logDateTime(void)
|
||||||
|
{
|
||||||
|
time_t unixTime;
|
||||||
|
struct tm timeStruct;
|
||||||
|
time(&unixTime);
|
||||||
|
localtime_r(&unixTime, &timeStruct);
|
||||||
|
return StringUtils::format("%04i-%02i-%02i %02i:%02i:%02i", timeStruct.tm_year + 1900, timeStruct.tm_mon + 1, timeStruct.tm_mday,
|
||||||
|
timeStruct.tm_hour, timeStruct.tm_min, timeStruct.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringUtils::UTF16toUTF8(const std::u16string& src)
|
||||||
|
{
|
||||||
|
static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
|
||||||
|
std::string dst = convert.to_bytes(src);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringUtils::removeForbiddenCharacters(std::string src)
|
||||||
|
{
|
||||||
|
static const std::string illegalChars = ".,!\\/:?*\"<>|";
|
||||||
|
for (size_t i = 0, sz = src.length(); i < sz; i++) {
|
||||||
|
if (illegalChars.find(src[i]) != std::string::npos) {
|
||||||
|
src[i] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
for (i = src.length() - 1; i > 0 && src[i] == ' '; i--)
|
||||||
|
;
|
||||||
|
src.erase(i + 1, src.length() - i);
|
||||||
|
|
||||||
|
return src;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StringUtils::format(const std::string fmt_str, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char* fp = NULL;
|
||||||
|
va_start(ap, fmt_str);
|
||||||
|
vasprintf(&fp, fmt_str.c_str(), ap);
|
||||||
|
va_end(ap);
|
||||||
|
std::unique_ptr<char[]> formatted(fp);
|
||||||
|
return std::string(formatted.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StringUtils::containsInvalidChar(const std::string& str)
|
||||||
|
{
|
||||||
|
for (size_t i = 0, sz = str.length(); i < sz; i++) {
|
||||||
|
if (!isascii(str[i])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringUtils::ltrim(std::string& s)
|
||||||
|
{
|
||||||
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch); }));
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringUtils::rtrim(std::string& s)
|
||||||
|
{
|
||||||
|
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringUtils::trim(std::string& s)
|
||||||
|
{
|
||||||
|
ltrim(s);
|
||||||
|
rtrim(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* getConsoleIP(void)
|
||||||
|
{
|
||||||
|
struct in_addr in;
|
||||||
|
in.s_addr = gethostid();
|
||||||
|
return inet_ntoa(in);
|
||||||
|
}
|
||||||
+247
-167
@@ -1,205 +1,278 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
#include <algorithm>
|
* This file is part of Checkpoint
|
||||||
#include <cstring>
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
#include <vector>
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "nxst/domain/account.hpp"
|
|
||||||
#include <nxst/domain/title.hpp>
|
#include <nxst/domain/title.hpp>
|
||||||
#include <nxst/domain/util.hpp>
|
#include <nxst/app/main.hpp>
|
||||||
#include <nxst/infra/fs/directory.hpp>
|
|
||||||
#include <nxst/infra/sys/logger.hpp>
|
|
||||||
|
|
||||||
using sort_t = enum { SortAlpha, SortLastPlayed, SortPlayTime, SortModesCount };
|
|
||||||
static constexpr const char* kEmptySave = "New...";
|
|
||||||
static sort_t s_sort_mode = SortAlpha;
|
|
||||||
|
|
||||||
static std::unordered_map<AccountUid, std::vector<Title>> titles;
|
static std::unordered_map<AccountUid, std::vector<Title>> titles;
|
||||||
static bool s_titles_loaded = false;
|
static bool s_titlesLoaded = false;
|
||||||
|
|
||||||
void Title::init(u8 save_data_type, u64 title_id, AccountUid uid, const std::string& name,
|
bool areTitlesLoaded(void)
|
||||||
const std::string& author) {
|
{
|
||||||
m_id = title_id;
|
return s_titlesLoaded;
|
||||||
m_uid = uid;
|
}
|
||||||
m_save_data_type = save_data_type;
|
|
||||||
m_user_name = account::username(uid);
|
|
||||||
m_author = author;
|
|
||||||
m_name = name;
|
|
||||||
m_safe_name = string_utils::containsInvalidChar(name) ? string_utils::format("0x%016llX", m_id)
|
|
||||||
: string_utils::removeForbiddenCharacters(name);
|
|
||||||
m_path = "sdmc:/switch/NXST/saves/" + string_utils::format("0x%016llX", m_id) + " " + m_safe_name;
|
|
||||||
|
|
||||||
std::string aname = string_utils::removeAccents(m_name);
|
void Title::init(u8 saveDataType, u64 id, AccountUid userID, const std::string& name, const std::string& author)
|
||||||
m_display_name = {aname, ""};
|
{
|
||||||
|
mId = id;
|
||||||
|
mUserId = userID;
|
||||||
|
mSaveDataType = saveDataType;
|
||||||
|
mUserName = Account::username(userID);
|
||||||
|
mAuthor = author;
|
||||||
|
mName = name;
|
||||||
|
mSafeName = StringUtils::containsInvalidChar(name) ? StringUtils::format("0x%016llX", mId) : StringUtils::removeForbiddenCharacters(name);
|
||||||
|
mPath = "sdmc:/switch/NXST/saves/" + StringUtils::format("0x%016llX", mId) + " " + mSafeName;
|
||||||
|
|
||||||
size_t colon = aname.rfind(':');
|
std::string aname = StringUtils::removeAccents(mName);
|
||||||
if (colon != std::string::npos) {
|
size_t pos = aname.rfind(":");
|
||||||
std::string head = aname.substr(0, colon);
|
mDisplayName = std::make_pair(aname, "");
|
||||||
std::string tail = aname.substr(colon + 1);
|
if (pos != std::string::npos) {
|
||||||
string_utils::trim(head);
|
std::string name1 = aname.substr(0, pos);
|
||||||
string_utils::trim(tail);
|
std::string name2 = aname.substr(pos + 1);
|
||||||
m_display_name = {head, tail};
|
StringUtils::trim(name1);
|
||||||
} else {
|
StringUtils::trim(name2);
|
||||||
size_t open = aname.rfind('(');
|
mDisplayName.first = name1;
|
||||||
size_t close = aname.rfind(')');
|
mDisplayName.second = name2;
|
||||||
if (open != std::string::npos && close != std::string::npos && close > open) {
|
}
|
||||||
std::string head = aname.substr(0, open);
|
else {
|
||||||
std::string paren = aname.substr(open + 1, close - open - 1);
|
// check for parenthesis
|
||||||
string_utils::trim(head);
|
size_t pos1 = aname.rfind("(");
|
||||||
string_utils::trim(paren);
|
size_t pos2 = aname.rfind(")");
|
||||||
m_display_name = {head, paren};
|
if (pos1 != std::string::npos && pos2 != std::string::npos) {
|
||||||
|
std::string name1 = aname.substr(0, pos1);
|
||||||
|
std::string name2 = aname.substr(pos1 + 1, pos2 - 1 - pos1);
|
||||||
|
StringUtils::trim(name1);
|
||||||
|
StringUtils::trim(name2);
|
||||||
|
mDisplayName.first = name1;
|
||||||
|
mDisplayName.second = name2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshDirectories();
|
refreshDirectories();
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 Title::saveDataType() const {
|
u8 Title::saveDataType(void)
|
||||||
return m_save_data_type;
|
{
|
||||||
}
|
return mSaveDataType;
|
||||||
u64 Title::id() const {
|
|
||||||
return m_id;
|
|
||||||
}
|
|
||||||
u64 Title::saveId() const {
|
|
||||||
return m_save_id;
|
|
||||||
}
|
|
||||||
void Title::saveId(u64 id) {
|
|
||||||
m_save_id = id;
|
|
||||||
}
|
|
||||||
AccountUid Title::userId() const {
|
|
||||||
return m_uid;
|
|
||||||
}
|
|
||||||
std::string Title::userName() const {
|
|
||||||
return m_user_name;
|
|
||||||
}
|
|
||||||
std::string Title::author() const {
|
|
||||||
return m_author;
|
|
||||||
}
|
|
||||||
std::string Title::name() const {
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
std::pair<std::string, std::string> Title::displayName() const {
|
|
||||||
return m_display_name;
|
|
||||||
}
|
|
||||||
std::string Title::path() const {
|
|
||||||
return m_path;
|
|
||||||
}
|
|
||||||
std::string Title::fullPath(size_t index) const {
|
|
||||||
return m_full_save_paths.at(index);
|
|
||||||
}
|
|
||||||
std::vector<std::string> Title::saves() const {
|
|
||||||
return m_saves;
|
|
||||||
}
|
|
||||||
u64 Title::playTimeNanoseconds() const {
|
|
||||||
return m_play_time_ns;
|
|
||||||
}
|
|
||||||
void Title::playTimeNanoseconds(u64 ns) {
|
|
||||||
m_play_time_ns = ns;
|
|
||||||
}
|
|
||||||
u32 Title::lastPlayedTimestamp() const {
|
|
||||||
return m_last_played_ts;
|
|
||||||
}
|
|
||||||
void Title::lastPlayedTimestamp(u32 ts) {
|
|
||||||
m_last_played_ts = ts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Title::playTime() const {
|
u64 Title::id(void)
|
||||||
const u64 minutes = m_play_time_ns / 60000000000ULL;
|
{
|
||||||
return string_utils::format("%d", minutes / 60) + ":" + string_utils::format("%02d", minutes % 60) +
|
return mId;
|
||||||
" hours";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Title::refreshDirectories() {
|
u64 Title::saveId(void)
|
||||||
m_saves.clear();
|
{
|
||||||
m_full_save_paths.clear();
|
return mSaveId;
|
||||||
|
}
|
||||||
|
|
||||||
Directory savelist(m_path);
|
void Title::saveId(u64 saveId)
|
||||||
|
{
|
||||||
|
mSaveId = saveId;
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountUid Title::userId(void)
|
||||||
|
{
|
||||||
|
return mUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Title::userName(void)
|
||||||
|
{
|
||||||
|
return mUserName;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Title::author(void)
|
||||||
|
{
|
||||||
|
return mAuthor;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Title::name(void)
|
||||||
|
{
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<std::string, std::string> Title::displayName(void)
|
||||||
|
{
|
||||||
|
return mDisplayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Title::path(void)
|
||||||
|
{
|
||||||
|
return mPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Title::fullPath(size_t index)
|
||||||
|
{
|
||||||
|
return mFullSavePaths.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Title::saves()
|
||||||
|
{
|
||||||
|
return mSaves;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 Title::playTimeNanoseconds(void)
|
||||||
|
{
|
||||||
|
return mPlayTimeNanoseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Title::playTime(void)
|
||||||
|
{
|
||||||
|
const u64 playTimeMinutes = mPlayTimeNanoseconds / 60000000000;
|
||||||
|
return StringUtils::format("%d", playTimeMinutes / 60) + ":" + StringUtils::format("%02d", playTimeMinutes % 60) + " hours";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Title::playTimeNanoseconds(u64 playTimeNanoseconds)
|
||||||
|
{
|
||||||
|
mPlayTimeNanoseconds = playTimeNanoseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 Title::lastPlayedTimestamp(void)
|
||||||
|
{
|
||||||
|
return mLastPlayedTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Title::lastPlayedTimestamp(u32 lastPlayedTimestamp)
|
||||||
|
{
|
||||||
|
mLastPlayedTimestamp = lastPlayedTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Title::refreshDirectories(void)
|
||||||
|
{
|
||||||
|
mSaves.clear();
|
||||||
|
mFullSavePaths.clear();
|
||||||
|
|
||||||
|
Directory savelist(mPath);
|
||||||
if (savelist.good()) {
|
if (savelist.good()) {
|
||||||
for (size_t i = 0; i < savelist.size(); ++i) {
|
for (size_t i = 0, sz = savelist.size(); i < sz; i++) {
|
||||||
if (savelist.folder(i)) {
|
if (savelist.folder(i)) {
|
||||||
m_saves.push_back(savelist.entry(i));
|
mSaves.push_back(savelist.entry(i));
|
||||||
m_full_save_paths.push_back(m_path + "/" + savelist.entry(i));
|
mFullSavePaths.push_back(mPath + "/" + savelist.entry(i));
|
||||||
}
|
|
||||||
}
|
|
||||||
std::sort(m_saves.rbegin(), m_saves.rend());
|
|
||||||
std::sort(m_full_save_paths.rbegin(), m_full_save_paths.rend());
|
|
||||||
m_saves.insert(m_saves.begin(), kEmptySave);
|
|
||||||
m_full_save_paths.insert(m_full_save_paths.begin(), kEmptySave);
|
|
||||||
} else {
|
|
||||||
nxst::log::error("Could not read save directory for title %s", m_name.c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool areTitlesLoaded() {
|
std::sort(mSaves.rbegin(), mSaves.rend());
|
||||||
return s_titles_loaded;
|
std::sort(mFullSavePaths.rbegin(), mFullSavePaths.rend());
|
||||||
|
mSaves.insert(mSaves.begin(), g_emptySave);
|
||||||
|
mFullSavePaths.insert(mFullSavePaths.begin(), g_emptySave);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Logger::getInstance().log(Logger::ERROR, "Couldn't retrieve the extdata directory list for the title " + name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadTitles() {
|
void loadTitles(void)
|
||||||
if (s_titles_loaded)
|
{
|
||||||
return;
|
if (s_titlesLoaded) return;
|
||||||
s_titles_loaded = true;
|
s_titlesLoaded = true;
|
||||||
|
|
||||||
titles.clear();
|
titles.clear();
|
||||||
|
|
||||||
FsSaveDataInfoReader reader;
|
FsSaveDataInfoReader reader;
|
||||||
Result res = fsOpenSaveDataInfoReader(&reader, FsSaveDataSpaceId_User);
|
FsSaveDataInfo info;
|
||||||
if (R_FAILED(res))
|
s64 total_entries = 0;
|
||||||
return;
|
|
||||||
|
|
||||||
std::vector<u8> nacp_buf(sizeof(NsApplicationControlData), 0);
|
|
||||||
auto* nsacd = reinterpret_cast<NsApplicationControlData*>(nacp_buf.data());
|
|
||||||
|
|
||||||
FsSaveDataInfo info{};
|
|
||||||
s64 count = 0;
|
|
||||||
while (true) {
|
|
||||||
res = fsSaveDataInfoReaderRead(&reader, &info, 1, &count);
|
|
||||||
if (R_FAILED(res) || count == 0)
|
|
||||||
break;
|
|
||||||
if (info.save_data_type != FsSaveDataType_Account)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
u64 tid = info.application_id;
|
|
||||||
AccountUid uid = info.uid;
|
|
||||||
size_t outsize = 0;
|
size_t outsize = 0;
|
||||||
NacpLanguageEntry* nle = nullptr;
|
|
||||||
|
|
||||||
|
NacpLanguageEntry* nle = NULL;
|
||||||
|
NsApplicationControlData* nsacd = (NsApplicationControlData*)malloc(sizeof(NsApplicationControlData));
|
||||||
|
if (nsacd == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
memset(nsacd, 0, sizeof(NsApplicationControlData));
|
memset(nsacd, 0, sizeof(NsApplicationControlData));
|
||||||
res = nsGetApplicationControlData(NsApplicationControlSource_Storage, tid, nsacd,
|
|
||||||
sizeof(NsApplicationControlData), &outsize);
|
|
||||||
if (R_FAILED(res) || outsize < sizeof(nsacd->nacp))
|
|
||||||
continue;
|
|
||||||
if (R_FAILED(nacpGetLanguageEntry(&nsacd->nacp, &nle)) || !nle)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
|
Result res = fsOpenSaveDataInfoReader(&reader, FsSaveDataSpaceId_User);
|
||||||
|
if (R_FAILED(res)) {
|
||||||
|
free(nsacd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
res = fsSaveDataInfoReaderRead(&reader, &info, 1, &total_entries);
|
||||||
|
if (R_FAILED(res) || total_entries == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info.save_data_type == FsSaveDataType_Account) {
|
||||||
|
u64 tid = info.application_id;
|
||||||
|
u64 sid = info.save_data_id;
|
||||||
|
AccountUid uid = info.uid;
|
||||||
|
// if (mFilterIds.find(tid) == mFilterIds.end()) {
|
||||||
|
res = nsGetApplicationControlData(NsApplicationControlSource_Storage, tid, nsacd, sizeof(NsApplicationControlData), &outsize);
|
||||||
|
if (R_SUCCEEDED(res) && !(outsize < sizeof(nsacd->nacp))) {
|
||||||
|
res = nacpGetLanguageEntry(&nsacd->nacp, &nle);
|
||||||
|
if (R_SUCCEEDED(res) && nle != NULL) {
|
||||||
Title title;
|
Title title;
|
||||||
title.init(info.save_data_type, tid, uid, std::string(nle->name), std::string(nle->author));
|
title.init(info.save_data_type, tid, uid, std::string(nle->name), std::string(nle->author));
|
||||||
title.saveId(info.save_data_id);
|
title.saveId(sid);
|
||||||
|
|
||||||
PdmPlayStatistics stats{};
|
// load play statistics
|
||||||
if (R_SUCCEEDED(pdmqryQueryPlayStatisticsByApplicationIdAndUserAccountId(tid, uid, false, &stats))) {
|
PdmPlayStatistics stats;
|
||||||
|
res = pdmqryQueryPlayStatisticsByApplicationIdAndUserAccountId(tid, uid, false, &stats);
|
||||||
|
if (R_SUCCEEDED(res)) {
|
||||||
title.playTimeNanoseconds(stats.playtime);
|
title.playTimeNanoseconds(stats.playtime);
|
||||||
title.lastPlayedTimestamp(stats.last_timestamp_user);
|
title.lastPlayedTimestamp(stats.last_timestamp_user);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = titles.find(uid);
|
// loadIcon(tid, nsacd, outsize - sizeof(nsacd->nacp));
|
||||||
|
|
||||||
|
// check if the vector is already created
|
||||||
|
std::unordered_map<AccountUid, std::vector<Title>>::iterator it = titles.find(uid);
|
||||||
if (it != titles.end()) {
|
if (it != titles.end()) {
|
||||||
|
// found
|
||||||
it->second.push_back(title);
|
it->second.push_back(title);
|
||||||
} else {
|
}
|
||||||
titles.emplace(uid, std::vector<Title>{title});
|
else {
|
||||||
|
// not found, insert into map
|
||||||
|
std::vector<Title> v;
|
||||||
|
v.push_back(title);
|
||||||
|
titles.emplace(uid, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nle = NULL;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(nsacd);
|
||||||
fsSaveDataInfoReaderClose(&reader);
|
fsSaveDataInfoReaderClose(&reader);
|
||||||
|
|
||||||
sortTitles();
|
sortTitles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sortTitles() {
|
void sortTitles(void)
|
||||||
for (auto& pair : titles) {
|
{
|
||||||
std::sort(pair.second.begin(), pair.second.end(), [](const Title& l, const Title& r) {
|
for (auto& vect : titles) {
|
||||||
switch (s_sort_mode) {
|
std::sort(vect.second.begin(), vect.second.end(), [](Title& l, Title& r) {
|
||||||
case SortLastPlayed:
|
switch (g_sortMode) {
|
||||||
|
case SORT_LAST_PLAYED:
|
||||||
return l.lastPlayedTimestamp() > r.lastPlayedTimestamp();
|
return l.lastPlayedTimestamp() > r.lastPlayedTimestamp();
|
||||||
case SortPlayTime:
|
case SORT_PLAY_TIME:
|
||||||
return l.playTimeNanoseconds() > r.playTimeNanoseconds();
|
return l.playTimeNanoseconds() > r.playTimeNanoseconds();
|
||||||
case SortAlpha:
|
case SORT_ALPHA:
|
||||||
default:
|
default:
|
||||||
return l.name() < r.name();
|
return l.name() < r.name();
|
||||||
}
|
}
|
||||||
@@ -207,36 +280,43 @@ void sortTitles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotateSortMode() {
|
void rotateSortMode(void)
|
||||||
s_sort_mode = static_cast<sort_t>((s_sort_mode + 1) % SortModesCount);
|
{
|
||||||
|
g_sortMode = static_cast<sort_t>((g_sortMode + 1) % SORT_MODES_COUNT);
|
||||||
sortTitles();
|
sortTitles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void getTitle(Title& dst, AccountUid uid, size_t i) {
|
void getTitle(Title& dst, AccountUid uid, size_t i)
|
||||||
auto it = titles.find(uid);
|
{
|
||||||
if (it != titles.end() && i < it->second.size())
|
std::unordered_map<AccountUid, std::vector<Title>>::iterator it = titles.find(uid);
|
||||||
dst = it->second[i];
|
if (it != titles.end() && i < getTitleCount(uid)) {
|
||||||
|
dst = it->second.at(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getTitleCount(AccountUid uid) {
|
size_t getTitleCount(AccountUid uid)
|
||||||
auto it = titles.find(uid);
|
{
|
||||||
|
std::unordered_map<AccountUid, std::vector<Title>>::iterator it = titles.find(uid);
|
||||||
return it != titles.end() ? it->second.size() : 0;
|
return it != titles.end() ? it->second.size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshDirectories(u64 id) {
|
void refreshDirectories(u64 id)
|
||||||
|
{
|
||||||
for (auto& pair : titles) {
|
for (auto& pair : titles) {
|
||||||
for (auto& title : pair.second) {
|
for (size_t i = 0; i < pair.second.size(); i++) {
|
||||||
if (title.id() == id)
|
if (pair.second.at(i).id() == id) {
|
||||||
title.refreshDirectories();
|
pair.second.at(i).refreshDirectories();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<std::string, std::string> getCompleteTitleList() {
|
std::unordered_map<std::string, std::string> getCompleteTitleList(void)
|
||||||
|
{
|
||||||
std::unordered_map<std::string, std::string> map;
|
std::unordered_map<std::string, std::string> map;
|
||||||
for (const auto& pair : titles) {
|
for (const auto& pair : titles) {
|
||||||
for (const auto& title : pair.second) {
|
for (auto value : pair.second) {
|
||||||
map.emplace(string_utils::format("0x%016llX", title.id()), title.name());
|
map.insert({StringUtils::format("0x%016llX", value.id()), value.name()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
|||||||
+114
-199
@@ -1,250 +1,165 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
#include <algorithm>
|
* This file is part of Checkpoint
|
||||||
#include <cctype>
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
#include <cstdarg>
|
*
|
||||||
#include <cstdio>
|
* This program is free software: you can redistribute it and/or modify
|
||||||
#include <string>
|
* it under the terms of the GNU General Public License as published by
|
||||||
#include <unordered_map>
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <nxst/domain/account.hpp>
|
|
||||||
#include <nxst/domain/util.hpp>
|
#include <nxst/domain/util.hpp>
|
||||||
#include <nxst/infra/fs/io.hpp>
|
|
||||||
#include <nxst/infra/sys/logger.hpp>
|
#include <nxst/infra/sys/logger.hpp>
|
||||||
|
#include <nxst/app/main_application.hpp>
|
||||||
|
#include <nxst/app/main.hpp>
|
||||||
|
|
||||||
static bool s_notification_led_available = false;
|
void servicesExit(void)
|
||||||
|
{
|
||||||
void servicesExit() {
|
Logger::getInstance().flush();
|
||||||
account::exit();
|
Account::exit();
|
||||||
plExit();
|
plExit();
|
||||||
romfsExit();
|
romfsExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result servicesInit() {
|
Result servicesInit(void)
|
||||||
|
{
|
||||||
io::createDirectory("sdmc:/switch");
|
io::createDirectory("sdmc:/switch");
|
||||||
io::createDirectory("sdmc:/switch/NXST");
|
io::createDirectory("sdmc:/switch/NXST");
|
||||||
io::createDirectory("sdmc:/switch/NXST/saves");
|
io::createDirectory("sdmc:/switch/NXST/saves");
|
||||||
|
|
||||||
if (appletGetAppletType() != AppletType_Application) {
|
if (appletGetAppletType() != AppletType_Application) {
|
||||||
nxst::log::warn("Please do not run NXST in applet mode.");
|
Logger::getInstance().log(Logger::WARN, "Please do not run NXST in applet mode.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Result res = 0;
|
Result res = 0;
|
||||||
|
|
||||||
romfsInit();
|
romfsInit();
|
||||||
|
|
||||||
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
|
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
|
||||||
hidInitializeTouchScreen();
|
hidInitializeTouchScreen();
|
||||||
|
|
||||||
if (R_FAILED(res = plInitialize(PlServiceType_User))) {
|
if (R_FAILED(res = plInitialize(PlServiceType_User))) {
|
||||||
nxst::log::error("plInitialize failed. Result code 0x%08X.", res);
|
Logger::getInstance().log(Logger::ERROR, "plInitialize failed. Result code 0x%08lX.", res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
if (R_FAILED(res = account::init())) {
|
|
||||||
nxst::log::error("account::init failed. Result code 0x%08X.", res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (R_FAILED(res = nsInitialize())) {
|
|
||||||
nxst::log::error("nsInitialize failed. Result code 0x%08X.", res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (R_SUCCEEDED(hidsysInitialize())) {
|
|
||||||
s_notification_led_available = true;
|
|
||||||
} else {
|
|
||||||
nxst::log::info("Notification LED not available.");
|
|
||||||
}
|
|
||||||
|
|
||||||
nxst::log::info("NXST loading completed.");
|
if (R_FAILED(res = Account::init())) {
|
||||||
|
Logger::getInstance().log(Logger::ERROR, "Account::init failed. Result code 0x%08lX.", res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (R_FAILED(res = nsInitialize())) {
|
||||||
|
Logger::getInstance().log(Logger::ERROR, "nsInitialize failed. Result code 0x{:08X}.", res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(res = hidsysInitialize())) {
|
||||||
|
g_notificationLedAvailable = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Logger::getInstance().log(Logger::INFO, "Notification led not available. Result code 0x{:08X}.", res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Logger::getInstance().log(Logger::INFO, "NXST loading completed!");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool string_utils::containsInvalidChar(const std::string& str) {
|
std::u16string StringUtils::UTF8toUTF16(const char* src)
|
||||||
for (unsigned char c : str) {
|
{
|
||||||
if (!isascii(c))
|
char16_t tmp[256] = {0};
|
||||||
return true;
|
utf8_to_utf16((uint16_t*)tmp, (uint8_t*)src, 256);
|
||||||
}
|
return std::u16string(tmp);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string string_utils::format(const char* fmt, ...) {
|
// https://stackoverflow.com/questions/14094621/change-all-accented-letters-to-normal-letters-in-c
|
||||||
va_list a1, a2;
|
std::string StringUtils::removeAccents(std::string str)
|
||||||
va_start(a1, fmt);
|
{
|
||||||
va_copy(a2, a1);
|
std::u16string src = UTF8toUTF16(str.c_str());
|
||||||
int n = vsnprintf(nullptr, 0, fmt, a1);
|
const std::u16string illegal = UTF8toUTF16("ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüūýþÿ");
|
||||||
va_end(a1);
|
const std::u16string fixed = UTF8toUTF16("AAAAAAECEEEEIIIIDNOOOOOx0UUUUYPsaaaaaaeceeeeiiiiOnooooo/0uuuuuypy");
|
||||||
if (n < 0) {
|
|
||||||
va_end(a2);
|
for (size_t i = 0, sz = src.length(); i < sz; i++) {
|
||||||
return {};
|
size_t index = illegal.find(src[i]);
|
||||||
|
if (index != std::string::npos) {
|
||||||
|
src[i] = fixed[index];
|
||||||
}
|
}
|
||||||
std::string buf(static_cast<size_t>(n), '\0');
|
|
||||||
vsnprintf(buf.data(), static_cast<size_t>(n) + 1, fmt, a2);
|
|
||||||
va_end(a2);
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string string_utils::removeForbiddenCharacters(std::string src) {
|
return UTF16toUTF8(src);
|
||||||
static constexpr std::string_view kForbidden = ".,!\\/:?*\"<>|";
|
|
||||||
for (char& c : src) {
|
|
||||||
if (kForbidden.find(c) != std::string_view::npos)
|
|
||||||
c = ' ';
|
|
||||||
}
|
|
||||||
auto last = src.find_last_not_of(' ');
|
|
||||||
if (last != std::string::npos)
|
|
||||||
src.erase(last + 1);
|
|
||||||
return src;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t encodeUtf8(char* out, char32_t cp) {
|
std::string StringUtils::removeNotAscii(std::string str)
|
||||||
if (cp < 0x80) {
|
{
|
||||||
out[0] = static_cast<char>(cp);
|
for (size_t i = 0, sz = str.length(); i < sz; i++) {
|
||||||
return 1;
|
if (!isascii(str[i])) {
|
||||||
|
str[i] = ' ';
|
||||||
}
|
}
|
||||||
if (cp < 0x800) {
|
|
||||||
out[0] = static_cast<char>(0xC0 | (cp >> 6));
|
|
||||||
out[1] = static_cast<char>(0x80 | (cp & 0x3F));
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
if (cp < 0x10000) {
|
|
||||||
out[0] = static_cast<char>(0xE0 | (cp >> 12));
|
|
||||||
out[1] = static_cast<char>(0x80 | ((cp >> 6) & 0x3F));
|
|
||||||
out[2] = static_cast<char>(0x80 | (cp & 0x3F));
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
out[0] = static_cast<char>(0xF0 | (cp >> 18));
|
|
||||||
out[1] = static_cast<char>(0x80 | ((cp >> 12) & 0x3F));
|
|
||||||
out[2] = static_cast<char>(0x80 | ((cp >> 6) & 0x3F));
|
|
||||||
out[3] = static_cast<char>(0x80 | (cp & 0x3F));
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string string_utils::UTF16toUTF8(const std::u16string& src) {
|
|
||||||
std::string result;
|
|
||||||
result.reserve(src.size() * 2);
|
|
||||||
for (size_t i = 0; i < src.size(); ++i) {
|
|
||||||
char32_t cp = src[i];
|
|
||||||
if (cp >= 0xD800 && cp <= 0xDBFF && i + 1 < src.size()) {
|
|
||||||
cp = 0x10000 + ((cp - 0xD800) << 10) + (src[++i] - 0xDC00);
|
|
||||||
}
|
|
||||||
char buf[4];
|
|
||||||
result.append(buf, encodeUtf8(buf, cp));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void string_utils::ltrim(std::string& s) {
|
|
||||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char c) {
|
|
||||||
return !std::isspace(c);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
void string_utils::rtrim(std::string& s) {
|
|
||||||
s.erase(std::find_if(s.rbegin(), s.rend(),
|
|
||||||
[](unsigned char c) {
|
|
||||||
return !std::isspace(c);
|
|
||||||
})
|
|
||||||
.base(),
|
|
||||||
s.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
void string_utils::trim(std::string& s) {
|
|
||||||
ltrim(s);
|
|
||||||
rtrim(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decodes a UTF-8 string to UTF-16, handling surrogate pairs for codepoints > U+FFFF.
|
|
||||||
std::u16string string_utils::UTF8toUTF16(const char* src) {
|
|
||||||
std::u16string result;
|
|
||||||
while (*src != '\0') {
|
|
||||||
char32_t cp = 0;
|
|
||||||
unsigned char c = static_cast<unsigned char>(*src);
|
|
||||||
if (c < 0x80) {
|
|
||||||
cp = c;
|
|
||||||
++src;
|
|
||||||
} else if (c < 0xE0) {
|
|
||||||
cp = static_cast<char32_t>(c & 0x1F) << 6 | (src[1] & 0x3F);
|
|
||||||
src += 2;
|
|
||||||
} else if (c < 0xF0) {
|
|
||||||
cp = static_cast<char32_t>(c & 0x0F) << 12 | static_cast<char32_t>(src[1] & 0x3F) << 6 |
|
|
||||||
(src[2] & 0x3F);
|
|
||||||
src += 3;
|
|
||||||
} else {
|
|
||||||
cp = static_cast<char32_t>(c & 0x07) << 18 | static_cast<char32_t>(src[1] & 0x3F) << 12 |
|
|
||||||
static_cast<char32_t>(src[2] & 0x3F) << 6 | (src[3] & 0x3F);
|
|
||||||
src += 4;
|
|
||||||
}
|
|
||||||
if (cp < 0x10000) {
|
|
||||||
result += static_cast<char16_t>(cp);
|
|
||||||
} else {
|
|
||||||
cp -= 0x10000;
|
|
||||||
result += static_cast<char16_t>(0xD800 | (cp >> 10));
|
|
||||||
result += static_cast<char16_t>(0xDC00 | (cp & 0x3FF));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replaces Latin characters with diacritics with their ASCII base equivalents.
|
|
||||||
std::string string_utils::removeAccents(std::string str) {
|
|
||||||
static const std::unordered_map<char16_t, char16_t> kMap = {
|
|
||||||
{u'À', u'A'}, {u'Á', u'A'}, {u'Â', u'A'}, {u'Ã', u'A'}, {u'Ä', u'A'}, {u'Å', u'A'}, {u'Æ', u'E'},
|
|
||||||
{u'Ç', u'C'}, {u'È', u'E'}, {u'É', u'E'}, {u'Ê', u'E'}, {u'Ë', u'E'}, {u'Ì', u'I'}, {u'Í', u'I'},
|
|
||||||
{u'Î', u'I'}, {u'Ï', u'I'}, {u'Ð', u'D'}, {u'Ñ', u'N'}, {u'Ò', u'O'}, {u'Ó', u'O'}, {u'Ô', u'O'},
|
|
||||||
{u'Õ', u'O'}, {u'Ö', u'O'}, {u'Ø', u'O'}, {u'Ù', u'U'}, {u'Ú', u'U'}, {u'Û', u'U'}, {u'Ü', u'U'},
|
|
||||||
{u'Ý', u'Y'}, {u'ß', u's'}, {u'à', u'a'}, {u'á', u'a'}, {u'â', u'a'}, {u'ã', u'a'}, {u'ä', u'a'},
|
|
||||||
{u'å', u'a'}, {u'æ', u'e'}, {u'ç', u'c'}, {u'è', u'e'}, {u'é', u'e'}, {u'ê', u'e'}, {u'ë', u'e'},
|
|
||||||
{u'ì', u'i'}, {u'í', u'i'}, {u'î', u'i'}, {u'ï', u'i'}, {u'ñ', u'n'}, {u'ò', u'o'}, {u'ó', u'o'},
|
|
||||||
{u'ô', u'o'}, {u'õ', u'o'}, {u'ö', u'o'}, {u'ø', u'o'}, {u'ù', u'u'}, {u'ú', u'u'}, {u'û', u'u'},
|
|
||||||
{u'ü', u'u'}, {u'ū', u'u'}, {u'ý', u'y'}, {u'ÿ', u'y'},
|
|
||||||
};
|
|
||||||
std::u16string wide = UTF8toUTF16(str.c_str());
|
|
||||||
for (char16_t& ch : wide) {
|
|
||||||
auto it = kMap.find(ch);
|
|
||||||
if (it != kMap.end())
|
|
||||||
ch = it->second;
|
|
||||||
}
|
|
||||||
return string_utils::UTF16toUTF8(wide);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string string_utils::removeNotAscii(std::string str) {
|
|
||||||
for (char& c : str) {
|
|
||||||
if (!isascii(static_cast<unsigned char>(c)))
|
|
||||||
c = ' ';
|
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string string_utils::elide(const std::string& s, size_t max_chars) {
|
std::string StringUtils::elide(const std::string& s, size_t maxChars)
|
||||||
if (s.size() <= max_chars || max_chars < 6)
|
{
|
||||||
return s;
|
if (s.size() <= maxChars || maxChars < 6) return s;
|
||||||
size_t budget = max_chars - 3;
|
constexpr const char* dots = "...";
|
||||||
|
size_t budget = maxChars - 3;
|
||||||
size_t head = (budget + 1) / 2;
|
size_t head = (budget + 1) / 2;
|
||||||
size_t tail = budget - head;
|
size_t tail = budget - head;
|
||||||
return s.substr(0, head) + "..." + s.substr(s.size() - tail);
|
return s.substr(0, head) + dots + s.substr(s.size() - tail);
|
||||||
}
|
}
|
||||||
|
|
||||||
static HidsysNotificationLedPattern makeLedPattern(u8 times) {
|
HidsysNotificationLedPattern blinkLedPattern(u8 times)
|
||||||
HidsysNotificationLedPattern p{};
|
{
|
||||||
p.baseMiniCycleDuration = 0x1;
|
HidsysNotificationLedPattern pattern;
|
||||||
p.totalMiniCycles = 0x2;
|
memset(&pattern, 0, sizeof(pattern));
|
||||||
p.totalFullCycles = times;
|
|
||||||
p.startIntensity = 0x0;
|
pattern.baseMiniCycleDuration = 0x1; // 12.5ms.
|
||||||
p.miniCycles[0] = {0xF, 0xF, 0x0};
|
pattern.totalMiniCycles = 0x2; // 2 mini cycles.
|
||||||
p.miniCycles[1] = {0x0, 0xF, 0x0};
|
pattern.totalFullCycles = times; // Repeat n times.
|
||||||
return p;
|
pattern.startIntensity = 0x0; // 0%.
|
||||||
|
|
||||||
|
pattern.miniCycles[0].ledIntensity = 0xF; // 100%.
|
||||||
|
pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
|
||||||
|
pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms.
|
||||||
|
pattern.miniCycles[1].ledIntensity = 0x0; // 0%.
|
||||||
|
pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
|
||||||
|
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
|
||||||
|
|
||||||
|
return pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
void blinkLed(u8 times) {
|
void blinkLed(u8 times)
|
||||||
if (!s_notification_led_available)
|
{
|
||||||
return;
|
if (g_notificationLedAvailable) {
|
||||||
|
|
||||||
PadState pad;
|
PadState pad;
|
||||||
padInitializeDefault(&pad);
|
padInitializeDefault(&pad);
|
||||||
s32 n = 0;
|
s32 n;
|
||||||
HidsysUniquePadId pads[2]{};
|
HidsysUniquePadId uniquePadIds[2] = {0};
|
||||||
HidsysNotificationLedPattern pattern = makeLedPattern(times);
|
HidsysNotificationLedPattern pattern = blinkLedPattern(times);
|
||||||
|
memset(uniquePadIds, 0, sizeof(uniquePadIds));
|
||||||
Result res = hidsysGetUniquePadsFromNpad(padIsHandheld(&pad) ? HidNpadIdType_Handheld : HidNpadIdType_No1,
|
Result res = hidsysGetUniquePadsFromNpad(padIsHandheld(&pad) ? HidNpadIdType_Handheld : HidNpadIdType_No1, uniquePadIds, 2, &n);
|
||||||
pads, 2, &n);
|
|
||||||
if (R_SUCCEEDED(res)) {
|
if (R_SUCCEEDED(res)) {
|
||||||
for (s32 i = 0; i < n; ++i) {
|
for (s32 i = 0; i < n; i++) {
|
||||||
hidsysSetNotificationLedPattern(&pattern, pads[i]);
|
hidsysSetNotificationLedPattern(&pattern, uniquePadIds[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+66
-17
@@ -1,27 +1,76 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
#include <cerrno>
|
* This file is part of Checkpoint
|
||||||
#include <dirent.h>
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <nxst/infra/fs/directory.hpp>
|
#include <nxst/infra/fs/directory.hpp>
|
||||||
|
|
||||||
Directory::Directory(const std::string& path) {
|
Directory::Directory(const std::string& root)
|
||||||
DIR* d = opendir(path.c_str());
|
{
|
||||||
if (!d) {
|
mGood = false;
|
||||||
m_error = static_cast<Result>(errno);
|
mError = 0;
|
||||||
return;
|
mList.clear();
|
||||||
}
|
|
||||||
|
DIR* dir = opendir(root.c_str());
|
||||||
struct dirent* ent;
|
struct dirent* ent;
|
||||||
while ((ent = readdir(d)) != nullptr) {
|
|
||||||
m_entries.push_back({ent->d_name, ent->d_type == DT_DIR});
|
if (dir == NULL) {
|
||||||
|
mError = (Result)errno;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
while ((ent = readdir(dir))) {
|
||||||
|
std::string name = std::string(ent->d_name);
|
||||||
|
bool directory = ent->d_type == DT_DIR;
|
||||||
|
struct DirectoryEntry de = {name, directory};
|
||||||
|
mList.push_back(de);
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
mGood = true;
|
||||||
}
|
}
|
||||||
closedir(d);
|
|
||||||
m_good = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Directory::entry(size_t i) const {
|
Result Directory::error(void)
|
||||||
return i < m_entries.size() ? m_entries[i].name : "";
|
{
|
||||||
|
return mError;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Directory::folder(size_t i) const {
|
bool Directory::good(void)
|
||||||
return i < m_entries.size() && m_entries[i].is_dir;
|
{
|
||||||
|
return mGood;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Directory::entry(size_t index)
|
||||||
|
{
|
||||||
|
return index < mList.size() ? mList.at(index).name : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Directory::folder(size_t index)
|
||||||
|
{
|
||||||
|
return index < mList.size() ? mList.at(index).directory : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Directory::size(void)
|
||||||
|
{
|
||||||
|
return mList.size();
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,42 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
|
* This file is part of Checkpoint
|
||||||
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <nxst/infra/fs/filesystem.hpp>
|
#include <nxst/infra/fs/filesystem.hpp>
|
||||||
|
|
||||||
Result file_system::mount(FsFileSystem* fs, u64 title_id, AccountUid uid) {
|
Result FileSystem::mount(FsFileSystem* fileSystem, u64 titleID, AccountUid userID)
|
||||||
return fsOpen_SaveData(fs, title_id, uid);
|
{
|
||||||
|
return fsOpen_SaveData(fileSystem, titleID, userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
int file_system::mount(FsFileSystem fs) {
|
int FileSystem::mount(FsFileSystem fs)
|
||||||
|
{
|
||||||
return fsdevMountDevice("save", fs);
|
return fsdevMountDevice("save", fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_system::unmount() {
|
void FileSystem::unmount(void)
|
||||||
|
{
|
||||||
fsdevUnmountDevice("save");
|
fsdevUnmountDevice("save");
|
||||||
}
|
}
|
||||||
+162
-151
@@ -1,36 +1,57 @@
|
|||||||
// Copyright (C) 2024-2026 NXST contributors
|
/*
|
||||||
#include <cstdio>
|
* This file is part of Checkpoint
|
||||||
#include <sys/stat.h>
|
* Copyright (C) 2017-2021 Bernardo Giordano, FlagBrew
|
||||||
#include <unistd.h>
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <nxst/infra/fs/io.hpp>
|
||||||
|
#include <nxst/infra/fs/handles.hpp>
|
||||||
|
#include <nxst/app/main.hpp>
|
||||||
|
#include <nxst/infra/sys/logger.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <nxst/domain/account.hpp>
|
bool io::fileExists(const std::string& path)
|
||||||
#include <nxst/domain/title.hpp>
|
{
|
||||||
#include <nxst/domain/util.hpp>
|
|
||||||
#include <nxst/infra/fs/directory.hpp>
|
|
||||||
#include <nxst/infra/fs/filesystem.hpp>
|
|
||||||
#include <nxst/infra/fs/handles.hpp>
|
|
||||||
#include <nxst/infra/fs/io.hpp>
|
|
||||||
#include <nxst/infra/sys/logger.hpp>
|
|
||||||
|
|
||||||
static constexpr size_t kBufSize = 0x80000;
|
|
||||||
|
|
||||||
bool io::fileExists(const std::string& path) {
|
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
return (stat(path.c_str(), &buffer) == 0);
|
return (stat(path.c_str(), &buffer) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void io::copyFile(const std::string& srcPath, const std::string& dstPath) {
|
void io::copyFile(const std::string& srcPath, const std::string& dstPath)
|
||||||
|
{
|
||||||
|
g_isTransferringFile = true;
|
||||||
|
|
||||||
nxst::FileHandle src(fopen(srcPath.c_str(), "rb"));
|
nxst::FileHandle src(fopen(srcPath.c_str(), "rb"));
|
||||||
if (!src) {
|
if (!src) {
|
||||||
nxst::log::error("Failed to open source file %s during copy with errno %d. Skipping...",
|
nxst::log::error("Failed to open source file %s during copy with errno %d. Skipping...",
|
||||||
srcPath.c_str(), errno);
|
srcPath.c_str(), errno);
|
||||||
|
g_isTransferringFile = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nxst::FileHandle dst(fopen(dstPath.c_str(), "wb"));
|
nxst::FileHandle dst(fopen(dstPath.c_str(), "wb"));
|
||||||
if (!dst) {
|
if (!dst) {
|
||||||
nxst::log::error("Failed to open destination file %s during copy with errno %d. Skipping...",
|
nxst::log::error("Failed to open destination file %s during copy with errno %d. Skipping...",
|
||||||
dstPath.c_str(), errno);
|
dstPath.c_str(), errno);
|
||||||
|
g_isTransferringFile = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,31 +59,33 @@ void io::copyFile(const std::string& srcPath, const std::string& dstPath) {
|
|||||||
u64 sz = (u64)ftell(src.get());
|
u64 sz = (u64)ftell(src.get());
|
||||||
rewind(src.get());
|
rewind(src.get());
|
||||||
|
|
||||||
std::vector<u8> buf(kBufSize);
|
std::vector<u8> buf(BUFFER_SIZE);
|
||||||
u64 offset = 0;
|
u64 offset = 0;
|
||||||
|
|
||||||
|
size_t slashpos = srcPath.rfind('/');
|
||||||
|
g_currentFile = srcPath.substr(slashpos + 1, srcPath.length() - slashpos - 1);
|
||||||
|
|
||||||
while (offset < sz) {
|
while (offset < sz) {
|
||||||
u32 count = (u32)fread(buf.data(), 1, kBufSize, src.get());
|
u32 count = (u32)fread(buf.data(), 1, BUFFER_SIZE, src.get());
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
nxst::log::error("fread returned 0 for %s at offset %llu/%llu (errno %d). Aborting.",
|
nxst::log::error("fread returned 0 for %s at offset %llu/%llu (errno %d). Aborting.",
|
||||||
srcPath.c_str(), (unsigned long long)offset, (unsigned long long)sz, errno);
|
srcPath.c_str(), (unsigned long long)offset,
|
||||||
break;
|
(unsigned long long)sz, errno);
|
||||||
}
|
|
||||||
size_t written = fwrite(buf.data(), 1, count, dst.get());
|
|
||||||
if (written != count) {
|
|
||||||
nxst::log::error("fwrite incomplete for %s (%zu/%u bytes). Aborting.", dstPath.c_str(), written,
|
|
||||||
count);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
fwrite(buf.data(), 1, count, dst.get());
|
||||||
offset += count;
|
offset += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dstPath.rfind("save:/", 0) == 0) {
|
if (dstPath.rfind("save:/", 0) == 0) {
|
||||||
fsdevCommitDevice("save");
|
fsdevCommitDevice("save");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_isTransferringFile = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result io::copyDirectory(const std::string& srcPath, const std::string& dstPath) {
|
Result io::copyDirectory(const std::string& srcPath, const std::string& dstPath)
|
||||||
|
{
|
||||||
Result res = 0;
|
Result res = 0;
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
Directory items(srcPath);
|
Directory items(srcPath);
|
||||||
@@ -76,132 +99,130 @@ Result io::copyDirectory(const std::string& srcPath, const std::string& dstPath)
|
|||||||
std::string newdst = dstPath + items.entry(i);
|
std::string newdst = dstPath + items.entry(i);
|
||||||
|
|
||||||
if (items.folder(i)) {
|
if (items.folder(i)) {
|
||||||
res = createDirectory(newdst);
|
res = io::createDirectory(newdst);
|
||||||
if (R_SUCCEEDED(res)) {
|
if (R_SUCCEEDED(res)) {
|
||||||
newsrc += "/";
|
newsrc += "/";
|
||||||
newdst += "/";
|
newdst += "/";
|
||||||
res = copyDirectory(newsrc, newdst);
|
res = io::copyDirectory(newsrc, newdst);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
quit = true;
|
quit = true;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
copyFile(newsrc, newdst);
|
else {
|
||||||
|
io::copyFile(newsrc, newdst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result io::createDirectory(const std::string& path) {
|
|
||||||
if (mkdir(path.c_str(), 0777) != 0 && errno != EEXIST) {
|
|
||||||
nxst::log::error("mkdir failed for %s (errno %d).", path.c_str(), errno);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool io::directoryExists(const std::string& path) {
|
Result io::createDirectory(const std::string& path)
|
||||||
|
{
|
||||||
|
mkdir(path.c_str(), 0777);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool io::directoryExists(const std::string& path)
|
||||||
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
return (stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode));
|
return (stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result io::deleteFolderRecursively(const std::string& path) {
|
Result io::deleteFolderRecursively(const std::string& path)
|
||||||
|
{
|
||||||
Directory dir(path);
|
Directory dir(path);
|
||||||
if (!dir.good()) {
|
if (!dir.good()) {
|
||||||
return dir.error();
|
return dir.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result res = 0;
|
|
||||||
for (size_t i = 0, sz = dir.size(); i < sz; i++) {
|
for (size_t i = 0, sz = dir.size(); i < sz; i++) {
|
||||||
if (dir.folder(i)) {
|
if (dir.folder(i)) {
|
||||||
std::string sub = path + "/" + dir.entry(i);
|
std::string newpath = path + "/" + dir.entry(i) + "/";
|
||||||
Result sub_res = deleteFolderRecursively(sub + "/");
|
deleteFolderRecursively(newpath);
|
||||||
if (R_FAILED(sub_res))
|
newpath = path + dir.entry(i);
|
||||||
res = sub_res;
|
rmdir(newpath.c_str());
|
||||||
rmdir(sub.c_str());
|
}
|
||||||
} else {
|
else {
|
||||||
std::remove((path + dir.entry(i)).c_str());
|
std::string newpath = path + dir.entry(i);
|
||||||
|
std::remove(newpath.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rmdir(path.c_str());
|
rmdir(path.c_str());
|
||||||
return res;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxst::Result<std::string> io::backup(size_t index, AccountUid uid) {
|
nxst::Result<std::string> io::backup(size_t index, AccountUid uid)
|
||||||
|
{
|
||||||
Title title;
|
Title title;
|
||||||
getTitle(title, uid, index);
|
getTitle(title, uid, index);
|
||||||
|
|
||||||
nxst::log::info("Started backup of %s. Title id: 0x%016lX; User id: 0x%lX%lX.", title.name().c_str(),
|
nxst::log::info("Started backup of %s. Title id: 0x%016lX; User id: 0x%lX%lX.",
|
||||||
title.id(), title.userId().uid[1], title.userId().uid[0]);
|
title.name().c_str(), title.id(),
|
||||||
|
title.userId().uid[1], title.userId().uid[0]);
|
||||||
|
|
||||||
nxst::FsFileSystemHandle fs_handle;
|
nxst::FsFileSystemHandle fsHandle;
|
||||||
Result res = file_system::mount(fs_handle.get(), title.id(), title.userId());
|
Result res = FileSystem::mount(fsHandle.get(), title.id(), title.userId());
|
||||||
if (R_FAILED(res)) {
|
if (R_FAILED(res)) {
|
||||||
nxst::log::error("Failed to mount filesystem during backup with result 0x%08X. "
|
nxst::log::error("Failed to mount filesystem during backup with result 0x%08lX. "
|
||||||
"Title id: 0x%016lX; User id: 0x%lX%lX.",
|
"Title id: 0x%016lX; User id: 0x%lX%lX.",
|
||||||
res, title.id(), title.userId().uid[1], title.userId().uid[0]);
|
res, title.id(), title.userId().uid[1], title.userId().uid[0]);
|
||||||
return nxst::Result<std::string>::failure("Failed to mount save.");
|
return nxst::Result<std::string>::failure("Failed to mount save.");
|
||||||
}
|
}
|
||||||
fs_handle.valid = true;
|
fsHandle.valid = true;
|
||||||
|
|
||||||
if (file_system::mount(*fs_handle.get()) == -1) {
|
if (FileSystem::mount(*fsHandle.get()) == -1) {
|
||||||
nxst::log::error("Failed to mount devfs during backup. Title id: 0x%016lX; User id: 0x%lX%lX.",
|
nxst::log::error("Failed to mount devfs during backup. Title id: 0x%016lX; User id: 0x%lX%lX.",
|
||||||
title.id(), title.userId().uid[1], title.userId().uid[0]);
|
title.id(), title.userId().uid[1], title.userId().uid[0]);
|
||||||
file_system::unmount();
|
FileSystem::unmount();
|
||||||
return nxst::Result<std::string>::failure("Failed to mount save.");
|
return nxst::Result<std::string>::failure("Failed to mount save.");
|
||||||
}
|
}
|
||||||
fs_handle.release(); // devfs now owns the kernel handle
|
fsHandle.release(); // devfs now owns the kernel handle
|
||||||
|
|
||||||
std::string suggestion =
|
std::string suggestion = StringUtils::removeNotAscii(StringUtils::removeAccents(Account::username(title.userId())));
|
||||||
string_utils::removeNotAscii(string_utils::removeAccents(account::username(title.userId())));
|
|
||||||
|
|
||||||
io::createDirectory(title.path());
|
io::createDirectory(title.path());
|
||||||
std::string dst_path = title.path() + "/" + suggestion;
|
std::string dst_path = title.path() + "/" + suggestion;
|
||||||
std::string tmp_path = dst_path + ".tmp";
|
std::string tmp_path = dst_path + ".tmp";
|
||||||
|
|
||||||
if (io::directoryExists(tmp_path)) {
|
if (io::directoryExists(tmp_path)) {
|
||||||
if (R_FAILED(io::deleteFolderRecursively(tmp_path + "/")))
|
|
||||||
nxst::log::warn("Failed to clean up stale tmp dir %s.", tmp_path.c_str());
|
|
||||||
}
|
|
||||||
res = io::createDirectory(tmp_path);
|
|
||||||
if (R_FAILED(res)) {
|
|
||||||
file_system::unmount();
|
|
||||||
nxst::log::error("Failed to create tmp dir %s.", tmp_path.c_str());
|
|
||||||
return nxst::Result<std::string>::failure("Failed to create tmp directory.");
|
|
||||||
}
|
|
||||||
res = copyDirectory("save:/", tmp_path + "/");
|
|
||||||
if (R_FAILED(res)) {
|
|
||||||
file_system::unmount();
|
|
||||||
io::deleteFolderRecursively(tmp_path + "/");
|
io::deleteFolderRecursively(tmp_path + "/");
|
||||||
nxst::log::error("Failed to copy directory to %s with result 0x%08X.", tmp_path.c_str(), res);
|
}
|
||||||
|
io::createDirectory(tmp_path);
|
||||||
|
res = io::copyDirectory("save:/", tmp_path + "/");
|
||||||
|
if (R_FAILED(res)) {
|
||||||
|
FileSystem::unmount();
|
||||||
|
io::deleteFolderRecursively(tmp_path + "/");
|
||||||
|
nxst::log::error("Failed to copy directory to %s with result 0x%08lX.", tmp_path.c_str(), res);
|
||||||
return nxst::Result<std::string>::failure("Failed to backup save.");
|
return nxst::Result<std::string>::failure("Failed to backup save.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (io::directoryExists(dst_path)) {
|
if (io::directoryExists(dst_path)) {
|
||||||
if (R_FAILED(io::deleteFolderRecursively(dst_path + "/")))
|
io::deleteFolderRecursively(dst_path + "/");
|
||||||
nxst::log::warn("Failed to remove old backup at %s.", dst_path.c_str());
|
|
||||||
}
|
}
|
||||||
if (rename(tmp_path.c_str(), dst_path.c_str()) != 0) {
|
if (rename(tmp_path.c_str(), dst_path.c_str()) != 0) {
|
||||||
file_system::unmount();
|
FileSystem::unmount();
|
||||||
nxst::log::error("Failed to rename temp backup to %s.", dst_path.c_str());
|
nxst::log::error("Failed to rename temp backup to %s.", dst_path.c_str());
|
||||||
return nxst::Result<std::string>::failure("Failed to finalise backup.");
|
return nxst::Result<std::string>::failure("Failed to finalise backup.");
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshDirectories(title.id());
|
refreshDirectories(title.id());
|
||||||
file_system::unmount();
|
FileSystem::unmount();
|
||||||
|
|
||||||
nxst::log::info("Backup succeeded.");
|
nxst::log::info("Backup succeeded.");
|
||||||
return nxst::Result<std::string>::success(dst_path);
|
return nxst::Result<std::string>::success(dst_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates the save data filesystem for a title if it doesn't exist yet.
|
// Creates the save data filesystem for a title if it doesn't exist yet.
|
||||||
static void createSaveIfNeeded(u64 title_id, AccountUid uid) {
|
static void createSaveIfNeeded(u64 title_id, AccountUid uid)
|
||||||
|
{
|
||||||
std::vector<u8> nsacd_buf(sizeof(NsApplicationControlData), 0);
|
std::vector<u8> nsacd_buf(sizeof(NsApplicationControlData), 0);
|
||||||
auto* nsacd = reinterpret_cast<NsApplicationControlData*>(nsacd_buf.data());
|
auto* nsacd = reinterpret_cast<NsApplicationControlData*>(nsacd_buf.data());
|
||||||
|
|
||||||
size_t outsize = 0;
|
size_t outsize = 0;
|
||||||
if (!R_SUCCEEDED(nsGetApplicationControlData(NsApplicationControlSource_Storage, title_id, nsacd,
|
if (!R_SUCCEEDED(nsGetApplicationControlData(NsApplicationControlSource_Storage,
|
||||||
|
title_id, nsacd,
|
||||||
sizeof(NsApplicationControlData), &outsize))) {
|
sizeof(NsApplicationControlData), &outsize))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -224,7 +245,51 @@ static void createSaveIfNeeded(u64 title_id, AccountUid uid) {
|
|||||||
fsCreateSaveDataFileSystem(&attr, &create_info, &meta);
|
fsCreateSaveDataFileSystem(&attr, &create_info, &meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
static nxst::Result<void> clearSaveRoot(const std::string& dst_path) {
|
nxst::Result<std::string> io::restore(size_t index, AccountUid uid, size_t cellIndex, const std::string& nameFromCell)
|
||||||
|
{
|
||||||
|
(void)cellIndex;
|
||||||
|
|
||||||
|
Title title;
|
||||||
|
getTitle(title, uid, index);
|
||||||
|
|
||||||
|
nxst::log::info("Started restore of %s. Title id: 0x%016lX; User id: 0x%lX%lX.",
|
||||||
|
title.name().c_str(), title.id(),
|
||||||
|
title.userId().uid[1], title.userId().uid[0]);
|
||||||
|
|
||||||
|
createSaveIfNeeded(title.id(), uid);
|
||||||
|
|
||||||
|
nxst::FsFileSystemHandle fsHandle;
|
||||||
|
Result res = FileSystem::mount(fsHandle.get(), title.id(), uid);
|
||||||
|
if (R_FAILED(res)) {
|
||||||
|
nxst::log::error("Failed to mount filesystem during restore with result 0x%08lX. "
|
||||||
|
"Title id: 0x%016lX; User id: 0x%lX%lX.",
|
||||||
|
res, title.id(), uid.uid[1], uid.uid[0]);
|
||||||
|
return nxst::Result<std::string>::failure("Failed to mount save.");
|
||||||
|
}
|
||||||
|
fsHandle.valid = true;
|
||||||
|
|
||||||
|
if (FileSystem::mount(*fsHandle.get()) == -1) {
|
||||||
|
nxst::log::error("Failed to mount devfs during restore. Title id: 0x%016lX; User id: 0x%lX%lX.",
|
||||||
|
title.id(), uid.uid[1], uid.uid[0]);
|
||||||
|
FileSystem::unmount();
|
||||||
|
return nxst::Result<std::string>::failure("Failed to mount save.");
|
||||||
|
}
|
||||||
|
fsHandle.release(); // devfs now owns the kernel handle
|
||||||
|
|
||||||
|
std::string suggestion = StringUtils::removeNotAscii(StringUtils::removeAccents(Account::username(uid)));
|
||||||
|
std::string src_path = title.path() + "/" + suggestion + "/";
|
||||||
|
const std::string dst_path = "save:/";
|
||||||
|
|
||||||
|
{
|
||||||
|
Directory src_check(src_path);
|
||||||
|
if (!src_check.good() || src_check.size() == 0) {
|
||||||
|
FileSystem::unmount();
|
||||||
|
nxst::log::error("Restore source is empty or missing: %s", src_path.c_str());
|
||||||
|
return nxst::Result<std::string>::failure("Restore source is empty or missing.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
Directory save_root(dst_path);
|
Directory save_root(dst_path);
|
||||||
for (size_t i = 0, sz = save_root.size(); i < sz; i++) {
|
for (size_t i = 0, sz = save_root.size(); i < sz; i++) {
|
||||||
if (save_root.folder(i)) {
|
if (save_root.folder(i)) {
|
||||||
@@ -234,86 +299,32 @@ static nxst::Result<void> clearSaveRoot(const std::string& dst_path) {
|
|||||||
std::remove((dst_path + save_root.entry(i)).c_str());
|
std::remove((dst_path + save_root.entry(i)).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result res = fsdevCommitDevice("save");
|
|
||||||
if (R_FAILED(res)) {
|
|
||||||
nxst::log::error("Failed to commit save after clearing with result 0x%08X.", res);
|
|
||||||
return nxst::Result<void>::failure("Failed to commit save after delete.");
|
|
||||||
}
|
|
||||||
return nxst::Result<void>::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
static nxst::Result<void> extractAndCommit(const std::string& src_path, const std::string& dst_path) {
|
|
||||||
Result res = io::copyDirectory(src_path, dst_path);
|
|
||||||
if (R_FAILED(res)) {
|
|
||||||
nxst::log::error("Failed to copy %s to save:/ with result 0x%08X.", src_path.c_str(), res);
|
|
||||||
return nxst::Result<void>::failure("Failed to restore save.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = fsdevCommitDevice("save");
|
res = fsdevCommitDevice("save");
|
||||||
if (R_FAILED(res)) {
|
if (R_FAILED(res)) {
|
||||||
nxst::log::error("Failed to commit save with result 0x%08X.", res);
|
FileSystem::unmount();
|
||||||
return nxst::Result<void>::failure("Failed to commit to save device.");
|
nxst::log::error("Failed to commit save after clearing with result 0x%08lX.", res);
|
||||||
}
|
return nxst::Result<std::string>::failure("Failed to commit save after delete.");
|
||||||
return nxst::Result<void>::success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nxst::Result<std::string> io::restore(size_t index, AccountUid uid, const std::string& title_name) {
|
res = io::copyDirectory(src_path, dst_path);
|
||||||
Title title;
|
|
||||||
getTitle(title, uid, index);
|
|
||||||
|
|
||||||
nxst::log::info("Started restore of %s. Title id: 0x%016lX; User id: 0x%lX%lX.", title.name().c_str(),
|
|
||||||
title.id(), title.userId().uid[1], title.userId().uid[0]);
|
|
||||||
|
|
||||||
createSaveIfNeeded(title.id(), uid);
|
|
||||||
|
|
||||||
nxst::FsFileSystemHandle fs_handle;
|
|
||||||
Result res = file_system::mount(fs_handle.get(), title.id(), uid);
|
|
||||||
if (R_FAILED(res)) {
|
if (R_FAILED(res)) {
|
||||||
nxst::log::error("Failed to mount filesystem during restore with result 0x%08X. "
|
FileSystem::unmount();
|
||||||
"Title id: 0x%016lX; User id: 0x%lX%lX.",
|
nxst::log::error("Failed to copy %s to save:/ with result 0x%08lX.", src_path.c_str(), res);
|
||||||
res, title.id(), uid.uid[1], uid.uid[0]);
|
return nxst::Result<std::string>::failure("Failed to restore save.");
|
||||||
return nxst::Result<std::string>::failure("Failed to mount save.");
|
|
||||||
}
|
|
||||||
fs_handle.valid = true;
|
|
||||||
|
|
||||||
if (file_system::mount(*fs_handle.get()) == -1) {
|
|
||||||
nxst::log::error("Failed to mount devfs during restore. Title id: 0x%016lX; User id: 0x%lX%lX.",
|
|
||||||
title.id(), uid.uid[1], uid.uid[0]);
|
|
||||||
file_system::unmount();
|
|
||||||
return nxst::Result<std::string>::failure("Failed to mount save.");
|
|
||||||
}
|
|
||||||
fs_handle.release(); // devfs now owns the kernel handle
|
|
||||||
|
|
||||||
std::string suggestion =
|
|
||||||
string_utils::removeNotAscii(string_utils::removeAccents(account::username(uid)));
|
|
||||||
std::string src_path = title.path() + "/" + suggestion + "/";
|
|
||||||
const std::string dst_path = "save:/";
|
|
||||||
|
|
||||||
{
|
|
||||||
Directory src_check(src_path);
|
|
||||||
if (!src_check.good() || src_check.size() == 0) {
|
|
||||||
file_system::unmount();
|
|
||||||
nxst::log::error("Restore source is empty or missing: %s", src_path.c_str());
|
|
||||||
return nxst::Result<std::string>::failure("Restore source is empty or missing.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto clear_res = clearSaveRoot(dst_path);
|
res = fsdevCommitDevice("save");
|
||||||
if (!clear_res.isOk()) {
|
if (R_FAILED(res)) {
|
||||||
file_system::unmount();
|
FileSystem::unmount();
|
||||||
return nxst::Result<std::string>::failure(clear_res.error());
|
nxst::log::error("Failed to commit save with result 0x%08lX.", res);
|
||||||
}
|
return nxst::Result<std::string>::failure("Failed to commit to save device.");
|
||||||
|
|
||||||
auto extract_res = extractAndCommit(src_path, dst_path);
|
|
||||||
if (!extract_res.isOk()) {
|
|
||||||
file_system::unmount();
|
|
||||||
return nxst::Result<std::string>::failure(extract_res.error());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
blinkLed(4);
|
blinkLed(4);
|
||||||
file_system::unmount();
|
FileSystem::unmount();
|
||||||
|
|
||||||
nxst::log::info("Restore succeeded.");
|
nxst::log::info("Restore succeeded.");
|
||||||
return nxst::Result<std::string>::success(title_name + "\nhas been restored successfully.");
|
return nxst::Result<std::string>::success(nameFromCell + "\nhas been restored successfully.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
// Logic moved to src/service/transfer_service.cpp
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// Logic moved to src/service/transfer_service.cpp
|
||||||
+14
-40
@@ -1,10 +1,10 @@
|
|||||||
|
#include <nxst/infra/sys/logger.hpp>
|
||||||
|
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include <nxst/infra/sys/logger.hpp>
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::mutex g_log_mutex;
|
std::mutex g_log_mutex;
|
||||||
@@ -15,7 +15,8 @@ namespace {
|
|||||||
constexpr const char* kLogPath = "nxst.log";
|
constexpr const char* kLogPath = "nxst.log";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void writeEntry(const char* tag, const char* fmt, va_list args) {
|
void writeEntry(const char* tag, const char* fmt, va_list args)
|
||||||
|
{
|
||||||
char msg[2048];
|
char msg[2048];
|
||||||
vsnprintf(msg, sizeof(msg), fmt, args);
|
vsnprintf(msg, sizeof(msg), fmt, args);
|
||||||
|
|
||||||
@@ -40,21 +41,14 @@ namespace {
|
|||||||
|
|
||||||
namespace nxst::log {
|
namespace nxst::log {
|
||||||
|
|
||||||
void write(Level level, const char* fmt, ...) {
|
void write(Level level, const char* fmt, ...)
|
||||||
|
{
|
||||||
const char* tag = "[INFO] ";
|
const char* tag = "[INFO] ";
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case Level::Debug:
|
case Level::Debug: tag = "[DEBUG]"; break;
|
||||||
tag = "[DEBUG]";
|
case Level::Info: tag = "[INFO] "; break;
|
||||||
break;
|
case Level::Warn: tag = "[WARN] "; break;
|
||||||
case Level::Info:
|
case Level::Error: tag = "[ERROR]"; break;
|
||||||
tag = "[INFO] ";
|
|
||||||
break;
|
|
||||||
case Level::Warn:
|
|
||||||
tag = "[WARN] ";
|
|
||||||
break;
|
|
||||||
case Level::Error:
|
|
||||||
tag = "[ERROR]";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@@ -62,29 +56,9 @@ namespace nxst::log {
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug(const char* fmt, ...) {
|
void debug(const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[DEBUG]", fmt, args); va_end(args); }
|
||||||
va_list args;
|
void info (const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[INFO] ", fmt, args); va_end(args); }
|
||||||
va_start(args, fmt);
|
void warn (const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[WARN] ", fmt, args); va_end(args); }
|
||||||
writeEntry("[DEBUG]", fmt, args);
|
void error(const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[ERROR]", fmt, args); va_end(args); }
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
void info(const char* fmt, ...) {
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
writeEntry("[INFO] ", fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
void warn(const char* fmt, ...) {
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
writeEntry("[WARN] ", fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
void error(const char* fmt, ...) {
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
writeEntry("[ERROR]", fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace nxst::log
|
} // namespace nxst::log
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include <nxst/service/transfer_service.hpp>
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -10,14 +12,11 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <nxst/service/transfer_service.hpp>
|
|
||||||
|
|
||||||
#ifdef __SWITCH__
|
#ifdef __SWITCH__
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
#include <nxst/domain/account.hpp>
|
|
||||||
#include <nxst/domain/util.hpp>
|
|
||||||
#include <nxst/infra/fs/io.hpp>
|
#include <nxst/infra/fs/io.hpp>
|
||||||
|
#include <nxst/domain/util.hpp>
|
||||||
|
#include <nxst/domain/account.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <nxst/domain/protocol.hpp>
|
#include <nxst/domain/protocol.hpp>
|
||||||
@@ -33,8 +32,7 @@ namespace nxst {
|
|||||||
size_t sent = 0;
|
size_t sent = 0;
|
||||||
while (sent < len) {
|
while (sent < len) {
|
||||||
ssize_t n = send(sock, static_cast<const char*>(buf) + sent, len - sent, 0);
|
ssize_t n = send(sock, static_cast<const char*>(buf) + sent, len - sent, 0);
|
||||||
if (n <= 0)
|
if (n <= 0) return false;
|
||||||
return false;
|
|
||||||
sent += n;
|
sent += n;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -44,8 +42,7 @@ namespace nxst {
|
|||||||
size_t got = 0;
|
size_t got = 0;
|
||||||
while (got < len) {
|
while (got < len) {
|
||||||
ssize_t n = read(sock, static_cast<char*>(buf) + got, len - got);
|
ssize_t n = read(sock, static_cast<char*>(buf) + got, len - got);
|
||||||
if (n <= 0)
|
if (n <= 0) return false;
|
||||||
return false;
|
|
||||||
got += n;
|
got += n;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -53,30 +50,24 @@ namespace nxst {
|
|||||||
|
|
||||||
static bool sendFile(int sock, const fs::path& filepath, TransferState& state) {
|
static bool sendFile(int sock, const fs::path& filepath, TransferState& state) {
|
||||||
std::ifstream infile(filepath, std::ios::binary | std::ios::ate);
|
std::ifstream infile(filepath, std::ios::binary | std::ios::ate);
|
||||||
if (!infile.is_open())
|
if (!infile.is_open()) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
uint32_t filename_len = (uint32_t)filepath.string().size();
|
uint32_t filename_len = (uint32_t)filepath.string().size();
|
||||||
uint64_t file_size = (uint64_t)infile.tellg();
|
uint64_t file_size = (uint64_t)infile.tellg();
|
||||||
infile.seekg(0, std::ios::beg);
|
infile.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
if (!sendAll(sock, &filename_len, sizeof(filename_len)))
|
if (!sendAll(sock, &filename_len, sizeof(filename_len))) return false;
|
||||||
return false;
|
if (!sendAll(sock, filepath.c_str(), filename_len)) return false;
|
||||||
if (!sendAll(sock, filepath.c_str(), filename_len))
|
if (!sendAll(sock, &file_size, sizeof(file_size))) return false;
|
||||||
return false;
|
|
||||||
if (!sendAll(sock, &file_size, sizeof(file_size)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
std::vector<char> buffer(proto::kBufSize);
|
std::vector<char> buffer(proto::BUF_SIZE);
|
||||||
uint64_t remaining = file_size;
|
uint64_t remaining = file_size;
|
||||||
while (remaining > 0) {
|
while (remaining > 0) {
|
||||||
size_t to_read = (size_t)std::min(remaining, (uint64_t)proto::kBufSize);
|
size_t to_read = (size_t)std::min(remaining, (uint64_t)proto::BUF_SIZE);
|
||||||
infile.read(buffer.data(), (std::streamsize)to_read);
|
infile.read(buffer.data(), (std::streamsize)to_read);
|
||||||
std::streamsize count = infile.gcount();
|
std::streamsize count = infile.gcount();
|
||||||
if (count <= 0)
|
if (count <= 0) break;
|
||||||
break;
|
if (!sendAll(sock, buffer.data(), (size_t)count)) return false;
|
||||||
if (!sendAll(sock, buffer.data(), (size_t)count))
|
|
||||||
return false;
|
|
||||||
state.bytes_done.fetch_add((uint64_t)count);
|
state.bytes_done.fetch_add((uint64_t)count);
|
||||||
remaining -= (uint64_t)count;
|
remaining -= (uint64_t)count;
|
||||||
}
|
}
|
||||||
@@ -93,23 +84,22 @@ namespace nxst {
|
|||||||
mkdir(path.c_str(), 0777);
|
mkdir(path.c_str(), 0777);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void receiveFile(int sock, const std::string& rel_path, uint64_t file_size, TransferState& state) {
|
static void receiveFile(int sock, const std::string& rel_path, uint64_t file_size,
|
||||||
|
TransferState& state) {
|
||||||
size_t last_slash = rel_path.rfind('/');
|
size_t last_slash = rel_path.rfind('/');
|
||||||
if (last_slash != std::string::npos) {
|
if (last_slash != std::string::npos) {
|
||||||
std::string dir = rel_path.substr(0, last_slash);
|
std::string dir = rel_path.substr(0, last_slash);
|
||||||
if (!dir.empty())
|
if (!dir.empty()) mkdirs(dir);
|
||||||
mkdirs(dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* outfile = fopen(rel_path.c_str(), "wb");
|
FILE* outfile = fopen(rel_path.c_str(), "wb");
|
||||||
if (!outfile) {
|
if (!outfile) {
|
||||||
std::vector<char> drain(proto::kBufSize);
|
std::vector<char> drain(proto::BUF_SIZE);
|
||||||
uint64_t remaining = file_size;
|
uint64_t remaining = file_size;
|
||||||
while (remaining > 0) {
|
while (remaining > 0) {
|
||||||
size_t to_read = (size_t)std::min(remaining, (uint64_t)proto::kBufSize);
|
size_t to_read = (size_t)std::min(remaining, (uint64_t)proto::BUF_SIZE);
|
||||||
ssize_t n = read(sock, drain.data(), to_read);
|
ssize_t n = read(sock, drain.data(), to_read);
|
||||||
if (n <= 0)
|
if (n <= 0) break;
|
||||||
break;
|
|
||||||
remaining -= (uint64_t)n;
|
remaining -= (uint64_t)n;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -118,13 +108,12 @@ namespace nxst {
|
|||||||
state.bytes_total.store(file_size);
|
state.bytes_total.store(file_size);
|
||||||
state.bytes_done.store(0);
|
state.bytes_done.store(0);
|
||||||
|
|
||||||
std::vector<char> buffer(proto::kBufSize);
|
std::vector<char> buffer(proto::BUF_SIZE);
|
||||||
uint64_t total = 0;
|
uint64_t total = 0;
|
||||||
while (total < file_size) {
|
while (total < file_size) {
|
||||||
size_t to_read = (size_t)std::min(file_size - total, (uint64_t)proto::kBufSize);
|
size_t to_read = (size_t)std::min(file_size - total, (uint64_t)proto::BUF_SIZE);
|
||||||
ssize_t n = read(sock, buffer.data(), to_read);
|
ssize_t n = read(sock, buffer.data(), to_read);
|
||||||
if (n <= 0)
|
if (n <= 0) break;
|
||||||
break;
|
|
||||||
fwrite(buffer.data(), 1, (size_t)n, outfile);
|
fwrite(buffer.data(), 1, (size_t)n, outfile);
|
||||||
total += (uint64_t)n;
|
total += (uint64_t)n;
|
||||||
state.bytes_done.store(total);
|
state.bytes_done.store(total);
|
||||||
@@ -142,20 +131,18 @@ namespace nxst {
|
|||||||
|
|
||||||
int TransferService::findServer(char* out_ip) {
|
int TransferService::findServer(char* out_ip) {
|
||||||
int udp_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
int udp_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (udp_fd < 0)
|
if (udp_fd < 0) return -1;
|
||||||
return -1;
|
|
||||||
sender_udp_sock.store(udp_fd);
|
sender_udp_sock.store(udp_fd);
|
||||||
|
|
||||||
auto releaseUdp = [&]() {
|
auto releaseUdp = [&]() {
|
||||||
int owned = sender_udp_sock.exchange(-1);
|
int owned = sender_udp_sock.exchange(-1);
|
||||||
if (owned == udp_fd)
|
if (owned == udp_fd) close(udp_fd);
|
||||||
close(udp_fd);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sockaddr_in addr{};
|
sockaddr_in addr{};
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(proto::kMulticastPort);
|
addr.sin_port = htons(proto::MULTICAST_PORT);
|
||||||
addr.sin_addr.s_addr = inet_addr(proto::kMulticastGroup);
|
addr.sin_addr.s_addr = inet_addr(proto::MULTICAST_GROUP);
|
||||||
|
|
||||||
if (sendto(udp_fd, "DISCOVER_SERVER", 15, 0, (sockaddr*)&addr, sizeof(addr)) < 0) {
|
if (sendto(udp_fd, "DISCOVER_SERVER", 15, 0, (sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||||
releaseUdp();
|
releaseUdp();
|
||||||
@@ -165,10 +152,7 @@ namespace nxst {
|
|||||||
// Poll in 100ms slices so cancel races within 100ms
|
// Poll in 100ms slices so cancel races within 100ms
|
||||||
auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(3);
|
auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(3);
|
||||||
while (std::chrono::steady_clock::now() < deadline) {
|
while (std::chrono::steady_clock::now() < deadline) {
|
||||||
if (sender_state.cancelled.load()) {
|
if (sender_state.cancelled.load()) { releaseUdp(); return -1; }
|
||||||
releaseUdp();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
struct timeval tv{0, 100000};
|
struct timeval tv{0, 100000};
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
@@ -216,8 +200,7 @@ namespace nxst {
|
|||||||
failSend("No receiver found.\nMake sure the other Switch is in Receive mode.");
|
failSend("No receiver found.\nMake sure the other Switch is in Receive mode.");
|
||||||
return finish();
|
return finish();
|
||||||
}
|
}
|
||||||
if (sender_state.cancelled.load())
|
if (sender_state.cancelled.load()) return finish();
|
||||||
return finish();
|
|
||||||
|
|
||||||
sender_state.setStatus("Creating backup...");
|
sender_state.setStatus("Creating backup...");
|
||||||
#ifdef __SWITCH__
|
#ifdef __SWITCH__
|
||||||
@@ -229,30 +212,24 @@ namespace nxst {
|
|||||||
fs::path directory = backup_result.value();
|
fs::path directory = backup_result.value();
|
||||||
#else
|
#else
|
||||||
fs::path directory = ".";
|
fs::path directory = ".";
|
||||||
(void)title_index;
|
(void)title_index; (void)uid;
|
||||||
(void)uid;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (sender_state.cancelled.load())
|
if (sender_state.cancelled.load()) return finish();
|
||||||
return finish();
|
|
||||||
|
|
||||||
sender_state.setStatus("Connecting...");
|
sender_state.setStatus("Connecting...");
|
||||||
int tcp_fd = socket(AF_INET, SOCK_STREAM, 0);
|
int tcp_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (tcp_fd < 0) {
|
if (tcp_fd < 0) { failSend("Failed to open socket."); return finish(); }
|
||||||
failSend("Failed to open socket.");
|
|
||||||
return finish();
|
|
||||||
}
|
|
||||||
sender_tcp_sock.store(tcp_fd);
|
sender_tcp_sock.store(tcp_fd);
|
||||||
|
|
||||||
auto releaseTcp = [&]() {
|
auto releaseTcp = [&]() {
|
||||||
int owned = sender_tcp_sock.exchange(-1);
|
int owned = sender_tcp_sock.exchange(-1);
|
||||||
if (owned == tcp_fd)
|
if (owned == tcp_fd) close(tcp_fd);
|
||||||
close(tcp_fd);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sockaddr_in serv{};
|
sockaddr_in serv{};
|
||||||
serv.sin_family = AF_INET;
|
serv.sin_family = AF_INET;
|
||||||
serv.sin_port = htons(proto::kTcpPort);
|
serv.sin_port = htons(proto::TCP_PORT);
|
||||||
if (inet_pton(AF_INET, server_ip, &serv.sin_addr) <= 0 ||
|
if (inet_pton(AF_INET, server_ip, &serv.sin_addr) <= 0 ||
|
||||||
connect(tcp_fd, (sockaddr*)&serv, sizeof(serv)) < 0) {
|
connect(tcp_fd, (sockaddr*)&serv, sizeof(serv)) < 0) {
|
||||||
if (!sender_state.cancelled.load())
|
if (!sender_state.cancelled.load())
|
||||||
@@ -268,17 +245,15 @@ namespace nxst {
|
|||||||
sender_state.bytes_total.store(total);
|
sender_state.bytes_total.store(total);
|
||||||
|
|
||||||
for (const auto& entry : fs::recursive_directory_iterator(directory)) {
|
for (const auto& entry : fs::recursive_directory_iterator(directory)) {
|
||||||
if (sender_state.cancelled.load())
|
if (sender_state.cancelled.load()) break;
|
||||||
break;
|
|
||||||
const fs::path& p = entry.path();
|
const fs::path& p = entry.path();
|
||||||
if (fs::is_regular_file(p)) {
|
if (fs::is_regular_file(p)) {
|
||||||
sender_state.setStatus(p.filename().string());
|
sender_state.setStatus(p.filename().string());
|
||||||
if (!sendFile(tcp_fd, p, sender_state))
|
if (!sendFile(tcp_fd, p, sender_state)) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sentinel = proto::kEofSentinel;
|
uint32_t sentinel = proto::EOF_SENTINEL;
|
||||||
sendAll(tcp_fd, &sentinel, sizeof(sentinel));
|
sendAll(tcp_fd, &sentinel, sizeof(sentinel));
|
||||||
|
|
||||||
releaseTcp();
|
releaseTcp();
|
||||||
@@ -303,26 +278,19 @@ namespace nxst {
|
|||||||
void TransferService::cancelSend() {
|
void TransferService::cancelSend() {
|
||||||
sender_state.cancelled.store(true);
|
sender_state.cancelled.store(true);
|
||||||
int udp = sender_udp_sock.exchange(-1);
|
int udp = sender_udp_sock.exchange(-1);
|
||||||
if (udp >= 0) {
|
if (udp >= 0) { shutdown(udp, SHUT_RDWR); close(udp); }
|
||||||
shutdown(udp, SHUT_RDWR);
|
|
||||||
close(udp);
|
|
||||||
}
|
|
||||||
int tcp = sender_tcp_sock.exchange(-1);
|
int tcp = sender_tcp_sock.exchange(-1);
|
||||||
if (tcp >= 0) {
|
if (tcp >= 0) { shutdown(tcp, SHUT_RDWR); close(tcp); }
|
||||||
shutdown(tcp, SHUT_RDWR);
|
|
||||||
close(tcp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Receiver ────────────────────────────────────────────────────────────────
|
// ─── Receiver ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
std::string TransferService::replaceUsername(const std::string& file_path) const {
|
std::string TransferService::replaceUsername(const std::string& file_path) const {
|
||||||
#ifdef __SWITCH__
|
#ifdef __SWITCH__
|
||||||
std::string username =
|
std::string username = StringUtils::removeNotAscii(
|
||||||
string_utils::removeNotAscii(string_utils::removeAccents(account::username(restore_uid)));
|
StringUtils::removeAccents(Account::username(restore_uid)));
|
||||||
size_t last_slash = file_path.rfind('/');
|
size_t last_slash = file_path.rfind('/');
|
||||||
if (last_slash == std::string::npos)
|
if (last_slash == std::string::npos) return file_path;
|
||||||
return file_path;
|
|
||||||
size_t prev_slash = file_path.rfind('/', last_slash - 1);
|
size_t prev_slash = file_path.rfind('/', last_slash - 1);
|
||||||
if (prev_slash == std::string::npos)
|
if (prev_slash == std::string::npos)
|
||||||
return username + file_path.substr(last_slash);
|
return username + file_path.substr(last_slash);
|
||||||
@@ -343,16 +311,12 @@ namespace nxst {
|
|||||||
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, nullptr);
|
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, nullptr);
|
||||||
|
|
||||||
int udp = socket(AF_INET, SOCK_DGRAM, 0);
|
int udp = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (udp < 0) {
|
if (udp < 0) { receiver_broadcast_active.store(false); return; }
|
||||||
receiver_broadcast_active.store(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
receiver_bcast_sock.store(udp);
|
receiver_bcast_sock.store(udp);
|
||||||
|
|
||||||
auto releaseUdp = [&]() {
|
auto releaseUdp = [&]() {
|
||||||
int owned = receiver_bcast_sock.exchange(-1);
|
int owned = receiver_bcast_sock.exchange(-1);
|
||||||
if (owned == udp)
|
if (owned == udp) close(udp);
|
||||||
close(udp);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct timeval tv{0, 20000}; // 20ms poll so cancel/exit wins race with socketExit
|
struct timeval tv{0, 20000}; // 20ms poll so cancel/exit wins race with socketExit
|
||||||
@@ -361,7 +325,7 @@ namespace nxst {
|
|||||||
sockaddr_in addr{};
|
sockaddr_in addr{};
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
addr.sin_port = htons(proto::kMulticastPort);
|
addr.sin_port = htons(proto::MULTICAST_PORT);
|
||||||
|
|
||||||
if (bind(udp, (sockaddr*)&addr, sizeof(addr)) < 0) {
|
if (bind(udp, (sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||||
releaseUdp();
|
releaseUdp();
|
||||||
@@ -370,7 +334,7 @@ namespace nxst {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ip_mreq group{};
|
ip_mreq group{};
|
||||||
group.imr_multiaddr.s_addr = inet_addr(proto::kMulticastGroup);
|
group.imr_multiaddr.s_addr = inet_addr(proto::MULTICAST_GROUP);
|
||||||
group.imr_interface.s_addr = htonl(INADDR_ANY);
|
group.imr_interface.s_addr = htonl(INADDR_ANY);
|
||||||
if (setsockopt(udp, IPPROTO_IP, IP_ADD_MEMBERSHIP, &group, sizeof(group)) < 0) {
|
if (setsockopt(udp, IPPROTO_IP, IP_ADD_MEMBERSHIP, &group, sizeof(group)) < 0) {
|
||||||
releaseUdp();
|
releaseUdp();
|
||||||
@@ -384,8 +348,7 @@ namespace nxst {
|
|||||||
while (true) {
|
while (true) {
|
||||||
ssize_t n = recvfrom(udp, buf, sizeof(buf) - 1, 0, (sockaddr*)&from, &fromlen);
|
ssize_t n = recvfrom(udp, buf, sizeof(buf) - 1, 0, (sockaddr*)&from, &fromlen);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (receiver_state.cancelled.load())
|
if (receiver_state.cancelled.load()) break;
|
||||||
break;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
buf[n] = '\0';
|
buf[n] = '\0';
|
||||||
@@ -417,47 +380,40 @@ namespace nxst {
|
|||||||
int client_sock = accept(server_fd, (sockaddr*)&client_addr, &client_len);
|
int client_sock = accept(server_fd, (sockaddr*)&client_addr, &client_len);
|
||||||
|
|
||||||
int owned_listen = receiver_listen_sock.exchange(-1);
|
int owned_listen = receiver_listen_sock.exchange(-1);
|
||||||
if (owned_listen == server_fd)
|
if (owned_listen == server_fd) close(server_fd);
|
||||||
close(server_fd);
|
|
||||||
|
|
||||||
if (client_sock >= 0) {
|
if (client_sock >= 0) {
|
||||||
receiver_client_sock.store(client_sock);
|
receiver_client_sock.store(client_sock);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
uint32_t filename_len = 0;
|
uint32_t filename_len = 0;
|
||||||
if (!recvAll(client_sock, &filename_len, sizeof(filename_len)))
|
if (!recvAll(client_sock, &filename_len, sizeof(filename_len))) break;
|
||||||
break;
|
if (filename_len == proto::EOF_SENTINEL) break;
|
||||||
if (filename_len == proto::kEofSentinel)
|
if (filename_len > proto::MAX_FILENAME) break;
|
||||||
break;
|
|
||||||
if (filename_len > proto::kMaxFilename)
|
|
||||||
break;
|
|
||||||
|
|
||||||
std::vector<char> filename_buf(filename_len + 1, '\0');
|
std::vector<char> filename_buf(filename_len + 1, '\0');
|
||||||
if (!recvAll(client_sock, filename_buf.data(), filename_len))
|
if (!recvAll(client_sock, filename_buf.data(), filename_len)) break;
|
||||||
break;
|
|
||||||
std::string filename_str(filename_buf.data(), filename_len);
|
std::string filename_str(filename_buf.data(), filename_len);
|
||||||
filename_str = replaceUsername(filename_str);
|
filename_str = replaceUsername(filename_str);
|
||||||
|
|
||||||
{
|
{
|
||||||
size_t sl = filename_str.rfind('/');
|
size_t sl = filename_str.rfind('/');
|
||||||
receiver_state.setStatus(sl != std::string::npos ? filename_str.substr(sl + 1)
|
receiver_state.setStatus(
|
||||||
: filename_str);
|
sl != std::string::npos ? filename_str.substr(sl + 1) : filename_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t file_size = 0;
|
uint64_t file_size = 0;
|
||||||
if (!recvAll(client_sock, &file_size, sizeof(file_size)))
|
if (!recvAll(client_sock, &file_size, sizeof(file_size))) break;
|
||||||
break;
|
|
||||||
receiveFile(client_sock, filename_str, file_size, receiver_state);
|
receiveFile(client_sock, filename_str, file_size, receiver_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int owned = receiver_client_sock.exchange(-1);
|
int owned = receiver_client_sock.exchange(-1);
|
||||||
if (owned == client_sock)
|
if (owned == client_sock) close(client_sock);
|
||||||
close(client_sock);
|
|
||||||
|
|
||||||
if (!receiver_state.cancelled.load()) {
|
if (!receiver_state.cancelled.load()) {
|
||||||
#ifdef __SWITCH__
|
#ifdef __SWITCH__
|
||||||
receiver_state.setStatus("Restoring...");
|
receiver_state.setStatus("Restoring...");
|
||||||
auto result = io::restore(restore_title_index, restore_uid, restore_title_name);
|
auto result = io::restore(restore_title_index, restore_uid, 0, restore_title_name);
|
||||||
restore_ok = result.isOk();
|
restore_ok = result.isOk();
|
||||||
restore_error = result.isOk() ? "" : result.error();
|
restore_error = result.isOk() ? "" : result.error();
|
||||||
#else
|
#else
|
||||||
@@ -480,16 +436,12 @@ namespace nxst {
|
|||||||
restore_error.clear();
|
restore_error.clear();
|
||||||
|
|
||||||
pthread_t bcast_thread;
|
pthread_t bcast_thread;
|
||||||
if (pthread_create(&bcast_thread, nullptr, broadcastEntry, this) != 0)
|
if (pthread_create(&bcast_thread, nullptr, broadcastEntry, this) != 0) return 1;
|
||||||
return 1;
|
|
||||||
receiver_bcast_thread = bcast_thread;
|
receiver_bcast_thread = bcast_thread;
|
||||||
pthread_detach(bcast_thread);
|
pthread_detach(bcast_thread);
|
||||||
|
|
||||||
Socket server(socket(AF_INET, SOCK_STREAM, 0));
|
Socket server(socket(AF_INET, SOCK_STREAM, 0));
|
||||||
if (!server.valid()) {
|
if (!server.valid()) { cancelReceive(); return 1; }
|
||||||
cancelReceive();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
|
setsockopt(server, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
|
||||||
@@ -497,9 +449,10 @@ namespace nxst {
|
|||||||
sockaddr_in addr{};
|
sockaddr_in addr{};
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = INADDR_ANY;
|
addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
addr.sin_port = htons(proto::kTcpPort);
|
addr.sin_port = htons(proto::TCP_PORT);
|
||||||
|
|
||||||
if (bind(server, (sockaddr*)&addr, sizeof(addr)) < 0 || listen(server, 3) < 0) {
|
if (bind(server, (sockaddr*)&addr, sizeof(addr)) < 0 ||
|
||||||
|
listen(server, 3) < 0) {
|
||||||
cancelReceive();
|
cancelReceive();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -519,22 +472,12 @@ namespace nxst {
|
|||||||
void TransferService::cancelReceive() {
|
void TransferService::cancelReceive() {
|
||||||
receiver_state.cancelled.store(true);
|
receiver_state.cancelled.store(true);
|
||||||
int sock = receiver_client_sock.exchange(-1);
|
int sock = receiver_client_sock.exchange(-1);
|
||||||
if (sock >= 0) {
|
if (sock >= 0) { shutdown(sock, SHUT_RDWR); close(sock); }
|
||||||
shutdown(sock, SHUT_RDWR);
|
|
||||||
close(sock);
|
|
||||||
}
|
|
||||||
int lsock = receiver_listen_sock.exchange(-1);
|
int lsock = receiver_listen_sock.exchange(-1);
|
||||||
if (lsock >= 0) {
|
if (lsock >= 0) { shutdown(lsock, SHUT_RDWR); close(lsock); }
|
||||||
shutdown(lsock, SHUT_RDWR);
|
|
||||||
close(lsock);
|
|
||||||
}
|
|
||||||
int bsock = receiver_bcast_sock.exchange(-1);
|
int bsock = receiver_bcast_sock.exchange(-1);
|
||||||
if (bsock >= 0) {
|
if (bsock >= 0) { shutdown(bsock, SHUT_RDWR); close(bsock); }
|
||||||
shutdown(bsock, SHUT_RDWR);
|
if (receiver_broadcast_active.load()) pthread_cancel(receiver_bcast_thread);
|
||||||
close(bsock);
|
|
||||||
}
|
|
||||||
if (receiver_broadcast_active.load())
|
|
||||||
pthread_cancel(receiver_bcast_thread);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace nxst
|
} // namespace nxst
|
||||||
|
|||||||
+43
-45
@@ -1,6 +1,7 @@
|
|||||||
#include <nxst/app/main_application.hpp>
|
#include <nxst/app/main_application.hpp>
|
||||||
#include <nxst/domain/util.hpp>
|
#include <nxst/domain/util.hpp>
|
||||||
#include <nxst/ui/transfer_overlay.hpp>
|
#include <nxst/ui/transfer_overlay.hpp>
|
||||||
|
#include <nxst/ui/const.h>
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
extern MainApplication *mainApp;
|
extern MainApplication *mainApp;
|
||||||
@@ -14,70 +15,75 @@ namespace ui {
|
|||||||
constexpr int ContentH = theme::layout::ContentH - 2 * theme::space::md;
|
constexpr int ContentH = theme::layout::ContentH - 2 * theme::space::md;
|
||||||
constexpr int BtnH = 56;
|
constexpr int BtnH = 56;
|
||||||
constexpr int BtnW = PanelW - 2 * theme::space::lg;
|
constexpr int BtnW = PanelW - 2 * theme::space::lg;
|
||||||
} // namespace
|
}
|
||||||
|
|
||||||
TitlesLayout::TitlesLayout() {
|
TitlesLayout::TitlesLayout() : Layout::Layout() {
|
||||||
using namespace theme;
|
using namespace theme;
|
||||||
|
|
||||||
this->titlesMenu =
|
this->titlesMenu = pu::ui::elm::Menu::New(
|
||||||
pu::ui::elm::Menu::New(ListX, ContentY, ListW, color::BgBase, color::BgSurface2, 88, 6);
|
ListX, ContentY, ListW,
|
||||||
|
color::BgBase, color::BgSurface2,
|
||||||
|
88, 6);
|
||||||
this->titlesMenu->SetScrollbarColor(color::Primary);
|
this->titlesMenu->SetScrollbarColor(color::Primary);
|
||||||
this->titlesMenu->SetItemsFocusColor(color::BgSurface2);
|
this->titlesMenu->SetItemsFocusColor(color::BgSurface2);
|
||||||
this->titlesMenu->SetOnSelectionChanged([this]() {
|
this->titlesMenu->SetOnSelectionChanged([this]() { this->refreshPanel(); });
|
||||||
this->refreshPanel();
|
|
||||||
});
|
|
||||||
this->SetBackgroundColor(color::BgBase);
|
this->SetBackgroundColor(color::BgBase);
|
||||||
this->Add(this->titlesMenu);
|
this->Add(this->titlesMenu);
|
||||||
|
|
||||||
this->panelBg =
|
this->panelBg = pu::ui::elm::Rectangle::New(
|
||||||
pu::ui::elm::Rectangle::New(PanelX, ContentY, PanelW, ContentH, color::BgSurface, radius::lg);
|
PanelX, ContentY, PanelW, ContentH, color::BgSurface, radius::lg);
|
||||||
this->Add(this->panelBg);
|
this->Add(this->panelBg);
|
||||||
|
|
||||||
this->panelTitle = pu::ui::elm::TextBlock::New(PanelX + space::lg, ContentY + space::lg, "");
|
this->panelTitle = pu::ui::elm::TextBlock::New(
|
||||||
|
PanelX + space::lg, ContentY + space::lg, "");
|
||||||
this->panelTitle->SetFont(type::font(type::Title));
|
this->panelTitle->SetFont(type::font(type::Title));
|
||||||
this->panelTitle->SetColor(color::TextPrimary);
|
this->panelTitle->SetColor(color::TextPrimary);
|
||||||
this->Add(this->panelTitle);
|
this->Add(this->panelTitle);
|
||||||
|
|
||||||
this->panelHint =
|
this->panelHint = pu::ui::elm::TextBlock::New(
|
||||||
pu::ui::elm::TextBlock::New(PanelX + space::lg, ContentY + space::lg + 48, "Pick an action:");
|
PanelX + space::lg, ContentY + space::lg + 48, "Pick an action:");
|
||||||
this->panelHint->SetFont(type::font(type::Body));
|
this->panelHint->SetFont(type::font(type::Body));
|
||||||
this->panelHint->SetColor(color::TextSecondary);
|
this->panelHint->SetColor(color::TextSecondary);
|
||||||
this->Add(this->panelHint);
|
this->Add(this->panelHint);
|
||||||
|
|
||||||
int btnY = ContentY + 200;
|
int btnY = ContentY + 200;
|
||||||
this->btnTransferBg =
|
this->btnTransferBg = pu::ui::elm::Rectangle::New(
|
||||||
pu::ui::elm::Rectangle::New(PanelX + space::lg, btnY, BtnW, BtnH, color::BgSurface2, radius::md);
|
PanelX + space::lg, btnY, BtnW, BtnH, color::BgSurface2, radius::md);
|
||||||
this->Add(this->btnTransferBg);
|
this->Add(this->btnTransferBg);
|
||||||
this->btnTransferText = pu::ui::elm::TextBlock::New(PanelX + space::lg + space::md, btnY + 14,
|
this->btnTransferText = pu::ui::elm::TextBlock::New(
|
||||||
"Transfer to another device");
|
PanelX + space::lg + space::md, btnY + 14, "Transfer to another device");
|
||||||
this->btnTransferText->SetFont(type::font(type::Body));
|
this->btnTransferText->SetFont(type::font(type::Body));
|
||||||
this->btnTransferText->SetColor(color::TextSecondary);
|
this->btnTransferText->SetColor(color::TextSecondary);
|
||||||
this->Add(this->btnTransferText);
|
this->Add(this->btnTransferText);
|
||||||
|
|
||||||
int btnY2 = btnY + BtnH + space::md;
|
int btnY2 = btnY + BtnH + space::md;
|
||||||
this->btnReceiveBg =
|
this->btnReceiveBg = pu::ui::elm::Rectangle::New(
|
||||||
pu::ui::elm::Rectangle::New(PanelX + space::lg, btnY2, BtnW, BtnH, color::BgSurface2, radius::md);
|
PanelX + space::lg, btnY2, BtnW, BtnH, color::BgSurface2, radius::md);
|
||||||
this->Add(this->btnReceiveBg);
|
this->Add(this->btnReceiveBg);
|
||||||
this->btnReceiveText = pu::ui::elm::TextBlock::New(PanelX + space::lg + space::md, btnY2 + 14,
|
this->btnReceiveText = pu::ui::elm::TextBlock::New(
|
||||||
"Receive from another device");
|
PanelX + space::lg + space::md, btnY2 + 14, "Receive from another device");
|
||||||
this->btnReceiveText->SetFont(type::font(type::Body));
|
this->btnReceiveText->SetFont(type::font(type::Body));
|
||||||
this->btnReceiveText->SetColor(color::TextSecondary);
|
this->btnReceiveText->SetColor(color::TextSecondary);
|
||||||
this->Add(this->btnReceiveText);
|
this->Add(this->btnReceiveText);
|
||||||
|
|
||||||
this->panelFooter = pu::ui::elm::TextBlock::New(
|
this->panelFooter = pu::ui::elm::TextBlock::New(
|
||||||
PanelX + space::lg, ContentY + ContentH - space::lg - 18, "Save data only");
|
PanelX + space::lg,
|
||||||
|
ContentY + ContentH - space::lg - 18,
|
||||||
|
"Save data only");
|
||||||
this->panelFooter->SetFont(type::font(type::Caption));
|
this->panelFooter->SetFont(type::font(type::Caption));
|
||||||
this->panelFooter->SetColor(color::TextMuted);
|
this->panelFooter->SetColor(color::TextMuted);
|
||||||
this->Add(this->panelFooter);
|
this->Add(this->panelFooter);
|
||||||
|
|
||||||
this->emptyText = pu::ui::elm::TextBlock::New(ListX + ListW / 2 - 280, ContentY + ContentH / 2 - 40,
|
this->emptyText = pu::ui::elm::TextBlock::New(
|
||||||
|
ListX + ListW / 2 - 280, ContentY + ContentH / 2 - 40,
|
||||||
"No save data on this profile");
|
"No save data on this profile");
|
||||||
this->emptyText->SetFont(type::font(type::Display));
|
this->emptyText->SetFont(type::font(type::Display));
|
||||||
this->emptyText->SetColor(color::TextPrimary);
|
this->emptyText->SetColor(color::TextPrimary);
|
||||||
this->emptyText->SetVisible(false);
|
this->emptyText->SetVisible(false);
|
||||||
this->Add(this->emptyText);
|
this->Add(this->emptyText);
|
||||||
|
|
||||||
this->emptySub = pu::ui::elm::TextBlock::New(ListX + ListW / 2 - 220, ContentY + ContentH / 2 + 16,
|
this->emptySub = pu::ui::elm::TextBlock::New(
|
||||||
|
ListX + ListW / 2 - 220, ContentY + ContentH / 2 + 16,
|
||||||
"Play something first, then come back.");
|
"Play something first, then come back.");
|
||||||
this->emptySub->SetFont(type::font(type::Body));
|
this->emptySub->SetFont(type::font(type::Body));
|
||||||
this->emptySub->SetColor(color::TextMuted);
|
this->emptySub->SetColor(color::TextMuted);
|
||||||
@@ -135,16 +141,15 @@ namespace ui {
|
|||||||
this->refreshButtons();
|
this->refreshButtons();
|
||||||
this->updateHints();
|
this->updateHints();
|
||||||
|
|
||||||
this->header->SetUser(uid, account::username(uid));
|
this->header->SetUser(uid, Account::username(uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitlesLayout::refreshPanel() {
|
void TitlesLayout::refreshPanel() {
|
||||||
if (this->titlesMenu->GetItems().empty())
|
if (this->titlesMenu->GetItems().empty()) return;
|
||||||
return;
|
|
||||||
int idx = this->titlesMenu->GetSelectedIndex();
|
int idx = this->titlesMenu->GetSelectedIndex();
|
||||||
Title title;
|
Title title;
|
||||||
getTitle(title, this->current_uid, idx);
|
getTitle(title, this->current_uid, idx);
|
||||||
this->panelTitle->SetText(string_utils::elide(title.name(), 24));
|
this->panelTitle->SetText(StringUtils::elide(title.name(), 24));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitlesLayout::refreshButtons() {
|
void TitlesLayout::refreshButtons() {
|
||||||
@@ -214,8 +219,7 @@ namespace ui {
|
|||||||
|
|
||||||
void TitlesLayout::runReceive(int index, Title& title) {
|
void TitlesLayout::runReceive(int index, Title& title) {
|
||||||
if (mainApp->transfer.startReceive((size_t)index, this->current_uid, title.name()) != 0) {
|
if (mainApp->transfer.startReceive((size_t)index, this->current_uid, title.name()) != 0) {
|
||||||
mainApp->CreateShowDialog("Receive", "Failed to start receiver.\nCheck network connection.",
|
mainApp->CreateShowDialog("Receive", "Failed to start receiver.\nCheck network connection.", {"OK"}, true);
|
||||||
{"OK"}, true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto ovl = TransferOverlay::New("Receiving save data...");
|
auto ovl = TransferOverlay::New("Receiving save data...");
|
||||||
@@ -238,20 +242,15 @@ namespace ui {
|
|||||||
if (mainApp->transfer.isReceiveCancelled()) {
|
if (mainApp->transfer.isReceiveCancelled()) {
|
||||||
mainApp->CreateShowDialog("Receive", "Transfer cancelled.", {"OK"}, true);
|
mainApp->CreateShowDialog("Receive", "Transfer cancelled.", {"OK"}, true);
|
||||||
} else if (mainApp->transfer.restoreSucceeded()) {
|
} else if (mainApp->transfer.restoreSucceeded()) {
|
||||||
mainApp->CreateShowDialog("Receive", "Save data received and restored successfully!", {"OK"},
|
mainApp->CreateShowDialog("Receive", "Save data received and restored successfully!", {"OK"}, true);
|
||||||
true);
|
|
||||||
} else {
|
} else {
|
||||||
mainApp->CreateShowDialog("Receive", "Restore failed:\n" + mainApp->transfer.restoreError(),
|
mainApp->CreateShowDialog("Receive", "Restore failed:\n" + mainApp->transfer.restoreError(), {"OK"}, true);
|
||||||
{"OK"}, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitlesLayout::onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint Pos) {
|
void TitlesLayout::onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint Pos) {
|
||||||
(void)Up;
|
(void)Up; (void)Held; (void)Pos;
|
||||||
(void)Held;
|
if (m_inputLocked) return;
|
||||||
(void)Pos;
|
|
||||||
if (m_inputLocked)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (Down & HidNpadButton_Plus) {
|
if (Down & HidNpadButton_Plus) {
|
||||||
mainApp->transfer.cancelSend();
|
mainApp->transfer.cancelSend();
|
||||||
@@ -267,8 +266,7 @@ namespace ui {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Down & HidNpadButton_A) {
|
if (Down & HidNpadButton_A) {
|
||||||
if (this->titlesMenu->GetItems().empty())
|
if (this->titlesMenu->GetItems().empty()) return;
|
||||||
return;
|
|
||||||
this->lockedListIndex = this->titlesMenu->GetSelectedIndex();
|
this->lockedListIndex = this->titlesMenu->GetSelectedIndex();
|
||||||
this->focus = TitlesFocus::Actions;
|
this->focus = TitlesFocus::Actions;
|
||||||
this->action = TitlesAction::Transfer;
|
this->action = TitlesAction::Transfer;
|
||||||
@@ -286,10 +284,10 @@ namespace ui {
|
|||||||
this->updateHints();
|
this->updateHints();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Down &
|
if (Down & (HidNpadButton_Up | HidNpadButton_Down |
|
||||||
(HidNpadButton_Up | HidNpadButton_Down | HidNpadButton_StickLUp | HidNpadButton_StickLDown)) {
|
HidNpadButton_StickLUp | HidNpadButton_StickLDown)) {
|
||||||
this->action =
|
this->action = (action == TitlesAction::Transfer)
|
||||||
(action == TitlesAction::Transfer) ? TitlesAction::Receive : TitlesAction::Transfer;
|
? TitlesAction::Receive : TitlesAction::Transfer;
|
||||||
this->refreshButtons();
|
this->refreshButtons();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -309,4 +307,4 @@ namespace ui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace ui
|
}
|
||||||
|
|||||||
+14
-8
@@ -6,21 +6,27 @@ namespace ui {
|
|||||||
UsersLayout::UsersLayout() : Layout::Layout() {
|
UsersLayout::UsersLayout() : Layout::Layout() {
|
||||||
using namespace theme;
|
using namespace theme;
|
||||||
|
|
||||||
this->usersMenu = pu::ui::elm::Menu::New(0, layout::ContentTop + space::md, layout::ScreenW,
|
this->usersMenu = pu::ui::elm::Menu::New(
|
||||||
color::BgBase, color::BgSurface2, 88, 6);
|
0, layout::ContentTop + space::md,
|
||||||
|
layout::ScreenW,
|
||||||
|
color::BgBase, color::BgSurface2,
|
||||||
|
88, 6);
|
||||||
this->usersMenu->SetScrollbarColor(color::Primary);
|
this->usersMenu->SetScrollbarColor(color::Primary);
|
||||||
this->usersMenu->SetItemsFocusColor(color::BgSurface2);
|
this->usersMenu->SetItemsFocusColor(color::BgSurface2);
|
||||||
|
|
||||||
for (AccountUid const& uid : account::ids()) {
|
for (AccountUid const& uid : Account::ids()) {
|
||||||
auto item = pu::ui::elm::MenuItem::New(account::username(uid));
|
auto item = pu::ui::elm::MenuItem::New(Account::username(uid));
|
||||||
item->SetColor(color::TextPrimary);
|
item->SetColor(color::TextPrimary);
|
||||||
this->usersMenu->AddItem(item);
|
this->usersMenu->AddItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->loadingBg = pu::ui::elm::Rectangle::New(0, 0, layout::ScreenW, layout::ScreenH, color::Scrim);
|
this->loadingBg = pu::ui::elm::Rectangle::New(
|
||||||
|
0, 0, layout::ScreenW, layout::ScreenH, color::Scrim);
|
||||||
this->loadingBg->SetVisible(false);
|
this->loadingBg->SetVisible(false);
|
||||||
|
|
||||||
this->loadingText = pu::ui::elm::TextBlock::New(layout::ScreenW / 2 - 120, layout::ScreenH / 2 - 12,
|
this->loadingText = pu::ui::elm::TextBlock::New(
|
||||||
|
layout::ScreenW / 2 - 120,
|
||||||
|
layout::ScreenH / 2 - 12,
|
||||||
"Loading saves...");
|
"Loading saves...");
|
||||||
this->loadingText->SetFont(type::font(type::Body));
|
this->loadingText->SetFont(type::font(type::Body));
|
||||||
this->loadingText->SetColor(color::TextSecondary);
|
this->loadingText->SetColor(color::TextSecondary);
|
||||||
@@ -47,7 +53,7 @@ namespace ui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Down & HidNpadButton_A) {
|
if (Down & HidNpadButton_A) {
|
||||||
AccountUid uid = account::ids().at(this->usersMenu->GetSelectedIndex());
|
AccountUid uid = Account::ids().at(this->usersMenu->GetSelectedIndex());
|
||||||
|
|
||||||
if (!areTitlesLoaded()) {
|
if (!areTitlesLoaded()) {
|
||||||
this->usersMenu->SetVisible(false);
|
this->usersMenu->SetVisible(false);
|
||||||
@@ -66,4 +72,4 @@ namespace ui {
|
|||||||
mainApp->LoadLayout(mainApp->titles_layout);
|
mainApp->LoadLayout(mainApp->titles_layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace ui
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user