[Project64] Cleanup RomInformationClass.cpp

This commit is contained in:
zilmar 2015-12-24 06:49:23 +11:00
parent 6ffd1663ca
commit 50df137466
2 changed files with 131 additions and 133 deletions

View File

@ -10,149 +10,147 @@
****************************************************************************/ ****************************************************************************/
#include "stdafx.h" #include "stdafx.h"
RomInformation::RomInformation (const char * RomFile): RomInformation::RomInformation(const char * RomFile) :
m_DeleteRomInfo(true), m_DeleteRomInfo(true),
m_FileName(RomFile? RomFile : ""), m_FileName(RomFile ? RomFile : ""),
m_pRomInfo(NULL) m_pRomInfo(NULL)
{ {
if (m_FileName.length() == 0) { return; } if (m_FileName.length() == 0) { return; }
m_pRomInfo = new CN64Rom; m_pRomInfo = new CN64Rom;
if (!m_pRomInfo->LoadN64Image(m_FileName.c_str())) { if (!m_pRomInfo->LoadN64Image(m_FileName.c_str())) {
delete m_pRomInfo; delete m_pRomInfo;
m_pRomInfo = NULL; m_pRomInfo = NULL;
return; return;
} }
} }
RomInformation::RomInformation (CN64Rom * RomInfo) : RomInformation::RomInformation(CN64Rom * RomInfo) :
m_DeleteRomInfo(false), m_DeleteRomInfo(false),
m_FileName(RomInfo ? RomInfo->GetFileName().c_str() : ""), m_FileName(RomInfo ? RomInfo->GetFileName().c_str() : ""),
m_pRomInfo(RomInfo) m_pRomInfo(RomInfo)
{ {
} }
RomInformation::~RomInformation() RomInformation::~RomInformation()
{ {
if (m_DeleteRomInfo) if (m_DeleteRomInfo)
delete m_pRomInfo; delete m_pRomInfo;
} }
#include <windows.h> #include <windows.h>
void RomInformation::DisplayInformation(HWND hParent) const { void RomInformation::DisplayInformation(HWND hParent) const {
if (m_FileName.length() == 0) { return; } if (m_FileName.length() == 0) { return; }
DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Rom_Information), DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_Rom_Information),
(HWND)hParent, (DLGPROC)RomInfoProc, (DWORD)this); (HWND)hParent, (DLGPROC)RomInfoProc, (DWORD)this);
} }
DWORD CALLBACK RomInfoProc (HWND hDlg, DWORD uMsg, DWORD wParam, DWORD lParam) { DWORD CALLBACK RomInfoProc(HWND hDlg, DWORD uMsg, DWORD wParam, DWORD lParam) {
switch (uMsg) { switch (uMsg) {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
//record class for future usage //record class for future usage
SetProp(hDlg,"this",(RomInformation *)lParam); SetProp(hDlg, "this", (RomInformation *)lParam);
RomInformation * _this = (RomInformation *)lParam; RomInformation * _this = (RomInformation *)lParam;
LONG_PTR originalWndProc = GetWindowLongPtrW(hDlg, GWLP_WNDPROC);
SetWindowLongPtrW(hDlg, GWLP_WNDPROC, (LONG_PTR) DefWindowProcW);
SetWindowTextW(hDlg, GS(INFO_TITLE));
SetWindowLongPtrW(hDlg, GWLP_WNDPROC, originalWndProc);
SetDlgItemTextW(hDlg, IDC_ROM_NAME, GS(INFO_ROM_NAME_TEXT)); LONG_PTR originalWndProc = GetWindowLongPtrW(hDlg, GWLP_WNDPROC);
SetDlgItemTextW(hDlg, IDC_FILE_NAME, GS(INFO_FILE_NAME_TEXT)); SetWindowLongPtrW(hDlg, GWLP_WNDPROC, (LONG_PTR)DefWindowProcW);
SetDlgItemTextW(hDlg, IDC_LOCATION, GS(INFO_LOCATION_TEXT)); SetWindowTextW(hDlg, GS(INFO_TITLE));
SetDlgItemTextW(hDlg, IDC_ROM_MD5, GS(INFO_MD5_TEXT)); SetWindowLongPtrW(hDlg, GWLP_WNDPROC, originalWndProc);
SetDlgItemTextW(hDlg, IDC_ROM_SIZE, GS(INFO_SIZE_TEXT));
SetDlgItemTextW(hDlg, IDC_CART_ID, GS(INFO_CART_ID_TEXT));
SetDlgItemTextW(hDlg, IDC_MANUFACTURER, GS(INFO_MANUFACTURER_TEXT));
SetDlgItemTextW(hDlg, IDC_COUNTRY, GS(INFO_COUNTRY_TEXT));
SetDlgItemTextW(hDlg, IDC_CRC1, GS(INFO_CRC1_TEXT));
SetDlgItemTextW(hDlg, IDC_CRC2, GS(INFO_CRC2_TEXT));
SetDlgItemTextW(hDlg, IDC_CIC_CHIP, GS(INFO_CIC_CHIP_TEXT));
SetDlgItemTextW(hDlg, IDC_CLOSE_BUTTON, GS(BOTTOM_CLOSE));
SetDlgItemTextW(hDlg, IDC_INFO_ROMNAME, _this->m_pRomInfo->GetRomName().ToUTF16(stdstr::CODEPAGE_932).c_str()); SetDlgItemTextW(hDlg, IDC_ROM_NAME, GS(INFO_ROM_NAME_TEXT));
SetDlgItemTextW(hDlg, IDC_FILE_NAME, GS(INFO_FILE_NAME_TEXT));
char path[_MAX_PATH], drive[_MAX_DRIVE],dir[_MAX_DIR], fname[_MAX_FNAME],ext[_MAX_EXT]; SetDlgItemTextW(hDlg, IDC_LOCATION, GS(INFO_LOCATION_TEXT));
_splitpath(_this->m_pRomInfo->GetFileName().c_str(), drive, dir, fname, ext); SetDlgItemTextW(hDlg, IDC_ROM_MD5, GS(INFO_MD5_TEXT));
_makepath(path, drive, dir, "", ""); SetDlgItemTextW(hDlg, IDC_ROM_SIZE, GS(INFO_SIZE_TEXT));
SetDlgItemTextW(hDlg, IDC_CART_ID, GS(INFO_CART_ID_TEXT));
SetDlgItemTextW(hDlg, IDC_MANUFACTURER, GS(INFO_MANUFACTURER_TEXT));
SetDlgItemTextW(hDlg, IDC_COUNTRY, GS(INFO_COUNTRY_TEXT));
SetDlgItemTextW(hDlg, IDC_CRC1, GS(INFO_CRC1_TEXT));
SetDlgItemTextW(hDlg, IDC_CRC2, GS(INFO_CRC2_TEXT));
SetDlgItemTextW(hDlg, IDC_CIC_CHIP, GS(INFO_CIC_CHIP_TEXT));
SetDlgItemTextW(hDlg, IDC_CLOSE_BUTTON, GS(BOTTOM_CLOSE));
SetDlgItemText(hDlg, IDC_INFO_FILENAME, stdstr_f("%s%s", fname, ext).c_str()); SetDlgItemTextW(hDlg, IDC_INFO_ROMNAME, _this->m_pRomInfo->GetRomName().ToUTF16(stdstr::CODEPAGE_932).c_str());
SetDlgItemText(hDlg, IDC_INFO_LOCATION, path);
SetDlgItemText(hDlg,IDC_INFO_MD5,_this->m_pRomInfo->GetRomMD5().c_str());
char String[255] = " "; char path[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT];
sprintf(&String[1],"%.1f MBit",(float)_this->m_pRomInfo->GetRomSize()/0x20000); _splitpath(_this->m_pRomInfo->GetFileName().c_str(), drive, dir, fname, ext);
SetDlgItemText(hDlg,IDC_INFO_ROMSIZE,String); _makepath(path, drive, dir, "", "");
BYTE * RomHeader = _this->m_pRomInfo->GetRomAddress(); SetDlgItemText(hDlg, IDC_INFO_FILENAME, stdstr_f("%s%s", fname, ext).c_str());
String[1] = RomHeader[0x3F]; SetDlgItemText(hDlg, IDC_INFO_LOCATION, path);
String[2] = RomHeader[0x3E];
String[3] = '\0';
SetDlgItemText(hDlg,IDC_INFO_CARTID,String);
switch (RomHeader[0x38]) {
case 'N': SetDlgItemText(hDlg,IDC_INFO_MANUFACTURER," Nintendo"); break;
case 0: SetDlgItemText(hDlg,IDC_INFO_MANUFACTURER," None"); break;
default: SetDlgItemText(hDlg,IDC_INFO_MANUFACTURER," (Unknown)"); break;
}
switch (RomHeader[0x3D]) { SetDlgItemText(hDlg, IDC_INFO_MD5, _this->m_pRomInfo->GetRomMD5().c_str());
case NTSC_BETA: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," Beta"); break;
case X_NTSC: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," NTSC"); break;
case Germany: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," Germany"); break;
case USA: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," America"); break;
case french: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," France"); break;
case Italian: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," Italy"); break;
case Japan: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," Japan"); break;
case Europe: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," Europe"); break;
case Spanish: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," Spain"); break;
case Australia: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," Australia"); break;
case X_PAL: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," PAL"); break;
case Y_PAL: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," PAL"); break;
case 0: SetDlgItemText(hDlg,IDC_INFO_COUNTRY," None"); break;
default:
sprintf(&String[1]," Unknown %c (%02X)",RomHeader[0x3D],RomHeader[0x3D]);
SetDlgItemText(hDlg,IDC_INFO_COUNTRY,String);
}
sprintf(&String[1],"0x%08X",*(DWORD *)(RomHeader + 0x10));
SetDlgItemText(hDlg,IDC_INFO_CRC1,String);
sprintf(&String[1],"0x%08X",*(DWORD *)(RomHeader + 0x14)); char String[255] = " ";
SetDlgItemText(hDlg,IDC_INFO_CRC2,String); sprintf(&String[1], "%.1f MBit", (float)_this->m_pRomInfo->GetRomSize() / 0x20000);
SetDlgItemText(hDlg, IDC_INFO_ROMSIZE, String);
if (_this->m_pRomInfo->CicChipID() == CIC_UNKNOWN) { BYTE * RomHeader = _this->m_pRomInfo->GetRomAddress();
sprintf(&String[1],"Unknown"); String[1] = RomHeader[0x3F];
} String[2] = RomHeader[0x3E];
else if (_this->m_pRomInfo->CicChipID() == CIC_NUS_8303) { String[3] = '\0';
sprintf(&String[1], "CIC-NUS-8303"); SetDlgItemText(hDlg, IDC_INFO_CARTID, String);
}
else if (_this->m_pRomInfo->CicChipID() == CIC_NUS_5167) {
sprintf(&String[1], "CIC-NUS-5167");
}
else {
sprintf(&String[1],"CIC-NUS-610%d",_this->m_pRomInfo->CicChipID());
}
SetDlgItemText(hDlg,IDC_INFO_CIC,String);
switch (RomHeader[0x38]) {
} case 'N': SetDlgItemText(hDlg, IDC_INFO_MANUFACTURER, " Nintendo"); break;
break; case 0: SetDlgItemText(hDlg, IDC_INFO_MANUFACTURER, " None"); break;
case WM_COMMAND: default: SetDlgItemText(hDlg, IDC_INFO_MANUFACTURER, " (Unknown)"); break;
switch (LOWORD(wParam)) { }
case IDCANCEL:
RemoveProp(hDlg,"this"); switch (RomHeader[0x3D]) {
EndDialog(hDlg,0); case NTSC_BETA: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " Beta"); break;
break; case X_NTSC: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " NTSC"); break;
case IDC_CLOSE_BUTTON: case Germany: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " Germany"); break;
RemoveProp(hDlg,"this"); case USA: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " America"); break;
EndDialog(hDlg,0); case french: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " France"); break;
break; case Italian: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " Italy"); break;
} case Japan: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " Japan"); break;
default: case Europe: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " Europe"); break;
return false; case Spanish: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " Spain"); break;
} case Australia: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " Australia"); break;
return true; case X_PAL: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " PAL"); break;
} case Y_PAL: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " PAL"); break;
case 0: SetDlgItemText(hDlg, IDC_INFO_COUNTRY, " None"); break;
default:
sprintf(&String[1], " Unknown %c (%02X)", RomHeader[0x3D], RomHeader[0x3D]);
SetDlgItemText(hDlg, IDC_INFO_COUNTRY, String);
}
sprintf(&String[1], "0x%08X", *(DWORD *)(RomHeader + 0x10));
SetDlgItemText(hDlg, IDC_INFO_CRC1, String);
sprintf(&String[1], "0x%08X", *(DWORD *)(RomHeader + 0x14));
SetDlgItemText(hDlg, IDC_INFO_CRC2, String);
if (_this->m_pRomInfo->CicChipID() == CIC_UNKNOWN) {
sprintf(&String[1], "Unknown");
}
else if (_this->m_pRomInfo->CicChipID() == CIC_NUS_8303) {
sprintf(&String[1], "CIC-NUS-8303");
}
else if (_this->m_pRomInfo->CicChipID() == CIC_NUS_5167) {
sprintf(&String[1], "CIC-NUS-5167");
}
else {
sprintf(&String[1], "CIC-NUS-610%d", _this->m_pRomInfo->CicChipID());
}
SetDlgItemText(hDlg, IDC_INFO_CIC, String);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCANCEL:
RemoveProp(hDlg, "this");
EndDialog(hDlg, 0);
break;
case IDC_CLOSE_BUTTON:
RemoveProp(hDlg, "this");
EndDialog(hDlg, 0);
break;
}
default:
return false;
}
return true;
}

View File

@ -10,18 +10,18 @@
****************************************************************************/ ****************************************************************************/
#pragma once #pragma once
class RomInformation class RomInformation
{ {
bool const m_DeleteRomInfo; bool const m_DeleteRomInfo;
stdstr const m_FileName; stdstr const m_FileName;
CN64Rom * m_pRomInfo; CN64Rom * m_pRomInfo;
friend DWORD CALLBACK RomInfoProc ( HWND, DWORD, DWORD, DWORD ); friend DWORD CALLBACK RomInfoProc(HWND, DWORD, DWORD, DWORD);
public: public:
RomInformation(const char* RomFile); RomInformation(const char* RomFile);
RomInformation(CN64Rom* RomInfo); RomInformation(CN64Rom* RomInfo);
~RomInformation(); ~RomInformation();
void DisplayInformation(HWND hParent) const; void DisplayInformation(HWND hParent) const;
}; };