diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..07ab7e9 --- /dev/null +++ b/Makefile @@ -0,0 +1,232 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +TOPDIR ?= $(CURDIR) +include $(DEVKITPRO)/libnx/switch_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional) +# +# NO_ICON: if set to anything, do not use icon. +# NO_NACP: if set to anything, no .nacp file is generated. +# APP_TITLE is the name of the app stored in the .nacp file (Optional) +# APP_AUTHOR is the author of the app stored in the .nacp file (Optional) +# APP_VERSION is the version of the app stored in the .nacp file (Optional) +# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) +# ICON is the filename of the icon (.jpg), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .jpg +# - icon.jpg +# - /default_icon.jpg +# +# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .json +# - config.json +# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead +# of a homebrew executable (.nro). This is intended to be used for sysmodules. +# NACP building is skipped as well. +#--------------------------------------------------------------------------------- +TARGET := tencent-switcher-gui +BUILD := build.nx +SOURCES := source +DATA := data +#ICON := resources/icon/borealis.jpg +INCLUDES := include +APP_TITLE := Tencent switcher GUI +APP_AUTHOR := CaiMiao +APP_VERSION := 0.1 + +ROMFS := resources +BOREALIS_PATH := lib/borealis +BOREALIS_RESOURCES := romfs:/ +#APP_RESOURCES := romfs:/app/ + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE + +CFLAGS := -g -Wall -O2 -ffunction-sections \ + $(ARCH) $(DEFINES) + +CFLAGS += $(INCLUDE) -D__SWITCH__ \ + -DBOREALIS_RESOURCES="\"$(BOREALIS_RESOURCES)\"" + +CXXFLAGS := $(CFLAGS) -std=c++1z -O2 -Wno-volatile + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +LIBS := -lnx -lm + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(LIBNX) + +include $(TOPDIR)/$(BOREALIS_PATH)/library/borealis.mk + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) +export TOPDIR := $(CURDIR) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SRC) +export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +ifeq ($(strip $(CONFIG_JSON)),) + jsons := $(wildcard *.json) + ifneq (,$(findstring $(TARGET).json,$(jsons))) + export APP_JSON := $(TOPDIR)/$(TARGET).json + else + ifneq (,$(findstring config.json,$(jsons))) + export APP_JSON := $(TOPDIR)/config.json + endif + endif +else + export APP_JSON := $(TOPDIR)/$(CONFIG_JSON) +endif + +ifeq ($(strip $(ICON)),) + icons := $(wildcard *.jpg) + ifneq (,$(findstring $(TARGET).jpg,$(icons))) + export APP_ICON := $(TOPDIR)/$(TARGET).jpg + else + ifneq (,$(findstring icon.jpg,$(icons))) + export APP_ICON := $(TOPDIR)/icon.jpg + endif + endif +else + export APP_ICON := $(TOPDIR)/$(ICON) +endif + +ifeq ($(strip $(NO_ICON)),) + export NROFLAGS += --icon=$(APP_ICON) +endif + +ifeq ($(strip $(NO_NACP)),) + export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp +endif + +ifneq ($(APP_TITLEID),) + export NACPFLAGS += --titleid=$(APP_TITLEID) +endif + +ifneq ($(ROMFS),) + export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) +endif + +.PHONY: $(BUILD) clean all + +#--------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @MSYS2_ARG_CONV_EXCL="-D;$(MSYS2_ARG_CONV_EXCL)" $(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... +ifeq ($(strip $(APP_JSON)),) + @rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf +else + @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf +endif + + +#--------------------------------------------------------------------------------- +else +.PHONY: all + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +ifeq ($(strip $(APP_JSON)),) + +all : $(OUTPUT).nro + +ifeq ($(strip $(NO_NACP)),) +$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp +else +$(OUTPUT).nro : $(OUTPUT).elf +endif + +else + +all : $(OUTPUT).nsp + +$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm + +$(OUTPUT).nso : $(OUTPUT).elf + +endif + +$(OUTPUT).elf : $(OFILES) + +$(OFILES_SRC) : $(HFILES_BIN) + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/README.md b/README.md new file mode 100644 index 0000000..edfa468 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +GUI version of [this](https://github.com/CaiMiao/Tencent-Switch-switcher). Just werks. + +## Usage +follow GUI. + +## License? + +GPLv3 + +Do not use for commercial purpose. + +##Credits + +[switch-examples](https://github.com/switchbrew/switch-examples) + +[borealis](https://github.com/CaiMiao/borealis) diff --git a/lib/borealis b/lib/borealis new file mode 160000 index 0000000..c03edbd --- /dev/null +++ b/lib/borealis @@ -0,0 +1 @@ +Subproject commit c03edbda11204cc365f7f6890a25087191ea5935 diff --git a/resources/.gitignore b/resources/.gitignore new file mode 100644 index 0000000..17dfeba --- /dev/null +++ b/resources/.gitignore @@ -0,0 +1,2 @@ +Illegal-Font.ttf +Wingdings.ttf diff --git a/resources/i18n/en-US/brls.json b/resources/i18n/en-US/brls.json new file mode 100644 index 0000000..6fe8fb3 --- /dev/null +++ b/resources/i18n/en-US/brls.json @@ -0,0 +1,15 @@ +{ + "hints": { + "ok": "OK", + "back": "Back", + "exit": "Exit" + }, + + "crash_frame": { + "button": "OK" + }, + + "thumbnail_sidebar": { + "save": "Save" + } +} diff --git a/resources/i18n/en-US/main.json b/resources/i18n/en-US/main.json new file mode 100644 index 0000000..ee2c6c1 --- /dev/null +++ b/resources/i18n/en-US/main.json @@ -0,0 +1,67 @@ +{ + "test_msg": "妳你她牠*战斗、戰鬥,戦闘ばとるフィールド。\n简体繁體日本語한국어", + "name": "Tencent switcher GUI", + "common": { + "disc_msg": "DISCLAIMER: The author does not take any responsibility regarding potential BRICKs & BANs.\nBe wise and use at your own risk.\n\nYou have been warned.", + "disc_dlg_msg": "DISCLAIMER: The author does not take any responsibility regarding potential BRICKs & BANs. Be wise and use at your own risk.\n\nYou have been warned.", + "btn_idk": "I've read & agreed, let me in", + "btn_continue": "Continue", + "btn_cancel": "Cancel", + "btn_quit": "Quit", + "EOL": "" + }, + + "tabs": { + "ez": "Easy mode", + "info": "Info", + "hc": "Brick mode", + "EOL": "" + }, + + "ez": { + "ok_msg": "Done. System menu change will take effect after reboot.", + "lbl": "Safe switches", + "safeT": "Set to safe Tencent params", + "safeNT": "Set to safe non-Tencent params", + "EOL": "" + }, + + "info": { + "about": "About", + "about_msg": "Tencent switcher GUI\n(c) 2021 CaiMiao\nMasterpiece of copy&paste development", + "now_val": "Current Values (when this app was launched)", + "btn_show_val": "Show current values", + "btn_brick": "Spawn Hardcore Mode", + "desc_brick": "Best place to brick yourself", + "brick_msg": "Not even exosphère can save you from brick", + "EOL": "" + }, + + "hc": { + "warn_msg": "WARNING: Mismatch settings can brick you in 2162-0002.\nIf app crashed, DO NOT REBOOT. Enter app again and set safe values.", + "lbl": "Screw", + "EOL": "" + }, + + "terms": { + "LanguageCode": "Language Code", + "RegionCode": "Region Code", + "IsT": "IsT (is Tencent)", + "Language": "Language", + "Region": "Region", + "PlatformRegion": "Platform Region", + "global": "Global", + "tencent": "Tencent", + "EOL": "" + }, + + "locale": { + "ja": "Japanese", + "en-US": "English (US)", + "zh-Hans": "Chinese (Simplified)", + "zh-Hant": "Chinese (Traditional)", + "EOL": "" + }, + + "EOL": "" +} diff --git a/resources/i18n/zh-Hans/brls.json b/resources/i18n/zh-Hans/brls.json new file mode 100644 index 0000000..9cd1848 --- /dev/null +++ b/resources/i18n/zh-Hans/brls.json @@ -0,0 +1,15 @@ +{ + "hints": { + "ok": "确认", + "back": "返回", + "exit": "退出" + }, + + "crash_frame": { + "button": "确认" + }, + + "thumbnail_sidebar": { + "save": "保存" + } +} diff --git a/resources/i18n/zh-Hans/main.json b/resources/i18n/zh-Hans/main.json new file mode 100644 index 0000000..61fdf1a --- /dev/null +++ b/resources/i18n/zh-Hans/main.json @@ -0,0 +1,67 @@ +{ + "test_msg": "妳你她牠*战斗、戰鬥,戦闘ばとるフィールド。\n简体繁體日本語한국어", + "name": "Tencent switcher GUI by CaiMiao 国行/国际版系统切换工具", + "common": { + "disc_msg": "DISCLAIMER: The author does not take any responsibility regarding potential BRICKs & BANs.\nBe wise and use at your own risk.\n\nYou have been warned.", + "disc_dlg_msg": "免责声明: 若使用出现砖/BAN,此软件作者概不负责,一切后果请自行承担。\n\n(Please read the DISCLAIMER text above\nor later in English)", + "btn_idk": "我已知悉上述风险,继续", + "btn_continue": "继续", + "btn_cancel": "取消", + "btn_quit": "退出", + "EOL": "" + }, + + "tabs": { + "ez": "简单模式", + "info": "当前信息", + "hc": "砖家选项", + "EOL": "" + }, + + "ez": { + "ok_msg": "已修改,系统跨区需重启后生效。", + "lbl": "安全选项", + "safeT": "设置为【腾讯国行】安全参数", + "safeNT": "设置为【全球版本】安全参数", + "EOL": "" + }, + + "info": { + "about": "关于", + "about_msg": "Tencent switcher GUI\n(c) 2021 菜“秒” a.k.a. CaiMiao\n高产卫星的秘密:复制粘贴", + "now_val": "当前值(打开此App时)", + "btn_show_val": "显示当前值", + "btn_brick": "打开砖家选项", + "desc_brick": "变砖快人一步", + "brick_msg": "逆天改命,回收砖机核弹头,\nqq337845818", + "EOL": "" + }, + + "hc": { + "warn_msg": "**警告**:任何不匹配的设定均会触发 2162-0002 开机假砖。\n若修改过程中崩溃,请勿重启系统。请重新进入app设置好安全参数。", + "lbl": "乱搞", + "EOL": "" + }, + + "terms": { + "LanguageCode": "语言代码", + "RegionCode": "地区代码", + "IsT": "IsT (是否腾讯系统)", + "Language": "语言", + "Region": "地区", + "PlatformRegion": "PlatformRegion (平台区域)", + "global": "国际", + "tencent": "腾讯", + "EOL": "" + }, + + "locale": { + "ja": "日语", + "en-US": "英语(美国)", + "zh-Hans": "简体中文", + "zh-Hant": "繁体中文", + "EOL": "" + }, + + "EOL": "" +} diff --git a/resources/material/LICENSE.txt b/resources/material/LICENSE.txt new file mode 100644 index 0000000..7a4a3ea --- /dev/null +++ b/resources/material/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/resources/material/MaterialIcons-Regular.ttf b/resources/material/MaterialIcons-Regular.ttf new file mode 100644 index 0000000..7015564 Binary files /dev/null and b/resources/material/MaterialIcons-Regular.ttf differ diff --git a/source/main.cpp b/source/main.cpp new file mode 100644 index 0000000..44ca6c0 --- /dev/null +++ b/source/main.cpp @@ -0,0 +1,347 @@ +/* + Borealis, a Nintendo Switch UI Library + Copyright (C) 2019-2020 natinusala + Copyright (C) 2019 p-sam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include + +#include +#include + +#ifdef __SWITCH__ +#include +#endif + +namespace i18n = brls::i18n; // for loadTranslations() and getStr() +using namespace i18n::literals; // for _i18n + +Result rc; +u64 languageCode; +SetRegion regionCode; +bool bT; + +const char *regionName[] = { "JPN", "USA", "EUR", "AUS", "HTK", "CHN" }; + +Result runtimeRc; +bool bHardcore = false; + +void showMsgDlg(std::string msgStr, std::string btnStr, bool cancelable = false) +{ + brls::Dialog* dlg = new brls::Dialog(msgStr); + + brls::GenericEvent::Callback closeCallback = [dlg](brls::View* view) { + dlg->close(); + }; + + dlg->addButton(btnStr, closeCallback); + + dlg->setCancelable(cancelable); + + dlg->open(); +} + +void mainForm() +{ + rc = setGetLanguageCode(&languageCode); + rc = setGetRegionCode(®ionCode); + rc = setsysGetT(&bT); + + // Create a sample view + brls::TabFrame* rootFrame = new brls::TabFrame(); + rootFrame->setTitle("main/name"_i18n); + //rootFrame->setIcon(BOREALIS_ASSET("icon/borealis.jpg")); + + // lists + brls::List* mainActionList = new brls::List(); + brls::List* infoTabList = new brls::List(); + brls::List* brickList = new brls::List(); + + + brls::ListItem* safeTenItem = new brls::ListItem("main/ez/safeT"_i18n); + safeTenItem->getClickEvent()->subscribe([=](brls::View* view) { + setMakeLanguageCode(SetLanguage_ZHHANS, &languageCode); + runtimeRc = setsysSetLanguageCode(languageCode); + setGetLanguageCode(&languageCode); + if (R_SUCCEEDED(runtimeRc)) brls::Logger::info(fmt::format("Success. LanguageCode: {}", (char*)&languageCode)); + runtimeRc = setsysSetRegionCode(SetRegion_CHN); + setGetRegionCode(®ionCode); + if (R_SUCCEEDED(runtimeRc)) brls::Logger::info(fmt::format("Success. RegionCode: {}", regionCode)); + runtimeRc = setsysSetT(true); + setsysGetT(&bT); + if (R_SUCCEEDED(runtimeRc)) brls::Logger::info(fmt::format("Success. IsT: {}", bT)); + auto msg = fmt::format("{}\nLanguageCode: {}\nRegionCode: {}\nIsT: {}", "main/ez/ok_msg"_i18n, (char*)&languageCode, regionCode, bT); + showMsgDlg(msg, "brls/hints/ok"_i18n); + }); + + brls::ListItem* safeNonTenItem = new brls::ListItem("main/ez/safeNT"_i18n); + safeNonTenItem->getClickEvent()->subscribe([=](brls::View* view) { + runtimeRc = setsysSetRegionCode(SetRegion_HTK); + setGetRegionCode(®ionCode); + if (R_SUCCEEDED(runtimeRc)) brls::Logger::info(fmt::format("Success. RegionCode: {}", regionCode)); + runtimeRc = setsysSetT(false); + setsysGetT(&bT); + if (R_SUCCEEDED(runtimeRc)) brls::Logger::info(fmt::format("Success. IsT: {}", bT)); + auto msg = fmt::format("{}\nLanguageCode: {}\nRegionCode: {}\nIsT: {}", "main/ez/ok_msg"_i18n, (char*)&languageCode, regionCode, bT); + showMsgDlg(msg, "brls/hints/ok"_i18n); + }); + + brls::ListItem* setEnglishItem = new brls::ListItem("Set to English language", "", "when you are gaijin"); + setEnglishItem->getClickEvent()->subscribe([=](brls::View* view) { + runtimeRc = setsysGetT(&bT); + if (R_FAILED(rc) || bT == true) { + auto msg = "You will brick yourself when IsT = true. Aborted.\n(Please use the second item first.)"; + showMsgDlg(msg, "brls/hints/ok"_i18n); + } else { + setMakeLanguageCode(SetLanguage_ENUS, &languageCode); + runtimeRc = setsysSetLanguageCode(languageCode); + setGetLanguageCode(&languageCode); + if (R_SUCCEEDED(runtimeRc)) brls::Logger::info(fmt::format("Success. LanguageCode: {}", (char*)&languageCode)); + auto msg = fmt::format("{}\nLanguageCode: {}\nRegionCode: {}\nIsT: {}", "main/ez/ok_msg"_i18n, (char*)&languageCode, regionCode, bT); + showMsgDlg(msg, "brls/hints/ok"_i18n); + } + }); + + { // list 1 + mainActionList->addView(new brls::Label(brls::LabelStyle::SMALL, "main/common/disc_msg"_i18n, true)); + + mainActionList->addView(new brls::Header("main/ez/lbl"_i18n, false)); + + mainActionList->addView(safeTenItem); + mainActionList->addView(safeNonTenItem); + mainActionList->addView(setEnglishItem); + + rootFrame->addTab("main/tabs/ez"_i18n, mainActionList); + } + + brls::Table* currentTable = new brls::Table(); + currentTable->addRow(brls::TableRowType::BODY, "main/terms/LanguageCode"_i18n, i18n::getCurrentLocale()); + currentTable->addRow(brls::TableRowType::BODY, "main/terms/RegionCode"_i18n, fmt::format("{} ({})",regionCode, regionName[(int)regionCode])); + currentTable->addRow(brls::TableRowType::BODY, "main/terms/IsT"_i18n, fmt::format("{}", bT)); + + brls::ListItem* showValueItem = new brls::ListItem("main/info/btn_show_val"_i18n); + showValueItem->getClickEvent()->subscribe([=](brls::View* view) { + auto msg = fmt::format("LanguageCode: {}\nRegionCode: {}\nIsT: {}", (char*)&languageCode, regionCode, bT); + showMsgDlg(msg, "brls/hints/ok"_i18n); + }); + + brls::ListItem* aboutItem = new brls::ListItem("main/info/about"_i18n); + aboutItem->getClickEvent()->subscribe([=](brls::View* view) { + showMsgDlg("main/info/about_msg"_i18n, "brls/hints/ok"_i18n); + }); + + brls::ListItem* brickModeItem = new brls::ListItem("main/info/btn_brick"_i18n, "", "main/info/desc_brick"_i18n); + brickModeItem->getClickEvent()->subscribe([=](brls::View* view) { + if (!bHardcore) + { + bHardcore = true; + brls::Application::notify("main/info/brick_msg"_i18n); + brickModeItem->willDisappear(); + brickModeItem->hide([](){}); + brls::Application::giveFocus(aboutItem); + rootFrame->addSeparator(); + rootFrame->addTab("main/tabs/hc"_i18n, brickList); + } + }); + + { // list 2 + infoTabList->addView(new brls::Header("main/info/now_val"_i18n, false)); + + infoTabList->addView(currentTable); + infoTabList->addView(showValueItem); + infoTabList->addView(aboutItem); + infoTabList->addView(brickModeItem); + + rootFrame->addTab("main/tabs/info"_i18n, infoTabList); + } + + brls::ListItem* showValueItemDupe = new brls::ListItem("main/info/btn_show_val"_i18n); + showValueItemDupe->getClickEvent()->subscribe([=](brls::View* view) { + auto msg = fmt::format("LanguageCode: {}\nRegionCode: {}\nIsT: {}", (char*)&languageCode, regionCode, bT); + showMsgDlg(msg, "brls/hints/ok"_i18n); + }); + + brls::SelectListItem* languageItem = new brls::SelectListItem( + "main/terms/Language"_i18n, + { + "main/locale/ja"_i18n, + "main/locale/en-US"_i18n, + "main/locale/zh-Hans"_i18n, + "main/locale/zh-Hant"_i18n, + }, 2); + languageItem->getValueSelectedEvent()->subscribe([=](size_t selection) { + SetLanguage i; + switch (selection) + { + case 0: + i = SetLanguage_JA; + break; + case 2: + i = SetLanguage_ZHHANS; + break; + case 3: + i = SetLanguage_ZHHANT; + break; + case 1: + default: + i = SetLanguage_ENUS; + break; + } + setMakeLanguageCode(i, &languageCode); + runtimeRc = setsysSetLanguageCode(languageCode); + setGetLanguageCode(&languageCode); + auto msg = fmt::format("Success.\nLanguageCode: {}", (char*)&languageCode); + if (R_SUCCEEDED(runtimeRc)) brls::Application::notify(msg); + }); + + brls::SelectListItem* regionItem = new brls::SelectListItem( + "main/terms/Region"_i18n, + { + "JPN (Japan)", + "USA (The Americas)", + "EUR (Europe)", + "AUS (Australia/New Zealand)", + "HTK (Hongkong/Taiwan/Korea)", + "CHN (China)", + }, 4); + regionItem->getValueSelectedEvent()->subscribe([=](size_t selection) { + SetRegion i; + switch (selection) + { + case 0: + i = SetRegion_JPN; + break; + case 1: + i = SetRegion_USA; + break; + case 2: + i = SetRegion_EUR; + break; + case 3: + i = SetRegion_AUS; + break; + case 5: + i = SetRegion_CHN; + break; + case 4: + default: + i = SetRegion_HTK; + break; + } + runtimeRc = setsysSetRegionCode(i); + setGetRegionCode(®ionCode); + auto msg = fmt::format("Success.\nRegionCode: {}", regionCode); + if (R_SUCCEEDED(runtimeRc)) brls::Application::notify(msg); + }); + + brls::SelectListItem* isTenItem = new brls::SelectListItem( + "main/terms/PlatformRegion"_i18n, + { + "main/terms/global"_i18n, + "main/terms/tencent"_i18n, + }, 0); + isTenItem->getValueSelectedEvent()->subscribe([=](size_t selection) { + bool b; + switch (selection) + { + case 1: + b = true; + break; + case 0: + default: + b = false; + break; + } + runtimeRc = setsysSetT(b); + setsysGetT(&bT); + auto msg = fmt::format("Success.\nIsT: {}", bT); + if (R_SUCCEEDED(runtimeRc)) brls::Application::notify(msg); + }); + + //brls::InputListItem* fullkeyboardItem = new brls::CustomInputListItem("test swkbd input", "Klaatu barada nikto", "Enter passcode", "", 20, (int)(SwkbdType)SwkbdType_All); + + { // list 3 + brickList->addView(new brls::Label(brls::LabelStyle::MEDIUM, "main/hc/warn_msg"_i18n, true)); + + brickList->addView(showValueItemDupe); + + brickList->addView(new brls::Header("main/hc/lbl"_i18n, false)); + + brickList->addView(languageItem); + brickList->addView(regionItem); + brickList->addView(isTenItem); + + // brickList->addView(new brls::Header("test item", false)); + // brickList->addView(fullkeyboardItem); + } // spawns on brickModeItem->getClickEvent() + + // Add the root view to the stack + brls::Application::pushView(rootFrame); + + //brls::Application::giveFocus(safeNonTenItem); +} + +int main(int argc, char* argv[]) +{ + // Init the app + brls::Logger::setLogLevel(brls::LogLevel::INFO); + + rc = setInitialize(); + if (R_FAILED(rc)) brls::Logger::error("setInitialize() failed: 0x{:x}.", rc); + + rc = setsysInitialize(); + if (R_FAILED(rc)) brls::Logger::error("setsysInitialize() failed: 0x{:x}.", rc); + + if (R_FAILED(rc)) + { + brls::Logger::error("Unable to init libnx set service"); + return EXIT_FAILURE; + } + + i18n::loadTranslations(); + if (!brls::Application::init("main/name"_i18n)) + { + brls::Logger::error("Unable to init Borealis application"); + return EXIT_FAILURE; + } + + { + brls::Dialog* dialog = new brls::Dialog("main/common/disc_dlg_msg"_i18n); + + brls::GenericEvent::Callback closeCallback = [dialog](brls::View* view) { + dialog->close(); + mainForm(); + }; + + std::string continueStr = "main/common/btn_idk"_i18n; + + dialog->addButton(continueStr, closeCallback); + + dialog->setCancelable(false); + + dialog->open(); + } + + // Run the app + while (brls::Application::mainLoop()) + ; + + // Exit + setsysExit(); + setExit(); + return EXIT_SUCCESS; +}