Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
c667580fa6 | |||
10b2957250 | |||
7e7772e09d | |||
fc40dc1204 |
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -1,3 +1,3 @@
|
|||
[submodule "SimpleIniParser"]
|
||||
path = SimpleIniParser
|
||||
url = https://github.com/AtlasNX/SimpleIniParser
|
||||
url = https://github.com/AtlasNX/SimpleIniParser.git
|
||||
|
|
9
Makefile
9
Makefile
|
@ -30,13 +30,12 @@ include $(DEVKITPRO)/libnx/switch_rules
|
|||
# - icon.jpg
|
||||
# - <libnx folder>/default_icon.jpg
|
||||
#---------------------------------------------------------------------------------
|
||||
VERSION_MAJOR := 5
|
||||
VERSION_MINOR := 0
|
||||
VERSION_MICRO := 0
|
||||
VERSION_MAJOR := 1
|
||||
VERSION_MINOR := 2
|
||||
|
||||
APP_TITLE := Isotope Toolbox
|
||||
APP_AUTHOR := WerWolv, cathery, Slluxx
|
||||
APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}
|
||||
APP_AUTHOR := WerWolv, cathery, Ta180m
|
||||
APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}
|
||||
|
||||
TARGET := IsotopeToolbox
|
||||
OUTDIR := out
|
||||
|
|
1
SimpleIniParser
Submodule
1
SimpleIniParser
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 625d49fb533a7648d4996a7d292ffcd51fb2a61d
|
13
SimpleIniParser/.gitignore
vendored
13
SimpleIniParser/.gitignore
vendored
|
@ -1,13 +0,0 @@
|
|||
pkg
|
||||
src
|
||||
debug
|
||||
example/**/build
|
||||
example/**/*.elf
|
||||
example/**/*.nacp
|
||||
example/**/*.nro
|
||||
release
|
||||
lib
|
||||
.vscode
|
||||
*.tar.bz2
|
||||
*.tar.xz
|
||||
*.tar.gz
|
|
@ -1,13 +0,0 @@
|
|||
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.
|
|
@ -1,145 +0,0 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
.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
|
||||
#---------------------------------------------------------------------------------------
|
|
@ -1,11 +0,0 @@
|
|||
# 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.
|
|
@ -1,231 +0,0 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
.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
|
||||
#---------------------------------------------------------------------------------------
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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 <iostream>
|
||||
#include <fstream>
|
||||
#include <switch.h>
|
||||
#include <SimpleIniParser.hpp>
|
||||
|
||||
using namespace simpleIniParser;
|
||||
using namespace std;
|
||||
|
||||
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")) {
|
||||
cout << "Ini file writen to: sdmc:/example.ini\n";
|
||||
}
|
||||
|
||||
delete hekateIni;
|
||||
|
||||
cout << "Press any key to close.\n";
|
||||
|
||||
while(appletMainLoop())
|
||||
{
|
||||
hidScanInput();
|
||||
if (hidKeysDown(CONTROLLER_P1_AUTO))
|
||||
break;
|
||||
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
|
||||
consoleExit(NULL);
|
||||
return 0;
|
||||
}
|
|
@ -1,232 +0,0 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
.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
|
||||
#---------------------------------------------------------------------------------------
|
|
@ -1,26 +0,0 @@
|
|||
# Sample Config
|
||||
global_setting=1
|
||||
; Comments
|
||||
global_setting_two=2
|
||||
|
||||
[config]
|
||||
autoboot=1
|
||||
autoboot_list=0
|
||||
bootwait=5
|
||||
customlogo=1
|
||||
verification=1
|
||||
|
||||
{AtlasNX/Kosmos}
|
||||
|
||||
; 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
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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 <iostream>
|
||||
#include <fstream>
|
||||
#include <switch.h>
|
||||
#include <SimpleIniParser.hpp>
|
||||
|
||||
using namespace simpleIniParser;
|
||||
using namespace std;
|
||||
|
||||
void copy_file(string srcPath, string destPath);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
consoleInit(NULL);
|
||||
|
||||
Result rc = romfsInit();
|
||||
if (R_FAILED(rc)) {
|
||||
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;
|
||||
}
|
||||
cout << "Original file written to: sdmc:/example1.ini\n";
|
||||
cout << "Modified file written to: sdmc:/example2.ini\n\n";
|
||||
cout << "Press any key to close.\n";
|
||||
|
||||
while(appletMainLoop())
|
||||
{
|
||||
hidScanInput();
|
||||
if (hidKeysDown(CONTROLLER_P1_AUTO))
|
||||
break;
|
||||
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
|
||||
consoleExit(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void copy_file(string srcPath, string destPath) {
|
||||
ifstream src(srcPath, ios::binary);
|
||||
ofstream dest(destPath, ios::binary);
|
||||
|
||||
dest << src.rdbuf();
|
||||
|
||||
src.close();
|
||||
dest.flush();
|
||||
dest.close();
|
||||
}
|
|
@ -1,231 +0,0 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
.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
|
||||
#---------------------------------------------------------------------------------------
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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 <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:
|
||||
cout << ((withTab) ? "\t" : "") << "Type: Semicolon Comment, Value: \"" << option->value << "\"\n";
|
||||
break;
|
||||
|
||||
case IniOptionType::HashtagComment:
|
||||
cout << ((withTab) ? "\t" : "") << "Type: Hashtag Comment, Value: \"" << option->value << "\"\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
cout << ((withTab) ? "\t" : "") << "Type: Option, Key: \"" << option->key << "\", Value: \"" << option->value << "\"\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void writeSection(IniSection * section) {
|
||||
switch (section->type) {
|
||||
case IniSectionType::SemicolonComment:
|
||||
cout << "Type: Semicolon Comment, Value: \"" << section->value << "\"\n";
|
||||
break;
|
||||
|
||||
case IniSectionType::HashtagComment:
|
||||
cout << "Type: Hashtag Comment, Value: \"" << section->value << "\"\n";
|
||||
break;
|
||||
|
||||
case IniSectionType::HekateCaption:
|
||||
cout << "Type: Hekate Caption, Value: \"" << section->value << "\"\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
cout << "Type: Section, Value: \"" << section->value << "\"\n";
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto const& option : section->options) {
|
||||
writeOption(option, true);
|
||||
}
|
||||
|
||||
cout << "\n";
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
consoleInit(NULL);
|
||||
|
||||
Ini * config = Ini::parseFileWithMagic("sdmc:/atmosphere/BCT.ini", "BCT0");
|
||||
|
||||
cout << "Reading through an INI file.\n";
|
||||
cout << "=====================================================\n\n";
|
||||
|
||||
|
||||
for (auto const& option : config->options) {
|
||||
writeOption(option, false);
|
||||
}
|
||||
|
||||
if (config->options.size() > 0)
|
||||
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");
|
||||
|
||||
cout << "Modified version of BCT.ini has been writen to the root of your SD Card.\n";
|
||||
}
|
||||
}
|
||||
|
||||
delete config;
|
||||
|
||||
cout << "\nPress any key to close.\n";
|
||||
|
||||
while(appletMainLoop())
|
||||
{
|
||||
hidScanInput();
|
||||
if (hidKeysDown(CONTROLLER_P1_AUTO))
|
||||
break;
|
||||
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
|
||||
consoleExit(NULL);
|
||||
return 0;
|
||||
}
|
|
@ -1,232 +0,0 @@
|
|||
#---------------------------------------------------------------------------------
|
||||
.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
|
||||
#---------------------------------------------------------------------------------------
|
|
@ -1,26 +0,0 @@
|
|||
# Sample Config
|
||||
global_setting=1
|
||||
; Comments
|
||||
global_setting_two=2
|
||||
|
||||
[config]
|
||||
autoboot=1
|
||||
autoboot_list=0
|
||||
bootwait=5
|
||||
customlogo=1
|
||||
verification=1
|
||||
|
||||
{AtlasNX/Kosmos}
|
||||
|
||||
; 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
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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 <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:
|
||||
cout << ((withTab) ? "\t" : "") << "Type: Semicolon Comment, Value: \"" << option->value << "\"\n";
|
||||
break;
|
||||
|
||||
case IniOptionType::HashtagComment:
|
||||
cout << ((withTab) ? "\t" : "") << "Type: Hashtag Comment, Value: \"" << option->value << "\"\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
cout << ((withTab) ? "\t" : "") << "Type: Option, Key: \"" << option->key << "\", Value: \"" << option->value << "\"\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void writeSection(IniSection * section) {
|
||||
switch (section->type) {
|
||||
case IniSectionType::SemicolonComment:
|
||||
cout << "Type: Semicolon Comment, Value: \"" << section->value << "\"\n";
|
||||
break;
|
||||
|
||||
case IniSectionType::HashtagComment:
|
||||
cout << "Type: Hashtag Comment, Value: \"" << section->value << "\"\n";
|
||||
break;
|
||||
|
||||
case IniSectionType::HekateCaption:
|
||||
cout << "Type: Hekate Caption, Value: \"" << section->value << "\"\n";
|
||||
break;
|
||||
|
||||
default:
|
||||
cout << "Type: Section, Value: \"" << section->value << "\"\n";
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto const& option : section->options) {
|
||||
writeOption(option, true);
|
||||
}
|
||||
|
||||
cout << "\n";
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
consoleInit(NULL);
|
||||
|
||||
Result rc = romfsInit();
|
||||
if (R_FAILED(rc)) {
|
||||
cout << "Unable to initialize romfs.\n";
|
||||
}
|
||||
else {
|
||||
Ini * config = Ini::parseFile("romfs:/config.ini");
|
||||
|
||||
cout << "Reading through an INI file.\n";
|
||||
cout << "=====================================================\n\n";
|
||||
|
||||
|
||||
for (auto const& option : config->options) {
|
||||
writeOption(option, false);
|
||||
}
|
||||
|
||||
if (config->options.size() > 0)
|
||||
cout << "\n";
|
||||
|
||||
for (auto const& section : config->sections) {
|
||||
writeSection(section);
|
||||
}
|
||||
|
||||
cout << "\nGet a specific option from a specific section.\n";
|
||||
cout << "=====================================================\n\n";
|
||||
IniOption * option = config->findSection("config")->findFirstOption("cUsToMlOgO", false);
|
||||
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);
|
||||
cout << "Key: \"" << option2->key << "\" | Value: \"" << option2->value << "\"\n\n";
|
||||
|
||||
delete config;
|
||||
}
|
||||
|
||||
cout << "\nPress any key to close.\n";
|
||||
|
||||
while(appletMainLoop())
|
||||
{
|
||||
hidScanInput();
|
||||
if (hidKeysDown(CONTROLLER_P1_AUTO))
|
||||
break;
|
||||
|
||||
consoleUpdate(NULL);
|
||||
}
|
||||
|
||||
consoleExit(NULL);
|
||||
return 0;
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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 "SimpleIniParser/Ini.hpp"
|
||||
#include "SimpleIniParser/IniSection.hpp"
|
||||
#include "SimpleIniParser/IniOption.hpp"
|
||||
#include "SimpleIniParser/IniStringHelper.hpp"
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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 <vector>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#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);
|
||||
IniSection * findSection(std::string term, bool caseSensitive = true, IniSectionType type = IniSectionType::Any);
|
||||
IniSection * findOrCreateSection(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);
|
||||
};
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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>
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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 <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 key, 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::string build();
|
||||
static IniSection * parse(std::string line, bool parseComments);
|
||||
};
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
#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
|
||||
};
|
||||
}
|
|
@ -1,210 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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 <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <switch.h>
|
||||
|
||||
#include "Ini.hpp"
|
||||
#include "IniOption.hpp"
|
||||
#include "IniStringHelper.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace simpleIniParser {
|
||||
Ini::~Ini() {
|
||||
magic = "";
|
||||
|
||||
for (IniSection * section : sections) {
|
||||
if (section != nullptr) {
|
||||
delete section;
|
||||
section = nullptr;
|
||||
}
|
||||
}
|
||||
sections.clear();
|
||||
}
|
||||
|
||||
string Ini::build() {
|
||||
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(string term, bool caseSensitive, IniOptionType type, IniOptionSearchField field) {
|
||||
if (!caseSensitive) {
|
||||
IniStringHelper::toupper(term);
|
||||
}
|
||||
|
||||
auto it = find_if(options.begin(), options.end(), [&term, &caseSensitive, &type, &field](const IniOption * obj) {
|
||||
if (type != IniOptionType::Any && type != obj->type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
if (it == options.end())
|
||||
return nullptr;
|
||||
|
||||
return (*it);
|
||||
}
|
||||
|
||||
|
||||
IniOption * Ini::findOrCreateFirstOption(string key, 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;
|
||||
}
|
||||
|
||||
IniSection * Ini::findSection(string term, bool caseSensitive, IniSectionType type) {
|
||||
if (!caseSensitive) {
|
||||
IniStringHelper::toupper(term);
|
||||
}
|
||||
|
||||
auto it = find_if(sections.begin(), sections.end(), [&term, &caseSensitive, &type](const IniSection * obj) {
|
||||
if (type != IniSectionType::Any && type != obj->type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
string fieldValue = (!caseSensitive) ? IniStringHelper::toupper_copy(obj->value) : obj->value;
|
||||
return fieldValue == term;
|
||||
});
|
||||
|
||||
if (it == sections.end())
|
||||
return nullptr;
|
||||
|
||||
return (*it);
|
||||
}
|
||||
|
||||
IniSection * Ini::findOrCreateSection(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;
|
||||
}
|
||||
|
||||
bool Ini::writeToFile(string path) {
|
||||
ofstream file(path);
|
||||
if (!file.is_open())
|
||||
return false;
|
||||
|
||||
file << build();
|
||||
|
||||
file.flush();
|
||||
file.close();
|
||||
|
||||
fsdevCommitDevice("sdmc");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Ini * Ini::parseFile(string path) {
|
||||
ifstream file(path);
|
||||
if (!file.is_open())
|
||||
return nullptr;
|
||||
|
||||
stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
file.close();
|
||||
|
||||
return _parseContent(&buffer, "");
|
||||
}
|
||||
|
||||
Ini * Ini::parseFileWithMagic(string path, string magic) {
|
||||
ifstream file(path);
|
||||
if (!file.is_open())
|
||||
return nullptr;
|
||||
|
||||
stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
file.close();
|
||||
|
||||
string line;
|
||||
getline(buffer, line);
|
||||
IniStringHelper::trim(line);
|
||||
if (line != magic) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return _parseContent(&buffer, magic);
|
||||
}
|
||||
|
||||
Ini * Ini::parseOrCreateFile(string path, string magic) {
|
||||
auto it = Ini::parseFileWithMagic(path, magic);
|
||||
if (it == nullptr)
|
||||
it = new Ini();
|
||||
return it;
|
||||
}
|
||||
|
||||
Ini * Ini::_parseContent(stringstream * content, string magic) {
|
||||
Ini * ini = new Ini();
|
||||
ini->magic = magic;
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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 "IniOption.hpp"
|
||||
#include "IniStringHelper.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace simpleIniParser {
|
||||
IniOption::IniOption(IniOptionType t, string k, string v) {
|
||||
type = t;
|
||||
key = k;
|
||||
value = v;
|
||||
}
|
||||
|
||||
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(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 != 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* SimpleIniParser
|
||||
* 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 <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include "IniSection.hpp"
|
||||
#include "IniStringHelper.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace simpleIniParser {
|
||||
IniSection::IniSection(IniSectionType t, string v) {
|
||||
type = t;
|
||||
value = v;
|
||||
}
|
||||
|
||||
IniSection::~IniSection() {
|
||||
for (IniOption * option : options) {
|
||||
if (option != nullptr) {
|
||||
delete option;
|
||||
option = nullptr;
|
||||
}
|
||||
}
|
||||
options.clear();
|
||||
}
|
||||
|
||||
IniOption * IniSection::findFirstOption(string term, bool caseSensitive, IniOptionType type, IniOptionSearchField field) {
|
||||
if (!caseSensitive) {
|
||||
IniStringHelper::toupper(term);
|
||||
}
|
||||
|
||||
auto it = find_if(options.begin(), options.end(), [&term, &caseSensitive, &type, &field](const IniOption * obj) {
|
||||
if (type != IniOptionType::Any && type != obj->type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
if (it == options.end())
|
||||
return nullptr;
|
||||
|
||||
return (*it);
|
||||
}
|
||||
|
||||
IniOption * IniSection::findOrCreateFirstOption(string key, 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;
|
||||
}
|
||||
|
||||
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:
|
||||
string result = "\n[" + value + "]\n";
|
||||
|
||||
for (auto const& option : options) {
|
||||
result += option->build();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
IniSection * IniSection::parse(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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <locale>
|
||||
|
||||
#include "IniStringHelper.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace simpleIniParser {
|
||||
void IniStringHelper::toupper(string &s) {
|
||||
for_each(s.begin(), s.end(), [](char & c){
|
||||
c = ::toupper(c);
|
||||
});
|
||||
}
|
||||
|
||||
string IniStringHelper::toupper_copy(string s) {
|
||||
toupper(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
// Start of Source from https://stackoverflow.com/questions/216823
|
||||
void IniStringHelper::ltrim(string &s) {
|
||||
s.erase(s.begin(), find_if(s.begin(), s.end(), [](int ch) {
|
||||
return !isspace(ch);
|
||||
}));
|
||||
}
|
||||
|
||||
void IniStringHelper::rtrim(string &s) {
|
||||
s.erase(find_if(s.rbegin(), s.rend(), [](int ch) {
|
||||
return !isspace(ch);
|
||||
}).base(), s.end());
|
||||
}
|
||||
|
||||
void IniStringHelper::trim(string &s) {
|
||||
ltrim(s);
|
||||
rtrim(s);
|
||||
}
|
||||
|
||||
string IniStringHelper::ltrim_copy(string s) {
|
||||
ltrim(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
string IniStringHelper::rtrim_copy(string s) {
|
||||
rtrim(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
string IniStringHelper::trim_copy(string s) {
|
||||
trim(s);
|
||||
return s;
|
||||
}
|
||||
// End
|
||||
}
|
||||
|
||||
|
Reference in a new issue