Initial commit

This commit is contained in:
Anthony Wang 2020-06-15 22:07:31 -05:00
parent 94141cc43e
commit 794d770cd8
93 changed files with 7959 additions and 2 deletions

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
.vscode
build
Swurl/debug
Swurl/lib
Swurl/release
*.elf
*.nacp
*.nro

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "SimpleIniParser"]
path = SimpleIniParser
url = https://github.com/AtlasNX/SimpleIniParser.git

339
LICENSE Normal file
View file

@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 2 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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

249
Makefile Normal file
View file

@ -0,0 +1,249 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/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):
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/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):
# - <Project name>.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 := $(notdir $(CURDIR))
BUILD := build
SOURCES := source source/models source/scenes source/views
DATA := data
INCLUDES := include
ROMFS := romfs
APP_TITLE := Isotope Updater
APP_AUTHOR := FennecTECH,Nichole Mattera
APP_VERSION := 4.2.1
APP_VERSION_MAJOR := 4
APP_VERSION_MINOR := 2
APP_VERSION_PATCH := 1
SETTING_CONFIG_VERSION := 2
INTERNAL_CONFIG_VERSION := 2
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
DEFINES += -D__SWITCH__ \
-DVERSION=\"$(APP_VERSION)\" \
-DVERSION_MAJOR=$(APP_VERSION_MAJOR) \
-DVERSION_MINOR=$(APP_VERSION_MINOR) \
-DVERSION_PATCH=$(APP_VERSION_PATCH) \
-DSETTING_CONFIG_VERSION=$(SETTING_CONFIG_VERSION) \
-DINTERNAL_CONFIG_VERSION=$(INTERNAL_CONFIG_VERSION)
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES) $(INCLUDE)
CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++17
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) \
-Wl,-Map,$(notdir $*.map)
LIBS := -lSDL2_ttf -lSDL2_image -lSDL2_gfx -lfreetype -lwebp -lpng -ljpeg \
-ljansson -lSwurl -lcurl -lz -lSimpleIniParser -lminizip -lconfig \
-lnx `sdl2-config --libs` `freetype-config --libs`
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/SimpleIniParser $(CURDIR)/Swurl
#---------------------------------------------------------------------------------
# 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):
ifeq ($(wildcard $(CURDIR)/SimpleIniParser/LICENSE),)
@$(error "Please run 'git submodule update --init' before running 'make'")
endif
ifeq ($(wildcard $(CURDIR)/Swurl/LICENSE),)
@$(error "Please run 'git submodule update --init' before running 'make'")
endif
@[ -d $@ ] || mkdir -p $@
@$(MAKE) -C $(CURDIR)/SimpleIniParser -f $(CURDIR)/SimpleIniParser/Makefile
@$(MAKE) -C $(CURDIR)/Swurl -f $(CURDIR)/Swurl/Makefile
@$(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
#---------------------------------------------------------------------------------------

View file

@ -1,2 +1,20 @@
# Isotope-Updater
Automatic updater for Isotope
# Isotope Updater
A homebrew application for the Nintendo Switch that will automatically update your CFW with the latest from Isotope.
## settings.cfg
| Config option | Description
| --------------------------------------------------------------------------- | ---
| `ignore = [ "sdmc://fileToIgnore.nro", "sdmc://anotherFileToIgnore.nro" ];` | Array of files to ignore when extracting.
| `autoupdate = true;` | Whether or not to auto update Isotope Updater.
| `proxy_enabled = false;` | Whether or not to use a proxy for network calls.
| `proxy_url = "http://example.com:8080";` | The URL of the proxy server.
| `proxy_username = "username";` | The username to use for the proxy server, if blank it will not be used.
| `proxy_password = "password";` | The password to use for the proxy server, if blank it will not be used.
## Credits
* Thanks to vgmoose for examples on using minizip in appstorenx.
* Thanks to y4my4m and natinusala in the ReSwitched discord for their discussions around libcurl.
* Thanks to alex. for improving the config and other elements in FileManager.

13
SimpleIniParser/.gitignore vendored Normal file
View file

@ -0,0 +1,13 @@
pkg
src
debug
example/**/build
example/**/*.elf
example/**/*.nacp
example/**/*.nro
release
lib
.vscode
*.tar.bz2
*.tar.xz
*.tar.gz

13
SimpleIniParser/LICENSE Normal file
View file

@ -0,0 +1,13 @@
Copyright (c) 2020 Nichole Mattera
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

145
SimpleIniParser/Makefile Normal file
View file

@ -0,0 +1,145 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
include $(DEVKITPRO)/libnx/switch_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# 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
#---------------------------------------------------------------------------------
TARGET := SimpleIniParser
VERSION := 1.0.0
SOURCES := source source/SimpleIniParser
INCLUDES := include include/SimpleIniParser
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
CFLAGS := -g -Wall -Werror \
-ffunction-sections \
-fdata-sections \
$(ARCH) \
$(BUILD_CFLAGS)
CFLAGS += $(INCLUDE)
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
ifneq (,$(shell which ccache))
CXX := $(shell which ccache) $(CXX)
CC := $(shell which ccache) $(CC)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX)
#---------------------------------------------------------------------------------
# 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 VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
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 := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I. \
-iquote $(CURDIR)/include/switch/
.PHONY: clean all
#---------------------------------------------------------------------------------
all: lib/lib$(TARGET).a lib/lib$(TARGET)d.a
lib:
@[ -d $@ ] || mkdir -p $@
release:
@[ -d $@ ] || mkdir -p $@
debug:
@[ -d $@ ] || mkdir -p $@
lib/lib$(TARGET).a : lib release $(SOURCES) $(INCLUDES)
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
BUILD_CFLAGS="-DNDEBUG=1 -O2" \
DEPSDIR=$(CURDIR)/release \
--no-print-directory -C release \
-f $(CURDIR)/Makefile
lib/lib$(TARGET)d.a : lib debug $(SOURCES) $(INCLUDES)
@$(MAKE) BUILD=debug OUTPUT=$(CURDIR)/$@ \
BUILD_CFLAGS="-DDEBUG=1 -Og" \
DEPSDIR=$(CURDIR)/debug \
--no-print-directory -C debug \
-f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr release debug lib *.bz2
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT) : $(OFILES)
$(OFILES_SRC) : $(HFILES)
#---------------------------------------------------------------------------------
%_bin.h %.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

11
SimpleIniParser/README.md Normal file
View file

