Skip to content

Commit

Permalink
Merge pull request #538 from lioncash/savestate-dragdrop
Browse files Browse the repository at this point in the history
Fix dragging and dropping savestates in the render window
  • Loading branch information
lioncash committed Jun 30, 2014
2 parents 0332d4d + 3df00cd commit ada3e97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 23 additions & 3 deletions Source/Core/DolphinWX/Frame.cpp
Expand Up @@ -15,6 +15,7 @@
#endif

#include <cstddef>
#include <fstream>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -152,6 +153,7 @@ void CRenderFrame::OnDropFiles(wxDropFilesEvent& event)
return;

wxFileName file = event.GetFiles()[0];
const std::string filepath = WxStrToStr(file.GetFullPath());

if (file.GetExt() == "dtm")
{
Expand All @@ -165,19 +167,37 @@ void CRenderFrame::OnDropFiles(wxDropFilesEvent& event)
main_frame->GetMenuBar()->FindItem(IDM_RECORDREADONLY)->Check(true);
}

if (Movie::PlayInput(WxStrToStr(file.GetFullPath())))
if (Movie::PlayInput(filepath))
main_frame->BootGame("");
}
else if (!Core::IsRunning())
{
main_frame->BootGame(WxStrToStr(file.GetFullPath()));
main_frame->BootGame(filepath);
}
else if (IsValidSavestateDropped(filepath) && Core::IsRunning())
{
State::LoadAs(filepath);
}
else
{
DVDInterface::ChangeDisc(WxStrToStr(file.GetFullPath()));
DVDInterface::ChangeDisc(filepath);
}
}

bool CRenderFrame::IsValidSavestateDropped(const std::string& filepath)
{
const int game_id_length = 6;
std::ifstream file(filepath, std::ios::in | std::ios::binary);

if (!file)
return false;

std::string internal_game_id(game_id_length, ' ');
file.read(&internal_game_id[0], game_id_length);

return internal_game_id == SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID();
}

#ifdef _WIN32
WXLRESULT CRenderFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinWX/Frame.h
Expand Up @@ -80,6 +80,7 @@ class CRenderFrame : public wxFrame

private:
void OnDropFiles(wxDropFilesEvent& event);
static bool IsValidSavestateDropped(const std::string& filepath);
#ifdef _WIN32
// Receive WndProc messages
WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
Expand Down

0 comments on commit ada3e97

Please sign in to comment.