mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 03:58:33 +08:00
add filesystem interface
This commit is contained in:
parent
ebc8e4052e
commit
7c6c5e3652
@ -1,6 +1,8 @@
|
||||
#include "awtk.h"
|
||||
#include "base/assets_manager.h"
|
||||
#ifndef WITH_FS_RES
|
||||
#include "assets/inc/strings/en_US.data"
|
||||
#include "assets/inc/strings/zh_CN.data"
|
||||
#include "assets/inc/styles/button.data"
|
||||
#include "assets/inc/styles/calibration.data"
|
||||
#include "assets/inc/styles/color.data"
|
||||
@ -313,6 +315,8 @@ ret_t assets_init(void) {
|
||||
assets_manager_add(rm, image_unchecked);
|
||||
assets_manager_add(rm, image_unmuted);
|
||||
assets_manager_add(rm, image_warn);
|
||||
assets_manager_add(rm, strings_en_US);
|
||||
assets_manager_add(rm, strings_zh_CN);
|
||||
assets_manager_add(rm, style_button);
|
||||
assets_manager_add(rm, style_calibration);
|
||||
assets_manager_add(rm, style_color);
|
||||
|
@ -117,4 +117,4 @@ const unsigned char image_check[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x60,0x25,0x40,0xa8,};/*2364*/
|
||||
0x00,0x00,0x00,0x00,};/*2364*/
|
||||
|
@ -117,4 +117,4 @@ const unsigned char image_checked[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x20,0x28,0x50,0xd8,};/*2364*/
|
||||
0x00,0x00,0x00,0x00,};/*2364*/
|
||||
|
@ -117,4 +117,4 @@ const unsigned char image_edit_clear_p[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,};/*2364*/
|
||||
0xd0,0x1d,0x50,0xc3,};/*2364*/
|
||||
|
@ -117,4 +117,4 @@ const unsigned char image_muted[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,};/*2364*/
|
||||
0x10,0x30,0xd0,0xe1,};/*2364*/
|
||||
|
@ -54,4 +54,4 @@ const unsigned char image_question[] = {
|
||||
0x3b,0x00,0xae,0x92,0xc2,0xa9,0xc2,0x88,0xe9,0xb4,0x94,0x6b,0xa7,0x6a,0xa8,0x97,0xf0,0xfa,0x49,0x80,
|
||||
0x8e,0x36,0x7d,0x5b,0x96,0x01,0xdc,0x62,0xe0,0x57,0xdf,0xe5,0x4b,0xe5,0x4f,0x52,0x95,0x76,0xdf,0x96,
|
||||
0xff,0x00,0x01,0x05,0x9f,0x7f,0x72,0x86,0xa6,0xc9,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,
|
||||
0x60,0x82,0x00,0x00,0x00,0x00,};/*1106*/
|
||||
0x60,0x82,0x00,0x00,0x08,0x3e,};/*1106*/
|
||||
|
@ -181,4 +181,4 @@ const unsigned char image_red_btn_n[] = {
|
||||
0xbb,0x2b,0x2b,0xff,0xbb,0x2b,0x2b,0xff,0xbb,0x2b,0x2b,0xff,0xbb,0x2b,0x2b,0xff,0xbb,0x2b,0x2b,0xff,
|
||||
0xbb,0x2b,0x2b,0xff,0xbb,0x2b,0x2b,0xff,0xbb,0x2b,0x2b,0xff,0xbb,0x2b,0x2b,0xff,0xbb,0x2b,0x2b,0xff,
|
||||
0xc0,0x3e,0x3e,0xff,0xcc,0x65,0x65,0xd7,0xd7,0x88,0x88,0x97,0xf0,0xd5,0xd5,0x37,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf9,0xd0,0x73,};/*3660*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*3660*/
|
||||
|
@ -49,4 +49,4 @@ const unsigned char image_slider_bg[] = {
|
||||
0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,
|
||||
0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,
|
||||
0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,0x86,0x86,0x86,0xff,0x87,0x87,0x87,0xff,
|
||||
0x94,0x94,0x94,0x98,0xce,0xce,0xce,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*1020*/
|
||||
0x94,0x94,0x94,0x98,0xce,0xce,0xce,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x2c,0xd2,0x73,};/*1020*/
|
||||
|
6
demos/assets/inc/strings/en_US.data
Normal file
6
demos/assets/inc/strings/en_US.data
Normal file
@ -0,0 +1,6 @@
|
||||
const unsigned char strings_en_US[] = {
|
||||
0x06,0x00,0x00,0x01,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x65,0x6e,0x5f,0x55,0x53,0x00,0x64,0x61,
|
||||
0x74,0x61,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x1c,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x2a,0x00,0x00,0x00,
|
||||
0x2d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x61,0x6e,0x63,0x65,0x6c,0x00,0x43,
|
||||
0x61,0x6e,0x63,0x65,0x6c,0x00,0x6f,0x6b,0x00,0x4f,0x4b,0x00,0x00,0x00,0x00,0x00,};/*96*/
|
6
demos/assets/inc/strings/zh_CN.data
Normal file
6
demos/assets/inc/strings/zh_CN.data
Normal file
@ -0,0 +1,6 @@
|
||||
const unsigned char strings_zh_CN[] = {
|
||||
0x06,0x00,0x00,0x01,0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7a,0x68,0x5f,0x43,0x4e,0x00,0x64,0x61,
|
||||
0x74,0x61,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x1c,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x2a,0x00,0x00,0x00,
|
||||
0x2d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,0x61,0x6e,0x63,0x65,0x6c,0x00,0xe5,
|
||||
0x8f,0x96,0xe6,0xb6,0x88,0x00,0x6f,0x6b,0x00,0xe7,0xa1,0xae,0xe5,0xae,0x9a,0x00,0x00,0x00,0x00,0x00,};/*100*/
|
@ -11,4 +11,4 @@ const unsigned char style_tab_bottom_compact[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x02,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0xa0,0xa0,0xa0,0xff,0x02,0x00,0x00,0x00,0xf0,0xf0,0xf0,0xff,
|
||||
0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0xa0,0xa0,0xa0,0xff,0x0b,0x00,0x00,0x00,
|
||||
0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*252*/
|
||||
0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,};/*252*/
|
||||
|
@ -11,4 +11,4 @@ const unsigned char style_tab_top_compact[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x02,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0xa0,0xa0,0xa0,0xff,0x02,0x00,0x00,0x00,0xf0,0xf0,0xf0,0xff,
|
||||
0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0xa0,0xa0,0xa0,0xff,0x0b,0x00,0x00,0x00,
|
||||
0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x0a,0x0a,0x0a,};/*252*/
|
||||
0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*252*/
|
||||
|
@ -79,4 +79,4 @@ const unsigned char ui_basic[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd2,0x00,0x00,0x00,
|
||||
0x68,0x01,0x00,0x00,0x28,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x72,0x61,0x77,
|
||||
0x5f,0x74,0x79,0x70,0x65,0x00,0x69,0x63,0x6f,0x6e,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x72,0x65,0x64,
|
||||
0x5f,0x62,0x74,0x6e,0x5f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*1614*/
|
||||
0x5f,0x62,0x74,0x6e,0x5f,0x6e,0x00,0x00,0x00,0x00,0x40,0x19,0xf5,0x7f,};/*1614*/
|
||||
|
@ -81,4 +81,4 @@ const unsigned char ui_kb_float[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x72,0x61,0x77,0x5f,
|
||||
0x74,0x79,0x70,0x65,0x00,0x69,0x63,0x6f,0x6e,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x62,0x61,0x63,0x6b,
|
||||
0x73,0x70,0x61,0x63,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x7f,0x00,0x00,};/*1656*/
|
||||
0x73,0x70,0x61,0x63,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*1656*/
|
||||
|
@ -154,4 +154,4 @@ const unsigned char ui_keyboard[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,
|
||||
0x01,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x63,0x6c,0x6f,0x73,0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x43,0x6c,
|
||||
0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*3111*/
|
||||
0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0x74,0xff,0x7f,0x00,};/*3111*/
|
||||
|
@ -21,4 +21,4 @@ const unsigned char ui_rich_text1[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,
|
||||
0x01,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x63,0x6c,0x6f,0x73,0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x43,0x6c,
|
||||
0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0xf0,0x1b,0x00,0x74,};/*451*/
|
||||
0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0xe0,0x1b,0x00,0x74,};/*451*/
|
||||
|
@ -21,5 +21,5 @@ const unsigned char ui_rich_text2[] = {
|
||||
0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x0a,0x00,0x00,
|
||||
0x00,0x19,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x63,0x6c,
|
||||
0x6f,0x73,0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x43,0x6c,0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0x73,0x65,
|
||||
0x00,0x78,};/*462*/
|
||||
0x6f,0x73,0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x43,0x6c,0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,};/*462*/
|
||||
|
2
demos/demo1_app.c
Executable file → Normal file
2
demos/demo1_app.c
Executable file → Normal file
@ -62,7 +62,7 @@ static ret_t on_show_dialog(void* ctx, event_t* e) {
|
||||
code = dialog_modal(win);
|
||||
log_debug("code=%d\n", (int)code);
|
||||
|
||||
(void)code;
|
||||
(void)code;
|
||||
tk_mem_info_dump();
|
||||
(void)e;
|
||||
|
||||
|
210
src/base/fs.c
210
src/base/fs.c
@ -19,45 +19,145 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(HAS_POSIX_FS) || defined(__APPLE__) || defined(LINUX) || defined(WIN32)
|
||||
|
||||
#if defined(__APPLE__) || defined(LINUX)
|
||||
#include <unistd.h>
|
||||
#elif defined(WIN32)
|
||||
#include <windows.h>
|
||||
#define unlink _unlink
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "base/fs.h"
|
||||
#include "base/mem.h"
|
||||
|
||||
int32_t fs_file_size(const char* name) {
|
||||
struct stat st = {0};
|
||||
return_value_if_fail(name != NULL, -1);
|
||||
int32_t fs_file_read(fs_file_t* file, void* buffer, uint32_t size) {
|
||||
return_value_if_fail(file != NULL && buffer != NULL && file->read != NULL, -1);
|
||||
|
||||
if (stat(name, &st) == 0 && (st.st_mode & S_IFMT) == S_IFREG) {
|
||||
return st.st_size;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return file->read(file, buffer, size);
|
||||
}
|
||||
|
||||
int32_t fs_file_write(fs_file_t* file, const void* buffer, uint32_t size) {
|
||||
return_value_if_fail(file != NULL && buffer != NULL && file->write != NULL, -1);
|
||||
|
||||
return file->write(file, buffer, size);
|
||||
}
|
||||
|
||||
ret_t fs_file_seek(fs_file_t* file, int32_t offset) {
|
||||
return_value_if_fail(file != NULL && file->seek != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return file->seek(file, offset);
|
||||
}
|
||||
|
||||
ret_t fs_file_truncate(fs_file_t* file, int32_t offset) {
|
||||
return_value_if_fail(file != NULL && file->truncate != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return file->truncate(file, offset);
|
||||
}
|
||||
|
||||
ret_t fs_file_close(fs_file_t* file) {
|
||||
return_value_if_fail(file != NULL && file->close != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return file->close(file);
|
||||
}
|
||||
|
||||
ret_t fs_dir_rewind(fs_dir_t* dir) {
|
||||
return_value_if_fail(dir != NULL && dir->rewind != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return dir->rewind(dir);
|
||||
}
|
||||
|
||||
ret_t fs_dir_read(fs_dir_t* dir, fs_item_t* item) {
|
||||
return_value_if_fail(dir != NULL && dir->read != NULL && item != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return dir->read(dir, item);
|
||||
}
|
||||
|
||||
ret_t fs_dir_close(fs_dir_t* dir) {
|
||||
return_value_if_fail(dir != NULL && dir->close != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return dir->close(dir);
|
||||
}
|
||||
|
||||
fs_file_t* fs_open_file(fs_t* fs, const char* name, const char* mode) {
|
||||
return_value_if_fail(fs != NULL && name != NULL && mode != NULL, NULL);
|
||||
|
||||
return fs->open_file(fs, name, mode);
|
||||
}
|
||||
|
||||
ret_t fs_remove_file(fs_t* fs, const char* name) {
|
||||
return_value_if_fail(fs != NULL && fs->remove_file != NULL && name != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return fs->remove_file(fs, name);
|
||||
}
|
||||
|
||||
bool_t fs_file_exist(fs_t* fs, const char* name) {
|
||||
return_value_if_fail(fs != NULL && fs->file_exist != NULL && name != NULL, FALSE);
|
||||
|
||||
return fs->file_exist(fs, name);
|
||||
}
|
||||
|
||||
bool_t fs_file_rename(fs_t* fs, const char* name, const char* new_name) {
|
||||
return_value_if_fail(fs != NULL && fs->file_rename != NULL && name != NULL && new_name != NULL,
|
||||
FALSE);
|
||||
|
||||
return fs->file_rename(fs, name, new_name);
|
||||
}
|
||||
|
||||
fs_dir_t* fs_open_dir(fs_t* fs, const char* name) {
|
||||
return_value_if_fail(fs != NULL && fs->open_dir != NULL && name != NULL, NULL);
|
||||
|
||||
return fs->open_dir(fs, name);
|
||||
}
|
||||
|
||||
ret_t fs_remove_dir(fs_t* fs, const char* name) {
|
||||
return_value_if_fail(fs != NULL && fs->remove_dir != NULL && name != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return fs->remove_dir(fs, name);
|
||||
}
|
||||
|
||||
bool_t fs_dir_exist(fs_t* fs, const char* name) {
|
||||
return_value_if_fail(fs != NULL && fs->dir_exist != NULL && name != NULL, FALSE);
|
||||
|
||||
return fs->dir_exist(fs, name);
|
||||
}
|
||||
|
||||
bool_t fs_dir_rename(fs_t* fs, const char* name, const char* new_name) {
|
||||
return_value_if_fail(fs != NULL && fs->dir_rename != NULL && name != NULL && new_name, FALSE);
|
||||
|
||||
return fs->dir_rename(fs, name, new_name);
|
||||
}
|
||||
|
||||
int32_t fs_get_file_size(fs_t* fs, const char* name) {
|
||||
return_value_if_fail(fs != NULL && fs->get_file_size != NULL && name != NULL, -1);
|
||||
|
||||
return fs->get_file_size(fs, name);
|
||||
}
|
||||
|
||||
ret_t fs_get_disk_info(fs_t* fs, int32_t* free_kb, int32_t* total_kb) {
|
||||
return_value_if_fail(fs != NULL && free_kb != NULL && total_kb != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return fs->get_disk_info(fs, free_kb, total_kb);
|
||||
}
|
||||
|
||||
ret_t fs_get_exe(fs_t* fs, char path[MAX_PATH + 1]) {
|
||||
return_value_if_fail(fs != NULL && fs->get_exe != NULL && path != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return fs->get_exe(fs, path);
|
||||
}
|
||||
|
||||
ret_t fs_get_cwd(fs_t* fs, char path[MAX_PATH + 1]) {
|
||||
return_value_if_fail(fs != NULL && fs->get_cwd != NULL && path != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return fs->get_cwd(fs, path);
|
||||
}
|
||||
|
||||
int32_t fs_file_size(const char* name) {
|
||||
return fs_get_file_size(os_fs(), name);
|
||||
}
|
||||
|
||||
int32_t fs_read_file_part(const char* name, void* buff, uint32_t size, uint32_t offset) {
|
||||
int32_t ret = 0;
|
||||
FILE* fp = NULL;
|
||||
return_value_if_fail(name != NULL && buff != NULL && size > 0, -1);
|
||||
|
||||
fp = fopen(name, "rb");
|
||||
fs_file_t* fp = NULL;
|
||||
return_value_if_fail(name != NULL && buff != NULL, -1);
|
||||
|
||||
fp = fs_open_file(os_fs(), name, "rb");
|
||||
if (fp != NULL) {
|
||||
ret = fseek(fp, offset, SEEK_SET);
|
||||
if (ret == 0) {
|
||||
ret = fread(buff, 1, size, fp);
|
||||
if (fs_file_seek(fp, offset) == RET_OK) {
|
||||
ret = fs_file_read(fp, buff, size);
|
||||
}
|
||||
fclose(fp);
|
||||
fs_file_close(fp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -89,14 +189,18 @@ void* fs_read_file(const char* name, uint32_t* size) {
|
||||
}
|
||||
|
||||
ret_t fs_write_file(const char* name, const void* buff, uint32_t size) {
|
||||
FILE* fp = NULL;
|
||||
ret_t ret = RET_OK;
|
||||
fs_file_t* fp = NULL;
|
||||
return_value_if_fail(name != NULL && buff != NULL, RET_BAD_PARAMS);
|
||||
|
||||
fp = fopen(name, "wb+");
|
||||
fp = fs_open_file(os_fs(), name, "wb+");
|
||||
return_value_if_fail(fp != NULL, RET_FAIL);
|
||||
|
||||
fwrite(buff, size, 1, fp);
|
||||
fclose(fp);
|
||||
if (fs_file_write(fp, buff, size) != size) {
|
||||
ret = RET_FAIL;
|
||||
}
|
||||
|
||||
fs_file_close(fp);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@ -104,47 +208,7 @@ ret_t fs_write_file(const char* name, const void* buff, uint32_t size) {
|
||||
ret_t fs_unlink(const char* name) {
|
||||
return_value_if_fail(name != NULL, RET_BAD_PARAMS);
|
||||
|
||||
unlink(name);
|
||||
fs_remove_file(os_fs(), name);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#else
|
||||
#include "base/fs.h"
|
||||
#include "base/mem.h"
|
||||
|
||||
int32_t fs_file_size(const char* name) {
|
||||
(void)name;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int32_t fs_read_file_part(const char* name, void* buff, uint32_t size, uint32_t offset) {
|
||||
(void)name;
|
||||
(void)buff;
|
||||
(void)size;
|
||||
(void)offset;
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
void* fs_read_file(const char* name, uint32_t* size) {
|
||||
(void)name;
|
||||
(void)size;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret_t fs_write_file(const char* name, const void* buff, uint32_t size) {
|
||||
(void)name;
|
||||
(void)buff;
|
||||
(void)size;
|
||||
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
ret_t fs_unlink(const char* name) {
|
||||
(void)name;
|
||||
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
101
src/base/fs.h
101
src/base/fs.h
@ -26,6 +26,107 @@
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
struct _fs_file_t;
|
||||
typedef struct _fs_file_t fs_file_t;
|
||||
|
||||
typedef int32_t (*fs_file_read_t)(fs_file_t* file, void* buffer, uint32_t size);
|
||||
typedef int32_t (*fs_file_write_t)(fs_file_t* file, const void* buffer, uint32_t size);
|
||||
typedef ret_t (*fs_file_seek_t)(fs_file_t* file, int32_t offset);
|
||||
typedef ret_t (*fs_file_truncate_t)(fs_file_t* file, int32_t offset);
|
||||
typedef ret_t (*fs_file_close_t)(fs_file_t* file);
|
||||
|
||||
struct _fs_file_t {
|
||||
fs_file_read_t read;
|
||||
fs_file_write_t write;
|
||||
fs_file_seek_t seek;
|
||||
fs_file_truncate_t truncate;
|
||||
fs_file_close_t close;
|
||||
void* data;
|
||||
};
|
||||
|
||||
int32_t fs_file_read(fs_file_t* file, void* buffer, uint32_t size);
|
||||
int32_t fs_file_write(fs_file_t* file, const void* buffer, uint32_t size);
|
||||
ret_t fs_file_seek(fs_file_t* file, int32_t offset);
|
||||
ret_t fs_file_truncate(fs_file_t* file, int32_t offset);
|
||||
ret_t fs_file_close(fs_file_t* file);
|
||||
|
||||
typedef struct _fs_item_t {
|
||||
uint32_t is_dir : 1;
|
||||
uint32_t is_file : 1;
|
||||
char name[MAX_PATH + 1];
|
||||
} fs_item_t;
|
||||
|
||||
struct _fs_dir_t;
|
||||
typedef struct _fs_dir_t fs_dir_t;
|
||||
|
||||
typedef ret_t (*fs_dir_rewind_t)(fs_dir_t* dir);
|
||||
typedef ret_t (*fs_dir_read_t)(fs_dir_t* dir, fs_item_t* item);
|
||||
typedef ret_t (*fs_dir_close_t)(fs_dir_t* dir);
|
||||
|
||||
struct _fs_dir_t {
|
||||
fs_dir_rewind_t rewind;
|
||||
fs_dir_read_t read;
|
||||
fs_dir_close_t close;
|
||||
void* data;
|
||||
};
|
||||
|
||||
ret_t fs_dir_rewind(fs_dir_t* dir);
|
||||
ret_t fs_dir_read(fs_dir_t* dir, fs_item_t* item);
|
||||
ret_t fs_dir_close(fs_dir_t* dir);
|
||||
|
||||
struct _fs_t;
|
||||
typedef struct _fs_t fs_t;
|
||||
|
||||
typedef fs_file_t* (*fs_open_file_t)(fs_t* fs, const char* name, const char* mode);
|
||||
typedef ret_t (*fs_remove_file_t)(fs_t* fs, const char* name);
|
||||
typedef bool_t (*fs_file_exist_t)(fs_t* fs, const char* name);
|
||||
typedef bool_t (*fs_file_rename_t)(fs_t* fs, const char* name, const char* new_name);
|
||||
|
||||
typedef fs_dir_t* (*fs_open_dir_t)(fs_t* fs, const char* name);
|
||||
typedef ret_t (*fs_remove_dir_t)(fs_t* fs, const char* name);
|
||||
typedef bool_t (*fs_dir_exist_t)(fs_t* fs, const char* name);
|
||||
typedef bool_t (*fs_dir_rename_t)(fs_t* fs, const char* name, const char* new_name);
|
||||
|
||||
typedef int32_t (*fs_get_file_size_t)(fs_t* fs, const char* name);
|
||||
typedef ret_t (*fs_get_disk_info_t)(fs_t* fs, int32_t* free_kb, int32_t* total_kb);
|
||||
typedef ret_t (*fs_get_exe_t)(fs_t* fs, char path[MAX_PATH + 1]);
|
||||
typedef ret_t (*fs_get_cwd_t)(fs_t* fs, char path[MAX_PATH + 1]);
|
||||
|
||||
struct _fs_t {
|
||||
fs_open_file_t open_file;
|
||||
fs_remove_file_t remove_file;
|
||||
fs_file_exist_t file_exist;
|
||||
fs_file_rename_t file_rename;
|
||||
|
||||
fs_open_dir_t open_dir;
|
||||
fs_remove_dir_t remove_dir;
|
||||
fs_dir_exist_t dir_exist;
|
||||
fs_dir_rename_t dir_rename;
|
||||
|
||||
fs_get_file_size_t get_file_size;
|
||||
fs_get_disk_info_t get_disk_info;
|
||||
fs_get_cwd_t get_cwd;
|
||||
fs_get_exe_t get_exe;
|
||||
};
|
||||
|
||||
fs_file_t* fs_open_file(fs_t* fs, const char* name, const char* mode);
|
||||
ret_t fs_remove_file(fs_t* fs, const char* name);
|
||||
bool_t fs_file_exist(fs_t* fs, const char* name);
|
||||
bool_t fs_file_rename(fs_t* fs, const char* name, const char* new_name);
|
||||
|
||||
fs_dir_t* fs_open_dir(fs_t* fs, const char* name);
|
||||
ret_t fs_remove_dir(fs_t* fs, const char* name);
|
||||
bool_t fs_dir_exist(fs_t* fs, const char* name);
|
||||
bool_t fs_dir_rename(fs_t* fs, const char* name, const char* new_name);
|
||||
|
||||
int32_t fs_get_file_size(fs_t* fs, const char* name);
|
||||
ret_t fs_get_disk_info(fs_t* fs, int32_t* free_kb, int32_t* total_kb);
|
||||
ret_t fs_get_exe(fs_t* fs, char path[MAX_PATH + 1]);
|
||||
ret_t fs_get_cwd(fs_t* fs, char path[MAX_PATH + 1]);
|
||||
|
||||
fs_t* os_fs(void);
|
||||
|
||||
/*wrapper*/
|
||||
ret_t fs_unlink(const char* name);
|
||||
int32_t fs_file_size(const char* name);
|
||||
void* fs_read_file(const char* name, uint32_t* size);
|
||||
|
46
src/base/path.h
Normal file
46
src/base/path.h
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* File: path.h
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: path
|
||||
*
|
||||
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* License file for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* History:
|
||||
* ================================================================
|
||||
* 2018-08-24 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef TK_PATH_H
|
||||
#define TK_PATH_H
|
||||
|
||||
#include "base/types_def.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
ret_t path_basename(const char* path, char* result, int32_t size);
|
||||
ret_t path_extname(const char* path, char* result, int32_t size);
|
||||
ret_t path_dirname(const char* path, char* result, int32_t size);
|
||||
ret_t path_normalize(const char* path, char* result, int32_t size);
|
||||
ret_t path_abs(const char* path, char* result, int32_t size);
|
||||
ret_t path_build(char* result, int32_t size, ...);
|
||||
|
||||
ret_t path_cwd(char* result, int32_t size);
|
||||
ret_t path_exe(char* result, int32_t size);
|
||||
ret_t path_app_root(char* result, int32_t size);
|
||||
|
||||
ret_t path_exist(const char* path);
|
||||
ret_t path_create(const char* path);
|
||||
ret_t path_remove(const char* path);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*TK_PATH_H*/
|
3
src/base/widget_factory.c
Executable file → Normal file
3
src/base/widget_factory.c
Executable file → Normal file
@ -80,8 +80,7 @@ static const creator_item_t s_builtin_creators[] = {
|
||||
{WIDGET_TYPE_COMBO_BOX, combo_box_create},
|
||||
{WIDGET_TYPE_COMBO_BOX_ITEM, combo_box_item_create},
|
||||
{WIDGET_TYPE_POPUP, popup_create},
|
||||
{WIDGET_TYPE_COLOR_TILE, color_tile_create}
|
||||
};
|
||||
{WIDGET_TYPE_COLOR_TILE, color_tile_create}};
|
||||
|
||||
static const creator_item_t* widget_factory_find_builtin_creator(const char* type) {
|
||||
uint32_t i = 0;
|
||||
|
@ -42,8 +42,10 @@ ret_t tk_ext_widgets_init() {
|
||||
widget_factory_register(widget_factory(), WIDGET_TYPE_LIST_VIEW_H, list_view_h_create);
|
||||
widget_factory_register(widget_factory(), WIDGET_TYPE_LIST_ITEM, list_item_create);
|
||||
widget_factory_register(widget_factory(), WIDGET_TYPE_SCROLL_BAR, scroll_bar_create);
|
||||
widget_factory_register(widget_factory(), WIDGET_TYPE_SCROLL_BAR_DESKTOP, scroll_bar_create_desktop);
|
||||
widget_factory_register(widget_factory(), WIDGET_TYPE_SCROLL_BAR_MOBILE, scroll_bar_create_mobile);
|
||||
widget_factory_register(widget_factory(), WIDGET_TYPE_SCROLL_BAR_DESKTOP,
|
||||
scroll_bar_create_desktop);
|
||||
widget_factory_register(widget_factory(), WIDGET_TYPE_SCROLL_BAR_MOBILE,
|
||||
scroll_bar_create_mobile);
|
||||
widget_factory_register(widget_factory(), WIDGET_TYPE_SLIDE_VIEW, slide_view_create);
|
||||
widget_factory_register(widget_factory(), WIDGET_TYPE_KEYBOARD, keyboard_create);
|
||||
widget_factory_register(widget_factory(), WIDGET_TYPE_CANDIDATES, candidates_create);
|
||||
|
108
src/platforms/pc/dirent.inc
Normal file
108
src/platforms/pc/dirent.inc
Normal file
@ -0,0 +1,108 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* dirent.c
|
||||
* opendir/readdir/closedir for win32/msvc
|
||||
*
|
||||
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* src/port/dirent.c
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
struct dirent {
|
||||
long d_ino;
|
||||
unsigned short d_reclen;
|
||||
unsigned short d_namlen;
|
||||
char d_name[MAX_PATH];
|
||||
};
|
||||
|
||||
typedef struct DIR DIR;
|
||||
|
||||
DIR* opendir(const char*);
|
||||
struct dirent* readdir(DIR*);
|
||||
int closedir(DIR*);
|
||||
|
||||
struct DIR {
|
||||
char* dirname;
|
||||
struct dirent ret; /* Used to return to caller */
|
||||
HANDLE handle;
|
||||
};
|
||||
|
||||
DIR* opendir(const char* dirname) {
|
||||
DWORD attr;
|
||||
DIR* d;
|
||||
|
||||
/* Make sure it is a directory */
|
||||
attr = GetFileAttributes(dirname);
|
||||
if (attr == INVALID_FILE_ATTRIBUTES) {
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
if ((attr & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) {
|
||||
errno = ENOTDIR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
d = malloc(sizeof(DIR));
|
||||
if (!d) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
d->dirname = malloc(strlen(dirname) + 4);
|
||||
if (!d->dirname) {
|
||||
errno = ENOMEM;
|
||||
free(d);
|
||||
return NULL;
|
||||
}
|
||||
strcpy(d->dirname, dirname);
|
||||
if (d->dirname[strlen(d->dirname) - 1] != '/' && d->dirname[strlen(d->dirname) - 1] != '\\')
|
||||
strcat(d->dirname, "\\"); /* Append backslash if not already
|
||||
* there */
|
||||
strcat(d->dirname, "*"); /* Search for entries named anything */
|
||||
d->handle = INVALID_HANDLE_VALUE;
|
||||
d->ret.d_ino = 0; /* no inodes on win32 */
|
||||
d->ret.d_reclen = 0; /* not used on win32 */
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
struct dirent* readdir(DIR* d) {
|
||||
WIN32_FIND_DATA fd;
|
||||
|
||||
if (d->handle == INVALID_HANDLE_VALUE) {
|
||||
d->handle = FindFirstFile(d->dirname, &fd);
|
||||
if (d->handle == INVALID_HANDLE_VALUE) {
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
if (!FindNextFile(d->handle, &fd)) {
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES) {
|
||||
/* No more files, force errno=0 (unlike mingw) */
|
||||
errno = 0;
|
||||
return NULL;
|
||||
}
|
||||
_dosmaperr(GetLastError());
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
strcpy(d->ret.d_name, fd.cFileName); /* Both strings are MAX_PATH
|
||||
* long */
|
||||
d->ret.d_namlen = strlen(d->ret.d_name);
|
||||
|
||||
return &d->ret;
|
||||
}
|
||||
|
||||
int closedir(DIR* d) {
|
||||
int ret = 0;
|
||||
|
||||
if (d->handle != INVALID_HANDLE_VALUE) ret = !FindClose(d->handle);
|
||||
free(d->dirname);
|
||||
free(d);
|
||||
|
||||
return ret;
|
||||
}
|
236
src/platforms/pc/fs_os.c
Normal file
236
src/platforms/pc/fs_os.c
Normal file
@ -0,0 +1,236 @@
|
||||
#if defined(__APPLE__) || defined(LINUX)
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#elif defined(WIN32)
|
||||
#include <windows.h>
|
||||
#define unlink _unlink
|
||||
#define rename _rename
|
||||
#include "./dirent.inc"
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <mach-o/dyld.h>
|
||||
#endif/*__APPLE__*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "base/fs.h"
|
||||
#include "base/mem.h"
|
||||
#include "base/utils.h"
|
||||
|
||||
static int32_t fs_os_file_read(fs_file_t* file, void* buffer, uint32_t size) {
|
||||
FILE* fp = (FILE*)(file->data);
|
||||
|
||||
return (int32_t)fread(buffer, 1, size, fp);
|
||||
}
|
||||
|
||||
int32_t fs_os_file_write(fs_file_t* file, const void* buffer, uint32_t size) {
|
||||
FILE* fp = (FILE*)(file->data);
|
||||
|
||||
return fwrite(buffer, 1, size, fp);
|
||||
}
|
||||
|
||||
ret_t fs_os_file_seek(fs_file_t* file, int32_t offset) {
|
||||
FILE* fp = (FILE*)(file->data);
|
||||
|
||||
return fseek(fp, offset, SEEK_SET) == 0 ? RET_OK : RET_FAIL;
|
||||
}
|
||||
|
||||
ret_t fs_os_file_truncate(fs_file_t* file, int32_t size) {
|
||||
FILE* fp = (FILE*)(file->data);
|
||||
|
||||
return ftruncate(fileno(fp), size) == 0 ? RET_OK : RET_FAIL;
|
||||
}
|
||||
|
||||
ret_t fs_os_file_close(fs_file_t* file) {
|
||||
FILE* fp = (FILE*)(file->data);
|
||||
fclose(fp);
|
||||
TKMEM_FREE(file);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t fs_os_dir_rewind(fs_dir_t* dir) {
|
||||
DIR* d = (DIR*)(dir->data);
|
||||
|
||||
rewinddir(d);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t fs_os_dir_read(fs_dir_t* dir, fs_item_t* item) {
|
||||
DIR* d = (DIR*)(dir->data);
|
||||
struct dirent* ent = readdir(d);
|
||||
|
||||
memset(item, 0x00, sizeof(fs_item_t));
|
||||
if (ent != NULL) {
|
||||
uint8_t type = ent->d_type;
|
||||
item->is_dir = type & DT_DIR;
|
||||
item->is_file = type & DT_REG;
|
||||
tk_strncpy(item->name, ent->d_name, MAX_PATH);
|
||||
|
||||
return RET_OK;
|
||||
} else {
|
||||
return RET_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
ret_t fs_os_dir_close(fs_dir_t* dir) {
|
||||
DIR* d = (DIR*)dir->data;
|
||||
closedir(d);
|
||||
TKMEM_FREE(dir);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static fs_file_t* fs_file_create(FILE* fp) {
|
||||
fs_file_t* f = NULL;
|
||||
return_value_if_fail(fp != NULL, NULL);
|
||||
|
||||
f = TKMEM_ZALLOC(fs_file_t);
|
||||
if (f != NULL) {
|
||||
f->read = fs_os_file_read;
|
||||
f->write = fs_os_file_write;
|
||||
f->seek = fs_os_file_seek;
|
||||
f->truncate = fs_os_file_truncate;
|
||||
f->close = fs_os_file_close;
|
||||
f->data = fp;
|
||||
} else {
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
fs_file_t* fs_os_open_file(fs_t* fs, const char* name, const char* mode) {
|
||||
(void)fs;
|
||||
return fs_file_create(fopen(name, mode));
|
||||
}
|
||||
|
||||
ret_t fs_os_remove_file(fs_t* fs, const char* name) {
|
||||
(void)fs;
|
||||
|
||||
unlink(name);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
bool_t fs_os_file_exist(fs_t* fs, const char* name) {
|
||||
struct stat st;
|
||||
|
||||
return (stat(name, &st) == 0 && st.st_mode & S_IFREG);
|
||||
}
|
||||
|
||||
bool_t fs_os_file_rename(fs_t* fs, const char* name, const char* new_name) {
|
||||
(void)fs;
|
||||
|
||||
return rename(name, new_name) == 0;
|
||||
}
|
||||
|
||||
fs_dir_t* fs_dir_create(DIR* dir) {
|
||||
fs_dir_t* d = NULL;
|
||||
return_value_if_fail(dir != NULL, NULL);
|
||||
|
||||
d = TKMEM_ZALLOC(fs_dir_t);
|
||||
if (d != NULL) {
|
||||
d->read = fs_os_dir_read;
|
||||
d->rewind = fs_os_dir_rewind;
|
||||
d->close = fs_os_dir_close;
|
||||
d->data = dir;
|
||||
} else {
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
fs_dir_t* fs_os_open_dir(fs_t* fs, const char* name) {
|
||||
return fs_dir_create(opendir(name));
|
||||
}
|
||||
|
||||
ret_t fs_os_remove_dir(fs_t* fs, const char* name) {
|
||||
(void)fs;
|
||||
return rmdir(name) == 0 ? RET_OK : RET_FAIL;
|
||||
}
|
||||
|
||||
bool_t fs_os_dir_exist(fs_t* fs, const char* name) {
|
||||
struct stat st;
|
||||
|
||||
return (stat(name, &st) == 0 && st.st_mode & S_IFDIR);
|
||||
}
|
||||
|
||||
bool_t fs_os_dir_rename(fs_t* fs, const char* name, const char* new_name) {
|
||||
(void)fs;
|
||||
(void)name;
|
||||
(void)new_name;
|
||||
assert(!"fs_os_dir_rename not supported yet");
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int32_t fs_os_get_file_size(fs_t* fs, const char* name) {
|
||||
struct stat st;
|
||||
return_value_if_fail(stat(name, &st) == 0, -1);
|
||||
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
ret_t fs_os_get_disk_info(fs_t* fs, int32_t* free_kb, int32_t* total_kb) {
|
||||
/*TODO*/
|
||||
*free_kb = 0;
|
||||
*total_kb = 0;
|
||||
(void)fs;
|
||||
assert(!"fs_os_get_disk_info not supported yet");
|
||||
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
ret_t fs_os_get_exe(fs_t* fs, char path[MAX_PATH + 1]) {
|
||||
uint32_t size = 0;
|
||||
(void)fs;
|
||||
*path = '\0';
|
||||
|
||||
#if defined(LINUX)
|
||||
readlink("/proc/self/exe", path, MAX_PATH);
|
||||
#elif defined(WIN32)
|
||||
GetModuleFileNameA(GetModuleHandle(NULL), path, MAX_PATH)
|
||||
#elif defined(__APPLE__)
|
||||
_NSGetExecutablePath(path, &size);
|
||||
assert(size <= MAX_PATH);
|
||||
path[size] = '\0';
|
||||
#else
|
||||
#endif
|
||||
(void)size;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t fs_os_get_cwd(fs_t* fs, char path[MAX_PATH + 1]) {
|
||||
(void)fs;
|
||||
|
||||
getcwd(path, MAX_PATH);
|
||||
path[MAX_PATH] = '\0';
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static const fs_t s_os_fs = {.open_file = fs_os_open_file,
|
||||
.remove_file = fs_os_remove_file,
|
||||
.file_exist = fs_os_file_exist,
|
||||
.file_rename = fs_os_file_rename,
|
||||
|
||||
.open_dir = fs_os_open_dir,
|
||||
.remove_dir = fs_os_remove_dir,
|
||||
.dir_exist = fs_os_dir_exist,
|
||||
.dir_rename = fs_os_dir_rename,
|
||||
|
||||
.get_file_size = fs_os_get_file_size,
|
||||
.get_disk_info = fs_os_get_disk_info,
|
||||
.get_cwd = fs_os_get_cwd,
|
||||
.get_exe = fs_os_get_exe};
|
||||
|
||||
fs_t* os_fs(void) {
|
||||
return (fs_t*)&s_os_fs;
|
||||
}
|
5
src/platforms/raw/fs_os.c
Normal file
5
src/platforms/raw/fs_os.c
Normal file
@ -0,0 +1,5 @@
|
||||
#include "base/fs.h"
|
||||
|
||||
fs_t* os_fs(void) {
|
||||
return (fs_t*)&s_os_fs;
|
||||
}
|
Loading…
Reference in New Issue
Block a user