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

251 lines
6.8 KiB
C++
Raw Normal View History

// MainMenuDlg.cpp : implementation file
//
2005-12-10 08:23:10 +00:00
#define CO_EXIST_WITH_MFC
#include "global.h"
#include "stdafx.h"
#include "smpackage.h"
#include "MainMenuDlg.h"
#include "EditInsallations.h"
#include "SmpackageExportDlg.h"
2005-09-24 20:36:25 +00:00
#include "ChangeGameSettings.h"
2005-09-27 09:57:13 +00:00
#include "RageUtil.h"
#include "SMPackageUtil.h"
2005-12-10 08:23:10 +00:00
#include "mainmenudlg.h"
#include "archutils/Win32/SpecialDirs.h"
#include "SpecialFiles.h"
#include "ProductInfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// MainMenuDlg dialog
MainMenuDlg::MainMenuDlg(CWnd* pParent /*=NULL*/)
: CDialog(MainMenuDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(MainMenuDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void MainMenuDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(MainMenuDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(MainMenuDlg, CDialog)
//{{AFX_MSG_MAP(MainMenuDlg)
ON_BN_CLICKED(IDC_EXPORT_PACKAGES, OnExportPackages)
ON_BN_CLICKED(IDC_EDIT_INSTALLATIONS, OnEditInstallations)
2005-09-27 09:57:13 +00:00
ON_BN_CLICKED(IDC_CREATE_SONG, OnCreateSong)
ON_BN_CLICKED(IDC_CLEAR_KEYMAPS, OnBnClickedClearKeymaps)
ON_BN_CLICKED(IDC_CHANGE_PREFERENCES, OnBnClickedChangePreferences)
ON_BN_CLICKED(IDC_OPEN_PREFERENCES, OnBnClickedOpenPreferences)
ON_BN_CLICKED(IDC_CLEAR_PREFERENCES, OnBnClickedClearPreferences)
//}}AFX_MSG_MAP
2005-11-28 05:24:09 +00:00
ON_BN_CLICKED(IDC_BUTTON_LAUNCH_GAME, OnBnClickedButtonLaunchGame)
2005-12-10 08:23:10 +00:00
ON_BN_CLICKED(IDC_VIEW_STATISTICS, OnBnClickedViewStatistics)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// MainMenuDlg message handlers
void MainMenuDlg::OnExportPackages()
{
// TODO: Add your control notification handler code here
CSmpackageExportDlg dlg;
int nResponse = dlg.DoModal();
// if (nResponse == IDOK)
}
void MainMenuDlg::OnEditInstallations()
{
// TODO: Add your control notification handler code here
EditInsallations dlg;
int nResponse = dlg.DoModal();
}
2005-12-10 08:23:10 +00:00
RString GetLastErrorString()
2005-09-27 09:57:13 +00:00
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Process any inserts in lpMsgBuf.
// ...
// Display the string.
2005-12-10 08:23:10 +00:00
RString s = (LPCTSTR)lpMsgBuf;
2005-09-27 09:57:13 +00:00
// Free the buffer.
LocalFree( lpMsgBuf );
return s;
}
void MainMenuDlg::OnCreateSong()
{
// TODO: Add your control notification handler code here
CFileDialog dialog (
TRUE, // file open?
NULL, // default file extension
NULL, // default file name
OFN_HIDEREADONLY | OFN_NOCHANGEDIR, // flags
"Music file (*.mp3;*.ogg)|*.mp3;*.ogg|||"
);
int iRet = dialog.DoModal();
2005-12-10 08:23:10 +00:00
RString sMusicFile = dialog.GetPathName();
2005-09-27 09:57:13 +00:00
if( iRet != IDOK )
return;
BOOL bSuccess;
2005-12-10 08:23:10 +00:00
RString sSongDirectory = "Songs\\My Creations\\";
bSuccess = CreateDirectory( sSongDirectory, NULL );
if( !bSuccess )
{
DWORD dwError = ::GetLastError();
switch( dwError )
{
case ERROR_ALREADY_EXISTS:
// This failure is ok. We probably created this directory already while importing another song.
break;
default:
MessageBox( "Failed to create directory '" + sSongDirectory + "': " + GetLastErrorString() );
return;
}
}
2005-12-10 08:23:10 +00:00
sSongDirectory += Basename( sMusicFile );
2005-09-27 09:57:13 +00:00
bSuccess = CreateDirectory( sSongDirectory, NULL ); // CreateDirectory doesn't like a trailing slash
if( !bSuccess )
{
MessageBox( "Failed to create song directory '" + sSongDirectory + "': " + GetLastErrorString() );
2005-09-27 09:57:13 +00:00
return;
}
sSongDirectory += "\\";
2005-12-10 08:23:10 +00:00
RString sNewMusicFile = sSongDirectory + Basename(sMusicFile);
2005-09-27 09:57:13 +00:00
bSuccess = CopyFile( sMusicFile, sNewMusicFile, TRUE );
if( !bSuccess )
{
MessageBox( "Failed to copy music file to '" + sNewMusicFile + "': " + GetLastErrorString() );
return;
}
// create a blank .sm file
2005-12-10 08:23:10 +00:00
RString sNewSongFile = sMusicFile;
SetExtension( sNewSongFile, "sm" );
2005-09-27 09:57:13 +00:00
FILE *fp = fopen( sNewSongFile, "w" );
if( fp == NULL )
{
MessageBox( "Failed to create the song file '" + sNewSongFile + "'" );
return;
}
fclose( fp );
MessageBox( "Success. Created the song '" + sSongDirectory + "'" );
}
BOOL MainMenuDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
TCHAR szCurDir[MAX_PATH];
GetCurrentDirectory( ARRAYSIZE(szCurDir), szCurDir );
GetDlgItem( IDC_EDIT_INSTALLATION )->SetWindowText( szCurDir );
2005-12-10 08:23:10 +00:00
SMPackageUtil::AddStepManiaInstallDir( szCurDir );
SMPackageUtil::SetDefaultInstallDir( szCurDir );
2005-09-27 09:57:13 +00:00
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
2005-09-28 17:51:16 +00:00
void MainMenuDlg::OnBnClickedClearKeymaps()
2005-09-28 17:51:16 +00:00
{
// TODO: Add your control notification handler code here
2005-12-10 08:23:10 +00:00
if( !DoesFileExist( SpecialFiles::KEYMAPS_PATH ) )
{
2005-12-10 08:23:10 +00:00
MessageBox( SpecialFiles::KEYMAPS_PATH + " is already cleared." );
}
else
{
2005-12-10 08:23:10 +00:00
if( !DeleteFile( SpecialFiles::KEYMAPS_PATH ) )
MessageBox( "Failed to delete file " + SpecialFiles::KEYMAPS_PATH + "." );
}
}
void MainMenuDlg::OnBnClickedChangePreferences()
{
// TODO: Add your control notification handler code here
ChangeGameSettings dlg;
int nResponse = dlg.DoModal();
}
void MainMenuDlg::OnBnClickedOpenPreferences()
{
// TODO: Add your control notification handler code here
2005-12-10 08:23:10 +00:00
if( !DoesFileExist( SpecialFiles::PREFERENCES_INI_PATH ) )
{
2005-12-10 08:23:10 +00:00
MessageBox( SpecialFiles::PREFERENCES_INI_PATH + " doesn't exist. It will be created next time you start the game." );
}
else
{
2005-12-10 08:23:10 +00:00
if( NULL == ::ShellExecute( this->m_hWnd, "open", SpecialFiles::PREFERENCES_INI_PATH, "", "", SW_SHOWNORMAL ) )
MessageBox( "Failed to open " + SpecialFiles::PREFERENCES_INI_PATH + ": " + GetLastErrorString() );
}
}
void MainMenuDlg::OnBnClickedClearPreferences()
{
// TODO: Add your control notification handler code here
2005-12-10 08:23:10 +00:00
if( !DoesFileExist( SpecialFiles::PREFERENCES_INI_PATH ) )
{
2005-12-10 08:23:10 +00:00
MessageBox( SpecialFiles::PREFERENCES_INI_PATH + " is already cleared." );
2005-11-24 10:45:41 +00:00
return;
}
2005-11-24 10:45:41 +00:00
2005-12-10 08:23:10 +00:00
if( !DeleteFile( SpecialFiles::PREFERENCES_INI_PATH ) )
{
2005-12-10 08:23:10 +00:00
MessageBox( "Failed to delete file " + SpecialFiles::PREFERENCES_INI_PATH + "." );
2005-11-24 10:45:41 +00:00
return;
}
2005-11-24 10:45:41 +00:00
2005-12-10 08:23:10 +00:00
MessageBox( SpecialFiles::PREFERENCES_INI_PATH + " cleared." );
2005-09-28 17:51:16 +00:00
}
2005-11-28 05:24:09 +00:00
void MainMenuDlg::OnBnClickedButtonLaunchGame()
{
// TODO: Add your control notification handler code here
2005-12-10 08:23:10 +00:00
SMPackageUtil::LaunchGame();
2005-11-28 05:24:09 +00:00
exit(0);
}
2005-12-10 08:23:10 +00:00
void MainMenuDlg::OnBnClickedViewStatistics()
{
// TODO: Add your control notification handler code here
RString sPersonalDir = GetMyDocumentsDir();
RString sFile = sPersonalDir + PRODUCT_ID +"/Save/MachineProfile/Stats.xml";
if( NULL == ::ShellExecute( this->m_hWnd, "open", sFile, "", "", SW_SHOWNORMAL ) )
MessageBox( "Failed to open '" + sFile + "': " + GetLastErrorString() );
}