2006-07-23 22:52:33 +00:00
|
|
|
#include <fstream>
|
2006-07-18 12:08:40 +00:00
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
#include <boost/lexical_cast.hpp>
|
2006-07-21 18:21:51 +00:00
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
2006-07-24 21:53:03 +00:00
|
|
|
#include <boost/bind.hpp>
|
2006-07-23 22:52:33 +00:00
|
|
|
#include "../saves/SaveExporter.h"
|
2006-07-18 12:08:40 +00:00
|
|
|
#include "SaveView.h"
|
2006-07-21 18:21:51 +00:00
|
|
|
#include "string_cast.h"
|
2006-07-18 12:08:40 +00:00
|
|
|
#include "win32/Static.h"
|
2006-07-23 22:52:33 +00:00
|
|
|
#include "win32/FileDialog.h"
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2007-02-20 21:16:34 +00:00
|
|
|
#define CLSNAME _T("CSaveView")
|
2006-07-18 12:08:40 +00:00
|
|
|
|
|
|
|
using namespace Framework;
|
|
|
|
using namespace boost;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
CSaveView::CSaveView(HWND hParent)
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
|
|
|
|
if(!DoesWindowClassExist(CLSNAME))
|
|
|
|
{
|
|
|
|
WNDCLASSEX wc;
|
|
|
|
memset(&wc, 0, sizeof(WNDCLASSEX));
|
|
|
|
wc.cbSize = sizeof(WNDCLASSEX);
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
2006-07-21 18:21:51 +00:00
|
|
|
wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_BTNFACE);
|
2006-07-18 12:08:40 +00:00
|
|
|
wc.hInstance = GetModuleHandle(NULL);
|
|
|
|
wc.lpszClassName = CLSNAME;
|
|
|
|
wc.lpfnWndProc = CWindow::WndProc;
|
|
|
|
wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
|
|
|
|
RegisterClassEx(&wc);
|
|
|
|
}
|
|
|
|
|
2007-02-20 21:16:34 +00:00
|
|
|
Create(NULL, CLSNAME, _T(""), WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD, &rc, hParent, NULL);
|
2006-07-18 12:08:40 +00:00
|
|
|
SetClassPtr();
|
|
|
|
|
|
|
|
GetClientRect(&rc);
|
|
|
|
|
2007-02-20 21:16:34 +00:00
|
|
|
m_pNameLine1 = new Win32::CEdit(m_hWnd, &rc, _T(""), ES_READONLY, 0);
|
|
|
|
m_pNameLine2 = new Win32::CEdit(m_hWnd, &rc, _T(""), ES_READONLY, 0);
|
|
|
|
m_pSize = new Win32::CEdit(m_hWnd, &rc, _T(""), ES_READONLY, 0);
|
|
|
|
m_pId = new Win32::CEdit(m_hWnd, &rc, _T(""), ES_READONLY, 0);
|
|
|
|
m_pLastModified = new Win32::CEdit(m_hWnd, &rc, _T(""), ES_READONLY, 0);
|
|
|
|
m_pOpenFolder = new Win32::CButton(_T("Open folder..."), m_hWnd, &rc);
|
|
|
|
m_pExport = new Win32::CButton(_T("Export..."), m_hWnd, &rc);
|
|
|
|
m_pDelete = new Win32::CButton(_T("Delete"), m_hWnd, &rc);
|
|
|
|
m_pNormalIcon = new Win32::CButton(_T("Normal Icon"), m_hWnd, &rc, BS_PUSHLIKE | BS_CHECKBOX);
|
|
|
|
m_pCopyingIcon = new Win32::CButton(_T("Copying Icon"), m_hWnd, &rc, BS_PUSHLIKE | BS_CHECKBOX);
|
|
|
|
m_pDeletingIcon = new Win32::CButton(_T("Deleting Icon"), m_hWnd, &rc, BS_PUSHLIKE | BS_CHECKBOX);
|
2006-07-22 17:41:19 +00:00
|
|
|
m_pIconViewWnd = new CIconViewWnd(m_hWnd, &rc);
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2006-07-24 21:53:03 +00:00
|
|
|
m_CommandSink.RegisterCallback(m_pOpenFolder->m_hWnd, bind(&CSaveView::OpenSaveFolder, this));
|
|
|
|
m_CommandSink.RegisterCallback(m_pNormalIcon->m_hWnd, bind(&CSaveView::SetIconType, this, ICON_NORMAL));
|
|
|
|
m_CommandSink.RegisterCallback(m_pCopyingIcon->m_hWnd, bind(&CSaveView::SetIconType, this, ICON_COPYING));
|
|
|
|
m_CommandSink.RegisterCallback(m_pDeletingIcon->m_hWnd, bind(&CSaveView::SetIconType, this, ICON_DELETING));
|
|
|
|
m_CommandSink.RegisterCallback(m_pExport->m_hWnd, bind(&CSaveView::Export, this));
|
|
|
|
m_CommandSink.RegisterCallback(m_pDelete->m_hWnd, bind(&CSaveView::Delete, this));
|
|
|
|
|
2006-07-18 12:08:40 +00:00
|
|
|
CHorizontalLayout* pSubLayout0;
|
2006-07-21 18:21:51 +00:00
|
|
|
{
|
|
|
|
pSubLayout0 = new CHorizontalLayout();
|
2007-03-03 19:24:42 +00:00
|
|
|
pSubLayout0->InsertObject(Win32::CLayoutWindow::CreateTextBoxBehavior(300, 23, m_pId));
|
|
|
|
pSubLayout0->InsertObject(Win32::CLayoutWindow::CreateButtonBehavior(100, 23, m_pOpenFolder));
|
2006-07-21 18:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CGridLayout* pSubLayout1;
|
|
|
|
{
|
|
|
|
pSubLayout1 = new CGridLayout(2, 5);
|
|
|
|
|
2007-03-03 19:24:42 +00:00
|
|
|
pSubLayout1->SetObject(0, 0, Win32::CLayoutWindow::CreateTextBoxBehavior(100, 23, new Win32::CStatic(m_hWnd, _T("Name:"))));
|
|
|
|
pSubLayout1->SetObject(0, 2, Win32::CLayoutWindow::CreateTextBoxBehavior(100, 23, new Win32::CStatic(m_hWnd, _T("Size:"))));
|
|
|
|
pSubLayout1->SetObject(0, 3, Win32::CLayoutWindow::CreateTextBoxBehavior(100, 23, new Win32::CStatic(m_hWnd, _T("Id:"))));
|
|
|
|
pSubLayout1->SetObject(0, 4, Win32::CLayoutWindow::CreateTextBoxBehavior(100, 23, new Win32::CStatic(m_hWnd, _T("Last Modified:"))));
|
2006-07-21 18:21:51 +00:00
|
|
|
|
2007-03-03 19:24:42 +00:00
|
|
|
pSubLayout1->SetObject(1, 0, Win32::CLayoutWindow::CreateTextBoxBehavior(300, 23, m_pNameLine1));
|
|
|
|
pSubLayout1->SetObject(1, 1, Win32::CLayoutWindow::CreateTextBoxBehavior(300, 23, m_pNameLine2));
|
|
|
|
pSubLayout1->SetObject(1, 2, Win32::CLayoutWindow::CreateTextBoxBehavior(300, 23, m_pSize));
|
2006-07-21 18:21:51 +00:00
|
|
|
pSubLayout1->SetObject(1, 3, pSubLayout0);
|
2007-03-03 19:24:42 +00:00
|
|
|
pSubLayout1->SetObject(1, 4, Win32::CLayoutWindow::CreateTextBoxBehavior(300, 23, m_pLastModified));
|
2006-07-21 18:21:51 +00:00
|
|
|
|
|
|
|
pSubLayout1->SetVerticalStretch(0);
|
|
|
|
}
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2006-07-21 18:21:51 +00:00
|
|
|
CHorizontalLayout* pSubLayout2;
|
|
|
|
{
|
|
|
|
pSubLayout2 = new CHorizontalLayout();
|
2007-03-03 19:24:42 +00:00
|
|
|
pSubLayout2->InsertObject(Win32::CLayoutWindow::CreateButtonBehavior(100, 23, m_pExport));
|
|
|
|
pSubLayout2->InsertObject(Win32::CLayoutWindow::CreateButtonBehavior(100, 23, m_pDelete));
|
2006-07-21 18:21:51 +00:00
|
|
|
pSubLayout2->SetVerticalStretch(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
CHorizontalLayout* pSubLayout3;
|
|
|
|
{
|
|
|
|
pSubLayout3 = new CHorizontalLayout();
|
2007-03-03 19:24:42 +00:00
|
|
|
pSubLayout3->InsertObject(new Win32::CLayoutWindow(50, 50, 1, 1, m_pIconViewWnd));
|
2006-07-21 18:21:51 +00:00
|
|
|
pSubLayout3->SetVerticalStretch(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
CHorizontalLayout* pSubLayout4;
|
|
|
|
{
|
|
|
|
pSubLayout4 = new CHorizontalLayout();
|
2007-03-03 19:24:42 +00:00
|
|
|
pSubLayout4->InsertObject(new Win32::CLayoutWindow(50, 23, 1, 0, m_pNormalIcon));
|
|
|
|
pSubLayout4->InsertObject(new Win32::CLayoutWindow(50, 23, 1, 0, m_pCopyingIcon));
|
|
|
|
pSubLayout4->InsertObject(new Win32::CLayoutWindow(50, 23, 1, 0, m_pDeletingIcon));
|
2006-07-21 18:21:51 +00:00
|
|
|
pSubLayout4->SetVerticalStretch(0);
|
|
|
|
}
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2006-07-22 17:41:19 +00:00
|
|
|
SetIconType(ICON_NORMAL);
|
2006-07-18 12:08:40 +00:00
|
|
|
|
2006-07-21 18:21:51 +00:00
|
|
|
m_pLayout = new CVerticalLayout();
|
|
|
|
m_pLayout->InsertObject(pSubLayout1);
|
|
|
|
m_pLayout->InsertObject(pSubLayout2);
|
|
|
|
m_pLayout->InsertObject(pSubLayout3);
|
|
|
|
m_pLayout->InsertObject(pSubLayout4);
|
2006-07-18 12:08:40 +00:00
|
|
|
|
|
|
|
RefreshLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
CSaveView::~CSaveView()
|
|
|
|
{
|
|
|
|
delete m_pLayout;
|
|
|
|
}
|
|
|
|
|
2006-07-19 19:56:16 +00:00
|
|
|
void CSaveView::SetSave(const CSave* pSave)
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
|
|
|
m_pSave = pSave;
|
|
|
|
|
|
|
|
if(m_pSave != NULL)
|
|
|
|
{
|
|
|
|
wstring sName(m_pSave->GetName());
|
|
|
|
|
|
|
|
m_pNameLine1->SetText(sName.substr(0, m_pSave->GetSecondLineStartPosition()).c_str());
|
|
|
|
m_pNameLine2->SetText(sName.substr(m_pSave->GetSecondLineStartPosition()).c_str());
|
2007-02-20 21:16:34 +00:00
|
|
|
m_pSize->SetText((lexical_cast<tstring>(m_pSave->GetSize()) + _T(" bytes")).c_str());
|
|
|
|
m_pId->SetText(string_cast<tstring>(m_pSave->GetId()).c_str());
|
2006-07-21 18:21:51 +00:00
|
|
|
m_pLastModified->SetText(
|
2007-02-20 21:16:34 +00:00
|
|
|
string_cast<tstring>(
|
2006-07-21 18:21:51 +00:00
|
|
|
posix_time::to_simple_string(
|
|
|
|
posix_time::from_time_t(m_pSave->GetLastModificationTime()))).c_str());
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-20 21:16:34 +00:00
|
|
|
m_pNameLine1->SetText(_T("--"));
|
|
|
|
m_pNameLine2->SetText(_T(""));
|
|
|
|
m_pSize->SetText(_T("--"));
|
|
|
|
m_pId->SetText(_T("--"));
|
|
|
|
m_pLastModified->SetText(_T("--"));
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 17:41:19 +00:00
|
|
|
m_pIconViewWnd->SetSave(pSave);
|
2006-07-18 12:08:40 +00:00
|
|
|
m_pOpenFolder->Enable(m_pSave != NULL);
|
2006-07-22 17:41:19 +00:00
|
|
|
m_pNormalIcon->Enable(m_pSave != NULL);
|
|
|
|
m_pDeletingIcon->Enable(m_pSave != NULL);
|
|
|
|
m_pCopyingIcon->Enable(m_pSave != NULL);
|
2006-07-24 21:53:03 +00:00
|
|
|
m_pExport->Enable(m_pSave != NULL);
|
|
|
|
m_pDelete->Enable(m_pSave != NULL);
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long CSaveView::OnSize(unsigned int nX, unsigned int nY, unsigned int nType)
|
|
|
|
{
|
|
|
|
RefreshLayout();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
long CSaveView::OnCommand(unsigned short nCmd, unsigned short nId, HWND hWndFrom)
|
|
|
|
{
|
2006-07-24 21:53:03 +00:00
|
|
|
return m_CommandSink.OnCommand(nCmd, nId, hWndFrom);
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSaveView::RefreshLayout()
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
|
|
|
|
GetClientRect(&rc);
|
|
|
|
|
|
|
|
SetRect(&rc, rc.left + 10, rc.top + 10, rc.right - 10, rc.bottom - 10);
|
|
|
|
|
|
|
|
m_pLayout->SetRect(rc.left, rc.top, rc.right, rc.bottom);
|
|
|
|
m_pLayout->RefreshGeometry();
|
|
|
|
|
|
|
|
Redraw();
|
|
|
|
}
|
|
|
|
|
2006-07-24 21:53:03 +00:00
|
|
|
long CSaveView::SetIconType(ICONTYPE nIconType)
|
2006-07-22 17:41:19 +00:00
|
|
|
{
|
|
|
|
m_nIconType = nIconType;
|
|
|
|
|
|
|
|
m_pIconViewWnd->SetIconType(nIconType);
|
|
|
|
|
|
|
|
m_pNormalIcon->SetCheck(m_nIconType == ICON_NORMAL);
|
|
|
|
m_pDeletingIcon->SetCheck(m_nIconType == ICON_DELETING);
|
|
|
|
m_pCopyingIcon->SetCheck(m_nIconType == ICON_COPYING);
|
2006-07-24 21:53:03 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2006-07-22 17:41:19 +00:00
|
|
|
}
|
|
|
|
|
2006-07-24 21:53:03 +00:00
|
|
|
long CSaveView::OpenSaveFolder()
|
2006-07-18 12:08:40 +00:00
|
|
|
{
|
2006-07-24 21:53:03 +00:00
|
|
|
if(m_pSave == NULL) return FALSE;
|
2006-07-18 12:08:40 +00:00
|
|
|
|
|
|
|
filesystem::path Path(filesystem::complete(m_pSave->GetPath()));
|
|
|
|
|
|
|
|
ShellExecuteA(m_hWnd, "open", Path.string().c_str(), NULL, NULL, SW_SHOW);
|
2006-07-24 21:53:03 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2006-07-18 12:08:40 +00:00
|
|
|
}
|
2006-07-23 22:52:33 +00:00
|
|
|
|
2006-07-24 21:53:03 +00:00
|
|
|
long CSaveView::Export()
|
2006-07-23 22:52:33 +00:00
|
|
|
{
|
2006-07-24 21:53:03 +00:00
|
|
|
if(m_pSave == NULL) return FALSE;
|
2006-07-23 22:52:33 +00:00
|
|
|
|
|
|
|
unsigned int nRet;
|
|
|
|
|
|
|
|
Win32::CFileDialog FileDialog;
|
2007-02-20 21:16:34 +00:00
|
|
|
FileDialog.m_OFN.lpstrFilter = _T("EMS Memory Adapter Save Dumps (*.psu)\0*.psu\0");
|
2006-07-23 22:52:33 +00:00
|
|
|
|
|
|
|
EnableWindow(GetParent(), FALSE);
|
|
|
|
nRet = FileDialog.Summon(m_hWnd);
|
|
|
|
EnableWindow(GetParent(), TRUE);
|
|
|
|
|
2006-07-24 21:53:03 +00:00
|
|
|
if(nRet == 0) return FALSE;
|
2006-07-23 22:52:33 +00:00
|
|
|
|
|
|
|
FILE* pStream;
|
2007-02-20 21:16:34 +00:00
|
|
|
pStream = _tfopen(FileDialog.m_sFile, _T("wb"));
|
2006-07-23 22:52:33 +00:00
|
|
|
|
|
|
|
if(pStream == NULL)
|
|
|
|
{
|
2007-02-20 21:16:34 +00:00
|
|
|
MessageBox(m_hWnd, _T("Couldn't open file for writing."), NULL, 16);
|
2006-07-24 21:53:03 +00:00
|
|
|
return FALSE;
|
2006-07-23 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ofstream Output(pStream);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
CSaveExporter::ExportPSU(Output, m_pSave->GetPath().string().c_str());
|
|
|
|
Output.close();
|
|
|
|
}
|
|
|
|
catch(const exception& Exception)
|
|
|
|
{
|
|
|
|
Output.close();
|
|
|
|
|
|
|
|
string sMessage;
|
|
|
|
sMessage = "Couldn't export save:\r\n\r\n";
|
|
|
|
sMessage += Exception.what();
|
|
|
|
MessageBoxA(m_hWnd, sMessage.c_str(), NULL, 16);
|
2006-07-24 21:53:03 +00:00
|
|
|
return FALSE;
|
2006-07-23 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2007-02-20 21:16:34 +00:00
|
|
|
MessageBox(m_hWnd, _T("Save exported successfully."), NULL, MB_ICONINFORMATION);
|
2006-07-24 21:53:03 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
long CSaveView::Delete()
|
|
|
|
{
|
|
|
|
if(m_pSave == NULL) return FALSE;
|
|
|
|
|
|
|
|
m_OnDeleteClicked.Notify(m_pSave);
|
|
|
|
|
|
|
|
return FALSE;
|
2006-07-23 22:52:33 +00:00
|
|
|
}
|