win32: a bunch of cleanup and fix recent roms not saving when emulator crashes

This commit is contained in:
zeromus 2009-12-20 00:06:45 +00:00
parent 64cecb1b3e
commit f397adaf47
20 changed files with 549 additions and 392 deletions

View File

@ -37,56 +37,6 @@ u8 logo_data[156] = {
0x78,0x00,0x90,0xCB,0x88,0x11,0x3A,0x94,0x65,0xC0,0x7C,0x63,0x87,0xF0,0x3C,0xAF,
0xD6,0x25,0xE4,0x8B,0x38,0x0A,0xAC,0x72,0x21,0xD4,0xF8,0x07};
#ifdef WIN32
char IniName[MAX_PATH];
void GetINIPath()
{
char vPath[MAX_PATH], *szPath;
/*if (*vPath)
szPath = vPath;
else
{*/
char *p;
ZeroMemory(vPath, sizeof(vPath));
GetModuleFileName(NULL, vPath, sizeof(vPath));
p = vPath + lstrlen(vPath);
while (p >= vPath && *p != '\\') p--;
if (++p >= vPath) *p = 0;
szPath = vPath;
//}
if (strlen(szPath) + strlen("\\desmume.ini") < MAX_PATH)
{
sprintf(IniName, "%s\\desmume.ini",szPath);
} else if (MAX_PATH> strlen(".\\desmume.ini")) {
sprintf(IniName, ".\\desmume.ini");
} else
{
memset(IniName,0,MAX_PATH) ;
}
}
void WritePrivateProfileBool(char* appname, char* keyname, bool val, char* file)
{
char temp[256] = "";
sprintf(temp, "%d", val?1:0);
WritePrivateProfileString(appname, keyname, temp, file);
}
bool GetPrivateProfileBool(const char* appname, const char* keyname, bool defval, const char* filename)
{
return GetPrivateProfileInt(appname,keyname,defval?1:0,filename) != 0;
}
void WritePrivateProfileInt(char* appname, char* keyname, int val, char* file)
{
char temp[256] = "";
sprintf(temp, "%d", val);
WritePrivateProfileString(appname, keyname, temp, file);
}
#endif
u8 reverseBitsInByte(u8 x)
{
u8 h = 0;

View File

@ -34,33 +34,7 @@ extern u8 logo_data[156];
#include <winsock2.h>
#include <windows.h>
#define IDT_VIEW_DISASM7 50001
#define IDT_VIEW_DISASM9 50002
#define IDT_VIEW_MEM7 50003
#define IDT_VIEW_MEM9 50004
#define IDT_VIEW_IOREG 50005
#define IDT_VIEW_PAL 50006
#define IDT_VIEW_TILE 50007
#define IDT_VIEW_MAP 50008
#define IDT_VIEW_OAM 50009
#define IDT_VIEW_MATRIX 50010
#define IDT_VIEW_LIGHTS 50011
#define IDM_EXEC 50112
#define IDM_RECENT_RESERVED0 65500
#define IDM_RECENT_RESERVED1 65501
#define IDM_RECENT_RESERVED2 65502
#define IDM_RECENT_RESERVED3 65503
#define IDM_RECENT_RESERVED4 65504
#define IDM_RECENT_RESERVED5 65505
#define IDM_RECENT_RESERVED6 65506
#define IDM_RECENT_RESERVED7 65507
#define IDM_RECENT_RESERVED8 65508
#define IDM_RECENT_RESERVED9 65509
#define IDM_RECENT_RESERVED10 65510
#define IDM_RECENT_RESERVED11 65511
#define IDM_RECENT_RESERVED12 65512
#define IDM_RECENT_RESERVED13 65513
#define CLASSNAME "DeSmuME"

View File

@ -1,7 +1,5 @@
/* Copyright (C) 2006 yopyop
yopyop156@ifrance.com
yopyop156.ifrance.com
/* gfx3d.cpp
Copyright (C) 2006 yopyop
Copyright (C) 2008-2009 DeSmuME team
This file is part of DeSmuME

View File

@ -64,11 +64,6 @@ static const char* magic = "DeSmuME SState\0";
//a savestate chunk loader can set this if it wants to permit a silent failure (for compatibility)
static bool SAV_silent_fail_flag;
#ifndef MAX_PATH
#define MAX_PATH 256
#endif
SFORMAT SF_ARM7[]={
{ "7INS", 4, 1, &NDS_ARM7.instruction },
{ "7INA", 4, 1, &NDS_ARM7.instruct_adr },

View File

@ -336,7 +336,7 @@ void WINCLASS::setMinSize(int width, int height)
minHeight = height;
}
void MyAdjustWindowRectEx(RECT* rect, HWND hwnd)
static void MyAdjustWindowRectEx(RECT* rect, HWND hwnd)
{
AdjustWindowRectEx(rect,GetWindowStyle(hwnd),TRUE,GetWindowExStyle(hwnd));
@ -363,18 +363,6 @@ void WINCLASS::sizingMsg(WPARAM wParam, LPARAM lParam, LONG keepRatio)
int _minWidth, _minHeight;
int xborder, yborder;
int ymenu, ymenunew;
int ycaption;
MENUBARINFO mbi;
/* Get the size of the menu bar */
ZeroMemory(&mbi, sizeof(mbi));
mbi.cbSize = sizeof(mbi);
GetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
ymenu = (mbi.rcBar.bottom - mbi.rcBar.top + 1);
RECT adjr;
SetRect(&adjr,0,0,minWidth,minHeight);
MyAdjustWindowRectEx(&adjr,hwnd);
@ -389,7 +377,6 @@ void WINCLASS::sizingMsg(WPARAM wParam, LPARAM lParam, LONG keepRatio)
_minWidth = adjr.right-adjr.left;
_minHeight = adjr.bottom-adjr.top;
/* Clamp the size to the minimum size (256x384) */
rect->right = (rect->left + std::max(_minWidth, (int)(rect->right - rect->left)));
rect->bottom = (rect->top + std::max(_minHeight, (int)(rect->bottom - rect->top)));
@ -439,15 +426,6 @@ void WINCLASS::sizingMsg(WPARAM wParam, LPARAM lParam, LONG keepRatio)
}
}
/* Check if the height of the menu has changed during the resize */
ZeroMemory(&mbi, sizeof(mbi));
mbi.cbSize = sizeof(mbi);
GetMenuBarInfo(hwnd, OBJID_MENU, 0, &mbi);
ymenunew = (mbi.rcBar.bottom - mbi.rcBar.top + 1);
if(ymenunew != ymenu)
rect->bottom += (ymenunew - ymenu);
// prevent "pushing" the window across the screen when resizing from the left or top
if(wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT || wParam == WMSZ_BOTTOMLEFT)
{

View File

@ -846,6 +846,14 @@
RelativePath=".\ramwatch.h"
>
</File>
<File
RelativePath=".\recentroms.cpp"
>
</File>
<File
RelativePath=".\recentroms.h"
>
</File>
<File
RelativePath=".\replay.cpp"
>
@ -898,6 +906,14 @@
RelativePath=".\windriver.h"
>
</File>
<File
RelativePath=".\winutil.cpp"
>
</File>
<File
RelativePath=".\winutil.h"
>
</File>
<Filter
Name="userconfig"
>

View File

@ -1304,14 +1304,6 @@
RelativePath=".\gbaslot_config.h"
>
</File>
<File
RelativePath=".\ginfo.cpp"
>
</File>
<File
RelativePath=".\ginfo.h"
>
</File>
<File
RelativePath=".\hotkey.cpp"
>
@ -1364,6 +1356,14 @@
RelativePath=".\pathsettings.h"
>
</File>
<File
RelativePath=".\recentroms.cpp"
>
</File>
<File
RelativePath=".\recentroms.h"
>
</File>
<File
RelativePath=".\replay.cpp"
>
@ -1392,6 +1392,14 @@
RelativePath=".\throttle.h"
>
</File>
<File
RelativePath=".\winutil.cpp"
>
</File>
<File
RelativePath=".\winutil.h"
>
</File>
<Filter
Name="filters"
>
@ -1443,6 +1451,14 @@
RelativePath=".\disView.h"
>
</File>
<File
RelativePath=".\ginfo.cpp"
>
</File>
<File
RelativePath=".\ginfo.h"
>
</File>
<File
RelativePath=".\IORegView.cpp"
>

View File

@ -28,6 +28,7 @@
#include "disView.h"
#include <commctrl.h>
#include "resource.h"
#include "main.h"
typedef struct
{

View File

@ -23,6 +23,7 @@
#include "gfx3d.h"
#include "resource.h"
#include "debug.h"
#include "main.h"
// Convert B5G5R5 color format into R8G8B8 color format
unsigned int ColorConv_B5R5R5ToR8G8B8(const unsigned int color)

View File

@ -24,32 +24,69 @@
// RGB(246, 246, 251) to RGB(128, 128, 192)
#include "windriver.h"
#include <algorithm>
#include <shellapi.h>
#include <shlwapi.h>
#include <string>
#include <vector>
//#include <sstream>
#include <Winuser.h>
#include <Winnls.h>
#include <windowsx.h>
#include <mmsystem.h>
#include <shellapi.h>
#include <shlwapi.h>
#include <commctrl.h>
#include <commdlg.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <sstream>
#include <tchar.h>
#include "gthread.h"
#include "version.h"
#include "CWindow.h"
#include <stdio.h>
//emulator core
#include "../common.h" //wtf this needs to disappear
#include "../MMU.h"
#include "../armcpu.h"
#include "../NDSSystem.h"
#include "../debug.h"
#include "../saves.h"
#include "../addons.h"
#include "../GPU_osd.h"
#include "../OGLRender.h"
#include "../rasterize.h"
#include "../gfx3d.h"
#include "../render3D.h"
#include "../gdbstub.h"
#include "../cheatSystem.h"
#include "../mic.h"
#include "../movie.h"
#include "../firmware.h"
#include "../lua-engine.h"
#include "../path.h"
//other random stuff
#include "recentroms.h"
#include "main.h"
#include "resource.h"
#include "GPU_osd.h"
#include "memView.h"
#include "disView.h"
#include "CWindow.h"
#include "gthread.h"
#include "version.h"
#include "inputdx.h"
#include "console.h"
#include "throttle.h"
#include "hotkey.h"
#include "snddx.h"
#include "commandline.h"
#include "7zip.h"
#include "OpenArchive.h"
#include "utils/xstring.h"
#include "directx/ddraw.h"
#include "video.h"
#include "aggdraw.h"
#include "agg2d.h"
//tools and dialogs
#include "pathsettings.h"
#include "colorctrl.h"
#include "ginfo.h"
#include "IORegView.h"
#include "palView.h"
@ -58,44 +95,17 @@
#include "mapview.h"
#include "matrixview.h"
#include "lightview.h"
#include "inputdx.h"
#include "FirmConfig.h"
#include "AboutBox.h"
#include "OGLRender.h"
#include "rasterize.h"
#include "../gfx3d.h"
#include "../render3D.h"
#include "../gdbstub.h"
#include "colorctrl.h"
#include "console.h"
#include "throttle.h"
#include "gbaslot_config.h"
#include "cheatsWin.h"
#include "../cheatSystem.h"
#include "Mmsystem.h"
#include "../mic.h"
#include "../common.h"
#include "main.h"
#include "hotkey.h"
#include "../movie.h"
#include "../replay.h"
#include "snddx.h"
#include "memView.h"
#include "disView.h"
#include "FirmConfig.h"
#include "AboutBox.h"
#include "replay.h"
#include "ramwatch.h"
#include "ram_search.h"
#include "aviout.h"
#include "soundView.h"
#include "commandline.h"
#include "../lua-engine.h"
#include "7zip.h"
#include "pathsettings.h"
#include "utils/xstring.h"
#include "directx/ddraw.h"
#include "video.h"
#include "path.h"
#include "../firmware.h"
#include "aggdraw.h"
#include "agg2d.h"
using namespace std;
@ -164,18 +174,11 @@ static BOOL OpenCore(const char* filename);
BOOL Mic_DeInit_Physical();
BOOL Mic_Init_Physical();
//----Recent ROMs menu globals----------
vector<string> RecentRoms; //The list of recent ROM filenames
const unsigned int MAX_RECENT_ROMS = 10; //To change the recent rom max, simply change this number
const unsigned int clearid = IDM_RECENT_RESERVED0; // ID for the Clear recent ROMs item
const unsigned int baseid = IDM_RECENT_RESERVED1; //Base identifier for the recent ROMs items
static HMENU recentromsmenu; //Handle to the recent ROMs submenu
//--------------------------------------
static bool _cheatsDisabled = false;
void UpdateHotkeyAssignments(); //Appends hotkey mappings to corresponding menu items
static HMENU mainMenu; //Holds handle to the main DeSmuME menu
HMENU mainMenu; //Holds handle to the main DeSmuME menu
DWORD hKeyInputTimer;
@ -661,197 +664,7 @@ static void SetStyle(u32 dws)
static u32 GetStyle() { return currWindowStyle; }
//---------
void UpdateRecentRomsMenu()
{
//This function will be called to populate the Recent Menu
//The array must be in the proper order ahead of time
//UpdateRecentRoms will always call this
//This will be always called by GetRecentRoms on DesMume startup
//----------------------------------------------------------------------
//Get Menu item info
MENUITEMINFO moo;
moo.cbSize = sizeof(moo);
moo.fMask = MIIM_SUBMENU | MIIM_STATE;
GetMenuItemInfo(GetSubMenu(mainMenu, 0), ID_FILE_RECENTROM, FALSE, &moo);
moo.hSubMenu = GetSubMenu(recentromsmenu, 0);
//moo.fState = RecentRoms[0].c_str() ? MFS_ENABLED : MFS_GRAYED;
moo.fState = MFS_ENABLED;
SetMenuItemInfo(GetSubMenu(mainMenu, 0), ID_FILE_RECENTROM, FALSE, &moo);
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//Clear the current menu items
for(int x = 0; x < MAX_RECENT_ROMS; x++)
{
DeleteMenu(GetSubMenu(recentromsmenu, 0), baseid + x, MF_BYCOMMAND);
}
if(RecentRoms.size() == 0)
{
EnableMenuItem(GetSubMenu(recentromsmenu, 0), clearid, MF_GRAYED);
moo.cbSize = sizeof(moo);
moo.fMask = MIIM_DATA | MIIM_ID | MIIM_STATE | MIIM_TYPE;
moo.cch = 5;
moo.fType = 0;
moo.wID = baseid;
moo.dwTypeData = "None";
moo.fState = MF_GRAYED;
InsertMenuItem(GetSubMenu(recentromsmenu, 0), 0, TRUE, &moo);
return;
}
EnableMenuItem(GetSubMenu(recentromsmenu, 0), clearid, MF_ENABLED);
DeleteMenu(GetSubMenu(recentromsmenu, 0), baseid, MF_BYCOMMAND);
HDC dc = GetDC(MainWindow->getHWnd());
//-----------------------------------------------------------------------
//Update the list using RecentRoms vector
for(int x = RecentRoms.size()-1; x >= 0; x--) //Must loop in reverse order since InsertMenuItem will insert as the first on the list
{
string tmp = RecentRoms[x];
LPSTR tmp2 = (LPSTR)tmp.c_str();
PathCompactPath(dc, tmp2, 500);
moo.cbSize = sizeof(moo);
moo.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;
moo.cch = tmp.size();
moo.fType = 0;
moo.wID = baseid + x;
moo.dwTypeData = tmp2;
//LOG("Inserting: %s\n",tmp.c_str()); //Debug
InsertMenuItem(GetSubMenu(recentromsmenu, 0), 0, 1, &moo);
}
ReleaseDC(MainWindow->getHWnd(), dc);
//-----------------------------------------------------------------------
HWND temp = MainWindow->getHWnd();
DrawMenuBar(temp);
}
void UpdateRecentRoms(const char* filename)
{
//This function assumes filename is a ROM filename that was successfully loaded
string newROM = filename; //Convert to std::string
//--------------------------------------------------------------
//Check to see if filename is in list
vector<string>::iterator x;
vector<string>::iterator theMatch;
bool match = false;
for (x = RecentRoms.begin(); x < RecentRoms.end(); ++x)
{
if (newROM == *x)
{
//We have a match
match = true; //Flag that we have a match
theMatch = x; //Hold on to the iterator (Note: the loop continues, so if for some reason we had a duplicate (which wouldn't happen under normal circumstances, it would pick the last one in the list)
}
}
//----------------------------------------------------------------
//If there was a match, remove it
if (match)
RecentRoms.erase(theMatch);
RecentRoms.insert(RecentRoms.begin(), newROM); //Add to the array
//If over the max, we have too many, so remove the last entry
if (RecentRoms.size() > MAX_RECENT_ROMS)
RecentRoms.pop_back();
//Debug
//for (int x = 0; x < RecentRoms.size(); x++)
// LOG("Recent ROM: %s\n",RecentRoms[x].c_str());
UpdateRecentRomsMenu();
}
void RemoveRecentRom(std::string filename)
{
vector<string>::iterator x;
vector<string>::iterator theMatch;
bool match = false;
for (x = RecentRoms.begin(); x < RecentRoms.end(); ++x)
{
if (filename == *x)
{
//We have a match
match = true; //Flag that we have a match
theMatch = x; //Hold on to the iterator (Note: the loop continues, so if for some reason we had a duplicate (which wouldn't happen under normal circumstances, it would pick the last one in the list)
}
}
//----------------------------------------------------------------
//If there was a match, remove it
if (match)
RecentRoms.erase(theMatch);
UpdateRecentRomsMenu();
}
void GetRecentRoms()
{
//This function retrieves the recent ROMs stored in the .ini file
//Then is populates the RecentRomsMenu array
//Then it calls Update RecentRomsMenu() to populate the menu
stringstream temp;
char tempstr[256];
// Avoids duplicating when changing the language.
RecentRoms.clear();
//Loops through all available recent slots
for (int x = 0; x < MAX_RECENT_ROMS; x++)
{
temp.str("");
temp << "Recent Rom " << (x+1);
GetPrivateProfileString("General",temp.str().c_str(),"", tempstr, 256, IniName);
if (tempstr[0])
RecentRoms.push_back(tempstr);
}
UpdateRecentRomsMenu();
}
void SaveRecentRoms()
{
//This function stores the RecentRomsMenu array to the .ini file
stringstream temp;
//Loops through all available recent slots
for (int x = 0; x < MAX_RECENT_ROMS; x++)
{
temp.str("");
temp << "Recent Rom " << (x+1);
if (x < (int)RecentRoms.size()) //If it exists in the array, save it
WritePrivateProfileString("General",temp.str().c_str(),RecentRoms[x].c_str(),IniName);
else //Else, make it empty
WritePrivateProfileString("General",temp.str().c_str(), "",IniName);
}
}
void ClearRecentRoms()
{
RecentRoms.clear();
SaveRecentRoms();
UpdateRecentRomsMenu();
}
static HMENU GetMenuItemParent(UINT itemId, HMENU hMenu = mainMenu)
{
@ -1325,7 +1138,7 @@ static void DD_DoDisplay()
}
}
//tripple buffering logic
//triple buffering logic
u16 displayBuffers[3][256*192*4];
volatile int currDisplayBuffer=-1;
volatile int newestDisplayBuffer=-2;
@ -1898,6 +1711,31 @@ static BOOL LoadROM(const char * filename, const char * logicalName)
return FALSE;
}
void OpenRecentROM(int listNum)
{
if (listNum > MAX_RECENT_ROMS) return; //Just in case
char filename[MAX_PATH];
strcpy(filename, RecentRoms[listNum].c_str());
//LOG("Attempting to load %s\n",filename);
if(OpenCore(filename))
{
romloaded = TRUE;
}
else
//Rom failed to load, ask the user how to handle it
{
string str = "Could not open ";
str.append(filename);
str.append("\n\nRemove from list?");
if (MessageBox(MainWindow->getHWnd(), str.c_str(), "File error", MB_YESNO) == IDYES)
{
RemoveRecentRom(RecentRoms[listNum]);
}
}
NDS_UnPause();
}
/*
* The thread handling functions needed by the GDB stub code.
*/
@ -1921,8 +1759,7 @@ int MenuInit()
mainMenu = LoadMenu(hAppInst, MAKEINTRESOURCE(MENU_PRINCIPAL)); //Load Menu, and store handle
if (!MainWindow->setMenu(mainMenu)) return 0;
recentromsmenu = LoadMenu(hAppInst, MAKEINTRESOURCE(RECENTROMS));
GetRecentRoms();
InitRecentRoms();
ResetSaveStateTimes();
@ -2653,7 +2490,6 @@ int _main()
KillDisplay();
SaveRecentRoms();
DRV_AviEnd();
WAV_End();
@ -3177,33 +3013,9 @@ void WavRecordTo(int wavmode)
NDS_UnPause();
}
void OpenRecentROM(int listNum)
{
if (listNum > MAX_RECENT_ROMS) return; //Just in case
char filename[MAX_PATH];
strcpy(filename, RecentRoms[listNum].c_str());
//LOG("Attempting to load %s\n",filename);
if(OpenCore(filename))
{
romloaded = TRUE;
}
else
//Rom failed to load, ask the user how to handle it
{
string str = "Could not open ";
str.append(filename);
str.append("\n\nRemove from list?");
if (MessageBox(MainWindow->getHWnd(), str.c_str(), "File error", MB_YESNO) == IDYES)
{
RemoveRecentRom(RecentRoms[listNum]);
}
}
NDS_UnPause();
}
#include "OpenArchive.h"
#include "utils/xstring.h"
static BOOL OpenCore(const char* filename)
{
@ -4235,12 +4047,12 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
//wParam &= 0xFFFF;
// A menu item from the recent files menu was clicked.
if(wParam >= baseid && wParam <= baseid + MAX_RECENT_ROMS - 1)
if(wParam >= recentRoms_baseid && wParam <= recentRoms_baseid + MAX_RECENT_ROMS - 1)
{
int x = wParam - baseid;
int x = wParam - recentRoms_baseid;
OpenRecentROM(x);
}
else if(wParam == clearid)
else if(wParam == recentRoms_clearid)
{
/* Clear all the recent ROMs */
if(IDOK == MessageBox(hwnd, "OK to clear recent ROMs list?","DeSmuME",MB_OKCANCEL))

View File

@ -3,6 +3,8 @@
#include "CWindow.h"
extern WINCLASS *MainWindow;
extern HINSTANCE hAppInst;
extern HMENU mainMenu; //Holds handle to the main DeSmuME menu
extern volatile bool execute, paused;
void NDS_Pause(bool showMsg = true);
@ -34,4 +36,32 @@ extern u32 backupmemorysize;
void WIN_InstallCFlash();
#define IDM_RECENT_RESERVED0 65500
#define IDM_RECENT_RESERVED1 65501
#define IDM_RECENT_RESERVED2 65502
#define IDM_RECENT_RESERVED3 65503
#define IDM_RECENT_RESERVED4 65504
#define IDM_RECENT_RESERVED5 65505
#define IDM_RECENT_RESERVED6 65506
#define IDM_RECENT_RESERVED7 65507
#define IDM_RECENT_RESERVED8 65508
#define IDM_RECENT_RESERVED9 65509
#define IDM_RECENT_RESERVED10 65510
#define IDM_RECENT_RESERVED11 65511
#define IDM_RECENT_RESERVED12 65512
#define IDM_RECENT_RESERVED13 65513
#define IDT_VIEW_DISASM7 50001
#define IDT_VIEW_DISASM9 50002
#define IDT_VIEW_MEM7 50003
#define IDT_VIEW_MEM9 50004
#define IDT_VIEW_IOREG 50005
#define IDT_VIEW_PAL 50006
#define IDT_VIEW_TILE 50007
#define IDT_VIEW_MAP 50008
#define IDT_VIEW_OAM 50009
#define IDT_VIEW_MATRIX 50010
#define IDT_VIEW_LIGHTS 50011
#define IDM_EXEC 50112
#endif

View File

@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "../MMU.h"
#include "../NDSSystem.h"
#include "debug.h"
#include "main.h"
#include "windriver.h"
using namespace GPU_EXT;

View File

@ -21,6 +21,7 @@
#include <commctrl.h>
#include "debug.h"
#include "resource.h"
#include "main.h"
#include "gfx3d.h"
typedef struct

View File

@ -21,6 +21,7 @@
#include "oamView.h"
#include <commctrl.h>
#include "main.h"
#include "debug.h"
#include "resource.h"
#include "../MMU.h"

View File

@ -21,6 +21,7 @@
#include "palView.h"
#include <commctrl.h>
#include "main.h"
#include "debug.h"
#include "resource.h"
#include "../MMU.h"

View File

@ -0,0 +1,232 @@
/* recentroms.cpp
Copyright (C) 2008-2009 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <vector>
#include <string>
#include "recentroms.h"
#include "common.h"
#include "resource.h"
#include "main.h"
#include "winutil.h"
#include <shlwapi.h>
std::vector<std::string> RecentRoms; //The list of recent ROM filenames
static HMENU recentromsmenu; //Handle to the recent ROMs submenu
void PopulateRecentRomsMenu()
{
//This function will be called to populate the Recent Menu
//The array must be in the proper order ahead of time
//UpdateRecentRoms will always call this
//This will be always called by GetRecentRoms on DesMume startup
//----------------------------------------------------------------------
//Get Menu item info
MENUITEMINFO moo;
moo.cbSize = sizeof(moo);
moo.fMask = MIIM_SUBMENU | MIIM_STATE;
GetMenuItemInfo(GetSubMenu(mainMenu, 0), ID_FILE_RECENTROM, FALSE, &moo);
moo.hSubMenu = GetSubMenu(recentromsmenu, 0);
//moo.fState = RecentRoms[0].c_str() ? MFS_ENABLED : MFS_GRAYED;
moo.fState = MFS_ENABLED;
SetMenuItemInfo(GetSubMenu(mainMenu, 0), ID_FILE_RECENTROM, FALSE, &moo);
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//Clear the current menu items
for(int x = 0; x < MAX_RECENT_ROMS; x++)
{
DeleteMenu(GetSubMenu(recentromsmenu, 0), recentRoms_baseid + x, MF_BYCOMMAND);
}
if(RecentRoms.size() == 0)
{
EnableMenuItem(GetSubMenu(recentromsmenu, 0), recentRoms_clearid, MF_GRAYED);
moo.cbSize = sizeof(moo);
moo.fMask = MIIM_DATA | MIIM_ID | MIIM_STATE | MIIM_TYPE;
moo.cch = 5;
moo.fType = 0;
moo.wID = recentRoms_baseid;
moo.dwTypeData = "None";
moo.fState = MF_GRAYED;
InsertMenuItem(GetSubMenu(recentromsmenu, 0), 0, TRUE, &moo);
return;
}
EnableMenuItem(GetSubMenu(recentromsmenu, 0), recentRoms_clearid, MF_ENABLED);
DeleteMenu(GetSubMenu(recentromsmenu, 0), recentRoms_baseid, MF_BYCOMMAND);
HDC dc = GetDC(MainWindow->getHWnd());
//-----------------------------------------------------------------------
//Update the list using RecentRoms vector
for(int x = RecentRoms.size()-1; x >= 0; x--) //Must loop in reverse order since InsertMenuItem will insert as the first on the list
{
string tmp = RecentRoms[x];
LPSTR tmp2 = (LPSTR)tmp.c_str();
PathCompactPath(dc, tmp2, 500);
moo.cbSize = sizeof(moo);
moo.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;
moo.cch = tmp.size();
moo.fType = 0;
moo.wID = recentRoms_baseid + x;
moo.dwTypeData = tmp2;
//LOG("Inserting: %s\n",tmp.c_str()); //Debug
InsertMenuItem(GetSubMenu(recentromsmenu, 0), 0, 1, &moo);
}
ReleaseDC(MainWindow->getHWnd(), dc);
//-----------------------------------------------------------------------
HWND temp = MainWindow->getHWnd();
DrawMenuBar(temp);
}
void RemoveRecentRom(const std::string& filename)
{
vector<string>::iterator x;
vector<string>::iterator theMatch;
bool match = false;
for (x = RecentRoms.begin(); x < RecentRoms.end(); ++x)
{
if (filename == *x)
{
//We have a match
match = true; //Flag that we have a match
theMatch = x; //Hold on to the iterator (Note: the loop continues, so if for some reason we had a duplicate (which wouldn't happen under normal circumstances, it would pick the last one in the list)
}
}
//----------------------------------------------------------------
//If there was a match, remove it
if (match)
RecentRoms.erase(theMatch);
PopulateRecentRomsMenu();
}
void LoadRecentRoms()
{
//This function retrieves the recent ROMs stored in the .ini file
//Then is populates the RecentRomsMenu array
char tempstr[256];
// Avoids duplicating when changing the language.
RecentRoms.clear();
//Loops through all available recent slots
for (int x = 0; x < MAX_RECENT_ROMS; x++)
{
char keyName[100];
sprintf(keyName,"Recent Rom %d",x);
GetPrivateProfileString("General",keyName,"", tempstr, 256, IniName);
if (tempstr[0])
RecentRoms.push_back(tempstr);
}
}
void SaveRecentRoms()
{
//This function stores the RecentRomsMenu array to the .ini file
//Loops through all available recent slots
for (int x = 0; x < MAX_RECENT_ROMS; x++)
{
char keyName[100];
sprintf(keyName,"Recent Rom %d",x);
if (x < (int)RecentRoms.size()) //If it exists in the array, save it
WritePrivateProfileString("General",keyName,RecentRoms[x].c_str(),IniName);
else //Else, make it empty
WritePrivateProfileString("General",keyName, "",IniName);
}
}
void ClearRecentRoms()
{
RecentRoms.clear();
SaveRecentRoms();
PopulateRecentRomsMenu();
}
void UpdateRecentRoms(const char* filename)
{
//This function assumes filename is a ROM filename that was successfully loaded
string newROM = filename; //Convert to std::string
//--------------------------------------------------------------
//Check to see if filename is in list
vector<string>::iterator x;
vector<string>::iterator theMatch;
bool match = false;
for (x = RecentRoms.begin(); x < RecentRoms.end(); ++x)
{
if (newROM == *x)
{
//We have a match
match = true; //Flag that we have a match
theMatch = x; //Hold on to the iterator (Note: the loop continues, so if for some reason we had a duplicate (which wouldn't happen under normal circumstances, it would pick the last one in the list)
}
}
//----------------------------------------------------------------
//If there was a match, remove it
if (match)
RecentRoms.erase(theMatch);
RecentRoms.insert(RecentRoms.begin(), newROM); //Add to the array
//If over the max, we have too many, so remove the last entry
if (RecentRoms.size() > MAX_RECENT_ROMS)
RecentRoms.pop_back();
//Debug
//for (int x = 0; x < RecentRoms.size(); x++)
// LOG("Recent ROM: %s\n",RecentRoms[x].c_str());
PopulateRecentRomsMenu();
SaveRecentRoms();
}
void InitRecentRoms()
{
recentromsmenu = LoadMenu(hAppInst, MAKEINTRESOURCE(RECENTROMS));
LoadRecentRoms();
PopulateRecentRomsMenu();
}

View File

@ -0,0 +1,43 @@
/* recentroms.h
Copyright (C) 2008-2009 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __RECENTROMS_H_
#define __RECENTROMS_H_
#include <vector>
#include <string>
#include "main.h"
static const unsigned int MAX_RECENT_ROMS = 10; //To change the recent rom max, simply change this number
static const unsigned int recentRoms_clearid = IDM_RECENT_RESERVED0; // ID for the Clear recent ROMs item
static const unsigned int recentRoms_baseid = IDM_RECENT_RESERVED1; //Base identifier for the recent ROMs items
extern std::vector<std::string> RecentRoms; //The list of recent ROM filenames
void UpdateRecentRoms(const char* filename);
void InitRecentRoms();
void OpenRecentROM(int listNum);
void ClearRecentRoms();
void RemoveRecentRom(const std::string& filename);
#endif __RECENTROMS_H_

View File

@ -23,6 +23,7 @@
#include "commctrl.h"
#include "resource.h"
#include "debug.h"
#include "main.h"
#include "../MMU.h"
#include "../gpu.h"

View File

@ -0,0 +1,74 @@
/* winutil.cpp
Copyright (C) 2008-2009 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "winutil.h"
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <windef.h>
char IniName[MAX_PATH];
void GetINIPath()
{
char vPath[MAX_PATH], *szPath;
/*if (*vPath)
szPath = vPath;
else
{*/
char *p;
ZeroMemory(vPath, sizeof(vPath));
GetModuleFileName(NULL, vPath, sizeof(vPath));
p = vPath + lstrlen(vPath);
while (p >= vPath && *p != '\\') p--;
if (++p >= vPath) *p = 0;
szPath = vPath;
//}
if (strlen(szPath) + strlen("\\desmume.ini") < MAX_PATH)
{
sprintf(IniName, "%s\\desmume.ini",szPath);
} else if (MAX_PATH> strlen(".\\desmume.ini")) {
sprintf(IniName, ".\\desmume.ini");
} else
{
memset(IniName,0,MAX_PATH) ;
}
}
void WritePrivateProfileBool(char* appname, char* keyname, bool val, char* file)
{
char temp[256] = "";
sprintf(temp, "%d", val?1:0);
WritePrivateProfileString(appname, keyname, temp, file);
}
bool GetPrivateProfileBool(const char* appname, const char* keyname, bool defval, const char* filename)
{
return GetPrivateProfileInt(appname,keyname,defval?1:0,filename) != 0;
}
void WritePrivateProfileInt(char* appname, char* keyname, int val, char* file)
{
char temp[256] = "";
sprintf(temp, "%d", val);
WritePrivateProfileString(appname, keyname, temp, file);
}

View File

@ -0,0 +1,32 @@
/* winutil.h
Copyright (C) 2008-2009 DeSmuME team
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __WINUTIL_H_
#define __WINUTIL_H_
#include <stdio.h>
#include <windows.h>
extern char IniName[MAX_PATH];
void GetINIPath();
#endif