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

176 lines
5.6 KiB
C++
Raw Normal View History

2005-12-10 08:23:10 +00:00
#define CO_EXIST_WITH_MFC
#include "global.h"
2002-01-28 21:24:17 +00:00
#include "stdafx.h"
#include "smpackage.h"
2003-02-06 23:15:21 +00:00
#include "smpackageExportDlg.h"
2002-01-28 21:24:17 +00:00
#include "smpackageInstallDlg.h"
#include "RageUtil.h"
#include "smpackageUtil.h"
#include "MainMenuDlg.h"
2005-12-10 08:23:10 +00:00
#include "RageFileManager.h"
2005-12-18 01:27:54 +00:00
#include "arch/arch.h"
2005-12-28 04:22:24 +00:00
#include "LuaManager.h"
2006-01-05 07:38:31 +00:00
#include "ThemeManager.h"
#include "SpecialFiles.h"
2006-01-06 23:34:41 +00:00
#include "IniFile.h"
2006-01-08 05:42:09 +00:00
#include "LocalizedString.h"
2002-01-28 21:24:17 +00:00
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CSmpackageApp, CWinApp)
//{{AFX_MSG_MAP(CSmpackageApp)
//}}AFX_MSG_MAP
2002-01-28 21:24:17 +00:00
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
CSmpackageApp::CSmpackageApp()
{
// Place all significant initialization in InitInstance
}
CSmpackageApp theApp;
2005-12-18 01:27:54 +00:00
#include "RageLog.h"
#include "RageFileManager.h"
2005-12-23 02:00:30 +00:00
#include "archutils/Win32/SpecialDirs.h"
#include "ProductInfo.h"
2006-01-20 09:31:26 +00:00
#include "archutils/Win32/CommandLine.h"
2005-12-23 02:00:30 +00:00
extern RString GetLastErrorString();
2002-01-28 21:24:17 +00:00
2006-01-08 05:42:09 +00:00
static LocalizedString FAILED_TO_OPEN ( "CSmpackageApp", "Failed to open '%s': %s" );
static LocalizedString THE_FILE_DOES_NOT_EXIST ( "CSmpackageApp", "The file '%s' does not exist. Aborting installation." );
2002-01-28 21:24:17 +00:00
BOOL CSmpackageApp::InitInstance()
{
2006-01-20 09:31:26 +00:00
char **argv;
int argc = GetWin32CmdLine( argv );
2005-12-28 04:22:24 +00:00
2005-12-18 01:27:54 +00:00
/* Almost everything uses this to read and write files. Load this early. */
2006-01-20 09:31:26 +00:00
FILEMAN = new RageFileManager( argv[0] );
2005-12-18 01:27:54 +00:00
FILEMAN->MountInitialFilesystems();
2002-02-12 06:55:04 +00:00
2005-12-18 01:27:54 +00:00
/* Set this up next. Do this early, since it's needed for RageException::Throw. */
LOG = new RageLog();
2002-02-12 06:55:04 +00:00
2004-02-27 22:48:17 +00:00
2005-12-18 01:27:54 +00:00
if( DoesFileExist("Songs") ) // this is a SM program directory
2006-01-20 09:31:26 +00:00
{
TCHAR szCurrentDirectory[MAX_PATH];
GetCurrentDirectory( ARRAYSIZE(szCurrentDirectory), szCurrentDirectory );
2006-01-20 23:38:17 +00:00
SMPackageUtil::AddGameInstallDir( szCurrentDirectory ); // add this if it doesn't already exist
2006-01-20 09:31:26 +00:00
}
2002-01-28 21:24:17 +00:00
// check if there's a .smzip command line argument
2005-12-10 08:23:10 +00:00
vector<RString> arrayCommandLineBits;
2005-12-23 02:00:30 +00:00
split( ::GetCommandLine(), " ", arrayCommandLineBits );
for( unsigned i=0; i<arrayCommandLineBits.size(); i++ )
{
CString sArg = arrayCommandLineBits[i];
if( sArg == "--machine-profile-stats" )
{
2005-12-29 02:40:09 +00:00
RString sPersonalDir = SpecialDirs::GetMyDocumentsDir();
2005-12-23 02:00:30 +00:00
RString sFile = sPersonalDir + PRODUCT_ID +"/Save/MachineProfile/Stats.xml";
if( NULL == ::ShellExecute( NULL, "open", sFile, "", "", SW_SHOWNORMAL ) )
2006-01-08 05:42:09 +00:00
AfxMessageBox( ssprintf(FAILED_TO_OPEN.GetValue(),sFile.c_str(),GetLastErrorString().c_str()) );
2005-12-23 02:00:30 +00:00
exit(0);
}
}
2002-01-28 21:24:17 +00:00
split( ::GetCommandLine(), "\"", arrayCommandLineBits );
for( unsigned i=0; i<arrayCommandLineBits.size(); i++ )
2002-01-28 21:24:17 +00:00
{
2005-12-10 08:23:10 +00:00
RString sPath = arrayCommandLineBits[i];
TrimLeft( sPath );
TrimRight( sPath );
RString sPathLower = sPath;
2002-01-28 21:24:17 +00:00
sPathLower.MakeLower();
// test to see if this is a smzip file
if( sPathLower.Right(3) == "zip" )
{
2005-12-10 08:23:10 +00:00
if( !FILEMAN->DoesFileExist(sPath) )
{
2006-01-08 05:42:09 +00:00
AfxMessageBox( ssprintf(THE_FILE_DOES_NOT_EXIST.GetValue(),sPath.c_str()), MB_ICONERROR );
exit(0);
}
2002-01-28 21:24:17 +00:00
// We found a zip package. Prompt the user to install it!
2005-12-10 08:23:10 +00:00
CSMPackageInstallDlg dlg( CString(sPath.c_str()) );
2002-01-28 21:24:17 +00:00
int nResponse = dlg.DoModal();
if( nResponse == IDOK )
{
CSmpackageExportDlg dlg;
int nResponse = dlg.DoModal();
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
2002-01-28 21:24:17 +00:00
}
else if (nResponse == IDCANCEL)
{
// the user cancelled. Don't fall through to the Manager.
2002-01-28 21:24:17 +00:00
exit(0);
}
}
}
2005-12-10 08:23:10 +00:00
FILEMAN = new RageFileManager( "" );
2005-12-28 04:22:24 +00:00
LUA = new LuaManager();
2006-01-05 07:38:31 +00:00
THEME = new ThemeManager();
2006-01-06 23:34:41 +00:00
// TODO: Use PrefsManager to get the current language instead? PrefsManager would
// need to be split up to reduce dependencies
IniFile ini;
RString sLanguage;
2006-01-20 09:31:26 +00:00
bool bPseudoLocalize = false;
if( ini.ReadFile(SpecialFiles::PREFERENCES_INI_PATH) )
{
ini.GetValue( "Preferences", "Language", sLanguage );
ini.GetValue( "PseudoLocalize", "Language", bPseudoLocalize );
}
2006-01-08 05:42:09 +00:00
THEME->SwitchThemeAndLanguage( SpecialFiles::BASE_THEME_NAME, sLanguage, bPseudoLocalize );
2005-12-10 08:23:10 +00:00
2002-01-28 21:24:17 +00:00
// Show the Manager Dialog
MainMenuDlg dlg;
2002-01-28 21:24:17 +00:00
int nResponse = dlg.DoModal();
// if (nResponse == IDOK)
2006-01-05 07:38:31 +00:00
SAFE_DELETE( THEME );
2005-12-28 04:22:24 +00:00
SAFE_DELETE( LUA );
2005-12-10 08:23:10 +00:00
SAFE_DELETE( FILEMAN );
2002-01-28 21:24:17 +00:00
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
2005-12-23 00:59:00 +00:00
/*
* (c) 2002-2005 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/