From aeeb491a49bc809bfc5f68e6834a54d709416633 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Thu, 9 Feb 2012 03:10:20 +0100 Subject: [PATCH] (360) Config file gets loaded and saved now --- 360/main.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++- 360/menu.cpp | 2 ++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/360/main.c b/360/main.c index 0270960a54..2bfdb567df 100644 --- a/360/main.c +++ b/360/main.c @@ -23,7 +23,10 @@ #include #include "menu.h" #include "xdk360_video.h" + #include "../console/main_wrap.h" +#include "../conf/config_file.h" +#include "../conf/config_file_macros.h" #include "../general.h" #include "shared.h" @@ -45,6 +48,8 @@ typedef struct _STRING { PCHAR Buffer; } STRING; +char SYS_CONFIG_FILE[MAX_PATH_LENGTH]; + extern "C" int __stdcall ObCreateSymbolicLink( STRING*, STRING*); bool init_ssnes = false; @@ -122,7 +127,7 @@ static int Mount( int Device, char* MountPoint ) return DriveMounted(MountPoint); } -static void set_default_settings(void) +static void set_default_settings (void) { //g_settings g_settings.rewind_enable = false; @@ -136,6 +141,71 @@ static void set_default_settings(void) g_extern.verbose = true; } +static bool file_exists(const char * filename) +{ + DWORD file_attr; + + file_attr = GetFileAttributes(filename); + + if (0xFFFFFFFF == file_attr) + return false; + + return true; +} + +static void init_settings (void) +{ + if(!file_exists(SYS_CONFIG_FILE)) + { + SSNES_ERR("Config file \"%s\" desn't exist! Creating...\n", "game:\\ssnes.cfg"); + FILE * f; + f = fopen(SYS_CONFIG_FILE, "w"); + fclose(f); + } + + config_file_t * conf = config_file_new(SYS_CONFIG_FILE); + + // g_settings + CONFIG_GET_BOOL(rewind_enable, "rewind_enable"); + + // g_console + CONFIG_GET_STRING_CONSOLE(default_rom_startup_dir, "default_rom_startup_dir"); + + // g_extern + CONFIG_GET_INT_EXTERN(state_slot, "state_slot"); + CONFIG_GET_INT_EXTERN(audio_data.mute, "audio_mute"); +} + +static void save_settings (void) +{ + if(!file_exists(SYS_CONFIG_FILE)) + { + FILE * f; + f = fopen(SYS_CONFIG_FILE, "w"); + fclose(f); + } + + config_file_t * conf = config_file_new(SYS_CONFIG_FILE); + + if(conf == NULL) + conf = config_file_new(NULL); + + // g_settings + config_set_bool(conf, "rewind_enable", g_settings.rewind_enable); + + // g_console + config_set_string(conf, "default_rom_startup_dir", g_console.default_rom_startup_dir); + + // g_extern + config_set_int(conf, "state_slot", g_extern.state_slot); + config_set_int(conf, "audio_mute", g_extern.audio_data.mute); + + if (!config_file_write(conf, SYS_CONFIG_FILE)) + SSNES_ERR("Failed to write config file to \"%s\"! Check permissions!\n", SYS_CONFIG_FILE); + + free(conf); +} + static void get_environment_settings (void) { //for devkits only, we will need to mount all partitions for retail @@ -195,6 +265,8 @@ static void get_environment_settings (void) } } + + strlcpy(SYS_CONFIG_FILE, "game:\\ssnes.cfg", sizeof(SYS_CONFIG_FILE)); } int main(int argc, char *argv[]) @@ -205,6 +277,7 @@ int main(int argc, char *argv[]) config_set_defaults(); set_default_settings(); + init_settings(); xdk360_video_init(); menu_init(); @@ -227,6 +300,7 @@ begin_loop: struct ssnes_main_wrap args = {0}; args.verbose = g_extern.verbose; + args.config_path = args.rom_path = g_console.rom_path; int init_ret = ssnes_main_init_wrap(&args); @@ -240,6 +314,8 @@ begin_loop: goto begin_loop; begin_shutdown: + if(file_exists(SYS_CONFIG_FILE)) + save_settings(); xdk360_video_deinit(); } diff --git a/360/menu.cpp b/360/menu.cpp index 077facce11..3d5798dc06 100644 --- a/360/menu.cpp +++ b/360/menu.cpp @@ -88,6 +88,8 @@ HRESULT CSSNESSettings::OnInit(XUIMessageInit * pInitData, BOOL& bHandled) GetChildById(L"XuiBtnRewind", &m_rewind); GetChildById(L"XuiCheckbox1", &m_rewind_cb); GetChildById(L"XuiBackButton1", &m_back); + + m_rewind_cb.SetCheck(g_settings.rewind_enable); return S_OK; }