Skip to content

Commit 3363538

Browse files
committed
initial commit
1 parent 575b83a commit 3363538

124 files changed

Lines changed: 34106 additions & 676 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "include/Plutonium"]
2+
path = include/Plutonium
3+
url = https://github.com/HookedBehemoth/Plutonium

LICENSE

Lines changed: 674 additions & 674 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
#---------------------------------------------------------------------------------
2+
.SUFFIXES:
3+
#---------------------------------------------------------------------------------
4+
5+
ifeq ($(strip $(DEVKITPRO)),)
6+
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
7+
endif
8+
9+
TOPDIR ?= $(CURDIR)
10+
include $(DEVKITPRO)/libnx/switch_rules
11+
12+
#---------------------------------------------------------------------------------
13+
# TARGET is the name of the output
14+
# BUILD is the directory where object files & intermediate files will be placed
15+
# SOURCES is a list of directories containing source code
16+
# DATA is a list of directories containing data files
17+
# INCLUDES is a list of directories containing header files
18+
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
19+
#
20+
# NO_ICON: if set to anything, do not use icon.
21+
# NO_NACP: if set to anything, no .nacp file is generated.
22+
# APP_TITLE is the name of the app stored in the .nacp file (Optional)
23+
# APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
24+
# APP_VERSION is the version of the app stored in the .nacp file (Optional)
25+
# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
26+
# ICON is the filename of the icon (.jpg), relative to the project folder.
27+
# If not set, it attempts to use one of the following (in this order):
28+
# - <Project name>.jpg
29+
# - icon.jpg
30+
# - <libnx folder>/default_icon.jpg
31+
#
32+
# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
33+
# If not set, it attempts to use one of the following (in this order):
34+
# - <Project name>.json
35+
# - config.json
36+
# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
37+
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
38+
# NACP building is skipped as well.
39+
#---------------------------------------------------------------------------------
40+
TARGET := $(notdir $(CURDIR))
41+
BUILD := build
42+
SOURCES := source source/ui source/data source/install source/nx source/nx/ipc source/util
43+
DATA := data
44+
INCLUDES := include include/ui include/data include/install include/nx include/nx/ipc include/util include/Plutonium/Plutonium/Output-switch/include
45+
APP_TITLE := Tinleaf Installer
46+
APP_AUTHOR := Adubbz & Xortroll
47+
APP_VERSION := 1.3.2
48+
ROMFS := romfs
49+
50+
#---------------------------------------------------------------------------------
51+
# options for code generation
52+
#---------------------------------------------------------------------------------
53+
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
54+
55+
CFLAGS := -g -Wall -O2 -ffunction-sections \
56+
$(ARCH) $(DEFINES)
57+
58+
CFLAGS += $(INCLUDE) -D__SWITCH__ -Wall -Werror #-D__DEBUG__ -DNXLINK_DEBUG
59+
60+
CXXFLAGS := $(CFLAGS) -fno-rtti -std=gnu++17 -Wall -Werror
61+
62+
63+
ASFLAGS := -g $(ARCH)
64+
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
65+
66+
LIBS := -lcurl -lz -lmbedtls -lmbedcrypto -lmbedx509 -lminizip -lnx -lstdc++fs -lzzip -lpu -lfreetype -lSDL2_mixer -lopusfile -lssh2 -lopus -lmodplug -lmpg123 -lvorbisidec -lSDL2 -lc -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lwebp -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lzstd
67+
68+
#---------------------------------------------------------------------------------
69+
# list of directories containing libraries, this must be the top level containing
70+
# include and lib
71+
#---------------------------------------------------------------------------------
72+
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/include/Plutonium/Plutonium/Output
73+
74+
75+
#---------------------------------------------------------------------------------
76+
# no real need to edit anything past this point unless you need to add additional
77+
# rules for different file extensions
78+
#---------------------------------------------------------------------------------
79+
ifneq ($(BUILD),$(notdir $(CURDIR)))
80+
#---------------------------------------------------------------------------------
81+
82+
export OUTPUT := $(CURDIR)/$(TARGET)
83+
export TOPDIR := $(CURDIR)
84+
85+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
86+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
87+
88+
export DEPSDIR := $(CURDIR)/$(BUILD)
89+
90+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
91+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
92+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
93+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
94+
95+
#---------------------------------------------------------------------------------
96+
# use CXX for linking C++ projects, CC for standard C
97+
#---------------------------------------------------------------------------------
98+
ifeq ($(strip $(CPPFILES)),)
99+
#---------------------------------------------------------------------------------
100+
export LD := $(CC)
101+
#---------------------------------------------------------------------------------
102+
else
103+
#---------------------------------------------------------------------------------
104+
export LD := $(CXX)
105+
#---------------------------------------------------------------------------------
106+
endif
107+
#---------------------------------------------------------------------------------
108+
109+
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
110+
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
111+
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
112+
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
113+
114+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
115+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
116+
-I$(CURDIR)/$(BUILD)
117+
118+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
119+
120+
ifeq ($(strip $(CONFIG_JSON)),)
121+
jsons := $(wildcard *.json)
122+
ifneq (,$(findstring $(TARGET).json,$(jsons)))
123+
export APP_JSON := $(TOPDIR)/$(TARGET).json
124+
else
125+
ifneq (,$(findstring config.json,$(jsons)))
126+
export APP_JSON := $(TOPDIR)/config.json
127+
endif
128+
endif
129+
else
130+
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
131+
endif
132+
133+
ifeq ($(strip $(ICON)),)
134+
icons := $(wildcard *.jpg)
135+
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
136+
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
137+
else
138+
ifneq (,$(findstring icon.jpg,$(icons)))
139+
export APP_ICON := $(TOPDIR)/icon.jpg
140+
endif
141+
endif
142+
else
143+
export APP_ICON := $(TOPDIR)/$(ICON)
144+
endif
145+
146+
ifeq ($(strip $(NO_ICON)),)
147+
export NROFLAGS += --icon=$(APP_ICON)
148+
endif
149+
150+
ifeq ($(strip $(NO_NACP)),)
151+
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
152+
endif
153+
154+
ifneq ($(APP_TITLEID),)
155+
export NACPFLAGS += --titleid=$(APP_TITLEID)
156+
endif
157+
158+
ifneq ($(ROMFS),)
159+
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
160+
endif
161+
162+
.PHONY: $(BUILD) clean all
163+
164+
#---------------------------------------------------------------------------------
165+
all: $(BUILD)
166+
167+
$(BUILD):
168+
@[ -d $@ ] || mkdir -p $@
169+
#comment this out if you are hacking on the code or compilation will take forever
170+
$(MAKE) --no-print-directory -C include/Plutonium -f Makefile lib
171+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
172+
173+
#---------------------------------------------------------------------------------
174+
clean:
175+
@echo clean ...
176+
ifeq ($(strip $(APP_JSON)),)
177+
@$(MAKE) --no-print-directory -C include/Plutonium/Plutonium -f Makefile clean
178+
@rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
179+
else
180+
@$(MAKE) --no-print-directory -C include/Plutonium/Plutonium -f Makefile clean
181+
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
182+
endif
183+
184+
185+
#---------------------------------------------------------------------------------
186+
else
187+
.PHONY: all
188+
189+
DEPENDS := $(OFILES:.o=.d)
190+
191+
#---------------------------------------------------------------------------------
192+
# main targets
193+
#---------------------------------------------------------------------------------
194+
ifeq ($(strip $(APP_JSON)),)
195+
196+
all : $(OUTPUT).nro
197+
198+
ifeq ($(strip $(NO_NACP)),)
199+
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
200+
else
201+
$(OUTPUT).nro : $(OUTPUT).elf
202+
endif
203+
204+
else
205+
206+
all : $(OUTPUT).nsp
207+
208+
$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm
209+
210+
$(OUTPUT).nso : $(OUTPUT).elf
211+
212+
endif
213+
214+
$(OUTPUT).elf : $(OFILES)
215+
216+
$(OFILES_SRC) : $(HFILES_BIN)
217+
218+
#---------------------------------------------------------------------------------
219+
# you need a rule like this for each extension you use as binary data
220+
#---------------------------------------------------------------------------------
221+
%.bin.o %_bin.h : %.bin
222+
#---------------------------------------------------------------------------------
223+
@echo $(notdir $<)
224+
@$(bin2o)
225+
226+
-include $(DEPENDS)
227+
228+
#---------------------------------------------------------------------------------------
229+
endif
230+
#---------------------------------------------------------------------------------------

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
1-
# tinleaf
2-
A No-Bullshit-No-Bullshit NSP, NSZ, XCI, and XCZ Installer for Nintendo Switch
1+
# Tinleaf
2+
A No-Bullshit-No-Bullshit NSP, NSZ, XCI, and XCZ Installer for Nintendo Switch
3+
4+
![Tinleaf Installer Main Menu](tinleaf.jpg)
5+
6+
## Features
7+
- Installs NSP/NSZ/XCI/XCZ files and split NSP/XCI files from your SD card
8+
- Installs NSP/NSZ/XCI/XCZ files over LAN or USB from tools such as [NS-USBloader](https://github.com/developersu/ns-usbloader)
9+
- Installs NSP/NSZ/XCI/XCZ files over the internet by URL or Google Drive
10+
- Verifies NCAs by header signature before they're installed
11+
- Installs and manages the latest signature patches quickly and easily
12+
13+
## Thanks to
14+
- Adubbz
15+
- Blawar

Tinfoil.LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2017-2018 Adubbz
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

icon.jpg

19.9 KB
Loading
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Copyright (c) 2017-2018 Adubbz
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
*/
22+
23+
#pragma once
24+
25+
#include <atomic>
26+
#include <switch/types.h>
27+
#include <memory>
28+
29+
#include "nx/ncm.hpp"
30+
#include "nx/nca_writer.h"
31+
32+
namespace tin::data
33+
{
34+
static const size_t BUFFER_SEGMENT_DATA_SIZE = 0x800000; // Approximately 8MB
35+
extern int NUM_BUFFER_SEGMENTS;
36+
37+
struct BufferSegment
38+
{
39+
std::atomic_bool isFinalized = false;
40+
u64 writeOffset = 0;
41+
u8 data[BUFFER_SEGMENT_DATA_SIZE] = {0};
42+
};
43+
44+
// Receives data in a circular buffer split into 8MB segments
45+
class BufferedPlaceholderWriter
46+
{
47+
private:
48+
size_t m_totalDataSize = 0;
49+
size_t m_sizeBuffered = 0;
50+
size_t m_sizeWrittenToPlaceholder = 0;
51+
52+
// The current segment to which further data will be appended
53+
u64 m_currentFreeSegment = 0;
54+
BufferSegment* m_currentFreeSegmentPtr = NULL;
55+
// The current segment that will be written to the placeholder
56+
u64 m_currentSegmentToWrite = 0;
57+
BufferSegment* m_currentSegmentToWritePtr = NULL;
58+
59+
std::unique_ptr<BufferSegment[]> m_bufferSegments;
60+
61+
std::shared_ptr<nx::ncm::ContentStorage> m_contentStorage;
62+
NcmContentId m_ncaId;
63+
NcaWriter m_writer;
64+
65+
public:
66+
BufferedPlaceholderWriter(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId ncaId, size_t totalDataSize);
67+
68+
void AppendData(void* source, size_t length);
69+
bool CanAppendData(size_t length);
70+
71+
void WriteSegmentToPlaceholder();
72+
bool CanWriteSegmentToPlaceholder();
73+
74+
// Determine the number of segments required to fit data of this size
75+
u32 CalcNumSegmentsRequired(size_t size);
76+
77+
// Check if there are enough free segments to fit data of this size
78+
bool IsSizeAvailable(size_t size);
79+
80+
bool IsBufferDataComplete();
81+
bool IsPlaceholderComplete();
82+
83+
size_t GetTotalDataSize();
84+
size_t GetSizeBuffered();
85+
size_t GetSizeWrittenToPlaceholder();
86+
87+
void DebugPrintBuffers();
88+
};
89+
}

0 commit comments

Comments
 (0)