linux compat
This commit is contained in:
19
lib/state.c
19
lib/state.c
@ -1,5 +1,10 @@
|
||||
#include <state.h>
|
||||
#include <string.h>
|
||||
#ifdef __windows__
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
void state_save(save_state* state) {
|
||||
printf("Saving state\n");
|
||||
@ -33,10 +38,17 @@ void state_save_file(u8 slot) {
|
||||
char *filename = strrchr(cart_get_context()->filename, '\\');
|
||||
filename++;
|
||||
char fn[1048];
|
||||
#ifdef __windows__
|
||||
char *profile = getenv("USERPROFILE");
|
||||
sprintf(fn, "%s/Documents/gbemu/states/%s", profile, filename);
|
||||
CreateDirectory(fn, NULL);
|
||||
sprintf(fn, "%s/Documents/gbemu/states/%s/%d.state", profile, filename, slot);
|
||||
#else
|
||||
char *profile = getenv("HOME");
|
||||
sprintf(fn, "%s/.config/gbemu/states/%s", profile, filename);
|
||||
mkdir(fn, 0755);
|
||||
sprintf(fn, "%s/.config/gbemu/states/%s/%d.state", profile, filename, slot);
|
||||
#endif
|
||||
FILE *fp = fopen(fn, "wb");
|
||||
|
||||
if(!fp) {
|
||||
@ -53,8 +65,13 @@ void state_load_file(u8 slot) {
|
||||
char *filename = strrchr(cart_get_context()->filename, '\\');
|
||||
filename++;
|
||||
char fn[1048];
|
||||
#ifdef __windows__
|
||||
char *profile = getenv("USERPROFILE");
|
||||
sprintf(fn, "%s/Documents/gbemu/states/%s/%d.state", profile, filename, slot);
|
||||
#else
|
||||
char *profile = getenv("HOME");
|
||||
sprintf(fn, "%s/.config/gbemu/states/%s/%d.state", profile, filename, slot);
|
||||
#endif
|
||||
FILE *fp = fopen(fn, "rb");
|
||||
|
||||
if(!fp) {
|
||||
@ -65,4 +82,4 @@ void state_load_file(u8 slot) {
|
||||
fread(state, sizeof(*state), 1, fp);
|
||||
fclose(fp);
|
||||
state_load(state);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user