2010-06-07 02:23:58 +00:00
|
|
|
#include "stdafx.h"
|
2008-09-18 03:15:49 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2012-09-28 20:07:45 +00:00
|
|
|
CNotification & Notify ( void )
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2012-11-17 00:58:31 +00:00
|
|
|
static CNotification g_Notify;
|
|
|
|
return g_Notify;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-09-23 09:00:51 +00:00
|
|
|
CNotification::CNotification() :
|
|
|
|
m_hWnd(NULL),
|
2013-01-03 08:51:00 +00:00
|
|
|
m_gfxPlugin(NULL),
|
2015-09-23 09:00:51 +00:00
|
|
|
m_NextMsg(0)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
_tzset();
|
|
|
|
}
|
|
|
|
|
2013-01-03 08:51:00 +00:00
|
|
|
void CNotification::SetMainWindow ( CMainGui * Gui )
|
|
|
|
{
|
|
|
|
m_hWnd = Gui;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
void CNotification::WindowMode ( void ) const
|
|
|
|
{
|
|
|
|
static bool InsideFunc = false;
|
|
|
|
if (InsideFunc)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
InsideFunc = true;
|
|
|
|
if (InFullScreen())
|
|
|
|
{
|
|
|
|
ChangeFullScreen();
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
Sleep(50);
|
|
|
|
if (ProcessGuiMessages())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InsideFunc = false;
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::DisplayError ( const wchar_t * Message, ... ) const
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start( ap, Message );
|
|
|
|
DisplayError (Message,ap);
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::DisplayError ( const wchar_t * Message, va_list ap ) const
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
if (this == NULL) { return; }
|
2015-03-04 09:36:08 +00:00
|
|
|
wchar_t Msg[1000];
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
_vsnwprintf( Msg,sizeof(Msg) - 1,Message, ap );
|
2008-09-18 03:15:49 +00:00
|
|
|
va_end( ap );
|
2009-12-28 22:22:50 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
stdstr TraceMessage;
|
|
|
|
TraceMessage.FromUTF16(Msg);
|
|
|
|
WriteTrace(TraceError,TraceMessage.c_str());
|
2009-12-28 22:22:50 +00:00
|
|
|
WindowMode();
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
HWND Parent = NULL;
|
2015-03-04 09:36:08 +00:00
|
|
|
if (m_hWnd)
|
|
|
|
{
|
|
|
|
Parent = m_hWnd->GetHandle();
|
|
|
|
}
|
|
|
|
MessageBoxW(Parent,Msg,GS(MSG_MSGBOX_TITLE),MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::DisplayMessage ( int DisplayTime, const wchar_t * Message, ... ) const
|
2013-01-03 08:51:00 +00:00
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start( ap, Message );
|
|
|
|
DisplayMessage (DisplayTime, Message,ap);
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::DisplayMessage ( int DisplayTime, const wchar_t * Message, va_list ap ) const
|
2013-01-03 08:51:00 +00:00
|
|
|
{
|
|
|
|
if (!m_hWnd) { return; }
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (m_NextMsg > 0 || DisplayTime > 0)
|
|
|
|
{
|
|
|
|
time_t Now = time(NULL);
|
|
|
|
if (DisplayTime == 0 && Now < m_NextMsg)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (DisplayTime > 0)
|
|
|
|
{
|
|
|
|
m_NextMsg = Now + DisplayTime;
|
|
|
|
}
|
|
|
|
if (m_NextMsg == 0)
|
|
|
|
{
|
|
|
|
m_NextMsg = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
wchar_t Msg[1000];
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
_vsnwprintf( Msg,sizeof(Msg) - 1,Message, ap );
|
2008-09-18 03:15:49 +00:00
|
|
|
va_end( ap );
|
|
|
|
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
if (InFullScreen())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2013-01-03 08:51:00 +00:00
|
|
|
if (m_gfxPlugin && m_gfxPlugin->DrawStatus)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": DrawStatus - Starting");
|
2015-03-06 07:27:31 +00:00
|
|
|
stdstr PluginMessage;
|
|
|
|
PluginMessage.FromUTF16(Msg);
|
|
|
|
m_gfxPlugin->DrawStatus(PluginMessage.c_str(), FALSE);
|
2012-12-17 00:21:29 +00:00
|
|
|
WriteTrace(TraceGfxPlugin,__FUNCTION__ ": DrawStatus - Done");
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-14 19:55:11 +00:00
|
|
|
#if defined(WINDOWS_UI)
|
2015-03-06 07:27:31 +00:00
|
|
|
m_hWnd->SetStatusText(0, Msg);
|
2015-09-14 19:55:11 +00:00
|
|
|
#else
|
|
|
|
g_Notify -> BreakPoint(__FILEW__, __LINE__);
|
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::DisplayMessage2 ( const wchar_t * Message, ... ) const
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start( ap, Message );
|
|
|
|
DisplayMessage2 (Message,ap);
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::DisplayMessage2 ( const wchar_t * Message, va_list ap ) const
|
|
|
|
{
|
2013-01-03 08:51:00 +00:00
|
|
|
if (!m_hWnd) { return; }
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
wchar_t Msg[1000];
|
|
|
|
_vsnwprintf( Msg,sizeof(Msg) - 1 ,Message, ap );
|
2008-09-18 03:15:49 +00:00
|
|
|
va_end( ap );
|
2015-09-14 19:55:11 +00:00
|
|
|
|
|
|
|
#if defined(WINDOWS_UI)
|
2015-03-06 07:27:31 +00:00
|
|
|
m_hWnd->SetStatusText(1,Msg);
|
2015-09-14 19:55:11 +00:00
|
|
|
#else
|
|
|
|
g_Notify -> BreakPoint(__FILEW__, __LINE__);
|
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CNotification::SetGfxPlugin( CGfxPlugin * Plugin )
|
|
|
|
{
|
2013-01-03 08:51:00 +00:00
|
|
|
m_gfxPlugin = Plugin;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::SetWindowCaption (const wchar_t * Caption)
|
|
|
|
{
|
2015-04-16 19:49:48 +00:00
|
|
|
static const size_t TITLE_SIZE = 256;
|
|
|
|
wchar_t WinTitle[TITLE_SIZE];
|
2015-09-14 19:55:11 +00:00
|
|
|
|
2015-04-16 19:49:48 +00:00
|
|
|
_snwprintf(WinTitle, TITLE_SIZE, L"%s - %s", Caption, g_Settings->LoadString(Setting_ApplicationName).ToUTF16().c_str());
|
|
|
|
WinTitle[TITLE_SIZE - 1] = 0;
|
2015-09-14 19:55:11 +00:00
|
|
|
#if defined(WINDOWS_UI)
|
2013-01-03 08:51:00 +00:00
|
|
|
m_hWnd->Caption(WinTitle);
|
2015-09-14 19:55:11 +00:00
|
|
|
#else
|
|
|
|
g_Notify -> BreakPoint(__FILEW__, __LINE__);
|
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::FatalError ( const wchar_t * Message, ... ) const
|
|
|
|
{
|
|
|
|
wchar_t Msg[1000];
|
2008-09-18 03:15:49 +00:00
|
|
|
va_list ap;
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
WindowMode();
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
va_start( ap, Message );
|
2015-03-04 09:36:08 +00:00
|
|
|
_vsnwprintf( Msg,(sizeof(Msg) / sizeof(Msg[0])) - 1, Message, ap );
|
2008-09-18 03:15:49 +00:00
|
|
|
va_end( ap );
|
|
|
|
HWND Parent = NULL;
|
2013-01-03 08:51:00 +00:00
|
|
|
if (m_hWnd) { Parent = reinterpret_cast<HWND>(m_hWnd->GetHandle()); }
|
2015-03-04 09:36:08 +00:00
|
|
|
MessageBoxW(Parent,Msg,L"Error",MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
|
2008-09-18 03:15:49 +00:00
|
|
|
ExitThread(0);
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::AddRecentDir ( const char * RomDir )
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
//Validate the passed string
|
|
|
|
if (HIWORD(RomDir) == NULL) { return; }
|
|
|
|
|
|
|
|
//Get Information about the stored rom list
|
2012-11-17 01:02:04 +00:00
|
|
|
size_t MaxRememberedDirs = g_Settings->LoadDword(Directory_RecentGameDirCount);
|
2008-09-18 03:15:49 +00:00
|
|
|
strlist RecentDirs;
|
2010-09-22 21:43:42 +00:00
|
|
|
size_t i;
|
2008-09-18 03:15:49 +00:00
|
|
|
for (i = 0; i < MaxRememberedDirs; i ++ )
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr RecentDir = g_Settings->LoadStringIndex(Directory_RecentGameDirIndex,i);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (RecentDir.empty())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
RecentDirs.push_back(RecentDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
//See if the dir is already in the list if so then move it to the top of the list
|
|
|
|
strlist::iterator iter;
|
|
|
|
for (iter = RecentDirs.begin(); iter != RecentDirs.end(); iter++)
|
|
|
|
{
|
|
|
|
if (_stricmp(RomDir,iter->c_str()) != 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
RecentDirs.erase(iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
RecentDirs.push_front(RomDir);
|
|
|
|
if (RecentDirs.size() > MaxRememberedDirs)
|
|
|
|
{
|
|
|
|
RecentDirs.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, iter = RecentDirs.begin(); iter != RecentDirs.end(); iter++, i++)
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(Directory_RecentGameDirIndex,i,*iter);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::AddRecentRom ( const char * ImagePath )
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
if (HIWORD(ImagePath) == NULL) { return; }
|
|
|
|
|
|
|
|
//Get Information about the stored rom list
|
2012-11-17 01:02:04 +00:00
|
|
|
size_t MaxRememberedFiles = g_Settings->LoadDword(File_RecentGameFileCount);
|
2008-11-14 20:51:06 +00:00
|
|
|
strlist RecentGames;
|
2010-09-22 21:43:42 +00:00
|
|
|
size_t i;
|
2008-11-14 20:51:06 +00:00
|
|
|
for (i = 0; i < MaxRememberedFiles; i ++ )
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
stdstr RecentGame = g_Settings->LoadStringIndex(File_RecentGameFileIndex,i);
|
2008-11-14 20:51:06 +00:00
|
|
|
if (RecentGame.empty())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
RecentGames.push_back(RecentGame);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
//See if the dir is already in the list if so then move it to the top of the list
|
|
|
|
strlist::iterator iter;
|
|
|
|
for (iter = RecentGames.begin(); iter != RecentGames.end(); iter++)
|
|
|
|
{
|
|
|
|
if (_stricmp(ImagePath,iter->c_str()) != 0)
|
|
|
|
{
|
|
|
|
continue;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
RecentGames.erase(iter);
|
|
|
|
break;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
RecentGames.push_front(ImagePath);
|
|
|
|
if (RecentGames.size() > MaxRememberedFiles)
|
|
|
|
{
|
|
|
|
RecentGames.pop_back();
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
for (i = 0, iter = RecentGames.begin(); iter != RecentGames.end(); iter++, i++)
|
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
g_Settings->SaveStringIndex(File_RecentGameFileIndex,i,*iter);
|
2008-11-14 20:51:06 +00:00
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::RefreshMenu ( void )
|
|
|
|
{
|
2013-01-03 08:51:00 +00:00
|
|
|
if (m_hWnd == NULL) { return; }
|
2015-09-14 19:55:11 +00:00
|
|
|
|
|
|
|
#if defined(WINDOWS_UI)
|
2013-01-03 08:51:00 +00:00
|
|
|
m_hWnd->RefreshMenu();
|
2015-09-14 19:55:11 +00:00
|
|
|
#else
|
|
|
|
g_Notify -> BreakPoint(__FILEW__, __LINE__);
|
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::HideRomBrowser ( void )
|
|
|
|
{
|
2013-01-03 08:51:00 +00:00
|
|
|
if (m_hWnd == NULL) { return; }
|
|
|
|
m_hWnd->HideRomList();
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::ShowRomBrowser ( void )
|
|
|
|
{
|
2013-01-03 08:51:00 +00:00
|
|
|
if (m_hWnd == NULL) { return; }
|
2015-03-04 09:36:08 +00:00
|
|
|
if (g_Settings->LoadDword(RomBrowser_Enabled))
|
|
|
|
{
|
2008-09-18 03:15:49 +00:00
|
|
|
//Display the rom browser
|
2013-01-03 08:51:00 +00:00
|
|
|
m_hWnd->ShowRomList();
|
|
|
|
m_hWnd->HighLightLastRom();
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::BringToTop ( void )
|
|
|
|
{
|
2013-01-03 08:51:00 +00:00
|
|
|
if (m_hWnd == NULL) { return; }
|
2015-09-14 19:55:11 +00:00
|
|
|
|
|
|
|
#if defined(WINDOWS_UI)
|
2013-01-03 08:51:00 +00:00
|
|
|
m_hWnd->BringToTop();
|
2015-09-14 19:55:11 +00:00
|
|
|
#else
|
|
|
|
g_Notify -> BreakPoint(__FILEW__, __LINE__);
|
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 09:36:08 +00:00
|
|
|
void CNotification::MakeWindowOnTop ( bool OnTop )
|
|
|
|
{
|
2013-01-03 08:51:00 +00:00
|
|
|
if (m_hWnd == NULL) { return; }
|
2015-09-14 19:55:11 +00:00
|
|
|
|
|
|
|
#if defined(WINDOWS_UI)
|
2013-01-03 08:51:00 +00:00
|
|
|
m_hWnd->MakeWindowOnTop(OnTop);
|
2015-09-14 19:55:11 +00:00
|
|
|
#else
|
|
|
|
g_Notify -> BreakPoint(__FILEW__, __LINE__);
|
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
void CNotification::ChangeFullScreen ( void ) const
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2013-01-03 08:51:00 +00:00
|
|
|
if (m_hWnd == NULL) { return; }
|
|
|
|
SendMessage((HWND)(m_hWnd->GetHandle()),WM_COMMAND,MAKELPARAM(ID_OPTIONS_FULLSCREEN2,false),0);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
bool CNotification::ProcessGuiMessages ( void ) const
|
|
|
|
{
|
2013-01-03 08:51:00 +00:00
|
|
|
if (m_hWnd == NULL) { return false; }
|
2015-09-14 19:55:11 +00:00
|
|
|
|
|
|
|
#if defined(WINDOWS_UI)
|
2013-01-03 08:51:00 +00:00
|
|
|
return m_hWnd->ProcessGuiMessages();
|
2015-09-14 19:55:11 +00:00
|
|
|
#else
|
|
|
|
g_Notify -> BreakPoint(__FILEW__, __LINE__);
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 19:50:30 +00:00
|
|
|
void CNotification::BreakPoint ( const wchar_t * FileName, const int LineNumber )
|
2012-10-04 10:58:40 +00:00
|
|
|
{
|
2012-11-17 01:02:04 +00:00
|
|
|
if (g_Settings->LoadBool(Debugger_Enabled))
|
2012-10-04 10:58:40 +00:00
|
|
|
{
|
2015-03-11 19:50:30 +00:00
|
|
|
DisplayError(L"Break point found at\n%s\n%d",FileName, LineNumber);
|
2012-10-04 10:58:40 +00:00
|
|
|
if (IsDebuggerPresent() != 0)
|
|
|
|
{
|
|
|
|
DebugBreak();
|
2015-03-04 09:36:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-17 01:09:19 +00:00
|
|
|
g_BaseSystem->CloseCpu();
|
2012-10-04 10:58:40 +00:00
|
|
|
}
|
2015-03-04 09:36:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DisplayError(L"Fatal Error: Stopping emulation");
|
2012-11-17 01:09:19 +00:00
|
|
|
g_BaseSystem->CloseCpu();
|
2012-10-04 10:58:40 +00:00
|
|
|
}
|
2015-01-31 19:27:27 +00:00
|
|
|
}
|