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

193 lines
6.0 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"
2006-02-03 05:45:04 +00:00
#include "arch/Dialog/Dialog.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-02-26 04:31:43 +00:00
static LocalizedString STATS_XML_NOT_YET_CREATED ( "CSmpackageApp", "The file Stats.xml has not yet been created. It will be created once the game is run." );
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. */
2006-03-06 19:29:11 +00:00
LOG = new RageLog;
2002-02-12 06:55:04 +00:00
2004-02-27 22:48:17 +00:00
TCHAR szCurrentDirectory[MAX_PATH];
2006-09-18 23:28:10 +00:00
GetCurrentDirectory( ARRAYLEN(szCurrentDirectory), szCurrentDirectory );
if( CAN_INSTALL_PACKAGES && SMPackageUtil::IsValidInstallDir(szCurrentDirectory) )
2006-01-20 09:31:26 +00:00
{
2006-01-20 23:38:17 +00:00
SMPackageUtil::AddGameInstallDir( szCurrentDirectory ); // add this if it doesn't already exist
2006-02-28 21:51:21 +00:00
SMPackageUtil::SetDefaultInstallDir( szCurrentDirectory );
2006-01-20 09:31:26 +00:00
}
2002-01-28 21:24:17 +00:00
2006-03-13 09:14:54 +00:00
FILEMAN->Remount( "/", szCurrentDirectory );
2002-01-28 21:24:17 +00:00
2006-03-06 19:29:11 +00:00
LUA = new LuaManager;
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
RString sTheme = SpecialFiles::BASE_THEME_NAME;
{
RString sType = "Preferences";
GetFileContents( SpecialFiles::TYPE_TXT_FILE, sType, true );
IniFile ini;
if( ini.ReadFile(SpecialFiles::STATIC_INI_PATH) )
{
while( 1 )
{
if( ini.GetValue(sType, "Theme", sTheme) )
break;
if( ini.GetValue(sType, "Fallback", sType) )
continue;
break;
}
}
}
2006-01-06 23:34:41 +00:00
RString sLanguage;
2006-01-20 09:31:26 +00:00
bool bPseudoLocalize = false;
2006-01-24 07:26:27 +00:00
bool bShowLogOutput = false;
bool bLogToDisk = false;
2006-01-20 09:31:26 +00:00
{
IniFile ini;
if( ini.ReadFile(SpecialFiles::PREFERENCES_INI_PATH) )
{
ini.GetValue( "Options", "Theme", sTheme );
2006-01-24 07:26:27 +00:00
ini.GetValue( "Options", "Language", sLanguage );
ini.GetValue( "Options", "PseudoLocalize", bPseudoLocalize );
ini.GetValue( "Options", "ShowLogOutput", bShowLogOutput );
ini.GetValue( "Options", "LogToDisk", bLogToDisk );
}
2006-01-20 09:31:26 +00:00
}
THEME->SwitchThemeAndLanguage( sTheme, sLanguage, bPseudoLocalize );
2006-01-24 07:26:27 +00:00
LOG->SetShowLogOutput( bShowLogOutput );
LOG->SetLogToDisk( bLogToDisk );
LOG->SetInfoToDisk( true );
2002-01-28 21:24:17 +00:00
// check for --machine-profile-stats and launch Stats.xml
for( int i=0; i<argc; i++ )
{
CString sArg = argv[i];
if( sArg == "--machine-profile-stats" )
{
2006-02-26 05:00:45 +00:00
RString sOSFile = SpecialDirs::GetMyDocumentsDir() + PRODUCT_ID +"/Save/MachineProfile/Stats.xml";
HINSTANCE hinst = ::ShellExecute( NULL, "open", sOSFile, "", "", SW_SHOWNORMAL );
2006-02-26 04:31:43 +00:00
// See MSDN for an explanation of this return value
if( (int)hinst == SE_ERR_FNF )
Dialog::OK( STATS_XML_NOT_YET_CREATED );
else if( (int)hinst <= 32 )
2006-02-26 05:00:45 +00:00
Dialog::OK( ssprintf(FAILED_TO_OPEN.GetValue(),sOSFile.c_str(),GetLastErrorString().c_str()) );
2006-01-24 07:26:27 +00:00
exit(1); // better way to quit?
}
}
// check if there's a .smzip command line argument and install it
for( int i=0; i<argc; i++ )
{
RString sPath = argv[i];
TrimLeft( sPath );
TrimRight( sPath );
RString sPathLower = sPath;
sPathLower.MakeLower();
// test to see if this is a smzip file
2006-01-24 07:26:27 +00:00
if( sPathLower.Right(3).CompareNoCase("zip")==0 )
{
// We found a zip package. Prompt the user to install it!
CSMPackageInstallDlg dlg( sPath );
int nResponse = dlg.DoModal();
2006-01-24 07:26:27 +00:00
if( nResponse == IDCANCEL )
exit(1); // better way to exit?
}
}
{
MainMenuDlg dlg;
int nResponse = dlg.DoModal();
}
2002-01-28 21:24:17 +00:00
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.
*/