Compare commits
27 Commits
stream_ins
...
0.8.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fb5319da3 | ||
|
|
6970fec554 | ||
|
|
36be56647f | ||
|
|
cca6326314 | ||
|
|
9176c6780a | ||
|
|
b1a6b12cf3 | ||
|
|
c7cc11cc98 | ||
|
|
ec4b96b95d | ||
|
|
a2e343daa7 | ||
|
|
b811c9e3cd | ||
|
|
8ffaa56bc3 | ||
|
|
eca3358e57 | ||
|
|
757e380e08 | ||
|
|
6c1b5de932 | ||
|
|
d79ac126f7 | ||
|
|
2d7763444e | ||
|
|
1dafa2748c | ||
|
|
9f7bf9581c | ||
|
|
8f39acbaa2 | ||
|
|
81469d0ac9 | ||
|
|
1eae35f072 | ||
|
|
5b82e07b1c | ||
|
|
73886c28ae | ||
|
|
eea09f6e57 | ||
|
|
282c6e5493 | ||
|
|
2c2f602d14 | ||
|
|
f7f1254699 |
34
README.md
34
README.md
@@ -49,6 +49,40 @@ The `path` field is optional. If left out, it will use the name of the ini to fi
|
|||||||
|
|
||||||
See `assets/romfs/assoc/` for more examples of file assoc entries.
|
See `assets/romfs/assoc/` for more examples of file assoc entries.
|
||||||
|
|
||||||
|
## Installing (applications)
|
||||||
|
|
||||||
|
Sphaira can install applications (nsp, xci, nsz, xcz) from various sources (sd card, gamecard, ftp, usb).
|
||||||
|
|
||||||
|
For informantion about the install options, [see the wiki](https://github.com/ITotalJustice/sphaira/wiki/Install).
|
||||||
|
|
||||||
|
### Usb (install)
|
||||||
|
|
||||||
|
The USB protocol is the same as tinfoil, so tools such as [ns-usbloader](https://github.com/developersu/ns-usbloader) and [fluffy](https://github.com/fourminute/Fluffy) should work with sphaira. You may also use the provided python script found [here](tools/usb_install_pc.py).
|
||||||
|
|
||||||
|
### Ftp (install)
|
||||||
|
|
||||||
|
Once you have connected your ftp client to your switch, you can upload files to install into the `install` folder.
|
||||||
|
|
||||||
|
## Building from source
|
||||||
|
|
||||||
|
You will first need to install [devkitPro](https://devkitpro.org/wiki/Getting_Started).
|
||||||
|
|
||||||
|
Next you will need to install the dependencies:
|
||||||
|
```sh
|
||||||
|
sudo pacman -S switch-dev deko3d switch-cmake switch-curl switch-glm switch-zlib
|
||||||
|
```
|
||||||
|
|
||||||
|
Once devkitPro and all dependencies are installed, you can now build sphaira.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/ITotalJustice/sphaira.git
|
||||||
|
cd sphaira
|
||||||
|
cmake --preset MinSizeRel
|
||||||
|
cmake --build --preset MinSizeRel
|
||||||
|
```
|
||||||
|
|
||||||
|
The output will be found in `build/MinSizeRel/sphaira.nro`
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
- borealis
|
- borealis
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
"Select Theme": "选择主题",
|
"Select Theme": "选择主题",
|
||||||
"Shuffle": "随机播放",
|
"Shuffle": "随机播放",
|
||||||
"Music": "音乐",
|
"Music": "音乐",
|
||||||
"12 Hour Time": "",
|
"12 Hour Time": "12小时制时间",
|
||||||
"Network": "网络",
|
"Network": "网络",
|
||||||
"Network Options": "网络选项",
|
"Network Options": "网络选项",
|
||||||
"Ftp": "FTP",
|
"Ftp": "FTP",
|
||||||
@@ -170,7 +170,7 @@
|
|||||||
"Controller": "控制器",
|
"Controller": "控制器",
|
||||||
"Pad ": "手柄 ",
|
"Pad ": "手柄 ",
|
||||||
" (Available)": " (可用的)",
|
" (Available)": " (可用的)",
|
||||||
" (Unsupported)": "",
|
" (Unsupported)": " (不支持的)",
|
||||||
" (Unconnected)": " (未连接)",
|
" (Unconnected)": " (未连接)",
|
||||||
"HandHeld": "掌机模式",
|
"HandHeld": "掌机模式",
|
||||||
"Rotation": "旋转",
|
"Rotation": "旋转",
|
||||||
@@ -239,7 +239,7 @@
|
|||||||
"Update avaliable: ": "有可用更新!",
|
"Update avaliable: ": "有可用更新!",
|
||||||
"Download update: ": "下载更新:",
|
"Download update: ": "下载更新:",
|
||||||
"Updated to ": "更新至 ",
|
"Updated to ": "更新至 ",
|
||||||
"Press OK to restart Sphaira": "",
|
"Press OK to restart Sphaira": "按OK键以重启shphaira菜单",
|
||||||
"Restart Sphaira?": "重启 Sphaira?",
|
"Restart Sphaira?": "重启 Sphaira?",
|
||||||
"Failed to download update": "更新下载失败",
|
"Failed to download update": "更新下载失败",
|
||||||
"Restore hbmenu?": "恢复 hbmenu?",
|
"Restore hbmenu?": "恢复 hbmenu?",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.13)
|
cmake_minimum_required(VERSION 3.13)
|
||||||
|
|
||||||
set(sphaira_VERSION 0.7.0)
|
set(sphaira_VERSION 0.8.2)
|
||||||
|
|
||||||
project(sphaira
|
project(sphaira
|
||||||
VERSION ${sphaira_VERSION}
|
VERSION ${sphaira_VERSION}
|
||||||
@@ -74,7 +74,6 @@ add_executable(sphaira
|
|||||||
source/nxlink.cpp
|
source/nxlink.cpp
|
||||||
source/owo.cpp
|
source/owo.cpp
|
||||||
source/swkbd.cpp
|
source/swkbd.cpp
|
||||||
source/web.cpp
|
|
||||||
source/i18n.cpp
|
source/i18n.cpp
|
||||||
source/ftpsrv_helper.cpp
|
source/ftpsrv_helper.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -102,6 +102,13 @@ public:
|
|||||||
|
|
||||||
static void PlaySoundEffect(SoundEffect effect);
|
static void PlaySoundEffect(SoundEffect effect);
|
||||||
|
|
||||||
|
static void DisplayThemeOptions(bool left_side = true);
|
||||||
|
// todo:
|
||||||
|
static void DisplayNetworkOptions(bool left_side = true);
|
||||||
|
static void DisplayMiscOptions(bool left_side = true);
|
||||||
|
static void DisplayAdvancedOptions(bool left_side = true);
|
||||||
|
static void DisplayInstallOptions(bool left_side = true);
|
||||||
|
|
||||||
void Draw();
|
void Draw();
|
||||||
void Update();
|
void Update();
|
||||||
void Poll();
|
void Poll();
|
||||||
@@ -182,6 +189,7 @@ public:
|
|||||||
option::OptionBool m_install{INI_SECTION, "install", false};
|
option::OptionBool m_install{INI_SECTION, "install", false};
|
||||||
option::OptionBool m_install_sd{INI_SECTION, "install_sd", true};
|
option::OptionBool m_install_sd{INI_SECTION, "install_sd", true};
|
||||||
option::OptionLong m_install_prompt{INI_SECTION, "install_prompt", true};
|
option::OptionLong m_install_prompt{INI_SECTION, "install_prompt", true};
|
||||||
|
option::OptionLong m_boost_mode{INI_SECTION, "boost_mode", false};
|
||||||
option::OptionBool m_allow_downgrade{INI_SECTION, "allow_downgrade", false};
|
option::OptionBool m_allow_downgrade{INI_SECTION, "allow_downgrade", false};
|
||||||
option::OptionBool m_skip_if_already_installed{INI_SECTION, "skip_if_already_installed", true};
|
option::OptionBool m_skip_if_already_installed{INI_SECTION, "skip_if_already_installed", true};
|
||||||
option::OptionBool m_ticket_only{INI_SECTION, "ticket_only", false};
|
option::OptionBool m_ticket_only{INI_SECTION, "ticket_only", false};
|
||||||
|
|||||||
@@ -8,15 +8,14 @@ namespace sphaira::ui {
|
|||||||
class ErrorBox final : public Widget {
|
class ErrorBox final : public Widget {
|
||||||
public:
|
public:
|
||||||
ErrorBox(Result code, const std::string& message);
|
ErrorBox(Result code, const std::string& message);
|
||||||
|
ErrorBox(const std::string& message);
|
||||||
|
|
||||||
auto Update(Controller* controller, TouchInfo* touch) -> void override;
|
auto Update(Controller* controller, TouchInfo* touch) -> void override;
|
||||||
auto Draw(NVGcontext* vg, Theme* theme) -> void override;
|
auto Draw(NVGcontext* vg, Theme* theme) -> void override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Result m_code{};
|
std::optional<Result> m_code{};
|
||||||
std::string m_message{};
|
std::string m_message{};
|
||||||
std::string m_module_str{};
|
|
||||||
std::string m_description_str{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sphaira::ui
|
} // namespace sphaira::ui
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ namespace sphaira::ui {
|
|||||||
|
|
||||||
struct List final : Object {
|
struct List final : Object {
|
||||||
using Callback = std::function<void(NVGcontext* vg, Theme* theme, Vec4 v, s64 index)>;
|
using Callback = std::function<void(NVGcontext* vg, Theme* theme, Vec4 v, s64 index)>;
|
||||||
using TouchCallback = std::function<void(s64 index)>;
|
using TouchCallback = std::function<void(bool touch, s64 index)>;
|
||||||
|
|
||||||
List(s64 row, s64 page, const Vec4& pos, const Vec4& v, const Vec2& pad = {});
|
List(s64 row, s64 page, const Vec4& pos, const Vec4& v, const Vec2& pad = {});
|
||||||
|
|
||||||
void OnUpdate(Controller* controller, TouchInfo* touch, s64 count, TouchCallback callback);
|
void OnUpdate(Controller* controller, TouchInfo* touch, s64 index, s64 count, TouchCallback callback);
|
||||||
|
|
||||||
void Draw(NVGcontext* vg, Theme* theme, s64 count, Callback callback) const;
|
void Draw(NVGcontext* vg, Theme* theme, s64 count, Callback callback) const;
|
||||||
|
|
||||||
|
|||||||
@@ -137,6 +137,13 @@ private:
|
|||||||
void InstallForwarder();
|
void InstallForwarder();
|
||||||
void InstallFile(const FileEntry& target);
|
void InstallFile(const FileEntry& target);
|
||||||
void InstallFiles(const std::vector<FileEntry>& targets);
|
void InstallFiles(const std::vector<FileEntry>& targets);
|
||||||
|
|
||||||
|
void UnzipFile(const fs::FsPath& folder, const FileEntry& target);
|
||||||
|
void UnzipFiles(fs::FsPath folder, const std::vector<FileEntry>& targets);
|
||||||
|
|
||||||
|
void ZipFile(const fs::FsPath& zip_path, const FileEntry& target);
|
||||||
|
void ZipFiles(fs::FsPath zip_path, const std::vector<FileEntry>& targets);
|
||||||
|
|
||||||
auto Scan(const fs::FsPath& new_path, bool is_walk_up = false) -> Result;
|
auto Scan(const fs::FsPath& new_path, bool is_walk_up = false) -> Result;
|
||||||
|
|
||||||
void LoadAssocEntriesPath(const fs::FsPath& path);
|
void LoadAssocEntriesPath(const fs::FsPath& path);
|
||||||
|
|||||||
@@ -3,20 +3,40 @@
|
|||||||
#include "ui/menus/menu_base.hpp"
|
#include "ui/menus/menu_base.hpp"
|
||||||
#include "yati/container/base.hpp"
|
#include "yati/container/base.hpp"
|
||||||
#include "yati/source/base.hpp"
|
#include "yati/source/base.hpp"
|
||||||
|
#include "ui/list.hpp"
|
||||||
|
#include <span>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace sphaira::ui::menu::gc {
|
namespace sphaira::ui::menu::gc {
|
||||||
|
|
||||||
enum class State {
|
struct GcCollection : yati::container::CollectionEntry {
|
||||||
// no gamecard inserted.
|
GcCollection(const char* _name, s64 _size, u8 _type, u8 _id_offset) {
|
||||||
None,
|
name = _name;
|
||||||
// set whilst transfer is in progress.
|
size = _size;
|
||||||
Progress,
|
type = _type;
|
||||||
// set when the transfer is finished.
|
id_offset = _id_offset;
|
||||||
Done,
|
}
|
||||||
// set when no gamecard is inserted.
|
|
||||||
NotFound,
|
// NcmContentType
|
||||||
// failed to parse gamecard.
|
u8 type{};
|
||||||
Failed,
|
u8 id_offset{};
|
||||||
|
};
|
||||||
|
|
||||||
|
using GcCollections = std::vector<GcCollection>;
|
||||||
|
|
||||||
|
struct ApplicationEntry {
|
||||||
|
u64 app_id{};
|
||||||
|
u32 version{};
|
||||||
|
u8 key_gen{};
|
||||||
|
|
||||||
|
std::vector<GcCollections> application{};
|
||||||
|
std::vector<GcCollections> patch{};
|
||||||
|
std::vector<GcCollections> add_on{};
|
||||||
|
std::vector<GcCollections> data_patch{};
|
||||||
|
yati::container::Collections tickets{};
|
||||||
|
|
||||||
|
auto GetSize() const -> s64;
|
||||||
|
auto GetSize(const std::vector<GcCollections>& entries) const -> s64;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Menu final : MenuBase {
|
struct Menu final : MenuBase {
|
||||||
@@ -26,13 +46,35 @@ struct Menu final : MenuBase {
|
|||||||
void Update(Controller* controller, TouchInfo* touch) override;
|
void Update(Controller* controller, TouchInfo* touch) override;
|
||||||
void Draw(NVGcontext* vg, Theme* theme) override;
|
void Draw(NVGcontext* vg, Theme* theme) override;
|
||||||
|
|
||||||
Result ScanGamecard();
|
private:
|
||||||
|
Result GcMount();
|
||||||
|
void GcUnmount();
|
||||||
|
Result GcPoll(bool* inserted);
|
||||||
|
Result GcOnEvent();
|
||||||
|
Result UpdateStorageSize();
|
||||||
|
|
||||||
|
void FreeImage();
|
||||||
|
void OnChangeIndex(s64 new_index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<fs::FsNativeGameCard> m_fs{};
|
|
||||||
FsDeviceOperator m_dev_op{};
|
FsDeviceOperator m_dev_op{};
|
||||||
yati::container::Collections m_collections{};
|
FsGameCardHandle m_handle{};
|
||||||
State m_state{State::None};
|
std::unique_ptr<fs::FsNativeGameCard> m_fs{};
|
||||||
|
FsEventNotifier m_event_notifier{};
|
||||||
|
Event m_event{};
|
||||||
|
|
||||||
|
std::vector<ApplicationEntry> m_entries{};
|
||||||
|
std::unique_ptr<List> m_list{};
|
||||||
|
s64 m_entry_index{};
|
||||||
|
s64 m_option_index{};
|
||||||
|
|
||||||
|
s64 m_size_free_sd{};
|
||||||
|
s64 m_size_total_sd{};
|
||||||
|
s64 m_size_free_nand{};
|
||||||
|
s64 m_size_total_nand{};
|
||||||
|
NacpLanguageEntry m_lang_entry{};
|
||||||
|
int m_icon{};
|
||||||
|
bool m_mounted{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sphaira::ui::menu::gc
|
} // namespace sphaira::ui::menu::gc
|
||||||
|
|||||||
@@ -34,12 +34,14 @@ struct Menu final : MenuBase {
|
|||||||
void Draw(NVGcontext* vg, Theme* theme) override;
|
void Draw(NVGcontext* vg, Theme* theme) override;
|
||||||
void OnFocusGained() override;
|
void OnFocusGained() override;
|
||||||
|
|
||||||
|
private:
|
||||||
void PollCameraStatus(bool statup = false);
|
void PollCameraStatus(bool statup = false);
|
||||||
void LoadDefaultConfig();
|
void LoadDefaultConfig();
|
||||||
void UpdateConfig(const IrsImageTransferProcessorExConfig* config);
|
void UpdateConfig(const IrsImageTransferProcessorExConfig* config);
|
||||||
void ResetImage();
|
void ResetImage();
|
||||||
void UpdateImage();
|
void UpdateImage();
|
||||||
void updateColourArray();
|
void updateColourArray();
|
||||||
|
auto GetEntryName(s64 i) -> std::string;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Result m_init_rc{};
|
Result m_init_rc{};
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ namespace sphaira::ui::menu::usb {
|
|||||||
enum class State {
|
enum class State {
|
||||||
// not connected.
|
// not connected.
|
||||||
None,
|
None,
|
||||||
|
// just connected, waiting for file list.
|
||||||
|
Connected_WaitForFileList,
|
||||||
// just connected, starts the transfer.
|
// just connected, starts the transfer.
|
||||||
Connected,
|
Connected_StartingTransfer,
|
||||||
// set whilst transfer is in progress.
|
// set whilst transfer is in progress.
|
||||||
Progress,
|
Progress,
|
||||||
// set when the transfer is finished.
|
// set when the transfer is finished.
|
||||||
@@ -35,9 +37,8 @@ struct Menu final : MenuBase {
|
|||||||
Mutex m_mutex{};
|
Mutex m_mutex{};
|
||||||
// the below are shared across threads, lock with the above mutex!
|
// the below are shared across threads, lock with the above mutex!
|
||||||
State m_state{State::None};
|
State m_state{State::None};
|
||||||
|
std::vector<std::string> m_names{};
|
||||||
bool m_usb_has_connection{};
|
bool m_usb_has_connection{};
|
||||||
u32 m_usb_speed{};
|
|
||||||
u32 m_usb_count{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sphaira::ui::menu::usb
|
} // namespace sphaira::ui::menu::usb
|
||||||
|
|||||||
@@ -5,17 +5,15 @@
|
|||||||
|
|
||||||
namespace sphaira::ui::gfx {
|
namespace sphaira::ui::gfx {
|
||||||
|
|
||||||
void drawImage(NVGcontext*, float x, float y, float w, float h, int texture);
|
void drawImage(NVGcontext*, float x, float y, float w, float h, int texture, float rounded = 0.F);
|
||||||
void drawImage(NVGcontext*, const Vec4& v, int texture);
|
void drawImage(NVGcontext*, const Vec4& v, int texture, float rounded = 0.F);
|
||||||
void drawImageRounded(NVGcontext*, float x, float y, float w, float h, int texture);
|
|
||||||
void drawImageRounded(NVGcontext*, const Vec4& v, int texture);
|
|
||||||
|
|
||||||
void dimBackground(NVGcontext*);
|
void dimBackground(NVGcontext*);
|
||||||
|
|
||||||
void drawRect(NVGcontext*, float x, float y, float w, float h, const NVGcolor& c, bool rounded = false);
|
void drawRect(NVGcontext*, float x, float y, float w, float h, const NVGcolor& c, float rounding = 0.F);
|
||||||
void drawRect(NVGcontext*, const Vec4& v, const NVGcolor& c, bool rounded = false);
|
void drawRect(NVGcontext*, const Vec4& v, const NVGcolor& c, float rounding = 0.F);
|
||||||
void drawRect(NVGcontext*, float x, float y, float w, float h, const NVGpaint& p, bool rounded = false);
|
void drawRect(NVGcontext*, float x, float y, float w, float h, const NVGpaint& p, float rounding = 0.F);
|
||||||
void drawRect(NVGcontext*, const Vec4& v, const NVGpaint& p, bool rounded = false);
|
void drawRect(NVGcontext*, const Vec4& v, const NVGpaint& p, float rounding = 0.F);
|
||||||
|
|
||||||
void drawRectOutline(NVGcontext*, const Theme*, float size, float x, float y, float w, float h);
|
void drawRectOutline(NVGcontext*, const Theme*, float size, float x, float y, float w, float h);
|
||||||
void drawRectOutline(NVGcontext*, const Theme*, float size, const Vec4& v);
|
void drawRectOutline(NVGcontext*, const Theme*, float size, const Vec4& v);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ private:
|
|||||||
Items m_items{};
|
Items m_items{};
|
||||||
Callback m_callback{};
|
Callback m_callback{};
|
||||||
s64 m_index{}; // index in list array
|
s64 m_index{}; // index in list array
|
||||||
|
s64 m_starting_index{};
|
||||||
|
|
||||||
std::unique_ptr<List> m_list{};
|
std::unique_ptr<List> m_list{};
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "widget.hpp"
|
#include "widget.hpp"
|
||||||
#include "fs.hpp"
|
#include "fs.hpp"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
namespace sphaira::ui {
|
namespace sphaira::ui {
|
||||||
|
|
||||||
@@ -12,6 +13,8 @@ using ProgressBoxDoneCallback = std::function<void(bool success)>;
|
|||||||
|
|
||||||
struct ProgressBox final : Widget {
|
struct ProgressBox final : Widget {
|
||||||
ProgressBox(
|
ProgressBox(
|
||||||
|
int image,
|
||||||
|
const std::string& action,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
ProgressBoxCallback callback, ProgressBoxDoneCallback done = [](bool success){},
|
ProgressBoxCallback callback, ProgressBoxDoneCallback done = [](bool success){},
|
||||||
int cpuid = 1, int prio = 0x2C, int stack_size = 1024*1024
|
int cpuid = 1, int prio = 0x2C, int stack_size = 1024*1024
|
||||||
@@ -24,6 +27,9 @@ struct ProgressBox final : Widget {
|
|||||||
auto SetTitle(const std::string& title) -> ProgressBox&;
|
auto SetTitle(const std::string& title) -> ProgressBox&;
|
||||||
auto NewTransfer(const std::string& transfer) -> ProgressBox&;
|
auto NewTransfer(const std::string& transfer) -> ProgressBox&;
|
||||||
auto UpdateTransfer(s64 offset, s64 size) -> ProgressBox&;
|
auto UpdateTransfer(s64 offset, s64 size) -> ProgressBox&;
|
||||||
|
// not const in order to avoid copy by using std::swap
|
||||||
|
auto SetImageData(std::vector<u8>& data) -> ProgressBox&;
|
||||||
|
auto SetImageDataConst(std::span<const u8> data) -> ProgressBox&;
|
||||||
void RequestExit();
|
void RequestExit();
|
||||||
auto ShouldExit() -> bool;
|
auto ShouldExit() -> bool;
|
||||||
|
|
||||||
@@ -41,6 +47,9 @@ struct ProgressBox final : Widget {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void FreeImage();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct ThreadData {
|
struct ThreadData {
|
||||||
ProgressBox* pbox{};
|
ProgressBox* pbox{};
|
||||||
@@ -52,12 +61,22 @@ private:
|
|||||||
Mutex m_mutex{};
|
Mutex m_mutex{};
|
||||||
Thread m_thread{};
|
Thread m_thread{};
|
||||||
ThreadData m_thread_data{};
|
ThreadData m_thread_data{};
|
||||||
|
|
||||||
ProgressBoxDoneCallback m_done{};
|
ProgressBoxDoneCallback m_done{};
|
||||||
|
|
||||||
|
// shared data start.
|
||||||
|
std::string m_action{};
|
||||||
std::string m_title{};
|
std::string m_title{};
|
||||||
std::string m_transfer{};
|
std::string m_transfer{};
|
||||||
s64 m_size{};
|
s64 m_size{};
|
||||||
s64 m_offset{};
|
s64 m_offset{};
|
||||||
|
s64 m_last_offset{};
|
||||||
|
s64 m_speed{};
|
||||||
|
TimeStamp m_timestamp{};
|
||||||
|
std::vector<u8> m_image_data{};
|
||||||
|
// shared data end.
|
||||||
|
|
||||||
|
int m_image{};
|
||||||
|
bool m_own_image{};
|
||||||
};
|
};
|
||||||
|
|
||||||
// this is a helper function that does many things.
|
// this is a helper function that does many things.
|
||||||
|
|||||||
@@ -226,7 +226,6 @@ struct ThemeMeta {
|
|||||||
|
|
||||||
struct Theme {
|
struct Theme {
|
||||||
ThemeMeta meta;
|
ThemeMeta meta;
|
||||||
PLSR_BFSTM music;
|
|
||||||
ElementEntry elements[ThemeEntryID_MAX];
|
ElementEntry elements[ThemeEntryID_MAX];
|
||||||
|
|
||||||
auto GetColour(ThemeEntryID id) const {
|
auto GetColour(ThemeEntryID id) const {
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <switch.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace sphaira {
|
|
||||||
|
|
||||||
// if show_error = true, it will display popup error box on
|
|
||||||
// faliure. set this to false if you want to handle errors
|
|
||||||
// from the caller.
|
|
||||||
auto WebShow(const std::string& url, bool show_error = true) -> Result;
|
|
||||||
|
|
||||||
} // namespace sphaira
|
|
||||||
@@ -175,7 +175,7 @@ struct Header {
|
|||||||
u8 old_key_gen; // see KeyGenerationOld.
|
u8 old_key_gen; // see KeyGenerationOld.
|
||||||
u8 kaek_index; // see KeyAreaEncryptionKeyIndex.
|
u8 kaek_index; // see KeyAreaEncryptionKeyIndex.
|
||||||
u64 size;
|
u64 size;
|
||||||
u64 title_id;
|
u64 program_id;
|
||||||
u32 context_id;
|
u32 context_id;
|
||||||
u32 sdk_version;
|
u32 sdk_version;
|
||||||
u8 key_gen; // see KeyGeneration.
|
u8 key_gen; // see KeyGeneration.
|
||||||
@@ -215,4 +215,6 @@ Result DecryptKeak(const keys::Keys& keys, Header& header);
|
|||||||
Result EncryptKeak(const keys::Keys& keys, Header& header, u8 key_generation);
|
Result EncryptKeak(const keys::Keys& keys, Header& header, u8 key_generation);
|
||||||
Result VerifyFixedKey(const Header& header);
|
Result VerifyFixedKey(const Header& header);
|
||||||
|
|
||||||
|
auto GetKeyGenStr(u8 key_gen) -> const char*;
|
||||||
|
|
||||||
} // namespace sphaira::nca
|
} // namespace sphaira::nca
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ static_assert(sizeof(PackagedContentMeta) == 0x20);
|
|||||||
|
|
||||||
struct ContentStorageRecord {
|
struct ContentStorageRecord {
|
||||||
NcmContentMetaKey key;
|
NcmContentMetaKey key;
|
||||||
u8 storage_id;
|
u8 storage_id; // NcmStorageId
|
||||||
u8 padding[0x7];
|
u8 padding[0x7];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,7 +31,9 @@ union ExtendedHeader {
|
|||||||
NcmDataPatchMetaExtendedHeader data_patch;
|
NcmDataPatchMetaExtendedHeader data_patch;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto GetAppId(u8 meta_type, u64 id) -> u64;
|
||||||
auto GetAppId(const NcmContentMetaKey& key) -> u64;
|
auto GetAppId(const NcmContentMetaKey& key) -> u64;
|
||||||
|
auto GetAppId(const PackagedContentMeta& meta) -> u64;
|
||||||
|
|
||||||
Result Delete(NcmContentStorage* cs, const NcmContentId *content_id);
|
Result Delete(NcmContentStorage* cs, const NcmContentId *content_id);
|
||||||
Result Register(NcmContentStorage* cs, const NcmContentId *content_id, const NcmPlaceHolderId *placeholder_id);
|
Result Register(NcmContentStorage* cs, const NcmContentId *content_id, const NcmPlaceHolderId *placeholder_id);
|
||||||
|
|||||||
@@ -1,265 +0,0 @@
|
|||||||
/*
|
|
||||||
* tik.h
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020-2024, DarkMatterCore <pabloacurielz@gmail.com>.
|
|
||||||
*
|
|
||||||
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
|
|
||||||
*
|
|
||||||
* nxdumptool 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.
|
|
||||||
*
|
|
||||||
* nxdumptool 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 <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef __TIK_H__
|
|
||||||
#define __TIK_H__
|
|
||||||
|
|
||||||
#include "signature.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SIGNED_TIK_MIN_SIZE sizeof(TikSigHmac160) /* Assuming no ESV1/ESV2 records are available. */
|
|
||||||
#define SIGNED_TIK_MAX_SIZE 0x400 /* Max ticket entry size in the ES ticket system savedata file. */
|
|
||||||
|
|
||||||
#define TIK_FORMAT_VERSION 2
|
|
||||||
|
|
||||||
#define GENERATE_TIK_STRUCT(sigtype, tiksize) \
|
|
||||||
typedef struct { \
|
|
||||||
SignatureBlock##sigtype sig_block; \
|
|
||||||
TikCommonBlock tik_common_block; \
|
|
||||||
u8 es_section_record_data[]; \
|
|
||||||
} TikSig##sigtype; \
|
|
||||||
NXDT_ASSERT(TikSig##sigtype, tiksize);
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TikTitleKeyType_Common = 0,
|
|
||||||
TikTitleKeyType_Personalized = 1,
|
|
||||||
TikTitleKeyType_Count = 2 ///< Total values supported by this enum.
|
|
||||||
} TikTitleKeyType;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TikLicenseType_Permanent = 0,
|
|
||||||
TikLicenseType_Demo = 1,
|
|
||||||
TikLicenseType_Trial = 2,
|
|
||||||
TikLicenseType_Rental = 3,
|
|
||||||
TikLicenseType_Subscription = 4,
|
|
||||||
TikLicenseType_Service = 5,
|
|
||||||
TikLicenseType_Count = 6 ///< Total values supported by this enum.
|
|
||||||
} TikLicenseType;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TikPropertyMask_None = 0,
|
|
||||||
TikPropertyMask_PreInstallation = BIT(0), ///< Determines if the title comes pre-installed on the device. Most likely unused -- a remnant from previous ticket formats.
|
|
||||||
TikPropertyMask_SharedTitle = BIT(1), ///< Determines if the title holds shared contents only. Most likely unused -- a remnant from previous ticket formats.
|
|
||||||
TikPropertyMask_AllContents = BIT(2), ///< Determines if the content index mask shall be bypassed. Most likely unused -- a remnant from previous ticket formats.
|
|
||||||
TikPropertyMask_DeviceLinkIndepedent = BIT(3), ///< Determines if the console should *not* connect to the Internet to verify if the title's being used by the primary console.
|
|
||||||
TikPropertyMask_Volatile = BIT(4), ///< Determines if the ticket copy inside ticket.bin is available after reboot. Can be encrypted.
|
|
||||||
TikPropertyMask_ELicenseRequired = BIT(5), ///< Determines if the console should connect to the Internet to perform license verification.
|
|
||||||
TikPropertyMask_Count = 6 ///< Total values supported by this enum.
|
|
||||||
} TikPropertyMask;
|
|
||||||
|
|
||||||
/// Placed after the ticket signature block.
|
|
||||||
typedef struct {
|
|
||||||
char issuer[0x40];
|
|
||||||
u8 titlekey_block[0x100];
|
|
||||||
u8 format_version; ///< Always matches TIK_FORMAT_VERSION.
|
|
||||||
u8 titlekey_type; ///< TikTitleKeyType.
|
|
||||||
u16 ticket_version;
|
|
||||||
u8 license_type; ///< TikLicenseType.
|
|
||||||
u8 key_generation; ///< NcaKeyGeneration.
|
|
||||||
u16 property_mask; ///< TikPropertyMask.
|
|
||||||
u8 reserved[0x8];
|
|
||||||
u64 ticket_id;
|
|
||||||
u64 device_id;
|
|
||||||
FsRightsId rights_id;
|
|
||||||
u32 account_id;
|
|
||||||
u32 sect_total_size;
|
|
||||||
u32 sect_hdr_offset;
|
|
||||||
u16 sect_hdr_count;
|
|
||||||
u16 sect_hdr_entry_size;
|
|
||||||
} TikCommonBlock;
|
|
||||||
|
|
||||||
NXDT_ASSERT(TikCommonBlock, 0x180);
|
|
||||||
|
|
||||||
/// ESV1/ESV2 section records are placed right after the ticket data. These aren't available in TikTitleKeyType_Common tickets.
|
|
||||||
/// These are only used if the sect_* fields from the common block are non-zero (other than 'sect_hdr_offset').
|
|
||||||
/// Each ESV2 section record is followed by a 'record_count' number of ESV1 records, each one of 'record_size' size.
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TikSectionType_None = 0,
|
|
||||||
TikSectionType_Permanent = 1,
|
|
||||||
TikSectionType_Subscription = 2,
|
|
||||||
TikSectionType_Content = 3,
|
|
||||||
TikSectionType_ContentConsumption = 4,
|
|
||||||
TikSectionType_AccessTitle = 5,
|
|
||||||
TikSectionType_LimitedResource = 6,
|
|
||||||
TikSectionType_Count = 7 ///< Total values supported by this enum.
|
|
||||||
} TikSectionType;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u32 sect_offset;
|
|
||||||
u32 record_size;
|
|
||||||
u32 section_size;
|
|
||||||
u16 record_count;
|
|
||||||
u16 section_type; ///< TikSectionType.
|
|
||||||
} TikESV2SectionRecord;
|
|
||||||
|
|
||||||
/// Used with TikSectionType_Permanent.
|
|
||||||
typedef struct {
|
|
||||||
u8 ref_id[0x10];
|
|
||||||
u32 ref_id_attr;
|
|
||||||
} TikESV1PermanentRecord;
|
|
||||||
|
|
||||||
/// Used with TikSectionType_Subscription.
|
|
||||||
typedef struct {
|
|
||||||
u32 limit;
|
|
||||||
u8 ref_id[0x10];
|
|
||||||
u32 ref_id_attr;
|
|
||||||
} TikESV1SubscriptionRecord;
|
|
||||||
|
|
||||||
/// Used with TikSectionType_Content.
|
|
||||||
typedef struct {
|
|
||||||
u32 offset;
|
|
||||||
u8 access_mask[0x80];
|
|
||||||
} TikESV1ContentRecord;
|
|
||||||
|
|
||||||
/// Used with TikSectionType_ContentConsumption.
|
|
||||||
typedef struct {
|
|
||||||
u16 index;
|
|
||||||
u16 code;
|
|
||||||
u32 limit;
|
|
||||||
} TikESV1ContentConsumptionRecord;
|
|
||||||
|
|
||||||
/// Used with TikSectionType_AccessTitle.
|
|
||||||
typedef struct {
|
|
||||||
u64 access_title_id;
|
|
||||||
u64 access_title_mask;
|
|
||||||
} TikESV1AccessTitleRecord;
|
|
||||||
|
|
||||||
/// Used with TikSectionType_LimitedResource.
|
|
||||||
typedef struct {
|
|
||||||
u32 limit;
|
|
||||||
u8 ref_id[0x10];
|
|
||||||
u32 ref_id_attr;
|
|
||||||
} TikESV1LimitedResourceRecord;
|
|
||||||
|
|
||||||
/// All tickets generated below use a little endian sig_type field.
|
|
||||||
GENERATE_TIK_STRUCT(Rsa4096, 0x3C0); /// RSA-4096 signature.
|
|
||||||
GENERATE_TIK_STRUCT(Rsa2048, 0x2C0); /// RSA-2048 signature.
|
|
||||||
GENERATE_TIK_STRUCT(Ecc480, 0x200); /// ECC signature.
|
|
||||||
GENERATE_TIK_STRUCT(Hmac160, 0x1C0); /// HMAC signature.
|
|
||||||
|
|
||||||
/// Ticket type.
|
|
||||||
typedef enum {
|
|
||||||
TikType_None = 0,
|
|
||||||
TikType_SigRsa4096 = 1,
|
|
||||||
TikType_SigRsa2048 = 2,
|
|
||||||
TikType_SigEcc480 = 3,
|
|
||||||
TikType_SigHmac160 = 4,
|
|
||||||
TikType_Count = 5 ///< Total values supported by this enum.
|
|
||||||
} TikType;
|
|
||||||
|
|
||||||
/// Used to store ticket type, size and raw data, as well as titlekey data.
|
|
||||||
typedef struct {
|
|
||||||
u8 type; ///< TikType.
|
|
||||||
u64 size; ///< Raw ticket size.
|
|
||||||
u8 data[SIGNED_TIK_MAX_SIZE]; ///< Raw ticket data.
|
|
||||||
u8 key_generation; ///< NcaKeyGeneration.
|
|
||||||
u8 enc_titlekey[0x10]; ///< Titlekey with titlekek crypto (RSA-OAEP unwrapped if dealing with a TikTitleKeyType_Personalized ticket).
|
|
||||||
char enc_titlekey_str[0x21]; ///< Character string representation of enc_titlekey.
|
|
||||||
u8 dec_titlekey[0x10]; ///< Titlekey without titlekek crypto. Ready to use for NCA FS section decryption.
|
|
||||||
char dec_titlekey_str[0x21]; ///< Character string representation of dec_titlekey.
|
|
||||||
char rights_id_str[0x21]; ///< Character string representation of the rights ID from the ticket.
|
|
||||||
} Ticket;
|
|
||||||
|
|
||||||
/// Retrieves a ticket from either the ES ticket system savedata file (eMMC BIS System partition) or the secure Hash FS partition from an inserted gamecard.
|
|
||||||
/// Both the input rights ID and key generation values must have been retrieved from a NCA that depends on the desired ticket.
|
|
||||||
/// Titlekey is also RSA-OAEP unwrapped (if needed) and titlekek-decrypted right away.
|
|
||||||
bool tikRetrieveTicketByRightsId(Ticket *dst, const FsRightsId *id, u8 key_generation, bool use_gamecard);
|
|
||||||
|
|
||||||
/// Converts a TikTitleKeyType_Personalized ticket into a TikTitleKeyType_Common ticket and optionally generates a raw certificate chain for the new signature issuer.
|
|
||||||
/// Bear in mind the 'size' member from the Ticket parameter will be updated by this function to remove any possible references to ESV1/ESV2 records.
|
|
||||||
/// If both 'out_raw_cert_chain' and 'out_raw_cert_chain_size' pointers are provided, raw certificate chain data will be saved to them.
|
|
||||||
/// certGenerateRawCertificateChainBySignatureIssuer() is used internally, so the output buffer must be freed by the user.
|
|
||||||
bool tikConvertPersonalizedTicketToCommonTicket(Ticket *tik, u8 **out_raw_cert_chain, u64 *out_raw_cert_chain_size);
|
|
||||||
|
|
||||||
/// Helper inline functions for signed ticket blobs.
|
|
||||||
|
|
||||||
NX_INLINE TikCommonBlock *tikGetCommonBlockFromSignedTicketBlob(void *buf)
|
|
||||||
{
|
|
||||||
return (TikCommonBlock*)signatureGetPayloadFromSignedBlob(buf, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE u64 tikGetSectionRecordsSizeFromSignedTicketBlob(void *buf)
|
|
||||||
{
|
|
||||||
TikCommonBlock *tik_common_block = tikGetCommonBlockFromSignedTicketBlob(buf);
|
|
||||||
if (!tik_common_block) return 0;
|
|
||||||
|
|
||||||
u64 offset = sizeof(TikCommonBlock), out_size = 0;
|
|
||||||
|
|
||||||
for(u32 i = 0; i < tik_common_block->sect_hdr_count; i++)
|
|
||||||
{
|
|
||||||
TikESV2SectionRecord *rec = (TikESV2SectionRecord*)((u8*)tik_common_block + offset);
|
|
||||||
offset += (sizeof(TikESV2SectionRecord) + ((u64)rec->record_count * (u64)rec->record_size));
|
|
||||||
out_size += offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
return out_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE bool tikIsValidSignedTicketBlob(void *buf)
|
|
||||||
{
|
|
||||||
u64 ticket_size = (signatureGetBlockSizeFromSignedBlob(buf, false) + sizeof(TikCommonBlock));
|
|
||||||
return (ticket_size > sizeof(TikCommonBlock) && (ticket_size + tikGetSectionRecordsSizeFromSignedTicketBlob(buf)) <= SIGNED_TIK_MAX_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE u64 tikGetSignedTicketBlobSize(void *buf)
|
|
||||||
{
|
|
||||||
return (tikIsValidSignedTicketBlob(buf) ? (signatureGetBlockSizeFromSignedBlob(buf, false) + sizeof(TikCommonBlock) + tikGetSectionRecordsSizeFromSignedTicketBlob(buf)) : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE u64 tikGetSignedTicketBlobHashAreaSize(void *buf)
|
|
||||||
{
|
|
||||||
return (tikIsValidSignedTicketBlob(buf) ? (sizeof(TikCommonBlock) + tikGetSectionRecordsSizeFromSignedTicketBlob(buf)) : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper inline functions for Ticket elements.
|
|
||||||
|
|
||||||
NX_INLINE bool tikIsValidTicket(Ticket *tik)
|
|
||||||
{
|
|
||||||
return (tik && tik->type > TikType_None && tik->type < TikType_Count && tik->size >= SIGNED_TIK_MIN_SIZE && tik->size <= SIGNED_TIK_MAX_SIZE && tikIsValidSignedTicketBlob(tik->data));
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE TikCommonBlock *tikGetCommonBlockFromTicket(Ticket *tik)
|
|
||||||
{
|
|
||||||
return (tikIsValidTicket(tik) ? tikGetCommonBlockFromSignedTicketBlob(tik->data) : NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE bool tikIsPersonalizedTicket(Ticket *tik)
|
|
||||||
{
|
|
||||||
TikCommonBlock *tik_common_block = tikGetCommonBlockFromTicket(tik);
|
|
||||||
return (tik_common_block ? (tik_common_block->titlekey_type == TikTitleKeyType_Personalized) : false);
|
|
||||||
}
|
|
||||||
|
|
||||||
NX_INLINE u64 tikGetHashAreaSizeFromTicket(Ticket *tik)
|
|
||||||
{
|
|
||||||
return (tikIsValidTicket(tik) ? tikGetSignedTicketBlobHashAreaSize(tik->data) : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __TIK_H__ */
|
|
||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
#include "base.hpp"
|
#include "base.hpp"
|
||||||
#include "fs.hpp"
|
#include "fs.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <new>
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
|
|
||||||
namespace sphaira::yati::source {
|
namespace sphaira::yati::source {
|
||||||
@@ -21,11 +25,39 @@ struct Usb final : Base {
|
|||||||
~Usb();
|
~Usb();
|
||||||
|
|
||||||
Result Read(void* buf, s64 off, s64 size, u64* bytes_read) override;
|
Result Read(void* buf, s64 off, s64 size, u64* bytes_read) override;
|
||||||
Result Finished() const;
|
Result Finished();
|
||||||
|
|
||||||
Result Init();
|
Result Init();
|
||||||
Result WaitForConnection(u64 timeout, u32& speed, u32& count);
|
Result IsUsbConnected(u64 timeout) const;
|
||||||
Result GetFileInfo(std::string& name_out, u64& size_out);
|
Result WaitForConnection(u64 timeout, std::vector<std::string>& out_names);
|
||||||
|
void SetFileNameForTranfser(const std::string& name);
|
||||||
|
|
||||||
|
public:
|
||||||
|
// custom allocator for std::vector that respects alignment.
|
||||||
|
// https://en.cppreference.com/w/cpp/named_req/Allocator
|
||||||
|
template <typename T, std::size_t Align>
|
||||||
|
struct CustomVectorAllocator {
|
||||||
|
public:
|
||||||
|
// https://en.cppreference.com/w/cpp/memory/new/operator_new
|
||||||
|
auto allocate(std::size_t n) -> T* {
|
||||||
|
return new(align) T[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://en.cppreference.com/w/cpp/memory/new/operator_delete
|
||||||
|
auto deallocate(T* p, std::size_t n) noexcept -> void {
|
||||||
|
::operator delete[] (p, n, align);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr inline std::align_val_t align{Align};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct PageAllocator : CustomVectorAllocator<T, 0x1000> {
|
||||||
|
using value_type = T; // used by std::vector
|
||||||
|
};
|
||||||
|
|
||||||
|
using PageAlignedVector = std::vector<u8, PageAllocator<u8>>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum UsbSessionEndpoint {
|
enum UsbSessionEndpoint {
|
||||||
@@ -33,20 +65,24 @@ private:
|
|||||||
UsbSessionEndpoint_Out = 1,
|
UsbSessionEndpoint_Out = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
Result SendCommand(s64 off, s64 size) const;
|
Result SendCmdHeader(u32 cmdId, size_t dataSize);
|
||||||
Result InternalRead(void* buf, s64 off, s64 size) const;
|
Result SendFileRangeCmd(u64 offset, u64 size);
|
||||||
|
|
||||||
bool GetConfigured() const;
|
|
||||||
Event *GetCompletionEvent(UsbSessionEndpoint ep) const;
|
Event *GetCompletionEvent(UsbSessionEndpoint ep) const;
|
||||||
Result WaitTransferCompletion(UsbSessionEndpoint ep, u64 timeout) const;
|
Result WaitTransferCompletion(UsbSessionEndpoint ep, u64 timeout) const;
|
||||||
Result TransferAsync(UsbSessionEndpoint ep, void *buffer, u32 size, u32 *out_urb_id) const;
|
Result TransferAsync(UsbSessionEndpoint ep, void *buffer, u32 size, u32 *out_urb_id) const;
|
||||||
Result GetTransferResult(UsbSessionEndpoint ep, u32 urb_id, u32 *out_requested_size, u32 *out_transferred_size) const;
|
Result GetTransferResult(UsbSessionEndpoint ep, u32 urb_id, u32 *out_requested_size, u32 *out_transferred_size) const;
|
||||||
Result TransferPacketImpl(bool read, void *page, u32 size, u32 *out_size_transferred, u64 timeout) const;
|
Result TransferPacketImpl(bool read, void *page, u32 size, u32 *out_size_transferred, u64 timeout) const;
|
||||||
|
Result TransferAll(bool read, void *data, u32 size, u64 timeout);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UsbDsInterface* m_interface{};
|
UsbDsInterface* m_interface{};
|
||||||
UsbDsEndpoint* m_endpoints[2]{};
|
UsbDsEndpoint* m_endpoints[2]{};
|
||||||
u64 m_transfer_timeout{};
|
u64 m_transfer_timeout{};
|
||||||
|
// aligned buffer that transfer data is copied to and from.
|
||||||
|
// a vector is used to avoid multiple alloc within the transfer loop.
|
||||||
|
PageAlignedVector m_aligned{};
|
||||||
|
std::string m_transfer_file_name{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sphaira::yati::source
|
} // namespace sphaira::yati::source
|
||||||
|
|||||||
@@ -10,8 +10,10 @@
|
|||||||
#include "fs.hpp"
|
#include "fs.hpp"
|
||||||
#include "source/base.hpp"
|
#include "source/base.hpp"
|
||||||
#include "container/base.hpp"
|
#include "container/base.hpp"
|
||||||
|
#include "nx/ncm.hpp"
|
||||||
#include "ui/progress_box.hpp"
|
#include "ui/progress_box.hpp"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace sphaira::yati {
|
namespace sphaira::yati {
|
||||||
|
|
||||||
@@ -69,6 +71,10 @@ enum : Result {
|
|||||||
struct Config {
|
struct Config {
|
||||||
bool sd_card_install{};
|
bool sd_card_install{};
|
||||||
|
|
||||||
|
// sets the performance mode to FastLoad which boosts the CPU clock
|
||||||
|
// and lowers the GPU clock.
|
||||||
|
bool boost_mode{};
|
||||||
|
|
||||||
// enables downgrading patch / data patch (dlc) version.
|
// enables downgrading patch / data patch (dlc) version.
|
||||||
bool allow_downgrade{};
|
bool allow_downgrade{};
|
||||||
|
|
||||||
@@ -112,10 +118,25 @@ struct Config {
|
|||||||
bool lower_system_version{};
|
bool lower_system_version{};
|
||||||
};
|
};
|
||||||
|
|
||||||
Result InstallFromFile(ui::ProgressBox* pbox, FsFileSystem* fs, const fs::FsPath& path);
|
// overridable options, set to avoid
|
||||||
Result InstallFromStdioFile(ui::ProgressBox* pbox, const fs::FsPath& path);
|
struct ConfigOverride {
|
||||||
Result InstallFromSource(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const fs::FsPath& path);
|
std::optional<bool> sd_card_install{};
|
||||||
Result InstallFromContainer(ui::ProgressBox* pbox, std::shared_ptr<container::Base> container);
|
std::optional<bool> skip_nca_hash_verify{};
|
||||||
Result InstallFromCollections(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const container::Collections& collections);
|
std::optional<bool> skip_rsa_header_fixed_key_verify{};
|
||||||
|
std::optional<bool> skip_rsa_npdm_fixed_key_verify{};
|
||||||
|
std::optional<bool> ignore_distribution_bit{};
|
||||||
|
std::optional<bool> convert_to_standard_crypto{};
|
||||||
|
std::optional<bool> lower_master_key{};
|
||||||
|
std::optional<bool> lower_system_version{};
|
||||||
|
};
|
||||||
|
|
||||||
|
Result InstallFromFile(ui::ProgressBox* pbox, FsFileSystem* fs, const fs::FsPath& path, const ConfigOverride& override = {});
|
||||||
|
Result InstallFromStdioFile(ui::ProgressBox* pbox, const fs::FsPath& path, const ConfigOverride& override = {});
|
||||||
|
Result InstallFromSource(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const fs::FsPath& path, const ConfigOverride& override = {});
|
||||||
|
Result InstallFromContainer(ui::ProgressBox* pbox, std::shared_ptr<container::Base> container, const ConfigOverride& override = {});
|
||||||
|
Result InstallFromCollections(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const container::Collections& collections, const ConfigOverride& override = {});
|
||||||
|
|
||||||
|
Result ParseCnmtNca(const fs::FsPath& path, u64 program_id, ncm::PackagedContentMeta& header, std::vector<u8>& extended_header, std::vector<NcmPackagedContentInfo>& infos);
|
||||||
|
Result ParseControlNca(const fs::FsPath& path, u64 program_id, void* nacp_out = nullptr, s64 nacp_size = 0, std::vector<u8>* icon_out = nullptr);
|
||||||
|
|
||||||
} // namespace sphaira::yati
|
} // namespace sphaira::yati
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
#include "ui/menus/main_menu.hpp"
|
|
||||||
#include "ui/error_box.hpp"
|
|
||||||
#include "ui/option_box.hpp"
|
#include "ui/option_box.hpp"
|
||||||
#include "ui/bubbles.hpp"
|
#include "ui/bubbles.hpp"
|
||||||
|
#include "ui/sidebar.hpp"
|
||||||
|
#include "ui/popup_list.hpp"
|
||||||
|
#include "ui/option_box.hpp"
|
||||||
|
#include "ui/progress_box.hpp"
|
||||||
|
#include "ui/error_box.hpp"
|
||||||
|
|
||||||
|
#include "ui/menus/main_menu.hpp"
|
||||||
|
#include "ui/menus/irs_menu.hpp"
|
||||||
|
#include "ui/menus/themezer.hpp"
|
||||||
|
#include "ui/menus/ghdl.hpp"
|
||||||
|
#include "ui/menus/usb_menu.hpp"
|
||||||
|
#include "ui/menus/ftp_menu.hpp"
|
||||||
|
#include "ui/menus/gc_menu.hpp"
|
||||||
|
|
||||||
#include "app.hpp"
|
#include "app.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
@@ -34,8 +45,33 @@ extern "C" {
|
|||||||
namespace sphaira {
|
namespace sphaira {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr fs::FsPath DEFAULT_MUSIC_PATH = "/config/sphaira/themes/default_music.bfstm";
|
||||||
|
constexpr const char* DEFAULT_MUSIC_URL = "https://files.catbox.moe/1ovji1.bfstm";
|
||||||
|
// constexpr const char* DEFAULT_MUSIC_URL = "https://raw.githubusercontent.com/ITotalJustice/sphaira/refs/heads/master/assets/default_music.bfstm";
|
||||||
|
|
||||||
|
void download_default_music() {
|
||||||
|
App::Push(std::make_shared<ui::ProgressBox>(0, "Downloading "_i18n, "default_music.bfstm", [](auto pbox){
|
||||||
|
const auto result = curl::Api().ToFile(
|
||||||
|
curl::Url{DEFAULT_MUSIC_URL},
|
||||||
|
curl::Path{DEFAULT_MUSIC_PATH},
|
||||||
|
curl::OnProgress{pbox->OnDownloadProgressCallback()}
|
||||||
|
);
|
||||||
|
|
||||||
|
return result.success;
|
||||||
|
}, [](bool success){
|
||||||
|
if (success) {
|
||||||
|
App::Notify("Downloaded "_i18n + "default_music.bfstm");
|
||||||
|
App::SetTheme(App::GetThemeIndex());
|
||||||
|
} else {
|
||||||
|
App::Push(std::make_shared<ui::ErrorBox>(
|
||||||
|
"Failed to download default_music.bfstm, please try again"_i18n
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
struct ThemeData {
|
struct ThemeData {
|
||||||
fs::FsPath music_path{"/config/sphaira/themes/default_music.bfstm"};
|
fs::FsPath music_path{DEFAULT_MUSIC_PATH};
|
||||||
std::string elements[ThemeEntryID_MAX]{};
|
std::string elements[ThemeEntryID_MAX]{};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1104,7 +1140,6 @@ void App::CloseTheme() {
|
|||||||
if (m_sound_ids[SoundEffect_Music]) {
|
if (m_sound_ids[SoundEffect_Music]) {
|
||||||
plsrPlayerFree(m_sound_ids[SoundEffect_Music]);
|
plsrPlayerFree(m_sound_ids[SoundEffect_Music]);
|
||||||
m_sound_ids[SoundEffect_Music] = nullptr;
|
m_sound_ids[SoundEffect_Music] = nullptr;
|
||||||
plsrBFSTMClose(&m_theme.music);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& e : m_theme.elements) {
|
for (auto& e : m_theme.elements) {
|
||||||
@@ -1134,10 +1169,12 @@ void App::LoadTheme(const ThemeMeta& meta) {
|
|||||||
|
|
||||||
// load music
|
// load music
|
||||||
if (!theme_data.music_path.empty()) {
|
if (!theme_data.music_path.empty()) {
|
||||||
if (R_SUCCEEDED(plsrBFSTMOpen(theme_data.music_path, &m_theme.music))) {
|
PLSR_BFSTM music_stream;
|
||||||
if (R_SUCCEEDED(plsrPlayerLoadStream(&m_theme.music, &m_sound_ids[SoundEffect_Music]))) {
|
if (R_SUCCEEDED(plsrBFSTMOpen(theme_data.music_path, &music_stream))) {
|
||||||
|
if (R_SUCCEEDED(plsrPlayerLoadStream(&music_stream, &m_sound_ids[SoundEffect_Music]))) {
|
||||||
PlaySoundEffect(SoundEffect_Music);
|
PlaySoundEffect(SoundEffect_Music);
|
||||||
}
|
}
|
||||||
|
plsrBFSTMClose(&music_stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1300,16 +1337,21 @@ App::App(const char* argv0) {
|
|||||||
if (R_SUCCEEDED(plsrBFSAROpen("qlaunch:/sound/qlaunch.bfsar", &qlaunch_bfsar))) {
|
if (R_SUCCEEDED(plsrBFSAROpen("qlaunch:/sound/qlaunch.bfsar", &qlaunch_bfsar))) {
|
||||||
ON_SCOPE_EXIT(plsrBFSARClose(&qlaunch_bfsar));
|
ON_SCOPE_EXIT(plsrBFSARClose(&qlaunch_bfsar));
|
||||||
|
|
||||||
plsrPlayerLoadSoundByName(&qlaunch_bfsar, "SeGameIconFocus", &m_sound_ids[SoundEffect_Focus]);
|
const auto load_sound = [&](const char* name, u32 id) {
|
||||||
plsrPlayerLoadSoundByName(&qlaunch_bfsar, "SeGameIconScroll", &m_sound_ids[SoundEffect_Scroll]);
|
if (R_FAILED(plsrPlayerLoadSoundByName(&qlaunch_bfsar, name, &m_sound_ids[id]))) {
|
||||||
plsrPlayerLoadSoundByName(&qlaunch_bfsar, "SeGameIconLimit", &m_sound_ids[SoundEffect_Limit]);
|
log_write("[PLSR] failed to load sound effect: %s\n", name);
|
||||||
plsrPlayerLoadSoundByName(&qlaunch_bfsar, "SeStartupMenu_game", &m_sound_ids[SoundEffect_Startup]);
|
}
|
||||||
plsrPlayerLoadSoundByName(&qlaunch_bfsar, "SeGameIconAdd", &m_sound_ids[SoundEffect_Install]);
|
};
|
||||||
plsrPlayerLoadSoundByName(&qlaunch_bfsar, "SeInsertError", &m_sound_ids[SoundEffect_Error]);
|
|
||||||
|
load_sound("SeGameIconFocus", SoundEffect_Focus);
|
||||||
|
load_sound("SeGameIconScroll", SoundEffect_Scroll);
|
||||||
|
load_sound("SeGameIconLimit", SoundEffect_Limit);
|
||||||
|
load_sound("StartupMenu_Game", SoundEffect_Startup);
|
||||||
|
load_sound("SeGameIconAdd", SoundEffect_Install);
|
||||||
|
load_sound("SeInsertError", SoundEffect_Error);
|
||||||
|
|
||||||
plsrPlayerSetVolume(m_sound_ids[SoundEffect_Limit], 2.0f);
|
plsrPlayerSetVolume(m_sound_ids[SoundEffect_Limit], 2.0f);
|
||||||
plsrPlayerSetVolume(m_sound_ids[SoundEffect_Focus], 0.5f);
|
plsrPlayerSetVolume(m_sound_ids[SoundEffect_Focus], 0.5f);
|
||||||
PlaySoundEffect(SoundEffect_Startup);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log_write("failed to mount romfs 0x0100000000001000\n");
|
log_write("failed to mount romfs 0x0100000000001000\n");
|
||||||
@@ -1374,15 +1416,6 @@ App::App(const char* argv0) {
|
|||||||
const long old_launch_count = ini_getl(GetExePath(), "launch_count", 0, App::PLAYLOG_PATH);
|
const long old_launch_count = ini_getl(GetExePath(), "launch_count", 0, App::PLAYLOG_PATH);
|
||||||
ini_putl(GetExePath(), "launch_count", old_launch_count + 1, App::PLAYLOG_PATH);
|
ini_putl(GetExePath(), "launch_count", old_launch_count + 1, App::PLAYLOG_PATH);
|
||||||
|
|
||||||
s64 sd_free_space;
|
|
||||||
if (R_SUCCEEDED(fs.GetFreeSpace("/", &sd_free_space))) {
|
|
||||||
log_write("sd_free_space: %zd\n", sd_free_space);
|
|
||||||
}
|
|
||||||
s64 sd_total_space;
|
|
||||||
if (R_SUCCEEDED(fs.GetTotalSpace("/", &sd_total_space))) {
|
|
||||||
log_write("sd_total_space: %zd\n", sd_total_space);
|
|
||||||
}
|
|
||||||
|
|
||||||
// load default image
|
// load default image
|
||||||
if (R_SUCCEEDED(romfsInit())) {
|
if (R_SUCCEEDED(romfsInit())) {
|
||||||
ON_SCOPE_EXIT(romfsExit());
|
ON_SCOPE_EXIT(romfsExit());
|
||||||
@@ -1437,6 +1470,194 @@ void App::PlaySoundEffect(SoundEffect effect) {
|
|||||||
plsrPlayerPlay(id);
|
plsrPlayerPlay(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void App::DisplayThemeOptions(bool left_side) {
|
||||||
|
ui::SidebarEntryArray::Items theme_items{};
|
||||||
|
const auto theme_meta = App::GetThemeMetaList();
|
||||||
|
for (auto& p : theme_meta) {
|
||||||
|
theme_items.emplace_back(p.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto options = std::make_shared<ui::Sidebar>("Theme Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT);
|
||||||
|
ON_SCOPE_EXIT(App::Push(options));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryArray>("Select Theme"_i18n, theme_items, [](s64& index_out){
|
||||||
|
App::SetTheme(index_out);
|
||||||
|
}, App::GetThemeIndex()));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Music"_i18n, App::GetThemeMusicEnable(), [](bool& enable){
|
||||||
|
App::SetThemeMusicEnable(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("12 Hour Time"_i18n, App::Get12HourTimeEnable(), [](bool& enable){
|
||||||
|
App::Set12HourTimeEnable(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryCallback>("Download Default Music"_i18n, [](){
|
||||||
|
// check if we already have music
|
||||||
|
if (fs::FileExists(DEFAULT_MUSIC_PATH)) {
|
||||||
|
App::Push(std::make_shared<ui::OptionBox>(
|
||||||
|
"Overwrite current default music?"_i18n,
|
||||||
|
"No"_i18n, "Yes"_i18n, 0, [](auto op_index){
|
||||||
|
if (op_index && *op_index) {
|
||||||
|
download_default_music();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
download_default_music();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::DisplayNetworkOptions(bool left_side) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::DisplayMiscOptions(bool left_side) {
|
||||||
|
auto options = std::make_shared<ui::Sidebar>("Misc Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT);
|
||||||
|
ON_SCOPE_EXIT(App::Push(options));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryCallback>("Themezer"_i18n, [](){
|
||||||
|
App::Push(std::make_shared<ui::menu::themezer::Menu>());
|
||||||
|
}));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryCallback>("GitHub"_i18n, [](){
|
||||||
|
App::Push(std::make_shared<ui::menu::gh::Menu>());
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (App::GetApp()->m_install.Get()) {
|
||||||
|
if (App::GetFtpEnable()) {
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryCallback>("Ftp Install"_i18n, [](){
|
||||||
|
App::Push(std::make_shared<ui::menu::ftp::Menu>());
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryCallback>("Usb Install"_i18n, [](){
|
||||||
|
App::Push(std::make_shared<ui::menu::usb::Menu>());
|
||||||
|
}));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryCallback>("GameCard Install"_i18n, [](){
|
||||||
|
App::Push(std::make_shared<ui::menu::gc::Menu>());
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryCallback>("Irs (Infrared Joycon Camera)"_i18n, [](){
|
||||||
|
App::Push(std::make_shared<ui::menu::irs::Menu>());
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::DisplayAdvancedOptions(bool left_side) {
|
||||||
|
auto options = std::make_shared<ui::Sidebar>("Advanced Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT);
|
||||||
|
ON_SCOPE_EXIT(App::Push(options));
|
||||||
|
|
||||||
|
ui::SidebarEntryArray::Items text_scroll_speed_items;
|
||||||
|
text_scroll_speed_items.push_back("Slow"_i18n);
|
||||||
|
text_scroll_speed_items.push_back("Normal"_i18n);
|
||||||
|
text_scroll_speed_items.push_back("Fast"_i18n);
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Logging"_i18n, App::GetLogEnable(), [](bool& enable){
|
||||||
|
App::SetLogEnable(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Replace hbmenu on exit"_i18n, App::GetReplaceHbmenuEnable(), [](bool& enable){
|
||||||
|
App::SetReplaceHbmenuEnable(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryArray>("Text scroll speed"_i18n, text_scroll_speed_items, [](s64& index_out){
|
||||||
|
App::SetTextScrollSpeed(index_out);
|
||||||
|
}, (s64)App::GetTextScrollSpeed()));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryCallback>("Install options"_i18n, [left_side](){
|
||||||
|
App::DisplayInstallOptions(left_side);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::DisplayInstallOptions(bool left_side) {
|
||||||
|
auto options = std::make_shared<ui::Sidebar>("Install Options"_i18n, left_side ? ui::Sidebar::Side::LEFT : ui::Sidebar::Side::RIGHT);
|
||||||
|
ON_SCOPE_EXIT(App::Push(options));
|
||||||
|
|
||||||
|
ui::SidebarEntryArray::Items install_items;
|
||||||
|
install_items.push_back("System memory"_i18n);
|
||||||
|
install_items.push_back("microSD card"_i18n);
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Enable"_i18n, App::GetApp()->m_install.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_install.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Show install warning"_i18n, App::GetApp()->m_install_prompt.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_install_prompt.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryArray>("Install location"_i18n, install_items, [](s64& index_out){
|
||||||
|
App::SetInstallSdEnable(index_out);
|
||||||
|
}, (s64)App::GetInstallSdEnable()));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Boost CPU clock"_i18n, App::GetApp()->m_boost_mode.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_boost_mode.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Allow downgrade"_i18n, App::GetApp()->m_allow_downgrade.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_allow_downgrade.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Skip if already installed"_i18n, App::GetApp()->m_skip_if_already_installed.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_skip_if_already_installed.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Ticket only"_i18n, App::GetApp()->m_ticket_only.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_ticket_only.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Skip base"_i18n, App::GetApp()->m_skip_base.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_skip_base.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Skip patch"_i18n, App::GetApp()->m_skip_patch.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_skip_patch.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Skip dlc"_i18n, App::GetApp()->m_skip_addon.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_skip_addon.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Skip data patch"_i18n, App::GetApp()->m_skip_data_patch.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_skip_data_patch.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Skip ticket"_i18n, App::GetApp()->m_skip_ticket.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_skip_ticket.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("skip NCA hash verify"_i18n, App::GetApp()->m_skip_nca_hash_verify.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_skip_nca_hash_verify.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Skip RSA header verify"_i18n, App::GetApp()->m_skip_rsa_header_fixed_key_verify.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_skip_rsa_header_fixed_key_verify.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Skip RSA NPDM verify"_i18n, App::GetApp()->m_skip_rsa_npdm_fixed_key_verify.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_skip_rsa_npdm_fixed_key_verify.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Ignore distribution bit"_i18n, App::GetApp()->m_ignore_distribution_bit.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_ignore_distribution_bit.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Convert to standard crypto"_i18n, App::GetApp()->m_convert_to_standard_crypto.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_convert_to_standard_crypto.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Lower master key"_i18n, App::GetApp()->m_lower_master_key.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_lower_master_key.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<ui::SidebarEntryBool>("Lower system version"_i18n, App::GetApp()->m_lower_system_version.Get(), [](bool& enable){
|
||||||
|
App::GetApp()->m_lower_system_version.Set(enable);
|
||||||
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
}
|
||||||
|
|
||||||
App::~App() {
|
App::~App() {
|
||||||
log_write("starting to exit\n");
|
log_write("starting to exit\n");
|
||||||
|
|
||||||
|
|||||||
@@ -195,6 +195,8 @@ private:
|
|||||||
} else {
|
} else {
|
||||||
const auto update_entry = [this, &hash_key](const char* tag, const std::string& value) {
|
const auto update_entry = [this, &hash_key](const char* tag, const std::string& value) {
|
||||||
if (value.empty()) {
|
if (value.empty()) {
|
||||||
|
// workaround for appstore accepting etags but not returning them.
|
||||||
|
yyjson_mut_obj_remove_str(hash_key, tag);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
auto key = yyjson_mut_obj_get(hash_key, tag);
|
auto key = yyjson_mut_obj_get(hash_key, tag);
|
||||||
@@ -471,7 +473,8 @@ auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.GetFlags() & Flag_Cache) {
|
// only add etag if the dst file still exists.
|
||||||
|
if ((e.GetFlags() & Flag_Cache) && fs::FileExists(&fs.m_fs, e.GetPath())) {
|
||||||
g_cache.get(e.GetPath(), header_in);
|
g_cache.get(e.GetPath(), header_in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -490,6 +493,8 @@ auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult {
|
|||||||
CURL_EASY_SETOPT_LOG(curl, CURLOPT_BUFFERSIZE, 1024*512);
|
CURL_EASY_SETOPT_LOG(curl, CURLOPT_BUFFERSIZE, 1024*512);
|
||||||
CURL_EASY_SETOPT_LOG(curl, CURLOPT_HEADERFUNCTION, header_callback);
|
CURL_EASY_SETOPT_LOG(curl, CURLOPT_HEADERFUNCTION, header_callback);
|
||||||
CURL_EASY_SETOPT_LOG(curl, CURLOPT_HEADERDATA, &header_out);
|
CURL_EASY_SETOPT_LOG(curl, CURLOPT_HEADERDATA, &header_out);
|
||||||
|
// enable all forms of compression supported by libcurl.
|
||||||
|
CURL_EASY_SETOPT_LOG(curl, CURLOPT_ACCEPT_ENCODING, "");
|
||||||
|
|
||||||
if (has_post) {
|
if (has_post) {
|
||||||
CURL_EASY_SETOPT_LOG(curl, CURLOPT_POSTFIELDS, e.GetFields().c_str());
|
CURL_EASY_SETOPT_LOG(curl, CURLOPT_POSTFIELDS, e.GetFields().c_str());
|
||||||
@@ -558,6 +563,15 @@ auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult {
|
|||||||
g_cache.set(e.GetPath(), header_out);
|
g_cache.set(e.GetPath(), header_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enable to log received headers.
|
||||||
|
#if 0
|
||||||
|
log_write("\n\nLOGGING HEADER\n");
|
||||||
|
for (auto [a, b] : header_out.m_map) {
|
||||||
|
log_write("\t%s: %s\n", a.c_str(), b.c_str());
|
||||||
|
}
|
||||||
|
log_write("\n\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
fs.DeleteFile(e.GetPath());
|
fs.DeleteFile(e.GetPath());
|
||||||
fs.CreateDirectoryRecursivelyWithPath(e.GetPath());
|
fs.CreateDirectoryRecursivelyWithPath(e.GetPath());
|
||||||
if (R_FAILED(fs.RenameFile(tmp_buf, e.GetPath()))) {
|
if (R_FAILED(fs.RenameFile(tmp_buf, e.GetPath()))) {
|
||||||
|
|||||||
@@ -715,7 +715,7 @@ void write_nca_header_encypted(nca::Header& nca_header, u64 tid, const keys::Key
|
|||||||
nca_header.magic = NCA3_MAGIC;
|
nca_header.magic = NCA3_MAGIC;
|
||||||
nca_header.distribution_type = nca::DistributionType_System;
|
nca_header.distribution_type = nca::DistributionType_System;
|
||||||
nca_header.content_type = type;
|
nca_header.content_type = type;
|
||||||
nca_header.title_id = tid;
|
nca_header.program_id = tid;
|
||||||
nca_header.sdk_version = 0x000C1100;
|
nca_header.sdk_version = 0x000C1100;
|
||||||
nca_header.size = buf.tell();
|
nca_header.size = buf.tell();
|
||||||
|
|
||||||
@@ -1005,7 +1005,7 @@ auto install_forwarder(ui::ProgressBox* pbox, OwoConfig& config, NcmStorageId st
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto install_forwarder(OwoConfig& config, NcmStorageId storage_id) -> Result {
|
auto install_forwarder(OwoConfig& config, NcmStorageId storage_id) -> Result {
|
||||||
App::Push(std::make_shared<ui::ProgressBox>("Installing Forwarder"_i18n, [config, storage_id](auto pbox) mutable -> bool {
|
App::Push(std::make_shared<ui::ProgressBox>(0, "Installing Forwarder"_i18n, config.name, [config, storage_id](auto pbox) mutable -> bool {
|
||||||
return R_SUCCEEDED(install_forwarder(pbox, config, storage_id));
|
return R_SUCCEEDED(install_forwarder(pbox, config, storage_id));
|
||||||
}));
|
}));
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -34,8 +34,35 @@ auto List::ClampY(float y, s64 count) const -> float {
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void List::OnUpdate(Controller* controller, TouchInfo* touch, s64 count, TouchCallback callback) {
|
void List::OnUpdate(Controller* controller, TouchInfo* touch, s64 index, s64 count, TouchCallback callback) {
|
||||||
if (touch->is_clicked && touch->in_range(GetPos())) {
|
const auto page_up_button = m_row == 1 ? Button::DPAD_LEFT : Button::L2;
|
||||||
|
const auto page_down_button = m_row == 1 ? Button::DPAD_RIGHT : Button::R2;
|
||||||
|
|
||||||
|
if (controller->GotDown(Button::DOWN)) {
|
||||||
|
if (ScrollDown(index, m_row, count)) {
|
||||||
|
callback(false, index);
|
||||||
|
}
|
||||||
|
} else if (controller->GotDown(Button::UP)) {
|
||||||
|
if (ScrollUp(index, m_row, count)) {
|
||||||
|
callback(false, index);
|
||||||
|
}
|
||||||
|
} else if (controller->GotDown(page_down_button)) {
|
||||||
|
if (ScrollDown(index, m_page, count)) {
|
||||||
|
callback(false, index);
|
||||||
|
}
|
||||||
|
} else if (controller->GotDown(page_up_button)) {
|
||||||
|
if (ScrollUp(index, m_page, count)) {
|
||||||
|
callback(false, index);
|
||||||
|
}
|
||||||
|
} else if (m_row > 1 && controller->GotDown(Button::RIGHT)) {
|
||||||
|
if (count && index < (count - 1) && (index + 1) % m_row != 0) {
|
||||||
|
callback(false, index + 1);
|
||||||
|
}
|
||||||
|
} else if (m_row > 1 && controller->GotDown(Button::LEFT)) {
|
||||||
|
if (count && index != 0 && (index % m_row) != 0) {
|
||||||
|
callback(false, index - 1);
|
||||||
|
}
|
||||||
|
} else if (touch->is_clicked && touch->in_range(GetPos())) {
|
||||||
auto v = m_v;
|
auto v = m_v;
|
||||||
v.y -= ClampY(m_yoff + m_y_prog, count);
|
v.y -= ClampY(m_yoff + m_y_prog, count);
|
||||||
|
|
||||||
@@ -63,7 +90,7 @@ void List::OnUpdate(Controller* controller, TouchInfo* touch, s64 count, TouchCa
|
|||||||
vv.h = std::min(v.y + v.h, m_pos.y + m_pos.h) - v.y;
|
vv.h = std::min(v.y + v.h, m_pos.y + m_pos.h) - v.y;
|
||||||
|
|
||||||
if (touch->in_range(vv)) {
|
if (touch->in_range(vv)) {
|
||||||
callback(i);
|
callback(true, i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,18 +236,15 @@ void DrawIcon(NVGcontext* vg, const LazyImage& l, const LazyImage& d, float x, f
|
|||||||
bool crop = false;
|
bool crop = false;
|
||||||
if (iw < w || ih < h) {
|
if (iw < w || ih < h) {
|
||||||
rounded_image = false;
|
rounded_image = false;
|
||||||
gfx::drawRect(vg, x, y, w, h, nvgRGB(i.first_pixel[0], i.first_pixel[1], i.first_pixel[2]), rounded);
|
gfx::drawRect(vg, x, y, w, h, nvgRGB(i.first_pixel[0], i.first_pixel[1], i.first_pixel[2]), rounded ? 15 : 0);
|
||||||
}
|
}
|
||||||
if (iw > w || ih > h) {
|
if (iw > w || ih > h) {
|
||||||
crop = true;
|
crop = true;
|
||||||
nvgSave(vg);
|
nvgSave(vg);
|
||||||
nvgIntersectScissor(vg, x, y, w, h);
|
nvgIntersectScissor(vg, x, y, w, h);
|
||||||
}
|
}
|
||||||
if (rounded_image) {
|
|
||||||
gfx::drawImageRounded(vg, ix, iy, iw, ih, i.image);
|
gfx::drawImage(vg, ix, iy, iw, ih, i.image, rounded_image ? 15 : 0);
|
||||||
} else {
|
|
||||||
gfx::drawImage(vg, ix, iy, iw, ih, i.image);
|
|
||||||
}
|
|
||||||
if (crop) {
|
if (crop) {
|
||||||
nvgRestore(vg);
|
nvgRestore(vg);
|
||||||
}
|
}
|
||||||
@@ -593,6 +590,14 @@ auto InstallApp(ProgressBox* pbox, const Entry& entry) -> bool {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// case-insensitive version of str.find()
|
||||||
|
auto FindCaseInsensitive(std::string_view base, std::string_view term) -> bool {
|
||||||
|
const auto it = std::search(base.cbegin(), base.cend(), term.cbegin(), term.cend(), [](char a, char b){
|
||||||
|
return std::toupper(a) == std::toupper(b);
|
||||||
|
});
|
||||||
|
return it != base.cend();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
EntryMenu::EntryMenu(Entry& entry, const LazyImage& default_icon, Menu& menu)
|
EntryMenu::EntryMenu(Entry& entry, const LazyImage& default_icon, Menu& menu)
|
||||||
@@ -769,7 +774,7 @@ void EntryMenu::UpdateOptions() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto install = [this](){
|
const auto install = [this](){
|
||||||
App::Push(std::make_shared<ProgressBox>("Installing "_i18n + m_entry.title, [this](auto pbox){
|
App::Push(std::make_shared<ProgressBox>(m_entry.image.image, "Downloading "_i18n, m_entry.title, [this](auto pbox){
|
||||||
return InstallApp(pbox, m_entry);
|
return InstallApp(pbox, m_entry);
|
||||||
}, [this](bool success){
|
}, [this](bool success){
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -782,7 +787,7 @@ void EntryMenu::UpdateOptions() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto uninstall = [this](){
|
const auto uninstall = [this](){
|
||||||
App::Push(std::make_shared<ProgressBox>("Uninstalling "_i18n + m_entry.title, [this](auto pbox){
|
App::Push(std::make_shared<ProgressBox>(m_entry.image.image, "Uninstalling "_i18n, m_entry.title, [this](auto pbox){
|
||||||
return UninstallApp(pbox, m_entry);
|
return UninstallApp(pbox, m_entry);
|
||||||
}, [this](bool success){
|
}, [this](bool success){
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -841,12 +846,6 @@ void EntryMenu::SetIndex(s64 index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto toLower(const std::string& str) -> std::string {
|
|
||||||
std::string lower;
|
|
||||||
std::transform(str.cbegin(), str.cend(), std::back_inserter(lower), tolower);
|
|
||||||
return lower;
|
|
||||||
}
|
|
||||||
|
|
||||||
Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"AppStore"_i18n}, m_nro_entries{nro_entries} {
|
Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"AppStore"_i18n}, m_nro_entries{nro_entries} {
|
||||||
fs::FsNativeSd fs;
|
fs::FsNativeSd fs;
|
||||||
fs.CreateDirectoryRecursively("/switch/sphaira/cache/appstore/icons");
|
fs.CreateDirectoryRecursively("/switch/sphaira/cache/appstore/icons");
|
||||||
@@ -854,48 +853,6 @@ Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"AppStore"_i18n}
|
|||||||
fs.CreateDirectoryRecursively("/switch/sphaira/cache/appstore/screens");
|
fs.CreateDirectoryRecursively("/switch/sphaira/cache/appstore/screens");
|
||||||
|
|
||||||
this->SetActions(
|
this->SetActions(
|
||||||
std::make_pair(Button::RIGHT, Action{[this](){
|
|
||||||
if (m_entries_current.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_index < (m_entries_current.size() - 1) && (m_index + 1) % 3 != 0) {
|
|
||||||
SetIndex(m_index + 1);
|
|
||||||
App::PlaySoundEffect(SoundEffect_Scroll);
|
|
||||||
log_write("moved right\n");
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::LEFT, Action{[this](){
|
|
||||||
if (m_entries_current.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_index != 0 && (m_index % 3) != 0) {
|
|
||||||
SetIndex(m_index - 1);
|
|
||||||
App::PlaySoundEffect(SoundEffect_Scroll);
|
|
||||||
log_write("moved left\n");
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::DOWN, Action{[this](){
|
|
||||||
if (m_list->ScrollDown(m_index, 3, m_entries_current.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::UP, Action{[this](){
|
|
||||||
if (m_list->ScrollUp(m_index, 3, m_entries_current.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::R2, Action{[this](){
|
|
||||||
if (m_list->ScrollDown(m_index, 9, m_entries_current.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::L2, Action{[this](){
|
|
||||||
if (m_list->ScrollUp(m_index, 9, m_entries_current.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::A, Action{"Info"_i18n, [this](){
|
std::make_pair(Button::A, Action{"Info"_i18n, [this](){
|
||||||
if (m_entries_current.empty()) {
|
if (m_entries_current.empty()) {
|
||||||
// log_write("pushing A when empty: size: %zu count: %zu\n", repo_json.size(), m_entries_current.size());
|
// log_write("pushing A when empty: size: %zu count: %zu\n", repo_json.size(), m_entries_current.size());
|
||||||
@@ -983,8 +940,8 @@ Menu::~Menu() {
|
|||||||
|
|
||||||
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
||||||
MenuBase::Update(controller, touch);
|
MenuBase::Update(controller, touch);
|
||||||
m_list->OnUpdate(controller, touch, m_entries_current.size(), [this](auto i) {
|
m_list->OnUpdate(controller, touch, m_index, m_entries_current.size(), [this](bool touch, auto i) {
|
||||||
if (m_index == i) {
|
if (touch && m_index == i) {
|
||||||
FireAction(Button::A);
|
FireAction(Button::A);
|
||||||
} else {
|
} else {
|
||||||
App::PlaySoundEffect(SoundEffect_Focus);
|
App::PlaySoundEffect(SoundEffect_Focus);
|
||||||
@@ -1096,16 +1053,16 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
|||||||
float i_size = 22;
|
float i_size = 22;
|
||||||
switch (e.status) {
|
switch (e.status) {
|
||||||
case EntryStatus::Get:
|
case EntryStatus::Get:
|
||||||
gfx::drawImageRounded(vg, x + w - 30.f, y + 110, i_size, i_size, m_get.image);
|
gfx::drawImage(vg, x + w - 30.f, y + 110, i_size, i_size, m_get.image, 15);
|
||||||
break;
|
break;
|
||||||
case EntryStatus::Installed:
|
case EntryStatus::Installed:
|
||||||
gfx::drawImageRounded(vg, x + w - 30.f, y + 110, i_size, i_size, m_installed.image);
|
gfx::drawImage(vg, x + w - 30.f, y + 110, i_size, i_size, m_installed.image, 15);
|
||||||
break;
|
break;
|
||||||
case EntryStatus::Local:
|
case EntryStatus::Local:
|
||||||
gfx::drawImageRounded(vg, x + w - 30.f, y + 110, i_size, i_size, m_local.image);
|
gfx::drawImage(vg, x + w - 30.f, y + 110, i_size, i_size, m_local.image, 15);
|
||||||
break;
|
break;
|
||||||
case EntryStatus::Update:
|
case EntryStatus::Update:
|
||||||
gfx::drawImageRounded(vg, x + w - 30.f, y + 110, i_size, i_size, m_update.image);
|
gfx::drawImage(vg, x + w - 30.f, y + 110, i_size, i_size, m_update.image, 15);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1338,12 +1295,11 @@ void Menu::SetSearch(const std::string& term) {
|
|||||||
|
|
||||||
m_search_term = term;
|
m_search_term = term;
|
||||||
m_entries_index_search.clear();
|
m_entries_index_search.clear();
|
||||||
const auto query = toLower(m_search_term);
|
const auto query = m_search_term;
|
||||||
const auto npos = std::string::npos;
|
|
||||||
|
|
||||||
for (u64 i = 0; i < m_entries.size(); i++) {
|
for (u64 i = 0; i < m_entries.size(); i++) {
|
||||||
const auto& e = m_entries[i];
|
const auto& e = m_entries[i];
|
||||||
if (toLower(e.title).find(query) != npos || toLower(e.author).find(query) != npos || toLower(e.details).find(query) != npos || toLower(e.description).find(query) != npos) {
|
if (FindCaseInsensitive(e.title, query) || FindCaseInsensitive(e.author, query) || FindCaseInsensitive(e.description, query)) {
|
||||||
m_entries_index_search.emplace_back(i);
|
m_entries_index_search.emplace_back(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1372,10 +1328,11 @@ void Menu::SetAuthor() {
|
|||||||
|
|
||||||
m_author_term = m_entries[m_entries_current[m_index]].author;
|
m_author_term = m_entries[m_entries_current[m_index]].author;
|
||||||
m_entries_index_author.clear();
|
m_entries_index_author.clear();
|
||||||
|
const auto query = m_author_term;
|
||||||
|
|
||||||
for (u64 i = 0; i < m_entries.size(); i++) {
|
for (u64 i = 0; i < m_entries.size(); i++) {
|
||||||
const auto& e = m_entries[i];
|
const auto& e = m_entries[i];
|
||||||
if (e.author.find(m_author_term) != std::string::npos) {
|
if (FindCaseInsensitive(e.author, query)) {
|
||||||
m_entries_index_author.emplace_back(i);
|
m_entries_index_author.emplace_back(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "yati/source/file.hpp"
|
#include "yati/source/file.hpp"
|
||||||
|
|
||||||
#include <minIni.h>
|
#include <minIni.h>
|
||||||
|
#include <minizip/zip.h>
|
||||||
#include <minizip/unzip.h>
|
#include <minizip/unzip.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -57,6 +58,14 @@ constexpr std::string_view IMAGE_EXTENSIONS[] = {
|
|||||||
constexpr std::string_view INSTALL_EXTENSIONS[] = {
|
constexpr std::string_view INSTALL_EXTENSIONS[] = {
|
||||||
"nsp", "xci", "nsz", "xcz",
|
"nsp", "xci", "nsz", "xcz",
|
||||||
};
|
};
|
||||||
|
// these are files that are already compressed or encrypted and should
|
||||||
|
// be stored raw in a zip file.
|
||||||
|
constexpr std::string_view COMPRESSED_EXTENSIONS[] = {
|
||||||
|
"zip", "xz", "7z", "rar", "tar", "nca", "nsp", "xci", "nsz", "xcz"
|
||||||
|
};
|
||||||
|
constexpr std::string_view ZIP_EXTENSIONS[] = {
|
||||||
|
"zip",
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct RomDatabaseEntry {
|
struct RomDatabaseEntry {
|
||||||
@@ -267,6 +276,25 @@ auto GetRomIcon(fs::FsNative* fs, ProgressBox* pbox, std::string filename, const
|
|||||||
|
|
||||||
Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"FileBrowser"_i18n}, m_nro_entries{nro_entries} {
|
Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"FileBrowser"_i18n}, m_nro_entries{nro_entries} {
|
||||||
this->SetActions(
|
this->SetActions(
|
||||||
|
std::make_pair(Button::L2, Action{[this](){
|
||||||
|
if (!m_selected_files.empty()) {
|
||||||
|
ResetSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto set = m_selected_count != m_entries_current.size();
|
||||||
|
|
||||||
|
for (const auto& i : m_entries_current) {
|
||||||
|
auto& e = GetEntry(i);
|
||||||
|
if (e.selected != set) {
|
||||||
|
e.selected = set;
|
||||||
|
if (set) {
|
||||||
|
m_selected_count++;
|
||||||
|
} else {
|
||||||
|
m_selected_count--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}),
|
||||||
std::make_pair(Button::R2, Action{[this](){
|
std::make_pair(Button::R2, Action{[this](){
|
||||||
if (!m_selected_files.empty()) {
|
if (!m_selected_files.empty()) {
|
||||||
ResetSelection();
|
ResetSelection();
|
||||||
@@ -279,26 +307,6 @@ Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"FileBrowser"_i1
|
|||||||
m_selected_count--;
|
m_selected_count--;
|
||||||
}
|
}
|
||||||
}}),
|
}}),
|
||||||
std::make_pair(Button::DOWN, Action{[this](){
|
|
||||||
if (m_list->ScrollDown(m_index, 1, m_entries_current.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::UP, Action{[this](){
|
|
||||||
if (m_list->ScrollUp(m_index, 1, m_entries_current.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::DPAD_RIGHT, Action{[this](){
|
|
||||||
if (m_list->ScrollDown(m_index, 8, m_entries_current.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::DPAD_LEFT, Action{[this](){
|
|
||||||
if (m_list->ScrollUp(m_index, 8, m_entries_current.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::A, Action{"Open"_i18n, [this](){
|
std::make_pair(Button::A, Action{"Open"_i18n, [this](){
|
||||||
if (m_entries_current.empty()) {
|
if (m_entries_current.empty()) {
|
||||||
return;
|
return;
|
||||||
@@ -495,22 +503,24 @@ Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"FileBrowser"_i1
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if install is enabled, check if all currently selected files are installable.
|
// returns true if all entries match the ext array.
|
||||||
if (m_entries_current.size() && App::GetInstallEnable()) {
|
const auto check_all_ext = [this](auto& exts){
|
||||||
bool should_install = true;
|
|
||||||
if (!m_selected_count) {
|
if (!m_selected_count) {
|
||||||
should_install = IsExtension(GetEntry().GetExtension(), INSTALL_EXTENSIONS);
|
return IsExtension(GetEntry().GetExtension(), exts);
|
||||||
} else {
|
} else {
|
||||||
const auto entries = GetSelectedEntries();
|
const auto entries = GetSelectedEntries();
|
||||||
for (auto&e : entries) {
|
for (auto&e : entries) {
|
||||||
if (!IsExtension(e.GetExtension(), INSTALL_EXTENSIONS)) {
|
if (!IsExtension(e.GetExtension(), exts)) {
|
||||||
should_install = false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
if (should_install) {
|
// if install is enabled, check if all currently selected files are installable.
|
||||||
|
if (m_entries_current.size() && App::GetInstallEnable()) {
|
||||||
|
if (check_all_ext(INSTALL_EXTENSIONS)) {
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Install"_i18n, [this](){
|
options->Add(std::make_shared<SidebarEntryCallback>("Install"_i18n, [this](){
|
||||||
if (!m_selected_count) {
|
if (!m_selected_count) {
|
||||||
InstallFile(GetEntry());
|
InstallFile(GetEntry());
|
||||||
@@ -521,6 +531,79 @@ Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"FileBrowser"_i1
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_fs_type == FsType::Sd && m_entries_current.size()) {
|
||||||
|
if (App::GetInstallEnable() && HasTypeInSelectedEntries(FsDirEntryType_File) && !m_selected_count && (GetEntry().GetExtension() == "nro" || !FindFileAssocFor().empty())) {
|
||||||
|
options->Add(std::make_shared<SidebarEntryCallback>("Install Forwarder"_i18n, [this](){;
|
||||||
|
if (App::GetInstallPrompt()) {
|
||||||
|
App::Push(std::make_shared<OptionBox>(
|
||||||
|
"WARNING: Installing forwarders will lead to a ban!"_i18n,
|
||||||
|
"Back"_i18n, "Install"_i18n, 0, [this](auto op_index){
|
||||||
|
if (op_index && *op_index) {
|
||||||
|
InstallForwarder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
InstallForwarder();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_entries_current.size()) {
|
||||||
|
if (check_all_ext(ZIP_EXTENSIONS)) {
|
||||||
|
options->Add(std::make_shared<SidebarEntryCallback>("Extract"_i18n, [this](){
|
||||||
|
auto options = std::make_shared<Sidebar>("Extract Options"_i18n, Sidebar::Side::RIGHT);
|
||||||
|
ON_SCOPE_EXIT(App::Push(options));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<SidebarEntryCallback>("Extract here"_i18n, [this](){
|
||||||
|
if (!m_selected_count) {
|
||||||
|
UnzipFile("", GetEntry());
|
||||||
|
} else {
|
||||||
|
UnzipFiles("", GetSelectedEntries());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<SidebarEntryCallback>("Extract to..."_i18n, [this](){
|
||||||
|
std::string out;
|
||||||
|
if (R_SUCCEEDED(swkbd::ShowText(out, "Enter the path to the folder to extract into", fs::AppendPath(m_path, ""))) && !out.empty()) {
|
||||||
|
if (!m_selected_count) {
|
||||||
|
UnzipFile(out, GetEntry());
|
||||||
|
} else {
|
||||||
|
UnzipFiles(out, GetSelectedEntries());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!check_all_ext(ZIP_EXTENSIONS) || m_selected_count) {
|
||||||
|
options->Add(std::make_shared<SidebarEntryCallback>("Compress"_i18n, [this](){
|
||||||
|
auto options = std::make_shared<Sidebar>("Compress Options"_i18n, Sidebar::Side::RIGHT);
|
||||||
|
ON_SCOPE_EXIT(App::Push(options));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<SidebarEntryCallback>("Compress"_i18n, [this](){
|
||||||
|
if (!m_selected_count) {
|
||||||
|
ZipFile("", GetEntry());
|
||||||
|
} else {
|
||||||
|
ZipFiles("", GetSelectedEntries());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
options->Add(std::make_shared<SidebarEntryCallback>("Compress to..."_i18n, [this](){
|
||||||
|
std::string out;
|
||||||
|
if (R_SUCCEEDED(swkbd::ShowText(out, "Enter the path to the folder to extract into", m_path)) && !out.empty()) {
|
||||||
|
if (!m_selected_count) {
|
||||||
|
ZipFile(out, GetEntry());
|
||||||
|
} else {
|
||||||
|
ZipFiles(out, GetSelectedEntries());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Advanced"_i18n, [this](){
|
options->Add(std::make_shared<SidebarEntryCallback>("Advanced"_i18n, [this](){
|
||||||
auto options = std::make_shared<Sidebar>("Advanced Options"_i18n, Sidebar::Side::RIGHT);
|
auto options = std::make_shared<Sidebar>("Advanced Options"_i18n, Sidebar::Side::RIGHT);
|
||||||
ON_SCOPE_EXIT(App::Push(options));
|
ON_SCOPE_EXIT(App::Push(options));
|
||||||
@@ -549,7 +632,7 @@ Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"FileBrowser"_i1
|
|||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Create Folder"_i18n, [this](){
|
options->Add(std::make_shared<SidebarEntryCallback>("Create Folder"_i18n, [this](){
|
||||||
std::string out;
|
std::string out;
|
||||||
if (R_SUCCEEDED(swkbd::ShowText(out, "Set Folder Name"_i18n.c_str())) && !out.empty()) {
|
if (R_SUCCEEDED(swkbd::ShowText(out, "Set Folder Name"_i18n.c_str(), fs::AppendPath(m_path, ""))) && !out.empty()) {
|
||||||
App::PopToMenu();
|
App::PopToMenu();
|
||||||
|
|
||||||
fs::FsPath full_path;
|
fs::FsPath full_path;
|
||||||
@@ -574,25 +657,6 @@ Menu::Menu(const std::vector<NroEntry>& nro_entries) : MenuBase{"FileBrowser"_i1
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_fs_type == FsType::Sd && m_entries_current.size()) {
|
|
||||||
if (App::GetInstallEnable() && HasTypeInSelectedEntries(FsDirEntryType_File) && !m_selected_count && (GetEntry().GetExtension() == "nro" || !FindFileAssocFor().empty())) {
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Install Forwarder"_i18n, [this](){;
|
|
||||||
if (App::GetInstallPrompt()) {
|
|
||||||
App::Push(std::make_shared<OptionBox>(
|
|
||||||
"WARNING: Installing forwarders will lead to a ban!"_i18n,
|
|
||||||
"Back"_i18n, "Install"_i18n, 0, [this](auto op_index){
|
|
||||||
if (op_index && *op_index) {
|
|
||||||
InstallForwarder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
InstallForwarder();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Ignore read only"_i18n, m_ignore_read_only.Get(), [this](bool& v_out){
|
options->Add(std::make_shared<SidebarEntryBool>("Ignore read only"_i18n, m_ignore_read_only.Get(), [this](bool& v_out){
|
||||||
m_ignore_read_only.Set(v_out);
|
m_ignore_read_only.Set(v_out);
|
||||||
m_fs->SetIgnoreReadOnly(v_out);
|
m_fs->SetIgnoreReadOnly(v_out);
|
||||||
@@ -626,8 +690,8 @@ Menu::~Menu() {
|
|||||||
|
|
||||||
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
||||||
MenuBase::Update(controller, touch);
|
MenuBase::Update(controller, touch);
|
||||||
m_list->OnUpdate(controller, touch, m_entries_current.size(), [this](auto i) {
|
m_list->OnUpdate(controller, touch, m_index, m_entries_current.size(), [this](bool touch, auto i) {
|
||||||
if (m_index == i) {
|
if (touch && m_index == i) {
|
||||||
FireAction(Button::A);
|
FireAction(Button::A);
|
||||||
} else {
|
} else {
|
||||||
App::PlaySoundEffect(SoundEffect_Focus);
|
App::PlaySoundEffect(SoundEffect_Focus);
|
||||||
@@ -693,7 +757,7 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
|||||||
} else if (IsExtension(ext, INSTALL_EXTENSIONS)) {
|
} else if (IsExtension(ext, INSTALL_EXTENSIONS)) {
|
||||||
// todo: maybe replace this icon with something else?
|
// todo: maybe replace this icon with something else?
|
||||||
icon = ThemeEntryID_ICON_NRO;
|
icon = ThemeEntryID_ICON_NRO;
|
||||||
} else if (IsExtension(ext, "zip")) {
|
} else if (IsExtension(ext, ZIP_EXTENSIONS)) {
|
||||||
icon = ThemeEntryID_ICON_ZIP;
|
icon = ThemeEntryID_ICON_ZIP;
|
||||||
} else if (IsExtension(ext, "nro")) {
|
} else if (IsExtension(ext, "nro")) {
|
||||||
icon = ThemeEntryID_ICON_NRO;
|
icon = ThemeEntryID_ICON_NRO;
|
||||||
@@ -802,7 +866,7 @@ void Menu::InstallForwarder() {
|
|||||||
if (op_index) {
|
if (op_index) {
|
||||||
const auto assoc = assoc_list[*op_index];
|
const auto assoc = assoc_list[*op_index];
|
||||||
log_write("pushing it\n");
|
log_write("pushing it\n");
|
||||||
App::Push(std::make_shared<ProgressBox>("Installing Forwarder"_i18n, [assoc, this](auto pbox) -> bool {
|
App::Push(std::make_shared<ProgressBox>(0, "Installing Forwarder"_i18n, GetEntry().name, [assoc, this](auto pbox) -> bool {
|
||||||
log_write("inside callback\n");
|
log_write("inside callback\n");
|
||||||
|
|
||||||
NroEntry nro{};
|
NroEntry nro{};
|
||||||
@@ -829,6 +893,7 @@ void Menu::InstallForwarder() {
|
|||||||
// config.name = file_name;
|
// config.name = file_name;
|
||||||
config.nacp = nro.nacp;
|
config.nacp = nro.nacp;
|
||||||
config.icon = GetRomIcon(m_fs.get(), pbox, file_name, db_indexs, nro);
|
config.icon = GetRomIcon(m_fs.get(), pbox, file_name, db_indexs, nro);
|
||||||
|
pbox->SetImageDataConst(config.icon);
|
||||||
|
|
||||||
return R_SUCCEEDED(App::Install(pbox, config));
|
return R_SUCCEEDED(App::Install(pbox, config));
|
||||||
}));
|
}));
|
||||||
@@ -849,7 +914,7 @@ void Menu::InstallFiles(const std::vector<FileEntry>& targets) {
|
|||||||
if (op_index && *op_index) {
|
if (op_index && *op_index) {
|
||||||
App::PopToMenu();
|
App::PopToMenu();
|
||||||
|
|
||||||
App::Push(std::make_shared<ui::ProgressBox>("Installing App"_i18n, [this, targets](auto pbox) mutable -> bool {
|
App::Push(std::make_shared<ui::ProgressBox>(0, "Installing "_i18n, "", [this, targets](auto pbox) mutable -> bool {
|
||||||
for (auto& e : targets) {
|
for (auto& e : targets) {
|
||||||
const auto rc = yati::InstallFromFile(pbox, &m_fs->m_fs, GetNewPath(e));
|
const auto rc = yati::InstallFromFile(pbox, &m_fs->m_fs, GetNewPath(e));
|
||||||
if (rc == yati::Result_Cancelled) {
|
if (rc == yati::Result_Cancelled) {
|
||||||
@@ -867,6 +932,272 @@ void Menu::InstallFiles(const std::vector<FileEntry>& targets) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Menu::UnzipFile(const fs::FsPath& dir_path, const FileEntry& target) {
|
||||||
|
std::vector<FileEntry> targets{target};
|
||||||
|
UnzipFiles(dir_path, targets);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::UnzipFiles(fs::FsPath dir_path, const std::vector<FileEntry>& targets) {
|
||||||
|
// set to current path.
|
||||||
|
if (dir_path.empty()) {
|
||||||
|
dir_path = m_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
App::Push(std::make_shared<ui::ProgressBox>(0, "Extracting "_i18n, "", [this, dir_path, targets](auto pbox) mutable -> bool {
|
||||||
|
constexpr auto chunk_size = 1024 * 512; // 512KiB
|
||||||
|
auto& fs = *m_fs.get();
|
||||||
|
|
||||||
|
for (auto& e : targets) {
|
||||||
|
pbox->SetTitle(e.GetName());
|
||||||
|
|
||||||
|
const auto zip_out = GetNewPath(e);
|
||||||
|
auto zfile = unzOpen64(zip_out);
|
||||||
|
if (!zfile) {
|
||||||
|
log_write("failed to open zip: %s\n", zip_out.s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ON_SCOPE_EXIT(unzClose(zfile));
|
||||||
|
|
||||||
|
unz_global_info64 pglobal_info;
|
||||||
|
if (UNZ_OK != unzGetGlobalInfo64(zfile, &pglobal_info)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < pglobal_info.number_entry; i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
if (UNZ_OK != unzGoToNextFile(zfile)) {
|
||||||
|
log_write("failed to unzGoToNextFile\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (UNZ_OK != unzOpenCurrentFile(zfile)) {
|
||||||
|
log_write("failed to open current file\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ON_SCOPE_EXIT(unzCloseCurrentFile(zfile));
|
||||||
|
|
||||||
|
unz_file_info64 info;
|
||||||
|
char name[512];
|
||||||
|
if (UNZ_OK != unzGetCurrentFileInfo64(zfile, &info, name, sizeof(name), 0, 0, 0, 0)) {
|
||||||
|
log_write("failed to get current info\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto file_path = fs::AppendPath(dir_path, name);
|
||||||
|
pbox->NewTransfer(name);
|
||||||
|
|
||||||
|
// create directories
|
||||||
|
fs.CreateDirectoryRecursivelyWithPath(file_path);
|
||||||
|
|
||||||
|
Result rc;
|
||||||
|
if (R_FAILED(rc = fs.CreateFile(file_path, info.uncompressed_size, 0)) && rc != FsError_PathAlreadyExists) {
|
||||||
|
log_write("failed to create file: %s 0x%04X\n", file_path.s, rc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
FsFile f;
|
||||||
|
if (R_FAILED(rc = fs.OpenFile(file_path, FsOpenMode_Write, &f))) {
|
||||||
|
log_write("failed to open file: %s 0x%04X\n", file_path.s, rc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ON_SCOPE_EXIT(fsFileClose(&f));
|
||||||
|
|
||||||
|
if (R_FAILED(rc = fsFileSetSize(&f, info.uncompressed_size))) {
|
||||||
|
log_write("failed to set file size: %s 0x%04X\n", file_path.s, rc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<char> buf(chunk_size);
|
||||||
|
s64 offset{};
|
||||||
|
while (offset < info.uncompressed_size) {
|
||||||
|
if (pbox->ShouldExit()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto bytes_read = unzReadCurrentFile(zfile, buf.data(), buf.size());
|
||||||
|
if (bytes_read <= 0) {
|
||||||
|
log_write("failed to read zip file: %s\n", name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (R_FAILED(rc = fsFileWrite(&f, offset, buf.data(), bytes_read, FsWriteOption_None))) {
|
||||||
|
log_write("failed to write file: %s 0x%04X\n", file_path.s, rc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pbox->UpdateTransfer(offset, info.uncompressed_size);
|
||||||
|
offset += bytes_read;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}, [this](bool success){
|
||||||
|
if (success) {
|
||||||
|
App::Notify("Extract success!");
|
||||||
|
} else {
|
||||||
|
App::Notify("Extract failed!");
|
||||||
|
}
|
||||||
|
Scan(m_path);
|
||||||
|
log_write("did extract\n");
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::ZipFile(const fs::FsPath& zip_path, const FileEntry& target) {
|
||||||
|
std::vector<FileEntry> targets{target};
|
||||||
|
ZipFiles(zip_path, targets);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::ZipFiles(fs::FsPath zip_out, const std::vector<FileEntry>& targets) {
|
||||||
|
// set to current path.
|
||||||
|
if (zip_out.empty()) {
|
||||||
|
if (std::size(targets) == 1) {
|
||||||
|
const auto name = targets[0].name;
|
||||||
|
const auto ext = std::strrchr(targets[0].name, '.');
|
||||||
|
fs::FsPath file_path;
|
||||||
|
if (!ext) {
|
||||||
|
std::snprintf(file_path, sizeof(file_path), "%s.zip", name);
|
||||||
|
} else {
|
||||||
|
std::snprintf(file_path, sizeof(file_path), "%.*s.zip", (int)(ext - name), name);
|
||||||
|
}
|
||||||
|
zip_out = fs::AppendPath(m_path, file_path);
|
||||||
|
log_write("zip out: %s name: %s file_path: %s\n", zip_out.s, name, file_path.s);
|
||||||
|
} else {
|
||||||
|
// loop until we find an unused file name.
|
||||||
|
for (u64 i = 0; ; i++) {
|
||||||
|
fs::FsPath file_path = "Archive.zip";
|
||||||
|
if (i) {
|
||||||
|
std::snprintf(file_path, sizeof(file_path), "Archive (%zu).zip", i);
|
||||||
|
}
|
||||||
|
|
||||||
|
zip_out = fs::AppendPath(m_path, file_path);
|
||||||
|
if (!fs::FileExists(&m_fs->m_fs, zip_out)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!std::string_view(zip_out).ends_with(".zip")) {
|
||||||
|
zip_out += ".zip";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
App::Push(std::make_shared<ui::ProgressBox>(0, "Compressing "_i18n, "", [this, zip_out, targets](auto pbox) mutable -> bool {
|
||||||
|
constexpr auto chunk_size = 1024 * 512; // 512KiB
|
||||||
|
auto& fs = *m_fs.get();
|
||||||
|
|
||||||
|
const auto t = std::time(NULL);
|
||||||
|
const auto tm = std::localtime(&t);
|
||||||
|
|
||||||
|
// pre-calculate the time rather than calculate it in the loop.
|
||||||
|
zip_fileinfo zip_info{};
|
||||||
|
zip_info.tmz_date.tm_sec = tm->tm_sec;
|
||||||
|
zip_info.tmz_date.tm_min = tm->tm_min;
|
||||||
|
zip_info.tmz_date.tm_hour = tm->tm_hour;
|
||||||
|
zip_info.tmz_date.tm_mday = tm->tm_mday;
|
||||||
|
zip_info.tmz_date.tm_mon = tm->tm_mon;
|
||||||
|
zip_info.tmz_date.tm_year = tm->tm_year;
|
||||||
|
|
||||||
|
auto zfile = zipOpen(zip_out, APPEND_STATUS_CREATE);
|
||||||
|
if (!zfile) {
|
||||||
|
log_write("failed to open zip: %s\n", zip_out.s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ON_SCOPE_EXIT(zipClose(zfile, "sphaira v" APP_VERSION_HASH));
|
||||||
|
|
||||||
|
const auto zip_add = [&](const fs::FsPath& file_path){
|
||||||
|
// the file name needs to be relative to the current directory.
|
||||||
|
const char* file_name_in_zip = file_path.s + std::strlen(m_path);
|
||||||
|
|
||||||
|
// root paths are banned in zips, they will warn when extracting otherwise.
|
||||||
|
if (file_name_in_zip[0] == '/') {
|
||||||
|
file_name_in_zip++;
|
||||||
|
}
|
||||||
|
|
||||||
|
pbox->NewTransfer(file_name_in_zip);
|
||||||
|
|
||||||
|
const auto ext = std::strrchr(file_name_in_zip, '.');
|
||||||
|
const auto raw = ext && IsExtension(ext + 1, COMPRESSED_EXTENSIONS);
|
||||||
|
|
||||||
|
if (ZIP_OK != zipOpenNewFileInZip2(zfile, file_name_in_zip, &zip_info, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION, raw)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ON_SCOPE_EXIT(zipCloseFileInZip(zfile));
|
||||||
|
|
||||||
|
FsFile f;
|
||||||
|
Result rc;
|
||||||
|
if (R_FAILED(rc = fs.OpenFile(file_path, FsOpenMode_Read, &f))) {
|
||||||
|
log_write("failed to open file: %s 0x%04X\n", file_path.s, rc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ON_SCOPE_EXIT(fsFileClose(&f));
|
||||||
|
|
||||||
|
s64 file_size;
|
||||||
|
if (R_FAILED(rc = fsFileGetSize(&f, &file_size))) {
|
||||||
|
log_write("failed to get file size: %s 0x%04X\n", file_path.s, rc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<char> buf(chunk_size);
|
||||||
|
s64 offset{};
|
||||||
|
while (offset < file_size) {
|
||||||
|
if (pbox->ShouldExit()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 bytes_read;
|
||||||
|
if (R_FAILED(rc = fsFileRead(&f, offset, buf.data(), buf.size(), FsReadOption_None, &bytes_read))) {
|
||||||
|
log_write("failed to write file: %s 0x%04X\n", file_path.s, rc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ZIP_OK != zipWriteInFileInZip(zfile, buf.data(), bytes_read)) {
|
||||||
|
log_write("failed to write zip file: %s\n", file_path.s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pbox->UpdateTransfer(offset, file_size);
|
||||||
|
offset += bytes_read;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto& e : targets) {
|
||||||
|
pbox->SetTitle(e.GetName());
|
||||||
|
if (e.IsFile()) {
|
||||||
|
const auto file_path = GetNewPath(e);
|
||||||
|
if (!zip_add(file_path)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
FsDirCollections collections;
|
||||||
|
get_collections(GetNewPath(e), e.name, collections);
|
||||||
|
|
||||||
|
for (const auto& collection : collections) {
|
||||||
|
for (const auto& file : collection.files) {
|
||||||
|
const auto file_path = fs::AppendPath(collection.path, file.name);
|
||||||
|
if (!zip_add(file_path)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}, [this](bool success){
|
||||||
|
if (success) {
|
||||||
|
App::Notify("Compress success!");
|
||||||
|
} else {
|
||||||
|
App::Notify("Compress failed!");
|
||||||
|
}
|
||||||
|
Scan(m_path);
|
||||||
|
log_write("did compress\n");
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
auto Menu::Scan(const fs::FsPath& new_path, bool is_walk_up) -> Result {
|
auto Menu::Scan(const fs::FsPath& new_path, bool is_walk_up) -> Result {
|
||||||
log_write("new scan path: %s\n", new_path.s);
|
log_write("new scan path: %s\n", new_path.s);
|
||||||
if (!is_walk_up && !m_path.empty() && !m_entries_current.empty()) {
|
if (!is_walk_up && !m_path.empty() && !m_entries_current.empty()) {
|
||||||
@@ -1226,7 +1557,7 @@ void Menu::OnDeleteCallback() {
|
|||||||
Scan(m_path);
|
Scan(m_path);
|
||||||
log_write("did delete\n");
|
log_write("did delete\n");
|
||||||
} else {
|
} else {
|
||||||
App::Push(std::make_shared<ProgressBox>("Deleting"_i18n, [this](auto pbox){
|
App::Push(std::make_shared<ProgressBox>(0, "Deleting"_i18n, "", [this](auto pbox){
|
||||||
FsDirCollections collections;
|
FsDirCollections collections;
|
||||||
|
|
||||||
// build list of dirs / files
|
// build list of dirs / files
|
||||||
@@ -1319,7 +1650,7 @@ void Menu::OnPasteCallback() {
|
|||||||
Scan(m_path);
|
Scan(m_path);
|
||||||
log_write("did paste\n");
|
log_write("did paste\n");
|
||||||
} else {
|
} else {
|
||||||
App::Push(std::make_shared<ProgressBox>("Pasting"_i18n, [this](auto pbox){
|
App::Push(std::make_shared<ProgressBox>(0, "Pasting"_i18n, "", [this](auto pbox){
|
||||||
|
|
||||||
if (m_selected_type == SelectedType::Cut) {
|
if (m_selected_type == SelectedType::Cut) {
|
||||||
for (const auto& p : m_selected_files) {
|
for (const auto& p : m_selected_files) {
|
||||||
|
|||||||
@@ -146,6 +146,10 @@ Menu::Menu() : MenuBase{"FTP Install (EXPERIMENTAL)"_i18n} {
|
|||||||
SetPop();
|
SetPop();
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
SetAction(Button::X, Action{"Options"_i18n, [this](){
|
||||||
|
App::DisplayInstallOptions(false);
|
||||||
|
}});
|
||||||
|
|
||||||
mutexInit(&m_mutex);
|
mutexInit(&m_mutex);
|
||||||
ftpsrv::InitInstallMode(this, OnInstallStart, OnInstallWrite, OnInstallClose);
|
ftpsrv::InitInstallMode(this, OnInstallStart, OnInstallWrite, OnInstallClose);
|
||||||
|
|
||||||
@@ -183,7 +187,7 @@ void Menu::Update(Controller* controller, TouchInfo* touch) {
|
|||||||
log_write("set to progress\n");
|
log_write("set to progress\n");
|
||||||
m_state = State::Progress;
|
m_state = State::Progress;
|
||||||
log_write("got connection\n");
|
log_write("got connection\n");
|
||||||
App::Push(std::make_shared<ui::ProgressBox>("Installing App"_i18n, [this](auto pbox) mutable -> bool {
|
App::Push(std::make_shared<ui::ProgressBox>(0, "Installing "_i18n, "", [this](auto pbox) mutable -> bool {
|
||||||
log_write("inside progress box\n");
|
log_write("inside progress box\n");
|
||||||
const auto rc = yati::InstallFromSource(pbox, m_source, m_source->m_path);
|
const auto rc = yati::InstallFromSource(pbox, m_source, m_source->m_path);
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "ui/menus/gc_menu.hpp"
|
#include "ui/menus/gc_menu.hpp"
|
||||||
#include "yati/yati.hpp"
|
#include "yati/yati.hpp"
|
||||||
|
#include "yati/nx/nca.hpp"
|
||||||
#include "app.hpp"
|
#include "app.hpp"
|
||||||
#include "defines.hpp"
|
#include "defines.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
@@ -10,26 +11,110 @@
|
|||||||
namespace sphaira::ui::menu::gc {
|
namespace sphaira::ui::menu::gc {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
const char *g_option_list[] = {
|
||||||
|
"Nand Install",
|
||||||
|
"SD Card Install",
|
||||||
|
"Exit",
|
||||||
|
};
|
||||||
|
|
||||||
|
struct HashStr {
|
||||||
|
char str[0x21];
|
||||||
|
};
|
||||||
|
|
||||||
|
HashStr hexIdToStr(auto id) {
|
||||||
|
HashStr str{};
|
||||||
|
const auto id_lower = std::byteswap(*(u64*)id.c);
|
||||||
|
const auto id_upper = std::byteswap(*(u64*)(id.c + 0x8));
|
||||||
|
std::snprintf(str.str, 0x21, "%016lx%016lx", id_lower, id_upper);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Gc is the mount point, S is for secure partion, the remaining is the
|
||||||
|
// the gamecard handle value in lower-case hex.
|
||||||
|
auto BuildGcPath(const char* name, const FsGameCardHandle* handle, FsGameCardPartition partiton = FsGameCardPartition_Secure) -> fs::FsPath {
|
||||||
|
static const char mount_parition[] = {
|
||||||
|
[FsGameCardPartition_Update] = 'U',
|
||||||
|
[FsGameCardPartition_Normal] = 'N',
|
||||||
|
[FsGameCardPartition_Secure] = 'S',
|
||||||
|
[FsGameCardPartition_Logo] = 'L',
|
||||||
|
};
|
||||||
|
|
||||||
|
fs::FsPath path;
|
||||||
|
std::snprintf(path, sizeof(path), "@Gc%c%08x://%s", mount_parition[partiton], handle->value, name);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result fsOpenGameCardDetectionEventNotifier(FsEventNotifier* out) {
|
||||||
|
return serviceDispatch(fsGetServiceSession(), 501,
|
||||||
|
.out_num_objects = 1,
|
||||||
|
.out_objects = &out->s
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
auto InRange(u64 off, u64 offset, u64 size) -> bool {
|
auto InRange(u64 off, u64 offset, u64 size) -> bool {
|
||||||
return off < offset + size && off >= offset;
|
return off < offset + size && off >= offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GcSource final : yati::source::Base {
|
struct GcSource final : yati::source::Base {
|
||||||
GcSource(const yati::container::Collections& collections, fs::FsNativeGameCard* fs);
|
GcSource(const ApplicationEntry& entry, fs::FsNativeGameCard* fs, bool sd_install);
|
||||||
~GcSource();
|
~GcSource();
|
||||||
Result Read(void* buf, s64 off, s64 size, u64* bytes_read);
|
Result Read(void* buf, s64 off, s64 size, u64* bytes_read);
|
||||||
|
|
||||||
const yati::container::Collections& m_collections;
|
yati::container::Collections m_collections{};
|
||||||
|
yati::ConfigOverride m_config{};
|
||||||
fs::FsNativeGameCard* m_fs{};
|
fs::FsNativeGameCard* m_fs{};
|
||||||
FsFile m_file{};
|
FsFile m_file{};
|
||||||
s64 m_offset{};
|
s64 m_offset{};
|
||||||
s64 m_size{};
|
s64 m_size{};
|
||||||
};
|
};
|
||||||
|
|
||||||
GcSource::GcSource(const yati::container::Collections& collections, fs::FsNativeGameCard* fs)
|
GcSource::GcSource(const ApplicationEntry& entry, fs::FsNativeGameCard* fs, bool sd_install)
|
||||||
: m_collections{collections}
|
: m_fs{fs} {
|
||||||
, m_fs{fs} {
|
|
||||||
m_offset = -1;
|
m_offset = -1;
|
||||||
|
|
||||||
|
s64 offset{};
|
||||||
|
const auto add_collections = [&](const auto& collections) {
|
||||||
|
for (auto collection : collections) {
|
||||||
|
collection.offset = offset;
|
||||||
|
m_collections.emplace_back(collection);
|
||||||
|
offset += collection.size;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto add_entries = [&](const auto& entries) {
|
||||||
|
for (auto& e : entries) {
|
||||||
|
add_collections(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// yati can handle all of this for use, however, yati lacks information
|
||||||
|
// for ncas until it installs the cnmt and parses it.
|
||||||
|
// as we already have this info, we can only send yati what we want to install.
|
||||||
|
if (App::GetApp()->m_ticket_only.Get()) {
|
||||||
|
add_collections(entry.tickets);
|
||||||
|
} else {
|
||||||
|
if (!App::GetApp()->m_skip_base.Get()) {
|
||||||
|
add_entries(entry.application);
|
||||||
|
}
|
||||||
|
if (!App::GetApp()->m_skip_patch.Get()) {
|
||||||
|
add_entries(entry.patch);
|
||||||
|
}
|
||||||
|
if (!App::GetApp()->m_skip_addon.Get()) {
|
||||||
|
add_entries(entry.add_on);
|
||||||
|
}
|
||||||
|
if (!App::GetApp()->m_skip_data_patch.Get()) {
|
||||||
|
add_entries(entry.data_patch);
|
||||||
|
}
|
||||||
|
if (!App::GetApp()->m_skip_ticket.Get()) {
|
||||||
|
add_collections(entry.tickets);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// we don't need to verify the nca's, this speeds up installs.
|
||||||
|
m_config.sd_card_install = sd_install;
|
||||||
|
m_config.skip_nca_hash_verify = true;
|
||||||
|
m_config.skip_rsa_header_fixed_key_verify = true;
|
||||||
|
m_config.skip_rsa_npdm_fixed_key_verify = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GcSource::~GcSource() {
|
GcSource::~GcSource() {
|
||||||
@@ -63,86 +148,133 @@ Result GcSource::Read(void* buf, s64 off, s64 size, u64* bytes_read) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Menu::Menu() : MenuBase{"GameCard"_i18n} {
|
auto ApplicationEntry::GetSize(const std::vector<GcCollections>& entries) const -> s64 {
|
||||||
SetAction(Button::B, Action{"Back"_i18n, [this](){
|
s64 size{};
|
||||||
SetPop();
|
for (auto& e : entries) {
|
||||||
}});
|
for (auto& collection : e) {
|
||||||
|
size += collection.size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
SetAction(Button::X, Action{"Refresh"_i18n, [this](){
|
auto ApplicationEntry::GetSize() const -> s64 {
|
||||||
m_state = State::None;
|
s64 size{};
|
||||||
}});
|
size += GetSize(application);
|
||||||
|
size += GetSize(patch);
|
||||||
|
size += GetSize(add_on);
|
||||||
|
size += GetSize(data_patch);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu::Menu() : MenuBase{"GameCard"_i18n} {
|
||||||
|
this->SetActions(
|
||||||
|
std::make_pair(Button::B, Action{"Back"_i18n, [this](){
|
||||||
|
SetPop();
|
||||||
|
}}),
|
||||||
|
std::make_pair(Button::X, Action{"Options"_i18n, [this](){
|
||||||
|
App::DisplayInstallOptions(false);
|
||||||
|
}})
|
||||||
|
);
|
||||||
|
|
||||||
|
const Vec4 v{485, 275, 720, 70};
|
||||||
|
const Vec2 pad{0, 125 - v.h};
|
||||||
|
m_list = std::make_unique<List>(1, 3, m_pos, v, pad);
|
||||||
|
|
||||||
fsOpenDeviceOperator(std::addressof(m_dev_op));
|
fsOpenDeviceOperator(std::addressof(m_dev_op));
|
||||||
|
fsOpenGameCardDetectionEventNotifier(std::addressof(m_event_notifier));
|
||||||
|
fsEventNotifierGetEventHandle(std::addressof(m_event_notifier), std::addressof(m_event), true);
|
||||||
|
GcOnEvent();
|
||||||
|
UpdateStorageSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu::~Menu() {
|
Menu::~Menu() {
|
||||||
// manually close this as it needs(?) to be closed before dev_op.
|
GcUnmount();
|
||||||
m_fs.reset();
|
eventClose(std::addressof(m_event));
|
||||||
|
fsEventNotifierClose(std::addressof(m_event_notifier));
|
||||||
fsDeviceOperatorClose(std::addressof(m_dev_op));
|
fsDeviceOperatorClose(std::addressof(m_dev_op));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
||||||
MenuBase::Update(controller, touch);
|
// poll for the gamecard first before handling inputs as the gamecard
|
||||||
|
// may have been removed, thus pressing A would fail.
|
||||||
switch (m_state) {
|
if (R_SUCCEEDED(eventWait(std::addressof(m_event), 0))) {
|
||||||
case State::None: {
|
GcOnEvent();
|
||||||
bool gc_inserted;
|
|
||||||
if (R_FAILED(fsDeviceOperatorIsGameCardInserted(std::addressof(m_dev_op), std::addressof(gc_inserted)))) {
|
|
||||||
m_state = State::Failed;
|
|
||||||
} else {
|
|
||||||
if (!gc_inserted) {
|
|
||||||
m_state = State::NotFound;
|
|
||||||
} else {
|
|
||||||
if (R_FAILED(ScanGamecard())) {
|
|
||||||
m_state = State::Failed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case State::Progress:
|
|
||||||
case State::Done:
|
|
||||||
case State::NotFound:
|
|
||||||
case State::Failed:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MenuBase::Update(controller, touch);
|
||||||
|
m_list->OnUpdate(controller, touch, m_option_index, std::size(g_option_list), [this](bool touch, auto i) {
|
||||||
|
if (touch && m_option_index == i) {
|
||||||
|
FireAction(Button::A);
|
||||||
|
} else {
|
||||||
|
App::PlaySoundEffect(SoundEffect_Focus);
|
||||||
|
m_option_index = i;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
||||||
MenuBase::Draw(vg, theme);
|
MenuBase::Draw(vg, theme);
|
||||||
|
|
||||||
switch (m_state) {
|
#define STORAGE_BAR_W 325
|
||||||
case State::None:
|
#define STORAGE_BAR_H 14
|
||||||
gfx::drawTextArgs(vg, SCREEN_WIDTH / 2.f, SCREEN_HEIGHT / 2.f, 36.f, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT_INFO), "Waiting for connection..."_i18n.c_str());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::Progress:
|
const auto size_sd_gb = (double)m_size_free_sd / 0x40000000;
|
||||||
gfx::drawTextArgs(vg, SCREEN_WIDTH / 2.f, SCREEN_HEIGHT / 2.f, 36.f, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT_INFO), "Transferring data..."_i18n.c_str());
|
const auto size_nand_gb = (double)m_size_free_nand / 0x40000000;
|
||||||
break;
|
|
||||||
|
|
||||||
case State::NotFound:
|
gfx::drawTextArgs(vg, 490, 135, 23.f, NVG_ALIGN_LEFT | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "System memory %.1f GB", size_nand_gb);
|
||||||
gfx::drawTextArgs(vg, SCREEN_WIDTH / 2.f, SCREEN_HEIGHT / 2.f, 36.f, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT_INFO), "No GameCard inserted, press X to refresh"_i18n.c_str());
|
gfx::drawRect(vg, 480, 170, STORAGE_BAR_W, STORAGE_BAR_H, theme->GetColour(ThemeEntryID_TEXT));
|
||||||
break;
|
gfx::drawRect(vg, 480 + 1, 170 + 1, STORAGE_BAR_W - 2, STORAGE_BAR_H - 2, theme->GetColour(ThemeEntryID_BACKGROUND));
|
||||||
|
gfx::drawRect(vg, 480 + 2, 170 + 2, STORAGE_BAR_W - (((double)m_size_free_nand / (double)m_size_total_nand) * STORAGE_BAR_W) - 4, STORAGE_BAR_H - 4, theme->GetColour(ThemeEntryID_TEXT));
|
||||||
|
|
||||||
case State::Done:
|
gfx::drawTextArgs(vg, 870, 135, 23.f, NVG_ALIGN_LEFT | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "microSD card %.1f GB", size_sd_gb);
|
||||||
gfx::drawTextArgs(vg, SCREEN_WIDTH / 2.f, SCREEN_HEIGHT / 2.f, 36.f, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT_INFO), "Installed GameCard, press B to exit..."_i18n.c_str());
|
gfx::drawRect(vg, 860, 170, STORAGE_BAR_W, STORAGE_BAR_H, theme->GetColour(ThemeEntryID_TEXT));
|
||||||
break;
|
gfx::drawRect(vg, 860 + 1, 170 + 1, STORAGE_BAR_W - 2, STORAGE_BAR_H - 2, theme->GetColour(ThemeEntryID_BACKGROUND));
|
||||||
|
gfx::drawRect(vg, 860 + 2, 170 + 2, STORAGE_BAR_W - (((double)m_size_free_sd / (double)m_size_total_sd) * STORAGE_BAR_W) - 4, STORAGE_BAR_H - 4, theme->GetColour(ThemeEntryID_TEXT));
|
||||||
|
|
||||||
case State::Failed:
|
gfx::drawRect(vg, 30, 90, 375, 555, theme->GetColour(ThemeEntryID_GRID));
|
||||||
gfx::drawTextArgs(vg, SCREEN_WIDTH / 2.f, SCREEN_HEIGHT / 2.f, 36.f, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT_INFO), "Failed to scan GameCard..."_i18n.c_str());
|
|
||||||
break;
|
if (!m_entries.empty()) {
|
||||||
|
const auto& e = m_entries[m_entry_index];
|
||||||
|
const auto size = e.GetSize();
|
||||||
|
gfx::drawImage(vg, 90, 130, 256, 256, m_icon ? m_icon : App::GetDefaultImage());
|
||||||
|
|
||||||
|
nvgSave(vg);
|
||||||
|
nvgIntersectScissor(vg, 50, 90, 325, 555);
|
||||||
|
gfx::drawTextArgs(vg, 50, 415, 18.f, NVG_ALIGN_LEFT | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "%s", m_lang_entry.name);
|
||||||
|
gfx::drawTextArgs(vg, 50, 455, 18.f, NVG_ALIGN_LEFT | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "%s", m_lang_entry.author);
|
||||||
|
gfx::drawTextArgs(vg, 50, 495, 18.f, NVG_ALIGN_LEFT | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "App-ID: 0%lX", e.app_id);
|
||||||
|
gfx::drawTextArgs(vg, 50, 535, 18.f, NVG_ALIGN_LEFT | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "Key-Gen: %u (%s)", e.key_gen, nca::GetKeyGenStr(e.key_gen));
|
||||||
|
gfx::drawTextArgs(vg, 50, 575, 18.f, NVG_ALIGN_LEFT | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "Size: %.2f GB", (double)size / 0x40000000);
|
||||||
|
gfx::drawTextArgs(vg, 50, 615, 18.f, NVG_ALIGN_LEFT | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "Base: %zu Patch: %zu Addon: %zu Data: %zu", e.application.size(), e.patch.size(), e.add_on.size(), e.data_patch.size());
|
||||||
|
nvgRestore(vg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_list->Draw(vg, theme, std::size(g_option_list), [this](auto* vg, auto* theme, auto v, auto i) {
|
||||||
|
const auto& [x, y, w, h] = v;
|
||||||
|
const auto text_y = y + (h / 2.f);
|
||||||
|
auto colour = ThemeEntryID_TEXT;
|
||||||
|
if (i == m_option_index) {
|
||||||
|
gfx::drawRectOutline(vg, theme, 4.f, v);
|
||||||
|
// g_background.selected_bar = create_shape(Colour_Nintendo_Cyan, 90, 230, 4, 45, true);
|
||||||
|
// draw_shape_position(&g_background.selected_bar, 485, g_options[i].text->rect.y - 10);
|
||||||
|
gfx::drawRect(vg, 490, text_y - 45.f / 2.f, 2, 45, theme->GetColour(ThemeEntryID_TEXT_SELECTED));
|
||||||
|
colour = ThemeEntryID_TEXT_SELECTED;
|
||||||
|
}
|
||||||
|
if (i != 2 && !m_mounted) {
|
||||||
|
colour = ThemeEntryID_TEXT_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::drawTextArgs(vg, x + 15, y + (h / 2.f), 23.f, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE, theme->GetColour(colour), "%s", g_option_list[i]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Menu::ScanGamecard() {
|
Result Menu::GcMount() {
|
||||||
m_state = State::None;
|
GcUnmount();
|
||||||
m_fs.reset();
|
|
||||||
m_collections.clear();
|
|
||||||
|
|
||||||
FsGameCardHandle gc_handle;
|
R_TRY(fsDeviceOperatorGetGameCardHandle(std::addressof(m_dev_op), std::addressof(m_handle)));
|
||||||
R_TRY(fsDeviceOperatorGetGameCardHandle(std::addressof(m_dev_op), std::addressof(gc_handle)));
|
|
||||||
|
|
||||||
m_fs = std::make_unique<fs::FsNativeGameCard>(std::addressof(gc_handle), FsGameCardPartition_Secure, false);
|
m_fs = std::make_unique<fs::FsNativeGameCard>(std::addressof(m_handle), FsGameCardPartition_Secure, false);
|
||||||
R_TRY(m_fs->GetFsOpenResult());
|
R_TRY(m_fs->GetFsOpenResult());
|
||||||
|
|
||||||
FsDir dir;
|
FsDir dir;
|
||||||
@@ -155,33 +287,245 @@ Result Menu::ScanGamecard() {
|
|||||||
std::vector<FsDirectoryEntry> buf(count);
|
std::vector<FsDirectoryEntry> buf(count);
|
||||||
s64 total_entries;
|
s64 total_entries;
|
||||||
R_TRY(m_fs->DirRead(std::addressof(dir), std::addressof(total_entries), buf.size(), buf.data()));
|
R_TRY(m_fs->DirRead(std::addressof(dir), std::addressof(total_entries), buf.size(), buf.data()));
|
||||||
m_collections.reserve(total_entries);
|
R_UNLESS(buf.size() == total_entries, 0x1);
|
||||||
|
|
||||||
s64 offset{};
|
yati::container::Collections ticket_collections;
|
||||||
for (s64 i = 0; i < total_entries; i++) {
|
for (const auto& e : buf) {
|
||||||
yati::container::CollectionEntry entry{};
|
if (!std::string_view(e.name).ends_with(".tik") && !std::string_view(e.name).ends_with(".cert")) {
|
||||||
entry.name = buf[i].name;
|
continue;
|
||||||
entry.offset = offset;
|
}
|
||||||
entry.size = buf[i].file_size;
|
|
||||||
m_collections.emplace_back(entry);
|
ticket_collections.emplace_back(e.name, 0, e.file_size);
|
||||||
offset += buf[i].file_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_state = State::Progress;
|
for (const auto& e : buf) {
|
||||||
App::Push(std::make_shared<ui::ProgressBox>("Installing App"_i18n, [this](auto pbox) mutable -> bool {
|
// we could use ncm to handle finding all the ncas for us
|
||||||
auto source = std::make_shared<GcSource>(m_collections, m_fs.get());
|
// however, we can parse faster than ncm.
|
||||||
return R_SUCCEEDED(yati::InstallFromCollections(pbox, source, m_collections));
|
// not only that, the first few calls trying to mount ncm db for
|
||||||
}, [this](bool result){
|
// the gamecard will fail as it has not yet been parsed (or it's locked?).
|
||||||
if (result) {
|
// we could, of course, just wait until ncm is ready, which is about
|
||||||
App::Notify("Gc install success!"_i18n);
|
// 32ms, but i already have code for manually parsing cnmt so lets re-use it.
|
||||||
m_state = State::Done;
|
if (!std::string_view(e.name).ends_with(".cnmt.nca")) {
|
||||||
} else {
|
continue;
|
||||||
App::Notify("Gc install failed!"_i18n);
|
|
||||||
m_state = State::Failed;
|
|
||||||
}
|
}
|
||||||
}));
|
|
||||||
|
// we don't yet use the header or extended header.
|
||||||
|
ncm::PackagedContentMeta header;
|
||||||
|
std::vector<u8> extended_header;
|
||||||
|
std::vector<NcmPackagedContentInfo> infos;
|
||||||
|
const auto path = BuildGcPath(e.name, &m_handle);
|
||||||
|
R_TRY(yati::ParseCnmtNca(path, 0, header, extended_header, infos));
|
||||||
|
|
||||||
|
u8 key_gen;
|
||||||
|
FsRightsId rights_id;
|
||||||
|
R_TRY(fsGetRightsIdAndKeyGenerationByPath(path, FsContentAttributes_All, &key_gen, &rights_id));
|
||||||
|
|
||||||
|
// always add tickets, yati will ignore them if not needed.
|
||||||
|
GcCollections collections;
|
||||||
|
// add cnmt file.
|
||||||
|
collections.emplace_back(e.name, e.file_size, NcmContentType_Meta, 0);
|
||||||
|
|
||||||
|
for (const auto& packed_info : infos) {
|
||||||
|
const auto& info = packed_info.info;
|
||||||
|
// these don't exist for gamecards, however i may copy/paste this code
|
||||||
|
// somewhere so i'm future proofing against myself.
|
||||||
|
if (info.content_type == NcmContentType_DeltaFragment) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find the nca file, this will never fail for gamecards, see above comment.
|
||||||
|
const auto str = hexIdToStr(info.content_id);
|
||||||
|
const auto it = std::find_if(buf.cbegin(), buf.cend(), [str](auto& e){
|
||||||
|
return !std::strncmp(str.str, e.name, std::strlen(str.str));
|
||||||
|
});
|
||||||
|
|
||||||
|
R_UNLESS(it != buf.cend(), yati::Result_NcaNotFound);
|
||||||
|
collections.emplace_back(it->name, it->file_size, info.content_type, info.id_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto app_id = ncm::GetAppId(header);
|
||||||
|
ApplicationEntry* app_entry{};
|
||||||
|
for (auto& app : m_entries) {
|
||||||
|
if (app.app_id == app_id) {
|
||||||
|
app_entry = &app;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!app_entry) {
|
||||||
|
app_entry = &m_entries.emplace_back(app_id, header.title_version);
|
||||||
|
}
|
||||||
|
|
||||||
|
app_entry->version = std::max(app_entry->version, header.title_version);
|
||||||
|
app_entry->key_gen = std::max(app_entry->key_gen, key_gen);
|
||||||
|
|
||||||
|
if (header.meta_type == NcmContentMetaType_Application) {
|
||||||
|
app_entry->application.emplace_back(collections);
|
||||||
|
} else if (header.meta_type == NcmContentMetaType_Patch) {
|
||||||
|
app_entry->patch.emplace_back(collections);
|
||||||
|
} else if (header.meta_type == NcmContentMetaType_AddOnContent) {
|
||||||
|
app_entry->add_on.emplace_back(collections);
|
||||||
|
} else if (header.meta_type == NcmContentMetaType_DataPatch) {
|
||||||
|
app_entry->data_patch.emplace_back(collections);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
R_UNLESS(m_entries.size(), 0x1);
|
||||||
|
|
||||||
|
// append tickets to every application, yati will ignore if undeeded.
|
||||||
|
for (auto& e : m_entries) {
|
||||||
|
e.tickets = ticket_collections;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAction(Button::A, Action{"OK"_i18n, [this](){
|
||||||
|
if (m_option_index == 2) {
|
||||||
|
SetPop();
|
||||||
|
} else {
|
||||||
|
if (m_mounted) {
|
||||||
|
App::Push(std::make_shared<ui::ProgressBox>(m_icon, "Installing "_i18n, m_lang_entry.name, [this](auto pbox) mutable -> bool {
|
||||||
|
auto source = std::make_shared<GcSource>(m_entries[m_entry_index], m_fs.get(), m_option_index == 1);
|
||||||
|
return R_SUCCEEDED(yati::InstallFromCollections(pbox, source, source->m_collections, source->m_config));
|
||||||
|
}, [this](bool result){
|
||||||
|
if (result) {
|
||||||
|
App::Notify("Gc install success!"_i18n);
|
||||||
|
} else {
|
||||||
|
App::Notify("Gc install failed!"_i18n);
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateStorageSize();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
|
||||||
|
if (m_entries.size() > 1) {
|
||||||
|
SetAction(Button::L, Action{"Prev"_i18n, [this](){
|
||||||
|
if (m_entry_index != 0) {
|
||||||
|
OnChangeIndex(m_entry_index - 1);
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
SetAction(Button::R, Action{"Next"_i18n, [this](){
|
||||||
|
if (m_entry_index < m_entries.size()) {
|
||||||
|
OnChangeIndex(m_entry_index + 1);
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
OnChangeIndex(0);
|
||||||
|
m_mounted = true;
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::GcUnmount() {
|
||||||
|
m_fs.reset();
|
||||||
|
m_entries.clear();
|
||||||
|
m_entry_index = 0;
|
||||||
|
m_mounted = false;
|
||||||
|
m_lang_entry = {};
|
||||||
|
FreeImage();
|
||||||
|
|
||||||
|
RemoveAction(Button::L);
|
||||||
|
RemoveAction(Button::R);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result Menu::GcPoll(bool* inserted) {
|
||||||
|
R_TRY(fsDeviceOperatorIsGameCardInserted(&m_dev_op, inserted));
|
||||||
|
|
||||||
|
// if the handle changed, re-mount the game card.
|
||||||
|
if (*inserted && m_mounted) {
|
||||||
|
FsGameCardHandle handle;
|
||||||
|
R_TRY(fsDeviceOperatorGetGameCardHandle(std::addressof(m_dev_op), std::addressof(handle)));
|
||||||
|
if (handle.value != m_handle.value) {
|
||||||
|
R_TRY(GcMount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result Menu::GcOnEvent() {
|
||||||
|
bool inserted{};
|
||||||
|
R_TRY(GcPoll(&inserted));
|
||||||
|
|
||||||
|
if (m_mounted != inserted) {
|
||||||
|
log_write("gc state changed\n");
|
||||||
|
m_mounted = inserted;
|
||||||
|
if (m_mounted) {
|
||||||
|
log_write("trying to mount\n");
|
||||||
|
m_mounted = R_SUCCEEDED(GcMount());
|
||||||
|
if (m_mounted) {
|
||||||
|
App::PlaySoundEffect(SoundEffect::SoundEffect_Startup);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log_write("trying to unmount\n");
|
||||||
|
GcUnmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result Menu::UpdateStorageSize() {
|
||||||
|
fs::FsNativeContentStorage fs_nand{FsContentStorageId_User};
|
||||||
|
fs::FsNativeContentStorage fs_sd{FsContentStorageId_SdCard};
|
||||||
|
|
||||||
|
R_TRY(fs_sd.GetFreeSpace("/", &m_size_free_sd));
|
||||||
|
R_TRY(fs_sd.GetTotalSpace("/", &m_size_total_sd));
|
||||||
|
R_TRY(fs_nand.GetFreeSpace("/", &m_size_free_nand));
|
||||||
|
R_TRY(fs_nand.GetTotalSpace("/", &m_size_total_nand));
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::FreeImage() {
|
||||||
|
if (m_icon) {
|
||||||
|
nvgDeleteImage(App::GetVg(), m_icon);
|
||||||
|
m_icon = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::OnChangeIndex(s64 new_index) {
|
||||||
|
FreeImage();
|
||||||
|
m_entry_index = new_index;
|
||||||
|
|
||||||
|
const auto index = m_entries.empty() ? 0 : m_entry_index + 1;
|
||||||
|
this->SetSubHeading(std::to_string(index) + " / " + std::to_string(m_entries.size()));
|
||||||
|
|
||||||
|
// nsGetApplicationControlData() will fail if it's the first time
|
||||||
|
// mounting a gamecard if the image is not already cached.
|
||||||
|
// waiting 1-2s after mount, then calling seems to work.
|
||||||
|
// however, we can just manually parse the nca to get the data we need,
|
||||||
|
// which always works and *is* faster too ;)
|
||||||
|
for (auto& e : m_entries[m_entry_index].application) {
|
||||||
|
for (auto& collection : e) {
|
||||||
|
if (collection.type == NcmContentType_Control) {
|
||||||
|
NacpStruct nacp;
|
||||||
|
std::vector<u8> icon;
|
||||||
|
const auto path = BuildGcPath(collection.name.c_str(), &m_handle);
|
||||||
|
|
||||||
|
u64 program_id = m_entries[m_entry_index].app_id | collection.id_offset;
|
||||||
|
if (hosversionAtLeast(17, 0, 0)) {
|
||||||
|
fsGetProgramId(&program_id, path, FsContentAttributes_All);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(yati::ParseControlNca(path, program_id, &nacp, sizeof(nacp), &icon))) {
|
||||||
|
log_write("managed to parse control nca %s\n", path.s);
|
||||||
|
NacpLanguageEntry* lang_entry{};
|
||||||
|
nacpGetLanguageEntry(&nacp, &lang_entry);
|
||||||
|
|
||||||
|
if (lang_entry) {
|
||||||
|
m_lang_entry = *lang_entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_icon = nvgCreateImageMem(App::GetVg(), 0, icon.data(), icon.size());
|
||||||
|
if (m_icon > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log_write("\tFAILED to parse control nca %s\n", path.s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sphaira::ui::menu::gc
|
} // namespace sphaira::ui::menu::gc
|
||||||
|
|||||||
@@ -247,27 +247,6 @@ Menu::Menu() : MenuBase{"GitHub"_i18n} {
|
|||||||
fs::FsNativeSd().CreateDirectoryRecursively(CACHE_PATH);
|
fs::FsNativeSd().CreateDirectoryRecursively(CACHE_PATH);
|
||||||
|
|
||||||
this->SetActions(
|
this->SetActions(
|
||||||
std::make_pair(Button::DOWN, Action{[this](){
|
|
||||||
if (m_list->ScrollDown(m_index, 1, m_entries.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::UP, Action{[this](){
|
|
||||||
if (m_list->ScrollUp(m_index, 1, m_entries.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::DPAD_RIGHT, Action{[this](){
|
|
||||||
if (m_list->ScrollDown(m_index, 8, m_entries.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::DPAD_LEFT, Action{[this](){
|
|
||||||
if (m_list->ScrollUp(m_index, 8, m_entries.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
|
|
||||||
std::make_pair(Button::A, Action{"Download"_i18n, [this](){
|
std::make_pair(Button::A, Action{"Download"_i18n, [this](){
|
||||||
if (m_entries.empty()) {
|
if (m_entries.empty()) {
|
||||||
return;
|
return;
|
||||||
@@ -277,7 +256,7 @@ Menu::Menu() : MenuBase{"GitHub"_i18n} {
|
|||||||
static GhApiEntry gh_entry;
|
static GhApiEntry gh_entry;
|
||||||
gh_entry = {};
|
gh_entry = {};
|
||||||
|
|
||||||
App::Push(std::make_shared<ProgressBox>("Downloading "_i18n + GetEntry().repo, [this](auto pbox){
|
App::Push(std::make_shared<ProgressBox>(0, "Downloading "_i18n, GetEntry().repo, [this](auto pbox){
|
||||||
return DownloadAssetJson(pbox, GenerateApiUrl(GetEntry()), gh_entry);
|
return DownloadAssetJson(pbox, GenerateApiUrl(GetEntry()), gh_entry);
|
||||||
}, [this](bool success){
|
}, [this](bool success){
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -325,7 +304,7 @@ Menu::Menu() : MenuBase{"GitHub"_i18n} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto func = [this, &asset_entry, ptr](){
|
const auto func = [this, &asset_entry, ptr](){
|
||||||
App::Push(std::make_shared<ProgressBox>("Downloading "_i18n + GetEntry().repo, [this, &asset_entry, ptr](auto pbox){
|
App::Push(std::make_shared<ProgressBox>(0, "Downloading "_i18n, GetEntry().repo, [this, &asset_entry, ptr](auto pbox){
|
||||||
return DownloadApp(pbox, asset_entry, ptr);
|
return DownloadApp(pbox, asset_entry, ptr);
|
||||||
}, [this, ptr](bool success){
|
}, [this, ptr](bool success){
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -373,8 +352,8 @@ Menu::~Menu() {
|
|||||||
|
|
||||||
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
||||||
MenuBase::Update(controller, touch);
|
MenuBase::Update(controller, touch);
|
||||||
m_list->OnUpdate(controller, touch, m_entries.size(), [this](auto i) {
|
m_list->OnUpdate(controller, touch, m_index, m_entries.size(), [this](bool touch, auto i) {
|
||||||
if (m_index == i) {
|
if (touch && m_index == i) {
|
||||||
FireAction(Button::A);
|
FireAction(Button::A);
|
||||||
} else {
|
} else {
|
||||||
App::PlaySoundEffect(SoundEffect_Focus);
|
App::PlaySoundEffect(SoundEffect_Focus);
|
||||||
|
|||||||
@@ -28,40 +28,6 @@ auto GenerateStarPath(const fs::FsPath& nro_path) -> fs::FsPath {
|
|||||||
|
|
||||||
Menu::Menu() : MenuBase{"Homebrew"_i18n} {
|
Menu::Menu() : MenuBase{"Homebrew"_i18n} {
|
||||||
this->SetActions(
|
this->SetActions(
|
||||||
std::make_pair(Button::RIGHT, Action{[this](){
|
|
||||||
if (m_index < (m_entries.size() - 1) && (m_index + 1) % 3 != 0) {
|
|
||||||
SetIndex(m_index + 1);
|
|
||||||
App::PlaySoundEffect(SoundEffect_Scroll);
|
|
||||||
log_write("moved right\n");
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::LEFT, Action{[this](){
|
|
||||||
if (m_index != 0 && (m_index % 3) != 0) {
|
|
||||||
SetIndex(m_index - 1);
|
|
||||||
App::PlaySoundEffect(SoundEffect_Scroll);
|
|
||||||
log_write("moved left\n");
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::DOWN, Action{[this](){
|
|
||||||
if (m_list->ScrollDown(m_index, 3, m_entries.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::UP, Action{[this](){
|
|
||||||
if (m_list->ScrollUp(m_index, 3, m_entries.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::R2, Action{[this](){
|
|
||||||
if (m_list->ScrollDown(m_index, 9, m_entries.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::L2, Action{[this](){
|
|
||||||
if (m_list->ScrollUp(m_index, 9, m_entries.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::A, Action{"Launch"_i18n, [this](){
|
std::make_pair(Button::A, Action{"Launch"_i18n, [this](){
|
||||||
nro_launch(m_entries[m_index].path);
|
nro_launch(m_entries[m_index].path);
|
||||||
}}),
|
}}),
|
||||||
@@ -157,8 +123,8 @@ Menu::~Menu() {
|
|||||||
|
|
||||||
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
||||||
MenuBase::Update(controller, touch);
|
MenuBase::Update(controller, touch);
|
||||||
m_list->OnUpdate(controller, touch, m_entries.size(), [this](auto i) {
|
m_list->OnUpdate(controller, touch, m_index, m_entries.size(), [this](bool touch, auto i) {
|
||||||
if (m_index == i) {
|
if (touch && m_index == i) {
|
||||||
FireAction(Button::A);
|
FireAction(Button::A);
|
||||||
} else {
|
} else {
|
||||||
App::PlaySoundEffect(SoundEffect_Focus);
|
App::PlaySoundEffect(SoundEffect_Focus);
|
||||||
@@ -202,7 +168,7 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const float image_size = 115;
|
const float image_size = 115;
|
||||||
gfx::drawImageRounded(vg, x + 20, y + 20, image_size, image_size, e.image ? e.image : App::GetDefaultImage());
|
gfx::drawImage(vg, x + 20, y + 20, image_size, image_size, e.image ? e.image : App::GetDefaultImage(), 15);
|
||||||
|
|
||||||
nvgSave(vg);
|
nvgSave(vg);
|
||||||
nvgIntersectScissor(vg, x, y, w - 30.f, h); // clip
|
nvgIntersectScissor(vg, x, y, w - 30.f, h); // clip
|
||||||
|
|||||||
@@ -86,20 +86,7 @@ Menu::Menu() : MenuBase{"Irs"_i18n} {
|
|||||||
|
|
||||||
SidebarEntryArray::Items controller_str;
|
SidebarEntryArray::Items controller_str;
|
||||||
for (u32 i = 0; i < IRS_MAX_CAMERAS; i++) {
|
for (u32 i = 0; i < IRS_MAX_CAMERAS; i++) {
|
||||||
const auto& e = m_entries[i];
|
controller_str.emplace_back(GetEntryName(i));
|
||||||
std::string text = "Pad "_i18n + (i == 8 ? "HandHeld"_i18n : std::to_string(i));
|
|
||||||
switch (e.status) {
|
|
||||||
case IrsIrCameraStatus_Available:
|
|
||||||
text += " (Available)"_i18n;
|
|
||||||
break;
|
|
||||||
case IrsIrCameraStatus_Unsupported:
|
|
||||||
text += " (Unsupported)"_i18n;
|
|
||||||
break;
|
|
||||||
case IrsIrCameraStatus_Unconnected:
|
|
||||||
text += " (Unconnected)"_i18n;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
controller_str.emplace_back(text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SidebarEntryArray::Items rotation_str;
|
SidebarEntryArray::Items rotation_str;
|
||||||
@@ -217,6 +204,17 @@ Menu::Menu() : MenuBase{"Irs"_i18n} {
|
|||||||
PollCameraStatus(true);
|
PollCameraStatus(true);
|
||||||
// load default config
|
// load default config
|
||||||
LoadDefaultConfig();
|
LoadDefaultConfig();
|
||||||
|
// poll to get first available handle.
|
||||||
|
PollCameraStatus(false);
|
||||||
|
|
||||||
|
// find the first available entry and connect to that.
|
||||||
|
for (s64 i = 0; i < std::size(m_entries); i++) {
|
||||||
|
if (m_entries[i].status == IrsIrCameraStatus_Available) {
|
||||||
|
m_index = i;
|
||||||
|
UpdateConfig(&m_config);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu::~Menu() {
|
Menu::~Menu() {
|
||||||
@@ -233,6 +231,7 @@ Menu::~Menu() {
|
|||||||
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
void Menu::Update(Controller* controller, TouchInfo* touch) {
|
||||||
MenuBase::Update(controller, touch);
|
MenuBase::Update(controller, touch);
|
||||||
PollCameraStatus();
|
PollCameraStatus();
|
||||||
|
SetTitleSubHeading(GetEntryName(m_index));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
||||||
@@ -530,4 +529,21 @@ void Menu::updateColourArray() {
|
|||||||
UpdateImage();
|
UpdateImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Menu::GetEntryName(s64 i) -> std::string {
|
||||||
|
const auto& e = m_entries[i];
|
||||||
|
std::string text = "Pad "_i18n + (i == 8 ? "HandHeld"_i18n : std::to_string(i));
|
||||||
|
switch (e.status) {
|
||||||
|
case IrsIrCameraStatus_Available:
|
||||||
|
text += " (Available)"_i18n;
|
||||||
|
break;
|
||||||
|
case IrsIrCameraStatus_Unsupported:
|
||||||
|
text += " (Unsupported)"_i18n;
|
||||||
|
break;
|
||||||
|
case IrsIrCameraStatus_Unconnected:
|
||||||
|
text += " (Unconnected)"_i18n;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sphaira::ui::menu::irs
|
} // namespace sphaira::ui::menu::irs
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
#include "ui/menus/main_menu.hpp"
|
#include "ui/menus/main_menu.hpp"
|
||||||
#include "ui/menus/irs_menu.hpp"
|
|
||||||
#include "ui/menus/themezer.hpp"
|
|
||||||
#include "ui/menus/ghdl.hpp"
|
|
||||||
#include "ui/menus/usb_menu.hpp"
|
|
||||||
#include "ui/menus/ftp_menu.hpp"
|
|
||||||
#include "ui/menus/gc_menu.hpp"
|
|
||||||
|
|
||||||
#include "ui/sidebar.hpp"
|
#include "ui/sidebar.hpp"
|
||||||
#include "ui/popup_list.hpp"
|
#include "ui/popup_list.hpp"
|
||||||
@@ -16,8 +10,8 @@
|
|||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
#include "download.hpp"
|
#include "download.hpp"
|
||||||
#include "defines.hpp"
|
#include "defines.hpp"
|
||||||
#include "web.hpp"
|
|
||||||
#include "i18n.hpp"
|
#include "i18n.hpp"
|
||||||
|
#include "ui/menus/usb_menu.hpp"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <minizip/unzip.h>
|
#include <minizip/unzip.h>
|
||||||
@@ -215,6 +209,9 @@ MainMenu::MainMenu() {
|
|||||||
|
|
||||||
this->SetActions(
|
this->SetActions(
|
||||||
std::make_pair(Button::START, Action{App::Exit}),
|
std::make_pair(Button::START, Action{App::Exit}),
|
||||||
|
std::make_pair(Button::SELECT, Action{"Misc"_i18n, [this](){
|
||||||
|
App::DisplayMiscOptions();
|
||||||
|
}}),
|
||||||
std::make_pair(Button::Y, Action{"Menu"_i18n, [this](){
|
std::make_pair(Button::Y, Action{"Menu"_i18n, [this](){
|
||||||
auto options = std::make_shared<Sidebar>("Menu Options"_i18n, "v" APP_VERSION_HASH, Sidebar::Side::LEFT);
|
auto options = std::make_shared<Sidebar>("Menu Options"_i18n, "v" APP_VERSION_HASH, Sidebar::Side::LEFT);
|
||||||
ON_SCOPE_EXIT(App::Push(options));
|
ON_SCOPE_EXIT(App::Push(options));
|
||||||
@@ -235,48 +232,29 @@ MainMenu::MainMenu() {
|
|||||||
language_items.push_back("Swedish"_i18n);
|
language_items.push_back("Swedish"_i18n);
|
||||||
language_items.push_back("Vietnamese"_i18n);
|
language_items.push_back("Vietnamese"_i18n);
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Theme"_i18n, [this](){
|
options->Add(std::make_shared<SidebarEntryCallback>("Theme"_i18n, [](){
|
||||||
SidebarEntryArray::Items theme_items{};
|
App::DisplayThemeOptions();
|
||||||
const auto theme_meta = App::GetThemeMetaList();
|
|
||||||
for (auto& p : theme_meta) {
|
|
||||||
theme_items.emplace_back(p.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto options = std::make_shared<Sidebar>("Theme Options"_i18n, Sidebar::Side::LEFT);
|
|
||||||
ON_SCOPE_EXIT(App::Push(options));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryArray>("Select Theme"_i18n, theme_items, [this, theme_items](s64& index_out){
|
|
||||||
App::SetTheme(index_out);
|
|
||||||
}, App::GetThemeIndex()));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Music"_i18n, App::GetThemeMusicEnable(), [this](bool& enable){
|
|
||||||
App::SetThemeMusicEnable(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("12 Hour Time"_i18n, App::Get12HourTimeEnable(), [this](bool& enable){
|
|
||||||
App::Set12HourTimeEnable(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Network"_i18n, [this](){
|
options->Add(std::make_shared<SidebarEntryCallback>("Network"_i18n, [this](){
|
||||||
auto options = std::make_shared<Sidebar>("Network Options"_i18n, Sidebar::Side::LEFT);
|
auto options = std::make_shared<Sidebar>("Network Options"_i18n, Sidebar::Side::LEFT);
|
||||||
ON_SCOPE_EXIT(App::Push(options));
|
ON_SCOPE_EXIT(App::Push(options));
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Ftp"_i18n, App::GetFtpEnable(), [this](bool& enable){
|
options->Add(std::make_shared<SidebarEntryBool>("Ftp"_i18n, App::GetFtpEnable(), [](bool& enable){
|
||||||
App::SetFtpEnable(enable);
|
App::SetFtpEnable(enable);
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Mtp"_i18n, App::GetMtpEnable(), [this](bool& enable){
|
options->Add(std::make_shared<SidebarEntryBool>("Mtp"_i18n, App::GetMtpEnable(), [](bool& enable){
|
||||||
App::SetMtpEnable(enable);
|
App::SetMtpEnable(enable);
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Nxlink"_i18n, App::GetNxlinkEnable(), [this](bool& enable){
|
options->Add(std::make_shared<SidebarEntryBool>("Nxlink"_i18n, App::GetNxlinkEnable(), [](bool& enable){
|
||||||
App::SetNxlinkEnable(enable);
|
App::SetNxlinkEnable(enable);
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
}, "Enabled"_i18n, "Disabled"_i18n));
|
||||||
|
|
||||||
if (m_update_state == UpdateState::Update) {
|
if (m_update_state == UpdateState::Update) {
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Download update: "_i18n + m_update_version, [this](){
|
options->Add(std::make_shared<SidebarEntryCallback>("Download update: "_i18n + m_update_version, [this](){
|
||||||
App::Push(std::make_shared<ProgressBox>("Downloading "_i18n + m_update_version, [this](auto pbox){
|
App::Push(std::make_shared<ProgressBox>(0, "Downloading "_i18n, "Sphaira v" + m_update_version, [this](auto pbox){
|
||||||
return InstallUpdate(pbox, m_update_url, m_update_version);
|
return InstallUpdate(pbox, m_update_url, m_update_version);
|
||||||
}, [this](bool success){
|
}, [this](bool success){
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -295,150 +273,16 @@ MainMenu::MainMenu() {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryArray>("Language"_i18n, language_items, [this](s64& index_out){
|
options->Add(std::make_shared<SidebarEntryArray>("Language"_i18n, language_items, [](s64& index_out){
|
||||||
App::SetLanguage(index_out);
|
App::SetLanguage(index_out);
|
||||||
}, (s64)App::GetLanguage()));
|
}, (s64)App::GetLanguage()));
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Misc"_i18n, [this](){
|
options->Add(std::make_shared<SidebarEntryCallback>("Misc"_i18n, [](){
|
||||||
auto options = std::make_shared<Sidebar>("Misc Options"_i18n, Sidebar::Side::LEFT);
|
App::DisplayMiscOptions();
|
||||||
ON_SCOPE_EXIT(App::Push(options));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Themezer"_i18n, [](){
|
|
||||||
App::Push(std::make_shared<menu::themezer::Menu>());
|
|
||||||
}));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("GitHub"_i18n, [](){
|
|
||||||
App::Push(std::make_shared<menu::gh::Menu>());
|
|
||||||
}));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Irs"_i18n, [](){
|
|
||||||
App::Push(std::make_shared<menu::irs::Menu>());
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (App::IsApplication()) {
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Web"_i18n, [](){
|
|
||||||
WebShow("https://lite.duckduckgo.com/lite");
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (App::GetApp()->m_install.Get()) {
|
|
||||||
if (App::GetFtpEnable()) {
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Ftp Install"_i18n, [](){
|
|
||||||
App::Push(std::make_shared<menu::ftp::Menu>());
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Usb Install"_i18n, [](){
|
|
||||||
App::Push(std::make_shared<menu::usb::Menu>());
|
|
||||||
}));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("GameCard Install"_i18n, [](){
|
|
||||||
App::Push(std::make_shared<menu::gc::Menu>());
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Advanced"_i18n, [this](){
|
options->Add(std::make_shared<SidebarEntryCallback>("Advanced"_i18n, [](){
|
||||||
auto options = std::make_shared<Sidebar>("Advanced Options"_i18n, Sidebar::Side::LEFT);
|
App::DisplayAdvancedOptions();
|
||||||
ON_SCOPE_EXIT(App::Push(options));
|
|
||||||
|
|
||||||
SidebarEntryArray::Items text_scroll_speed_items;
|
|
||||||
text_scroll_speed_items.push_back("Slow"_i18n);
|
|
||||||
text_scroll_speed_items.push_back("Normal"_i18n);
|
|
||||||
text_scroll_speed_items.push_back("Fast"_i18n);
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Logging"_i18n, App::GetLogEnable(), [this](bool& enable){
|
|
||||||
App::SetLogEnable(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Replace hbmenu on exit"_i18n, App::GetReplaceHbmenuEnable(), [this](bool& enable){
|
|
||||||
App::SetReplaceHbmenuEnable(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryArray>("Text scroll speed"_i18n, text_scroll_speed_items, [this](s64& index_out){
|
|
||||||
App::SetTextScrollSpeed(index_out);
|
|
||||||
}, (s64)App::GetTextScrollSpeed()));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryCallback>("Install options"_i18n, [this](){
|
|
||||||
auto options = std::make_shared<Sidebar>("Install Options"_i18n, Sidebar::Side::LEFT);
|
|
||||||
ON_SCOPE_EXIT(App::Push(options));
|
|
||||||
|
|
||||||
SidebarEntryArray::Items install_items;
|
|
||||||
install_items.push_back("System memory"_i18n);
|
|
||||||
install_items.push_back("microSD card"_i18n);
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Enable"_i18n, App::GetInstallEnable(), [this](bool& enable){
|
|
||||||
App::SetInstallEnable(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Show install warning"_i18n, App::GetInstallPrompt(), [this](bool& enable){
|
|
||||||
App::SetInstallPrompt(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryArray>("Install location"_i18n, install_items, [this](s64& index_out){
|
|
||||||
App::SetInstallSdEnable(index_out);
|
|
||||||
}, (s64)App::GetInstallSdEnable()));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Allow downgrade"_i18n, App::GetApp()->m_allow_downgrade.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_allow_downgrade.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Skip if already installed"_i18n, App::GetApp()->m_skip_if_already_installed.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_skip_if_already_installed.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Ticket only"_i18n, App::GetApp()->m_ticket_only.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_ticket_only.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Skip base"_i18n, App::GetApp()->m_skip_base.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_skip_base.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Skip Patch"_i18n, App::GetApp()->m_skip_patch.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_skip_patch.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Skip addon"_i18n, App::GetApp()->m_skip_addon.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_skip_addon.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Skip data patch"_i18n, App::GetApp()->m_skip_data_patch.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_skip_data_patch.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Skip ticket"_i18n, App::GetApp()->m_skip_ticket.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_skip_ticket.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("skip NCA hash verify"_i18n, App::GetApp()->m_skip_nca_hash_verify.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_skip_nca_hash_verify.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Skip RSA header verify"_i18n, App::GetApp()->m_skip_rsa_header_fixed_key_verify.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_skip_rsa_header_fixed_key_verify.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Skip RSA NPDM verify"_i18n, App::GetApp()->m_skip_rsa_npdm_fixed_key_verify.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_skip_rsa_npdm_fixed_key_verify.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Ignore distribution bit"_i18n, App::GetApp()->m_ignore_distribution_bit.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_ignore_distribution_bit.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Convert to standard crypto"_i18n, App::GetApp()->m_convert_to_standard_crypto.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_convert_to_standard_crypto.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Lower master key"_i18n, App::GetApp()->m_lower_master_key.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_lower_master_key.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
|
|
||||||
options->Add(std::make_shared<SidebarEntryBool>("Lower system version"_i18n, App::GetApp()->m_lower_system_version.Get(), [this](bool& enable){
|
|
||||||
App::GetApp()->m_lower_system_version.Set(enable);
|
|
||||||
}, "Enabled"_i18n, "Disabled"_i18n));
|
|
||||||
}));
|
|
||||||
}));
|
}));
|
||||||
}})
|
}})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -306,6 +306,7 @@ auto InstallTheme(ProgressBox* pbox, const PackListEntry& entry) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto file_path = fs::AppendPath(dir_path, name);
|
const auto file_path = fs::AppendPath(dir_path, name);
|
||||||
|
pbox->NewTransfer(name);
|
||||||
|
|
||||||
Result rc;
|
Result rc;
|
||||||
if (R_FAILED(rc = fs.CreateFile(file_path, info.uncompressed_size, 0)) && rc != FsError_PathAlreadyExists) {
|
if (R_FAILED(rc = fs.CreateFile(file_path, info.uncompressed_size, 0)) && rc != FsError_PathAlreadyExists) {
|
||||||
@@ -375,45 +376,6 @@ Menu::Menu() : MenuBase{"Themezer"_i18n} {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
this->SetActions(
|
this->SetActions(
|
||||||
std::make_pair(Button::RIGHT, Action{[this](){
|
|
||||||
const auto& page = m_pages[m_page_index];
|
|
||||||
if (m_index < (page.m_packList.size() - 1) && (m_index + 1) % 3 != 0) {
|
|
||||||
SetIndex(m_index + 1);
|
|
||||||
App::PlaySoundEffect(SoundEffect_Scroll);
|
|
||||||
log_write("moved right\n");
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::LEFT, Action{[this](){
|
|
||||||
if (m_index != 0 && (m_index % 3) != 0) {
|
|
||||||
SetIndex(m_index - 1);
|
|
||||||
App::PlaySoundEffect(SoundEffect_Scroll);
|
|
||||||
log_write("moved left\n");
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::DOWN, Action{[this](){
|
|
||||||
const auto& page = m_pages[m_page_index];
|
|
||||||
if (m_list->ScrollDown(m_index, 3, page.m_packList.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::UP, Action{[this](){
|
|
||||||
const auto& page = m_pages[m_page_index];
|
|
||||||
if (m_list->ScrollUp(m_index, 3, page.m_packList.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::R2, Action{[this](){
|
|
||||||
const auto& page = m_pages[m_page_index];
|
|
||||||
if (m_list->ScrollDown(m_index, 6, page.m_packList.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::L2, Action{[this](){
|
|
||||||
const auto& page = m_pages[m_page_index];
|
|
||||||
if (m_list->ScrollUp(m_index, 6, page.m_packList.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::A, Action{"Download"_i18n, [this](){
|
std::make_pair(Button::A, Action{"Download"_i18n, [this](){
|
||||||
App::Push(std::make_shared<OptionBox>(
|
App::Push(std::make_shared<OptionBox>(
|
||||||
"Download theme?"_i18n,
|
"Download theme?"_i18n,
|
||||||
@@ -424,7 +386,7 @@ Menu::Menu() : MenuBase{"Themezer"_i18n} {
|
|||||||
const auto& entry = page.m_packList[m_index];
|
const auto& entry = page.m_packList[m_index];
|
||||||
const auto url = apiBuildUrlDownloadPack(entry);
|
const auto url = apiBuildUrlDownloadPack(entry);
|
||||||
|
|
||||||
App::Push(std::make_shared<ProgressBox>("Installing "_i18n + entry.details.name, [this, &entry](auto pbox){
|
App::Push(std::make_shared<ProgressBox>(entry.themes[0].preview.lazy_image.image, "Downloading "_i18n, entry.details.name, [this, &entry](auto pbox){
|
||||||
return InstallTheme(pbox, entry);
|
return InstallTheme(pbox, entry);
|
||||||
}, [this, &entry](bool success){
|
}, [this, &entry](bool success){
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -532,8 +494,8 @@ void Menu::Update(Controller* controller, TouchInfo* touch) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_list->OnUpdate(controller, touch, page.m_packList.size(), [this](auto i) {
|
m_list->OnUpdate(controller, touch, m_index, page.m_packList.size(), [this](bool touch, auto i) {
|
||||||
if (m_index == i) {
|
if (touch && m_index == i) {
|
||||||
FireAction(Button::A);
|
FireAction(Button::A);
|
||||||
} else {
|
} else {
|
||||||
App::PlaySoundEffect(SoundEffect_Focus);
|
App::PlaySoundEffect(SoundEffect_Focus);
|
||||||
@@ -642,7 +604,7 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::drawImageRounded(vg, x + xoff, y, 320, 180, image.image ? image.image : App::GetDefaultImage());
|
gfx::drawImage(vg, x + xoff, y, 320, 180, image.image ? image.image : App::GetDefaultImage(), 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
nvgSave(vg);
|
nvgSave(vg);
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
namespace sphaira::ui::menu::usb {
|
namespace sphaira::ui::menu::usb {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr u64 CONNECTION_TIMEOUT = 1e+9 * 3;
|
constexpr u64 CONNECTION_TIMEOUT = 1e+9 * 1; // 1 second
|
||||||
constexpr u64 TRANSFER_TIMEOUT = 1e+9 * 5;
|
constexpr u64 TRANSFER_TIMEOUT = 1e+9 * 5; // 5 seconds
|
||||||
|
|
||||||
void thread_func(void* user) {
|
void thread_func(void* user) {
|
||||||
auto app = static_cast<Menu*>(user);
|
auto app = static_cast<Menu*>(user);
|
||||||
@@ -21,17 +21,26 @@ void thread_func(void* user) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto rc = app->m_usb_source->WaitForConnection(CONNECTION_TIMEOUT, app->m_usb_speed, app->m_usb_count);
|
const auto rc = app->m_usb_source->IsUsbConnected(CONNECTION_TIMEOUT);
|
||||||
|
|
||||||
|
// set connected status
|
||||||
mutexLock(&app->m_mutex);
|
mutexLock(&app->m_mutex);
|
||||||
ON_SCOPE_EXIT(mutexUnlock(&app->m_mutex));
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
app->m_state = State::Connected_WaitForFileList;
|
||||||
|
} else {
|
||||||
|
app->m_state = State::None;
|
||||||
|
}
|
||||||
|
mutexUnlock(&app->m_mutex);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
app->m_state = State::Connected;
|
std::vector<std::string> names;
|
||||||
break;
|
if (R_SUCCEEDED(app->m_usb_source->WaitForConnection(CONNECTION_TIMEOUT, names))) {
|
||||||
} else if (R_FAILED(rc) && R_VALUE(rc) != 0xEA01) {
|
mutexLock(&app->m_mutex);
|
||||||
log_write("got: 0x%X value: 0x%X\n", rc, R_VALUE(rc));
|
ON_SCOPE_EXIT(mutexUnlock(&app->m_mutex));
|
||||||
app->m_state = State::Failed;
|
app->m_state = State::Connected_StartingTransfer;
|
||||||
break;
|
app->m_names = names;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,6 +52,10 @@ Menu::Menu() : MenuBase{"USB"_i18n} {
|
|||||||
SetPop();
|
SetPop();
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
SetAction(Button::X, Action{"Options"_i18n, [this](){
|
||||||
|
App::DisplayInstallOptions(false);
|
||||||
|
}});
|
||||||
|
|
||||||
// if mtp is enabled, disable it for now.
|
// if mtp is enabled, disable it for now.
|
||||||
m_was_mtp_enabled = App::GetMtpEnable();
|
m_was_mtp_enabled = App::GetMtpEnable();
|
||||||
if (m_was_mtp_enabled) {
|
if (m_was_mtp_enabled) {
|
||||||
@@ -91,54 +104,36 @@ void Menu::Update(Controller* controller, TouchInfo* touch) {
|
|||||||
mutexLock(&m_mutex);
|
mutexLock(&m_mutex);
|
||||||
ON_SCOPE_EXIT(mutexUnlock(&m_mutex));
|
ON_SCOPE_EXIT(mutexUnlock(&m_mutex));
|
||||||
|
|
||||||
switch (m_state) {
|
if (m_state == State::Connected_StartingTransfer) {
|
||||||
case State::None:
|
log_write("set to progress\n");
|
||||||
break;
|
m_state = State::Progress;
|
||||||
|
log_write("got connection\n");
|
||||||
|
App::Push(std::make_shared<ui::ProgressBox>(0, "Installing "_i18n, "", [this](auto pbox) mutable -> bool {
|
||||||
|
ON_SCOPE_EXIT(m_usb_source->Finished());
|
||||||
|
|
||||||
case State::Connected:
|
log_write("inside progress box\n");
|
||||||
log_write("set to progress\n");
|
for (const auto& file_name : m_names) {
|
||||||
m_state = State::Progress;
|
m_usb_source->SetFileNameForTranfser(file_name);
|
||||||
log_write("got connection\n");
|
|
||||||
App::Push(std::make_shared<ui::ProgressBox>("Installing App"_i18n, [this](auto pbox) mutable -> bool {
|
|
||||||
log_write("inside progress box\n");
|
|
||||||
for (u32 i = 0; i < m_usb_count; i++) {
|
|
||||||
std::string file_name;
|
|
||||||
u64 file_size;
|
|
||||||
if (R_FAILED(m_usb_source->GetFileInfo(file_name, file_size))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_write("got file name: %s size: %lX\n", file_name.c_str(), file_size);
|
const auto rc = yati::InstallFromSource(pbox, m_usb_source, file_name);
|
||||||
|
if (R_FAILED(rc)) {
|
||||||
const auto rc = yati::InstallFromSource(pbox, m_usb_source, file_name);
|
return false;
|
||||||
if (R_FAILED(rc)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
App::Notify("Installed via usb"_i18n);
|
|
||||||
m_usb_source->Finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
App::Notify("Installed via usb"_i18n);
|
||||||
}, [this](bool result){
|
}
|
||||||
if (result) {
|
|
||||||
App::Notify("Usb install success!"_i18n);
|
|
||||||
m_state = State::Done;
|
|
||||||
} else {
|
|
||||||
App::Notify("Usb install failed!"_i18n);
|
|
||||||
m_state = State::Failed;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::Progress:
|
return true;
|
||||||
break;
|
}, [this](bool result){
|
||||||
|
if (result) {
|
||||||
case State::Done:
|
App::Notify("Usb install success!"_i18n);
|
||||||
break;
|
m_state = State::Done;
|
||||||
|
SetPop();
|
||||||
case State::Failed:
|
} else {
|
||||||
break;
|
App::Notify("Usb install failed!"_i18n);
|
||||||
|
m_state = State::Failed;
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +148,12 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
|||||||
gfx::drawTextArgs(vg, SCREEN_WIDTH / 2.f, SCREEN_HEIGHT / 2.f, 36.f, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT_INFO), "Waiting for connection..."_i18n.c_str());
|
gfx::drawTextArgs(vg, SCREEN_WIDTH / 2.f, SCREEN_HEIGHT / 2.f, 36.f, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT_INFO), "Waiting for connection..."_i18n.c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::Connected:
|
case State::Connected_WaitForFileList:
|
||||||
|
gfx::drawTextArgs(vg, SCREEN_WIDTH / 2.f, SCREEN_HEIGHT / 2.f, 36.f, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT_INFO), "Connected, waiting for file list..."_i18n.c_str());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case State::Connected_StartingTransfer:
|
||||||
|
gfx::drawTextArgs(vg, SCREEN_WIDTH / 2.f, SCREEN_HEIGHT / 2.f, 36.f, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT_INFO), "Connected, starting transfer..."_i18n.c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::Progress:
|
case State::Progress:
|
||||||
|
|||||||
@@ -34,24 +34,16 @@ constexpr std::array buttons = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// NEW ---------------------
|
// NEW ---------------------
|
||||||
void drawRectIntenal(NVGcontext* vg, const Vec4& v, const NVGcolor& c, bool rounded) {
|
void drawRectIntenal(NVGcontext* vg, const Vec4& v, const NVGcolor& c, float rounded) {
|
||||||
nvgBeginPath(vg);
|
nvgBeginPath(vg);
|
||||||
if (rounded) {
|
nvgRoundedRect(vg, v.x, v.y, v.w, v.h, rounded);
|
||||||
nvgRoundedRect(vg, v.x, v.y, v.w, v.h, 15);
|
|
||||||
} else {
|
|
||||||
nvgRect(vg, v.x, v.y, v.w, v.h);
|
|
||||||
}
|
|
||||||
nvgFillColor(vg, c);
|
nvgFillColor(vg, c);
|
||||||
nvgFill(vg);
|
nvgFill(vg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawRectIntenal(NVGcontext* vg, const Vec4& v, const NVGpaint& p, bool rounded) {
|
void drawRectIntenal(NVGcontext* vg, const Vec4& v, const NVGpaint& p, float rounded) {
|
||||||
nvgBeginPath(vg);
|
nvgBeginPath(vg);
|
||||||
if (rounded) {
|
nvgRoundedRect(vg, v.x, v.y, v.w, v.h, rounded);
|
||||||
nvgRoundedRect(vg, v.x, v.y, v.w, v.h, 15);
|
|
||||||
} else {
|
|
||||||
nvgRect(vg, v.x, v.y, v.w, v.h);
|
|
||||||
}
|
|
||||||
nvgFillPaint(vg, p);
|
nvgFillPaint(vg, p);
|
||||||
nvgFill(vg);
|
nvgFill(vg);
|
||||||
}
|
}
|
||||||
@@ -164,25 +156,13 @@ void drawTextArgs(NVGcontext* vg, float x, float y, float size, int align, const
|
|||||||
drawText(vg, x, y, size, buffer, nullptr, align, c);
|
drawText(vg, x, y, size, buffer, nullptr, align, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawImage(NVGcontext* vg, const Vec4& v, int texture) {
|
void drawImage(NVGcontext* vg, const Vec4& v, int texture, float rounded) {
|
||||||
const auto paint = nvgImagePattern(vg, v.x, v.y, v.w, v.h, 0, texture, 1.f);
|
const auto paint = nvgImagePattern(vg, v.x, v.y, v.w, v.h, 0, texture, 1.f);
|
||||||
drawRect(vg, v, paint, false);
|
drawRect(vg, v, paint, rounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawImage(NVGcontext* vg, float x, float y, float w, float h, int texture) {
|
void drawImage(NVGcontext* vg, float x, float y, float w, float h, int texture, float rounded) {
|
||||||
drawImage(vg, Vec4(x, y, w, h), texture);
|
drawImage(vg, Vec4(x, y, w, h), texture, rounded);
|
||||||
}
|
|
||||||
|
|
||||||
void drawImageRounded(NVGcontext* vg, const Vec4& v, int texture) {
|
|
||||||
const auto paint = nvgImagePattern(vg, v.x, v.y, v.w, v.h, 0, texture, 1.f);
|
|
||||||
nvgBeginPath(vg);
|
|
||||||
nvgRoundedRect(vg, v.x, v.y, v.w, v.h, 15);
|
|
||||||
nvgFillPaint(vg, paint);
|
|
||||||
nvgFill(vg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawImageRounded(NVGcontext* vg, float x, float y, float w, float h, int texture) {
|
|
||||||
drawImageRounded(vg, Vec4(x, y, w, h), texture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawTextBox(NVGcontext* vg, float x, float y, float size, float bound, const NVGcolor& c, const char* str, int align, const char* end) {
|
void drawTextBox(NVGcontext* vg, float x, float y, float size, float bound, const NVGcolor& c, const char* str, int align, const char* end) {
|
||||||
@@ -208,19 +188,19 @@ void dimBackground(NVGcontext* vg) {
|
|||||||
drawRectIntenal(vg, {0.f,0.f,SCREEN_WIDTH,SCREEN_HEIGHT}, nvgRGBA(0, 0, 0, 180), false);
|
drawRectIntenal(vg, {0.f,0.f,SCREEN_WIDTH,SCREEN_HEIGHT}, nvgRGBA(0, 0, 0, 180), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawRect(NVGcontext* vg, float x, float y, float w, float h, const NVGcolor& c, bool rounded) {
|
void drawRect(NVGcontext* vg, float x, float y, float w, float h, const NVGcolor& c, float rounded) {
|
||||||
drawRectIntenal(vg, {x,y,w,h}, c, rounded);
|
drawRectIntenal(vg, {x,y,w,h}, c, rounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawRect(NVGcontext* vg, const Vec4& v, const NVGcolor& c, bool rounded) {
|
void drawRect(NVGcontext* vg, const Vec4& v, const NVGcolor& c, float rounded) {
|
||||||
drawRectIntenal(vg, v, c, rounded);
|
drawRectIntenal(vg, v, c, rounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawRect(NVGcontext* vg, float x, float y, float w, float h, const NVGpaint& p, bool rounded) {
|
void drawRect(NVGcontext* vg, float x, float y, float w, float h, const NVGpaint& p, float rounded) {
|
||||||
drawRectIntenal(vg, {x,y,w,h}, p, rounded);
|
drawRectIntenal(vg, {x,y,w,h}, p, rounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawRect(NVGcontext* vg, const Vec4& v, const NVGpaint& p, bool rounded) {
|
void drawRect(NVGcontext* vg, const Vec4& v, const NVGpaint& p, float rounded) {
|
||||||
drawRectIntenal(vg, v, p, rounded);
|
drawRectIntenal(vg, v, p, rounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,16 +62,6 @@ PopupList::PopupList(std::string title, Items items, Callback cb, s64 index)
|
|||||||
, m_callback{cb}
|
, m_callback{cb}
|
||||||
, m_index{index} {
|
, m_index{index} {
|
||||||
this->SetActions(
|
this->SetActions(
|
||||||
std::make_pair(Button::DOWN, Action{[this](){
|
|
||||||
if (m_list->ScrollDown(m_index, 1, m_items.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::UP, Action{[this](){
|
|
||||||
if (m_list->ScrollUp(m_index, 1, m_items.size())) {
|
|
||||||
SetIndex(m_index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::A, Action{"Select"_i18n, [this](){
|
std::make_pair(Button::A, Action{"Select"_i18n, [this](){
|
||||||
if (m_callback) {
|
if (m_callback) {
|
||||||
m_callback(m_index);
|
m_callback(m_index);
|
||||||
@@ -83,6 +73,8 @@ PopupList::PopupList(std::string title, Items items, Callback cb, s64 index)
|
|||||||
}})
|
}})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
m_starting_index = m_index;
|
||||||
|
|
||||||
m_pos.w = 1280.f;
|
m_pos.w = 1280.f;
|
||||||
const float a = std::min(370.f, (60.f * static_cast<float>(m_items.size())));
|
const float a = std::min(370.f, (60.f * static_cast<float>(m_items.size())));
|
||||||
m_pos.h = 80.f + 140.f + a;
|
m_pos.h = 80.f + 140.f + a;
|
||||||
@@ -103,9 +95,11 @@ PopupList::PopupList(std::string title, Items items, Callback cb, s64 index)
|
|||||||
|
|
||||||
auto PopupList::Update(Controller* controller, TouchInfo* touch) -> void {
|
auto PopupList::Update(Controller* controller, TouchInfo* touch) -> void {
|
||||||
Widget::Update(controller, touch);
|
Widget::Update(controller, touch);
|
||||||
m_list->OnUpdate(controller, touch, m_items.size(), [this](auto i) {
|
m_list->OnUpdate(controller, touch, m_index, m_items.size(), [this](bool touch, auto i) {
|
||||||
SetIndex(i);
|
SetIndex(i);
|
||||||
FireAction(Button::A);
|
if (touch) {
|
||||||
|
FireAction(Button::A);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,15 +112,21 @@ auto PopupList::Draw(NVGcontext* vg, Theme* theme) -> void {
|
|||||||
|
|
||||||
m_list->Draw(vg, theme, m_items.size(), [this](auto* vg, auto* theme, auto v, auto i) {
|
m_list->Draw(vg, theme, m_items.size(), [this](auto* vg, auto* theme, auto v, auto i) {
|
||||||
const auto& [x, y, w, h] = v;
|
const auto& [x, y, w, h] = v;
|
||||||
|
auto colour = ThemeEntryID_TEXT;
|
||||||
if (m_index == i) {
|
if (m_index == i) {
|
||||||
gfx::drawRectOutline(vg, theme, 4.f, v);
|
gfx::drawRectOutline(vg, theme, 4.f, v);
|
||||||
gfx::drawText(vg, x + m_text_xoffset, y + (h / 2.f), 20.f, m_items[i].c_str(), NULL, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT_SELECTED));
|
|
||||||
} else {
|
} else {
|
||||||
if (i != m_items.size() - 1) {
|
if (i != m_items.size() - 1) {
|
||||||
gfx::drawRect(vg, x, y + h, w, 1.f, theme->GetColour(ThemeEntryID_LINE_SEPARATOR));
|
gfx::drawRect(vg, x, y + h, w, 1.f, theme->GetColour(ThemeEntryID_LINE_SEPARATOR));
|
||||||
}
|
}
|
||||||
gfx::drawText(vg, x + m_text_xoffset, y + (h / 2.f), 20.f, m_items[i].c_str(), NULL, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE, theme->GetColour(ThemeEntryID_TEXT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_starting_index == i) {
|
||||||
|
colour = ThemeEntryID_TEXT_SELECTED;
|
||||||
|
gfx::drawText(vg, x + w - m_text_xoffset, y + (h / 2.f), 20.f, "\uE14B", NULL, NVG_ALIGN_RIGHT | NVG_ALIGN_MIDDLE, theme->GetColour(colour));
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::drawText(vg, x + m_text_xoffset, y + (h / 2.f), 20.f, m_items[i].c_str(), NULL, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE, theme->GetColour(colour));
|
||||||
});
|
});
|
||||||
|
|
||||||
Widget::Draw(vg, theme);
|
Widget::Draw(vg, theme);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "defines.hpp"
|
#include "defines.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
#include "i18n.hpp"
|
#include "i18n.hpp"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace sphaira::ui {
|
namespace sphaira::ui {
|
||||||
namespace {
|
namespace {
|
||||||
@@ -17,7 +18,7 @@ void threadFunc(void* arg) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ProgressBox::ProgressBox(const std::string& title, ProgressBoxCallback callback, ProgressBoxDoneCallback done, int cpuid, int prio, int stack_size) {
|
ProgressBox::ProgressBox(int image, const std::string& action, const std::string& title, ProgressBoxCallback callback, ProgressBoxDoneCallback done, int cpuid, int prio, int stack_size) {
|
||||||
SetAction(Button::B, Action{"Back"_i18n, [this](){
|
SetAction(Button::B, Action{"Back"_i18n, [this](){
|
||||||
App::Push(std::make_shared<OptionBox>("Are you sure you wish to cancel?"_i18n, "No"_i18n, "Yes"_i18n, 1, [this](auto op_index){
|
App::Push(std::make_shared<OptionBox>("Are you sure you wish to cancel?"_i18n, "No"_i18n, "Yes"_i18n, 1, [this](auto op_index){
|
||||||
if (op_index && *op_index) {
|
if (op_index && *op_index) {
|
||||||
@@ -27,11 +28,6 @@ ProgressBox::ProgressBox(const std::string& title, ProgressBoxCallback callback,
|
|||||||
}));
|
}));
|
||||||
}});
|
}});
|
||||||
|
|
||||||
m_pos.w = 770.f;
|
|
||||||
m_pos.h = 430.f;
|
|
||||||
m_pos.x = 255;
|
|
||||||
m_pos.y = 145;
|
|
||||||
|
|
||||||
m_pos.w = 770.f;
|
m_pos.w = 770.f;
|
||||||
m_pos.h = 295.f;
|
m_pos.h = 295.f;
|
||||||
m_pos.x = (SCREEN_WIDTH / 2.f) - (m_pos.w / 2.f);
|
m_pos.x = (SCREEN_WIDTH / 2.f) - (m_pos.w / 2.f);
|
||||||
@@ -39,6 +35,8 @@ ProgressBox::ProgressBox(const std::string& title, ProgressBoxCallback callback,
|
|||||||
|
|
||||||
m_done = done;
|
m_done = done;
|
||||||
m_title = title;
|
m_title = title;
|
||||||
|
m_action = action;
|
||||||
|
m_image = image;
|
||||||
|
|
||||||
m_thread_data.pbox = this;
|
m_thread_data.pbox = this;
|
||||||
m_thread_data.callback = callback;
|
m_thread_data.callback = callback;
|
||||||
@@ -60,6 +58,7 @@ ProgressBox::~ProgressBox() {
|
|||||||
log_write("failed to close thread\n");
|
log_write("failed to close thread\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FreeImage();
|
||||||
m_done(m_thread_data.result);
|
m_done(m_thread_data.result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,12 +72,28 @@ auto ProgressBox::Update(Controller* controller, TouchInfo* touch) -> void {
|
|||||||
|
|
||||||
auto ProgressBox::Draw(NVGcontext* vg, Theme* theme) -> void {
|
auto ProgressBox::Draw(NVGcontext* vg, Theme* theme) -> void {
|
||||||
mutexLock(&m_mutex);
|
mutexLock(&m_mutex);
|
||||||
|
std::vector<u8> image_data{};
|
||||||
|
std::swap(m_image_data, image_data);
|
||||||
|
if (m_timestamp.GetSeconds()) {
|
||||||
|
m_timestamp.Update();
|
||||||
|
m_speed = m_offset - m_last_offset;
|
||||||
|
m_last_offset = m_offset;
|
||||||
|
}
|
||||||
|
|
||||||
const auto title = m_title;
|
const auto title = m_title;
|
||||||
const auto transfer = m_transfer;
|
const auto transfer = m_transfer;
|
||||||
const auto size = m_size;
|
const auto size = m_size;
|
||||||
const auto offset = m_offset;
|
const auto offset = m_offset;
|
||||||
|
const auto speed = m_speed;
|
||||||
|
const auto last_offset = m_last_offset;
|
||||||
mutexUnlock(&m_mutex);
|
mutexUnlock(&m_mutex);
|
||||||
|
|
||||||
|
if (!image_data.empty()) {
|
||||||
|
FreeImage();
|
||||||
|
m_image = nvgCreateImageMem(vg, 0, image_data.data(), image_data.size());
|
||||||
|
m_own_image = true;
|
||||||
|
}
|
||||||
|
|
||||||
gfx::dimBackground(vg);
|
gfx::dimBackground(vg);
|
||||||
gfx::drawRect(vg, m_pos, theme->GetColour(ThemeEntryID_POPUP));
|
gfx::drawRect(vg, m_pos, theme->GetColour(ThemeEntryID_POPUP));
|
||||||
|
|
||||||
@@ -86,20 +101,62 @@ auto ProgressBox::Draw(NVGcontext* vg, Theme* theme) -> void {
|
|||||||
// const Vec4 box = { 255, 145, 770, 430 };
|
// const Vec4 box = { 255, 145, 770, 430 };
|
||||||
const auto center_x = m_pos.x + m_pos.w/2;
|
const auto center_x = m_pos.x + m_pos.w/2;
|
||||||
const auto end_y = m_pos.y + m_pos.h;
|
const auto end_y = m_pos.y + m_pos.h;
|
||||||
const Vec4 prog_bar = { 400, end_y - 80, 480, 12 };
|
const auto progress_bar_w = m_pos.w - 230;
|
||||||
|
const Vec4 prog_bar = { center_x - progress_bar_w / 2, end_y - 100, progress_bar_w, 12 };
|
||||||
|
|
||||||
|
nvgSave(vg);
|
||||||
|
nvgIntersectScissor(vg, GetX(), GetY(), GetW(), GetH());
|
||||||
|
|
||||||
|
if (m_image) {
|
||||||
|
gfx::drawImage(vg, GetX() + 30, GetY() + 30, 128, 128, m_image, 10);
|
||||||
|
}
|
||||||
|
|
||||||
// shapes.
|
// shapes.
|
||||||
if (offset && size) {
|
if (offset && size) {
|
||||||
gfx::drawRect(vg, prog_bar, theme->GetColour(ThemeEntryID_PROGRESSBAR_BACKGROUND));
|
const auto font_size = 18.F;
|
||||||
|
const auto pad = 15.F;
|
||||||
|
const float rounding = 5;
|
||||||
|
|
||||||
|
gfx::drawRect(vg, prog_bar, theme->GetColour(ThemeEntryID_PROGRESSBAR_BACKGROUND), rounding);
|
||||||
const u32 percentage = ((double)offset / (double)size) * 100.0;
|
const u32 percentage = ((double)offset / (double)size) * 100.0;
|
||||||
gfx::drawRect(vg, prog_bar.x, prog_bar.y, ((float)offset / (float)size) * prog_bar.w, prog_bar.h, theme->GetColour(ThemeEntryID_PROGRESSBAR));
|
gfx::drawRect(vg, prog_bar.x, prog_bar.y, ((float)offset / (float)size) * prog_bar.w, prog_bar.h, theme->GetColour(ThemeEntryID_PROGRESSBAR), rounding);
|
||||||
gfx::drawTextArgs(vg, prog_bar.x + prog_bar.w + 10, prog_bar.y, 20, NVG_ALIGN_LEFT | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "%u%%", percentage);
|
gfx::drawTextArgs(vg, prog_bar.x + prog_bar.w + pad, prog_bar.y, font_size, NVG_ALIGN_LEFT | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "%u%%", percentage);
|
||||||
|
|
||||||
|
const double speed_mb = (double)speed / (1024.0 * 1024.0);
|
||||||
|
const double speed_kb = (double)speed / (1024.0);
|
||||||
|
|
||||||
|
char speed_str[32];
|
||||||
|
if (speed_mb >= 0.01) {
|
||||||
|
std::snprintf(speed_str, sizeof(speed_str), "%.2f MiB/s", speed_mb);
|
||||||
|
} else {
|
||||||
|
std::snprintf(speed_str, sizeof(speed_str), "%.2f KiB/s", speed_kb);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto left = size - last_offset;
|
||||||
|
const auto left_seconds = left / speed;
|
||||||
|
const auto hours = left_seconds / (60 * 60);
|
||||||
|
const auto minutes = left_seconds % (60 * 60) / 60;
|
||||||
|
const auto seconds = left_seconds % 60;
|
||||||
|
|
||||||
|
char time_str[64];
|
||||||
|
if (hours) {
|
||||||
|
std::snprintf(time_str, sizeof(time_str), "%zu hours %zu minutes remaining", hours, minutes);
|
||||||
|
} else if (minutes) {
|
||||||
|
std::snprintf(time_str, sizeof(time_str), "%zu minutes %zu seconds remaining", minutes, seconds);
|
||||||
|
} else {
|
||||||
|
std::snprintf(time_str, sizeof(time_str), "%zu seconds remaining", seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::drawTextArgs(vg, center_x, prog_bar.y + prog_bar.h + 30, 18, NVG_ALIGN_CENTER | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), "%s (%s)", time_str, speed_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::drawTextArgs(vg, center_x, m_pos.y + 60, 25, NVG_ALIGN_CENTER | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), title.c_str());
|
gfx::drawTextArgs(vg, center_x, m_pos.y + 40, 24, NVG_ALIGN_CENTER | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), m_action.c_str());
|
||||||
|
gfx::drawTextArgs(vg, center_x, m_pos.y + 100, 22, NVG_ALIGN_CENTER | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT), title.c_str());
|
||||||
if (!transfer.empty()) {
|
if (!transfer.empty()) {
|
||||||
gfx::drawTextArgs(vg, center_x, prog_bar.y - 15 - 20 * 1.5F, 20, NVG_ALIGN_CENTER, theme->GetColour(ThemeEntryID_TEXT), "%s", transfer.c_str());
|
gfx::drawTextArgs(vg, center_x, m_pos.y + 150, 18, NVG_ALIGN_CENTER | NVG_ALIGN_TOP, theme->GetColour(ThemeEntryID_TEXT_INFO), "%s", transfer.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvgRestore(vg);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ProgressBox::SetTitle(const std::string& title) -> ProgressBox& {
|
auto ProgressBox::SetTitle(const std::string& title) -> ProgressBox& {
|
||||||
@@ -115,6 +172,8 @@ auto ProgressBox::NewTransfer(const std::string& transfer) -> ProgressBox& {
|
|||||||
m_transfer = transfer;
|
m_transfer = transfer;
|
||||||
m_size = 0;
|
m_size = 0;
|
||||||
m_offset = 0;
|
m_offset = 0;
|
||||||
|
m_last_offset = 0;
|
||||||
|
m_timestamp.Update();
|
||||||
mutexUnlock(&m_mutex);
|
mutexUnlock(&m_mutex);
|
||||||
Yield();
|
Yield();
|
||||||
return *this;
|
return *this;
|
||||||
@@ -129,6 +188,21 @@ auto ProgressBox::UpdateTransfer(s64 offset, s64 size) -> ProgressBox& {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto ProgressBox::SetImageData(std::vector<u8>& data) -> ProgressBox& {
|
||||||
|
mutexLock(&m_mutex);
|
||||||
|
std::swap(m_image_data, data);
|
||||||
|
mutexUnlock(&m_mutex);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ProgressBox::SetImageDataConst(std::span<const u8> data) -> ProgressBox& {
|
||||||
|
mutexLock(&m_mutex);
|
||||||
|
m_image_data.resize(data.size());
|
||||||
|
std::memcpy(m_image_data.data(), data.data(), m_image_data.size());
|
||||||
|
mutexUnlock(&m_mutex);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void ProgressBox::RequestExit() {
|
void ProgressBox::RequestExit() {
|
||||||
m_stop_source.request_stop();
|
m_stop_source.request_stop();
|
||||||
}
|
}
|
||||||
@@ -184,4 +258,13 @@ void ProgressBox::Yield() {
|
|||||||
svcSleepThread(YieldType_WithoutCoreMigration);
|
svcSleepThread(YieldType_WithoutCoreMigration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProgressBox::FreeImage() {
|
||||||
|
if (m_image && m_own_image) {
|
||||||
|
nvgDeleteImage(App::GetVg(), m_image);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_image = 0;
|
||||||
|
m_own_image = false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sphaira::ui
|
} // namespace sphaira::ui
|
||||||
|
|||||||
@@ -259,9 +259,11 @@ auto Sidebar::Update(Controller* controller, TouchInfo* touch) -> void {
|
|||||||
if (touch->is_clicked && !touch->in_range(GetPos())) {
|
if (touch->is_clicked && !touch->in_range(GetPos())) {
|
||||||
App::PopToMenu();
|
App::PopToMenu();
|
||||||
} else {
|
} else {
|
||||||
m_list->OnUpdate(controller, touch, m_items.size(), [this](auto i) {
|
m_list->OnUpdate(controller, touch, m_index, m_items.size(), [this](bool touch, auto i) {
|
||||||
SetIndex(i);
|
SetIndex(i);
|
||||||
FireAction(Button::A);
|
if (touch) {
|
||||||
|
FireAction(Button::A);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,18 +336,6 @@ void Sidebar::SetupButtons() {
|
|||||||
|
|
||||||
// add default actions, overriding if needed.
|
// add default actions, overriding if needed.
|
||||||
this->SetActions(
|
this->SetActions(
|
||||||
std::make_pair(Button::DOWN, Action{[this](){
|
|
||||||
auto index = m_index;
|
|
||||||
if (m_list->ScrollDown(index, 1, m_items.size())) {
|
|
||||||
SetIndex(index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
std::make_pair(Button::UP, Action{[this](){
|
|
||||||
auto index = m_index;
|
|
||||||
if (m_list->ScrollUp(index, 1, m_items.size())) {
|
|
||||||
SetIndex(index);
|
|
||||||
}
|
|
||||||
}}),
|
|
||||||
// each item has it's own Action, but we take over B
|
// each item has it's own Action, but we take over B
|
||||||
std::make_pair(Button::B, Action{"Back"_i18n, [this](){
|
std::make_pair(Button::B, Action{"Back"_i18n, [this](){
|
||||||
SetPop();
|
SetPop();
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
#include "web.hpp"
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "defines.hpp"
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
namespace sphaira {
|
|
||||||
|
|
||||||
auto WebShow(const std::string& url, bool show_error) -> Result {
|
|
||||||
// showError("Running in applet mode\nPlease launch hbmenu by holding R on an APP (e.g. a game) NOT an applet (e.g. Gallery)", "", 0);
|
|
||||||
// showError("Error: Nag active, check more details", "Browser won't launch if supernag is active\n\nUse gagorder or switch-sys-tweak (the latter is bundled with BrowseNX) to disable supernag.", 0);
|
|
||||||
// log_write("web show with url: %s\n", url.c_str());
|
|
||||||
// return 0;
|
|
||||||
WebCommonConfig config{};
|
|
||||||
WebCommonReply reply{};
|
|
||||||
WebExitReason reason{};
|
|
||||||
AccountUid account_uid{};
|
|
||||||
char last_url[FS_MAX_PATH]{};
|
|
||||||
size_t last_url_len{};
|
|
||||||
|
|
||||||
// WebBackgroundKind_Unknown1 = shows background
|
|
||||||
// WebBackgroundKind_Unknown2 = shows background faded
|
|
||||||
if (R_FAILED(accountTrySelectUserWithoutInteraction(&account_uid, false))) { log_write("failed: accountTrySelectUserWithoutInteraction\n"); }
|
|
||||||
if (R_FAILED(webPageCreate(&config, url.c_str()))) { log_write("failed: webPageCreate\n"); }
|
|
||||||
if (R_FAILED(webConfigSetWhitelist(&config, "^http"))) { log_write("failed: webConfigSetWhitelist\n"); }
|
|
||||||
if (R_FAILED(webConfigSetEcClientCert(&config, true))) { log_write("failed: webConfigSetEcClientCert\n"); }
|
|
||||||
if (R_FAILED(webConfigSetScreenShot(&config, true))) { log_write("failed: webConfigSetScreenShot\n"); }
|
|
||||||
if (R_FAILED(webConfigSetBootDisplayKind(&config, WebBootDisplayKind_Black))) { log_write("failed: webConfigSetBootDisplayKind\n"); }
|
|
||||||
if (R_FAILED(webConfigSetBackgroundKind(&config, WebBackgroundKind_Default))) { log_write("failed: webConfigSetBackgroundKind\n"); }
|
|
||||||
if (R_FAILED(webConfigSetPointer(&config, true))) { log_write("failed: webConfigSetPointer\n"); }
|
|
||||||
if (R_FAILED(webConfigSetLeftStickMode(&config, WebLeftStickMode_Pointer))) { log_write("failed: webConfigSetLeftStickMode\n"); }
|
|
||||||
// if (R_FAILED(webConfigSetBootAsMediaPlayer(&config, true))) { log_write("failed: webConfigSetBootAsMediaPlayer\n"); }
|
|
||||||
if (R_FAILED(webConfigSetJsExtension(&config, true))) { log_write("failed: webConfigSetJsExtension\n"); }
|
|
||||||
if (R_FAILED(webConfigSetMediaPlayerAutoClose(&config, true))) { log_write("failed: webConfigSetMediaPlayerAutoClose\n"); }
|
|
||||||
if (R_FAILED(webConfigSetPageCache(&config, true))) { log_write("failed: webConfigSetPageCache\n"); }
|
|
||||||
if (R_FAILED(webConfigSetFooterFixedKind(&config, WebFooterFixedKind_Hidden))) { log_write("failed: webConfigSetFooterFixedKind\n"); }
|
|
||||||
if (R_FAILED(webConfigSetPageFade(&config, true))) { log_write("failed: webConfigSetPageFade\n"); }
|
|
||||||
if (R_FAILED(webConfigSetPageScrollIndicator(&config, true))) { log_write("failed: webConfigSetPageScrollIndicator\n"); }
|
|
||||||
// if (R_FAILED(webConfigSetMediaPlayerSpeedControl(&config, true))) { log_write("failed: webConfigSetMediaPlayerSpeedControl\n"); }
|
|
||||||
if (R_FAILED(webConfigSetBootMode(&config, WebSessionBootMode_AllForeground))) { log_write("failed: webConfigSetBootMode\n"); }
|
|
||||||
if (R_FAILED(webConfigSetTransferMemory(&config, true))) { log_write("failed: webConfigSetTransferMemory\n"); }
|
|
||||||
if (R_FAILED(webConfigSetTouchEnabledOnContents(&config, true))) { log_write("failed: webConfigSetTouchEnabledOnContents\n"); }
|
|
||||||
// if (R_FAILED(webConfigSetMediaPlayerUi(&config, true))) { log_write("failed: webConfigSetMediaPlayerUi\n"); }
|
|
||||||
// if (R_FAILED(webConfigSetWebAudio(&config, true))) { log_write("failed: webConfigSetWebAudio\n"); }
|
|
||||||
if (R_FAILED(webConfigSetPageCache(&config, true))) { log_write("failed: webConfigSetPageCache\n"); }
|
|
||||||
if (R_FAILED(webConfigSetBootLoadingIcon(&config, true))) { log_write("failed: webConfigSetBootLoadingIcon\n"); }
|
|
||||||
if (R_FAILED(webConfigSetUid(&config, account_uid))) { log_write("failed: webConfigSetUid\n"); }
|
|
||||||
if (R_FAILED(webConfigShow(&config, &reply))) { log_write("failed: webConfigShow\n"); }
|
|
||||||
if (R_FAILED(webReplyGetExitReason(&reply, &reason))) { log_write("failed: webReplyGetExitReason\n"); }
|
|
||||||
if (R_FAILED(webReplyGetLastUrl(&reply, last_url, sizeof(last_url), &last_url_len))) { log_write("failed: webReplyGetLastUrl\n"); }
|
|
||||||
log_write("last url: %s\n", last_url);
|
|
||||||
R_SUCCEED();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sphaira
|
|
||||||
@@ -151,4 +151,30 @@ Result VerifyFixedKey(const Header& header) {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto GetKeyGenStr(u8 key_gen) -> const char* {
|
||||||
|
switch (key_gen) {
|
||||||
|
case KeyGenerationOld_100: return "1.0.0";
|
||||||
|
case KeyGenerationOld_300: return "3.0.0";
|
||||||
|
case KeyGeneration_301: return "3.0.1";
|
||||||
|
case KeyGeneration_400: return "4.0.0";
|
||||||
|
case KeyGeneration_500: return "5.0.0";
|
||||||
|
case KeyGeneration_600: return "6.0.0";
|
||||||
|
case KeyGeneration_620: return "6.2.0";
|
||||||
|
case KeyGeneration_700: return "7.0.0";
|
||||||
|
case KeyGeneration_810: return "8.1.0";
|
||||||
|
case KeyGeneration_900: return "9.0.0";
|
||||||
|
case KeyGeneration_910: return "9.1.0";
|
||||||
|
case KeyGeneration_1210: return "12.1.0";
|
||||||
|
case KeyGeneration_1300: return "13.0.0";
|
||||||
|
case KeyGeneration_1400: return "14.0.0";
|
||||||
|
case KeyGeneration_1500: return "15.0.0";
|
||||||
|
case KeyGeneration_1600: return "16.0.0";
|
||||||
|
case KeyGeneration_1700: return "17.0.0";
|
||||||
|
case KeyGeneration_1800: return "18.0.0";
|
||||||
|
case KeyGeneration_1900: return "19.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sphaira::nca
|
} // namespace sphaira::nca
|
||||||
|
|||||||
@@ -7,16 +7,24 @@ namespace {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
auto GetAppId(const NcmContentMetaKey& key) -> u64 {
|
auto GetAppId(u8 meta_type, u64 id) -> u64 {
|
||||||
if (key.type == NcmContentMetaType_Patch) {
|
if (meta_type == NcmContentMetaType_Patch) {
|
||||||
return key.id ^ 0x800;
|
return id ^ 0x800;
|
||||||
} else if (key.type == NcmContentMetaType_AddOnContent) {
|
} else if (meta_type == NcmContentMetaType_AddOnContent) {
|
||||||
return (key.id ^ 0x1000) & ~0xFFF;
|
return (id ^ 0x1000) & ~0xFFF;
|
||||||
} else {
|
} else {
|
||||||
return key.id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto GetAppId(const NcmContentMetaKey& key) -> u64 {
|
||||||
|
return GetAppId(key.type, key.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto GetAppId(const PackagedContentMeta& meta) -> u64 {
|
||||||
|
return GetAppId(meta.meta_type, meta.title_id);
|
||||||
|
}
|
||||||
|
|
||||||
Result Delete(NcmContentStorage* cs, const NcmContentId *content_id) {
|
Result Delete(NcmContentStorage* cs, const NcmContentId *content_id) {
|
||||||
bool has;
|
bool has;
|
||||||
R_TRY(ncmContentStorageHas(cs, std::addressof(has), content_id));
|
R_TRY(ncmContentStorageHas(cs, std::addressof(has), content_id));
|
||||||
|
|||||||
@@ -14,33 +14,58 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Most of the usb transfer code was taken from Haze.
|
// The USB transfer code was taken from Haze (part of Atmosphere).
|
||||||
|
// The USB protocol was taken from Tinfoil, by Adubbz.
|
||||||
|
|
||||||
#include "yati/source/usb.hpp"
|
#include "yati/source/usb.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
namespace sphaira::yati::source {
|
namespace sphaira::yati::source {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr u32 MAGIC = 0x53504841;
|
enum USBCmdType : u8 {
|
||||||
constexpr u32 VERSION = 2;
|
REQUEST = 0,
|
||||||
|
RESPONSE = 1
|
||||||
struct SendHeader {
|
|
||||||
u32 magic;
|
|
||||||
u32 version;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RecvHeader {
|
enum USBCmdId : u32 {
|
||||||
u32 magic;
|
EXIT = 0,
|
||||||
u32 version;
|
FILE_RANGE = 1
|
||||||
u32 bcdUSB;
|
|
||||||
u32 count;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NX_PACKED USBCmdHeader {
|
||||||
|
u32 magic;
|
||||||
|
USBCmdType type;
|
||||||
|
u8 padding[0x3] = {0};
|
||||||
|
u32 cmdId;
|
||||||
|
u64 dataSize;
|
||||||
|
u8 reserved[0xC] = {0};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FileRangeCmdHeader {
|
||||||
|
u64 size;
|
||||||
|
u64 offset;
|
||||||
|
u64 nspNameLen;
|
||||||
|
u64 padding;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TUSHeader {
|
||||||
|
u32 magic; // TUL0 (Tinfoil Usb List 0)
|
||||||
|
u32 nspListSize;
|
||||||
|
u64 padding;
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(sizeof(TUSHeader) == 0x10, "TUSHeader must be 0x10!");
|
||||||
|
static_assert(sizeof(USBCmdHeader) == 0x20, "USBCmdHeader must be 0x20!");
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Usb::Usb(u64 transfer_timeout) {
|
Usb::Usb(u64 transfer_timeout) {
|
||||||
m_open_result = usbDsInitialize();
|
m_open_result = usbDsInitialize();
|
||||||
m_transfer_timeout = transfer_timeout;
|
m_transfer_timeout = transfer_timeout;
|
||||||
|
// this avoids allocations during transfers.
|
||||||
|
m_aligned.reserve(1024 * 1024 * 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
Usb::~Usb() {
|
Usb::~Usb() {
|
||||||
@@ -53,6 +78,11 @@ Result Usb::Init() {
|
|||||||
log_write("doing USB init\n");
|
log_write("doing USB init\n");
|
||||||
R_TRY(m_open_result);
|
R_TRY(m_open_result);
|
||||||
|
|
||||||
|
SetSysSerialNumber serial_number;
|
||||||
|
R_TRY(setsysInitialize());
|
||||||
|
ON_SCOPE_EXIT(setsysExit());
|
||||||
|
R_TRY(setsysGetSerialNumber(&serial_number));
|
||||||
|
|
||||||
u8 iManufacturer, iProduct, iSerialNumber;
|
u8 iManufacturer, iProduct, iSerialNumber;
|
||||||
static const u16 supported_langs[1] = {0x0409};
|
static const u16 supported_langs[1] = {0x0409};
|
||||||
// Send language descriptor
|
// Send language descriptor
|
||||||
@@ -62,7 +92,7 @@ Result Usb::Init() {
|
|||||||
// Send product
|
// Send product
|
||||||
R_TRY(usbDsAddUsbStringDescriptor(&iProduct, "Nintendo Switch"));
|
R_TRY(usbDsAddUsbStringDescriptor(&iProduct, "Nintendo Switch"));
|
||||||
// Send serial number
|
// Send serial number
|
||||||
R_TRY(usbDsAddUsbStringDescriptor(&iSerialNumber, "SerialNumber"));
|
R_TRY(usbDsAddUsbStringDescriptor(&iSerialNumber, serial_number.number));
|
||||||
|
|
||||||
// Send device descriptors
|
// Send device descriptors
|
||||||
struct usb_device_descriptor device_descriptor = {
|
struct usb_device_descriptor device_descriptor = {
|
||||||
@@ -131,13 +161,11 @@ Result Usb::Init() {
|
|||||||
.bInterfaceProtocol = USB_CLASS_VENDOR_SPEC,
|
.bInterfaceProtocol = USB_CLASS_VENDOR_SPEC,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct usb_endpoint_descriptor endpoint_descriptor_in = {
|
struct usb_endpoint_descriptor endpoint_descriptor_in = {
|
||||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||||
.bDescriptorType = USB_DT_ENDPOINT,
|
.bDescriptorType = USB_DT_ENDPOINT,
|
||||||
.bEndpointAddress = USB_ENDPOINT_IN,
|
.bEndpointAddress = USB_ENDPOINT_IN,
|
||||||
.bmAttributes = USB_TRANSFER_TYPE_BULK,
|
.bmAttributes = USB_TRANSFER_TYPE_BULK,
|
||||||
.wMaxPacketSize = 0x40,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct usb_endpoint_descriptor endpoint_descriptor_out = {
|
struct usb_endpoint_descriptor endpoint_descriptor_out = {
|
||||||
@@ -145,7 +173,6 @@ Result Usb::Init() {
|
|||||||
.bDescriptorType = USB_DT_ENDPOINT,
|
.bDescriptorType = USB_DT_ENDPOINT,
|
||||||
.bEndpointAddress = USB_ENDPOINT_OUT,
|
.bEndpointAddress = USB_ENDPOINT_OUT,
|
||||||
.bmAttributes = USB_TRANSFER_TYPE_BULK,
|
.bmAttributes = USB_TRANSFER_TYPE_BULK,
|
||||||
.wMaxPacketSize = 0x40,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct usb_ss_endpoint_companion_descriptor endpoint_companion = {
|
const struct usb_ss_endpoint_companion_descriptor endpoint_companion = {
|
||||||
@@ -163,6 +190,8 @@ Result Usb::Init() {
|
|||||||
endpoint_descriptor_out.bEndpointAddress += interface_descriptor.bInterfaceNumber + 1;
|
endpoint_descriptor_out.bEndpointAddress += interface_descriptor.bInterfaceNumber + 1;
|
||||||
|
|
||||||
// Full Speed Config
|
// Full Speed Config
|
||||||
|
endpoint_descriptor_in.wMaxPacketSize = 0x40;
|
||||||
|
endpoint_descriptor_out.wMaxPacketSize = 0x40;
|
||||||
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Full, &interface_descriptor, USB_DT_INTERFACE_SIZE));
|
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Full, &interface_descriptor, USB_DT_INTERFACE_SIZE));
|
||||||
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Full, &endpoint_descriptor_in, USB_DT_ENDPOINT_SIZE));
|
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Full, &endpoint_descriptor_in, USB_DT_ENDPOINT_SIZE));
|
||||||
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Full, &endpoint_descriptor_out, USB_DT_ENDPOINT_SIZE));
|
R_TRY(usbDsInterface_AppendConfigurationData(m_interface, UsbDeviceSpeed_Full, &endpoint_descriptor_out, USB_DT_ENDPOINT_SIZE));
|
||||||
@@ -194,62 +223,38 @@ Result Usb::Init() {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Usb::WaitForConnection(u64 timeout, u32& speed, u32& count) {
|
Result Usb::IsUsbConnected(u64 timeout) const {
|
||||||
const SendHeader send_header{
|
return usbDsWaitReady(timeout);
|
||||||
.magic = MAGIC,
|
}
|
||||||
.version = VERSION,
|
|
||||||
};
|
|
||||||
|
|
||||||
alignas(0x1000) u8 aligned[0x1000]{};
|
Result Usb::WaitForConnection(u64 timeout, std::vector<std::string>& out_names) {
|
||||||
std::memcpy(aligned, std::addressof(send_header), sizeof(send_header));
|
TUSHeader header;
|
||||||
|
R_TRY(TransferAll(true, &header, sizeof(header), timeout));
|
||||||
|
R_UNLESS(header.magic == 0x304C5554, Result_BadMagic);
|
||||||
|
R_UNLESS(header.nspListSize > 0, Result_BadCount);
|
||||||
|
log_write("USB got header\n");
|
||||||
|
|
||||||
// send header.
|
std::vector<char> names(header.nspListSize);
|
||||||
u32 transferredSize;
|
R_TRY(TransferAll(true, names.data(), names.size(), timeout));
|
||||||
R_TRY(TransferPacketImpl(false, aligned, sizeof(send_header), &transferredSize, timeout));
|
|
||||||
|
|
||||||
// receive header.
|
out_names.clear();
|
||||||
struct RecvHeader recv_header{};
|
for (const auto& name : std::views::split(names, '\n')) {
|
||||||
R_TRY(TransferPacketImpl(true, aligned, sizeof(recv_header), &transferredSize, timeout));
|
if (!name.empty()) {
|
||||||
|
out_names.emplace_back(name.data(), name.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// copy data into header struct.
|
for (auto& name : out_names) {
|
||||||
std::memcpy(&recv_header, aligned, sizeof(recv_header));
|
log_write("got name: %s\n", name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
// validate received header.
|
R_UNLESS(!out_names.empty(), Result_BadCount);
|
||||||
R_UNLESS(recv_header.magic == MAGIC, Result_BadMagic);
|
log_write("USB SUCCESS\n");
|
||||||
R_UNLESS(recv_header.version == VERSION, Result_BadVersion);
|
|
||||||
R_UNLESS(recv_header.count > 0, Result_BadCount);
|
|
||||||
|
|
||||||
count = recv_header.count;
|
|
||||||
speed = recv_header.bcdUSB;
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Usb::GetFileInfo(std::string& name_out, u64& size_out) {
|
void Usb::SetFileNameForTranfser(const std::string& name) {
|
||||||
struct {
|
m_transfer_file_name = name;
|
||||||
u64 size;
|
|
||||||
u64 name_length;
|
|
||||||
} file_info_meta;
|
|
||||||
|
|
||||||
alignas(0x1000) u8 aligned[0x1000]{};
|
|
||||||
|
|
||||||
// receive meta.
|
|
||||||
u32 transferredSize;
|
|
||||||
R_TRY(TransferPacketImpl(true, aligned, sizeof(file_info_meta), &transferredSize, m_transfer_timeout));
|
|
||||||
std::memcpy(&file_info_meta, aligned, sizeof(file_info_meta));
|
|
||||||
R_UNLESS(file_info_meta.name_length < sizeof(aligned), 0x1);
|
|
||||||
|
|
||||||
R_TRY(TransferPacketImpl(true, aligned, file_info_meta.name_length, &transferredSize, m_transfer_timeout));
|
|
||||||
name_out.resize(file_info_meta.name_length);
|
|
||||||
std::memcpy(name_out.data(), aligned, name_out.size());
|
|
||||||
|
|
||||||
size_out = file_info_meta.size;
|
|
||||||
R_SUCCEED();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Usb::GetConfigured() const {
|
|
||||||
UsbState usb_state;
|
|
||||||
usbDsGetState(std::addressof(usb_state));
|
|
||||||
return usb_state == UsbState_Configured;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Event *Usb::GetCompletionEvent(UsbSessionEndpoint ep) const {
|
Event *Usb::GetCompletionEvent(UsbSessionEndpoint ep) const {
|
||||||
@@ -286,12 +291,7 @@ Result Usb::TransferPacketImpl(bool read, void *page, u32 size, u32 *out_size_tr
|
|||||||
u32 urb_id;
|
u32 urb_id;
|
||||||
|
|
||||||
/* If we're not configured yet, wait to become configured first. */
|
/* If we're not configured yet, wait to become configured first. */
|
||||||
// R_TRY(usbDsWaitReady(timeout));
|
R_TRY(IsUsbConnected(timeout));
|
||||||
if (!GetConfigured()) {
|
|
||||||
R_TRY(eventWait(usbDsGetStateChangeEvent(), timeout));
|
|
||||||
R_TRY(eventClear(usbDsGetStateChangeEvent()));
|
|
||||||
R_THROW(0xEA01);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Select the appropriate endpoint and begin a transfer. */
|
/* Select the appropriate endpoint and begin a transfer. */
|
||||||
const auto ep = read ? UsbSessionEndpoint_Out : UsbSessionEndpoint_In;
|
const auto ep = read ? UsbSessionEndpoint_Out : UsbSessionEndpoint_In;
|
||||||
@@ -304,78 +304,73 @@ Result Usb::TransferPacketImpl(bool read, void *page, u32 size, u32 *out_size_tr
|
|||||||
return GetTransferResult(ep, urb_id, nullptr, out_size_transferred);
|
return GetTransferResult(ep, urb_id, nullptr, out_size_transferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Usb::SendCommand(s64 off, s64 size) const {
|
// while it may seem like a bad idea to transfer data to a buffer and copy it
|
||||||
struct {
|
// in practice, this has no impact on performance.
|
||||||
u32 hash;
|
// the switch is *massively* bottlenecked by slow io (nand and sd).
|
||||||
u32 magic;
|
// so making usb transfers zero-copy provides no benefit other than increased
|
||||||
s64 off;
|
// code complexity and the increase of future bugs if/when sphaira is forked
|
||||||
s64 size;
|
// an changes are made.
|
||||||
} meta{0, 0, off, size};
|
// yati already goes to great lengths to be zero-copy during installing
|
||||||
|
// by swapping buffers and inflating in-place.
|
||||||
alignas(0x1000) static u8 aligned[0x1000]{};
|
Result Usb::TransferAll(bool read, void *data, u32 size, u64 timeout) {
|
||||||
std::memcpy(aligned, std::addressof(meta), sizeof(meta));
|
auto buf = static_cast<u8*>(data);
|
||||||
|
m_aligned.resize((size + 0xFFF) & ~0xFFF);
|
||||||
u32 transferredSize;
|
|
||||||
return TransferPacketImpl(false, aligned, sizeof(meta), &transferredSize, m_transfer_timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result Usb::Finished() const {
|
|
||||||
return SendCommand(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Result Usb::InternalRead(void* _buf, s64 off, s64 size) const {
|
|
||||||
u8* buf = (u8*)_buf;
|
|
||||||
alignas(0x1000) u8 aligned[0x1000]{};
|
|
||||||
const auto stored_size = size;
|
|
||||||
s64 total = 0;
|
|
||||||
|
|
||||||
while (size) {
|
while (size) {
|
||||||
auto read_size = size;
|
if (!read) {
|
||||||
auto read_buf = buf;
|
std::memcpy(m_aligned.data(), buf, size);
|
||||||
|
|
||||||
if (u64(buf) & 0xFFF) {
|
|
||||||
read_size = std::min<u64>(size, sizeof(aligned) - (u64(buf) & 0xFFF));
|
|
||||||
read_buf = aligned;
|
|
||||||
log_write("unaligned read %zd %zd read_size: %zd align: %zd\n", off, size, read_size, u64(buf) & 0xFFF);
|
|
||||||
} else if (read_size & 0xFFF) {
|
|
||||||
if (read_size <= 0xFFF) {
|
|
||||||
log_write("unaligned small read %zd %zd read_size: %zd align: %zd\n", off, size, read_size, u64(buf) & 0xFFF);
|
|
||||||
read_buf = aligned;
|
|
||||||
} else {
|
|
||||||
log_write("unaligned big read %zd %zd read_size: %zd align: %zd\n", off, size, read_size, u64(buf) & 0xFFF);
|
|
||||||
// read as much as possible into buffer, the rest will
|
|
||||||
// be handled in a second read which will be aligned size aligned.
|
|
||||||
read_size = read_size & ~0xFFF;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
R_TRY(SendCommand(off, read_size));
|
u32 out_size_transferred;
|
||||||
|
R_TRY(TransferPacketImpl(read, m_aligned.data(), size, &out_size_transferred, timeout));
|
||||||
|
|
||||||
u32 transferredSize{};
|
if (read) {
|
||||||
R_TRY(TransferPacketImpl(true, read_buf, read_size, &transferredSize, m_transfer_timeout));
|
std::memcpy(buf, m_aligned.data(), out_size_transferred);
|
||||||
R_UNLESS(transferredSize <= read_size, Result_BadTransferSize);
|
|
||||||
|
|
||||||
if (read_buf == aligned) {
|
|
||||||
std::memcpy(buf, aligned, transferredSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transferredSize < read_size) {
|
buf += out_size_transferred;
|
||||||
log_write("reading less than expected! %u vs %zd stored: %zd\n", transferredSize, read_size, stored_size);
|
size -= out_size_transferred;
|
||||||
}
|
|
||||||
|
|
||||||
off += transferredSize;
|
|
||||||
buf += transferredSize;
|
|
||||||
size -= transferredSize;
|
|
||||||
total += transferredSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
R_UNLESS(total == stored_size, Result_BadTotalSize);
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result Usb::SendCmdHeader(u32 cmdId, size_t dataSize) {
|
||||||
|
USBCmdHeader header{
|
||||||
|
.magic = 0x30435554, // TUC0 (Tinfoil USB Command 0)
|
||||||
|
.type = USBCmdType::REQUEST,
|
||||||
|
.cmdId = cmdId,
|
||||||
|
.dataSize = dataSize,
|
||||||
|
};
|
||||||
|
|
||||||
|
return TransferAll(false, &header, sizeof(header), m_transfer_timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result Usb::SendFileRangeCmd(u64 off, u64 size) {
|
||||||
|
FileRangeCmdHeader fRangeHeader;
|
||||||
|
fRangeHeader.size = size;
|
||||||
|
fRangeHeader.offset = off;
|
||||||
|
fRangeHeader.nspNameLen = m_transfer_file_name.size();
|
||||||
|
fRangeHeader.padding = 0;
|
||||||
|
|
||||||
|
R_TRY(SendCmdHeader(USBCmdId::FILE_RANGE, sizeof(fRangeHeader) + fRangeHeader.nspNameLen));
|
||||||
|
R_TRY(TransferAll(false, &fRangeHeader, sizeof(fRangeHeader), m_transfer_timeout));
|
||||||
|
R_TRY(TransferAll(false, m_transfer_file_name.data(), m_transfer_file_name.size(), m_transfer_timeout));
|
||||||
|
|
||||||
|
USBCmdHeader responseHeader;
|
||||||
|
R_TRY(TransferAll(true, &responseHeader, sizeof(responseHeader), m_transfer_timeout));
|
||||||
|
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result Usb::Finished() {
|
||||||
|
return SendCmdHeader(USBCmdId::EXIT, 0);
|
||||||
|
}
|
||||||
|
|
||||||
Result Usb::Read(void* buf, s64 off, s64 size, u64* bytes_read) {
|
Result Usb::Read(void* buf, s64 off, s64 size, u64* bytes_read) {
|
||||||
R_TRY(GetOpenResult());
|
R_TRY(GetOpenResult());
|
||||||
R_TRY(InternalRead(buf, off, size));
|
R_TRY(SendFileRangeCmd(off, size));
|
||||||
|
R_TRY(TransferAll(true, buf, size, m_transfer_timeout));
|
||||||
*bytes_read = size;
|
*bytes_read = size;
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#include "i18n.hpp"
|
#include "i18n.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
|
|
||||||
#include <new>
|
|
||||||
#include <zstd.h>
|
#include <zstd.h>
|
||||||
#include <minIni.h>
|
#include <minIni.h>
|
||||||
|
|
||||||
@@ -30,40 +29,10 @@ constexpr NcmStorageId NCM_STORAGE_IDS[]{
|
|||||||
NcmStorageId_SdCard,
|
NcmStorageId_SdCard,
|
||||||
};
|
};
|
||||||
|
|
||||||
// custom allocator for std::vector that respects alignment.
|
|
||||||
// https://en.cppreference.com/w/cpp/named_req/Allocator
|
|
||||||
template <typename T, std::size_t Align>
|
|
||||||
struct CustomVectorAllocator {
|
|
||||||
public:
|
|
||||||
// https://en.cppreference.com/w/cpp/memory/new/operator_new
|
|
||||||
auto allocate(std::size_t n) -> T* {
|
|
||||||
// log_write("allocating ptr size: %zu\n", n);
|
|
||||||
return new(align) T[n];
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://en.cppreference.com/w/cpp/memory/new/operator_delete
|
|
||||||
auto deallocate(T* p, std::size_t n) noexcept -> void {
|
|
||||||
// log_write("deleting ptr size: %zu\n", n);
|
|
||||||
::operator delete[] (p, n, align);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static constexpr inline std::align_val_t align{Align};
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct PageAllocator : CustomVectorAllocator<T, 0x1000> {
|
|
||||||
using value_type = T; // used by std::vector
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T, class U>
|
|
||||||
bool operator==(const PageAllocator <T>&, const PageAllocator <U>&) { return true; }
|
|
||||||
|
|
||||||
using PageAlignedVector = std::vector<u8, PageAllocator<u8>>;
|
|
||||||
|
|
||||||
constexpr u32 KEYGEN_LIMIT = 0x20;
|
constexpr u32 KEYGEN_LIMIT = 0x20;
|
||||||
|
|
||||||
struct NcaCollection : container::CollectionEntry {
|
struct NcaCollection : container::CollectionEntry {
|
||||||
|
nca::Header header{};
|
||||||
// NcmContentType
|
// NcmContentType
|
||||||
u8 type{};
|
u8 type{};
|
||||||
NcmContentId content_id{};
|
NcmContentId content_id{};
|
||||||
@@ -72,6 +41,8 @@ struct NcaCollection : container::CollectionEntry {
|
|||||||
u8 hash[SHA256_HASH_SIZE]{};
|
u8 hash[SHA256_HASH_SIZE]{};
|
||||||
// set true if nca has been modified.
|
// set true if nca has been modified.
|
||||||
bool modified{};
|
bool modified{};
|
||||||
|
// set if the nca was not installed.
|
||||||
|
bool skipped{};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CnmtCollection : NcaCollection {
|
struct CnmtCollection : NcaCollection {
|
||||||
@@ -81,7 +52,7 @@ struct CnmtCollection : NcaCollection {
|
|||||||
// if set, the ticket / cert will be installed once all nca's have installed.
|
// if set, the ticket / cert will be installed once all nca's have installed.
|
||||||
std::vector<FsRightsId> rights_id{};
|
std::vector<FsRightsId> rights_id{};
|
||||||
|
|
||||||
NcmContentMetaHeader header{};
|
NcmContentMetaHeader meta_header{};
|
||||||
NcmContentMetaKey key{};
|
NcmContentMetaKey key{};
|
||||||
NcmContentInfo content_info{};
|
NcmContentInfo content_info{};
|
||||||
std::vector<u8> extended_header{};
|
std::vector<u8> extended_header{};
|
||||||
@@ -107,7 +78,7 @@ struct ThreadBuffer {
|
|||||||
buf.reserve(INFLATE_BUFFER_MAX);
|
buf.reserve(INFLATE_BUFFER_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
PageAlignedVector buf;
|
std::vector<u8> buf;
|
||||||
s64 off;
|
s64 off;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -137,7 +108,7 @@ public:
|
|||||||
return ringbuf_capacity() - ringbuf_size();
|
return ringbuf_capacity() - ringbuf_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ringbuf_push(PageAlignedVector& buf_in, s64 off_in) {
|
void ringbuf_push(std::vector<u8>& buf_in, s64 off_in) {
|
||||||
auto& value = this->buf[this->w_index % ringbuf_capacity()];
|
auto& value = this->buf[this->w_index % ringbuf_capacity()];
|
||||||
value.off = off_in;
|
value.off = off_in;
|
||||||
std::swap(value.buf, buf_in);
|
std::swap(value.buf, buf_in);
|
||||||
@@ -145,7 +116,7 @@ public:
|
|||||||
this->w_index = (this->w_index + 1U) % (ringbuf_capacity() * 2U);
|
this->w_index = (this->w_index + 1U) % (ringbuf_capacity() * 2U);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ringbuf_pop(PageAlignedVector& buf_out, s64& off_out) {
|
void ringbuf_pop(std::vector<u8>& buf_out, s64& off_out) {
|
||||||
auto& value = this->buf[this->r_index % ringbuf_capacity()];
|
auto& value = this->buf[this->r_index % ringbuf_capacity()];
|
||||||
off_out = value.off;
|
off_out = value.off;
|
||||||
std::swap(value.buf, buf_out);
|
std::swap(value.buf, buf_out);
|
||||||
@@ -178,7 +149,7 @@ struct ThreadData {
|
|||||||
|
|
||||||
Result Read(void* buf, s64 size, u64* bytes_read);
|
Result Read(void* buf, s64 size, u64* bytes_read);
|
||||||
|
|
||||||
Result SetDecompressBuf(PageAlignedVector& buf, s64 off, s64 size) {
|
Result SetDecompressBuf(std::vector<u8>& buf, s64 off, s64 size) {
|
||||||
buf.resize(size);
|
buf.resize(size);
|
||||||
|
|
||||||
mutexLock(std::addressof(read_mutex));
|
mutexLock(std::addressof(read_mutex));
|
||||||
@@ -192,7 +163,7 @@ struct ThreadData {
|
|||||||
return condvarWakeOne(std::addressof(can_decompress));
|
return condvarWakeOne(std::addressof(can_decompress));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result GetDecompressBuf(PageAlignedVector& buf_out, s64& off_out) {
|
Result GetDecompressBuf(std::vector<u8>& buf_out, s64& off_out) {
|
||||||
mutexLock(std::addressof(read_mutex));
|
mutexLock(std::addressof(read_mutex));
|
||||||
if (!read_buffers.ringbuf_size()) {
|
if (!read_buffers.ringbuf_size()) {
|
||||||
R_TRY(condvarWait(std::addressof(can_decompress), std::addressof(read_mutex)));
|
R_TRY(condvarWait(std::addressof(can_decompress), std::addressof(read_mutex)));
|
||||||
@@ -204,7 +175,7 @@ struct ThreadData {
|
|||||||
return condvarWakeOne(std::addressof(can_read));
|
return condvarWakeOne(std::addressof(can_read));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SetWriteBuf(PageAlignedVector& buf, s64 size, bool skip_verify) {
|
Result SetWriteBuf(std::vector<u8>& buf, s64 size, bool skip_verify) {
|
||||||
buf.resize(size);
|
buf.resize(size);
|
||||||
if (!skip_verify) {
|
if (!skip_verify) {
|
||||||
sha256ContextUpdate(std::addressof(sha256), buf.data(), buf.size());
|
sha256ContextUpdate(std::addressof(sha256), buf.data(), buf.size());
|
||||||
@@ -221,7 +192,7 @@ struct ThreadData {
|
|||||||
return condvarWakeOne(std::addressof(can_write));
|
return condvarWakeOne(std::addressof(can_write));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result GetWriteBuf(PageAlignedVector& buf_out, s64& off_out) {
|
Result GetWriteBuf(std::vector<u8>& buf_out, s64& off_out) {
|
||||||
mutexLock(std::addressof(write_mutex));
|
mutexLock(std::addressof(write_mutex));
|
||||||
if (!write_buffers.ringbuf_size()) {
|
if (!write_buffers.ringbuf_size()) {
|
||||||
R_TRY(condvarWait(std::addressof(can_write), std::addressof(write_mutex)));
|
R_TRY(condvarWait(std::addressof(can_write), std::addressof(write_mutex)));
|
||||||
@@ -274,10 +245,10 @@ struct Yati {
|
|||||||
Yati(ui::ProgressBox*, std::shared_ptr<source::Base>);
|
Yati(ui::ProgressBox*, std::shared_ptr<source::Base>);
|
||||||
~Yati();
|
~Yati();
|
||||||
|
|
||||||
Result Setup();
|
Result Setup(const ConfigOverride& override);
|
||||||
Result InstallNca(std::span<TikCollection> tickets, NcaCollection& nca);
|
Result InstallNca(std::span<TikCollection> tickets, NcaCollection& nca);
|
||||||
|
Result InstallNcaInternal(std::span<TikCollection> tickets, NcaCollection& nca);
|
||||||
Result InstallCnmtNca(std::span<TikCollection> tickets, CnmtCollection& cnmt, const container::Collections& collections);
|
Result InstallCnmtNca(std::span<TikCollection> tickets, CnmtCollection& cnmt, const container::Collections& collections);
|
||||||
Result InstallControlNca(std::span<TikCollection> tickets, const CnmtCollection& cnmt, NcaCollection& nca);
|
|
||||||
|
|
||||||
Result readFuncInternal(ThreadData* t);
|
Result readFuncInternal(ThreadData* t);
|
||||||
Result decompressFuncInternal(ThreadData* t);
|
Result decompressFuncInternal(ThreadData* t);
|
||||||
@@ -361,11 +332,11 @@ HashStr hexIdToStr(auto id) {
|
|||||||
// parsing ncz headers, sections and reading ncz blocks
|
// parsing ncz headers, sections and reading ncz blocks
|
||||||
Result Yati::readFuncInternal(ThreadData* t) {
|
Result Yati::readFuncInternal(ThreadData* t) {
|
||||||
// the main buffer which data is read into.
|
// the main buffer which data is read into.
|
||||||
PageAlignedVector buf;
|
std::vector<u8> buf;
|
||||||
// workaround ncz block reading ahead. if block isn't found, we usually
|
// workaround ncz block reading ahead. if block isn't found, we usually
|
||||||
// would seek back to the offset, however this is not possible in stream
|
// would seek back to the offset, however this is not possible in stream
|
||||||
// mode, so we instead store the data to the temp buffer and pre-pend it.
|
// mode, so we instead store the data to the temp buffer and pre-pend it.
|
||||||
PageAlignedVector temp_buf;
|
std::vector<u8> temp_buf;
|
||||||
buf.reserve(t->max_buffer_size);
|
buf.reserve(t->max_buffer_size);
|
||||||
temp_buf.reserve(t->max_buffer_size);
|
temp_buf.reserve(t->max_buffer_size);
|
||||||
|
|
||||||
@@ -453,12 +424,12 @@ Result Yati::decompressFuncInternal(ThreadData* t) {
|
|||||||
|
|
||||||
s64 inflate_offset{};
|
s64 inflate_offset{};
|
||||||
Aes128CtrContext ctx{};
|
Aes128CtrContext ctx{};
|
||||||
PageAlignedVector inflate_buf{};
|
std::vector<u8> inflate_buf{};
|
||||||
inflate_buf.reserve(t->max_buffer_size);
|
inflate_buf.reserve(t->max_buffer_size);
|
||||||
|
|
||||||
s64 written{};
|
s64 written{};
|
||||||
s64 decompress_buf_off{};
|
s64 decompress_buf_off{};
|
||||||
PageAlignedVector buf{};
|
std::vector<u8> buf{};
|
||||||
buf.reserve(t->max_buffer_size);
|
buf.reserve(t->max_buffer_size);
|
||||||
|
|
||||||
// encrypts the nca and passes the buffer to the write thread.
|
// encrypts the nca and passes the buffer to the write thread.
|
||||||
@@ -471,7 +442,7 @@ Result Yati::decompressFuncInternal(ThreadData* t) {
|
|||||||
// the remaining data.
|
// the remaining data.
|
||||||
// rather that copying the entire vector to the write thread,
|
// rather that copying the entire vector to the write thread,
|
||||||
// only copy (store) the remaining amount.
|
// only copy (store) the remaining amount.
|
||||||
PageAlignedVector temp_vector{};
|
std::vector<u8> temp_vector{};
|
||||||
if (size < inflate_offset) {
|
if (size < inflate_offset) {
|
||||||
temp_vector.resize(inflate_offset - size);
|
temp_vector.resize(inflate_offset - size);
|
||||||
std::memcpy(temp_vector.data(), inflate_buf.data() + size, temp_vector.size());
|
std::memcpy(temp_vector.data(), inflate_buf.data() + size, temp_vector.size());
|
||||||
@@ -538,6 +509,9 @@ Result Yati::decompressFuncInternal(ThreadData* t) {
|
|||||||
R_UNLESS(header.magic == 0x3341434E, Result_InvalidNcaMagic);
|
R_UNLESS(header.magic == 0x3341434E, Result_InvalidNcaMagic);
|
||||||
log_write("nca magic is ok! type: %u\n", header.content_type);
|
log_write("nca magic is ok! type: %u\n", header.content_type);
|
||||||
|
|
||||||
|
// store the unmodified header.
|
||||||
|
t->nca->header = header;
|
||||||
|
|
||||||
if (!config.skip_rsa_header_fixed_key_verify) {
|
if (!config.skip_rsa_header_fixed_key_verify) {
|
||||||
log_write("verifying nca fixed key\n");
|
log_write("verifying nca fixed key\n");
|
||||||
R_TRY(nca::VerifyFixedKey(header));
|
R_TRY(nca::VerifyFixedKey(header));
|
||||||
@@ -549,14 +523,14 @@ Result Yati::decompressFuncInternal(ThreadData* t) {
|
|||||||
t->write_size = header.size;
|
t->write_size = header.size;
|
||||||
R_TRY(ncmContentStorageSetPlaceHolderSize(std::addressof(cs), std::addressof(t->nca->placeholder_id), header.size));
|
R_TRY(ncmContentStorageSetPlaceHolderSize(std::addressof(cs), std::addressof(t->nca->placeholder_id), header.size));
|
||||||
|
|
||||||
if (header.distribution_type == nca::DistributionType_GameCard) {
|
if (!config.ignore_distribution_bit && header.distribution_type == nca::DistributionType_GameCard) {
|
||||||
header.distribution_type = nca::DistributionType_System;
|
header.distribution_type = nca::DistributionType_System;
|
||||||
t->nca->modified = true;
|
t->nca->modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TikCollection* ticket = nullptr;
|
TikCollection* ticket = nullptr;
|
||||||
if (isRightsIdValid(header.rights_id)) {
|
if (isRightsIdValid(header.rights_id)) {
|
||||||
auto it = std::find_if(t->tik.begin(), t->tik.end(), [header](auto& e){
|
auto it = std::find_if(t->tik.begin(), t->tik.end(), [&header](auto& e){
|
||||||
return !std::memcmp(&header.rights_id, &e.rights_id, sizeof(e.rights_id));
|
return !std::memcmp(&header.rights_id, &e.rights_id, sizeof(e.rights_id));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -709,7 +683,7 @@ Result Yati::decompressFuncInternal(ThreadData* t) {
|
|||||||
|
|
||||||
// write thread writes data to the nca placeholder.
|
// write thread writes data to the nca placeholder.
|
||||||
Result Yati::writeFuncInternal(ThreadData* t) {
|
Result Yati::writeFuncInternal(ThreadData* t) {
|
||||||
PageAlignedVector buf;
|
std::vector<u8> buf;
|
||||||
buf.reserve(t->max_buffer_size);
|
buf.reserve(t->max_buffer_size);
|
||||||
|
|
||||||
while (t->write_offset < t->write_size && R_SUCCEEDED(t->GetResults())) {
|
while (t->write_offset < t->write_size && R_SUCCEEDED(t->GetResults())) {
|
||||||
@@ -790,10 +764,15 @@ Yati::~Yati() {
|
|||||||
|
|
||||||
serviceClose(std::addressof(es));
|
serviceClose(std::addressof(es));
|
||||||
appletSetMediaPlaybackState(false);
|
appletSetMediaPlaybackState(false);
|
||||||
|
|
||||||
|
if (config.boost_mode) {
|
||||||
|
appletSetCpuBoostMode(ApmCpuBoostMode_Normal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Yati::Setup() {
|
Result Yati::Setup(const ConfigOverride& override) {
|
||||||
config.sd_card_install = App::GetApp()->m_install_sd.Get();
|
config.sd_card_install = override.sd_card_install.value_or(App::GetApp()->m_install_sd.Get());
|
||||||
|
config.boost_mode = App::GetApp()->m_boost_mode.Get();
|
||||||
config.allow_downgrade = App::GetApp()->m_allow_downgrade.Get();
|
config.allow_downgrade = App::GetApp()->m_allow_downgrade.Get();
|
||||||
config.skip_if_already_installed = App::GetApp()->m_skip_if_already_installed.Get();
|
config.skip_if_already_installed = App::GetApp()->m_skip_if_already_installed.Get();
|
||||||
config.ticket_only = App::GetApp()->m_ticket_only.Get();
|
config.ticket_only = App::GetApp()->m_ticket_only.Get();
|
||||||
@@ -802,15 +781,19 @@ Result Yati::Setup() {
|
|||||||
config.skip_addon = App::GetApp()->m_skip_addon.Get();
|
config.skip_addon = App::GetApp()->m_skip_addon.Get();
|
||||||
config.skip_data_patch = App::GetApp()->m_skip_data_patch.Get();
|
config.skip_data_patch = App::GetApp()->m_skip_data_patch.Get();
|
||||||
config.skip_ticket = App::GetApp()->m_skip_ticket.Get();
|
config.skip_ticket = App::GetApp()->m_skip_ticket.Get();
|
||||||
config.skip_nca_hash_verify = App::GetApp()->m_skip_nca_hash_verify.Get();
|
config.skip_nca_hash_verify = override.skip_nca_hash_verify.value_or(App::GetApp()->m_skip_nca_hash_verify.Get());
|
||||||
config.skip_rsa_header_fixed_key_verify = App::GetApp()->m_skip_rsa_header_fixed_key_verify.Get();
|
config.skip_rsa_header_fixed_key_verify = override.skip_rsa_header_fixed_key_verify.value_or(App::GetApp()->m_skip_rsa_header_fixed_key_verify.Get());
|
||||||
config.skip_rsa_npdm_fixed_key_verify = App::GetApp()->m_skip_rsa_npdm_fixed_key_verify.Get();
|
config.skip_rsa_npdm_fixed_key_verify = override.skip_rsa_npdm_fixed_key_verify.value_or(App::GetApp()->m_skip_rsa_npdm_fixed_key_verify.Get());
|
||||||
config.ignore_distribution_bit = App::GetApp()->m_ignore_distribution_bit.Get();
|
config.ignore_distribution_bit = override.ignore_distribution_bit.value_or(App::GetApp()->m_ignore_distribution_bit.Get());
|
||||||
config.convert_to_standard_crypto = App::GetApp()->m_convert_to_standard_crypto.Get();
|
config.convert_to_standard_crypto = override.convert_to_standard_crypto.value_or(App::GetApp()->m_convert_to_standard_crypto.Get());
|
||||||
config.lower_master_key = App::GetApp()->m_lower_master_key.Get();
|
config.lower_master_key = override.lower_master_key.value_or(App::GetApp()->m_lower_master_key.Get());
|
||||||
config.lower_system_version = App::GetApp()->m_lower_system_version.Get();
|
config.lower_system_version = override.lower_system_version.value_or(App::GetApp()->m_lower_system_version.Get());
|
||||||
storage_id = config.sd_card_install ? NcmStorageId_SdCard : NcmStorageId_BuiltInUser;
|
storage_id = config.sd_card_install ? NcmStorageId_SdCard : NcmStorageId_BuiltInUser;
|
||||||
|
|
||||||
|
if (config.boost_mode) {
|
||||||
|
appletSetCpuBoostMode(ApmCpuBoostMode_FastLoad);
|
||||||
|
}
|
||||||
|
|
||||||
R_TRY(source->GetOpenResult());
|
R_TRY(source->GetOpenResult());
|
||||||
R_TRY(splCryptoInitialize());
|
R_TRY(splCryptoInitialize());
|
||||||
R_TRY(nsInitialize());
|
R_TRY(nsInitialize());
|
||||||
@@ -829,10 +812,17 @@ Result Yati::Setup() {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Yati::InstallNca(std::span<TikCollection> tickets, NcaCollection& nca) {
|
Result Yati::InstallNcaInternal(std::span<TikCollection> tickets, NcaCollection& nca) {
|
||||||
log_write("in install nca\n");
|
if (config.skip_if_already_installed) {
|
||||||
pbox->NewTransfer(nca.name);
|
R_TRY(ncmContentStorageHas(std::addressof(cs), std::addressof(nca.skipped), std::addressof(nca.content_id)));
|
||||||
keys::parse_hex_key(std::addressof(nca.content_id), nca.name.c_str());
|
if (nca.skipped) {
|
||||||
|
log_write("\tskipped nca as it's already installed ncmContentStorageHas()\n");
|
||||||
|
R_TRY(ncmContentStorageReadContentIdFile(std::addressof(cs), std::addressof(nca.header), sizeof(nca.header), std::addressof(nca.content_id), 0));
|
||||||
|
crypto::cryptoAes128Xts(std::addressof(nca.header), std::addressof(nca.header), keys.header_key, 0, 0x200, sizeof(nca.header), false);
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log_write("generateing placeholder\n");
|
log_write("generateing placeholder\n");
|
||||||
R_TRY(ncmContentStorageGeneratePlaceHolderId(std::addressof(cs), std::addressof(nca.placeholder_id)));
|
R_TRY(ncmContentStorageGeneratePlaceHolderId(std::addressof(cs), std::addressof(nca.placeholder_id)));
|
||||||
log_write("creating placeholder\n");
|
log_write("creating placeholder\n");
|
||||||
@@ -918,67 +908,71 @@ Result Yati::InstallNca(std::span<TikCollection> tickets, NcaCollection& nca) {
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result Yati::InstallNca(std::span<TikCollection> tickets, NcaCollection& nca) {
|
||||||
|
log_write("in install nca\n");
|
||||||
|
pbox->NewTransfer(nca.name);
|
||||||
|
keys::parse_hex_key(std::addressof(nca.content_id), nca.name.c_str());
|
||||||
|
|
||||||
|
R_TRY(InstallNcaInternal(tickets, nca));
|
||||||
|
|
||||||
|
fs::FsPath path;
|
||||||
|
if (nca.skipped) {
|
||||||
|
R_TRY(ncmContentStorageGetPath(std::addressof(cs), path, sizeof(path), std::addressof(nca.content_id)));
|
||||||
|
} else {
|
||||||
|
R_TRY(ncmContentStorageFlushPlaceHolder(std::addressof(cs)));
|
||||||
|
R_TRY(ncmContentStorageGetPlaceHolderPath(std::addressof(cs), path, sizeof(path), std::addressof(nca.placeholder_id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nca.header.content_type == nca::ContentType_Program) {
|
||||||
|
// todo: verify npdm key.
|
||||||
|
} else if (nca.header.content_type == nca::ContentType_Control) {
|
||||||
|
NacpLanguageEntry entry;
|
||||||
|
std::vector<u8> icon;
|
||||||
|
R_TRY(yati::ParseControlNca(path, nca.header.program_id, &entry, sizeof(entry), &icon));
|
||||||
|
pbox->SetTitle(entry.name).SetImageData(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
Result Yati::InstallCnmtNca(std::span<TikCollection> tickets, CnmtCollection& cnmt, const container::Collections& collections) {
|
Result Yati::InstallCnmtNca(std::span<TikCollection> tickets, CnmtCollection& cnmt, const container::Collections& collections) {
|
||||||
R_TRY(InstallNca(tickets, cnmt));
|
R_TRY(InstallNca(tickets, cnmt));
|
||||||
|
|
||||||
fs::FsPath path;
|
fs::FsPath path;
|
||||||
R_TRY(ncmContentStorageFlushPlaceHolder(std::addressof(cs)));
|
if (cnmt.skipped) {
|
||||||
R_TRY(ncmContentStorageGetPlaceHolderPath(std::addressof(cs), path, sizeof(path), std::addressof(cnmt.placeholder_id)));
|
R_TRY(ncmContentStorageGetPath(std::addressof(cs), path, sizeof(path), std::addressof(cnmt.content_id)));
|
||||||
|
} else {
|
||||||
|
R_TRY(ncmContentStorageFlushPlaceHolder(std::addressof(cs)));
|
||||||
|
R_TRY(ncmContentStorageGetPlaceHolderPath(std::addressof(cs), path, sizeof(path), std::addressof(cnmt.placeholder_id)));
|
||||||
|
}
|
||||||
|
|
||||||
FsFileSystem fs;
|
|
||||||
R_TRY(fsOpenFileSystem(std::addressof(fs), FsFileSystemType_ContentMeta, path));
|
|
||||||
ON_SCOPE_EXIT(fsFsClose(std::addressof(fs)));
|
|
||||||
|
|
||||||
FsDir dir;
|
|
||||||
R_TRY(fsFsOpenDirectory(std::addressof(fs), fs::FsPath{"/"}, FsDirOpenMode_ReadFiles, std::addressof(dir)));
|
|
||||||
ON_SCOPE_EXIT(fsDirClose(std::addressof(dir)));
|
|
||||||
|
|
||||||
s64 total_entries;
|
|
||||||
FsDirectoryEntry buf;
|
|
||||||
R_TRY(fsDirRead(std::addressof(dir), std::addressof(total_entries), 1, std::addressof(buf)));
|
|
||||||
|
|
||||||
FsFile file;
|
|
||||||
R_TRY(fsFsOpenFile(std::addressof(fs), fs::AppendPath("/", buf.name), FsOpenMode_Read, std::addressof(file)));
|
|
||||||
ON_SCOPE_EXIT(fsFileClose(std::addressof(file)));
|
|
||||||
|
|
||||||
s64 offset{};
|
|
||||||
u64 bytes_read;
|
|
||||||
ncm::PackagedContentMeta header;
|
ncm::PackagedContentMeta header;
|
||||||
R_TRY(fsFileRead(std::addressof(file), offset, std::addressof(header), sizeof(header), 0, std::addressof(bytes_read)));
|
std::vector<NcmPackagedContentInfo> infos;
|
||||||
offset += bytes_read;
|
R_TRY(ParseCnmtNca(path, cnmt.header.program_id, header, cnmt.extended_header, infos));
|
||||||
|
|
||||||
// read extended header
|
for (const auto& packed_info : infos) {
|
||||||
cnmt.extended_header.resize(header.meta_header.extended_header_size);
|
const auto& info = packed_info.info;
|
||||||
R_TRY(fsFileRead(std::addressof(file), offset, cnmt.extended_header.data(), cnmt.extended_header.size(), 0, std::addressof(bytes_read)));
|
if (info.content_type == NcmContentType_DeltaFragment) {
|
||||||
offset += bytes_read;
|
|
||||||
|
|
||||||
// read infos.
|
|
||||||
std::vector<NcmPackagedContentInfo> infos(header.meta_header.content_count);
|
|
||||||
R_TRY(fsFileRead(std::addressof(file), offset, infos.data(), infos.size() * sizeof(NcmPackagedContentInfo), 0, std::addressof(bytes_read)));
|
|
||||||
offset += bytes_read;
|
|
||||||
|
|
||||||
for (const auto& info : infos) {
|
|
||||||
if (info.info.content_type == NcmContentType_DeltaFragment) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto str = hexIdToStr(info.info.content_id);
|
const auto str = hexIdToStr(info.content_id);
|
||||||
const auto it = std::find_if(collections.cbegin(), collections.cend(), [str](auto& e){
|
const auto it = std::find_if(collections.cbegin(), collections.cend(), [&str](auto& e){
|
||||||
return e.name.find(str.str) != e.name.npos;
|
return e.name.find(str.str) != e.name.npos;
|
||||||
});
|
});
|
||||||
|
|
||||||
R_UNLESS(it != collections.cend(), Result_NcaNotFound);
|
R_UNLESS(it != collections.cend(), Result_NcaNotFound);
|
||||||
|
|
||||||
log_write("found: %s\n", str.str);
|
log_write("found: %s\n", str.str);
|
||||||
cnmt.infos.emplace_back(info);
|
cnmt.infos.emplace_back(packed_info);
|
||||||
auto& nca = cnmt.ncas.emplace_back(*it);
|
auto& nca = cnmt.ncas.emplace_back(*it);
|
||||||
nca.type = info.info.content_type;
|
nca.type = info.content_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update header
|
// update header
|
||||||
cnmt.header = header.meta_header;
|
cnmt.meta_header = header.meta_header;
|
||||||
cnmt.header.content_count = cnmt.infos.size() + 1;
|
cnmt.meta_header.content_count = cnmt.infos.size() + 1;
|
||||||
cnmt.header.storage_id = 0;
|
cnmt.meta_header.storage_id = 0;
|
||||||
|
|
||||||
cnmt.key.id = header.title_id;
|
cnmt.key.id = header.title_id;
|
||||||
cnmt.key.version = header.title_version;
|
cnmt.key.version = header.title_version;
|
||||||
@@ -1013,32 +1007,6 @@ Result Yati::InstallCnmtNca(std::span<TikCollection> tickets, CnmtCollection& cn
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Yati::InstallControlNca(std::span<TikCollection> tickets, const CnmtCollection& cnmt, NcaCollection& nca) {
|
|
||||||
R_TRY(InstallNca(tickets, nca));
|
|
||||||
|
|
||||||
fs::FsPath path;
|
|
||||||
R_TRY(ncmContentStorageFlushPlaceHolder(std::addressof(cs)));
|
|
||||||
R_TRY(ncmContentStorageGetPlaceHolderPath(std::addressof(cs), path, sizeof(path), std::addressof(nca.placeholder_id)));
|
|
||||||
|
|
||||||
log_write("got control path: %s\n", path.s);
|
|
||||||
FsFileSystem fs;
|
|
||||||
R_TRY(fsOpenFileSystemWithId(std::addressof(fs), ncm::GetAppId(cnmt.key), FsFileSystemType_ContentControl, path, FsContentAttributes_All));
|
|
||||||
ON_SCOPE_EXIT(fsFsClose(std::addressof(fs)));
|
|
||||||
log_write("opened control path fs: %s\n", path.s);
|
|
||||||
|
|
||||||
FsFile file;
|
|
||||||
R_TRY(fsFsOpenFile(std::addressof(fs), fs::FsPath{"/control.nacp"}, FsOpenMode_Read, std::addressof(file)));
|
|
||||||
ON_SCOPE_EXIT(fsFileClose(std::addressof(file)));
|
|
||||||
log_write("got control path file: %s\n", path.s);
|
|
||||||
|
|
||||||
NacpLanguageEntry entry;
|
|
||||||
u64 bytes_read;
|
|
||||||
R_TRY(fsFileRead(&file, 0, &entry, sizeof(entry), 0, &bytes_read));
|
|
||||||
pbox->SetTitle("Installing "_i18n + entry.name);
|
|
||||||
|
|
||||||
R_SUCCEED();
|
|
||||||
}
|
|
||||||
|
|
||||||
Result Yati::ParseTicketsIntoCollection(std::vector<TikCollection>& tickets, const container::Collections& collections, bool read_data) {
|
Result Yati::ParseTicketsIntoCollection(std::vector<TikCollection>& tickets, const container::Collections& collections, bool read_data) {
|
||||||
for (const auto& collection : collections) {
|
for (const auto& collection : collections) {
|
||||||
if (collection.name.ends_with(".tik")) {
|
if (collection.name.ends_with(".tik")) {
|
||||||
@@ -1046,7 +1014,7 @@ Result Yati::ParseTicketsIntoCollection(std::vector<TikCollection>& tickets, con
|
|||||||
keys::parse_hex_key(entry.rights_id.c, collection.name.c_str());
|
keys::parse_hex_key(entry.rights_id.c, collection.name.c_str());
|
||||||
const auto str = collection.name.substr(0, collection.name.length() - 4) + ".cert";
|
const auto str = collection.name.substr(0, collection.name.length() - 4) + ".cert";
|
||||||
|
|
||||||
const auto cert = std::find_if(collections.cbegin(), collections.cend(), [str](auto& e){
|
const auto cert = std::find_if(collections.cbegin(), collections.cend(), [&str](auto& e){
|
||||||
return e.name.find(str) != e.name.npos;
|
return e.name.find(str) != e.name.npos;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1070,41 +1038,37 @@ Result Yati::ParseTicketsIntoCollection(std::vector<TikCollection>& tickets, con
|
|||||||
|
|
||||||
Result Yati::GetLatestVersion(const CnmtCollection& cnmt, u32& version_out, bool& skip) {
|
Result Yati::GetLatestVersion(const CnmtCollection& cnmt, u32& version_out, bool& skip) {
|
||||||
const auto app_id = ncm::GetAppId(cnmt.key);
|
const auto app_id = ncm::GetAppId(cnmt.key);
|
||||||
|
|
||||||
bool has_records;
|
|
||||||
R_TRY(nsIsAnyApplicationEntityInstalled(app_id, &has_records));
|
|
||||||
|
|
||||||
// TODO: fix this when gamecard is inserted as it will only return records
|
|
||||||
// for the gamecard...
|
|
||||||
// may have to use ncm directly to get the keys, then parse that.
|
|
||||||
version_out = cnmt.key.version;
|
version_out = cnmt.key.version;
|
||||||
if (has_records) {
|
|
||||||
s32 meta_count{};
|
|
||||||
R_TRY(nsCountApplicationContentMeta(app_id, &meta_count));
|
|
||||||
R_UNLESS(meta_count > 0, 0x1);
|
|
||||||
|
|
||||||
std::vector<ncm::ContentStorageRecord> records(meta_count);
|
for (auto& db : ncm_db) {
|
||||||
s32 count;
|
s32 db_list_total;
|
||||||
R_TRY(ns::ListApplicationRecordContentMeta(std::addressof(ns_app), 0, app_id, records.data(), records.size(), &count));
|
s32 db_list_count;
|
||||||
R_UNLESS(count == records.size(), 0x1);
|
std::vector<NcmContentMetaKey> keys(1);
|
||||||
|
if (R_SUCCEEDED(ncmContentMetaDatabaseList(std::addressof(db), std::addressof(db_list_total), std::addressof(db_list_count), keys.data(), keys.size(), NcmContentMetaType_Unknown, app_id, 0, UINT64_MAX, NcmContentInstallType_Full))) {
|
||||||
for (auto& record : records) {
|
if (db_list_total != keys.size()) {
|
||||||
log_write("found record: 0x%016lX type: %u version: %u\n", record.key.id, record.key.type, record.key.version);
|
keys.resize(db_list_total);
|
||||||
log_write("cnmt record: 0x%016lX type: %u version: %u\n", cnmt.key.id, cnmt.key.type, cnmt.key.version);
|
if (keys.size()) {
|
||||||
|
R_TRY(ncmContentMetaDatabaseList(std::addressof(db), std::addressof(db_list_total), std::addressof(db_list_count), keys.data(), keys.size(), NcmContentMetaType_Unknown, app_id, 0, UINT64_MAX, NcmContentInstallType_Full));
|
||||||
if (record.key.id == cnmt.key.id && cnmt.key.version == record.key.version && config.skip_if_already_installed) {
|
}
|
||||||
log_write("skipping as already installed\n");
|
|
||||||
skip = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we are downgrading
|
for (auto& key : keys) {
|
||||||
if (cnmt.key.type == NcmContentMetaType_Patch) {
|
log_write("found record: %016lX type: %u version: %u\n", key.id, key.type, key.version);
|
||||||
if (cnmt.key.type == record.key.type && cnmt.key.version < record.key.version && !config.allow_downgrade) {
|
|
||||||
log_write("skipping due to it being lower\n");
|
if (key.id == cnmt.key.id && cnmt.key.version == key.version && config.skip_if_already_installed) {
|
||||||
|
log_write("skipping as already installed\n");
|
||||||
skip = true;
|
skip = true;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
version_out = std::max(version_out, record.key.version);
|
// check if we are downgrading
|
||||||
|
if (cnmt.key.type == NcmContentMetaType_Patch) {
|
||||||
|
if (cnmt.key.type == key.type && cnmt.key.version < key.version && !config.allow_downgrade) {
|
||||||
|
log_write("skipping due to it being lower\n");
|
||||||
|
skip = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
version_out = std::max(version_out, key.version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1129,6 +1093,13 @@ Result Yati::ShouldSkip(const CnmtCollection& cnmt, bool& skip) {
|
|||||||
} else if (config.skip_data_patch && cnmt.key.type == NcmContentMetaType_DataPatch) {
|
} else if (config.skip_data_patch && cnmt.key.type == NcmContentMetaType_DataPatch) {
|
||||||
log_write("\tskipping: [NcmContentMetaType_DataPatch]\n");
|
log_write("\tskipping: [NcmContentMetaType_DataPatch]\n");
|
||||||
skip = true;
|
skip = true;
|
||||||
|
} else if (config.skip_if_already_installed) {
|
||||||
|
bool has;
|
||||||
|
R_TRY(ncmContentMetaDatabaseHas(std::addressof(db), std::addressof(has), std::addressof(cnmt.key)));
|
||||||
|
if (has) {
|
||||||
|
log_write("\tskipping: [ncmContentMetaDatabaseHas()]\n");
|
||||||
|
skip = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
@@ -1160,7 +1131,6 @@ Result Yati::RemoveInstalledNcas(const CnmtCollection& cnmt) {
|
|||||||
s32 db_list_count;
|
s32 db_list_count;
|
||||||
u64 id_min = cnmt.key.id;
|
u64 id_min = cnmt.key.id;
|
||||||
u64 id_max = cnmt.key.id;
|
u64 id_max = cnmt.key.id;
|
||||||
std::vector<NcmContentMetaKey> keys(1);
|
|
||||||
|
|
||||||
// if installing a patch, remove all previously installed patches.
|
// if installing a patch, remove all previously installed patches.
|
||||||
if (cnmt.key.type == NcmContentMetaType_Patch) {
|
if (cnmt.key.type == NcmContentMetaType_Patch) {
|
||||||
@@ -1222,7 +1192,7 @@ Result Yati::RegisterNcasAndPushRecord(const CnmtCollection& cnmt, u32 latest_ve
|
|||||||
log_write("registered cnmt nca\n");
|
log_write("registered cnmt nca\n");
|
||||||
|
|
||||||
for (auto& nca : cnmt.ncas) {
|
for (auto& nca : cnmt.ncas) {
|
||||||
if (nca.type != NcmContentType_DeltaFragment) {
|
if (!nca.skipped && nca.type != NcmContentType_DeltaFragment) {
|
||||||
log_write("registering nca: %s\n", nca.name.c_str());
|
log_write("registering nca: %s\n", nca.name.c_str());
|
||||||
R_TRY(ncm::Register(std::addressof(cs), std::addressof(nca.content_id), std::addressof(nca.placeholder_id)));
|
R_TRY(ncm::Register(std::addressof(cs), std::addressof(nca.content_id), std::addressof(nca.placeholder_id)));
|
||||||
log_write("registered nca: %s\n", nca.name.c_str());
|
log_write("registered nca: %s\n", nca.name.c_str());
|
||||||
@@ -1233,7 +1203,7 @@ Result Yati::RegisterNcasAndPushRecord(const CnmtCollection& cnmt, u32 latest_ve
|
|||||||
|
|
||||||
// build ncm meta and push to the database.
|
// build ncm meta and push to the database.
|
||||||
BufHelper buf{};
|
BufHelper buf{};
|
||||||
buf.write(std::addressof(cnmt.header), sizeof(cnmt.header));
|
buf.write(std::addressof(cnmt.meta_header), sizeof(cnmt.meta_header));
|
||||||
buf.write(cnmt.extended_header.data(), cnmt.extended_header.size());
|
buf.write(cnmt.extended_header.data(), cnmt.extended_header.size());
|
||||||
buf.write(std::addressof(cnmt.content_info), sizeof(cnmt.content_info));
|
buf.write(std::addressof(cnmt.content_info), sizeof(cnmt.content_info));
|
||||||
|
|
||||||
@@ -1263,9 +1233,9 @@ Result Yati::RegisterNcasAndPushRecord(const CnmtCollection& cnmt, u32 latest_ve
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result InstallInternal(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const container::Collections& collections) {
|
Result InstallInternal(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const container::Collections& collections, const ConfigOverride& override) {
|
||||||
auto yati = std::make_unique<Yati>(pbox, source);
|
auto yati = std::make_unique<Yati>(pbox, source);
|
||||||
R_TRY(yati->Setup());
|
R_TRY(yati->Setup(override));
|
||||||
|
|
||||||
std::vector<TikCollection> tickets{};
|
std::vector<TikCollection> tickets{};
|
||||||
R_TRY(yati->ParseTicketsIntoCollection(tickets, collections, true));
|
R_TRY(yati->ParseTicketsIntoCollection(tickets, collections, true));
|
||||||
@@ -1301,12 +1271,7 @@ Result InstallInternal(ui::ProgressBox* pbox, std::shared_ptr<source::Base> sour
|
|||||||
|
|
||||||
log_write("installing nca's\n");
|
log_write("installing nca's\n");
|
||||||
for (auto& nca : cnmt.ncas) {
|
for (auto& nca : cnmt.ncas) {
|
||||||
if (nca.type == NcmContentType_Control) {
|
R_TRY(yati->InstallNca(tickets, nca));
|
||||||
log_write("installing control nca\n");
|
|
||||||
R_TRY(yati->InstallControlNca(tickets, cnmt, nca));
|
|
||||||
} else {
|
|
||||||
R_TRY(yati->InstallNca(tickets, nca));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
R_TRY(yati->ImportTickets(tickets));
|
R_TRY(yati->ImportTickets(tickets));
|
||||||
@@ -1318,11 +1283,12 @@ Result InstallInternal(ui::ProgressBox* pbox, std::shared_ptr<source::Base> sour
|
|||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result InstallInternalStream(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, container::Collections collections) {
|
Result InstallInternalStream(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, container::Collections collections, const ConfigOverride& override) {
|
||||||
auto yati = std::make_unique<Yati>(pbox, source);
|
auto yati = std::make_unique<Yati>(pbox, source);
|
||||||
R_TRY(yati->Setup());
|
R_TRY(yati->Setup(override));
|
||||||
|
|
||||||
// not supported with stream installs (yet).
|
// not supported with stream installs (yet).
|
||||||
|
yati->config.skip_if_already_installed = false;
|
||||||
yati->config.convert_to_standard_crypto = false;
|
yati->config.convert_to_standard_crypto = false;
|
||||||
yati->config.lower_master_key = false;
|
yati->config.lower_master_key = false;
|
||||||
|
|
||||||
@@ -1365,7 +1331,7 @@ Result InstallInternalStream(ui::ProgressBox* pbox, std::shared_ptr<source::Base
|
|||||||
keys::parse_hex_key(rights_id.c, collection.name.c_str());
|
keys::parse_hex_key(rights_id.c, collection.name.c_str());
|
||||||
const auto str = collection.name.substr(0, collection.name.length() - 4) + ".cert";
|
const auto str = collection.name.substr(0, collection.name.length() - 4) + ".cert";
|
||||||
|
|
||||||
auto entry = std::find_if(tickets.begin(), tickets.end(), [rights_id](auto& e){
|
auto entry = std::find_if(tickets.begin(), tickets.end(), [&rights_id](auto& e){
|
||||||
return !std::memcmp(&rights_id, &e.rights_id, sizeof(rights_id));
|
return !std::memcmp(&rights_id, &e.rights_id, sizeof(rights_id));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1384,7 +1350,7 @@ Result InstallInternalStream(ui::ProgressBox* pbox, std::shared_ptr<source::Base
|
|||||||
for (auto& cnmt : cnmts) {
|
for (auto& cnmt : cnmts) {
|
||||||
// copy nca structs into cnmt.
|
// copy nca structs into cnmt.
|
||||||
for (auto& cnmt_nca : cnmt.ncas) {
|
for (auto& cnmt_nca : cnmt.ncas) {
|
||||||
auto it = std::find_if(ncas.cbegin(), ncas.cend(), [cnmt_nca](auto& e){
|
auto it = std::find_if(ncas.cbegin(), ncas.cend(), [&cnmt_nca](auto& e){
|
||||||
return e.name == cnmt_nca.name;
|
return e.name == cnmt_nca.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1415,40 +1381,107 @@ Result InstallInternalStream(ui::ProgressBox* pbox, std::shared_ptr<source::Base
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Result InstallFromFile(ui::ProgressBox* pbox, FsFileSystem* fs, const fs::FsPath& path) {
|
Result InstallFromFile(ui::ProgressBox* pbox, FsFileSystem* fs, const fs::FsPath& path, const ConfigOverride& override) {
|
||||||
return InstallFromSource(pbox, std::make_shared<source::File>(fs, path), path);
|
return InstallFromSource(pbox, std::make_shared<source::File>(fs, path), path, override);
|
||||||
// return InstallFromSource(pbox, std::make_shared<source::StreamFile>(fs, path), path);
|
// return InstallFromSource(pbox, std::make_shared<source::StreamFile>(fs, path), path, override);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result InstallFromStdioFile(ui::ProgressBox* pbox, const fs::FsPath& path) {
|
Result InstallFromStdioFile(ui::ProgressBox* pbox, const fs::FsPath& path, const ConfigOverride& override) {
|
||||||
return InstallFromSource(pbox, std::make_shared<source::Stdio>(path), path);
|
return InstallFromSource(pbox, std::make_shared<source::Stdio>(path), path, override);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result InstallFromSource(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const fs::FsPath& path) {
|
Result InstallFromSource(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const fs::FsPath& path, const ConfigOverride& override) {
|
||||||
const auto ext = std::strrchr(path.s, '.');
|
const auto ext = std::strrchr(path.s, '.');
|
||||||
R_UNLESS(ext, Result_ContainerNotFound);
|
R_UNLESS(ext, Result_ContainerNotFound);
|
||||||
|
|
||||||
if (!strcasecmp(ext, ".nsp") || !strcasecmp(ext, ".nsz")) {
|
if (!strcasecmp(ext, ".nsp") || !strcasecmp(ext, ".nsz")) {
|
||||||
return InstallFromContainer(pbox, std::make_unique<container::Nsp>(source));
|
return InstallFromContainer(pbox, std::make_unique<container::Nsp>(source), override);
|
||||||
} else if (!strcasecmp(ext, ".xci") || !strcasecmp(ext, ".xcz")) {
|
} else if (!strcasecmp(ext, ".xci") || !strcasecmp(ext, ".xcz")) {
|
||||||
return InstallFromContainer(pbox, std::make_unique<container::Xci>(source));
|
return InstallFromContainer(pbox, std::make_unique<container::Xci>(source), override);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_THROW(Result_ContainerNotFound);
|
R_THROW(Result_ContainerNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result InstallFromContainer(ui::ProgressBox* pbox, std::shared_ptr<container::Base> container) {
|
Result InstallFromContainer(ui::ProgressBox* pbox, std::shared_ptr<container::Base> container, const ConfigOverride& override) {
|
||||||
container::Collections collections;
|
container::Collections collections;
|
||||||
R_TRY(container->GetCollections(collections));
|
R_TRY(container->GetCollections(collections));
|
||||||
return InstallFromCollections(pbox, container->GetSource(), collections);
|
return InstallFromCollections(pbox, container->GetSource(), collections);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result InstallFromCollections(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const container::Collections& collections) {
|
Result InstallFromCollections(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const container::Collections& collections, const ConfigOverride& override) {
|
||||||
if (source->IsStream()) {
|
if (source->IsStream()) {
|
||||||
return InstallInternalStream(pbox, source, collections);
|
return InstallInternalStream(pbox, source, collections, override);
|
||||||
} else {
|
} else {
|
||||||
return InstallInternal(pbox, source, collections);
|
return InstallInternal(pbox, source, collections, override);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result ParseCnmtNca(const fs::FsPath& path, u64 program_id, ncm::PackagedContentMeta& header, std::vector<u8>& extended_header, std::vector<NcmPackagedContentInfo>& infos) {
|
||||||
|
FsFileSystem fs;
|
||||||
|
R_TRY(fsOpenFileSystemWithId(std::addressof(fs), program_id, FsFileSystemType_ContentMeta, path, FsContentAttributes_All));
|
||||||
|
ON_SCOPE_EXIT(fsFsClose(std::addressof(fs)));
|
||||||
|
|
||||||
|
FsDir dir;
|
||||||
|
R_TRY(fsFsOpenDirectory(std::addressof(fs), fs::FsPath{"/"}, FsDirOpenMode_ReadFiles, std::addressof(dir)));
|
||||||
|
ON_SCOPE_EXIT(fsDirClose(std::addressof(dir)));
|
||||||
|
|
||||||
|
s64 total_entries;
|
||||||
|
FsDirectoryEntry buf;
|
||||||
|
R_TRY(fsDirRead(std::addressof(dir), std::addressof(total_entries), 1, std::addressof(buf)));
|
||||||
|
|
||||||
|
FsFile file;
|
||||||
|
R_TRY(fsFsOpenFile(std::addressof(fs), fs::AppendPath("/", buf.name), FsOpenMode_Read, std::addressof(file)));
|
||||||
|
ON_SCOPE_EXIT(fsFileClose(std::addressof(file)));
|
||||||
|
|
||||||
|
s64 offset{};
|
||||||
|
u64 bytes_read;
|
||||||
|
R_TRY(fsFileRead(std::addressof(file), offset, std::addressof(header), sizeof(header), 0, std::addressof(bytes_read)));
|
||||||
|
offset += bytes_read;
|
||||||
|
|
||||||
|
// read extended header
|
||||||
|
extended_header.resize(header.meta_header.extended_header_size);
|
||||||
|
R_TRY(fsFileRead(std::addressof(file), offset, extended_header.data(), extended_header.size(), 0, std::addressof(bytes_read)));
|
||||||
|
offset += bytes_read;
|
||||||
|
|
||||||
|
// read infos.
|
||||||
|
infos.resize(header.meta_header.content_count);
|
||||||
|
R_TRY(fsFileRead(std::addressof(file), offset, infos.data(), infos.size() * sizeof(NcmPackagedContentInfo), 0, std::addressof(bytes_read)));
|
||||||
|
offset += bytes_read;
|
||||||
|
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result ParseControlNca(const fs::FsPath& path, u64 program_id, void* nacp_out, s64 nacp_size, std::vector<u8>* icon_out) {
|
||||||
|
FsFileSystem fs;
|
||||||
|
R_TRY(fsOpenFileSystemWithId(std::addressof(fs), program_id, FsFileSystemType_ContentControl, path, FsContentAttributes_All));
|
||||||
|
ON_SCOPE_EXIT(fsFsClose(std::addressof(fs)));
|
||||||
|
|
||||||
|
// read nacp.
|
||||||
|
if (nacp_out) {
|
||||||
|
FsFile file;
|
||||||
|
R_TRY(fsFsOpenFile(std::addressof(fs), fs::FsPath{"/control.nacp"}, FsOpenMode_Read, std::addressof(file)));
|
||||||
|
ON_SCOPE_EXIT(fsFileClose(std::addressof(file)));
|
||||||
|
|
||||||
|
u64 bytes_read;
|
||||||
|
R_TRY(fsFileRead(&file, 0, nacp_out, nacp_size, 0, &bytes_read));
|
||||||
|
}
|
||||||
|
|
||||||
|
// read icon.
|
||||||
|
if (icon_out) {
|
||||||
|
FsFile file;
|
||||||
|
R_TRY(fsFsOpenFile(std::addressof(fs), fs::FsPath{"/icon_AmericanEnglish.dat"}, FsOpenMode_Read, std::addressof(file)));
|
||||||
|
ON_SCOPE_EXIT(fsFileClose(std::addressof(file)));
|
||||||
|
|
||||||
|
s64 size;
|
||||||
|
R_TRY(fsFileGetSize(std::addressof(file), std::addressof(size)));
|
||||||
|
icon_out->resize(size);
|
||||||
|
|
||||||
|
u64 bytes_read;
|
||||||
|
R_TRY(fsFileRead(&file, 0, icon_out->data(), icon_out->size(), 0, &bytes_read));
|
||||||
|
}
|
||||||
|
|
||||||
|
R_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sphaira::yati
|
} // namespace sphaira::yati
|
||||||
|
|||||||
171
tools/usb_install_pc.py
Normal file
171
tools/usb_install_pc.py
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
# This script depends on PyUSB. You can get it with pip install pyusb.
|
||||||
|
# You will also need libusb installed
|
||||||
|
|
||||||
|
# My sincere apologies for this process being overly complicated. Apparently Python and Windows
|
||||||
|
# aren't very friendly :(
|
||||||
|
# Windows Instructions:
|
||||||
|
# 1. Download Zadig from https://zadig.akeo.ie/.
|
||||||
|
# 2. With your switch plugged in and on the Tinfoil USB install menu,
|
||||||
|
# choose "List All Devices" under the options menu in Zadig, and select libnx USB comms.
|
||||||
|
# 3. Choose libusbK from the driver list and click the "Replace Driver" button.
|
||||||
|
# 4. Run this script
|
||||||
|
|
||||||
|
# macOS Instructions:
|
||||||
|
# 1. Install Homebrew https://brew.sh
|
||||||
|
# 2. Install Python 3
|
||||||
|
# sudo mkdir /usr/local/Frameworks
|
||||||
|
# sudo chown $(whoami) /usr/local/Frameworks
|
||||||
|
# brew install python
|
||||||
|
# 3. Install PyUSB
|
||||||
|
# pip3 install pyusb
|
||||||
|
# 4. Install libusb
|
||||||
|
# brew install libusb
|
||||||
|
# 5. Plug in your Switch and go to Tinfoil > Title Management > USB Install NSP
|
||||||
|
# 6. Run this script
|
||||||
|
# python3 usb_install_pc.py <path/to/nsp_folder>
|
||||||
|
|
||||||
|
import usb.core
|
||||||
|
import usb.util
|
||||||
|
import struct
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
import time
|
||||||
|
|
||||||
|
CMD_ID_EXIT = 0
|
||||||
|
CMD_ID_FILE_RANGE = 1
|
||||||
|
|
||||||
|
CMD_TYPE_RESPONSE = 1
|
||||||
|
|
||||||
|
# list of supported extensions.
|
||||||
|
EXTS = (".nsp", ".xci", ".nsz", ".xcz")
|
||||||
|
|
||||||
|
def send_response_header(out_ep, cmd_id, data_size):
|
||||||
|
out_ep.write(b'TUC0') # Tinfoil USB Command 0
|
||||||
|
out_ep.write(struct.pack('<B', CMD_TYPE_RESPONSE))
|
||||||
|
out_ep.write(b'\x00' * 3)
|
||||||
|
out_ep.write(struct.pack('<I', cmd_id))
|
||||||
|
out_ep.write(struct.pack('<Q', data_size))
|
||||||
|
out_ep.write(b'\x00' * 0xC)
|
||||||
|
|
||||||
|
def file_range_cmd(nsp_dir, in_ep, out_ep, data_size):
|
||||||
|
file_range_header = in_ep.read(0x20)
|
||||||
|
|
||||||
|
range_size = struct.unpack('<Q', file_range_header[:8])[0]
|
||||||
|
range_offset = struct.unpack('<Q', file_range_header[8:16])[0]
|
||||||
|
nsp_name_len = struct.unpack('<Q', file_range_header[16:24])[0]
|
||||||
|
#in_ep.read(0x8) # Reserved
|
||||||
|
nsp_name = bytes(in_ep.read(nsp_name_len)).decode('utf-8')
|
||||||
|
|
||||||
|
print('Range Size: {}, Range Offset: {}, Name len: {}, Name: {}'.format(range_size, range_offset, nsp_name_len, nsp_name))
|
||||||
|
send_response_header(out_ep, CMD_ID_FILE_RANGE, range_size)
|
||||||
|
|
||||||
|
with open(nsp_name, 'rb') as f:
|
||||||
|
f.seek(range_offset)
|
||||||
|
|
||||||
|
curr_off = 0x0
|
||||||
|
end_off = range_size
|
||||||
|
read_size = 0x800000
|
||||||
|
|
||||||
|
while curr_off < end_off:
|
||||||
|
if curr_off + read_size >= end_off:
|
||||||
|
read_size = end_off - curr_off
|
||||||
|
|
||||||
|
buf = f.read(read_size)
|
||||||
|
out_ep.write(data=buf, timeout=0)
|
||||||
|
curr_off += read_size
|
||||||
|
|
||||||
|
def poll_commands(nsp_dir, in_ep, out_ep):
|
||||||
|
while True:
|
||||||
|
cmd_header = bytes(in_ep.read(0x20, timeout=0))
|
||||||
|
magic = cmd_header[:4]
|
||||||
|
print('Magic: {}'.format(magic), flush=True)
|
||||||
|
|
||||||
|
if magic != b'TUC0': # Tinfoil USB Command 0
|
||||||
|
continue
|
||||||
|
|
||||||
|
cmd_type = struct.unpack('<B', cmd_header[4:5])[0]
|
||||||
|
cmd_id = struct.unpack('<I', cmd_header[8:12])[0]
|
||||||
|
data_size = struct.unpack('<Q', cmd_header[12:20])[0]
|
||||||
|
|
||||||
|
print('Cmd Type: {}, Command id: {}, Data size: {}'.format(cmd_type, cmd_id, data_size), flush=True)
|
||||||
|
|
||||||
|
if cmd_id == CMD_ID_EXIT:
|
||||||
|
print('Exiting...')
|
||||||
|
break
|
||||||
|
elif cmd_id == CMD_ID_FILE_RANGE:
|
||||||
|
file_range_cmd(nsp_dir, in_ep, out_ep, data_size)
|
||||||
|
|
||||||
|
def send_nsp_list(nsp_dir, out_ep):
|
||||||
|
nsp_path_list = list()
|
||||||
|
nsp_path_list_len = 0
|
||||||
|
|
||||||
|
# Add all files with the extension .nsp in the provided dir
|
||||||
|
for nsp_path in [f for f in nsp_dir.iterdir() if f.is_file() and (f.suffix in EXTS)]:
|
||||||
|
nsp_path_list.append(nsp_path.__str__() + '\n')
|
||||||
|
nsp_path_list_len += len(nsp_path.__str__()) + 1
|
||||||
|
|
||||||
|
print('Sending header...')
|
||||||
|
|
||||||
|
out_ep.write(b'TUL0') # Tinfoil USB List 0
|
||||||
|
out_ep.write(struct.pack('<I', nsp_path_list_len))
|
||||||
|
out_ep.write(b'\x00' * 0x8) # Padding
|
||||||
|
|
||||||
|
print('Sending NSP list: {}'.format(nsp_path_list))
|
||||||
|
|
||||||
|
for nsp_path in nsp_path_list:
|
||||||
|
out_ep.write(nsp_path)
|
||||||
|
|
||||||
|
def print_usage():
|
||||||
|
print("""\
|
||||||
|
usb_install_pc.py
|
||||||
|
|
||||||
|
Used for the installation of NSPs over USB.
|
||||||
|
|
||||||
|
Usage: usb_install_pc.py <nsp folder>""")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print_usage()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
nsp_dir = Path(sys.argv[1])
|
||||||
|
|
||||||
|
if not nsp_dir.is_dir():
|
||||||
|
raise ValueError('1st argument must be a directory')
|
||||||
|
|
||||||
|
print("waiting for switch...\n")
|
||||||
|
dev = None
|
||||||
|
|
||||||
|
while (dev is None):
|
||||||
|
dev = usb.core.find(idVendor=0x057E, idProduct=0x3000)
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
print("found the switch!\n")
|
||||||
|
|
||||||
|
cfg = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
cfg = dev.get_active_configuration()
|
||||||
|
print("found active config")
|
||||||
|
except usb.core.USBError:
|
||||||
|
print("no currently active config")
|
||||||
|
cfg = None
|
||||||
|
|
||||||
|
if cfg is None:
|
||||||
|
dev.reset()
|
||||||
|
dev.set_configuration()
|
||||||
|
cfg = dev.get_active_configuration()
|
||||||
|
|
||||||
|
is_out_ep = lambda ep: usb.util.endpoint_direction(ep.bEndpointAddress) == usb.util.ENDPOINT_OUT
|
||||||
|
is_in_ep = lambda ep: usb.util.endpoint_direction(ep.bEndpointAddress) == usb.util.ENDPOINT_IN
|
||||||
|
out_ep = usb.util.find_descriptor(cfg[(0,0)], custom_match=is_out_ep)
|
||||||
|
in_ep = usb.util.find_descriptor(cfg[(0,0)], custom_match=is_in_ep)
|
||||||
|
|
||||||
|
assert out_ep is not None
|
||||||
|
assert in_ep is not None
|
||||||
|
|
||||||
|
print("iManufacturer: {} iProduct: {} iSerialNumber: {}".format(dev.manufacturer, dev.product, dev.serial_number))
|
||||||
|
print("bcdUSB: {} bMaxPacketSize0: {}".format(hex(dev.bcdUSB), dev.bMaxPacketSize0))
|
||||||
|
|
||||||
|
send_nsp_list(nsp_dir, out_ep)
|
||||||
|
poll_commands(nsp_dir, in_ep, out_ep)
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
# based on usb.py from Tinfoil, by Adubbz.
|
|
||||||
import struct
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import usb.core
|
|
||||||
import usb.util
|
|
||||||
import time
|
|
||||||
import glob
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
# magic number (SPHA) for the script and switch.
|
|
||||||
MAGIC = 0x53504841
|
|
||||||
# version of the usb script.
|
|
||||||
VERSION = 2
|
|
||||||
# list of supported extensions.
|
|
||||||
EXTS = (".nsp", ".xci", ".nsz", ".xcz")
|
|
||||||
|
|
||||||
def verify_switch(bcdUSB, count, in_ep, out_ep):
|
|
||||||
header = in_ep.read(8, timeout=0)
|
|
||||||
switch_magic = struct.unpack('<I', header[0:4])[0]
|
|
||||||
switch_version = struct.unpack('<I', header[4:8])[0]
|
|
||||||
|
|
||||||
if switch_magic != MAGIC:
|
|
||||||
raise Exception("Unexpected magic {}".format(switch_magic))
|
|
||||||
|
|
||||||
if switch_version != VERSION:
|
|
||||||
raise Exception("Unexpected version {}".format(switch_version))
|
|
||||||
|
|
||||||
send_data = struct.pack('<IIII', MAGIC, VERSION, bcdUSB, count)
|
|
||||||
out_ep.write(data=send_data, timeout=0)
|
|
||||||
|
|
||||||
def send_file_info(path, in_ep, out_ep):
|
|
||||||
file_name = Path(path).name
|
|
||||||
file_size = Path(path).stat().st_size
|
|
||||||
file_name_len = len(file_name)
|
|
||||||
|
|
||||||
send_data = struct.pack('<QQ', file_size, file_name_len)
|
|
||||||
out_ep.write(data=send_data, timeout=0)
|
|
||||||
out_ep.write(data=file_name, timeout=0)
|
|
||||||
|
|
||||||
def wait_for_input(path, in_ep, out_ep):
|
|
||||||
buf = None
|
|
||||||
predicted_off = 0
|
|
||||||
print("now waiting for intput\n")
|
|
||||||
|
|
||||||
with open(path, "rb") as file:
|
|
||||||
while True:
|
|
||||||
header = in_ep.read(24, timeout=0)
|
|
||||||
|
|
||||||
range_offset = struct.unpack('<Q', header[8:16])[0]
|
|
||||||
range_size = struct.unpack('<Q', header[16:24])[0]
|
|
||||||
|
|
||||||
if (range_offset == 0 and range_size == 0):
|
|
||||||
break
|
|
||||||
|
|
||||||
if (buf != None and range_offset == predicted_off and range_size == len(buf)):
|
|
||||||
# print("predicted the read off {} size {}".format(predicted_off, len(buf)))
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
file.seek(range_offset)
|
|
||||||
buf = file.read(range_size)
|
|
||||||
|
|
||||||
if (len(buf) != range_size):
|
|
||||||
# print("off: {} size: {}".format(range_offset, range_size))
|
|
||||||
raise ValueError('bad buf size!!!!!')
|
|
||||||
|
|
||||||
result = out_ep.write(data=buf, timeout=0)
|
|
||||||
if (len(buf) != result):
|
|
||||||
print("off: {} size: {}".format(range_offset, range_size))
|
|
||||||
raise ValueError('bad result!!!!!')
|
|
||||||
|
|
||||||
predicted_off = range_offset + range_size
|
|
||||||
buf = file.read(range_size)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
print("hello world")
|
|
||||||
|
|
||||||
# check which mode the user has selected.
|
|
||||||
args = len(sys.argv)
|
|
||||||
if (args != 2):
|
|
||||||
print("either run python usb_total.py game.nsp OR drag and drop the game onto the python file (if python is in your path)")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
path = sys.argv[1]
|
|
||||||
files = []
|
|
||||||
|
|
||||||
if os.path.isfile(path) and path.endswith(EXTS):
|
|
||||||
files.append(path)
|
|
||||||
elif os.path.isdir(path):
|
|
||||||
for f in glob.glob(path + "/**/*.*", recursive=True):
|
|
||||||
if os.path.isfile(f) and f.endswith(EXTS):
|
|
||||||
files.append(f)
|
|
||||||
else:
|
|
||||||
raise ValueError('must be a file!')
|
|
||||||
|
|
||||||
# for file in files:
|
|
||||||
# print("found file: {}".format(file))
|
|
||||||
|
|
||||||
# Find the switch
|
|
||||||
print("waiting for switch...\n")
|
|
||||||
dev = None
|
|
||||||
|
|
||||||
while (dev is None):
|
|
||||||
dev = usb.core.find(idVendor=0x057E, idProduct=0x3000)
|
|
||||||
time.sleep(0.5)
|
|
||||||
|
|
||||||
print("found the switch!\n")
|
|
||||||
|
|
||||||
cfg = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
cfg = dev.get_active_configuration()
|
|
||||||
print("found active config")
|
|
||||||
except usb.core.USBError:
|
|
||||||
print("no currently active config")
|
|
||||||
cfg = None
|
|
||||||
|
|
||||||
if cfg is None:
|
|
||||||
dev.set_configuration()
|
|
||||||
cfg = dev.get_active_configuration()
|
|
||||||
|
|
||||||
is_out_ep = lambda ep: usb.util.endpoint_direction(ep.bEndpointAddress) == usb.util.ENDPOINT_OUT
|
|
||||||
is_in_ep = lambda ep: usb.util.endpoint_direction(ep.bEndpointAddress) == usb.util.ENDPOINT_IN
|
|
||||||
out_ep = usb.util.find_descriptor(cfg[(0,0)], custom_match=is_out_ep)
|
|
||||||
in_ep = usb.util.find_descriptor(cfg[(0,0)], custom_match=is_in_ep)
|
|
||||||
assert out_ep is not None
|
|
||||||
assert in_ep is not None
|
|
||||||
|
|
||||||
print("iManufacturer: {} iProduct: {} iSerialNumber: {}".format(dev.manufacturer, dev.product, dev.serial_number))
|
|
||||||
print("bcdUSB: {} bMaxPacketSize0: {}".format(hex(dev.bcdUSB), dev.bMaxPacketSize0))
|
|
||||||
|
|
||||||
try:
|
|
||||||
verify_switch(dev.bcdUSB, len(files), in_ep, out_ep)
|
|
||||||
|
|
||||||
for file in files:
|
|
||||||
print("installing file: {}".format(file))
|
|
||||||
send_file_info(file, in_ep, out_ep)
|
|
||||||
wait_for_input(file, in_ep, out_ep)
|
|
||||||
dev.reset()
|
|
||||||
except Exception as inst:
|
|
||||||
print("An exception occurred " + str(inst))
|
|
||||||
Reference in New Issue
Block a user