@ -0,0 +1,11 @@
# SimpleIniParser
A library for the Nintendo Switch to be able to easily parse, modify, and create INI files. The main reason this library was written was due to the special needs of the hekate ini file. The hekate ini file can have the same key used multiple times within the same section, and its captions surrounded by curly braces. As these are outside the ini standard, other ini parsers would remove the duplicate keys and strip out the captions.
## Installation
I recommend adding this as a git submodule to your and then modifying your makefile to look in this directory for libs. For examples on how to do this please look at [Kosmos Updater](https://github.com/AtlasNX/Kosmos-Updater), and [ReiNX Spoofer](https://github.com/NicholeMattera/ReiNX-Spoofer).
## Usage
I've included multiple examples for editing, creating, and reading ini files. You can find them under the example folder. Remember to add `-lSimpleIniParser` to `LIBS` in your makefile.

View file

@ -0,0 +1,231 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/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):
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/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):
# - <Project name>.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 := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
APP_TITLE := SimpleIniParser Creating Example
APP_AUTHOR := Nichole Mattera
APP_VERSION := 2.0.1
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lSimpleIniParser -lnx
ifneq (,$(shell which ccache))
CXX := $(shell which ccache) $(CXX)
CC := $(shell which ccache) $(CC)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../../
#---------------------------------------------------------------------------------
# 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 $@
@$(MAKE) -C $(CURDIR)/../.. -f $(CURDIR)/../../Makefile
@$(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
#---------------------------------------------------------------------------------------

View file

@ -0,0 +1,76 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <iostream>
#include <fstream>
#include <switch.h>
#include <SimpleIniParser.hpp>
using namespace simpleIniParser;
int main(int argc, char **argv) {
consoleInit(NULL);
Ini * hekateIni = new Ini();
IniSection * configSection = new IniSection(IniSectionType::Section, "config");
configSection->options.push_back(new IniOption(IniOptionType::Option, "autoboot", "1"));
configSection->options.push_back(new IniOption(IniOptionType::Option, "autoboot_list", "0"));
configSection->options.push_back(new IniOption(IniOptionType::Option, "bootwait", "5"));
configSection->options.push_back(new IniOption(IniOptionType::Option, "customlogo", "1"));
configSection->options.push_back(new IniOption(IniOptionType::Option, "verification", "1"));
configSection->options.push_back(new IniOption(IniOptionType::Option, "backlight", "100"));
configSection->options.push_back(new IniOption(IniOptionType::Option, "autohosoff", "0"));
configSection->options.push_back(new IniOption(IniOptionType::Option, "autonogc", "1"));
hekateIni->sections.push_back(configSection);
hekateIni->sections.push_back(new IniSection(IniSectionType::HekateCaption, "CFW"));
IniSection * cfwSection = new IniSection(IniSectionType::Section, "CFW");
cfwSection->options.push_back(new IniOption(IniOptionType::Option, "fss0", "atmosphere/fusee-secondary.bin"));
cfwSection->options.push_back(new IniOption(IniOptionType::Option, "kip1patch", "nosigchk"));
cfwSection->options.push_back(new IniOption(IniOptionType::Option, "atmosphere", "1"));
cfwSection->options.push_back(new IniOption(IniOptionType::Option, "logopath", "bootloader/bootlogo.bmp"));
hekateIni->sections.push_back(cfwSection);
hekateIni->sections.push_back(new IniSection(IniSectionType::HekateCaption, "Stock"));
IniSection * stockSection = new IniSection(IniSectionType::Section, "Stock");
stockSection->options.push_back(new IniOption(IniOptionType::Option, "fss0", "atmosphere/fusee-secondary.bin"));
stockSection->options.push_back(new IniOption(IniOptionType::Option, "stock", "1"));
hekateIni->sections.push_back(stockSection);
if (hekateIni->writeToFile("sdmc:/example.ini")) {
std::cout << "Ini file writen to: sdmc:/example.ini\n";
}
delete hekateIni;
std::cout << "Press any key to close.\n";
while(appletMainLoop())
{
hidScanInput();
if (hidKeysDown(CONTROLLER_P1_AUTO))
break;
consoleUpdate(NULL);
}
consoleExit(NULL);
return 0;
}

View file

@ -0,0 +1,232 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/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):
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/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):
# - <Project name>.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 := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
ROMFS := romfs
APP_TITLE := SimpleIniParser Editing Example
APP_AUTHOR := Nichole Mattera
APP_VERSION := 2.0.1
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lSimpleIniParser -lnx
ifneq (,$(shell which ccache))
CXX := $(shell which ccache) $(CXX)
CC := $(shell which ccache) $(CC)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../../
#---------------------------------------------------------------------------------
# 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 $@
@$(MAKE) -C $(CURDIR)/../.. -f $(CURDIR)/../../Makefile
@$(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
#---------------------------------------------------------------------------------------

View file

@ -0,0 +1,26 @@
# Sample Config
global_setting=1
; Comments
global_setting_two=2
[config]
autoboot=1
autoboot_list=0
bootwait=5
customlogo=1
verification=1
{AtlasNX/Isotope}
; Custom Firmwares
[CFW]
kip1patch=nosigchk
# Option Comment Test
atmosphere=1
logopath=bootloader/bootlogo1.bmp
logopath=bootloader/bootlogo2.bmp
# Miscellaneous
[Stock]
fss0=atmosphere/fusee-secondary.bin
stock=1

View file

@ -0,0 +1,71 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <iostream>
#include <fstream>
#include <switch.h>
#include <SimpleIniParser.hpp>
using namespace simpleIniParser;
void copy_file(std::string srcPath, std::string destPath) {
std::ifstream src(srcPath, std::ios::binary);
std::ofstream dest(destPath, std::ios::binary);
dest << src.rdbuf();
src.close();
dest.flush();
dest.close();
}
int main(int argc, char **argv) {
consoleInit(NULL);
Result rc = romfsInit();
if (R_FAILED(rc)) {
std::cout << "Unable to initialize romfs.\n";
}
else {
copy_file("romfs:/config.ini", "sdmc:/example1.ini");
Ini * exampleIni = Ini::parseFile("sdmc:/example1.ini");
exampleIni->sections.pop_back();
exampleIni->sections.pop_back();
exampleIni->findSection("config")->findFirstOption("autoboot")->value = "0";
exampleIni->writeToFile("sdmc:/example2.ini");
delete exampleIni;
}
std::cout << "Original file written to: sdmc:/example1.ini\n";
std::cout << "Modified file written to: sdmc:/example2.ini\n\n";
std::cout << "Press any key to close.\n";
while(appletMainLoop())
{
hidScanInput();
if (hidKeysDown(CONTROLLER_P1_AUTO))
break;
consoleUpdate(NULL);
}
consoleExit(NULL);
return 0;
}

View file

@ -0,0 +1,231 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/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):
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/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):
# - <Project name>.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 := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
APP_TITLE := SimpleIniParser Magic Example
APP_AUTHOR := Nichole Mattera
APP_VERSION := 2.0.1
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lSimpleIniParser -lnx
ifneq (,$(shell which ccache))
CXX := $(shell which ccache) $(CXX)
CC := $(shell which ccache) $(CC)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../../
#---------------------------------------------------------------------------------
# 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 $@
@$(MAKE) -C $(CURDIR)/../.. -f $(CURDIR)/../../Makefile
@$(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
#---------------------------------------------------------------------------------------

View file

@ -0,0 +1,115 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <iostream>
#include <fstream>
#include <switch.h>
#include <SimpleIniParser.hpp>
using namespace simpleIniParser;
using namespace std;
void writeOption(IniOption * option, bool withTab) {
switch (option->type) {
case IniOptionType::SemicolonComment:
std::cout << ((withTab) ? "\t" : "") << "Type: Semicolon Comment, Value: \"" << option->value << "\"\n";
break;
case IniOptionType::HashtagComment:
std::cout << ((withTab) ? "\t" : "") << "Type: Hashtag Comment, Value: \"" << option->value << "\"\n";
break;
default:
std::cout << ((withTab) ? "\t" : "") << "Type: Option, Key: \"" << option->key << "\", Value: \"" << option->value << "\"\n";
break;
}
}
void writeSection(IniSection * section) {
switch (section->type) {
case IniSectionType::SemicolonComment:
std::cout << "Type: Semicolon Comment, Value: \"" << section->value << "\"\n";
break;
case IniSectionType::HashtagComment:
std::cout << "Type: Hashtag Comment, Value: \"" << section->value << "\"\n";
break;
case IniSectionType::HekateCaption:
std::cout << "Type: Hekate Caption, Value: \"" << section->value << "\"\n";
break;
default:
std::cout << "Type: Section, Value: \"" << section->value << "\"\n";
break;
}
for (auto const& option : section->options) {
writeOption(option, true);
}
std::cout << "\n";
}
int main(int argc, char **argv) {
consoleInit(NULL);
Ini * config = Ini::parseFileWithMagic("sdmc:/atmosphere/BCT.ini", "BCT0");
std::cout << "Reading through an INI file.\n";
std::cout << "=====================================================\n\n";
for (auto const& option : config->options) {
writeOption(option, false);
}
if (config->options.size() > 0)
std::cout << "\n";
for (auto const& section : config->sections) {
writeSection(section);
}
auto exosphereSection = config->findSection("exosphere"); //->findFirstOption("autoboot")->value = "0";
if (exosphereSection != nullptr) {
auto debugModeOption = exosphereSection->findFirstOption("debugmode");
if (debugModeOption != nullptr) {
debugModeOption->value = "0";
config->writeToFile("sdmc:/BCT.ini");
std::cout << "Modified version of BCT.ini has been writen to the root of your SD Card.\n";
}
}
delete config;
std::cout << "\nPress any key to close.\n";
while(appletMainLoop())
{
hidScanInput();
if (hidKeysDown(CONTROLLER_P1_AUTO))
break;
consoleUpdate(NULL);
}
consoleExit(NULL);
return 0;
}

View file

@ -0,0 +1,232 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/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):
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/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):
# - <Project name>.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 := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
ROMFS := romfs
APP_TITLE := SimpleIniParser Reading Example
APP_AUTHOR := Nichole Mattera
APP_VERSION := 2.0.1
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lSimpleIniParser -lnx
ifneq (,$(shell which ccache))
CXX := $(shell which ccache) $(CXX)
CC := $(shell which ccache) $(CC)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../../
#---------------------------------------------------------------------------------
# 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 $@
@$(MAKE) -C $(CURDIR)/../.. -f $(CURDIR)/../../Makefile
@$(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
#---------------------------------------------------------------------------------------

View file

@ -0,0 +1,26 @@
# Sample Config
global_setting=1
; Comments
global_setting_two=2
[config]
autoboot=1
autoboot_list=0
bootwait=5
customlogo=1
verification=1
{AtlasNX/Isotope}
; Custom Firmwares
[CFW]
kip1patch=nosigchk
# Option Comment Test
atmosphere=1
logopath=bootloader/bootlogo1.bmp
logopath=bootloader/bootlogo2.bmp
# Miscellaneous
[Stock]
fss0=atmosphere/fusee-secondary.bin
stock=1

View file

@ -0,0 +1,123 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <iostream>
#include <fstream>
#include <switch.h>
#include <SimpleIniParser.hpp>
#include <vector>
using namespace simpleIniParser;
void writeOption(IniOption * option, bool withTab) {
switch (option->type) {
case IniOptionType::SemicolonComment:
std::cout << ((withTab) ? "\t" : "") << "Type: Semicolon Comment, Value: \"" << option->value << "\"\n";
break;
case IniOptionType::HashtagComment:
std::cout << ((withTab) ? "\t" : "") << "Type: Hashtag Comment, Value: \"" << option->value << "\"\n";
break;
default:
std::cout << ((withTab) ? "\t" : "") << "Type: Option, Key: \"" << option->key << "\", Value: \"" << option->value << "\"\n";
break;
}
}
void writeSection(IniSection * section) {
switch (section->type) {
case IniSectionType::SemicolonComment:
std::cout << "Type: Semicolon Comment, Value: \"" << section->value << "\"\n";
break;
case IniSectionType::HashtagComment:
std::cout << "Type: Hashtag Comment, Value: \"" << section->value << "\"\n";
break;
case IniSectionType::HekateCaption:
std::cout << "Type: Hekate Caption, Value: \"" << section->value << "\"\n";
break;
default:
std::cout << "Type: Section, Value: \"" << section->value << "\"\n";
break;
}
for (auto const& option : section->options) {
writeOption(option, true);
}
std::cout << "\n";
}
int main(int argc, char **argv) {
consoleInit(NULL);
Result rc = romfsInit();
if (R_FAILED(rc)) {
std::cout << "Unable to initialize romfs.\n";
}
else {
Ini * config = Ini::parseFile("romfs:/config.ini");
std::cout << "Reading through an INI file.\n";
std::cout << "=====================================================\n\n";
for (auto const& option : config->options) {
writeOption(option, false);
}
if (config->options.size() > 0)
std::cout << "\n";
for (auto const& section : config->sections) {
writeSection(section);
}
std::cout << "\nGet a specific option from a specific section.\n";
std::cout << "=====================================================\n\n";
std::vector<IniOption *> options = config->findSection("CFW", true, IniSectionType::Section)->findAllOptions("logopath");
for (auto const& option : options) {
writeOption(option, false);
}
IniOption * option = config->findSection("config")->findFirstOption("cUsToMlOgO", false);
std::cout << "Key: \"" << option->key << "\" | Value: \"" << option->value << "\"\n";
IniOption * option2 = config->findSection("CFW", true, IniSectionType::Section)->findFirstOption("option comment test", false, IniOptionType::HashtagComment, IniOptionSearchField::Value);
std::cout << "Key: \"" << option2->key << "\" | Value: \"" << option2->value << "\"\n\n";
delete config;
}
std::cout << "\nPress any key to close.\n";
while(appletMainLoop())
{
hidScanInput();
if (hidKeysDown(CONTROLLER_P1_AUTO))
break;
consoleUpdate(NULL);
}
consoleExit(NULL);
return 0;
}

View file

@ -0,0 +1,22 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "SimpleIniParser/Ini.hpp"
#include "SimpleIniParser/IniHelper.hpp"
#include "SimpleIniParser/IniSection.hpp"
#include "SimpleIniParser/IniOption.hpp"
#include "SimpleIniParser/IniStringHelper.hpp"

View file

@ -0,0 +1,51 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include "IniSection.hpp"
#include "IniOption.hpp"
namespace simpleIniParser {
class Ini {
public:
std::vector<IniOption *> options;
std::vector<IniSection *> sections;
std::string magic;
~Ini();
std::string build();
IniOption * findFirstOption(std::string term, bool caseSensitive = true, IniOptionType type = IniOptionType::Any, IniOptionSearchField field = IniOptionSearchField::Key);
IniOption * findOrCreateFirstOption(std::string key, std::string val, bool caseSensitive = true, IniOptionType type = IniOptionType::Any, IniOptionSearchField field = IniOptionSearchField::Key);
std::vector<IniOption *> findAllOptions(std::string term, bool caseSensitive = true, IniOptionType type = IniOptionType::Any, IniOptionSearchField field = IniOptionSearchField::Key);
IniSection * findSection(std::string term, bool caseSensitive = true, IniSectionType type = IniSectionType::Any);
IniSection * findOrCreateSection(std::string term, bool caseSensitive = true, IniSectionType type = IniSectionType::Any);
std::vector<IniSection *> findAllSections(std::string term, bool caseSensitive = true, IniSectionType type = IniSectionType::Any);
bool writeToFile(std::string path);
static Ini * parseFile(std::string path);
static Ini * parseFileWithMagic(std::string path, std::string magic);
static Ini * parseOrCreateFile(std::string path, std::string magic="");
private:
static Ini * _parseContent(std::stringstream * content, std::string magic);
};
}

View file

@ -0,0 +1,32 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <string>
#include "IniOption.hpp"
#include "IniSection.hpp"
namespace simpleIniParser {
class IniHelper {
public:
static bool findOption(const IniOption * obj, std::string term, bool caseSensitive, IniOptionType type, IniOptionSearchField field);
static bool findSection(const IniSection * obj, std::string term, bool caseSensitive, IniSectionType type);
};
}

View file

@ -0,0 +1,45 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <string>
namespace simpleIniParser {
enum class IniOptionType {
Any,
Option,
SemicolonComment,
HashtagComment,
};
enum class IniOptionSearchField {
Key,
Value
};
class IniOption {
public:
IniOptionType type;
std::string key;
std::string value;
IniOption(IniOptionType type, std::string key, std::string val);
std::string build();
static IniOption * parse(std::string line);
};
}

View file

@ -0,0 +1,49 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <string>
#include <vector>
#include "IniOption.hpp"
namespace simpleIniParser {
enum class IniSectionType {
Any,
Section,
SemicolonComment,
HashtagComment,
HekateCaption,
};
class IniSection {
public:
IniSectionType type;
std::string value;
std::vector<IniOption *> options;
IniSection(IniSectionType type, std::string value);
~IniSection();
IniOption * findFirstOption(std::string term, bool caseSensitive = true, IniOptionType type = IniOptionType::Any, IniOptionSearchField field = IniOptionSearchField::Key);
IniOption * findOrCreateFirstOption(std::string key, std::string val, bool caseSensitive = true, IniOptionType type = IniOptionType::Any, IniOptionSearchField field = IniOptionSearchField::Key);
std::vector<IniOption *> findAllOptions(std::string term, bool caseSensitive = true, IniOptionType type = IniOptionType::Any, IniOptionSearchField field = IniOptionSearchField::Key);
std::string build();
static IniSection * parse(std::string line, bool parseComments);
};
}

View file

@ -0,0 +1,20 @@
#pragma once
#include <string>
namespace simpleIniParser {
class IniStringHelper {
public:
static void toupper(std::string &s);
static std::string toupper_copy(std::string s);
// Start of Source from https://stackoverflow.com/questions/216823
static void ltrim(std::string &s);
static void rtrim(std::string &s);
static void trim(std::string &s);
static std::string ltrim_copy(std::string s);
static std::string rtrim_copy(std::string s);
static std::string trim_copy(std::string s);
// End
};
}

View file

@ -0,0 +1,258 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <sstream>
#include <switch.h>
#include "Ini.hpp"
#include "IniHelper.hpp"
#include "IniOption.hpp"
#include "IniStringHelper.hpp"
namespace simpleIniParser {
Ini::~Ini() {
magic = "";
for (IniSection * section : sections) {
if (section != nullptr) {
delete section;
section = nullptr;
}
}
sections.clear();
}
std::string Ini::build() {
std::string result;
if (magic != "") {
result += magic + "\n";
}
for (auto const& option : options) {
result += option->build();
}
for (auto const& section : sections) {
result += section->build();
}
return result;
}
IniOption * Ini::findFirstOption(std::string term, bool caseSensitive, IniOptionType type, IniOptionSearchField field) {
if (!caseSensitive) {
IniStringHelper::toupper(term);
}
auto it = std::find_if(
options.begin(),
options.end(),
std::bind(
IniHelper::findOption,
std::placeholders::_1,
term,
caseSensitive,
type,
field
)
);
if (it == options.end())
return nullptr;
return (*it);
}
IniOption * Ini::findOrCreateFirstOption(std::string key, std::string val, bool caseSensitive, IniOptionType type, IniOptionSearchField field) {
auto it = findFirstOption(key, caseSensitive, type, field);
if (it == nullptr)
{
it = new IniOption(type, key, val);
options.push_back(it);
}
return it;
}
std::vector<IniOption *> Ini::findAllOptions(std::string term, bool caseSensitive, IniOptionType type, IniOptionSearchField field) {
std::vector<IniOption *> results;
if (!caseSensitive) {
IniStringHelper::toupper(term);
}
std::copy_if(
options.begin(),
options.end(),
std::back_inserter(results),
std::bind(
IniHelper::findOption,
std::placeholders::_1,
term,
caseSensitive,
type,
field
)
);
return results;
}
IniSection * Ini::findSection(std::string term, bool caseSensitive, IniSectionType type) {
if (!caseSensitive) {
IniStringHelper::toupper(term);
}
auto it = std::find_if(
sections.begin(),
sections.end(),
std::bind(
IniHelper::findSection,
std::placeholders::_1,
term,
caseSensitive,
type
)
);
if (it == sections.end())
return nullptr;
return (*it);
}
IniSection * Ini::findOrCreateSection(std::string term, bool caseSensitive, IniSectionType type) {
auto it = findSection(term, caseSensitive, type);
if (it == nullptr)
{
it = new IniSection(type, term);
sections.push_back(it);
}
return it;
}
std::vector<IniSection *> Ini::findAllSections(std::string term, bool caseSensitive, IniSectionType type) {
std::vector<IniSection *> results;
if (!caseSensitive) {
IniStringHelper::toupper(term);
}
std::copy_if(
sections.begin(),
sections.end(),
std::back_inserter(results),
std::bind(
IniHelper::findSection,
std::placeholders::_1,
term,
caseSensitive,
type
)
);
return results;
}
bool Ini::writeToFile(std::string path) {
std::ofstream file(path);
if (!file.is_open())
return false;
file << build();
file.flush();
file.close();
fsdevCommitDevice("sdmc");
return true;
}
Ini * Ini::parseFile(std::string path) {
std::ifstream file(path);
if (!file.is_open())
return nullptr;
std::stringstream buffer;
buffer << file.rdbuf();
file.close();
return _parseContent(&buffer, "");
}
Ini * Ini::parseFileWithMagic(std::string path, std::string magic) {
std::ifstream file(path);
if (!file.is_open())
return nullptr;
std::stringstream buffer;
buffer << file.rdbuf();
file.close();
std::string line;
getline(buffer, line);
IniStringHelper::trim(line);
if (line != magic) {
return nullptr;
}
return _parseContent(&buffer, magic);
}
Ini * Ini::parseOrCreateFile(std::string path, std::string magic) {
auto it = Ini::parseFileWithMagic(path, magic);
if (it == nullptr)
it = new Ini();
return it;
}
Ini * Ini::_parseContent(std::stringstream * content, std::string magic) {
Ini * ini = new Ini();
ini->magic = magic;
std::string line;
while (getline(* content, line)) {
IniStringHelper::trim(line);
if (line.size() == 0)
continue;
bool shouldParseCommentsAsSection = ini->sections.size() != 0 && ini->sections.back()->type != IniSectionType::Section;
IniSection * section = IniSection::parse(line, shouldParseCommentsAsSection);
if (section != nullptr) {
ini->sections.push_back(section);
} else {
IniOption * option = IniOption::parse(line);
if (option != nullptr && ini->sections.size() == 0) {
ini->options.push_back(option);
} else if (option != nullptr && ini->sections.size() != 0 && ini->sections.back()->type == IniSectionType::Section) {
ini->sections.back()->options.push_back(option);
}
}
}
return ini;
}
}

View file

@ -0,0 +1,47 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "IniHelper.hpp"
#include "IniStringHelper.hpp"
namespace simpleIniParser {
bool IniHelper::findOption(const IniOption * obj, std::string term, bool caseSensitive, IniOptionType type, IniOptionSearchField field) {
if (type != IniOptionType::Any && type != obj->type) {
return false;
}
std::string fieldValue = "";
if (field == IniOptionSearchField::Key) {
fieldValue = (!caseSensitive) ? IniStringHelper::toupper_copy(obj->key) : obj->key;
} else {
fieldValue = (!caseSensitive) ? IniStringHelper::toupper_copy(obj->value) : obj->value;
}
return fieldValue == term;
}
bool IniHelper::findSection(const IniSection * obj, std::string term, bool caseSensitive, IniSectionType type) {
if (type != IniSectionType::Any && type != obj->type) {
return false;
}
std::string fieldValue = (!caseSensitive) ? IniStringHelper::toupper_copy(obj->value) : obj->value;
return fieldValue == term;
}
}

View file

@ -0,0 +1,55 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "IniOption.hpp"
#include "IniStringHelper.hpp"
namespace simpleIniParser {
IniOption::IniOption(IniOptionType t, std::string k, std::string v) {
type = t;
key = k;
value = v;
}
std::string IniOption::build() {
switch (type) {
case IniOptionType::SemicolonComment:
return "; " + value + "\n";
case IniOptionType::HashtagComment:
return "# " + value + "\n";
default:
return key + "=" + value + "\n";
}
}
IniOption * IniOption::parse(std::string line) {
if (line.at(0) == ';') {
return new IniOption(IniOptionType::SemicolonComment, "", IniStringHelper::trim_copy(line.substr(1, line.size() - 1)));
} else if (line.at(0) == '#') {
return new IniOption(IniOptionType::HashtagComment, "", IniStringHelper::trim_copy(line.substr(1, line.size() - 1)));
} else {
size_t pos = line.find('=');
if (pos != std::string::npos && pos > 0) {
return new IniOption(IniOptionType::Option, IniStringHelper::rtrim_copy(line.substr(0, pos)), IniStringHelper::ltrim_copy(line.substr(pos + 1)));
} else {
return nullptr;
}
}
}
}

View file

@ -0,0 +1,136 @@
/*
* SimpleIniParser
* Copyright (c) 2020 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <algorithm>
#include <functional>
#include <iostream>
#include "IniHelper.hpp"
#include "IniSection.hpp"
#include "IniStringHelper.hpp"
namespace simpleIniParser {
IniSection::IniSection(IniSectionType t, std::string v) {
type = t;
value = v;
}
IniSection::~IniSection() {
for (IniOption * option : options) {
if (option != nullptr) {
delete option;
option = nullptr;
}
}
options.clear();
}
IniOption * IniSection::findFirstOption(std::string term, bool caseSensitive, IniOptionType type, IniOptionSearchField field) {
if (!caseSensitive) {
IniStringHelper::toupper(term);
}
auto it = std::find_if(
options.begin(),
options.end(),
std::bind(
IniHelper::findOption,
std::placeholders::_1,
term,
caseSensitive,
type,
field
)
);
if (it == options.end())
return nullptr;
return (*it);
}
IniOption * IniSection::findOrCreateFirstOption(std::string key, std::string val, bool caseSensitive, IniOptionType type, IniOptionSearchField field) {
auto it = findFirstOption(key, caseSensitive, type, field);
if (it == nullptr)
{
it = new IniOption(type, key, val);
options.push_back(it);
}
return it;
}
std::vector<IniOption *> IniSection::findAllOptions(std::string term, bool caseSensitive, IniOptionType type, IniOptionSearchField field) {
std::vector<IniOption *> results;
if (!caseSensitive) {
IniStringHelper::toupper(term);
}
std::copy_if(
options.begin(),
options.end(),
std::back_inserter(results),
std::bind(
IniHelper::findOption,
std::placeholders::_1,
term,
caseSensitive,
type,
field
)
);
return results;
}
std::string IniSection::build() {
switch (type) {
case IniSectionType::HekateCaption:
return "\n{" + value + "}\n";
case IniSectionType::SemicolonComment:
return "\n; " + value + "\n";
case IniSectionType::HashtagComment:
return "\n# " + value + "\n";
default:
std::string result = "\n[" + value + "]\n";
for (auto const& option : options) {
result += option->build();
}
return result;
}
}
IniSection * IniSection::parse(std::string line, bool parseComments) {
if (line.at(0) == '{' && line.at(line.size() - 1) == '}') {
return new IniSection(IniSectionType::HekateCaption, IniStringHelper::trim_copy(line.substr(1, line.size() - 2)));
} else if (parseComments && line.at(0) == ';') {
return new IniSection(IniSectionType::SemicolonComment, IniStringHelper::trim_copy(line.substr(1, line.size() - 1)));
} else if (parseComments && line.at(0) == '#') {
return new IniSection(IniSectionType::HashtagComment, IniStringHelper::trim_copy(line.substr(1, line.size() - 1)));
} else if (line.at(0) == '[' && line.at(line.size() - 1) == ']') {
return new IniSection(IniSectionType::Section, IniStringHelper::trim_copy(line.substr(1, line.size() - 2)));
} else {
return nullptr;
}
}
}

View file

@ -0,0 +1,56 @@
#include <algorithm>
#include <cctype>
#include <locale>
#include "IniStringHelper.hpp"
namespace simpleIniParser {
void IniStringHelper::toupper(std::string &s) {
for_each(s.begin(), s.end(), [](char & c){
c = ::toupper(c);
});
}
std::string IniStringHelper::toupper_copy(std::string s) {
toupper(s);
return s;
}
// Start of Source from https://stackoverflow.com/questions/216823
void IniStringHelper::ltrim(std::string &s) {
s.erase(s.begin(), find_if(s.begin(), s.end(), [](int ch) {
return !isspace(ch);
}));
}
void IniStringHelper::rtrim(std::string &s) {
s.erase(find_if(s.rbegin(), s.rend(), [](int ch) {
return !isspace(ch);
}).base(), s.end());
}
void IniStringHelper::trim(std::string &s) {
ltrim(s);
rtrim(s);
}
std::string IniStringHelper::ltrim_copy(std::string s) {
ltrim(s);
return s;
}
std::string IniStringHelper::rtrim_copy(std::string s) {
rtrim(s);
return s;
}
std::string IniStringHelper::trim_copy(std::string s) {
trim(s);
return s;
}
// End
}

13
Swurl/LICENSE Normal file
View file

@ -0,0 +1,13 @@
Copyright (c) 2019 Nichole Mattera
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

157
Swurl/Makefile Normal file
View file

@ -0,0 +1,157 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
include $(DEVKITPRO)/libnx/switch_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# 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
#---------------------------------------------------------------------------------
TARGET := Swurl
VERSION := 1.0.0
SOURCES := source source/Swurl
INCLUDES := include include/Swurl
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
CFLAGS := -g -Wall -Werror \
-ffunction-sections \
-fdata-sections \
$(ARCH) \
$(BUILD_CFLAGS)
CFLAGS += $(INCLUDE)
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
ifneq (,$(shell which ccache))
CXX := $(shell which ccache) $(CXX)
CC := $(shell which ccache) $(CC)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX)
#---------------------------------------------------------------------------------
# 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 VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
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 := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I. \
-iquote $(CURDIR)/include/switch/
.PHONY: clean all
#---------------------------------------------------------------------------------
all: lib/lib$(TARGET).a lib/lib$(TARGET)d.a
lib:
@[ -d $@ ] || mkdir -p $@
release:
@[ -d $@ ] || mkdir -p $@
debug:
@[ -d $@ ] || mkdir -p $@
lib/lib$(TARGET).a : lib release $(SOURCES) $(INCLUDES)
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
BUILD_CFLAGS="-DNDEBUG=1 -O2" \
DEPSDIR=$(CURDIR)/release \
--no-print-directory -C release \
-f $(CURDIR)/Makefile
lib/lib$(TARGET)d.a : lib debug $(SOURCES) $(INCLUDES)
@$(MAKE) BUILD=debug OUTPUT=$(CURDIR)/$@ \
BUILD_CFLAGS="-DDEBUG=1 -Og" \
DEPSDIR=$(CURDIR)/debug \
--no-print-directory -C debug \
-f $(CURDIR)/Makefile
dist-bin: all
@tar --exclude=*~ -cjf lib$(TARGET)-$(VERSION).tar.bz2 include lib LICENSE
dist-src:
@tar --exclude=*~ -cjf lib$(TARGET)-src-$(VERSION).tar.bz2 example include source LICENSE Makefile README.md
dist: dist-src dist-bin
install: dist-bin
mkdir -p $(DESTDIR)$(PORTLIBS)
bzip2 -cd lib$(TARGET)-$(VERSION).tar.bz2 | tar -xf - -C $(DESTDIR)$(PORTLIBS)
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr release debug lib *.bz2
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT) : $(OFILES)
$(OFILES_SRC) : $(HFILES)
#---------------------------------------------------------------------------------
%_bin.h %.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

11
Swurl/README.md Normal file
View file

@ -0,0 +1,11 @@
# Swurl
A wrapper library for CURL on the Nintendo Switch. The objective is to have a simple library where you can pass it a request and recieve back calls on its progress updates, completion and if it incountered an error. Right now the response object is very basic with the parsed headers, raw headers, raw body, and status code. However I plan on in the future allowing for you to pass the response type through the request and have the body be parsed out. (Ex JSON)
## Installation
I recommend adding this as a git submodule to your and then modifying your makefile to look in this directory for libs. For examples on how to do this please look at [Isotope Updater](https://github.com/Team-Neptune/Isotope-Updater).
## Usage
I've included an example under the example folder. Remember to add `-lSwurl -lcurl -lz -lmbedtls -lmbedx509 -lmbedcrypto` to `LIBS` in your makefile. Other than that remember to run `SessionManager::initialize();` at the beginning of your app as this initializes sockets and curl, and call `SessionManager::dealloc();` when cleaning up your app as this closes sockets and curl.

20
Swurl/include/Swurl.hpp Normal file
View file

@ -0,0 +1,20 @@
/*
* Swurl
* Copyright (c) 2019 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "Swurl/SessionManager.hpp"
#include "Swurl/WebRequest.hpp"
#include "Swurl/WebResponse.hpp"

View file

@ -0,0 +1,52 @@
/*
* Swurl
* Copyright (c) 2019 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <string>
#include <map>
#include <functional>
#include <curl/curl.h>
#include "WebRequest.hpp"
namespace swurl {
class SessionManager {
public:
static std::string proxyUrl;
static std::string proxyUsername;
static std::string proxyPassword;
static std::string userAgent;
static std::map<std::string, std::string> requestHeaders;
static std::function<void(WebRequest *, double)> onProgressChanged;
static std::function<void(WebRequest *)> onCompleted;
static std::function<void(WebRequest *, std::string)> onError;
static void initialize();
static void dealloc();
static void makeRequest(WebRequest * request);
private:
static curl_slist * _generateHeaders(WebRequest * request);
static std::string _getMethod(WebRequest * request);
static size_t _writeHeader(const char * in, std::size_t size, std::size_t num, WebRequest * request);
static size_t _write(const char* in, std::size_t size, std::size_t num, WebRequest * request);
static size_t _progress(WebRequest * request, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
static void _parseResponseHeader(WebRequest * request);
};
}

View file

@ -0,0 +1,45 @@
/*
* Swurl
* Copyright (c) 2019 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <string>
#include <map>
#include "WebResponse.hpp"
namespace swurl {
typedef enum {
GET,
POST,
PUT,
DELETE
} WebRequestMethod;
class WebRequest {
public:
WebRequestMethod method;
std::string url;
std::map<std::string, std::string> headers;
bool sslVerifyHost;
WebResponse response;
WebRequest(std::string url);
WebRequest(WebRequestMethod method, std::string url);
WebRequest(WebRequestMethod method, std::string url, std::map<std::string, std::string> headers);
};
}

View file

@ -0,0 +1,31 @@
/*
* Swurl
* Copyright (c) 2019 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <string>
#include <map>
namespace swurl {
class WebResponse {
public:
std::map<std::string, std::string> headers;
std::string rawResponseHeader;
std::string rawResponseBody;
long statusCode;
};
}

View file

@ -0,0 +1,190 @@
/*
* Swurl
* Copyright (c) 2019 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sstream>
#include <switch.h>
#include "SessionManager.hpp"
#include "WebResponse.hpp"
using namespace std;
namespace swurl {
std::string SessionManager::proxyUrl = "";
std::string SessionManager::proxyUsername = "";
std::string SessionManager::proxyPassword = "";
std::string SessionManager::userAgent = "";
std::map<std::string, std::string> SessionManager::requestHeaders;
std::function<void(WebRequest *, double)> SessionManager::onProgressChanged;
std::function<void(WebRequest *)> SessionManager::onCompleted;
std::function<void(WebRequest *, std::string)> SessionManager::onError;
void SessionManager::initialize() {
socketInitializeDefault();
curl_global_init(CURL_GLOBAL_ALL);
}
void SessionManager::dealloc() {
curl_global_cleanup();
socketExit();
}
void SessionManager::makeRequest(WebRequest * request) {
CURL * curl = curl_easy_init();
if (!curl) {
onError(request, "Unable to initialize CURL.");
return;
}
struct curl_slist * headers = _generateHeaders(request);
if (headers != NULL) {
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
}
if (userAgent.size() > 0) {
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());
}
if (proxyUrl.size() > 0) {
curl_easy_setopt(curl, CURLOPT_PROXY, proxyUrl.c_str());
if (proxyUsername.size() > 0) {
curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME, proxyUsername.c_str());
if (proxyPassword.size() > 0)
curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD, proxyPassword.c_str());
}
}
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, _getMethod(request).c_str());
curl_easy_setopt(curl, CURLOPT_URL, request->url.c_str());
// TODO: For this to work you have to pass CURL a CA bundle.
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
if (!request->sslVerifyHost) {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
}
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, _writeHeader);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, (void *) request);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _write);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) request);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, _progress);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, (void *) request);
CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK) {
onError(request, string(curl_easy_strerror(res)));
curl_easy_cleanup(curl);
curl_slist_free_all(headers);
return;
}
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &request->response.statusCode);
curl_easy_cleanup(curl);
curl_slist_free_all(headers);
_parseResponseHeader(request);
onCompleted(request);
}
curl_slist * SessionManager::_generateHeaders(WebRequest * request) {
struct curl_slist * result = NULL;
// Add the global headers.
map<string, string>::iterator glIt;
for (glIt = requestHeaders.begin(); glIt != requestHeaders.end(); glIt++) {
// Skip global headers that have been overwritten in the request.
auto findReqIt = request->headers.find(glIt->first);
if (findReqIt == request->headers.end()) {
result = curl_slist_append(result, (glIt->first + ": " + glIt->second).c_str());
}
}
// Add the request headers.
map<string, string>::iterator reqIt;
for (reqIt = request->headers.begin(); reqIt != request->headers.end(); reqIt++) {
result = curl_slist_append(result, (reqIt->first + ": " + reqIt->second).c_str());
}
return result;
}
string SessionManager::_getMethod(WebRequest * request) {
switch (request->method) {
case GET:
return "GET";
case POST:
return "POST";
case PUT:
return "PUT";
case DELETE:
return "DELETE";
}
return NULL;
}
size_t SessionManager::_writeHeader(const char * in, size_t size, size_t num, WebRequest * request) {
const size_t totalBytes(size * num);
request->response.rawResponseHeader.append(in, totalBytes);
return totalBytes;
}
size_t SessionManager::_write(const char * in, size_t size, size_t num, WebRequest * request) {
const size_t totalBytes(size * num);
request->response.rawResponseBody.append(in, totalBytes);
return totalBytes;
}
size_t SessionManager::_progress(WebRequest * request, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) {
auto progress = (double) dlnow / (double) dltotal;
if (onProgressChanged) {
onProgressChanged(request, progress);
}
return 0;
}
void SessionManager::_parseResponseHeader(WebRequest * request) {
if (request->response.rawResponseHeader.size() != 0) {
istringstream ss(request->response.rawResponseHeader);
string header;
while(getline(ss, header)) {
if (header.size() == 0)
continue;
auto colonPos = header.find(":");
if (colonPos != string::npos) {
request->response.headers.insert(
pair<string, string>(
header.substr(0, colonPos),
header.substr(colonPos + 2, header.size() - (colonPos + 2))
)
);
}
}
}
}
}

View file

@ -0,0 +1,36 @@
/*
* Swurl
* Copyright (c) 2019 Nichole Mattera
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <switch.h>
#include "SessionManager.hpp"
using namespace std;
namespace swurl {
WebRequest::WebRequest(std::string url) : WebRequest(GET, url) {}
WebRequest::WebRequest(WebRequestMethod method, std::string url) {
this->method = method;
this->url = url;
this->sslVerifyHost = true;
}
WebRequest::WebRequest(WebRequestMethod method, std::string url, std::map<std::string, std::string> headers) : WebRequest(method, url) {
this->headers = headers;
}
}

BIN
icon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
romfs/dark/downloading.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
romfs/dark/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

BIN
romfs/light/downloading.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
romfs/light/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

140
source/AssetManager.cpp Normal file
View file

@ -0,0 +1,140 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "AssetManager.hpp"
#include "SceneDirector.hpp"
using namespace std;
namespace dsu {
void AssetManager::dealloc() {
if (AssetManager::large_button_font != NULL)
TTF_CloseFont(AssetManager::large_button_font);
if (AssetManager::button_font != NULL)
TTF_CloseFont(AssetManager::button_font);
if (AssetManager::subbody_font != NULL)
TTF_CloseFont(AssetManager::subbody_font);
if (AssetManager::body_font != NULL)
TTF_CloseFont(AssetManager::body_font);
if (AssetManager::header_font != NULL)
TTF_CloseFont(AssetManager::header_font);
if (AssetManager::icon != NULL)
SDL_DestroyTexture(AssetManager::icon);
if (AssetManager::downloading != NULL)
SDL_DestroyTexture(AssetManager::downloading);
if (AssetManager::checkmark != NULL)
SDL_DestroyTexture(AssetManager::checkmark);
if (AssetManager::handheld != NULL)
SDL_DestroyTexture(AssetManager::handheld);
if (AssetManager::y_button != NULL)
SDL_DestroyTexture(AssetManager::y_button);
if (AssetManager::x_button != NULL)
SDL_DestroyTexture(AssetManager::x_button);
if (AssetManager::b_button != NULL)
SDL_DestroyTexture(AssetManager::b_button);
if (AssetManager::a_button != NULL)
SDL_DestroyTexture(AssetManager::a_button);
}
bool AssetManager::initialize() {
Result rc;
setsysGetColorSetId(&AssetManager::theme);
if (AssetManager::theme == ColorSetId_Light) {
AssetManager::background = { 235, 235, 235, 255 };
AssetManager::sidebard_background = { 240, 240, 240, 255 };
AssetManager::header_footer_divider = { 45, 45, 45, 255 };
AssetManager::header_bullet = { 121, 121, 121, 255 };
AssetManager::list_divider = { 205, 205, 205, 255 };
AssetManager::active_player_indicator = { 158, 228, 0, 255 };
AssetManager::player_indicator = { 125, 125, 125, 255 };
AssetManager::selected_background = { 253, 253, 253, 255 };
AssetManager::selected_border_1 = { 0, 255, 196, 255 };
AssetManager::selected_border_2 = { 22, 146, 197, 255 };
AssetManager::modal_faded_background = { 18, 27, 36, 229 };
AssetManager::modal_background = { 240, 240, 240, 255 };
AssetManager::text = { 45, 45, 45, 255 };
AssetManager::active_text = { 50, 80, 240, 255 };
AssetManager::disabled_text = { 165, 165, 165, 255 };
} else {
AssetManager::background = { 45, 45, 45, 255 };
AssetManager::sidebard_background = { 51, 51, 51, 255 };
AssetManager::header_footer_divider = { 255, 255, 255, 255 };
AssetManager::header_bullet = { 160, 160, 160, 255 };
AssetManager::list_divider = { 77, 77, 77, 255 };
AssetManager::active_player_indicator = { 158, 228, 0, 255 };
AssetManager::player_indicator = { 125, 125, 125, 255 };
AssetManager::selected_background = { 31, 34, 39, 255 };
AssetManager::selected_border_1 = { 0, 255, 196, 255 };
AssetManager::selected_border_2 = { 22, 146, 197, 255 };
AssetManager::modal_faded_background = { 18, 27, 36, 229 };
AssetManager::modal_background = { 70, 70, 70, 255 };
AssetManager::text = { 255, 255, 255, 255 };
AssetManager::active_text = { 0, 255, 196, 255 };
AssetManager::disabled_text = { 125, 125, 125, 255 };
}
rc = plGetSharedFontByType(&AssetManager::standardFontData, PlSharedFontType_Standard);
if (R_FAILED(rc))
return false;
AssetManager::header_font = TTF_OpenFontRW(SDL_RWFromMem(AssetManager::standardFontData.address, AssetManager::standardFontData.size), 1, 28);
AssetManager::body_font = TTF_OpenFontRW(SDL_RWFromMem(AssetManager::standardFontData.address, AssetManager::standardFontData.size), 1, 23);
AssetManager::subbody_font = TTF_OpenFontRW(SDL_RWFromMem(AssetManager::standardFontData.address, AssetManager::standardFontData.size), 1, 18);
if (!AssetManager::header_font || !AssetManager::body_font)
return false;
rc = plGetSharedFontByType(&AssetManager::extendedFontData, PlSharedFontType_NintendoExt);
if (R_FAILED(rc))
return false;
AssetManager::button_font = TTF_OpenFontRW(SDL_RWFromMem(AssetManager::extendedFontData.address, AssetManager::extendedFontData.size), 1, 25);
if (!AssetManager::button_font)
return false;
AssetManager::large_button_font = TTF_OpenFontRW(SDL_RWFromMem(AssetManager::extendedFontData.address, AssetManager::extendedFontData.size), 1, 70);
if (!AssetManager::large_button_font)
return false;
return true;
}
void AssetManager::setRenderColor(SDL_Color color) {
SDL_SetRenderDrawColor(SceneDirector::renderer, color.r, color.g, color.b, color.a);
}
SDL_Texture * AssetManager::loadAsset(string file) {
string themeDirectory = (AssetManager::theme == ColorSetId_Light) ? "light" : "dark";
string path = "romfs:/" + themeDirectory + "/" + file;
SDL_Surface * image = IMG_Load(path.c_str());
SDL_Texture * texture = SDL_CreateTextureFromSurface(SceneDirector::renderer, image);
SDL_FreeSurface(image);
return texture;
}
}

71
source/AssetManager.hpp Normal file
View file

@ -0,0 +1,71 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <string>
#include <switch.h>
namespace dsu {
class AssetManager {
public:
/* Textures */
static inline SDL_Texture * a_button = NULL;
static inline SDL_Texture * b_button = NULL;
static inline SDL_Texture * x_button = NULL;
static inline SDL_Texture * y_button = NULL;
static inline SDL_Texture * handheld = NULL;
static inline SDL_Texture * checkmark = NULL;
static inline SDL_Texture * downloading = NULL;
static inline SDL_Texture * icon = NULL;
/* Colors */
static inline ColorSetId theme;
static inline SDL_Color background;
static inline SDL_Color sidebard_background;
static inline SDL_Color header_footer_divider;
static inline SDL_Color header_bullet;
static inline SDL_Color list_divider;
static inline SDL_Color active_player_indicator;
static inline SDL_Color player_indicator;
static inline SDL_Color selected_background;
static inline SDL_Color selected_border_1;
static inline SDL_Color selected_border_2;
static inline SDL_Color modal_faded_background;
static inline SDL_Color modal_background;
static inline SDL_Color text;
static inline SDL_Color active_text;
static inline SDL_Color disabled_text;
/* Fonts */
static inline PlFontData standardFontData;
static inline TTF_Font * header_font = NULL;
static inline TTF_Font * body_font = NULL;
static inline TTF_Font * subbody_font = NULL;
static inline PlFontData extendedFontData;
static inline TTF_Font * button_font = NULL;
static inline TTF_Font * large_button_font = NULL;
static bool initialize();
static void dealloc();
static void setRenderColor(SDL_Color color);
static SDL_Texture * loadAsset(std::string file);
};
}

