Merge pull request #265 from Sonicadvance1/GenerateMD5Sum
Add the ability to generate a file's MD5sum.
This commit is contained in:
commit
c549e2fca1
|
@ -15,6 +15,7 @@
|
|||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <polarssl/md5.h>
|
||||
#include <wx/arrstr.h>
|
||||
#include <wx/bitmap.h>
|
||||
#include <wx/button.h>
|
||||
|
@ -100,6 +101,7 @@ BEGIN_EVENT_TABLE(CISOProperties, wxDialog)
|
|||
EVT_CLOSE(CISOProperties::OnClose)
|
||||
EVT_BUTTON(wxID_OK, CISOProperties::OnCloseClick)
|
||||
EVT_BUTTON(ID_EDITCONFIG, CISOProperties::OnEditConfig)
|
||||
EVT_BUTTON(ID_MD5SUMCOMPUTE, CISOProperties::OnComputeMD5Sum)
|
||||
EVT_BUTTON(ID_SHOWDEFAULTCONFIG, CISOProperties::OnShowDefaultConfig)
|
||||
EVT_CHOICE(ID_EMUSTATE, CISOProperties::SetRefresh)
|
||||
EVT_CHOICE(ID_EMU_ISSUES, CISOProperties::SetRefresh)
|
||||
|
@ -526,6 +528,9 @@ void CISOProperties::CreateGUIControls(bool IsWad)
|
|||
m_Date = new wxTextCtrl(m_Information, ID_DATE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
|
||||
wxStaticText* const m_FSTText = new wxStaticText(m_Information, wxID_ANY, _("FST Size:"));
|
||||
m_FST = new wxTextCtrl(m_Information, ID_FST, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
|
||||
wxStaticText* const m_MD5SumText = new wxStaticText(m_Information, wxID_ANY, _("MD5 Checksum:"));
|
||||
m_MD5Sum = new wxTextCtrl(m_Information, ID_MD5SUM, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
|
||||
m_MD5SumCompute = new wxButton(m_Information, ID_MD5SUMCOMPUTE, _("Compute"));
|
||||
|
||||
wxStaticText* const m_LangText = new wxStaticText(m_Information, wxID_ANY, _("Show Language:"));
|
||||
arrayStringFor_Lang.Add(_("English"));
|
||||
|
@ -559,19 +564,25 @@ void CISOProperties::CreateGUIControls(bool IsWad)
|
|||
// ISO Details
|
||||
wxGridBagSizer* const sISODetails = new wxGridBagSizer(0, 0);
|
||||
sISODetails->Add(m_NameText, wxGBPosition(0, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
sISODetails->Add(m_Name, wxGBPosition(0, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_Name, wxGBPosition(0, 1), wxGBSpan(1, 2), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_GameIDText, wxGBPosition(1, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
sISODetails->Add(m_GameID, wxGBPosition(1, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_GameID, wxGBPosition(1, 1), wxGBSpan(1, 2), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_CountryText, wxGBPosition(2, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
sISODetails->Add(m_Country, wxGBPosition(2, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_Country, wxGBPosition(2, 1), wxGBSpan(1, 2), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_MakerIDText, wxGBPosition(3, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
sISODetails->Add(m_MakerID, wxGBPosition(3, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_MakerID, wxGBPosition(3, 1), wxGBSpan(1, 2), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_RevisionText, wxGBPosition(4, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
sISODetails->Add(m_Revision, wxGBPosition(4, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_Revision, wxGBPosition(4, 1), wxGBSpan(1, 2), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_DateText, wxGBPosition(5, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
sISODetails->Add(m_Date, wxGBPosition(5, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_Date, wxGBPosition(5, 1), wxGBSpan(1, 2), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_FSTText, wxGBPosition(6, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
sISODetails->Add(m_FST, wxGBPosition(6, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_FST, wxGBPosition(6, 1), wxGBSpan(1, 2), wxEXPAND|wxALL, 5);
|
||||
sISODetails->Add(m_MD5SumText, wxGBPosition(7, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
sISODetails->Add(m_MD5Sum, wxGBPosition(7, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
|
||||
wxSizer* sMD5SumButtonSizer = CreateButtonSizer(wxNO_DEFAULT);
|
||||
sMD5SumButtonSizer->Add(m_MD5SumCompute);
|
||||
sISODetails->Add(sMD5SumButtonSizer, wxGBPosition(7, 2), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
|
||||
|
||||
sISODetails->AddGrowableCol(1);
|
||||
wxStaticBoxSizer* const sbISODetails =
|
||||
new wxStaticBoxSizer(wxVERTICAL, m_Information, _("ISO Details"));
|
||||
|
@ -1192,6 +1203,50 @@ void CISOProperties::OnEditConfig(wxCommandEvent& WXUNUSED (event))
|
|||
LoadGameConfig();
|
||||
}
|
||||
|
||||
void CISOProperties::OnComputeMD5Sum(wxCommandEvent& WXUNUSED (event))
|
||||
{
|
||||
u8 output[16];
|
||||
std::string output_string;
|
||||
std::vector<u8> data(8 * 1024 * 1024);
|
||||
size_t read_offset = 0;
|
||||
md5_context ctx;
|
||||
|
||||
File::IOFile file(OpenGameListItem->GetFileName(), "rb");
|
||||
u64 game_size = file.GetSize();
|
||||
|
||||
wxProgressDialog progressDialog(
|
||||
_("Computing MD5 checksum"),
|
||||
_("Working..."),
|
||||
game_size,
|
||||
this,
|
||||
wxPD_APP_MODAL | wxPD_CAN_ABORT |
|
||||
wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME |
|
||||
wxPD_SMOOTH
|
||||
);
|
||||
|
||||
md5_starts(&ctx);
|
||||
|
||||
while(read_offset < game_size)
|
||||
{
|
||||
if (!progressDialog.Update(read_offset, _("Computing MD5 checksum")))
|
||||
return;
|
||||
|
||||
size_t read_size;
|
||||
file.ReadArray(&data[0], data.size(), &read_size);
|
||||
md5_update(&ctx, &data[0], read_size);
|
||||
|
||||
read_offset += read_size;
|
||||
}
|
||||
|
||||
md5_finish(&ctx, output);
|
||||
|
||||
// Convert to hex
|
||||
for (int a = 0; a < 16; ++a)
|
||||
output_string += StringFromFormat("%02x", output[a]);
|
||||
|
||||
m_MD5Sum->SetValue(output_string);
|
||||
}
|
||||
|
||||
void CISOProperties::OnShowDefaultConfig(wxCommandEvent& WXUNUSED (event))
|
||||
{
|
||||
LaunchExternalEditor(GameIniFileDefault);
|
||||
|
|
|
@ -95,6 +95,8 @@ private:
|
|||
wxTextCtrl *m_Revision;
|
||||
wxTextCtrl *m_Date;
|
||||
wxTextCtrl *m_FST;
|
||||
wxTextCtrl *m_MD5Sum;
|
||||
wxButton *m_MD5SumCompute;
|
||||
wxArrayString arrayStringFor_Lang;
|
||||
wxChoice *m_Lang;
|
||||
wxTextCtrl *m_ShortName;
|
||||
|
@ -154,6 +156,8 @@ private:
|
|||
ID_REVISION,
|
||||
ID_DATE,
|
||||
ID_FST,
|
||||
ID_MD5SUM,
|
||||
ID_MD5SUMCOMPUTE,
|
||||
ID_VERSION,
|
||||
ID_LANG,
|
||||
ID_SHORTNAME,
|
||||
|
@ -176,6 +180,7 @@ private:
|
|||
void OnClose(wxCloseEvent& event);
|
||||
void OnCloseClick(wxCommandEvent& event);
|
||||
void OnEditConfig(wxCommandEvent& event);
|
||||
void OnComputeMD5Sum(wxCommandEvent& event);
|
||||
void OnShowDefaultConfig(wxCommandEvent& event);
|
||||
void ListSelectionChanged(wxCommandEvent& event);
|
||||
void PatchButtonClicked(wxCommandEvent& event);
|
||||
|
|
Loading…
Reference in New Issue