Skip to content

Commit

Permalink
Documentation and minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
mtheall committed Apr 28, 2020
1 parent 86be27c commit 34c6d61
Show file tree
Hide file tree
Showing 56 changed files with 1,297 additions and 293 deletions.
12 changes: 7 additions & 5 deletions .gitignore
Expand Up @@ -10,8 +10,10 @@
*.pfs0
*.smdh
.gdb_history
build.*/
ftpd
romfs.3ds/*.t3x
romfs.switch/*.zst
romfs.switch/shaders/*.dksh
3ds/build
3ds/romfs/*.t3x
linux/build
linux/ftpd
switch/build
switch/romfs/*.zst
switch/romfs/shaders/*.dksh
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
26 changes: 13 additions & 13 deletions Makefile
Expand Up @@ -17,19 +17,19 @@ all: 3dsx nro linux
nxlink:
@$(MAKE) -f Makefile.switch nxlink

3dslink: 3dsx
@/opt/devkitpro/tools/bin/3dslink $(TARGET)-3ds.3dsx
3dslink:
@$(MAKE) -f Makefile.3ds 3dslink

format:
@clang-format -style=file -i $(filter-out \
include/imgui.h \
source/pc/imgui_impl_glfw.cpp \
source/pc/imgui_impl_glfw.h \
source/pc/imgui_impl_opengl3.cpp \
source/pc/imgui_impl_opengl3.h \
source/pc/KHR/khrplatform.h \
source/pc/glad.c \
source/pc/glad/glad.h \
source/linux/imgui_impl_glfw.cpp \
source/linux/imgui_impl_glfw.h \
source/linux/imgui_impl_opengl3.cpp \
source/linux/imgui_impl_opengl3.h \
source/linux/KHR/khrplatform.h \
source/linux/glad.c \
source/linux/glad/glad.h \
source/imgui/imgui.cpp \
source/imgui/imgui_demo.cpp \
source/imgui/imgui_draw.cpp \
Expand All @@ -41,9 +41,9 @@ format:
$(shell find source include -type f -name \*.c -o -name \*.cpp -o -name \*.h))

release: release-3ds release-nro
@xz -c <$(TARGET)-3ds.3dsx >ftpd.3dsx.xz
@echo xz -c <$(TARGET)-3ds.cia >ftpd.cia.xz
@echo xz -c <$(TARGET)-nx.nro >ftpd.nro.xz
@xz -c <3ds/$(TARGET).3dsx >ftpd.3dsx.xz
@xz -c <3ds/$(TARGET).cia >ftpd.cia.xz
@xz -c <switch/$(TARGET).nro >ftpd.nro.xz

nro:
@$(MAKE) -f Makefile.switch all
Expand All @@ -64,7 +64,7 @@ release-cia: release-3dsx
@$(MAKE) DEFINES=-NDEBUG -f Makefile.3ds cia

release-3ds:
# can't let these three run in parallel with each other due to using same
# can't let these run in parallel with each other due to using same
# .elf file name
@$(MAKE) DEFINES=-DNDEBUG -f Makefile.3ds 3dsx
@$(MAKE) DEFINES=-DNDEBUG -f Makefile.3ds cia
Expand Down
17 changes: 10 additions & 7 deletions Makefile.3ds
Expand Up @@ -31,13 +31,13 @@ include $(DEVKITARM)/3ds_rules
# - icon.png
# - <libctru folder>/default_icon.png
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))-3ds
BUILD := build.3ds
TARGET := 3ds/$(notdir $(CURDIR))
BUILD := 3ds/build
SOURCES := source source/3ds source/imgui
DATA := data
INCLUDES := include
GRAPHICS := gfx.3ds
ROMFS := romfs.3ds
GRAPHICS := 3ds/gfx
ROMFS := 3ds/romfs
GFXBUILD := $(ROMFS)

APP_TITLE := ftpd
Expand Down Expand Up @@ -66,7 +66,7 @@ CFLAGS += $(INCLUDE) -DARM11 -D_3DS \
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(TARGET).map $(OPTIMIZE)
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) $(OPTIMIZE)

LIBS := -lcitro3d -lctru -lm

Expand All @@ -81,7 +81,7 @@ LIBDIRS := $(CTRULIB)
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
ifneq ($(TOPDIR)/$(BUILD),$(CURDIR))
#---------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)
Expand Down Expand Up @@ -165,7 +165,7 @@ ifneq ($(ROMFS),)
export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
endif

.PHONY: $(BUILD) clean all 3dsx cia
.PHONY: $(BUILD) clean all 3dsx cia 3dslink

#---------------------------------------------------------------------------------
all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES)
Expand Down Expand Up @@ -196,6 +196,9 @@ $(GFXBUILD)/%.t3x $(BUILD)/%.h: %.t3s
cia: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES)
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.3ds cia

3dslink: 3dsx
@3dslink $(OUTPUT).3dsx

#---------------------------------------------------------------------------------
clean:
@echo clean ...
Expand Down
10 changes: 5 additions & 5 deletions Makefile.linux
@@ -1,12 +1,12 @@
TARGET := ftpd
BUILD := build.linux
TARGET := linux/ftpd
BUILD := linux/build

CFILES := $(wildcard source/pc/*.c)
CFILES := $(wildcard source/linux/*.c)
OFILES := $(patsubst source/%,$(BUILD)/%,$(CFILES:.c=.c.o))
CXXFILES := $(wildcard source/*.cpp source/imgui/*.cpp source/pc/*.cpp)
CXXFILES := $(wildcard source/*.cpp source/imgui/*.cpp source/linux/*.cpp)
OXXFILES := $(patsubst source/%,$(BUILD)/%,$(CXXFILES:.cpp=.cpp.o))

CPPFLAGS := -g -Wall -pthread -Iinclude -Isource/pc \
CPPFLAGS := -g -Wall -pthread -Iinclude -Isource/linux \
`pkg-config --cflags gl glfw3` \
-DSTATUS_STRING="\"ftpd v$(VERSION)\"" \
-DIMGUI_DISABLE_INCLUDE_IMCONFIG_H=1 \
Expand Down
17 changes: 7 additions & 10 deletions Makefile.switch
Expand Up @@ -42,13 +42,13 @@ APP_AUTHOR := mtheall, TuxSH, WinterMute
ICON := meta/ftpd.jpg
APP_VERSION := $(VERSION)

TARGET := $(notdir $(CURDIR))-nx
BUILD := build.switch
SOURCES := source source/imgui source/nx
TARGET := switch/$(notdir $(CURDIR))
BUILD := switch/build
SOURCES := source source/imgui source/switch
DATA := data
INCLUDES := include
GRAPHICS := gfx.switch
ROMFS := romfs.switch
GRAPHICS := switch/gfx
ROMFS := switch/romfs

# Output folders for autogenerated files in romfs
OUT_SHADERS := shaders
Expand Down Expand Up @@ -85,7 +85,7 @@ 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)))
ifneq ($(TOPDIR)/$(BUILD),$(CURDIR))
#---------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)
Expand Down Expand Up @@ -193,7 +193,7 @@ all: $(ROMFS_TARGETS) | $(BUILD)
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.switch

nxlink: all
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.switch nxlink
@nxlink -s $(OUTPUT).nro

$(BUILD):
@mkdir -p $@
Expand Down Expand Up @@ -260,9 +260,6 @@ ifeq ($(strip $(APP_JSON)),)

all : $(OUTPUT).nro

nxlink: $(OUTPUT).nro
@nxlink -s $(OUTPUT).nro

ifeq ($(strip $(NO_NACP)),)
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp $(ROMFS_DEPS)
else
Expand Down
74 changes: 69 additions & 5 deletions include/fs.h
Expand Up @@ -29,8 +29,11 @@

namespace fs
{
/// \brief Print size in human-readable format (KiB, MiB, etc)
/// \param size_ Size to print
std::string printSize (std::uint64_t size_);

/// \brief File I/O object
class File
{
public:
Expand All @@ -40,51 +43,97 @@ class File

File (File const &that_) = delete;

/// \brief Move constructor
/// \param that_ Object to move from
File (File &&that_);

File &operator= (File const &that_) = delete;

/// \brief Move assignment
/// \param that_ Object to move from
File &operator= (File &&that_);

operator bool () const;
operator FILE * () const;
/// \brief bool cast operator
explicit operator bool () const;

/// \brief std::FILE* cast operator
operator std::FILE * () const;

/// \brief Set buffer size
/// \param size_ Buffer size
void setBufferSize (std::size_t size_);

/// \brief Open file
/// \param path_ Path to open
/// \param mode_ Access mode (\sa std::fopen)
bool open (char const *path_, char const *mode_ = "rb");

/// \brief Close file
void close ();

/// \brief Seek to file position
/// \param pos_ File position
/// \param origin_ Reference position (\sa std::fseek)
ssize_t seek (std::size_t pos_, int origin_);

/// \brief Read data
/// \param data_ Output buffer
/// \param size_ Size to read
/// \note Can return partial reads
ssize_t read (void *data_, std::size_t size_);

/// \brief Read data
/// \param data_ Output buffer
/// \param size_ Size to read
/// \note Fails on partial reads and errors
bool readAll (void *data_, std::size_t size_);

/// \brief Write data
/// \param data_ Input data
/// \param size_ Size to write
/// \note Can return partial writes
ssize_t write (void const *data_, std::size_t size_);

/// \brief Write data
/// \param data_ Input data
/// \param size_ Size to write
/// \note Fails on partials writes and errors
bool writeAll (void const *data_, std::size_t size_);

/// \brief Read data
/// \tparam T Type to read
template <typename T>
T read ()
{
T data;
if (read (&data, sizeof (data)) != sizeof (data))
if (!readAll (&data, sizeof (data)))
std::abort ();

return data;
}

/// \brief Write data
/// \tparam T type to write
/// \param data_ Data to write
template <typename T>
void write (T const &data_)
{
if (write (&data_, sizeof (data_)) != sizeof (data_))
if (!writeAll (&data_, sizeof (data_)))
std::abort ();
}

private:
/// \brief Underlying std::FILE*
std::unique_ptr<std::FILE, int (*) (std::FILE *)> m_fp{nullptr, nullptr};

/// \brief Buffer
std::unique_ptr<char[]> m_buffer;

/// \brief Buffer size
std::size_t m_bufferSize = 0;
};

/// Directory object
class Dir
{
public:
Expand All @@ -94,20 +143,35 @@ class Dir

Dir (Dir const &that_) = delete;

/// \brief Move constructor
/// \param that_ Object to move from
Dir (Dir &&that_);

Dir &operator= (Dir const &that_) = delete;

/// \brief Move assignment
/// \param that_ Object to move from
Dir &operator= (Dir &&that_);

operator bool () const;
/// \brief bool cast operator
explicit operator bool () const;

/// \brief DIR* cast operator
operator DIR * () const;

/// \brief Open directory
/// \param path_ Path to open
bool open (char const *const path_);

/// \brief Close directory
void close ();

/// \brief Read a directory entry
/// \note Returns nullptr on end-of-directory or error; check errno
struct dirent *read ();

private:
/// \brief Underlying DIR*
std::unique_ptr<DIR, int (*) (DIR *)> m_dp{nullptr, nullptr};
};
}

0 comments on commit 34c6d61

Please sign in to comment.