363
source/ConfigManager.cpp Normal file
View file

@ -0,0 +1,363 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "ConfigManager.hpp"
using namespace std;
namespace dsu {
void ConfigManager::initialize() {
config_init(&_cfg);
config_init(&_internalDb);
if(!config_read_file(&_internalDb, INTERNAL_FILENAME.c_str())) {
config_setting_t * root, * setting;
root = config_root_setting(&_internalDb);
setting = config_setting_add(root, VERSION_KEY.c_str(), CONFIG_TYPE_STRING);
config_setting_set_string(setting, VERSION_DEF.c_str());
setting = config_setting_add(root, INSTALLED_FILES_KEY.c_str(), CONFIG_TYPE_ARRAY);
setting = config_setting_add(root, RECEIVED_EXFAT_WARNING_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, RECEIVED_EXFAT_WARNING_DEF);
// setting = config_setting_add(root, RECEIVED_IGNORE_CONFIG_WARNING_KEY.c_str(), CONFIG_TYPE_BOOL);
// config_setting_set_bool(setting, RECEIVED_IGNORE_CONFIG_WARNING_DEF);
setting = config_setting_add(root, IGNORE_CONFIG_FILES_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, IGNORE_CONFIG_FILES_DEF);
setting = config_setting_add(root, CONFIG_VERSION_KEY.c_str(), CONFIG_TYPE_INT);
config_setting_set_int(setting, INTERNAL_CONFIG_VERSION);
config_write_file(&_internalDb, INTERNAL_FILENAME.c_str());
}
if(!config_read_file(&_cfg, CONFIG_FILENAME.c_str())) {
config_setting_t * root, * setting;
root = config_root_setting(&_cfg);
setting = config_setting_add(root, IGNORE_KEY.c_str(), CONFIG_TYPE_ARRAY);
setting = config_setting_add(root, AUTOUPDATE_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, AUTOUPDATE_DEF);
setting = config_setting_add(root, PROXY_ENABLED_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(setting, PROXY_ENABLED_DEF);
setting = config_setting_add(root, PROXY_URL_KEY.c_str(), CONFIG_TYPE_STRING);
config_setting_set_string(setting, PROXY_URL_DEF.c_str());
setting = config_setting_add(root, PROXY_USERNAME_KEY.c_str(), CONFIG_TYPE_STRING);
config_setting_set_string(setting, PROXY_USERNAME_DEF.c_str());
setting = config_setting_add(root, PROXY_PASSWORD_KEY.c_str(), CONFIG_TYPE_STRING);
config_setting_set_string(setting, PROXY_PASSWORD_DEF.c_str());
setting = config_setting_add(root, CONFIG_VERSION_KEY.c_str(), CONFIG_TYPE_INT);
config_setting_set_int(setting, SETTING_CONFIG_VERSION);
config_write_file(&_cfg, CONFIG_FILENAME.c_str());
}
_migrateConfigFiles();
}
void ConfigManager::dealloc() {
config_destroy(&_cfg);
config_destroy(&_internalDb);
}
vector<string> ConfigManager::getFilesToIgnore() {
vector<string> defaultValue;
return _readArrayOfStrings(IGNORE_KEY, defaultValue, _cfg);
}
bool ConfigManager::shouldAutoUpdate() {
#ifdef DEBUG
return false;
#endif
return _readBoolean(AUTOUPDATE_KEY, AUTOUPDATE_DEF, _cfg);
}
bool ConfigManager::shouldUseProxy() {
return _readBoolean(PROXY_ENABLED_KEY, PROXY_ENABLED_DEF, _cfg);
}
string ConfigManager::getProxy() {
return _readString(PROXY_URL_KEY, PROXY_URL_DEF, _cfg);
}
string ConfigManager::getProxyUsername() {
return _readString(PROXY_USERNAME_KEY, PROXY_USERNAME_DEF, _cfg);
}
string ConfigManager::getProxyPassword() {
return _readString(PROXY_PASSWORD_KEY, PROXY_PASSWORD_DEF, _cfg);
}
int ConfigManager::getSettingsConfigVersion() {
return _readInt(CONFIG_VERSION_KEY, CONFIG_VERSION_DEF, _cfg);
}
bool ConfigManager::setFilesToIgnore(vector<string> files) {
return _appendArrayOfStrings(IGNORE_KEY, files, _cfg, CONFIG_FILENAME);
}
string ConfigManager::getCurrentVersion() {
return _readString(VERSION_KEY, VERSION_DEF, _internalDb);
}
vector<string> ConfigManager::getInstalledFiles() {
vector<string> defaultValue;
return _readArrayOfStrings(INSTALLED_FILES_KEY, defaultValue, _internalDb);
}
bool ConfigManager::getReceivedExFATWarning() {
return _readBoolean(RECEIVED_EXFAT_WARNING_KEY, RECEIVED_EXFAT_WARNING_DEF, _internalDb);
}
// bool ConfigManager::getReceivedIgnoreConfigWarning() {
// return _readBoolean(RECEIVED_IGNORE_CONFIG_WARNING_KEY, RECEIVED_IGNORE_CONFIG_WARNING_DEF, _internalDb);
// }
bool ConfigManager::getIgnoreConfigFiles() {
return _readBoolean(IGNORE_CONFIG_FILES_KEY, IGNORE_CONFIG_FILES_DEF, _internalDb);
}
int ConfigManager::getInternalConfigVersion() {
return _readInt(CONFIG_VERSION_KEY, CONFIG_VERSION_DEF, _internalDb);
}
bool ConfigManager::setCurrentVersion(string version) {
return _writeString(VERSION_KEY, version, _internalDb, INTERNAL_FILENAME);
}
bool ConfigManager::setInstalledFiles(vector<string> files) {
return _writeArrayOfStrings(INSTALLED_FILES_KEY, files, _internalDb, INTERNAL_FILENAME);
}
bool ConfigManager::setReceivedExFATWarning(bool received) {
return _writeBoolean(RECEIVED_EXFAT_WARNING_KEY, received, _internalDb, INTERNAL_FILENAME);
}
// bool ConfigManager::setReceivedIgnoreConfigWarning(bool received) {
// return _writeBoolean(RECEIVED_IGNORE_CONFIG_WARNING_KEY, received, _internalDb, INTERNAL_FILENAME);
// }
bool ConfigManager::setIgnoreConfigFiles(bool ignore) {
return _writeBoolean(IGNORE_CONFIG_FILES_KEY, ignore, _internalDb, INTERNAL_FILENAME);
}
// Private Methods
bool ConfigManager::_readBoolean(string key, bool def, config_t config) {
int result;
if (!config_lookup_bool(&config, key.c_str(), &result))
return def;
return result;
}
int ConfigManager::_readInt(std::string key, int def, config_t config) {
int result;
if (!config_lookup_int(&config, key.c_str(), &result))
return def;
return result;
}
string ConfigManager::_readString(string key, string def, config_t config) {
const char * result;
if (!config_lookup_string(&config, key.c_str(), &result))
return def;
return string(result);
}
vector<string> ConfigManager::_readArrayOfStrings(string key, vector<string> def, config_t config) {
vector<string> result;
config_setting_t * array = config_lookup(&config, key.c_str());
if (array == NULL)
return def;
int count = config_setting_length(array);
for (int i = 0; i < count; i++) {
auto file = string(config_setting_get_string_elem(array, i));
if (file.substr(0,1) == "/") {
result.push_back("sdmc:" + file);
}
else if (file.substr(0,7) == "sdmc://") {
result.push_back("sdmc:/" + file.substr(7, file.length() - 7));
}
else {
result.push_back(file);
}
}
return result;
}
bool ConfigManager::_writeBoolean(string key, bool value, config_t config, string filename) {
config_setting_t * root, * setting;
root = config_root_setting(&config);
setting = config_setting_get_member(root, key.c_str());
if (setting == NULL) {
setting = config_setting_add(root, key.c_str(), CONFIG_TYPE_BOOL);
}
config_setting_set_bool(setting, value);
return config_write_file(&config, filename.c_str());
}
bool ConfigManager::_writeString(string key, string value, config_t config, string filename) {
config_setting_t * root, * setting;
root = config_root_setting(&config);
setting = config_setting_get_member(root, key.c_str());
if (setting == NULL) {
setting = config_setting_add(root, key.c_str(), CONFIG_TYPE_STRING);
}
config_setting_set_string(setting, value.c_str());
return config_write_file(&config, filename.c_str());
}
bool ConfigManager::_writeArrayOfStrings(string key, vector<string> values, config_t config, string filename) {
config_setting_t * root = config_root_setting(&config);
config_setting_remove(root, key.c_str());
config_setting_t * array = config_setting_add(root, key.c_str(), CONFIG_TYPE_ARRAY);
for (auto const& value : values) {
config_setting_set_string_elem(array, -1, value.c_str());
}
return config_write_file(&config, filename.c_str());
}
bool ConfigManager::_appendArrayOfStrings(string key, vector<string> values, config_t config, string filename) {
config_setting_t * root = config_root_setting(&config);
config_setting_t * array = config_lookup(&config, key.c_str());
if (array == NULL)
array = config_setting_add(root, key.c_str(), CONFIG_TYPE_ARRAY);
for (auto const& value : values) {
config_setting_set_string_elem(array, -1, value.c_str());
}
return config_write_file(&config, filename.c_str());
}
bool ConfigManager::_removeSetting(string key, config_t config, string filename) {
config_setting_t * root = config_root_setting(&config);
config_setting_remove(root, key.c_str());
return config_write_file(&config, filename.c_str());
}
void ConfigManager::_migrateConfigFiles() {
auto settingsVersion = getSettingsConfigVersion();
auto internalVersion = getInternalConfigVersion();
if (internalVersion < INTERNAL_CONFIG_VERSION) {
_migrateInternalConfigFiles(internalVersion);
}
if (settingsVersion < SETTING_CONFIG_VERSION) {
_migrateSettingsConfigFiles(settingsVersion);
}
}
void ConfigManager::_migrateSettingsConfigFiles(int currentVersion) {
bool configChanged = false;
config_setting_t * root = config_root_setting(&_cfg);
if (currentVersion < 2) {
configChanged = true;
config_setting_remove(root, "host");
// Migrate sys-ftp path.
config_setting_t * ignoredFiles = config_lookup(&_cfg, IGNORE_KEY.c_str());
if (ignoredFiles != NULL) {
int count = config_setting_length(ignoredFiles);
for (int i = 0; i < count; i++) {
auto file = string(config_setting_get_string_elem(ignoredFiles, i));
if (file == "sdmc:/config/ftpd/config.ini") {
config_setting_set_string_elem(ignoredFiles, i, "sdmc:/config/sys-ftpd/config.ini");
setIgnoreConfigFiles(true);
break;
}
}
}
// Added config version for future migrations
if (currentVersion < 1) {
config_setting_t * configVersion = config_setting_add(root, CONFIG_VERSION_KEY.c_str(), CONFIG_TYPE_INT);
config_setting_set_int(configVersion, 2);
} else {
config_setting_t * configVersion = config_setting_get_member(root, CONFIG_VERSION_KEY.c_str());
config_setting_set_int(configVersion, 2);
}
}
if (configChanged) {
config_write_file(&_cfg, CONFIG_FILENAME.c_str());
}
}
void ConfigManager::_migrateInternalConfigFiles(int currentVersion) {
bool configChanged = false;
config_setting_t * root = config_root_setting(&_internalDb);
if (currentVersion < 1 && config_lookup(&_internalDb, IGNORE_CONFIG_FILES_KEY.c_str()) == NULL) {
configChanged = true;
// Added setting in internal to keep track of if the user is ignoring config files.
config_setting_t * ignoreConfigFiles = config_setting_add(root, IGNORE_CONFIG_FILES_KEY.c_str(), CONFIG_TYPE_BOOL);
config_setting_set_bool(ignoreConfigFiles, IGNORE_CONFIG_FILES_DEF);
}
if (currentVersion < 2) {
configChanged = true;
if (config_lookup(&_internalDb, CONFIG_VERSION_KEY.c_str()) == NULL) {
// Added separate config version to internal db.
config_setting_t * configVersion = config_setting_add(root, CONFIG_VERSION_KEY.c_str(), CONFIG_TYPE_INT);
config_setting_set_int(configVersion, 2);
} else {
// How???
config_setting_t * configVersion = config_lookup(&_internalDb, CONFIG_VERSION_KEY.c_str());
config_setting_set_int(configVersion, 2);
}
}
if (configChanged) {
config_write_file(&_internalDb, INTERNAL_FILENAME.c_str());
}
}
}

112
source/ConfigManager.hpp Normal file
View file

@ -0,0 +1,112 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <libconfig.h>
#include <string>
#include <vector>
namespace dsu {
class ConfigManager {
public:
static void initialize();
static void dealloc();
static std::vector<std::string> getFilesToIgnore();
static bool shouldAutoUpdate();
static bool shouldUseProxy();
static std::string getProxy();
static std::string getProxyUsername();
static std::string getProxyPassword();
static int getSettingsConfigVersion();
static bool setFilesToIgnore(std::vector<std::string> files);
static std::string getCurrentVersion();
static std::vector<std::string> getInstalledFiles();
static bool getReceivedExFATWarning();
// static bool getReceivedIgnoreConfigWarning();
static bool getIgnoreConfigFiles();
static int getInternalConfigVersion();
static bool setCurrentVersion(std::string version);
static bool setInstalledFiles(std::vector<std::string> files);
static bool setReceivedExFATWarning(bool received);
// static bool setReceivedIgnoreConfigWarning(bool received);
static bool setIgnoreConfigFiles(bool ignore);
private:
static inline config_t _cfg;
static inline config_t _internalDb;
static bool _readBoolean(std::string key, bool def, config_t config);
static int _readInt(std::string key, int def, config_t config);
static std::string _readString(std::string key, std::string def, config_t config);
static std::vector<std::string> _readArrayOfStrings(std::string key, std::vector<std::string> def, config_t config);
static bool _writeBoolean(std::string key, bool value, config_t config, std::string filename);
static bool _writeString(std::string key, std::string value, config_t config, std::string filename);
static bool _writeArrayOfStrings(std::string key, std::vector<std::string> values, config_t config, std::string filename);
static bool _appendArrayOfStrings(std::string key, std::vector<std::string> values, config_t config, std::string filename);
static bool _removeSetting(std::string key, config_t config, std::string filename);
static void _migrateConfigFiles();
static void _migrateSettingsConfigFiles(int currentVersion);
static void _migrateInternalConfigFiles(int currentVersion);
static inline const std::string CONFIG_FILENAME = "settings.cfg";
static inline const std::string INTERNAL_FILENAME = "internal.db";
static inline const std::string IGNORE_KEY = "ignore";
static inline const std::string AUTOUPDATE_KEY = "autoupdate";
static inline const bool AUTOUPDATE_DEF = true;
static inline const std::string PROXY_ENABLED_KEY = "proxy_enabled";
static inline const bool PROXY_ENABLED_DEF = false;
static inline const std::string PROXY_URL_KEY = "proxy_url";
static inline const std::string PROXY_URL_DEF = "";
static inline const std::string PROXY_USERNAME_KEY = "proxy_username";
static inline const std::string PROXY_USERNAME_DEF = "";
static inline const std::string PROXY_PASSWORD_KEY = "proxy_password";
static inline const std::string PROXY_PASSWORD_DEF = "";
static inline const std::string VERSION_KEY = "version";
static inline const std::string VERSION_DEF = "";
static inline const std::string INSTALLED_FILES_KEY = "installed_files";
static inline const std::string RECEIVED_EXFAT_WARNING_KEY = "received_exfat_warning";
static inline const bool RECEIVED_EXFAT_WARNING_DEF = false;
// static inline const std::string RECEIVED_IGNORE_CONFIG_WARNING_KEY = "received_ignore_config_warning";
// static inline const bool RECEIVED_IGNORE_CONFIG_WARNING_DEF = false;
static inline const std::string IGNORE_CONFIG_FILES_KEY = "ignore_config_files";
static inline const bool IGNORE_CONFIG_FILES_DEF = false;
static inline const std::string CONFIG_VERSION_KEY = "config_version";
static inline const int CONFIG_VERSION_DEF = 0;
};
}

403
source/FileManager.cpp Normal file
View file

@ -0,0 +1,403 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <algorithm>
#include <dirent.h>
#include <fstream>
#include <SimpleIniParser.hpp>
#include <string.h>
#include <switch.h>
#include <sys/stat.h>
#include <unistd.h>
#include <filesystem>
#include "FileManager.hpp"
#include "ConfigManager.hpp"
using namespace simpleIniParser;
using namespace std;
namespace fs = std::filesystem;
namespace dsu
{
vector<char> FileManager::readFile(string path)
{
ifstream file;
file.open(path, ios::in | ios::binary | ios::ate);
auto size = file.tellg();
file.seekg(0, ios::beg);
vector<char> buffer(size);
file.read(buffer.data(), size);
file.close();
return buffer;
}
// Overwrites a file if it already exists!
bool FileManager::writeFile(string filename, string data)
{
deleteFile(filename);
FILE *file = fopen(filename.c_str(), "wb");
if (!file)
{
return false;
}
size_t result = fwrite(data.c_str(), sizeof(char), data.size(), file);
fflush(file);
fsync(fileno(file));
fclose(file);
return (result == data.size());
}
bool FileManager::appendFile(string filename, string data)
{
ofstream file;
// Make sure we are only adding, not overwriting.
file.open(filename, ios_base::app);
if(!file.is_open()) return false;
file << data;
file.close();
return true;
}
bool FileManager::deleteFile(string filename)
{
if (fs::exists(filename))
{
return remove(filename.c_str()) == 0;
}
return false;
}
bool FileManager::fileExists(string filename)
{
if(fs::exists(filename)) return true;
return false;
}
// This scans all FILES in the given directory and it's respective subdirs.
vector<string> FileManager::scanDirectoryRecursive(string path)
{
vector<string> files;
// First check if the dir even exists.
if(fs::exists(path))
{
// Then make sure it's actually a directory, and not a file. All before
// iterating all of the files in the directory.
if(fs::is_directory(path))
{
for (auto ft : fs::recursive_directory_iterator(path))
{
if(ft.is_directory()) continue;
string path = ft.path().string();
files.push_back(path);
}
}
}
return files;
}
// http://stackoverflow.com/a/11366985
bool FileManager::createSubfolder(string path)
{
bool bSuccess = false;
int nRC = ::mkdir(path.c_str(), 0775);
if (nRC == -1)
{
switch (errno)
{
case ENOENT:
//parent didn't exist, try to create it
if (createSubfolder(path.substr(0, path.find_last_of('/'))))
//Now, try to create again.
bSuccess = 0 == ::mkdir(path.c_str(), 0775);
else
bSuccess = false;
break;
case EEXIST:
//Done!
bSuccess = true;
break;
default:
bSuccess = false;
break;
}
}
else
bSuccess = true;
return bSuccess;
}
bool FileManager::extract(string zipFilename, string destination)
{
unzFile unz = unzOpen(zipFilename.c_str());
vector<string> filesToIgnore = ConfigManager::getFilesToIgnore();
vector<string> filesInstalled = ConfigManager::getInstalledFiles();
int i = 0;
for (;;)
{
int code;
if (i == 0)
{
code = unzGoToFirstFile(unz);
}
else
{
code = unzGoToNextFile(unz);
}
i++;
if (code == UNZ_END_OF_LIST_OF_FILE)
{
break;
}
else
{
unz_file_pos pos;
unzGetFilePos(unz, &pos);
}
unz_file_info_s *fileInfo = _getFileInfo(unz);
string filename = destination;
filename += _getFullFileName(unz, fileInfo);
if (find(begin(filesToIgnore), end(filesToIgnore), filename) != end(filesToIgnore))
{
free(fileInfo);
continue;
}
// No need to extract Hekate's payload.
if (filename.compare(0, 12, "sdmc:/hekate") == 0 && filename.compare(filename.length() - 4, 4, ".bin") == 0)
{
free(fileInfo);
continue;
}
// No need to extract Isotope Updater.
if (filename.compare(0, 29, "sdmc:/switch/Isotope-Updater/") == 0)
{
free(fileInfo);
continue;
}
if (filename.back() != '/')
{
filesInstalled.push_back(filename);
int result = _extractFile(filename.c_str(), unz, fileInfo);
if (result < 0)
{
free(fileInfo);
unzClose(unz);
return false;
}
}
free(fileInfo);
}
if (i <= 0)
{
unzClose(unz);
return false;
}
ConfigManager::setInstalledFiles(filesInstalled);
unzClose(unz);
return true;
}
void FileManager::cleanUpFiles()
{
vector<string> installedFiles = ConfigManager::getInstalledFiles();
vector<string> filesToIgnore = ConfigManager::getFilesToIgnore();
for (auto const &fileName : installedFiles)
{
if (find(begin(filesToIgnore), end(filesToIgnore), fileName) != end(filesToIgnore))
{
continue;
}
deleteFile(fileName);
}
vector<string> blankVector;
ConfigManager::setInstalledFiles(blankVector);
}
void FileManager::applyNoGC()
{
Ini *ini = Ini::parseFile(HEKATE_FILE);
for (auto const &section : ini->sections)
{
if (section->type != IniSectionType::Section)
continue;
if (section->value == "config")
{
bool patchApplied = false;
for (auto const &option : section->options)
{
if (option->key == "autonogc")
{
option->value = "1";
patchApplied = true;
break;
}
}
if (!patchApplied)
{
section->options.push_back(new IniOption(IniOptionType::Option, "autonogc", "1"));
}
break;
}
}
ini->writeToFile(HEKATE_FILE);
delete ini;
}
unz_file_info_s *FileManager::_getFileInfo(unzFile unz)
{
unz_file_info_s *fileInfo = (unz_file_info_s *)malloc(sizeof(unz_file_info_s));
unzGetCurrentFileInfo(unz, fileInfo, NULL, 0, NULL, 0, NULL, 0);
return fileInfo;
}
string FileManager::_getFullFileName(unzFile unz, unz_file_info_s *fileInfo)
{
char filePath[fileInfo->size_filename + 1];
unzGetCurrentFileInfo(unz, fileInfo, filePath, fileInfo->size_filename, NULL, 0, NULL, 0);
filePath[fileInfo->size_filename] = '\0';
string path(filePath);
path.resize(fileInfo->size_filename);
return path;
}
bool FileManager::_makeDirectoryParents(string path)
{
bool bSuccess = false;
int nRC = ::mkdir(path.c_str(), 0775);
if (nRC == -1)
{
switch (errno)
{
case ENOENT:
//parent didn't exist, try to create it
if (_makeDirectoryParents(path.substr(0, path.find_last_of('/'))))
//Now, try to create again.
bSuccess = 0 == ::mkdir(path.c_str(), 0775);
else
bSuccess = false;
break;
case EEXIST:
//Done!
bSuccess = true;
break;
default:
bSuccess = false;
break;
}
}
else
bSuccess = true;
return bSuccess;
}
int FileManager::_extractFile(const char *path, unzFile unz, unz_file_info_s *fileInfo)
{
//check to make sure filepath or fileInfo isnt null
if (path == NULL || fileInfo == NULL)
return -1;
if (unzOpenCurrentFile(unz) != UNZ_OK)
return -2;
char folderPath[strlen(path) + 1];
strcpy(folderPath, path);
char *pos = strrchr(folderPath, '/');
if (pos != NULL)
{
*pos = '\0';
_makeDirectoryParents(string(folderPath));
}
u32 blocksize = 0x8000;
u8 *buffer = (u8 *)malloc(blocksize);
if (buffer == NULL)
return -3;
u32 done = 0;
int writeBytes = 0;
FILE *fp = fopen(path, "w");
if (fp == NULL)
{
free(buffer);
return -4;
}
while (done < fileInfo->uncompressed_size)
{
if (done + blocksize > fileInfo->uncompressed_size)
{
blocksize = fileInfo->uncompressed_size - done;
}
unzReadCurrentFile(unz, buffer, blocksize);
writeBytes = write(fileno(fp), buffer, blocksize);
if (writeBytes <= 0)
{
break;
}
done += writeBytes;
}
fflush(fp);
fsync(fileno(fp));
fclose(fp);
free(buffer);
if (done != fileInfo->uncompressed_size)
return -4;
unzCloseCurrentFile(unz);
return 0;
}
} // namespace dsu

46
source/FileManager.hpp Normal file
View file

@ -0,0 +1,46 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <minizip/unzip.h>
#include <string>
#include <vector>
namespace dsu {
class FileManager {
public:
static std::vector<char> readFile(std::string path);
static bool writeFile(std::string filename, std::string data);
static bool deleteFile(std::string filename);
static bool appendFile(std::string filename, std::string data);
static bool fileExists(std::string filename);
static std::vector<std::string> scanDirectoryRecursive(std::string path);
static bool createSubfolder(std::string path);
static bool extract(std::string filename, std::string destination);
static void cleanUpFiles();
static void applyNoGC();
private:
static unz_file_info_s * _getFileInfo(unzFile unz);
static std::string _getFullFileName(unzFile unz, unz_file_info_s * fileInfo);
static bool _makeDirectoryParents(std::string path);
static int _extractFile(const char * path, unzFile unz, unz_file_info_s * fileInfo);
static inline const std::string HEKATE_FILE = "sdmc:/bootloader/hekate_ipl.ini";
};
}

32
source/ModalView.cpp Normal file
View file

@ -0,0 +1,32 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "ModalView.hpp"
#include "SceneDirector.hpp"
namespace dsu {
void ModalView::show() {
SceneDirector::modal = this;
}
void ModalView:: dismiss(bool success) {
SceneDirector::modal = NULL;
if (onDismiss) {
onDismiss(this, success);
}
}
}

37
source/ModalView.hpp Normal file
View file

@ -0,0 +1,37 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <functional>
#include <list>
#include <SDL2/SDL.h>
#include <switch.h>
#include "View.hpp"
namespace dsu {
class ModalView : public dsu::View {
public:
std::function<void(ModalView *, bool)> onDismiss;
virtual void handleButton(u32 buttons, double dTime){};
void show();
void dismiss(bool success);
};
}

65
source/Scene.cpp Normal file
View file

@ -0,0 +1,65 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "Scene.hpp"
namespace dsu {
Scene::Scene() {
_touchedView = NULL;
}
void Scene::render(SDL_Rect rect, double dTime) {
for (auto const& view : subviews) {
if (!view->hidden) {
SDL_Rect subviewFrame = view->frame;
view->render({ rect.x + subviewFrame.x, rect.y + subviewFrame.y, subviewFrame.w, subviewFrame.h }, dTime);
}
}
}
void Scene::touchStarted() {
for (auto const& view : subviews) {
// TODO: Check if touch is within the view
if (view->isTouchable) {
_touchedView = view;
_touchedView->touchStarted();
}
}
}
void Scene::touchMoved() {
if (_touchedView != NULL) {
_touchedView->touchMoved();
}
}
void Scene::touchEnded() {
if (_touchedView != NULL) {
_touchedView->touchEnded();
}
}
void Scene::addSubView(View * view) {
view->superview = NULL;
subviews.push_back(view);
}
void Scene::removeSubView(View * view) {
view->superview = NULL;
subviews.remove(view);
}
}

48
source/Scene.hpp Normal file
View file

@ -0,0 +1,48 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <list>
#include <SDL2/SDL.h>
#include <switch.h>
#include "View.hpp"
namespace dsu {
class Scene {
public:
Scene();
virtual ~Scene(){};
virtual void handleButton(u32 buttons, double dTime){};
virtual void render(SDL_Rect rect, double dTime);
/* Touch Controls */
void touchStarted();
void touchMoved();
void touchEnded();
/* View Hierarchy */
std::list<View *> subviews;
void addSubView(View * view);
void removeSubView(View * view);
private:
View * _touchedView;
};
}

225
source/SceneDirector.cpp Normal file
View file

@ -0,0 +1,225 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <switch.h>
#include "AssetManager.hpp"
#include "ConfigManager.hpp"
#include "SceneDirector.hpp"
using namespace dsu::scenes;
namespace dsu
{
SceneDirector::SceneDirector()
{
currentSceneDirector = this;
romfsInit();
setsysInitialize();
plInitialize(PlServiceType_User);
SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_AUDIO);
if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG))
return;
SceneDirector::window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_FULLSCREEN);
if (!SceneDirector::window)
return;
SceneDirector::renderer = SDL_CreateRenderer(SceneDirector::window, 0, SDL_RENDERER_SOFTWARE);
if (!SceneDirector::renderer)
return;
TTF_Init();
_now = SDL_GetPerformanceCounter();
_last = 0;
_exFatWarningScene = NULL;
_appUpdateScene = NULL;
_packageSelectScene = NULL;
_packageDownloadScene = NULL;
_currentScene = NULL;
if (!ConfigManager::getReceivedExFATWarning())
{
currentScene = SCENE_EXFAT_WARNING;
}
else if (!ConfigManager::shouldAutoUpdate())
{
currentScene = SCENE_PACKAGE_SELECT;
}
}
SceneDirector::~SceneDirector()
{
if (_exFatWarningScene != NULL)
delete _exFatWarningScene;
if (_appUpdateScene != NULL)
delete _appUpdateScene;
if (_packageSelectScene != NULL)
delete _packageSelectScene;
if (_packageDownloadScene != NULL)
delete _packageDownloadScene;
TTF_Quit();
if (SceneDirector::renderer != NULL)
SDL_DestroyRenderer(SceneDirector::renderer);
if (SceneDirector::window != NULL)
SDL_DestroyWindow(SceneDirector::window);
IMG_Quit();
SDL_Quit();
plExit();
setsysExit();
romfsExit();
}
bool SceneDirector::direct()
{
double dTime = _getDeltaTime();
hidScanInput();
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
// TODO: Handle touch controls
// Unload previous scenes
switch (SceneDirector::currentScene)
{
case SCENE_APP_UPDATE:
if (_exFatWarningScene != NULL)
{
delete _exFatWarningScene;
_exFatWarningScene = NULL;
}
break;
case SCENE_PACKAGE_SELECT:
if (_appUpdateScene != NULL)
{
delete _appUpdateScene;
_appUpdateScene = NULL;
}
break;
case SCENE_PACKAGE_DOWNLOAD:
if (_appUpdateScene != NULL)
{
delete _appUpdateScene;
_appUpdateScene = NULL;
}
if (_packageSelectScene != NULL)
{
delete _packageSelectScene;
_packageSelectScene = NULL;
}
break;
default:
/* Do Nothing */
break;
}
// Load new scenes
switch (SceneDirector::currentScene)
{
case SCENE_EXFAT_WARNING:
if (_exFatWarningScene == NULL)
_exFatWarningScene = new ExFatWarningScene();
_currentScene = _exFatWarningScene;
break;
case SCENE_APP_UPDATE:
if (_appUpdateScene == NULL)
_appUpdateScene = new AppUpdateScene();
_currentScene = _appUpdateScene;
break;
case SCENE_PACKAGE_SELECT:
if (_packageSelectScene == NULL)
_packageSelectScene = new PackageSelectScene();
_currentScene = _packageSelectScene;
break;
case SCENE_PACKAGE_DOWNLOAD:
if (_packageDownloadScene == NULL)
_packageDownloadScene = new PackageDownloadScene();
_currentScene = _packageDownloadScene;
break;
}
if (modal != NULL)
{
modal->handleButton(kDown, dTime);
}
else
{
_currentScene->handleButton(kDown, dTime);
}
_render(dTime);
return !SceneDirector::exitApp;
}
void SceneDirector::render()
{
double dTime = _getDeltaTime();
_render(dTime);
}
double SceneDirector::_getDeltaTime()
{
_last = _now;
_now = SDL_GetPerformanceCounter();
return (double)((_now - _last) * 1000 / SDL_GetPerformanceFrequency());
}
void SceneDirector::_render(double dTime)
{
AssetManager::setRenderColor(AssetManager::background);
SDL_RenderClear(SceneDirector::renderer);
_currentScene->render({0, 0, 1280, 720}, dTime);
if (modal != NULL)
{
// Draw Faded background.
AssetManager::setRenderColor(AssetManager::modal_faded_background);
SDL_Rect fadedBGFrame = {0, 0, 1280, 720};
SDL_SetRenderDrawBlendMode(SceneDirector::renderer, SDL_BLENDMODE_BLEND);
SDL_RenderFillRect(SceneDirector::renderer, &fadedBGFrame);
modal->render({0, 0, 1280, 720}, dTime);
}
SDL_RenderPresent(SceneDirector::renderer);
}
} // namespace dsu

