commit f2cb06b8f909a816ebb8c96f9e4c8497effab406 Author: dragonflylee Date: Thu Apr 13 15:21:21 2023 +0800 Initial commit diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..1e07f3f --- /dev/null +++ b/.clang-format @@ -0,0 +1,14 @@ +--- +BasedOnStyle: Google +ColumnLimit: 120 +AccessModifierOffset: -4 +AlignAfterOpenBracket: false +IndentWidth: 4 +BreakBeforeBraces: Attach +CommentPragmas: '^[^ ]' +IncludeBlocks: Regroup +PointerAlignment: Left +SortIncludes: Never +IndentCaseLabels : false +Standard: Cpp11 +... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f5bc79 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +/build +/.vscode +/cDrive.* \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..e3cbb32 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,32 @@ +{ + "configurations": [ + { + "name": "Switch", + "includePath": [ + "${workspaceFolder}/**", + "${env:DEVKITPRO}/libnx/include", + "${env:DEVKITPRO}/devkitA64/aarch64-none-elf/include/**", + "${env:DEVKITPRO}/portlibs/switch/include/**" + ], + "defines": [ + "__SWITCH__" + ], + "compilerPath": "${env:DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "gcc-arm64" + }, + { + "name": "MinGW64", + "includePath": [ + "${workspaceFolder}/**", + "D:\\msys64\\mingw64\\include" + ], + "compilerPath": "D:\\msys64\\mingw64\\bin\\gcc.exe", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "windows-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9d45bce --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.15) + +set(CMAKE_BUILD_TYPE Release) + +find_package(CURL REQUIRED) + +project(cDrive) +file(GLOB_RECURSE MAIN_SRC "${CMAKE_SOURCE_DIR}/src/*.cpp") +add_executable(${PROJECT_NAME} ${MAIN_SRC}) +target_include_directories(${PROJECT_NAME} PRIVATE include) + +if (NINTENDO_SWITCH) + target_link_libraries(${PROJECT_NAME} + PRIVATE + glfw3 glapi drm_nouveau nx m + CURL::libcurl + ) + nx_generate_nacp(${PROJECT_NAME}.nacp NAME ${PROJECT_NAME} AUTHOR dragonflylee VERSION 1.0) + nx_create_nro(${PROJECT_NAME} ICON ${CMAKE_SOURCE_DIR}/icon.jpg NACP ${PROJECT_NAME}.nacp) +else () + find_package(glfw3 REQUIRED) + if (MINGW) + set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") + endif () + target_link_libraries(${PROJECT_NAME} PRIVATE glfw CURL::libcurl) +endif () \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d3894d2 --- /dev/null +++ b/Makefile @@ -0,0 +1,189 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +TOPDIR ?= $(CURDIR) +include $(DEVKITPRO)/libnx/switch_rules + +#--------------------------------------------------------------------------------- +TARGET := cDrive +BUILD := build +SRCS := src +DATA := data +INCLUDES := include +#ROMFS := romfs + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE +CFLAGS := -g -Wall -O2 -ffunction-sections $(ARCH) $(DEFINES) `curl-config --cflags` +CFLAGS += $(INCLUDE) -D__SWITCH__ +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -DIMGUI_IMPL_OPENGL_LOADER_CUSTOM +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) +LIBS := -lglfw3 -lEGL -lglapi -ldrm_nouveau `curl-config --libs` + +#--------------------------------------------------------------------------------- +# 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 OUTPUT := $(CURDIR)/$(TARGET) +export TOPDIR := $(CURDIR) + +export VPATH := $(foreach dir,$(SRCS),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SRCS),$(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) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... +ifeq ($(strip $(APP_JSON)),) + @rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf +else + @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf +endif + + +#--------------------------------------------------------------------------------- +else +.PHONY: all + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +ifeq ($(strip $(APP_JSON)),) + +all : $(OUTPUT).nro + +ifeq ($(strip $(NO_NACP)),) +$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp +else +$(OUTPUT).nro : $(OUTPUT).elf +endif + +else + +all : $(OUTPUT).nsp + +$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm + +$(OUTPUT).nso : $(OUTPUT).elf + +endif + +$(OUTPUT).elf : $(OFILES) + +$(OFILES_SRC) : $(HFILES_BIN) + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/Makefile.mingw b/Makefile.mingw new file mode 100644 index 0000000..3d9f047 --- /dev/null +++ b/Makefile.mingw @@ -0,0 +1,24 @@ +TARGET := cDrive +SRCS := src + +VPATH := $(foreach dir,$(SRCS),$(CURDIR)/$(dir)) +CFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SRCS),$(notdir $(wildcard $(dir)/*.cpp))) +OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) + +INCLUDES := -I$(CURDIR)/include +CFLAGS := -O2 -Wall $(INCLUDES) `curl-config --cflags` +CXXFLAGS := $(CFLAGS) -fno-rtti -std=c++17 +LDFLAGS := `curl-config --libs` `pkg-config glfw3 --libs` + +.PHONY: all +all: $(TARGET) + +$(TARGET): $(OFILES) + $(CXX) -o $@ $^ $(LDFLAGS) + +run: all + @./$(TARGET) + +clean: + $(RM) $(OFILES) $(TARGET) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..df42c0f --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# cDrive +Cloud drive explorer for C/C++ + +### Build On MSYS2 + +```bash +pacman -S ${MINGW_PACKAGE_PREFIX}-glfw ${MINGW_PACKAGE_PREFIX}-cc + +cmake -B build -G 'MinGW Makefiles' +cmake --build build +``` + +### Building for Switch + +To build for Switch, a standard development environment must first be set up. In order to do so, [refer to the Getting Started guide](https://devkitpro.org/wiki/Getting_Started). + +```bash +(dkp-)pacman -S switch-glfw switch-curl + +cmake -B build -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Switch.cmake" +make -C build xPlayer_nro -j$(nproc) +# for debug +nxlink -a 192.168.3.97 -s build/xPlayer.nro --args https://pan.3m3m.top/api/public/dl/Cwg6sGXL +``` \ No newline at end of file diff --git a/icon.jpg b/icon.jpg new file mode 100644 index 0000000..cf97369 Binary files /dev/null and b/icon.jpg differ diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..a2bb330 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,62 @@ +#include + +#include +#define GLFW_INCLUDE_NONE +#include + +#ifdef __SWITCH__ +#include + +extern "C" void userAppInit() { + socketInitializeDefault(); + nxlinkStdio(); + appletSetWirelessPriorityMode(AppletWirelessPriorityMode_OptimizedForWlan); + plInitialize(PlServiceType_User); +} + +extern "C" void userAppExit() { + plExit(); + socketExit(); +} +#endif + +static void die(const char* msg) { + fprintf(stderr, "%s\n", msg); + exit(1); +} + +int main(int argc, char* argv[]) { + if (!glfwInit()) die("init glfw failed"); + + curl_global_init(CURL_GLOBAL_ALL); + + // Create window with graphics context + GLFWwindow* window = glfwCreateWindow(1280, 720, "cDrive", nullptr, nullptr); + if (!window) { + glfwTerminate(); + return -1; + } + glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods) { + if (action == GLFW_PRESS) { + if (key == GLFW_KEY_ESCAPE) glfwSetWindowShouldClose(window, 1); + } + }); + + glfwMakeContextCurrent(window); + glfwSwapInterval(1); + glfwSetTime(0); + + int fbw = 0, fbh = 0; + // Main loop + while (!glfwWindowShouldClose(window)) { + glfwGetFramebufferSize(window, &fbw, &fbh); + glfwSwapBuffers(window); + glfwWaitEvents(); + } + + curl_global_cleanup(); + + glfwDestroyWindow(window); + glfwTerminate(); + return 0; +} \ No newline at end of file