diff --git a/OSLoader/start.c b/OSLoader/start.c index 858ecbca..f3e60902 100644 --- a/OSLoader/start.c +++ b/OSLoader/start.c @@ -220,7 +220,7 @@ void System(void *par) { for (int i = 120; i <= 150; ++i) DisplayFillBox(i - 2, 84, i, 92, 72); - if ((*bootAddr != 0xEF5AE0EF) && *(bootAddr + 1) != 0xFECDAFDE) { + if ((*bootAddr != 0xEF5AE0EF) && *(bootAddr + 1) != 0xFECDAFDE || portIsKeyDown(KEY_F3)) { slowDownEnable(false); // DisplayClean(); // DisplayPutStr(0, 16 * 0, "========[Exist OS Loader]======", 0, 255, 16); diff --git a/System/Fs/Fatfs/ffconf.h b/System/Fs/Fatfs/ffconf.h index f124fccd..e8cffa89 100644 --- a/System/Fs/Fatfs/ffconf.h +++ b/System/Fs/Fatfs/ffconf.h @@ -84,7 +84,7 @@ / Locale and Namespace Configurations /---------------------------------------------------------------------------*/ -#define FF_CODE_PAGE 437 +#define FF_CODE_PAGE 936 /* This option specifies the OEM code page to be used on the target system. / Incorrect code page setting can cause a file open failure. / diff --git a/System/UICore.cpp b/System/UICore.cpp index 5ea8e506..66646122 100644 --- a/System/UICore.cpp +++ b/System/UICore.cpp @@ -50,6 +50,19 @@ void memtest(uint32_t testSize); extern uint32_t OnChipMemorySize; extern uint32_t TotalAllocatableSize; +TCHAR *pathNow, *pathBefore; +TCHAR **dirItemNames; +bool *dirItemInfos; // ture:file false:folder +unsigned long *filesCount; +unsigned char *openStatus; +unsigned int *pageNow, *pageAll; +unsigned char *selectedItem; +static DIR fileManagerDir; +static FILINFO fileInfo; +unsigned long getFileCounts(TCHAR *path); +void refreshFileNames(TCHAR *path, TCHAR **names, bool *info, unsigned long *counts); +void refreshDir(); + size_t getOnChipHeapAllocated(); size_t getSwapMemHeapAllocated(); @@ -101,6 +114,8 @@ void UI_SetLang(int lang) { MAIN_WIN_TITLE = MAIN_WIN_TITLE_EN; MAIN_WIN_FKEY_BAR = MAIN_WIN_FKEY_BAR_EN; MAIN_WIN_FKEY_BAR2 = MAIN_WIN_FKEY_BAR2_EN; + MAIN_WIN_FKEY_BARFILE = MAIN_WIN_FKEY_BARFILE_EN; + UI_TEMPERRATURE = UI_TEMPERRATURE_EN; UI_MEMUSE = UI_MEMUSED_EN; UI_BATTERY = UI_BATTERY_EN; @@ -122,6 +137,8 @@ void UI_SetLang(int lang) { MAIN_WIN_TITLE = MAIN_WIN_TITLE_CN; MAIN_WIN_FKEY_BAR = MAIN_WIN_FKEY_BAR_CN; MAIN_WIN_FKEY_BAR2 = MAIN_WIN_FKEY_BAR2_CN; + MAIN_WIN_FKEY_BARFILE = MAIN_WIN_FKEY_BARFILE_CN; + UI_TEMPERRATURE = UI_TEMPERRATURE_CN; UI_MEMUSE = UI_MEMUSED_CN; UI_BATTERY = UI_BATTERY_CN; @@ -178,6 +195,16 @@ void pageUpdate() { uidisp->draw_printf(180, 0, 16, 255, -1, "%s", timeStr); } + if (curPage == 2) { + uidisp->draw_box(180, 0, 255, 11, -1, 0); + uidisp->draw_printf(180, 0, 16, 255, -1, "%s", timeStr); + uidisp->draw_box(DISPX, DISPY + 16, 255, DISPY + 16, -1, 0); + uidisp->draw_printf(DISPX, DISPY, 16, 0, 255, "%d item(s) [%s] (%d/%d)", *filesCount, pathNow, *pageNow, *pageAll); + for (int i = 1; i <= 5 && ((*pageNow - 1) * 5 + i) <= *filesCount; i++) { + uidisp->draw_printf(DISPX, DISPY + i * 16 + 1, 16, (i == *selectedItem ? 255 : 0), (i == *selectedItem ? 0 : 255), "%s%s", (dirItemInfos[(*pageNow - 1) * 5 + i - 1] == false ? "/" : ""), dirItemNames[(*pageNow - 1) * 5 + i - 1]); + } + } + if (curPage == 3) { uidisp->draw_box(180, 0, 255, 11, -1, 0); uidisp->draw_printf(200, 0, 16, 255, -1, "%d/%d", page3Subpage + 1, CONF_SUBPAGES); @@ -333,12 +360,29 @@ void keyMsg(uint32_t key, int state) { timeChange(0, 0, 1); } break; + default: break; } } if (state == KEY_TRIG) { + if (curPage == 2 && (key == KEY_F1 || key == KEY_F6)) { + f_closedir(&fileManagerDir); + free(pathNow); + for (int i = 0; i < *filesCount; i++) { + free(dirItemNames[i]); + } + free(dirItemNames); + free(dirItemInfos); + free(filesCount); + free(openStatus); + free(pageNow); + free(pageAll); + free(selectedItem); + free(pathBefore); + } + switch (key) { case KEY_SHIFT: shift++; @@ -370,6 +414,78 @@ void keyMsg(uint32_t key, int state) { mainw->setFuncKeys(MAIN_WIN_FKEY_BAR); break; + case KEY_F5: + if (curPage == 2) + break; + + filesCount = (unsigned long *)malloc(sizeof(unsigned long)); + pathNow = (TCHAR *)calloc(255, sizeof(TCHAR)); + pathBefore = (TCHAR *)calloc(255, sizeof(TCHAR)); + openStatus = (unsigned char *)malloc(sizeof(unsigned char)); + pageNow = (unsigned int *)malloc(sizeof(unsigned int)); + pageAll = (unsigned int *)malloc(sizeof(unsigned int)); + selectedItem = (unsigned char *)malloc(sizeof(unsigned char)); // 1 to 5 + + if (pathNow != NULL && pathBefore != NULL && filesCount != NULL && openStatus != NULL && pageNow != NULL && pageAll != NULL) { + strcpy(pathNow, "/"); + strcpy(pathBefore, "/"); + if (f_opendir(&fileManagerDir, pathNow) == FR_OK) { + if (f_readdir(&fileManagerDir, &fileInfo) == FR_OK) { + f_closedir(&fileManagerDir); + + *filesCount = getFileCounts(pathNow); + *pageNow = 1; + *selectedItem = 1; + *pageAll = *filesCount / 5 + (*filesCount % 5 == 0 ? 0 : 1); + + dirItemNames = (TCHAR **)calloc(*filesCount, sizeof(TCHAR *)); + dirItemInfos = (bool *)calloc(*filesCount, sizeof(bool)); + for (int i = 0; i < *filesCount; i++) { + dirItemNames[i] = (TCHAR *)calloc(255, sizeof(TCHAR)); + } + + refreshFileNames(pathNow, dirItemNames, dirItemInfos, filesCount); + if (dirItemNames != NULL) { + curPage = 2; + drawPage(curPage); + mainw->setFuncKeys(MAIN_WIN_FKEY_BARFILE); + } else { + *openStatus = 2; + } + + } else { + *openStatus = 1; + } + } else { + *openStatus = 1; + } + } else { + *openStatus = 1; + } + + switch (*openStatus) { + case 2: + for (int i = 0; i < *filesCount; i++) { + free(dirItemNames[i]); + } + free(dirItemNames); + free(dirItemInfos); + // NO "break;" here. :P + case 1: + free(filesCount); + free(openStatus); + free(pathNow); + free(pageNow); + free(pageAll); + free(selectedItem); + free(pathBefore); + break; + + default: + break; + } + break; + case KEY_F4: { if (curPage == 3) { if (page3Subpage < CONF_SUBPAGES - 1) @@ -401,17 +517,43 @@ void keyMsg(uint32_t key, int state) { case KEY_LEFT: if (curPage == 0) { - if (appPage_select > 0) + if (appPage_select > 0) { appPage_select--; - drawPage(curPage); + drawPage(curPage); + } + } else if (curPage == 2) { + if (strcmp(pathNow, "/")) { + strcpy(pathNow, pathBefore); + refreshDir(); + drawPage(curPage); + } } break; case KEY_RIGHT: if (curPage == 0) { - if (appPage_select < 1) + if (appPage_select < 1) { appPage_select++; - drawPage(curPage); + drawPage(curPage); + } + } + break; + + case KEY_UP: + if (curPage == 2) { + if (*selectedItem != 1) { + (*selectedItem)--; + drawPage(curPage); + } + } + break; + + case KEY_DOWN: + if (curPage == 2) { + if (*selectedItem != 5 && (*pageNow - 1) * 5 + *selectedItem != *filesCount) { + (*selectedItem)++; + drawPage(curPage); + } } break; @@ -422,8 +564,37 @@ void keyMsg(uint32_t key, int state) { void StartKhiCAS(); StartKhiCAS(); } + } else if (curPage == 2) { + if (dirItemInfos[(*pageNow - 1) * 5 + *selectedItem - 1] == false) { + // open a folder + strcpy(pathBefore, pathNow); + strcat(pathNow, dirItemNames[(*pageNow - 1) * 5 + *selectedItem - 1]); + strcat(pathNow, "/"); + + refreshDir(); + drawPage(curPage); + } else { + // do something with the file here... + } + } + break; + + case KEY_PLUS: + if (*pageNow < *pageAll) { + (*pageNow)++; + *selectedItem = 1; + drawPage(curPage); + } + break; + + case KEY_SUBTRACTION: + if (*pageNow > 1) { + (*pageNow)--; + *selectedItem = 1; + drawPage(curPage); } break; + case KEY_1: if (curPage == 3) { switch (page3Subpage) { @@ -552,6 +723,71 @@ static void checkFS() { } } +unsigned long getFileCounts(TCHAR *path) { + unsigned long count = 0; + DIR dir; + FILINFO fno; + f_opendir(&dir, path); + for (;;) { + if (f_readdir(&dir, &fno) == FR_OK) { + if (fno.fname[0] != 0) { + count++; + } else { + break; + } + } else { + break; + } + } + f_closedir(&dir); + return count; +} + +void refreshFileNames(TCHAR *path, TCHAR **names, bool *info, unsigned long *counts) { + DIR dir; + FILINFO fno; + f_opendir(&dir, path); + for (int i = 0; i < *counts; i++) { + if (f_readdir(&dir, &fno) == FR_OK) { + strcat(names[i], fno.fname); + if (fno.fattrib & AM_DIR) { + info[i] = false; + } else { + info[i] = true; + } + } else { + break; + } + } + f_closedir(&dir); +} + +void refreshDir() { + for (int i = 0; i < *filesCount; i++) { + free(dirItemNames[i]); + } + free(dirItemNames); + free(dirItemInfos); + if (f_opendir(&fileManagerDir, pathNow) == FR_OK) { + if (f_readdir(&fileManagerDir, &fileInfo) == FR_OK) { + f_closedir(&fileManagerDir); + + *filesCount = getFileCounts(pathNow); + *pageNow = 1; + *selectedItem = 1; + *pageAll = *filesCount / 5 + (*filesCount % 5 == 0 ? 0 : 1); + + dirItemNames = (TCHAR **)calloc(*filesCount, sizeof(TCHAR *)); + dirItemInfos = (bool *)calloc(*filesCount, sizeof(bool)); + for (int i = 0; i < *filesCount; i++) { + dirItemNames[i] = (TCHAR *)calloc(255, sizeof(TCHAR)); + } + + refreshFileNames(pathNow, dirItemNames, dirItemInfos, filesCount); + } + } +} + void UI_Task(void *_) { uidisp = new UI_Display(LCD_PIX_W, LCD_PIX_H, ll_disp_put_area); diff --git a/System/UICore.h b/System/UICore.h index 02264b88..35c9ed13 100644 --- a/System/UICore.h +++ b/System/UICore.h @@ -210,7 +210,7 @@ class UI_Display { break; } } else { - draw_char_GBK16(x, y0, buffer[i + 1] | (buffer[i] << 8), fg, -1); + draw_char_GBK16(x, y0, buffer[i + 1] | (buffer[i] << 8), fg, bg); x += 16; if (x > disp_w) { break; diff --git a/System/UI_Chinese.h b/System/UI_Chinese.h index ff0e5ace..63a9f1b8 100644 --- a/System/UI_Chinese.h +++ b/System/UI_Chinese.h @@ -2,37 +2,37 @@ #pragma once -#define TEST_STRING_CN "我能吞下玻璃而不伤身体" +#define TEST_STRING_CN "我能吞下玻璃而不伤身体" #define MAIN_WIN_TITLE_CN "Exist OS" -#define MAIN_WIN_FKEY_BAR_CN "应用|终端| | | |设置|" -#define MAIN_WIN_FKEY_BAR2_CN "应用|终端|<|>| |设置|" +#define MAIN_WIN_FKEY_BAR_CN "应用|终端| | |文件|设置|" +#define MAIN_WIN_FKEY_BAR2_CN "应用|终端|<|>|文件|设置|" +#define MAIN_WIN_FKEY_BARFILE_CN "应用|终端|属性|复制|删除|设置|" - -#define UI_TEMPERRATURE_CN "温度" -#define UI_MEMUSED_CN "内存使用" +#define UI_TEMPERRATURE_CN "温度" +#define UI_MEMUSED_CN "内存使用" #define UI_BATTERY_CN "电池电压" #define UI_CHARGING_CN "充电中" -#define UI_TIME_CN "时间" +#define UI_TIME_CN "时间" -#define UI_Power_Save_Mode_CN "省电模式 " -#define UI_Enable_Charge_CN "开启充电" +#define UI_Power_Save_Mode_CN "省电模式 " +#define UI_Enable_Charge_CN "开启充电" #define UI_FS_init1 "文件系统未初始化" #define UI_FS_init2 "按下[F2]键进行格式化" #define UI_FS_init3 "正在进行格式化..." -#define UI_LANGUAGE_CN "语言" -#define UI_LANGUAGE_CHINESE_CN "中文" +#define UI_LANGUAGE_CN "语言" +#define UI_LANGUAGE_CHINESE_CN "中文" -#define UI_Hours_CN "时" -#define UI_Minutes_CN "分" -#define UI_Seconds_CN "秒" +#define UI_Hours_CN "时" +#define UI_Minutes_CN "分" +#define UI_Seconds_CN "秒" -#define UI_Storage_Space_CN "存储空间" -#define UI_ONF5Format_CN "[ON]+[F5]打开格式化菜单" +#define UI_Storage_Space_CN "存储空间" +#define UI_ONF5Format_CN "[ON]+[F5]打开格式化菜单" diff --git a/System/UI_English.h b/System/UI_English.h index 4b10d02a..5502f101 100644 --- a/System/UI_English.h +++ b/System/UI_English.h @@ -2,32 +2,33 @@ #pragma once -#define TEST_STRING_EN "I can eat glass, it doesn't hurt me." +#define TEST_STRING_EN "I can eat glass, it doesn't hurt me." #define MAIN_WIN_TITLE_EN "Exist OS" -#define MAIN_WIN_FKEY_BAR_EN "APP|CONS| | | |CONF|" -#define MAIN_WIN_FKEY_BAR2_EN "APP|CONS|<|>| |CONF|" +#define MAIN_WIN_FKEY_BAR_EN "APP|CONS| | |FILE|CONF|" +#define MAIN_WIN_FKEY_BAR2_EN "APP|CONS|<|>|FILE|CONF|" +#define MAIN_WIN_FKEY_BARFILE_EN "APP|CONS|INFO|COPY|DEL|CONF|" -#define UI_TEMPERRATURE_EN "Temp." -#define UI_MEMUSED_EN "MEM USED" +#define UI_TEMPERRATURE_EN "Temp." +#define UI_MEMUSED_EN "MEM USED" #define UI_BATTERY_EN "Battery" #define UI_CHARGING_EN "Charging" -#define UI_TIME_EN "Time" +#define UI_TIME_EN "Time" -#define UI_Power_Save_Mode_EN "Power Save Mode" -#define UI_Enable_Charge_EN "Enable Charge" +#define UI_Power_Save_Mode_EN "Power Save Mode" +#define UI_Enable_Charge_EN "Enable Charge" -#define UI_LANGUAGE_EN "Language" -#define UI_LANGUAGE_ENGLISH_EN "EN" +#define UI_LANGUAGE_EN "Language" +#define UI_LANGUAGE_ENGLISH_EN "EN" -#define UI_Hours_EN "H" -#define UI_Minutes_EN "M" -#define UI_Seconds_EN "S" +#define UI_Hours_EN "H" +#define UI_Minutes_EN "M" +#define UI_Seconds_EN "S" -#define UI_Storage_Space_EN "Storage Space" -#define UI_ONF5Format_EN "[ON]+[F5] enter format menu" +#define UI_Storage_Space_EN "Storage Space" +#define UI_ONF5Format_EN "[ON]+[F5] enter format menu" -#define UI_Allocate_Mem_EN "Allocate MEM" -#define UI_PhyMem_EN "Phy MEM" -#define UI_Compression_rate_EN "Compression rate" \ No newline at end of file +#define UI_Allocate_Mem_EN "Allocate MEM" +#define UI_PhyMem_EN "Phy MEM" +#define UI_Compression_rate_EN "Compression rate" \ No newline at end of file diff --git a/System/UI_Language.h b/System/UI_Language.h index edec5011..18dd2544 100644 --- a/System/UI_Language.h +++ b/System/UI_Language.h @@ -5,8 +5,7 @@ const char *MAIN_WIN_TITLE = MAIN_WIN_TITLE_EN; const char *MAIN_WIN_FKEY_BAR = MAIN_WIN_FKEY_BAR_EN; const char *MAIN_WIN_FKEY_BAR2 = MAIN_WIN_FKEY_BAR2_EN; - - +const char *MAIN_WIN_FKEY_BARFILE = MAIN_WIN_FKEY_BARFILE_EN; const char *UI_TEMPERRATURE = UI_TEMPERRATURE_EN; const char *UI_MEMUSE = UI_MEMUSED_EN;