65
source/SceneDirector.hpp Normal file
View file

@ -0,0 +1,65 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <SDL2/SDL.h>
#include "ModalView.hpp"
#include "Scene.hpp"
#include "scenes/AppUpdateScene.hpp"
#include "scenes/ExFatWarningScene.hpp"
#include "scenes/PackageDownloadScene.hpp"
#include "scenes/PackageSelectScene.hpp"
namespace dsu {
typedef enum {
SCENE_EXFAT_WARNING,
SCENE_APP_UPDATE,
SCENE_PACKAGE_SELECT,
SCENE_PACKAGE_DOWNLOAD
} Scenes;
class SceneDirector {
public:
static inline SceneDirector * currentSceneDirector = NULL;
static inline SDL_Window * window = NULL;
static inline SDL_Renderer * renderer = NULL;
static inline ModalView * modal = NULL;
static inline Scenes currentScene = SCENE_APP_UPDATE;
static inline bool exitApp = false;
SceneDirector();
~SceneDirector();
bool direct();
void render();
private:
Uint64 _now;
Uint64 _last;
Scene * _currentScene;
scenes::ExFatWarningScene * _exFatWarningScene;
scenes::AppUpdateScene * _appUpdateScene;
scenes::PackageSelectScene * _packageSelectScene;
scenes::PackageDownloadScene * _packageDownloadScene;
double _getDeltaTime();
void _render(double dTime);
};
}

