Skip to content

Commit

Permalink
fix some bugs, download cancelable
Browse files Browse the repository at this point in the history
  • Loading branch information
badda71 committed Feb 29, 2020
1 parent 223ec13 commit 7f3ec45
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
17 changes: 15 additions & 2 deletions src/3ds/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "homedir.h"
#include "3ds_cia.h"
#include "http.h"
#include "uibottom.h"
#include "keyboard.h"

extern int __system_argc;
extern char** __system_argv;
Expand Down Expand Up @@ -75,6 +77,18 @@ static char *prog_title=NULL;
static char *prog_text=NULL;
static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
{
// check events
SDL_Event e;
if (SDL_PollEvent(&e) &&
!uib_handle_event(&e) &&
e.type==SDL_KEYDOWN && (
e.key.keysym.sym == AK_ESC ||
e.key.keysym.sym == DS_B))
{
return -1;
}

// draw update message box
char *bar="##############################";
char buf[512];
sprintf(buf, "%s\n\n%-30s\n%s / ",
Expand All @@ -84,7 +98,6 @@ static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow
strcat(buf,humanSize(dltotal));
text_messagebox(
prog_title?prog_title:"Download", buf, MB_NONE);
SDL_Delay(100);
return 0;
}

Expand Down Expand Up @@ -181,7 +194,7 @@ int check_update()
}
}
if (update_fname[0] == 0) {
sprintf(update_fname,"%s%s", SAVE_PREFIX, strrchr(update_url,'/'));
sprintf(update_fname,"%s%s", SAVE_PREFIX, strrchr(update_url,'/')+1);
}
mkpath(update_fname, 0);

Expand Down
8 changes: 4 additions & 4 deletions src/homedir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#define MKDIRMOD 0644
#define PATH_SEP_CHAR '/'

const char *home_dir="/3ds/uae3DS";
const char *config_dir=home_dir;
char home_dir[]="/3ds/uae3DS";
char *config_dir=home_dir;

int mkpath(const char* file_path, int complete) {
int mkpath(char* file_path, int complete) {
char* p;

for (p=strchr(file_path+1, PATH_SEP_CHAR); p; p=strchr(p+1, PATH_SEP_CHAR)) {
for (p=strchr(file_path+1, PATH_SEP_CHAR); p != NULL; p=strchr(p+1, PATH_SEP_CHAR)) {
*p='\0';
if (mkdir(file_path, MKDIRMOD)==-1) {
if (errno!=EEXIST) { *p=PATH_SEP_CHAR; goto mkpath_err; }
Expand Down
6 changes: 3 additions & 3 deletions src/include/homedir.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern int mkpath(const char* file_path, int complete);
extern int mkpath(char* file_path, int complete);
extern void get_config_dir(void);

extern const char *home_dir;
extern const char *config_dir;
extern char home_dir[];
extern char *config_dir;
20 changes: 11 additions & 9 deletions src/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,13 +749,11 @@ int text_messagebox(char *title, char *message, mb_mode mode) {
text_draw_background();
text_draw_window(x * FONT_W - MSGBOX_PADDING, y * FONT_H - MSGBOX_PADDING, width*FONT_W + MSGBOX_PADDING*2, height*FONT_H + MSGBOX_PADDING*2, title);

for (c=message; c!=1; c=strchr(c, '\n')+1)
char *n=NULL;
for (c=message; c!=1; c=n+1)
{
char *n;
if ((n=strchr(c,'\n'))!=NULL)
*n=0;
snprintf(buf, width+1, "%s", c);
if (n) *n='\n';
n=strchr(c,'\n');
snprintf(buf, MIN(n?n-c:strlen(c), width)+1, "%s", c);
write_text(x, y+yo, buf);
++yo;
}
Expand Down Expand Up @@ -811,9 +809,13 @@ int text_messagebox(char *title, char *message, mb_mode mode) {
write_text(x+width/2+1, y+yo+1, "NO");
break;
}
text_flip();
SDL_Delay(10);
// text_flip() but without the SDL_Delay
SDL_BlitSurface(text_screen,NULL,prSDLScreen,NULL);
uib_update();
SDL_Flip(prSDLScreen);
if (mode == MB_NONE) break;
SDL_Delay(20);
frame = (frame + 1) % 6;
} while (mode != MB_NONE);
} while (1);
return 0;
}
1 change: 1 addition & 0 deletions src/menu/menu_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ static enum MainMenuEntry c = MAIN_MENU_ENTRY_LOAD;
while (action == MAIN_MENU_ENTRY_NONE)
{
draw_mainMenu(c);
SDL_Delay(10);
action = key_mainMenu(&c);
}
unraise_mainMenu();
Expand Down
21 changes: 1 addition & 20 deletions src/sysconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,23 +460,4 @@

/* Define if you have the <windows.h> header file. */
/* #undef HAVE_WINDOWS_H */

#ifdef WIN32
#define random() (rand())
#endif

#ifdef DREAMCAST
#include<kos.h>
#include<sys/stat.h>
#include<utime.h>
#define dup(a) (int)fs_dup((file_t)a)
#define access(a,b) 0
#define mkdir(a,b) fs_mkdir(a)
#define rmdir(a) fs_rmdir(a)
#define chmod(a,b) 0
#define utime(a,b) 0
#define random() (rand())
#define creat(x,y) open("T:creat",O_CREAT|O_WRONLY|O_TRUNC)
#define tmpnam(a) "/ram/tmp"
#endif

#define MIN(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })

0 comments on commit 7f3ec45

Please sign in to comment.