Skip to content

Commit 1107e60

Browse files
committed
fs: Refactor FS to use libc and add support for browsing USB devices via libusbhsfs
1 parent 6f3d028 commit 1107e60

30 files changed

+867
-594
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@
3636
*.elf
3737
*.nacp
3838
build/
39-
res/shaders
39+
res/shaders
40+
!libs/lib/libusbhsfs.a

Makefile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,44 @@ ROMFS := res
4747
# Output folders for autogenerated files in romfs
4848
OUT_SHADERS := shaders
4949

50-
VERSION_MAJOR := 3
51-
VERSION_MINOR := 2
50+
VERSION_MAJOR := 4
51+
VERSION_MINOR := 0
5252
VERSION_MICRO := 0
5353

5454
APP_TITLE := NX-Shell
5555
APP_AUTHOR := Joel16
5656
APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}
5757

58+
EXT_LIBS := $(CURDIR)/libs
59+
5860
#---------------------------------------------------------------------------------
5961
# options for code generation
6062
#---------------------------------------------------------------------------------
6163
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
6264

63-
CFLAGS := -g -Wall -O2 -ffunction-sections $(ARCH) $(DEFINES)
65+
CFLAGS := -g -Wall -O3 -ffunction-sections -Wno-restrict $(ARCH) $(DEFINES)
6466

6567
CFLAGS += $(INCLUDE) -D__SWITCH__
6668
CFLAGS += `freetype-config --cflags`
6769
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_MICRO=$(VERSION_MICRO)
68-
CFLAGS += -DIMGUI_IMPL_OPENGL_LOADER_GLAD -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_DISABLE_DEMO_WINDOWS
69-
CFLAGS += -DIMGUI_DISABLE_DEBUG_TOOLS -DIMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS
70-
CFLAGS += -DIMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS -DIMGUI_DISABLE_WIN32_FUNCTIONS
71-
CFLAGS += -DIMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION -DIMGUI_ENABLE_FREETYPE
70+
CFLAGS += -DIMGUI_IMPL_OPENGL_LOADER_GLAD -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_DISABLE_DEMO_WINDOWS
71+
CFLAGS += -DIMGUI_DISABLE_DEBUG_TOOLS -DIMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS
72+
CFLAGS += -DIMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS -DIMGUI_DISABLE_WIN32_FUNCTIONS
73+
CFLAGS += -DIMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION -DIMGUI_ENABLE_FREETYPE
7274

7375
CXXFLAGS := $(CFLAGS) -std=gnu++20 -fno-exceptions -fno-rtti
7476

7577
ASFLAGS := -g $(ARCH)
7678
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
7779

7880
LIBS := `curl-config --libs` `freetype-config --libs` -lgif -lturbojpeg -ljpeg -lpng -lwebp -ljansson \
79-
-lglad -lEGL -lglapi -ldrm_nouveau -lnx -lm -lz
81+
-lglad -lEGL -lglapi -ldrm_nouveau -lusbhsfs -lnx -lm -lz
8082

8183
#---------------------------------------------------------------------------------
8284
# list of directories containing libraries, this must be the top level containing
8385
# include and lib
8486
#---------------------------------------------------------------------------------
85-
LIBDIRS := $(PORTLIBS) $(LIBNX)
87+
LIBDIRS := $(PORTLIBS) $(LIBNX) $(EXT_LIBS)
8688

8789

8890
#---------------------------------------------------------------------------------

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ NX Shell is a multi-purpose file manager for the Nintendo Switch that aims towar
2121
- **Preetisketch** for the banner.
2222
- **Dear ImGui developers and contributors** for the GUI.
2323
- **devkitPro maintainers and contributors** for libnx, devkitA64, and many other packages used by this project.
24+
- **DarkMatterCore** for libusbhsfs.

include/config.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ typedef struct {
1010
} config_t;
1111

1212
extern config_t cfg;
13-
extern char cwd[FS_MAX_PATH];
13+
extern std::string cwd;
14+
extern std::string device;
1415

