From 6e20e2540f0143b4dca7c183b006c47210cffecb Mon Sep 17 00:00:00 2001 From: jpd002 Date: Sat, 15 May 2010 21:58:26 +0000 Subject: [PATCH] PsfPlayer: Added ability to change character encoding interpretation of tags. git-svn-id: http://svn.purei.org/purei/trunk@651 b36208d7-6611-0410-8bec-b1987f11c4a2 --- tools/PsfPlayer/Source/AppDef.h | 4 +- tools/PsfPlayer/Source/PsfTags.cpp | 12 ++- tools/PsfPlayer/Source/PsfTags.h | 7 +- .../PsfPlayer/Source/win32_ui/MainWindow.cpp | 93 +++++++++++++++++++ tools/PsfPlayer/Source/win32_ui/MainWindow.h | 20 +++- tools/PsfPlayer/Source/win32_ui/Res.rc | 1 + tools/PsfPlayer/Source/win32_ui/resource.h | 3 +- 7 files changed, 127 insertions(+), 13 deletions(-) diff --git a/tools/PsfPlayer/Source/AppDef.h b/tools/PsfPlayer/Source/AppDef.h index 79ed78d7..a9fd5f99 100644 --- a/tools/PsfPlayer/Source/AppDef.h +++ b/tools/PsfPlayer/Source/AppDef.h @@ -4,7 +4,7 @@ //Don't put tabs here since it will screw up the installer package #define APP_NAME _T("PsfPlayer") -#define APP_VERSION (44) -#define APP_VERSIONSTR _T("0.44") +#define APP_VERSION (45) +#define APP_VERSIONSTR _T("0.45") #endif diff --git a/tools/PsfPlayer/Source/PsfTags.cpp b/tools/PsfPlayer/Source/PsfTags.cpp index 0f6d67aa..f865e96e 100644 --- a/tools/PsfPlayer/Source/PsfTags.cpp +++ b/tools/PsfPlayer/Source/PsfTags.cpp @@ -1,5 +1,6 @@ #include "PsfTags.h" #include "string_cast_sjis.h" +#include "string_cast_win1252.h" #include "Utf8.h" using namespace Framework; @@ -23,13 +24,13 @@ CPsfTags::~CPsfTags() void CPsfTags::Init() { - SetDefaultCharEncoding(SHIFT_JIS); - SetStringConverter(m_defaultEncoding); + SetDefaultCharEncoding(CE_WINDOWS_1252); } void CPsfTags::SetDefaultCharEncoding(const CHAR_ENCODING& encoding) { m_defaultEncoding = encoding; + SetStringConverter(m_defaultEncoding); } bool CPsfTags::HasTag(const char* tagName) const @@ -145,10 +146,13 @@ void CPsfTags::SetStringConverter(const CHAR_ENCODING& encoding) { switch(encoding) { - case SHIFT_JIS: + case CE_WINDOWS_1252: + m_stringConverter = string_cast_win1252; + break; + case CE_SHIFT_JIS: m_stringConverter = string_cast_sjis; break; - case UTF8: + case CE_UTF8: m_stringConverter = Utf8::ConvertFromSafe; break; default: diff --git a/tools/PsfPlayer/Source/PsfTags.h b/tools/PsfPlayer/Source/PsfTags.h index fce7944b..281fba9c 100644 --- a/tools/PsfPlayer/Source/PsfTags.h +++ b/tools/PsfPlayer/Source/PsfTags.h @@ -13,9 +13,10 @@ public: enum CHAR_ENCODING { - INVALID, - SHIFT_JIS, - UTF8, + CE_INVALID = 0, + CE_WINDOWS_1252 = 1, + CE_SHIFT_JIS = 2, + CE_UTF8 = 3, }; CPsfTags(); diff --git a/tools/PsfPlayer/Source/win32_ui/MainWindow.cpp b/tools/PsfPlayer/Source/win32_ui/MainWindow.cpp index f9986344..2a247a1b 100644 --- a/tools/PsfPlayer/Source/win32_ui/MainWindow.cpp +++ b/tools/PsfPlayer/Source/win32_ui/MainWindow.cpp @@ -20,6 +20,7 @@ #define WNDSTYLEEX (0) #define ID_FILE_AUDIOPLUGIN_PLUGIN_0 (0xBEEF) +#define ID_FILE_CHARENCODING_ENCODING_0 (0xCEEF) #define PLAYLIST_EXTENSION _T("psfpl") #define PLAYLIST_FILTER _T("PsfPlayer Playlists (*.") PLAYLIST_EXTENSION _T(")\0*.") PLAYLIST_EXTENSION _T("\0") @@ -30,6 +31,9 @@ #define PREF_SOUNDHANDLER_ID ("soundhandler.id") #define DEFAULT_SOUND_HANDLER_ID (1) +#define PREF_CHAR_ENCODING_ID ("charencoding.id") +#define DEFAULT_CHAR_ENCODING_ID (CPsfTags::CE_WINDOWS_1252) + CMainWindow::SOUNDHANDLER_INFO CMainWindow::m_handlerInfo[] = { { 1, _T("Win32 WaveOut"), _T("SH_WaveOut.dll") }, @@ -37,6 +41,14 @@ CMainWindow::SOUNDHANDLER_INFO CMainWindow::m_handlerInfo[] = { NULL, NULL, NULL }, }; +CMainWindow::CHARENCODING_INFO CMainWindow::m_charEncodingInfo[] = +{ + { CPsfTags::CE_WINDOWS_1252, _T("Windows 1252") }, + { CPsfTags::CE_SHIFT_JIS, _T("Shift-JIS") }, + { CPsfTags::CE_UTF8, _T("UTF-8") }, + { NULL, NULL }, +}; + using namespace Framework; using namespace std; @@ -45,6 +57,7 @@ m_virtualMachine(virtualMachine), m_ready(false), m_frames(0), m_selectedAudioPlugin(DEFAULT_SOUND_HANDLER_ID), +m_selectedCharEncoding(DEFAULT_CHAR_ENCODING_ID), m_ejectButton(NULL), m_pauseButton(NULL), m_repeatButton(NULL), @@ -60,7 +73,10 @@ m_trackLength(0), m_accel(CreateAccelerators()) { CAppConfig::GetInstance().RegisterPreferenceInteger(PREF_SOUNDHANDLER_ID, DEFAULT_SOUND_HANDLER_ID); + CAppConfig::GetInstance().RegisterPreferenceInteger(PREF_CHAR_ENCODING_ID, DEFAULT_CHAR_ENCODING_ID); + LoadAudioPluginPreferences(); + LoadCharEncodingPreferences(); for(unsigned int i = 0; i < MAX_PANELS; i++) { @@ -160,6 +176,10 @@ m_accel(CreateAccelerators()) CreateAudioPluginMenu(); UpdateAudioPluginMenu(); + + CreateCharEncodingMenu(); + UpdateCharEncodingMenu(); + UpdateClock(); UpdateTitle(); UpdateButtons(); @@ -296,6 +316,18 @@ long CMainWindow::OnCommand(unsigned short nID, unsigned short nCmd, HWND hContr case ID_FILE_AUDIOPLUGIN_PLUGIN_0 + 9: ChangeAudioPlugin(nID - ID_FILE_AUDIOPLUGIN_PLUGIN_0); break; + case ID_FILE_CHARENCODING_ENCODING_0 + 0: + case ID_FILE_CHARENCODING_ENCODING_0 + 1: + case ID_FILE_CHARENCODING_ENCODING_0 + 2: + case ID_FILE_CHARENCODING_ENCODING_0 + 3: + case ID_FILE_CHARENCODING_ENCODING_0 + 4: + case ID_FILE_CHARENCODING_ENCODING_0 + 5: + case ID_FILE_CHARENCODING_ENCODING_0 + 6: + case ID_FILE_CHARENCODING_ENCODING_0 + 7: + case ID_FILE_CHARENCODING_ENCODING_0 + 8: + case ID_FILE_CHARENCODING_ENCODING_0 + 9: + ChangeCharEncoding(nID - ID_FILE_CHARENCODING_ENCODING_0); + break; } } return TRUE; @@ -565,6 +597,66 @@ void CMainWindow::ChangeAudioPlugin(unsigned int pluginIdx) UpdateAudioPluginMenu(); } +void CMainWindow::CreateCharEncodingMenu() +{ + Win32::CMenuItem pluginSubMenu(CreatePopupMenu()); + + for(unsigned int i = 0; m_charEncodingInfo[i].name != NULL; i++) + { + tstring caption = m_charEncodingInfo[i].name; + InsertMenu(pluginSubMenu, i, MF_STRING, ID_FILE_CHARENCODING_ENCODING_0 + i, caption.c_str()); + } + + Win32::CMenuItem pluginMenu(Win32::CMenuItem::FindById(m_popupMenu, ID_FILE_CHARACTERENCODING)); + MENUITEMINFO ItemInfo; + memset(&ItemInfo, 0, sizeof(MENUITEMINFO)); + ItemInfo.cbSize = sizeof(MENUITEMINFO); + ItemInfo.fMask = MIIM_SUBMENU; + ItemInfo.hSubMenu = pluginSubMenu; + + SetMenuItemInfo(pluginMenu, ID_FILE_CHARACTERENCODING, FALSE, &ItemInfo); +} + +void CMainWindow::UpdateCharEncodingMenu() +{ + for(unsigned int i = 0; m_charEncodingInfo[i].name != NULL; i++) + { + Win32::CMenuItem pluginSubMenuEntry(Win32::CMenuItem::FindById(m_popupMenu, ID_FILE_CHARENCODING_ENCODING_0 + i)); + pluginSubMenuEntry.Check(m_charEncodingInfo[i].id == m_selectedCharEncoding); + } +} + +void CMainWindow::ChangeCharEncoding(unsigned int encodingIdx) +{ + CHARENCODING_INFO* encodingInfo = m_charEncodingInfo + encodingIdx; + m_selectedCharEncoding = encodingInfo->id; + CAppConfig::GetInstance().SetPreferenceInteger(PREF_CHAR_ENCODING_ID, m_selectedCharEncoding); + UpdateCharEncodingMenu(); +} + +void CMainWindow::LoadCharEncodingPreferences() +{ + int charEncodingId = CAppConfig::GetInstance().GetPreferenceInteger(PREF_CHAR_ENCODING_ID); + int charEncodingIdx = FindCharEncoding(charEncodingId); + if(charEncodingIdx == -1) + { + m_selectedCharEncoding = DEFAULT_CHAR_ENCODING_ID; + } + else + { + m_selectedCharEncoding = charEncodingId; + } +} + +int CMainWindow::FindCharEncoding(unsigned int encodingId) +{ + for(unsigned int i = 0; m_charEncodingInfo[i].name != NULL; i++) + { + if(m_charEncodingInfo[i].id == encodingId) return i; + } + return -1; +} + HACCEL CMainWindow::CreateAccelerators() { Win32::CAcceleratorTableGenerator tableGenerator; @@ -735,6 +827,7 @@ bool CMainWindow::PlayFile(const char* path) CPsfBase::TagMap tags; CPsfLoader::LoadPsf(m_virtualMachine, path, &tags); m_tags = CPsfTags(tags); + m_tags.SetDefaultCharEncoding(static_cast(m_selectedCharEncoding)); try { m_volumeAdjust = boost::lexical_cast(m_tags.GetTagValue("volume")); diff --git a/tools/PsfPlayer/Source/win32_ui/MainWindow.h b/tools/PsfPlayer/Source/win32_ui/MainWindow.h index a8ed0f87..c504758a 100644 --- a/tools/PsfPlayer/Source/win32_ui/MainWindow.h +++ b/tools/PsfPlayer/Source/win32_ui/MainWindow.h @@ -56,6 +56,12 @@ private: const TCHAR* dllName; }; + struct CHARENCODING_INFO + { + int id; + const TCHAR* name; + }; + CSoundHandler* CreateHandler(const TCHAR*); void OnNewFrame(); @@ -84,15 +90,21 @@ private: void UpdateTitle(); void UpdateButtons(); void UpdateRepeatButton(); - void CreateAudioPluginMenu(); - void UpdateAudioPluginMenu(); void Reset(); void ActivatePanel(unsigned int); + void CreateAudioPluginMenu(); + void UpdateAudioPluginMenu(); + void ChangeAudioPlugin(unsigned int); void LoadAudioPluginPreferences(); int FindAudioPlugin(unsigned int); - void ChangeAudioPlugin(unsigned int); + + void CreateCharEncodingMenu(); + void UpdateCharEncodingMenu(); + void ChangeCharEncoding(unsigned int); + void LoadCharEncodingPreferences(); + int FindCharEncoding(unsigned int); HACCEL CreateAccelerators(); @@ -133,9 +145,11 @@ private: uint64 m_fadePosition; float m_volumeAdjust; int m_selectedAudioPlugin; + int m_selectedCharEncoding; REPEAT_MODE m_repeatMode; static SOUNDHANDLER_INFO m_handlerInfo[]; + static CHARENCODING_INFO m_charEncodingInfo[]; }; #endif diff --git a/tools/PsfPlayer/Source/win32_ui/Res.rc b/tools/PsfPlayer/Source/win32_ui/Res.rc index dbefd941..62e8b42c 100644 --- a/tools/PsfPlayer/Source/win32_ui/Res.rc +++ b/tools/PsfPlayer/Source/win32_ui/Res.rc @@ -111,6 +111,7 @@ BEGIN POPUP "File" BEGIN MENUITEM "Audio Plugin", ID_FILE_AUDIOPLUGIN + MENUITEM "Character Encoding", ID_FILE_CHARACTERENCODING MENUITEM SEPARATOR MENUITEM "About", ID_FILE_ABOUT MENUITEM "Quit", ID_FILE_EXIT diff --git a/tools/PsfPlayer/Source/win32_ui/resource.h b/tools/PsfPlayer/Source/win32_ui/resource.h index f5a57f9c..8d0a023a 100644 --- a/tools/PsfPlayer/Source/win32_ui/resource.h +++ b/tools/PsfPlayer/Source/win32_ui/resource.h @@ -19,13 +19,14 @@ #define ID_FILE_QUIT 40010 #define ID_FILE_ABOUT 40015 #define ID_FILE_AUDIOPLUGIN 40016 +#define ID_FILE_CHARACTERENCODING 40020 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 107 -#define _APS_NEXT_COMMAND_VALUE 40020 +#define _APS_NEXT_COMMAND_VALUE 40021 #define _APS_NEXT_CONTROL_VALUE 1001 #define _APS_NEXT_SYMED_VALUE 101 #endif