49
source/View.cpp Normal file
View file

@ -0,0 +1,49 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "View.hpp"
namespace dsu {
View::View() {
frame = { 0, 0, 0, 0 };
hidden = false;
hasFocus = false;
}
View::~View() {
subviews.clear();
}
void View::render(SDL_Rect rect, double dTime) {
for (auto const& view : subviews) {
if (!view->hidden) {
SDL_Rect subviewFrame = view->frame;
view->render({ rect.x + subviewFrame.x, rect.y + subviewFrame.y, subviewFrame.w, subviewFrame.h }, dTime);
}
}
}
void View::addSubView(View * view) {
view->superview = view;
subviews.push_back(view);
}
void View::removeSubView(View * view) {
view->superview = NULL;
subviews.remove(view);
}
}

50
source/View.hpp Normal file
View file

@ -0,0 +1,50 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <list>
#include <SDL2/SDL.h>
namespace dsu {
class View {
public:
SDL_Rect frame;
bool hidden;
View();
virtual ~View();
virtual void render(SDL_Rect rect, double dTime);
/* Controller Input */
bool isFocusable;
bool hasFocus;
/* Touch Controls */
bool isTouchable;
virtual void touchStarted(){};
virtual void touchMoved(){};
virtual void touchEnded(){};
/* View Hierarchy */
View * superview;
std::list<View *> subviews;
void addSubView(View * view);
void removeSubView(View * view);
};
}

70
source/main.cpp Normal file
View file

@ -0,0 +1,70 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <switch.h>
#include <Swurl.hpp>
#include "FileManager.hpp"
#include "AssetManager.hpp"
#include "ConfigManager.hpp"
#include "SceneDirector.hpp"
using namespace dsu;
using namespace std;
using namespace swurl;
int main(int argc, char **argv)
{
SessionManager::initialize();
SessionManager::userAgent = string("Isotope-updater/") + VERSION;
nxlinkStdio();
ConfigManager::initialize();
if (ConfigManager::shouldUseProxy()) {
SessionManager::proxyUrl = ConfigManager::getProxy();
SessionManager::proxyUsername = ConfigManager::getProxyUsername();
SessionManager::proxyPassword = ConfigManager::getProxyPassword();
}
SceneDirector * sceneDirector = new SceneDirector();
if (!SceneDirector::renderer || !SceneDirector::window) {
return -1;
}
if (!AssetManager::initialize()) {
AssetManager::dealloc();
return -1;
}
// Main Game Loop
while (appletMainLoop())
{
if (!sceneDirector->direct())
break;
}
AssetManager::dealloc();
delete sceneDirector;
ConfigManager::dealloc();
SessionManager::dealloc();
return 0;
}

37
source/models/Action.cpp Normal file
View file

@ -0,0 +1,37 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "Action.hpp"
using namespace std;
namespace dsu::models {
Action::Action(ActionButton actionButton, string actionText) {
button = actionButton;
text = actionText;
textTexture = NULL;
textWidth = 0;
textHeight = 0;
}
Action::~Action() {
if (textTexture != NULL) {
SDL_DestroyTexture(textTexture);
textTexture = NULL;
}
}
}

43
source/models/Action.hpp Normal file
View file

@ -0,0 +1,43 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <SDL2/SDL.h>
#include <string>
namespace dsu::models {
typedef enum {
A_BUTTON,
B_BUTTON,
Y_BUTTON,
X_BUTTON
} ActionButton;
class Action {
public:
ActionButton button;
std::string text;
SDL_Texture * textTexture;
int textWidth;
int textHeight;
Action(ActionButton actionButton, std::string actionText);
~Action();
};
}

21
source/models/Touch.cpp Normal file
View file

@ -0,0 +1,21 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "Touch.hpp"
namespace dsu::models {
}

23
source/models/Touch.hpp Normal file
View file

@ -0,0 +1,23 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
namespace dsu::models {
class Touch {
};
}

View file

