1
0

Initial commit

This commit is contained in:
2023-04-13 15:21:21 +08:00
commit f2cb06b8f9
9 changed files with 375 additions and 0 deletions

14
.clang-format Normal file
View File

@@ -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
...

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.o
/build
/.vscode
/cDrive.*

32
.vscode/c_cpp_properties.json vendored Normal file
View File

@@ -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
}

26
CMakeLists.txt Normal file
View File

@@ -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 ()

189
Makefile Normal file
View File

@@ -0,0 +1,189 @@
#---------------------------------------------------------------------------------
.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 := 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
#---------------------------------------------------------------------------------------

24
Makefile.mingw Normal file
View File

@@ -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)

24
README.md Normal file
View File

@@ -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
```

BIN
icon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

62
src/main.cpp Normal file
View File

@@ -0,0 +1,62 @@
#include <cstdlib>
#include <curl/curl.h>
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#ifdef __SWITCH__
#include <switch.h>
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;
}