Cleaned up some code.

This commit is contained in:
rheiny 2007-02-07 20:35:15 +00:00
parent 618d4fccea
commit 507ddedda5
5 changed files with 164 additions and 82 deletions

View File

@ -64,13 +64,13 @@ static CFGSTRUCT fceuconfig[] = {
ACS(gfsdir), ACS(gfsdir),
NACS("odcheats",DOvers[0]), NACS("odcheats",directory_names[0]),
NACS("odmisc",DOvers[1]), NACS("odmisc",directory_names[1]),
NACS("odnonvol",DOvers[2]), NACS("odnonvol",directory_names[2]),
NACS("odstates",DOvers[3]), NACS("odstates",directory_names[3]),
NACS("odsnaps",DOvers[4]), NACS("odsnaps",directory_names[4]),
NACS("odbase",DOvers[5]), NACS("odbase",directory_names[5]),
NACS("odbase",DOvers[6]), NACS("odbase",directory_names[6]),
AC(winspecial), AC(winspecial),
AC(winsizemulx), AC(winsizemulx),

View File

@ -73,9 +73,18 @@ HINSTANCE fceu_hInstance;
HRESULT ddrval; HRESULT ddrval;
// cheats, misc, nonvol, states, snaps, ..., base /**
static char *DOvers[6]={0,0,0,0,0,0}; * Contains the names of the overridden standard directories
static const char *defaultds[5]={"cheats","sav","fcs","snaps","movie"}; * in the order cheats, misc, nonvol, states, snaps, ..., base
**/
static char *directory_names[6] = {0, 0, 0, 0, 0, 0};
/**
* Contains the names of the default directories.
**/
static const char *default_directory_names[5] = {"cheats", "sav", "fcs", "snaps", "movie"};
#define NUMBER_OF_DIRECTORIES sizeof(directory_names) / sizeof(*directory_names)
static char TempArray[2048]; static char TempArray[2048];
@ -100,12 +109,12 @@ void SetDirs(void)
for(x=0; x < sizeof(jlist) / sizeof(*jlist); x++) for(x=0; x < sizeof(jlist) / sizeof(*jlist); x++)
{ {
FCEUI_SetDirOverride(jlist[x], DOvers[x]); FCEUI_SetDirOverride(jlist[x], directory_names[x]);
} }
if(DOvers[5]) if(directory_names[5])
{ {
FCEUI_SetBaseDirectory(DOvers[5]); FCEUI_SetBaseDirectory(directory_names[5]);
} }
else else
{ {
@ -118,9 +127,9 @@ void RemoveDirs(void)
int x; int x;
for(x=0;x<5;x++) for(x=0;x<5;x++)
if(!DOvers[x]) if(!directory_names[x])
{ {
sprintf(TempArray,"%s\\%s",DOvers[5]?DOvers[5]:BaseDirectory,defaultds[x]); sprintf(TempArray,"%s\\%s",directory_names[5]?directory_names[5]:BaseDirectory,default_directory_names[x]);
RemoveDirectory(TempArray); RemoveDirectory(TempArray);
} }
} }
@ -132,11 +141,11 @@ void CreateDirs(void)
{ {
int x; int x;
for(x = 0; x < sizeof(defaultds) / sizeof(*defaultds); x++) for(x = 0; x < sizeof(default_directory_names) / sizeof(*default_directory_names); x++)
{ {
if(!DOvers[x]) if(!directory_names[x])
{ {
sprintf(TempArray, "%s\\%s", DOvers[5] ? DOvers[5] : BaseDirectory, defaultds[x]); sprintf(TempArray, "%s\\%s", directory_names[5] ? directory_names[5] : BaseDirectory, default_directory_names[x]);
CreateDirectory(TempArray,0); CreateDirectory(TempArray,0);
} }
} }

Binary file not shown.

View File

@ -3,8 +3,10 @@
// Used by res.rc // Used by res.rc
// //
#define GUI_BOT_CLOSE 1 #define GUI_BOT_CLOSE 1
#define CLOSE_BUTTON 1
#define GUI_BOT_VALUES 2 #define GUI_BOT_VALUES 2
#define MENU_OPEN_FILE 100 #define MENU_OPEN_FILE 100
#define EDIT_CHEATS 100
#define MENU_CLOSE_FILE 101 #define MENU_CLOSE_FILE 101
#define IDI_ICON1 101 #define IDI_ICON1 101
#define IDI_ICON2 102 #define IDI_ICON2 102
@ -18,17 +20,20 @@
#define MENU_STOP_AVI 152 #define MENU_STOP_AVI 152
#define MENU_EXIT 153 #define MENU_EXIT 153
#define MENU_RESET 200 #define MENU_RESET 200
#define BUTTON_CHEATS 200
#define MENU_POWER 201 #define MENU_POWER 201
#define MENU_EJECT_DISK 202 #define MENU_EJECT_DISK 202
#define MENU_SWITCH_DISK 203 #define MENU_SWITCH_DISK 203
#define MENU_INSERT_COIN 204 #define MENU_INSERT_COIN 204
#define MENU_HIDE_MENU 300 #define MENU_HIDE_MENU 300
#define CHECK_SCREENSHOT_NAMES 300
#define MENU_RUN_IN_BACKGROUND 301 #define MENU_RUN_IN_BACKGROUND 301
#define MENU_BACKGROUND_INPUT 302 #define MENU_BACKGROUND_INPUT 302
#define MENU_SHOW_STATUS_ICON 303 #define MENU_SHOW_STATUS_ICON 303
#define MENU_ENABLE_REWIND 304 #define MENU_ENABLE_REWIND 304
#define MENU_GAME_GENIE 310 #define MENU_GAME_GENIE 310
#define MENU_PAL 311 #define MENU_PAL 311
#define MENU_DIRECTORIES 320
#define GUI_BOT_A_1 1000 #define GUI_BOT_A_1 1000
#define GUI_BOT_B_1 1001 #define GUI_BOT_B_1 1001
#define GUI_BOT_SELECT_1 1002 #define GUI_BOT_SELECT_1 1002
@ -165,7 +170,7 @@
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103 #define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40037 #define _APS_NEXT_COMMAND_VALUE 40038
#define _APS_NEXT_CONTROL_VALUE 1117 #define _APS_NEXT_CONTROL_VALUE 1117
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif

View File

@ -845,7 +845,12 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
UpdateCheckedMenuItems(); break; UpdateCheckedMenuItems(); break;
case 40002: CreateBasicBot();break; case 40002: CreateBasicBot();break;
// case 40028: DoMemmo(0); break; //mbg merge 7/18/06 removed as part of old debugger // case 40028: DoMemmo(0); break; //mbg merge 7/18/06 removed as part of old debugger
case 320:ConfigDirectories();break;
case MENU_DIRECTORIES:
// Directories menu was selected
ConfigDirectories();
break;
case 327:ConfigGUI();break; case 327:ConfigGUI();break;
case 321:ConfigInput(hWnd);break; case 321:ConfigInput(hWnd);break;
case 322:ConfigTiming();break; case 322:ConfigTiming();break;
@ -1519,79 +1524,142 @@ static int BrowseForFolder(HWND hParent, char *htext, char *buf)
return(ret); return(ret);
} }
static BOOL CALLBACK DirConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) /**
* Processes information from the Directories selection dialog after
* the dialog was closed.
*
* @param hwndDlg Handle of the dialog window.
**/
void CloseDirectoriesDialog(HWND hwndDlg)
{ {
int x; int x;
switch(uMsg){ // Update the information from the screenshot naming checkbox
case WM_INITDIALOG: if(IsDlgButtonChecked(hwndDlg, CHECK_SCREENSHOT_NAMES) == BST_CHECKED)
SetDlgItemText(hwndDlg,65508,"The settings in the \"Individual Directory Overrides\" group will override the settings in the \"Base Directory Override\" group. To delete an override, delete the text from the text edit control. Note that the directory the configuration file is in cannot be overridden"); {
for(x=0;x<6;x++) eoptions |= EO_SNAPNAME;
SetDlgItemText(hwndDlg,100+x,DOvers[x]); }
if(eoptions&EO_SNAPNAME) else
CheckDlgButton(hwndDlg,300,BST_CHECKED); {
break; eoptions &= ~EO_SNAPNAME;
case WM_CLOSE: }
case WM_QUIT: goto gornk;
case WM_COMMAND:
if(!(wParam>>16))
{
if((wParam&0xFFFF)>=200 && (wParam&0xFFFF)<=205)
{
static char *helpert[6]={"Cheats","Miscellaneous","Nonvolatile Game Data","Save States","Screen Snapshots","Base Directory"};
char name[MAX_PATH];
if(BrowseForFolder(hwndDlg,helpert[((wParam&0xFFFF)-200)],name)) RemoveDirs(); // Remove empty directories.
SetDlgItemText(hwndDlg,100+((wParam&0xFFFF)-200),name);
}
else switch(wParam&0xFFFF)
{
case 1:
gornk:
if(IsDlgButtonChecked(hwndDlg,300)==BST_CHECKED) // Read the information from the edit fields and update the
eoptions|=EO_SNAPNAME; // necessary variables.
else for(x = 0; x < NUMBER_OF_DIRECTORIES; x++)
eoptions&=~EO_SNAPNAME; {
LONG len;
len = SendDlgItemMessage(hwndDlg, EDIT_CHEATS + x, WM_GETTEXTLENGTH, 0, 0);
RemoveDirs(); // Remove empty directories. if(len <= 0)
{
if(directory_names[x])
{
free(directory_names[x]);
}
for(x=0;x<6;x++) directory_names[x] = 0;
{ continue;
LONG len; }
len=SendDlgItemMessage(hwndDlg,100+x,WM_GETTEXTLENGTH,0,0);
if(len<=0)
{
if(DOvers[x]) free(DOvers[x]);
DOvers[x]=0;
continue;
}
len++; // Add 1 for null character.
if(!(DOvers[x]=(char*)malloc(len))) //mbg merge 7/17/06 added cast
continue;
if(!GetDlgItemText(hwndDlg,100+x,DOvers[x],len))
{
free(DOvers[x]);
DOvers[x]=0;
continue;
}
} len++; // Add 1 for null character.
CreateDirs(); // Create needed directories. if( !(directory_names[x] = (char*)malloc(len))) //mbg merge 7/17/06 added cast
SetDirs(); // Set the directories in the core. {
EndDialog(hwndDlg,0); continue;
break; }
}
} if(!GetDlgItemText(hwndDlg, EDIT_CHEATS + x, directory_names[x], len))
} {
return 0; free(directory_names[x]);
directory_names[x]=0;
continue;
}
}
CreateDirs(); // Create needed directories.
SetDirs(); // Set the directories in the core.
EndDialog(hwndDlg, 0);
} }
/**
static void ConfigDirectories(void) * Callback function for the directories configuration dialog.
**/
static BOOL CALLBACK DirConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
DialogBox(fceu_hInstance,"DIRCONFIG",hAppWnd,DirConCallB); int x;
switch(uMsg)
{
case WM_INITDIALOG:
SetDlgItemText(hwndDlg,65508,"The settings in the \"Individual Directory Overrides\" group will override the settings in the \"Base Directory Override\" group. To delete an override, delete the text from the text edit control. Note that the directory the configuration file is in cannot be overridden");
// Initialize the directories textboxes
for(x = 0; x < NUMBER_OF_DIRECTORIES; x++)
{
SetDlgItemText(hwndDlg, EDIT_CHEATS + x, directory_names[x]);
}
// Check the screenshot naming checkbox if necessary
if(eoptions & EO_SNAPNAME)
{
CheckDlgButton(hwndDlg, CHECK_SCREENSHOT_NAMES, BST_CHECKED);
}
break;
case WM_CLOSE:
case WM_QUIT:
CloseDirectoriesDialog(hwndDlg);
break;
case WM_COMMAND:
if( !(wParam >> 16) )
{
if( (wParam & 0xFFFF) >= BUTTON_CHEATS && (wParam & 0xFFFF) <= BUTTON_CHEATS + NUMBER_OF_DIRECTORIES)
{
// If a directory selection button was pressed, ask the
// user for a directory.
static char *helpert[6] = {
"Cheats",
"Miscellaneous",
"Nonvolatile Game Data",
"Save States",
"Screen Snapshots",
"Base Directory"
};
char name[MAX_PATH];
if(BrowseForFolder(hwndDlg, helpert[ ( (wParam & 0xFFFF) - BUTTON_CHEATS)], name))
{
SetDlgItemText(hwndDlg, EDIT_CHEATS + ((wParam & 0xFFFF) - BUTTON_CHEATS), name);
}
}
else switch(wParam & 0xFFFF)
{
case CLOSE_BUTTON:
CloseDirectoriesDialog(hwndDlg);
break;
}
}
}
return 0;
}
/**
* Shows the dialog for configuring the standard directories.
**/
void ConfigDirectories(void)
{
DialogBox(fceu_hInstance, "DIRCONFIG", hAppWnd, DirConCallB);
} }
static int ReplayDialogReadOnlyStatus = 0; static int ReplayDialogReadOnlyStatus = 0;