@ -0,0 +1,288 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <jansson.h>
#include "AppUpdateScene.hpp"
#include "../ConfigManager.hpp"
#include "../FileManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace dsu::models;
using namespace dsu::views;
using namespace std;
using namespace std::placeholders;
using namespace swurl;
namespace dsu::scenes
{
AppUpdateScene::AppUpdateScene()
{
SessionManager::onProgressChanged = bind(&AppUpdateScene::_onProgressUpdate, this, _1, _2);
SessionManager::onCompleted = bind(&AppUpdateScene::_onCompleted, this, _1);
SessionManager::onError = bind(&AppUpdateScene::_onError, this, _1, _2);
_headerView = new HeaderView("Isotope Updater", true);
_headerView->frame = {0, 0, 1280, 88};
_updateView = new UpdateView("Checking for updates to Isotope Updater...");
_updateView->frame.x = 0;
_updateView->frame.y = 200;
_statusView = new StatusView("", "");
_statusView->frame.x = 0;
_statusView->frame.y = 323;
_statusView->hidden = true;
_footerView = new FooterView();
_footerView->frame = {0, 647, 1280, 73};
addSubView(_headerView);
addSubView(_updateView);
addSubView(_statusView);
addSubView(_footerView);
}
AppUpdateScene::~AppUpdateScene()
{
if (_headerView != NULL)
delete _headerView;
if (_updateView != NULL)
delete _updateView;
if (_statusView != NULL)
delete _statusView;
if (_footerView != NULL)
delete _footerView;
if (_appVersionRequest != NULL)
delete _appVersionRequest;
if (_appRequest != NULL)
delete _appRequest;
}
void AppUpdateScene::handleButton(u32 buttons, double dTime)
{
if (!_statusView->hidden && buttons & KEY_A)
{
SceneDirector::exitApp = true;
}
}
void AppUpdateScene::render(SDL_Rect rect, double dTime)
{
if (_appVersionRequest == NULL)
{
_appVersionRequest = new WebRequest("https://api.github.com/repos/Ta180m/Isotope-Updater/releases");
SessionManager::makeRequest(_appVersionRequest);
}
_updateView->setProgress(_downloadProgess);
Scene::render(rect, dTime);
}
void AppUpdateScene::_showStatus(string text, string subtext)
{
_statusView->setText(text);
_statusView->setSubtext(subtext);
_updateView->hidden = true;
_statusView->hidden = false;
_footerView->actions.push_back(new Action(A_BUTTON, "Quit"));
}
std::string AppUpdateScene::_sanitizeVersion(std::string version)
{
std::string result = "";
for (char &c : version)
{
if ((c >= '0' && c <= '9') || c == '.')
{
result += c;
}
}
return result;
}
tuple<int, int, int> AppUpdateScene::_parseVersion(string version)
{
size_t pos = 0;
int index = 0, major = 0, minor = 0, patch = 0;
while (pos != string::npos)
{
size_t end_pos = version.find(".", pos);
int versionNumber = 0;
if (end_pos == string::npos)
{
versionNumber = stoi(version.substr(pos, string::npos));
pos = string::npos;
}
else
{
versionNumber = stoi(version.substr(pos, end_pos - pos));
pos = end_pos + 1;
}
if (index == 0)
{
major = versionNumber;
}
else if (index == 1)
{
minor = versionNumber;
}
else if (index == 2)
{
patch = versionNumber;
break;
}
index++;
}
return make_tuple(major, minor, patch);
}
// Swurl Callback Methods
void AppUpdateScene::_onProgressUpdate(WebRequest *request, double progress)
{
_downloadProgess = progress;
SceneDirector::currentSceneDirector->render();
}
void AppUpdateScene::_onCompleted(WebRequest *request)
{
if (request == _appVersionRequest)
{
json_t *root = json_loads(request->response.rawResponseBody.c_str(), 0, NULL);
if (!root || !json_is_array(root) || json_array_size(root) < 1)
{
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[4]");
return;
}
json_t *release = json_array_get(root, 0);
if (!release || !json_is_object(release))
{
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[5]");
return;
}
json_t *tagName = json_object_get(release, "tag_name");
if (!tagName || !json_is_string(tagName))
{
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[6]");
return;
}
auto latestVersion = _parseVersion(_sanitizeVersion(json_string_value(tagName)));
// No Update
if (
VERSION_MAJOR > get<0>(latestVersion) ||
(VERSION_MAJOR == get<0>(latestVersion) && VERSION_MINOR > get<1>(latestVersion)) ||
(VERSION_MAJOR == get<0>(latestVersion) && VERSION_MINOR == get<1>(latestVersion) && VERSION_PATCH > get<2>(latestVersion)) ||
(VERSION_MAJOR == get<0>(latestVersion) && VERSION_MINOR == get<1>(latestVersion) && VERSION_PATCH == get<2>(latestVersion)))
{
json_decref(root);
SessionManager::onProgressChanged = NULL;
SessionManager::onCompleted = NULL;
SessionManager::onError = NULL;
SceneDirector::currentScene = SCENE_PACKAGE_SELECT;
}
// Update
else
{
json_t *assets = json_object_get(release, "assets");
if (!assets || !json_is_array(assets) || json_array_size(assets) < 1)
{
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.");
return;
}
std::string downloadUrl = "";
for (size_t i = 0; i < json_array_size(assets); i++)
{
json_t *asset = json_array_get(assets, i);
if (!asset || !json_is_object(asset))
{
continue;
}
json_t *name = json_object_get(asset, "name");
if (!name || !json_is_string(name))
{
continue;
}
std::string assetName(json_string_value(name));
if (assetName.compare(assetName.length() - 4, 4, ".nro") != 0)
{
continue;
}
json_t *browserDownloadUrl = json_object_get(asset, "browser_download_url");
if (!browserDownloadUrl || !json_is_string(browserDownloadUrl))
{
continue;
}
downloadUrl = std::string(json_string_value(browserDownloadUrl));
break;
}
json_decref(root);
if (downloadUrl.length() == 0)
{
_showStatus("Unable to find the latest release assets.", "Please restart the app to try again.");
return;
}
_updateView->setProgress(0);
_updateView->setText("Getting the latest version of Isotope Updater...");
_appRequest = new WebRequest(downloadUrl);
SessionManager::makeRequest(_appRequest);
}
}
else if (request == _appRequest)
{
romfsExit();
FileManager::writeFile("Isotope-Updater.nro", request->response.rawResponseBody);
_showStatus("Isotope Updater has been updated to version " + _appVersionRequest->response.rawResponseBody + "!", "Please restart the app.");
}
}
void AppUpdateScene::_onError(WebRequest *request, string error)
{
_showStatus(error, "Please restart the app to try again.");
}
} // namespace dsu::scenes

View file

@ -0,0 +1,57 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <string>
#include <Swurl.hpp>
#include <tuple>
#include "../Scene.hpp"
#include "../views/FooterView.hpp"
#include "../views/HeaderView.hpp"
#include "../views/StatusView.hpp"
#include "../views/UpdateView.hpp"
namespace dsu::scenes {
class AppUpdateScene : public dsu::Scene {
public:
AppUpdateScene();
~AppUpdateScene();
void handleButton(u32 buttons, double dTime);
void render(SDL_Rect rect, double dTime);
private:
dsu::views::HeaderView * _headerView = NULL;
dsu::views::UpdateView * _updateView = NULL;
dsu::views::StatusView * _statusView = NULL;
dsu::views::FooterView * _footerView = NULL;
swurl::WebRequest * _appVersionRequest = NULL;
swurl::WebRequest * _appRequest = NULL;
double _downloadProgess = 0;
void _showStatus(std::string text, std::string subtext);
std::string _sanitizeVersion(std::string version);
std::tuple<int, int, int> _parseVersion(std::string version);
void _onProgressUpdate(swurl::WebRequest * request, double progress);
void _onCompleted(swurl::WebRequest * request);
void _onError(swurl::WebRequest * request, std::string error);
};
}

View file

@ -0,0 +1,83 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "ExFatWarningScene.hpp"
#include "../AssetManager.hpp"
#include "../ConfigManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace dsu::views;
namespace dsu::scenes {
ExFatWarningScene::ExFatWarningScene() {
_timeSpent = -10000;
_footerVisible = false;
_headerTextView = new TextView(AssetManager::header_font, "Warning - SD Card Corruption", AssetManager::text);
_headerTextView->frame = { 0, 122, 1280, 1 };
_headerTextView->textAlignment = CENTER_ALIGN;
_bodyTextView = new TextView(AssetManager::body_font, "Isotope Updater may cause corruption to your SD card if it is formatted as ExFAT. This\nis due to an issue with Nintendo's ExFAT drivers built into the Switch. It is recommended\nthat you use an SD card formatted as FAT32, however if you wish to continue and you are\nusing ExFAT you do so at your own risk. This warning will not show up again.", AssetManager::text);
_bodyTextView->frame = { 0, 272, 1280, 1 };
_bodyTextView->textAlignment = CENTER_ALIGN;
_bodyTextView->lineHeight = 50;
_footerTextView = new TextView(AssetManager::header_font, "Press any button to continue.", AssetManager::text);
_footerTextView->frame = { 0, 567, 1280, 1 };
_footerTextView->textAlignment = CENTER_ALIGN;
_footerTextView->alpha = 0;
addSubView(_headerTextView);
addSubView(_bodyTextView);
addSubView(_footerTextView);
}
ExFatWarningScene::~ExFatWarningScene() {
if (_headerTextView != NULL)
delete _headerTextView;
if (_bodyTextView != NULL)
delete _bodyTextView;
if (_footerTextView != NULL)
delete _footerTextView;
}
void ExFatWarningScene::handleButton(u32 buttons, double dTime) {
if (buttons > 0 && _footerVisible) {
ConfigManager::setReceivedExFATWarning(true);
SceneDirector::currentScene = (ConfigManager::shouldAutoUpdate()) ? SCENE_APP_UPDATE : SCENE_PACKAGE_SELECT;
}
}
void ExFatWarningScene::render(SDL_Rect rect, double dTime) {
if (_footerVisible == false) {
_timeSpent += dTime;
if (_timeSpent >= 0 && _timeSpent < 1000) {
_footerTextView->alpha = _timeSpent / 1000 * 255;
} else if (_timeSpent >= 1) {
_footerVisible = true;
_footerTextView->alpha = 255;
}
}
Scene::render(rect, dTime);
}
}

View file

@ -0,0 +1,42 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <switch.h>
#include "../Scene.hpp"
#include "../views/TextView.hpp"
namespace dsu::scenes {
class ExFatWarningScene : public dsu::Scene {
public:
ExFatWarningScene();
~ExFatWarningScene();
void handleButton(u32 buttons, double dTime);
void render(SDL_Rect rect, double dTime);
private:
double _timeSpent;
bool _footerVisible;
dsu::views::TextView * _headerTextView;
dsu::views::TextView * _bodyTextView;
dsu::views::TextView * _footerTextView;
};
}

View file

@ -0,0 +1,291 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <cstring>
#include <jansson.h>
#include <SimpleIniParser.hpp>
#include "PackageDownloadScene.hpp"
#include "../ConfigManager.hpp"
#include "../FileManager.hpp"
#include "../SceneDirector.hpp"
#define IRAM_PAYLOAD_MAX_SIZE 0x2F000
#define IRAM_PAYLOAD_BASE 0x40010000
static __attribute__((aligned(0x1000))) u8 g_ff_page[0x1000];
static __attribute__((aligned(0x1000))) u8 g_work_page[0x1000];
using namespace dsu;
using namespace dsu::models;
using namespace dsu::views;
using namespace simpleIniParser;
using namespace std;
using namespace std::placeholders;
using namespace swurl;
namespace dsu::scenes {
PackageDownloadScene::PackageDownloadScene() {
SessionManager::onProgressChanged = bind(&PackageDownloadScene::_onProgressUpdate, this, _1, _2);
SessionManager::onCompleted = bind(&PackageDownloadScene::_onCompleted, this, _1);
SessionManager::onError = bind(&PackageDownloadScene::_onError, this, _1, _2);
bpcInitialize();
_headerView = new HeaderView("Isotope Updater", true);
_headerView->frame = { 0, 0, 1280, 88 };
_updateView = new UpdateView("Downloading the latest Isotope...");
_updateView->frame.x = 0;
_updateView->frame.y = 200;
_statusView = new StatusView("", "");
_statusView->frame.x = 0;
_statusView->frame.y = 323;
_statusView->hidden = true;
_footerView = new FooterView();
_footerView->frame = { 0, 647, 1280, 73 };
vector<string> buttons;
buttons.push_back("Restart");
buttons.push_back("Quit");
_restartAlertView = new AlertView("Are you sure?", "Restarting while using an ExFAT formatted SD card\nwill cause it to corrupt. It is recommended that if\nyou have an ExFAT formatted SD card to quit,\npress the home button, and restart the switch.", buttons);
_restartAlertView->onDismiss = bind(&PackageDownloadScene::_onAlertViewDismiss, this, _1, _2);
addSubView(_headerView);
addSubView(_updateView);
addSubView(_statusView);
addSubView(_footerView);
}
PackageDownloadScene::~PackageDownloadScene() {
if (_headerView != NULL)
delete _headerView;
if (_updateView != NULL)
delete _updateView;
if (_statusView != NULL)
delete _statusView;
if (_footerView != NULL)
delete _footerView;
if (_IsotopeUrlRequest != NULL)
delete _IsotopeUrlRequest;
if (_IsotopeRequest != NULL)
delete _IsotopeRequest;
bpcExit();
}
void PackageDownloadScene::handleButton(u32 buttons, double dTime) {
if (!_statusView->hidden && buttons & KEY_A) {
SceneDirector::exitApp = true;
}
if (!_statusView->hidden && _footerView->actions.size() == 2 && buttons & KEY_X) {
_restartAlertView->reset();
_restartAlertView->show();
}
}
void PackageDownloadScene::render(SDL_Rect rect, double dTime) {
if (_IsotopeUrlRequest == NULL) {
_IsotopeUrlRequest = new WebRequest("https://api.github.com/repos/Ta180m/Isotope/releases");
SessionManager::makeRequest(_IsotopeUrlRequest);
}
Scene::render(rect, dTime);
}
void PackageDownloadScene::_copyToIram(uintptr_t iram_addr, void *buf, size_t size) {
memcpy(g_work_page, buf, size);
SecmonArgs args = {0};
args.X[0] = 0xF0000201; /* smcAmsIramCopy */
args.X[1] = (uintptr_t)g_work_page; /* DRAM Address */
args.X[2] = iram_addr; /* IRAM Address */
args.X[3] = size; /* Copy size */
args.X[4] = 1;
svcCallSecureMonitor(&args);
memcpy(buf, g_work_page, size);
}
void PackageDownloadScene::_clearIram() {
memset(g_ff_page, 0xFF, sizeof(g_ff_page));
for(size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += sizeof(g_ff_page)) {
this->_copyToIram(IRAM_PAYLOAD_BASE + i, g_ff_page, sizeof(g_ff_page));
}
}
void PackageDownloadScene::_showStatus(string text, string subtext, bool wasSuccessful) {
_statusView->setText(text);
_statusView->setSubtext(subtext);
_updateView->hidden = true;
_statusView->hidden = false;
_footerView->actions.push_back(new Action(A_BUTTON, "Quit"));
if (wasSuccessful) {
_footerView->actions.push_back(new Action(X_BUTTON, "Restart"));
}
}
void PackageDownloadScene::_onAlertViewDismiss(ModalView * view, bool success) {
if (success) {
if (_restartAlertView->getSelectedOption() == 0) {
auto payload = FileManager::readFile("sdmc:/bootloader/update.bin");
if (payload.size() == 0) {
SceneDirector::exitApp = true;
return;
}
Result rc = splInitialize();
if (R_FAILED(rc)) {
SceneDirector::exitApp = true;
return;
}
this->_clearIram();
for (size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += 0x1000) {
this->_copyToIram(IRAM_PAYLOAD_BASE + i, &payload[i], 0x1000);
}
splSetConfig((SplConfigItem) 65001, 2);
splExit();
}
else {
SceneDirector::exitApp = true;
}
}
}
void PackageDownloadScene::_onProgressUpdate(WebRequest * request, double progress) {
_updateView->setProgress(progress);
SceneDirector::currentSceneDirector->render();
}
void PackageDownloadScene::_onCompleted(WebRequest * request) {
if (request == _IsotopeUrlRequest) {
json_t * root = json_loads(request->response.rawResponseBody.c_str(), 0, NULL);
if (!root || !json_is_array(root) || json_array_size(root) < 1) {
if (root) {
json_decref(root);
}
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[7]", false);
return;
}
json_t * release = json_array_get(root, 0);
if (!release || !json_is_object(release)) {
json_decref(root);
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[8]", false);
return;
}
json_t * tagName = json_object_get(release, "tag_name");
if (!tagName || !json_is_string(tagName)) {
json_decref(root);
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[9]", false);
return;
}
_IsotopeVersion = json_string_value(tagName);
json_t * assets = json_object_get(release, "assets");
if (!assets || !json_is_array(assets) || json_array_size(assets) < 1) {
json_decref(root);
_showStatus("Unable to parse response from GitHub API.", "Please restart the app to try again.[10]", false);
return;
}
std::string downloadUrl = "";
for(size_t i = 0; i < json_array_size(assets); i++) {
json_t * asset = json_array_get(assets, i);
if (!asset || !json_is_object(asset)) {
continue;
}
json_t * name = json_object_get(asset, "name");
if (!name || !json_is_string(name)) {
continue;
}
std::string assetName(json_string_value(name));
if (assetName.compare(0, 8, "isotope_") != 0 || assetName.compare(assetName.length() - 4, 4, ".zip") != 0) {
continue;
}
json_t * browserDownloadUrl = json_object_get(asset, "browser_download_url");
if (!browserDownloadUrl || !json_is_string(browserDownloadUrl)) {
continue;
}
downloadUrl = std::string(json_string_value(browserDownloadUrl));
break;
}
json_decref(root);
if (downloadUrl.length() == 0) {
_showStatus("Unable to find the latest release assets.", "Please restart the app to try again.", false);
return;
}
_IsotopeRequest = new WebRequest(downloadUrl);
SessionManager::makeRequest(_IsotopeRequest);
} else {
FileManager::writeFile("temp.zip", request->response.rawResponseBody);
_updateView->setText("Removing old package...");
_updateView->setProgressBarHidden(true);
SceneDirector::currentSceneDirector->render();
FileManager::cleanUpFiles();
_updateView->setText("Extracting the latest package...");
SceneDirector::currentSceneDirector->render();
if (!FileManager::extract("temp.zip", "sdmc:/")) {
FileManager::deleteFile("temp.zip");
_showStatus("There was an error while trying to extract files.", "Please restart the app to try again.", false);
return;
}
FileManager::deleteFile("temp.zip");
ConfigManager::setCurrentVersion(_IsotopeVersion);
_updateView->setText("Applying disabled game cart option...");
SceneDirector::currentSceneDirector->render();
FileManager::applyNoGC();
_showStatus("Isotope has been updated to version " + _IsotopeVersion + "!", "Please restart your Switch to finish the update.", true);
}
}
void PackageDownloadScene::_onError(WebRequest * request, string error) {
_showStatus(error, "Please restart the app to try again.", false);
}
}

View file

@ -0,0 +1,63 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <string>
#include <Swurl.hpp>
#include "../ModalView.hpp"
#include "../Scene.hpp"
#include "../views/AlertView.hpp"
#include "../views/FooterView.hpp"
#include "../views/HeaderView.hpp"
#include "../views/StatusView.hpp"
#include "../views/UpdateView.hpp"
namespace dsu::scenes {
class PackageDownloadScene : public dsu::Scene {
public:
PackageDownloadScene();
~PackageDownloadScene();
void handleButton(u32 buttons, double dTime);
void render(SDL_Rect rect, double dTime);
private:
dsu::views::HeaderView * _headerView = NULL;
dsu::views::UpdateView * _updateView = NULL;
dsu::views::StatusView * _statusView = NULL;
dsu::views::FooterView * _footerView = NULL;
dsu::views::AlertView * _restartAlertView = NULL;
std::string _IsotopeVersion = "";
swurl::WebRequest * _IsotopeUrlRequest = NULL;
swurl::WebRequest * _IsotopeRequest = NULL;
void _copyToIram(uintptr_t iram_addr, void *buf, size_t size);
void _clearIram();
void _showStatus(std::string text, std::string subtext, bool wasSuccessful);
void _onAlertViewDismiss(dsu::ModalView * view, bool success);
std::string _getVersionNumber(std::string version);
void _onProgressUpdate(swurl::WebRequest * request, double progress);
void _onCompleted(swurl::WebRequest * request);
void _onError(swurl::WebRequest * request, std::string error);
};
}

View file

