Files
itgmania212121/stepmania/src/smpackage/SMPackageInstallDlg.cpp
T

254 lines
5.8 KiB
C++
Raw Normal View History

2002-01-28 21:24:17 +00:00
// SMPackageInstallDlg.cpp : implementation file
//
#include "stdafx.h"
#include "smpackage.h"
#include "SMPackageInstallDlg.h"
#include "RageUtil.h"
#include "smpackageUtil.h"
#include "EditInsallations.h"
2002-01-28 21:24:17 +00:00
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSMPackageInstallDlg dialog
CSMPackageInstallDlg::CSMPackageInstallDlg(CString sPackagePath, CWnd* pParent /*=NULL*/)
: CDialog(CSMPackageInstallDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSMPackageInstallDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_sPackagePath = sPackagePath;
}
void CSMPackageInstallDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSMPackageInstallDlg)
DDX_Control(pDX, IDC_BUTTON_EDIT, m_buttonEdit);
DDX_Control(pDX, IDC_COMBO_DIR, m_comboDir);
2002-01-28 21:24:17 +00:00
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSMPackageInstallDlg, CDialog)
//{{AFX_MSG_MAP(CSMPackageInstallDlg)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
2002-01-28 21:24:17 +00:00
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
2002-01-28 21:24:17 +00:00
/////////////////////////////////////////////////////////////////////////////
// CSMPackageInstallDlg message handlers
BOOL CSMPackageInstallDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
int i;
2002-02-24 10:31:20 +00:00
//
// Set the text of the first Edit box
//
CString sMessage1 = ssprintf(
2002-01-28 21:24:17 +00:00
"You have chosen to install the Stepmania package:\r\n"
2002-02-24 10:31:20 +00:00
"\r\n"
2002-01-28 21:24:17 +00:00
"\t%s\r\n"
"\r\n"
"This package contains the following files:\r\n",
m_sPackagePath
);
2002-02-24 10:31:20 +00:00
CEdit* pEdit1 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE1);
pEdit1->SetWindowText( sMessage1 );
2002-01-28 21:24:17 +00:00
2002-02-24 10:31:20 +00:00
//
// Set the text of the second Edit box
//
CString sMessage2;
2002-01-28 21:24:17 +00:00
try
{
2002-02-24 10:31:20 +00:00
m_zip.Open( m_sPackagePath, CZipArchive::zipOpenReadOnly );
2002-01-28 21:24:17 +00:00
}
catch (CException* e)
{
AfxMessageBox( ssprintf("'%s' is not a valid zip archive.", m_sPackagePath), MB_ICONSTOP );
e->Delete();
exit( 1 );
}
for( i=0; i<m_zip.GetCount(); i++ )
2002-01-28 21:24:17 +00:00
{
CZipFileHeader fh;
m_zip.GetFileInfo(fh, (WORD)i);
2002-02-24 10:31:20 +00:00
if( fh.IsDirectory() )
continue;
sMessage2 += ssprintf( "\t%s\r\n", fh.GetFileName() );
}
CEdit* pEdit2 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE2);
pEdit2->SetWindowText( sMessage2 );
//
// Set the text of the third Edit box
//
CString sMessage3 = "The package will be installed in the following Stepmania program folder:\r\n";
2002-01-28 21:24:17 +00:00
// Set the message
2002-02-24 10:31:20 +00:00
CEdit* pEdit3 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE3);
pEdit3->SetWindowText( sMessage3 );
2002-01-28 21:24:17 +00:00
RefreshInstallationList();
2002-01-28 21:24:17 +00:00
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSMPackageInstallDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
void CSMPackageInstallDlg::OnOK()
{
// TODO: Add extra validation here
m_comboDir.EnableWindow( FALSE );
m_buttonEdit.EnableWindow( FALSE );
2002-01-28 21:24:17 +00:00
CString sInstallDir;
m_comboDir.GetWindowText( sInstallDir );
2002-01-28 21:24:17 +00:00
// Unzip the SMzip package into the Stepmania installation folder
2002-02-24 10:31:20 +00:00
for( int i=0; i<m_zip.GetCount(); i++ )
2002-01-28 21:24:17 +00:00
{
2002-02-25 03:38:35 +00:00
// Throw some text up so the user has something to look at during the long pause.
CEdit* pEdit1 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE1);
pEdit1->SetWindowText( ssprintf("Installing '%s'. Please wait...", m_sPackagePath) );
CEdit* pEdit2 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE2);
pEdit2->SetWindowText( "" );
CEdit* pEdit3 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE3);
pEdit3->SetWindowText( "" );
SendMessage( WM_PAINT );
UpdateWindow(); // Force the silly thing to hadle WM_PAINT now!
2002-01-28 21:24:17 +00:00
retry_unzip:
2002-02-25 03:38:35 +00:00
// Extract the files
2002-01-28 21:24:17 +00:00
try
{
// skip extracting "thumbs.db" files
CZipFileHeader fhInfo;
if( m_zip.GetFileInfo(fhInfo, (WORD)i) )
{
CString sFileName = fhInfo.GetFileName();
sFileName.MakeLower();
if( sFileName.Find("thumbs.db") != -1 )
continue; // skip to next file
}
m_zip.ExtractFile( (WORD)i, sInstallDir, true ); // extract file to current directory
2002-01-28 21:24:17 +00:00
}
catch (CException* e)
{
char szError[4096];
e->GetErrorMessage( szError, sizeof(szError) );
2002-01-28 21:24:17 +00:00
e->Delete();
switch( MessageBox( szError, "Error Extracting File", MB_ABORTRETRYIGNORE|MB_ICONEXCLAMATION ) )
{
case IDABORT:
exit(1);
break;
case IDRETRY:
goto retry_unzip;
break;
case IDIGNORE:
// do nothing
break;
}
2002-01-28 21:24:17 +00:00
}
}
AfxMessageBox( "Package installed successfully!" );
// close the dialog
CDialog::OnOK();
}
void CSMPackageInstallDlg::OnButtonEdit()
{
// TODO: Add your control notification handler code here
EditInsallations dlg;
int nResponse = dlg.DoModal();
if( nResponse == IDOK )
{
WriteStepManiaInstallDirs( dlg.m_asReturnedInstallDirs );
RefreshInstallationList();
}
}
void CSMPackageInstallDlg::RefreshInstallationList()
{
m_comboDir.ResetContent();
CStringArray asInstallDirs;
GetStepManiaInstallDirs( asInstallDirs );
for( int i=0; i<asInstallDirs.GetSize(); i++ )
{
m_comboDir.AddString( asInstallDirs[i] );
}
m_comboDir.SetCurSel( 0 ); // guaranteed to be at least one item
}