Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixelsuft committed Jun 4, 2024
1 parent 3d4b13b commit 561f91b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ vs
*.o
*.a
*.exe
*.apk
*.dll
*.zip
*.rar
Expand Down
38 changes: 32 additions & 6 deletions src/ui-mobile.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,36 @@ void mobui_place_elems(void) {
page.cfg_btn.base.set_rect(&page.cfg_btn, &tr3);
}

void mobui_copy_config(void) {
void* in_f = h_fopen("default_mobile.conf", "rb");
if (in_f == NULL)
return;
int64_t sz = h_fsize(in_f);
if (sz <= 0) {
fclose(in_f);
return;
}
void* buf = h_malloc((size_t)sz + 1);
if (buf == NULL) {
fclose(in_f);
return;
}
h_fread(buf, 1, (size_t)sz, in_f);
h_fclose(in_f);
char out_path[1024 * 10];
size_t path_inp_len = strlen(page.path_inp.text);
memcpy(out_path, page.path_inp.text, path_inp_len);
strcpy(out_path + path_inp_len, "/halfix.conf");
void* out_f = h_fopen(out_path, "wb");
if (out_f == NULL) {
h_free(buf);
return;
}
h_fwrite(buf, 1, (size_t)sz, out_f);
h_fclose(out_f);
h_free(buf);
}

void mobui_run_main(void) {
int running = 1;
SDL_Event ev;
Expand Down Expand Up @@ -342,12 +372,7 @@ void mobui_run_main(void) {
}
if (page.cfg_btn.was_pressed) {
page.cfg_btn.was_pressed = 0;
char cmd_buf[10 * 1024] = "cp default_mobile.conf \"";
size_t path_len = strlen(page.path_inp.text);
memcpy(cmd_buf + 24, page.path_inp.text, path_len + 1);
cmd_buf[24 + path_len] = '"';
cmd_buf[25 + path_len] = '\0';
system(cmd_buf);
mobui_copy_config();
}
SDL_RenderPresent(ren);
}
Expand Down Expand Up @@ -388,6 +413,7 @@ void mobui_init(void) {
page.elems[2] = (mobui_elem*)&page.cfg_btn;
page.elem_count = 10;
#ifndef MOBILE_WIP
// IDK which is right...
SDL_AndroidRequestPermission("READ_EXTERNAL_STORAGE");
SDL_AndroidRequestPermission("permission.READ_EXTERNAL_STORAGE");
SDL_AndroidRequestPermission("android.permission.READ_EXTERNAL_STORAGE");
Expand Down
6 changes: 3 additions & 3 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ void h_free(void* ptr) {

void* h_fopen(const char* fp, const char* mode) {
#if defined(_WIN32) && !defined(PREFER_SDL2) && !defined(PREFER_STD)
int can_write = mode[0] == 'r' && mode[1] == 'b' && mode[2] == '+'; // Hack
int can_write = (mode[0] == 'r' && mode[1] == 'b' && mode[2] == '+') || (mode[0] == 'w'); // Hack
#ifdef FILES_WIN32_USE_ANSI
HANDLE res = CreateFileA(
fp, GENERIC_READ | (can_write ? GENERIC_WRITE : 0), FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
(mode[0] == 'w') ? CREATE_ALWAYS : OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
);
#else
int count = MultiByteToWideChar(CP_UTF8, 0, fp, (int)strlen(fp), NULL, 0);
Expand All @@ -98,7 +98,7 @@ void* h_fopen(const char* fp, const char* mode) {
fp_buf[encode_res] = L'\0';
HANDLE res = CreateFileW(
fp_buf, GENERIC_READ | (can_write ? GENERIC_WRITE : 0), FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
(mode[0] == 'w') ? CREATE_ALWAYS : OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
);
h_free(fp_buf);
#endif
Expand Down

0 comments on commit 561f91b

Please sign in to comment.