@ -0,0 +1,277 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <jansson.h>
#include "PackageSelectScene.hpp"
#include "../ConfigManager.hpp"
#include "../SceneDirector.hpp"
#include "../FileManager.hpp"
using namespace dsu;
using namespace dsu::models;
using namespace dsu::views;
using namespace std;
using namespace std::placeholders;
using namespace swurl;
namespace dsu::scenes
{
PackageSelectScene::PackageSelectScene()
{
SessionManager::onProgressChanged = bind(&PackageSelectScene::_onProgressUpdate, this, _1, _2);
SessionManager::onCompleted = bind(&PackageSelectScene::_onCompleted, this, _1);
SessionManager::onError = bind(&PackageSelectScene::_onError, this, _1, _2);
_headerView = new HeaderView("Isotope Updater", true);
_headerView->frame = {0, 0, 1280, 88};
_updateView = new UpdateView("Checking for updates to Isotope...");
_updateView->frame.x = 0;
_updateView->frame.y = 200;
_statusView = new StatusView("", "");
_statusView->frame.x = 0;
_statusView->frame.y = 323;
_installRowView = new ListRowView("Install Latest Isotope", "", SUBTITLE);
_installRowView->frame.x = 215;
_installRowView->frame.y = 137;
_installRowView->isLast = true;
_installRowView->hasFocus = true;
_footerView = new FooterView();
_footerView->frame = {0, 647, 1280, 73};
vector<string> buttons;
buttons.push_back("Yes");
buttons.push_back("No");
_ignoreConfigsAlertView = new AlertView("Ignore Config Files?", "Would you like for Isotope Updater to ignore config\nfiles? This will prevent Isotope Updater from overwriting\nall config files except for Hekate's main config file, and save the\nignored files for next time as well.", buttons);
_ignoreConfigsAlertView->onDismiss = bind(&PackageSelectScene::_onAlertViewDismiss, this, _1, _2);
addSubView(_headerView);
addSubView(_updateView);
addSubView(_statusView);
addSubView(_installRowView);
addSubView(_footerView);
_showUpdateView();
}
PackageSelectScene::~PackageSelectScene()
{
if (_headerView != NULL)
delete _headerView;
if (_updateView != NULL)
delete _updateView;
if (_statusView != NULL)
delete _statusView;
if (_installRowView != NULL)
delete _installRowView;
if (_footerView != NULL)
delete _footerView;
if (_IsotopeVersionRequest != NULL)
delete _IsotopeVersionRequest;
}
void PackageSelectScene::handleButton(u32 buttons, double dTime)
{
if (!_statusView->hidden && buttons & KEY_A)
{
SceneDirector::exitApp = true;
}
else if (_updateView->hidden && _statusView->hidden)
{
if (buttons & KEY_A)
{
SceneDirector::currentScene = SCENE_PACKAGE_DOWNLOAD;
}
if (buttons & KEY_B)
{
SceneDirector::exitApp = true;
}
}
}
void PackageSelectScene::render(SDL_Rect rect, double dTime)
{
if (_IsotopeVersionRequest == NULL)
{
_IsotopeVersionRequest = new WebRequest("https://api.github.com/repos/Ta180m/Isotope/releases");
SceneDirector::currentSceneDirector->render();
SessionManager::makeRequest(_IsotopeVersionRequest);
}
Scene::render(rect, dTime);
}
void PackageSelectScene::_showUpdateView()
{
_updateView->setProgress(0);
_updateView->hidden = false;
_statusView->hidden = true;
_installRowView->hidden = true;
for (auto const &action : _footerView->actions)
{
delete action;
}
_footerView->actions.clear();
}
void PackageSelectScene::_showPackageSelectViews(std::string IsotopeVersion)
{
// if (!ConfigManager::getReceivedIgnoreConfigWarning())
// {
_ignoreConfigsAlertView->show();
// }
_updateView->hidden = true;
_statusView->hidden = true;
_installRowView->hidden = false;
_installRowView->hasFocus = true;
string version = ConfigManager::getCurrentVersion();
if (version.compare(IsotopeVersion) == 0)
{
_installRowView->setPrimaryText("Reinstall Isotope");
}
else
{
_installRowView->setPrimaryText("Install Latest Isotope");
}
if (version == "" || version.compare(IsotopeVersion) == 0)
{
_installRowView->setSecondaryText("Latest Version is " + IsotopeVersion);
}
else
{
_installRowView->setSecondaryText("You currently have version " + version + " installed, and the latest version is " + IsotopeVersion + ".");
}
for (auto const &action : _footerView->actions)
{
delete action;
}
_footerView->actions.clear();
_footerView->actions.push_back(new Action(A_BUTTON, "OK"));
_footerView->actions.push_back(new Action(B_BUTTON, "Quit"));
}
void PackageSelectScene::_showStatusView(string text, string subtext)
{
_statusView->setText(text);
_statusView->setSubtext(subtext);
_updateView->hidden = true;
_statusView->hidden = false;
_installRowView->hidden = true;
for (auto const &action : _footerView->actions)
{
delete action;
}
_footerView->actions.clear();
_footerView->actions.push_back(new Action(A_BUTTON, "Quit"));
}
// Alert View Callback Method
void PackageSelectScene::_onAlertViewDismiss(ModalView *view, bool success)
{
if (success && _ignoreConfigsAlertView->getSelectedOption() == 0)
{
vector<string> files = FileManager::scanDirectoryRecursive("sdmc:/config");
vector<string> filesToIgnore = ConfigManager::getFilesToIgnore();
files.push_back("sdmc:/atmosphere/config/BCT.ini");
files.push_back("sdmc:/atmosphere/config/override_config.ini");
files.push_back("sdmc:/atmosphere/config/system_settings.ini");
files.push_back("sdmc:/bootloader/patches.ini");
files.push_back("sdmc:/bootloader/hekate_ipl.ini");
files.push_back("sdmc:/switch/Isotope-Toolbox/config.json");
files.push_back("sdmc:/switch/Isotope-Updater/internal.db");
files.push_back("sdmc:/switch/Isotope-Updater/settings.cfg");
if(filesToIgnore.empty())
{
ConfigManager::setFilesToIgnore(files);
} else {
for (auto i : filesToIgnore)
{
files.erase(remove(files.begin(), files.end(), i), files.end());
}
}
ConfigManager::setIgnoreConfigFiles(true);
} else {
ConfigManager::setIgnoreConfigFiles(false);
}
}
// Swurl Callback Methods
void PackageSelectScene::_onProgressUpdate(WebRequest *request, double progress)
{
_updateView->setProgress(progress);
SceneDirector::currentSceneDirector->render();
}
void PackageSelectScene::_onCompleted(WebRequest *request)
{
json_t *root = json_loads(request->response.rawResponseBody.c_str(), 0, NULL);
if (!root || !json_is_array(root) || json_array_size(root) < 1)
{
_showStatusView("Unable to parse response from GitHub API.", "Please restart the app to try again.[1]");
return;
}
json_t *release = json_array_get(root, 0);
if (!release || !json_is_object(release))
{
_showStatusView("Unable to parse response from GitHub API.", "Please restart the app to try again.[2]");
return;
}
json_t *tagName = json_object_get(release, "tag_name");
if (!tagName || !json_is_string(tagName))
{
_showStatusView("Unable to parse response from GitHub API.", "Please restart the app to try again.[3]");
return;
}
_showPackageSelectViews(json_string_value(tagName));
json_decref(root);
SessionManager::onProgressChanged = NULL;
SessionManager::onCompleted = NULL;
SessionManager::onError = NULL;
}
void PackageSelectScene::_onError(WebRequest *request, string error)
{
_showStatusView(error, "Please restart the app to try again.");
}
} // namespace dsu::scenes

View file

@ -0,0 +1,60 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <switch.h>
#include <Swurl.hpp>
#include "../Scene.hpp"
#include "../views/FooterView.hpp"
#include "../views/HeaderView.hpp"
#include "../views/ListRowView.hpp"
#include "../views/StatusView.hpp"
#include "../views/UpdateView.hpp"
#include "../views/AlertView.hpp"
namespace dsu::scenes {
class PackageSelectScene : public dsu::Scene {
public:
PackageSelectScene();
~PackageSelectScene();
void handleButton(u32 buttons, double dTime);
void render(SDL_Rect rect, double dTime);
private:
dsu::views::HeaderView * _headerView = NULL;
dsu::views::UpdateView * _updateView = NULL;
dsu::views::StatusView * _statusView = NULL;
dsu::views::ListRowView * _installRowView = NULL;
dsu::views::FooterView * _footerView = NULL;
dsu::views::AlertView * _ignoreConfigsAlertView = NULL;
swurl::WebRequest * _IsotopeVersionRequest = NULL;
void _showUpdateView();
void _showPackageSelectViews(std::string IsotopeVersion);
void _showStatusView(std::string text, std::string subtext);
void _onAlertViewDismiss(dsu::ModalView * view, bool success);
void _onProgressUpdate(swurl::WebRequest * request, double progress);
void _onCompleted(swurl::WebRequest * request);
void _onError(swurl::WebRequest * request, std::string error);
};
}

View file

@ -0,0 +1,56 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "AlertButtonView.hpp"
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace std;
namespace dsu::views {
AlertButtonView::AlertButtonView(string title, bool hasFocus, SDL_Rect rect) {
frame = rect;
_textView = new TextView(AssetManager::body_font, title, (hasFocus) ? AssetManager::active_text : AssetManager::text);
_textView->textAlignment = CENTER_ALIGN;
_textView->frame = { 0, (72 - _textView->getTextHeight()) / 2, rect.w, 1 };
addSubView(_textView);
}
AlertButtonView::~AlertButtonView() {
if (_textView != NULL)
delete _textView;
}
void AlertButtonView::setHasFocus(bool focus) {
_textView->setTextColor((focus) ? AssetManager::active_text : AssetManager::text);
}
void AlertButtonView::render(SDL_Rect rect, double dTime) {
AssetManager::setRenderColor(AssetManager::list_divider);
SDL_RenderDrawLine(SceneDirector::renderer, rect.x, rect.y, rect.x + rect.w, rect.y);
if (!isLast) {
SDL_RenderDrawLine(SceneDirector::renderer, rect.x + rect.w, rect.y, rect.x + rect.w, rect.y + rect.h);
}
// Render any subviews.
ControlView::render(rect, dTime);
}
}

View file

@ -0,0 +1,40 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <string>
#include "ControlView.hpp"
#include "TextView.hpp"
namespace dsu::views {
class AlertButtonView : public ControlView {
public:
bool isLast;
AlertButtonView(std::string title, bool hasFocus, SDL_Rect rect);
~AlertButtonView();
void setHasFocus(bool focus);
void render(SDL_Rect rect, double dTime);
private:
TextView * _textView;
};
}

125
source/views/AlertView.cpp Normal file
View file

@ -0,0 +1,125 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <SDL2/SDL2_gfxPrimitives.h>
#include "AlertView.hpp"
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace std;
namespace dsu::views {
AlertView::AlertView(string title, string message, vector<string> buttons) {
_focusSelection = 0;
_alertHeight = 203;
_titleTextView = new TextView(AssetManager::header_font, title, AssetManager::text);
_titleTextView->textAlignment = CENTER_ALIGN;
_alertHeight += _titleTextView->getTextHeight();
addSubView(_titleTextView);
_messageTextView = new TextView(AssetManager::body_font, message, AssetManager::text);
_messageTextView->textAlignment = CENTER_ALIGN;
_messageTextView->lineHeight = 32;
_alertHeight += _messageTextView->getTextHeight();
addSubView(_messageTextView);
_alertY = (720 - _alertHeight) / 2;
int i = 0;
int buttonWidth = 770 / buttons.size();
for (auto const& text : buttons) {
AlertButtonView * button = new AlertButtonView(text, (i == 0), { 255 + buttonWidth * i, _alertY + _alertHeight - 72, buttonWidth, 72 });
button->isLast = (i == (int) buttons.size() - 1);
_buttons.push_back(button);
addSubView(button);
i++;
}
_titleTextView->frame = { 255, _alertY + 55, 770, 1 };
_messageTextView->frame = { 255, _alertY + 93 + _titleTextView->getTextHeight(), 770, 1 };
}
AlertView::~AlertView() {
if (_titleTextView != NULL)
delete _titleTextView;
if (_messageTextView != NULL)
delete _messageTextView;
for (auto const& button : _buttons) {
if (button != NULL)
delete button;
}
_buttons.clear();
}
void AlertView::handleButton(u32 buttons, double dTime) {
if (buttons & KEY_LEFT && _focusSelection > 0) {
_focusSelection--;
int i = 0;
for (auto const& button : _buttons) {
button->setHasFocus(i == _focusSelection);
i++;
}
}
else if (buttons & KEY_RIGHT && _focusSelection < (int) _buttons.size() - 1) {
_focusSelection++;
int i = 0;
for (auto const& button : _buttons) {
button->setHasFocus(i == _focusSelection);
i++;
}
}
else if (buttons & KEY_A) {
dismiss(true);
}
else if (buttons & KEY_B) {
dismiss(false);
}
}
void AlertView::render(SDL_Rect rect, double dTime) {
// Draw background.
roundedBoxRGBA(
SceneDirector::renderer,
255,
_alertY,
1025,
_alertY + _alertHeight,
4,
AssetManager::background.r, AssetManager::background.g, AssetManager::background.b, AssetManager::background.a);
// Render any subviews.
View::render(rect, dTime);
}
int AlertView::getSelectedOption() {
return _focusSelection;
}
void AlertView::reset() {
_focusSelection = 0;
int i = 0;
for (auto const& button : _buttons) {
button->setHasFocus(i == _focusSelection);
i++;
}
}
}

View file

@ -0,0 +1,49 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <string>
#include <vector>
#include "AlertButtonView.hpp"
#include "FooterView.hpp"
#include "HeaderView.hpp"
#include "../ModalView.hpp"
#include "TextView.hpp"
namespace dsu::views {
class AlertView : public dsu::ModalView {
public:
AlertView(std::string title, std::string message, std::vector<std::string> buttons);
~AlertView();
void handleButton(u32 buttons, double dTime);
void render(SDL_Rect rect, double dTime);
int getSelectedOption();
void reset();
private:
int _focusSelection;
int _alertY;
int _alertHeight;
TextView * _titleTextView;
TextView * _messageTextView;
std::vector<AlertButtonView *> _buttons;
};
}

View file

@ -0,0 +1,84 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <SDL2/SDL2_gfxPrimitives.h>
#include "ControlView.hpp"
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
namespace dsu::views {
SDL_Color ControlView::_generateSelectionColor() {
SDL_Color color1 = AssetManager::selected_border_1;
SDL_Color color2 = AssetManager::selected_border_2;
SDL_Color result = { 0, 0, 0, 255 };
if (_timeElapsed > 2000)
_timeElapsed -= 2000;
// Color1 -> Color2
if (floor(((int) _timeElapsed) / 1000) == 0) {
double time = (_timeElapsed / 1000) * -1;
result.r = color1.r + floor((color1.r - color2.r) * time);
result.g = color1.g + floor((color1.g - color2.g) * time);
result.b = color1.b + floor((color1.b - color2.b) * time);
}
// Color2 -> Color1
else {
double time = ((_timeElapsed - 1000) / 1000) * -1;
result.r = color2.r + floor((color2.r - color1.r) * time);
result.g = color2.g + floor((color2.g - color1.g) * time);
result.b = color2.b + floor((color2.b - color1.b) * time);
}
return result;
}
void ControlView::_drawBorders(int x1, int y1, int x2, int y2, SDL_Color color) {
// Top
thickLineRGBA(
SceneDirector::renderer,
x1, y1 + 3, x2, y1 + 3,
5,
color.r, color.g, color.b, color.a);
// Right
thickLineRGBA(
SceneDirector::renderer,
x2 - 2, y1 + 3, x2 - 2, y2 - 3,
5,
color.r, color.g, color.b, color.a);
// Bottom
thickLineRGBA(
SceneDirector::renderer,
x2, y2 - 3, x1, y2 - 3,
5,
color.r, color.g, color.b, color.a);
// Left
thickLineRGBA(
SceneDirector::renderer,
x1 + 2, y2 - 3, x1 + 2, y1 + 3,
5,
color.r, color.g, color.b, color.a);
}
}

View file

@ -0,0 +1,32 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <string>
#include "../View.hpp"
namespace dsu::views {
class ControlView : public dsu::View {
protected:
double _timeElapsed;
SDL_Color _generateSelectionColor();
void _drawBorders(int x1, int y1, int x2, int y2, SDL_Color color);
};
}

125
source/views/FooterView.cpp Normal file
View file

@ -0,0 +1,125 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "FooterView.hpp"
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace dsu::models;
namespace dsu::views {
FooterView::FooterView() : View() {
isFocusable = false;
isTouchable = false;
if (AssetManager::a_button == NULL) {
SDL_Surface *surface = TTF_RenderGlyph_Blended(AssetManager::button_font, 0xE0E0, AssetManager::text);
AssetManager::a_button = SDL_CreateTextureFromSurface(SceneDirector::renderer, surface);
SDL_FreeSurface(surface);
}
if (AssetManager::b_button == NULL) {
SDL_Surface *surface = TTF_RenderGlyph_Blended(AssetManager::button_font, 0xE0E1, AssetManager::text);
AssetManager::b_button = SDL_CreateTextureFromSurface(SceneDirector::renderer, surface);
SDL_FreeSurface(surface);
}
if (AssetManager::x_button == NULL) {
SDL_Surface *surface = TTF_RenderGlyph_Blended(AssetManager::button_font, 0xE0E2, AssetManager::text);
AssetManager::x_button = SDL_CreateTextureFromSurface(SceneDirector::renderer, surface);
SDL_FreeSurface(surface);
}
if (AssetManager::y_button == NULL) {
SDL_Surface *surface = TTF_RenderGlyph_Blended(AssetManager::button_font, 0xE0E3, AssetManager::text);
AssetManager::y_button = SDL_CreateTextureFromSurface(SceneDirector::renderer, surface);
SDL_FreeSurface(surface);
}
if (AssetManager::handheld == NULL) {
SDL_Surface *surface = TTF_RenderGlyph_Blended(AssetManager::large_button_font, 0xE121, AssetManager::text);
AssetManager::handheld = SDL_CreateTextureFromSurface(SceneDirector::renderer, surface);
SDL_FreeSurface(surface);
}
}
FooterView::~FooterView() {
for (auto const& action : actions) {
delete action;
}
actions.clear();
}
void FooterView::render(SDL_Rect rect, double dTime) {
// Draw Background
AssetManager::setRenderColor(AssetManager::background);
SDL_RenderFillRect(SceneDirector::renderer, &rect);
// Divider.
AssetManager::setRenderColor(AssetManager::header_footer_divider);
SDL_RenderDrawLine(SceneDirector::renderer, rect.x + 30, rect.y, rect.w - 30, rect.y);
SDL_Rect handheldFrame = { 55, rect.y + 2, 70, 70 };
SDL_RenderCopy(SceneDirector::renderer, AssetManager::handheld, NULL, &handheldFrame);
// Render Actions.
int current_x = rect.w - 60;
for (auto const& action : actions) {
// Create texture if it doesn't already exists.
if (action->textTexture == NULL) {
SDL_Surface *surface = TTF_RenderText_Blended(AssetManager::body_font, action->text.c_str(), AssetManager::text);
action->textTexture = SDL_CreateTextureFromSurface(SceneDirector::renderer, surface);
action->textWidth = surface->w;
action->textHeight = surface->h;
SDL_FreeSurface(surface);
}
// Render Action Text
current_x -= action->textWidth;
SDL_Rect textFrame = { current_x, rect.y + 25, action->textWidth, action->textHeight };
SDL_RenderCopy(SceneDirector::renderer, action->textTexture, NULL, &textFrame);
current_x -= 37;
// Render Action Button Icon
SDL_Rect iconFrame = { current_x, rect.y + 25, 25, 25 };
switch(action->button) {
case B_BUTTON:
SDL_RenderCopy(SceneDirector::renderer, AssetManager::b_button, NULL, &iconFrame);
break;
case X_BUTTON:
SDL_RenderCopy(SceneDirector::renderer, AssetManager::x_button, NULL, &iconFrame);
break;
case Y_BUTTON:
SDL_RenderCopy(SceneDirector::renderer, AssetManager::y_button, NULL, &iconFrame);
break;
default:
SDL_RenderCopy(SceneDirector::renderer, AssetManager::a_button, NULL, &iconFrame);
break;
}
current_x -= 40;
}
// Render any subviews.
View::render(rect, dTime);
}
}