1516
namespace Config {
1617
int Save(config_t &config);

include/fs.hpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@ extern FsFileSystem *fs;
2323
extern FsFileSystem devices[FileSystemMax];
2424

2525
namespace FS {
26-
bool FileExists(const char path[FS_MAX_PATH]);
27-
bool DirExists(const char path[FS_MAX_PATH]);
28-
Result GetFileSize(const char path[FS_MAX_PATH], s64 &size);
29-
std::string GetFileExt(const std::string &filename);
30-
FileType GetFileType(const std::string &filename);
31-
Result GetDirList(const char path[FS_MAX_PATH], std::vector<FsDirectoryEntry> &entries);
32-
Result ChangeDirNext(const char path[FS_MAX_PATH], std::vector<FsDirectoryEntry> &entries);
33-
Result ChangeDirPrev(std::vector<FsDirectoryEntry> &entries);
34-
Result GetTimeStamp(FsDirectoryEntry &entry, FsTimeStampRaw &timestamp);
35-
Result Rename(FsDirectoryEntry &entry, const char filename[FS_MAX_PATH]);
36-
Result Delete(FsDirectoryEntry &entry);
37-
Result SetArchiveBit(FsDirectoryEntry &entry);
26+
bool FileExists(const std::string &path);
27+
bool DirExists(const std::string &path);
28+
bool GetFileSize(const std::string &path, std::size_t &size);
29+
bool GetDirList(const std::string &device, const std::string &path, std::vector<FsDirectoryEntry> &entries);
30+
bool ChangeDirNext(const std::string &path, std::vector<FsDirectoryEntry> &entries);
31+
bool ChangeDirPrev(std::vector<FsDirectoryEntry> &entries);
32+
bool GetTimeStamp(FsDirectoryEntry &entry, FsTimeStampRaw &timestamp);
33+
bool Rename(FsDirectoryEntry &entry, const std::string &dest_path);
34+
bool Delete(FsDirectoryEntry &entry);
3835
void Copy(FsDirectoryEntry &entry, const std::string &path);
39-
Result Paste(void);
40-
Result Move(void);
36+
bool Paste(void);
37+
bool Move(void);
38+
FileType GetFileType(const std::string &filename);
39+
Result SetArchiveBit(const std::string &path);
4140
Result GetFreeStorageSpace(s64 &size);
4241
Result GetTotalStorageSpace(s64 &size);
4342
Result GetUsedStorageSpace(s64 &size);
43+
std::string BuildPath(FsDirectoryEntry &entry);
44+
std::string BuildPath(const std::string &path, bool device_name);
45+
std::string GetFileExt(const std::string &filename);
4446
}

include/language.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ namespace Lang {
4848
SettingsTitle,
4949
SettingsSortTitle,
5050
SettingsLanguageTitle,
51+
SettingsUSBTitle,
52+
SettingsUSBUnmount,
5153
SettingsImageViewTitle,
5254
SettingsDevOptsTitle,
5355
SettingsAboutTitle,
5456
SettingsCheckForUpdates,
55-
SettingsSortNameAsc,
56-
SettingsSortNameDesc,
57-
SettingsSortSizeLarge,
58-
SettingsSortSizeSmall,
5957
SettingsImageViewFilenameToggle,
6058
SettingsDevOptsLogsToggle,
6159
SettingsAboutVersion,
@@ -71,6 +69,10 @@ namespace Lang {
7169
UpdateRestart,
7270
UpdateNotAvailable,
7371

72+
// USB Dialog
73+
USBUnmountPrompt,
74+
USBUnmountSuccess,
75+
7476
// Keyboard
7577
KeyboardEmpty,
7678

include/popups.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Popups {
2222
void FilePropertiesPopup(WindowData &data);
2323
void ImageProperties(bool &state, Tex &texture);
2424
void OptionsPopup(WindowData &data);
25-
void ProgressPopup(float offset, float size, const std::string &title, const std::string &text);
2625
void UpdatePopup(bool &state, bool &connection_status, bool &available, const std::string &tag);
2726
void ProgressBar(float offset, float size, const std::string &title, const std::string &text);
27+
void USBPopup(bool &state);
2828
}

include/textures.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern std::vector<Tex> file_icons;
1515
extern Tex folder_icon, check_icon, uncheck_icon;
1616

1717
namespace Textures {
18-
bool LoadImageFile(const char path[FS_MAX_PATH], std::vector<Tex> &textures);
18+
bool LoadImageFile(const std::string &path, std::vector<Tex> &textures);
1919
void Free(Tex &texture);
2020
void Init(void);
2121
void Exit(void);

include/usb.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include <switch.h>
4+
#include <vector>
5+
6+
namespace USB {
7+
Result Init(void);
8+
void Exit(void);
9+
void Unmount(void);
10+
bool Connected(void);
11+
}

include/windows.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <string>
34
#include <switch.h>
45
#include <vector>
56

@@ -26,7 +27,8 @@ enum FS_SORT_STATE {
2627
typedef struct {
2728
std::vector<bool> checked;
2829
std::vector<bool> checked_copy;
29-
char cwd[FS_MAX_PATH + 1] = "";
30+
std::string cwd = "";
31+
std::string device = "";
3032
u64 count = 0;
3133
} WindowCheckboxData;
3234

@@ -44,9 +46,11 @@ typedef struct {
4446

4547
extern WindowData data;
4648
extern int sort;
49+
extern std::vector<std::string> devices_list;
4750

4851
namespace FileBrowser {
4952
bool Sort(const FsDirectoryEntry &entryA, const FsDirectoryEntry &entryB);
53+
bool TableSort(const FsDirectoryEntry &entryA, const FsDirectoryEntry &entryB);
5054
}
5155

5256
namespace ImageViewer {

0 commit comments

Comments
 (0)