View file

@ -0,0 +1,37 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <list>
#include "../models/Action.hpp"
#include "../View.hpp"
namespace dsu::views {
class FooterView : public dsu::View {
public:
std::list<dsu::models::Action *> actions;
FooterView();
~FooterView();
void render(SDL_Rect rect, double dTime);
private:
void _renderButton(dsu::models::ActionButton button, SDL_Texture * texture, SDL_Rect frame);
};
}

View file

@ -0,0 +1,73 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "HeaderView.hpp"
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
namespace dsu::views {
HeaderView::HeaderView(string title, bool showIcon) : View() {
isFocusable = false;
isTouchable = false;
_showIcon = showIcon;
if (AssetManager::icon == NULL) {
AssetManager::icon = AssetManager::loadAsset("icon.png");
}
SDL_Surface *surface = TTF_RenderText_Blended(AssetManager::header_font, title.c_str(), AssetManager::text);
_titleTexture = SDL_CreateTextureFromSurface(SceneDirector::renderer, surface);
_titleWidth = surface->w;
_titleHeight = surface->h;
SDL_FreeSurface(surface);
}
HeaderView::~HeaderView() {
if (_titleTexture != NULL)
SDL_DestroyTexture(_titleTexture);
}
void HeaderView::render(SDL_Rect rect, double dTime) {
// Draw Background
AssetManager::setRenderColor(AssetManager::background);
SDL_RenderFillRect(SceneDirector::renderer, &rect);
if (_showIcon) {
// Icon
SDL_Rect iconFrame = { rect.x + 74, rect.y + 29, 30, 44 };
SDL_RenderCopy(SceneDirector::renderer, AssetManager::icon, NULL, &iconFrame);
// Title
SDL_Rect titleFrame = { rect.x + 132, rect.y + 36, _titleWidth, _titleHeight };
SDL_RenderCopy(SceneDirector::renderer, _titleTexture, NULL, &titleFrame);
} else {
// Title
SDL_Rect titleFrame = { rect.x + 74, rect.y + 36, _titleWidth, _titleHeight };
SDL_RenderCopy(SceneDirector::renderer, _titleTexture, NULL, &titleFrame);
}
// Divider
AssetManager::setRenderColor(AssetManager::header_footer_divider);
SDL_RenderDrawLine(SceneDirector::renderer, rect.x + 30, rect.y + 87, rect.w - 30, rect.y + 87);
// Render any subviews
View::render(rect, dTime);
}
}

View file

@ -0,0 +1,36 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include "TextView.hpp"
#include "../View.hpp"
namespace dsu::views {
class HeaderView : public dsu::View {
public:
HeaderView(std::string title, bool showIcon);
~HeaderView();
void render(SDL_Rect rect, double dTime);
private:
bool _showIcon;
SDL_Texture * _titleTexture;
int _titleWidth;
int _titleHeight;
};
}

View file

@ -0,0 +1,33 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "ImageView.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
namespace dsu::views {
ImageView::ImageView(SDL_Texture * image) : View() {
_image = image;
}
void ImageView::render(SDL_Rect rect, double dTime) {
SDL_RenderCopy(SceneDirector::renderer, _image, NULL, &rect);
View::render(rect, dTime);
}
}

View file

@ -0,0 +1,35 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include "../View.hpp"
using namespace std;
namespace dsu::views {
class ImageView : public dsu::View {
public:
ImageView(SDL_Texture * image);
~ImageView(){};
void render(SDL_Rect rect, double dTime);
private:
SDL_Texture * _image;
};
}

View file

@ -0,0 +1,129 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <SDL2/SDL2_gfxPrimitives.h>
#include "ListRowView.hpp"
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace std;
namespace dsu::views {
ListRowView::ListRowView(string primaryText, string secondaryText, ListRowStyle style) : ControlView() {
isLast = false;
hasCheckmark = false;
frame = { 0, 0, 850, 71 };
_timeElapsed = 0;
_isOn = false;
_style = style;
_primaryTextView = new TextView(AssetManager::body_font, primaryText, AssetManager::text);
_primaryTextView->textAlignment = LEFT_ALIGN;
if (style != SUBTITLE) {
_primaryTextView->frame = { 21, 26, 808, 0 };
} else {
_primaryTextView->frame = { 21, 10, 808, 0 };
}
addSubView(_primaryTextView);
if (style != DEFAULT) {
if (style == BOOLEAN) {
_secondaryTextView = new TextView(AssetManager::subbody_font, "Off", AssetManager::disabled_text);
} else {
_secondaryTextView = new TextView(AssetManager::subbody_font, secondaryText, (style == SUBTITLE) ? AssetManager::disabled_text : AssetManager::active_text);
}
if (style != SUBTITLE) {
_secondaryTextView->textAlignment = RIGHT_ALIGN;
_secondaryTextView->frame = { 21, 29, 808, 0 };
} else {
_secondaryTextView->textAlignment = LEFT_ALIGN;
_secondaryTextView->frame = { 21, 41, 808, 0 };
}
addSubView(_secondaryTextView);
} else {
_secondaryTextView = NULL;
}
if (AssetManager::checkmark == NULL) {
SDL_Surface *surface = TTF_RenderGlyph_Blended(AssetManager::button_font, 0xE14B, AssetManager::background);
AssetManager::checkmark = SDL_CreateTextureFromSurface(SceneDirector::renderer, surface);
SDL_FreeSurface(surface);
}
}
ListRowView::~ListRowView() {
if (_primaryTextView != NULL)
delete _primaryTextView;
if (_secondaryTextView != NULL)
delete _secondaryTextView;
}
void ListRowView::render(SDL_Rect rect, double dTime) {
// Draw Separators
AssetManager::setRenderColor(AssetManager::list_divider);
SDL_RenderDrawLine(SceneDirector::renderer, rect.x + 5, rect.y, rect.x + rect.w - 10, rect.y);
if (isLast) {
SDL_RenderDrawLine(SceneDirector::renderer, rect.x + 5, rect.y + rect.h, rect.x + rect.w - 10, rect.y + rect.h);
}
// Draw Focus Background
if (hasFocus) {
_timeElapsed += dTime;
SDL_Rect backgroundFrame = { rect.x + 5, rect.y + 5, rect.w - 10, rect.h - 10 };
AssetManager::setRenderColor(AssetManager::selected_background);
SDL_RenderFillRect(SceneDirector::renderer, &backgroundFrame);
SDL_Color selectionColor = _generateSelectionColor();
_drawBorders(rect.x, rect.y, rect.x + rect.w, rect.y + rect.h, selectionColor);
} else {
_timeElapsed = 0;
}
if (hasCheckmark) {
SDL_Color activeColor = AssetManager::active_text;
filledCircleRGBA(SceneDirector::renderer, rect.x + rect.w - 35, rect.y + 36, 15, activeColor.r, activeColor.g, activeColor.b, activeColor.a);
aacircleRGBA(SceneDirector::renderer, rect.x + rect.w - 35, rect.y + 36, 15, activeColor.r, activeColor.g, activeColor.b, activeColor.a);
SDL_Rect checkmarkFrame = { rect.x + rect.w - 47, rect.y + 24, 25, 25 };
SDL_RenderCopy(SceneDirector::renderer, AssetManager::checkmark, NULL, &checkmarkFrame);
}
// Render any subviews.
ControlView::render(rect, dTime);
}
void ListRowView::setPrimaryText(string text) {
_primaryTextView->setText(text);
}
void ListRowView::setSecondaryText(string text) {
_secondaryTextView->setText(text);
}
void ListRowView::setIsOn(bool isOn) {
_secondaryTextView->setText((isOn) ? "On" : "Off");
_secondaryTextView->setTextColor((isOn) ? AssetManager::active_text : AssetManager::disabled_text);
}
}

View file

@ -0,0 +1,58 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <string>
#include "ControlView.hpp"
#include "TextView.hpp"
namespace dsu::views {
typedef enum {
DEFAULT,
SUBTITLE,
VALUE,
BOOLEAN
} ListRowStyle;
class ListRowView : public ControlView {
public:
bool isLast;
bool hasCheckmark;
ListRowView(std::string primaryText, std::string secondaryText, ListRowStyle style);
~ListRowView();
void render(SDL_Rect rect, double dTime);
void setPrimaryText(std::string text);
void setSecondaryText(std::string text);
void setIsOn(bool isOn);
private:
bool _isOn;
TextView * _primaryTextView;
TextView * _secondaryTextView;
ListRowStyle _style;
void _renderDefaultStyle(SDL_Rect rect);
void _renderSubtitleStyle(SDL_Rect rect);
void _renderValueStyle(SDL_Rect rect);
};
}

View file

@ -0,0 +1,64 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <SDL2/SDL2_gfxPrimitives.h>
#include "ProgressBarView.hpp"
#include "../AssetManager.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
namespace dsu::views {
ProgressBarView::ProgressBarView() : View() {
progress = 0;
}
void ProgressBarView::render(SDL_Rect rect, double dTime) {
// Draw background.
roundedBoxRGBA(
SceneDirector::renderer,
rect.x,
rect.y,
rect.x + rect.w,
rect.y + rect.h,
rect.h / 2,
AssetManager::disabled_text.r, AssetManager::disabled_text.g, AssetManager::disabled_text.b, AssetManager::disabled_text.a);
// Draw progress bar.
int progressWidth = (rect.w - rect.h) * progress;
if (progressWidth > rect.w - rect.h)
progressWidth = rect.w - rect.h;
if (progressWidth < 0)
progressWidth = 0;
roundedBoxRGBA(
SceneDirector::renderer,
rect.x,
rect.y,
rect.x + rect.h + progressWidth,
rect.y + rect.h,
rect.h / 2,
AssetManager::active_text.r, AssetManager::active_text.g, AssetManager::active_text.b, AssetManager::active_text.a);
// Render any subviews.
View::render(rect, dTime);
}
}

View file

@ -0,0 +1,32 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include "../View.hpp"
namespace dsu::views {
class ProgressBarView : public dsu::View {
public:
double progress;
ProgressBarView();
~ProgressBarView(){};
void render(SDL_Rect rect, double dTime);
};
}

View file

@ -0,0 +1,61 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "StatusView.hpp"
#include "../AssetManager.hpp"
using namespace dsu;
using namespace std;
namespace dsu::views {
StatusView::StatusView(string text, string subtext) : View() {
frame = { 0, 0, 1280, 100 };
_textView = new TextView(AssetManager::body_font, text, AssetManager::text);
_textView->frame = { 0, 0, 1280, 1 };
_textView->textAlignment = CENTER_ALIGN;
_subtextView = new TextView(AssetManager::subbody_font, subtext, AssetManager::text);
_subtextView->frame = { 0, 52, 1280, 1 };
_subtextView->textAlignment = CENTER_ALIGN;
addSubView(_textView);
addSubView(_subtextView);
}
StatusView::~StatusView() {
if (_textView == NULL)
delete _textView;
if (_subtextView == NULL)
delete _subtextView;
}
void StatusView::render(SDL_Rect rect, double dTime) {
// Render any subviews.
View::render(rect, dTime);
}
void StatusView::setText(string text) {
_textView->setText(text);
}
void StatusView::setSubtext(string text) {
_subtextView->setText(text);
}
}

View file

@ -0,0 +1,41 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <string>
#include "TextView.hpp"
#include "../View.hpp"
using namespace std;
namespace dsu::views {
class StatusView : public dsu::View {
public:
StatusView(std::string text, std::string subtext);
~StatusView();
void render(SDL_Rect rect, double dTime);
void setText(std::string text);
void setSubtext(std::string text);
private:
TextView * _textView;
TextView * _subtextView;
};
}

118
source/views/TextView.cpp Normal file
View file

@ -0,0 +1,118 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <sstream>
#include "TextView.hpp"
#include "../SceneDirector.hpp"
using namespace dsu;
using namespace std;
namespace dsu::views {
TextView::TextView(TTF_Font * theFont, string theText, SDL_Color theTextColor) : View() {
isFocusable = false;
isTouchable = false;
textAlignment = LEFT_ALIGN;
alpha = 255;
lineHeight = TTF_FontHeight(theFont);
font = theFont;
text = theText;
textColor = theTextColor;
_reset();
}
TextView::~TextView() {
for (auto const& textLine : _textLines) {
SDL_DestroyTexture(textLine->textTexture);
}
_textLines.clear();
}
void TextView::render(SDL_Rect rect, double dTime) {
int y = rect.y;
for (auto const& textLine : _textLines) {
SDL_SetTextureAlphaMod(textLine->textTexture, alpha);
int x = 0;
int width = max(textLine->textWidth, rect.w);
switch (textAlignment) {
case LEFT_ALIGN:
x = rect.x;
break;
case CENTER_ALIGN:
x = rect.x + (width - textLine->textWidth) / 2;
break;
case RIGHT_ALIGN:
x = rect.x + width - textLine->textWidth;
break;
}
SDL_Rect textFrame = { x, y, textLine->textWidth, textLine->textHeight };
SDL_RenderCopy(SceneDirector::renderer, textLine->textTexture, NULL, &textFrame);
y += lineHeight;
}
// Render any subviews.
View::render(rect, dTime);
}
int TextView::getTextHeight() {
return _textLines.size() * lineHeight;
}
void TextView::setFont(TTF_Font * theFont) {
font = theFont;
_reset();
}
void TextView::setText(string theText) {
text = theText;
_reset();
}
void TextView::setTextColor(SDL_Color theTextColor) {
textColor = theTextColor;
_reset();
}
void TextView::_reset() {
for (auto const& textLine : _textLines) {
SDL_DestroyTexture(textLine->textTexture);
}
_textLines.clear();
stringstream textStream = stringstream(text);
string text;
while(getline(textStream, text, '\n')) {
SDL_Surface *surface = TTF_RenderText_Blended(font, text.c_str(), textColor);
if (surface != NULL) {
TextLine * textLine = new TextLine();
textLine->textTexture = SDL_CreateTextureFromSurface(SceneDirector::renderer, surface);
textLine->textWidth = surface->w;
textLine->textHeight = surface->h;
SDL_FreeSurface(surface);
_textLines.push_back(textLine);
}
}
}
}

63
source/views/TextView.hpp Normal file
View file

@ -0,0 +1,63 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <SDL2/SDL_ttf.h>
#include <string>
#include <vector>
#include "../View.hpp"
namespace dsu::views {
typedef enum {
LEFT_ALIGN,
CENTER_ALIGN,
RIGHT_ALIGN
} TextAlignment;
class TextLine {
public:
SDL_Texture * textTexture;
int textWidth;
int textHeight;
};
class TextView : public dsu::View {
public:
TTF_Font * font;
std::string text;
SDL_Color textColor;
TextAlignment textAlignment;
int alpha;
int lineHeight;
TextView(TTF_Font * theFont, std::string theText, SDL_Color theTextColor);
~TextView();
void render(SDL_Rect rect, double dTime);
int getTextHeight();
void setFont(TTF_Font * theFont);
void setText(std::string theText);
void setTextColor(SDL_Color theTextColor);
void setLineHeight(int lineHeight);
private:
std::vector<TextLine *> _textLines;
void _reset();
};
}

View file

@ -0,0 +1,74 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "UpdateView.hpp"
#include "../AssetManager.hpp"
using namespace dsu;
using namespace std;
namespace dsu::views {
UpdateView::UpdateView(string text) : View() {
frame = { 0, 0, 1280, 325 };
if (AssetManager::downloading == NULL) {
AssetManager::downloading = AssetManager::loadAsset("downloading.png");
}
_downloadImageView = new ImageView(AssetManager::downloading);
_downloadImageView->frame = { 400, 0, 479, 197 };
_progressBarView = new ProgressBarView();
_progressBarView->frame = { 437, 257, 411, 10 };
_statusTextView = new TextView(AssetManager::subbody_font, text, AssetManager::text);
_statusTextView->frame = { 0, 291, 1280, 0 };
_statusTextView->textAlignment = CENTER_ALIGN;
addSubView(_downloadImageView);
addSubView(_progressBarView);
addSubView(_statusTextView);
}
UpdateView::~UpdateView() {
if (_downloadImageView == NULL)
delete _downloadImageView;
if (_progressBarView == NULL)
delete _progressBarView;
if (_statusTextView == NULL)
delete _statusTextView;
}
void UpdateView::render(SDL_Rect rect, double dTime) {
// Render any subviews.
View::render(rect, dTime);
}
void UpdateView::setProgress(double progress) {
_progressBarView->progress = progress;
}
void UpdateView::setText(string text) {
_statusTextView->setText(text);
}
void UpdateView::setProgressBarHidden(bool hidden) {
_progressBarView->hidden = hidden;
}
}

View file

@ -0,0 +1,43 @@
// Isotope Updater
// Copyright (C) 2020 Nichole Mattera
//
// 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 2
// 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, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#pragma once
#include <string>
#include "ImageView.hpp"
#include "ProgressBarView.hpp"
#include "TextView.hpp"
#include "../View.hpp"
namespace dsu::views {
class UpdateView : public dsu::View {
public:
UpdateView(std::string text);
~UpdateView();
void render(SDL_Rect rect, double dTime);
void setProgress(double progress);
void setText(std::string text);
void setProgressBarHidden(bool hidden);
private:
ImageView * _downloadImageView;
ProgressBarView * _progressBarView;
TextView * _statusTextView;
};
}