diff --git a/stepmania/src/ExportStrings.cpp b/stepmania/src/ExportStrings.cpp index 62b5ba719c..d913d739ba 100644 --- a/stepmania/src/ExportStrings.cpp +++ b/stepmania/src/ExportStrings.cpp @@ -9,9 +9,115 @@ #include "ProductInfo.h" #include "DateTime.h" #include "Foreach.h" +#include "arch/Dialog/Dialog.h" +#include "RageFileManager.h" +#include "SpecialFiles.h" const RString INSTALLER_LANGUAGES_DIR = "Themes/_Installer/Languages/"; +static const RString TEMP_MOUNT_POINT = "/@tempinstallpackage/"; + +static bool IsPackageFile( RString sFile ) +{ + RString sOsDir, sFilename, sExt; + splitpath( sFile, sOsDir, sFilename, sExt ); + + return sExt.EqualsNoCase(".smzip") || sExt.EqualsNoCase(".zip"); +} + +static void GetPackageFilesToInstall( vector &vs ) +{ + int argc; + char **argv; + GetCommandLineArguments( argc, argv ); + + for( int i = 1; i vs; + GetPackageFilesToInstall( vs ); + return !vs.empty(); +} + + +struct FileCopyResult +{ + FileCopyResult( RString _sFile, RString _sComment ) : sFile(_sFile), sComment(_sComment) {} + RString sFile, sComment; +}; + +void ExportStrings::Install() +{ + vector vSucceeded; + vector vFailed; + + vector vs; + GetPackageFilesToInstall( vs ); + FOREACH_CONST( RString, vs, s ) + { + if( !IsPackageFile(*s) ) + { + vFailed.push_back( FileCopyResult(*s,"wrong file extension") ); + continue; + } + + RString sOsDir, sFilename, sExt; + splitpath( *s, sOsDir, sFilename, sExt ); + + FILEMAN->Mount( "dir", sOsDir, TEMP_MOUNT_POINT ); + + // TODO: Validate that this zip contains files for this version of StepMania + + bool bFileExists = DoesFileExist( SpecialFiles::USER_PACKAGES_DIR + sFilename + sExt ); + if( FileCopy( TEMP_MOUNT_POINT + sFilename + sExt, SpecialFiles::USER_PACKAGES_DIR + sFilename + sExt ) ) + vSucceeded.push_back( FileCopyResult(*s,bFileExists ? "overwrote existing file" : "") ); + else + vFailed.push_back( FileCopyResult(*s,ssprintf("error copying file to '%s'",sOsDir.c_str())) ); + + FILEMAN->Unmount( "dir", sOsDir, TEMP_MOUNT_POINT ); + } + if( vSucceeded.empty() && vFailed.empty() ) + { + Dialog::OK( "Install: no files specified" ); + return; + } + + + RString sMessage; + for( int i=0; i<2; i++ ) + { + const vector &v = (i==0) ? vSucceeded : vFailed; + if( !v.empty() ) + { + sMessage += (i==0) ? "Install succeeded for:\n" : "Install failed for:\n"; + FOREACH_CONST( FileCopyResult, v, iter ) + { + sMessage += " - " + iter->sFile; + if( !iter->sComment.empty() ) + sMessage += " : " + iter->sComment; + sMessage += "\n"; + } + sMessage += "\n"; + } + } + Dialog::OK( sMessage ); +} + void ExportStrings::Nsis() { RageFile out; diff --git a/stepmania/src/ExportStrings.h b/stepmania/src/ExportStrings.h index 26710b4b82..b089eafcd8 100644 --- a/stepmania/src/ExportStrings.h +++ b/stepmania/src/ExportStrings.h @@ -3,6 +3,8 @@ namespace ExportStrings { + bool AnyPackageFilesInCommandLine(); + void Install(); void Nsis(); void LuaInformation(); } diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index 5d7c88abae..136436a753 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -896,6 +896,12 @@ void SetCommandlineArguments( int argc, char **argv ) g_argv = argv; } +void GetCommandLineArguments( int &argc, char **&argv ) +{ + argc = g_argc; + argv = g_argv; +} + /* * Search for the commandline argument given; eg. "test" searches for the * option "--test". All commandline arguments are getopt_long style: --foo; diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index 83b4fff6ca..2a42bef769 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -423,6 +423,7 @@ RString DwiEscape( const char *cUnescaped, int len ); RString GetCwd(); void SetCommandlineArguments( int argc, char **argv ); +void GetCommandLineArguments( int &argc, char **&argv ); bool GetCommandlineArgument( const RString &option, RString *argument=NULL, int iIndex=0 ); extern int g_argc; extern char **g_argv; diff --git a/stepmania/src/SpecialFiles.cpp b/stepmania/src/SpecialFiles.cpp index 10bb2d1a10..df80d4d930 100644 --- a/stepmania/src/SpecialFiles.cpp +++ b/stepmania/src/SpecialFiles.cpp @@ -1,6 +1,8 @@ #include "global.h" #include "SpecialFiles.h" +const RString SpecialFiles::USER_PACKAGES_DIR = "UserPackages/"; +const RString SpecialFiles::SYSTEM_PACKAGES_DIR = "SystemPackages/"; const RString SpecialFiles::KEYMAPS_PATH = "Save/Keymaps.ini"; const RString SpecialFiles::PREFERENCES_INI_PATH = "Save/Preferences.ini"; const RString SpecialFiles::THEMES_DIR = "Themes/"; diff --git a/stepmania/src/SpecialFiles.h b/stepmania/src/SpecialFiles.h index fc32553112..28f0e87bb5 100644 --- a/stepmania/src/SpecialFiles.h +++ b/stepmania/src/SpecialFiles.h @@ -5,6 +5,8 @@ namespace SpecialFiles { + extern const RString USER_PACKAGES_DIR; + extern const RString SYSTEM_PACKAGES_DIR; extern const RString KEYMAPS_PATH; extern const RString PREFERENCES_INI_PATH; extern const RString THEMES_DIR; diff --git a/stepmania/src/StepMania-net2008.vcproj b/stepmania/src/StepMania-net2008.vcproj index 6a63abc167..c40b7decda 100644 --- a/stepmania/src/StepMania-net2008.vcproj +++ b/stepmania/src/StepMania-net2008.vcproj @@ -2356,6 +2356,10 @@ RelativePath="archutils\Win32\RestartProgram.h" > + + @@ -6893,6 +6897,10 @@ RelativePath="archutils\Win32\DialogErrorHeader.bmp" > + + diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 172735fed9..7c01dd0cdc 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -70,6 +70,7 @@ #include "MessageManager.h" #include "StatsManager.h" #include "GameLoop.h" +#include "SpecialFiles.h" #if defined(XBOX) #include "Archutils/Xbox/VirtualMemory.h" @@ -79,8 +80,6 @@ #include #endif -#define ZIPS_DIR "Packages/" - static Preference g_bAllowMultipleInstances( "AllowMultipleInstances", false ); @@ -325,7 +324,7 @@ RString StepMania::GetInitialScreen() static Preference g_iLastSeenMemory( "LastSeenMemory", 0 ); #endif -static void CheckSettings() +static void AdjustForChangedSystemCapabilities() { #if defined(WIN32) /* Has the amount of memory changed? */ @@ -777,12 +776,15 @@ static void SwitchToLastPlayedGame() StepMania::ChangeCurrentGame( pGame ); } -static void ReadGamePrefsFromDisk() +void StepMania::ChangeCurrentGame( const Game* g ) { + ASSERT( g ); ASSERT( GAMESTATE ); ASSERT( ANNOUNCER ); ASSERT( THEME ); + GAMESTATE->SetCurGame( g ); + RString sAnnouncer = PREFSMAN->m_sAnnouncer; RString sTheme = PREFSMAN->m_sTheme; @@ -794,15 +796,7 @@ static void ReadGamePrefsFromDisk() // it's OK to call these functions with names that don't exist. ANNOUNCER->SwitchAnnouncer( sAnnouncer ); THEME->SwitchThemeAndLanguage( sTheme, PREFSMAN->m_sLanguage, PREFSMAN->m_bPseudoLocalize ); -} -void StepMania::ChangeCurrentGame( const Game* g ) -{ - ASSERT( g ); - - GAMESTATE->SetCurGame( g ); - - ReadGamePrefsFromDisk(); /* Set the input scheme for the new game, and load keymaps. */ if( INPUTMAPPER ) @@ -896,12 +890,29 @@ static void ApplyLogPreferences() static LocalizedString COULDNT_OPEN_LOADING_WINDOW( "StepMania", "Couldn't open any loading windows." ); int main(int argc, char* argv[]) -{ +{ RageThreadRegister thread( "Main thread" ); RageException::SetCleanupHandler( HandleException ); SetCommandlineArguments( argc, argv ); + + enum RunMode + { + RunMode_Normal, + RunMode_Install, + RunMode_ExportNsisStrings, + RunMode_ExportLuaInformation, + }; + RunMode runmode = RunMode_Normal; + if( ExportStrings::AnyPackageFilesInCommandLine() ) + runmode = RunMode_Install; + else if( GetCommandlineArgument("ExportNsisStrings") ) + runmode = RunMode_ExportNsisStrings; + else if( GetCommandlineArgument("ExportLuaInformation") ) + runmode = RunMode_ExportLuaInformation; + + /* Set up arch hooks first. This may set up crash handling. */ HOOKS = ArchHooks::Create(); HOOKS->Init(); @@ -913,7 +924,7 @@ int main(int argc, char* argv[]) FILEMAN->MountInitialFilesystems(); /* Set this up next. Do this early, since it's needed for RageException::Throw. */ - LOG = new RageLog; + LOG = new RageLog; /* Whew--we should be able to crash safely now! */ @@ -963,7 +974,7 @@ int main(int argc, char* argv[]) FILEMAN->Mount( "dir", dirs[i], "/AdditionalCourses" ); } - MountTreeOfZips( ZIPS_DIR ); + MountTreeOfZips( SpecialFiles::SYSTEM_PACKAGES_DIR ); /* One of the above filesystems might contain files that affect preferences, eg Data/Static.ini. * Re-read preferences. */ @@ -980,9 +991,17 @@ int main(int argc, char* argv[]) GAMESTATE = new GameState; /* This requires PREFSMAN, for PREFSMAN->m_bShowLoadingWindow. */ - LoadingWindow *pLoadingWindow = LoadingWindow::Create(); - if( pLoadingWindow == NULL ) - RageException::Throw( "%s", COULDNT_OPEN_LOADING_WINDOW.GetValue().c_str() ); + LoadingWindow *pLoadingWindow = NULL; + switch( runmode ) + { + case RunMode_Normal: + pLoadingWindow = LoadingWindow::Create(); + if( pLoadingWindow == NULL ) + RageException::Throw( "%s", COULDNT_OPEN_LOADING_WINDOW.GetValue().c_str() ); + break; + default: + ; // no loading window for other RunModes + } srand( time(NULL) ); // seed number generator @@ -996,7 +1015,7 @@ int main(int argc, char* argv[]) LOG->Info( "TLS is %savailable", RageThread::GetSupportsTLS()? "":"not " ); #endif - CheckSettings(); + AdjustForChangedSystemCapabilities(); THEME = new ThemeManager; ANNOUNCER = new AnnouncerManager; @@ -1005,6 +1024,35 @@ int main(int argc, char* argv[]) /* Switch to the last used game type, and set up the theme and announcer. */ SwitchToLastPlayedGame(); + + // Handle special RunModes. Some of these depend on ThemeManager being loaded above in SwitchToLastPlayedGame. + switch( runmode ) + { + DEFAULT_FAIL( runmode ); + case RunMode_Normal: + break; + case RunMode_Install: + case RunMode_ExportNsisStrings: + case RunMode_ExportLuaInformation: + THEME->SwitchThemeAndLanguage( "default", PREFSMAN->m_sLanguage, PREFSMAN->m_bPseudoLocalize ); + switch( runmode ) + { + DEFAULT_FAIL( runmode ); + case RunMode_Install: + ExportStrings::Install(); + break; + case RunMode_ExportNsisStrings: + ExportStrings::Nsis(); + break; + case RunMode_ExportLuaInformation: + ExportStrings::LuaInformation(); + break; + }; + exit(0); + } + + + { /* Now that THEME is loaded, load the icon for the current theme into the * loading window. */ @@ -1015,7 +1063,6 @@ int main(int argc, char* argv[]) delete pIcon; } - if( PREFSMAN->m_iSoundWriteAhead ) LOG->Info( "Sound writeahead has been overridden to %i", PREFSMAN->m_iSoundWriteAhead.Get() ); SOUNDMAN = new RageSoundManager; @@ -1036,8 +1083,7 @@ int main(int argc, char* argv[]) /* depends on SONGINDEX: */ SONGMAN = new SongManager; WORKOUTMAN = new WorkoutManager; - if( !GetCommandlineArgument("ExportNsisStrings") && !GetCommandlineArgument("ExportLuaInformation") ) - SONGMAN->InitAll( pLoadingWindow ); // this takes a long time + SONGMAN->InitAll( pLoadingWindow ); // this takes a long time CRYPTMAN = new CryptManager; // need to do this before ProfileMan if( PREFSMAN->m_bSignProfileData ) CRYPTMAN->GenerateGlobalKeys(); @@ -1103,14 +1149,8 @@ int main(int argc, char* argv[]) NSMAN->DisplayStartupStatus(); // If we're using networking show what happened /* Run the main loop. */ + GameLoop::RunGameLoop(); - if( GetCommandlineArgument("ExportNsisStrings") ) - ExportStrings::Nsis(); - else if( GetCommandlineArgument("ExportLuaInformation") ) - ExportStrings::LuaInformation(); - else - GameLoop::RunGameLoop(); - PREFSMAN->SavePrefsToDisk(); ShutdownGame(); diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 915274aca9..e4ac9148b7 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -1095,6 +1095,7 @@ RString ThemeManager::GetString( const RString &sMetricsGroup, const RString &sV sValueName.Replace( "\r\n", "\\n" ); sValueName.Replace( "\n", "\\n" ); + ASSERT( g_pLoadedThemeData ); RString s = GetMetricRaw( g_pLoadedThemeData->iniStrings, sMetricsGroup, sValueName ); FontCharAliases::ReplaceMarkers( s ); diff --git a/stepmania/src/archutils/Win32/WindowsResources.h b/stepmania/src/archutils/Win32/WindowsResources.h index 9471e34fd6..348f2ffdb0 100644 --- a/stepmania/src/archutils/Win32/WindowsResources.h +++ b/stepmania/src/archutils/Win32/WindowsResources.h @@ -45,13 +45,14 @@ #define IDC_STATIC_BOMBREASON 1284 #define IDC_STATIC_BOMBREASON2 1285 #define IDC_CALL_STACK 1310 +#define IDI_ICON1 1311 #define IDM_EXIT 40003 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 133 +#define _APS_NEXT_RESOURCE_VALUE 134 #define _APS_NEXT_COMMAND_VALUE 40009 #define _APS_NEXT_CONTROL_VALUE 1030 #define _APS_NEXT_SYMED_VALUE 101 diff --git a/stepmania/src/archutils/Win32/WindowsResources.rc b/stepmania/src/archutils/Win32/WindowsResources.rc index 82efdeeb85..1fa5c810f1 100644 --- a/stepmania/src/archutils/Win32/WindowsResources.rc +++ b/stepmania/src/archutils/Win32/WindowsResources.rc @@ -33,13 +33,11 @@ FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN CONTROL "",IDC_STATIC,"Static",SS_WHITERECT,0,0,332,35 DEFPUSHBUTTON "Close",IDOK,265,215,60,15 - EDITTEXT IDC_EDIT_ERROR,5,59,320,151,ES_MULTILINE | ES_READONLY | - WS_VSCROLL | NOT WS_TABSTOP + EDITTEXT IDC_EDIT_ERROR,5,59,320,151,ES_MULTILINE | ES_READONLY | WS_VSCROLL | NOT WS_TABSTOP PUSHBUTTON "View Log",IDC_BUTTON_VIEW_LOG,8,215,74,15 PUSHBUTTON "Report Error",IDC_BUTTON_REPORT,90,215,76,15 PUSHBUTTON "Restart Game",IDC_BUTTON_RESTART,175,215,80,15 - LTEXT "Specific details about the error are shown in the box below:", - IDC_STATIC,7,45,319,11 + LTEXT "Specific details about the error are shown in the box below:",IDC_STATIC,7,45,319,11 LTEXT "Fatal Error",IDC_STATIC_HEADER_TEXT,5,5,249,23 ICON IDI_ICON,IDC_STATIC_ICON,296,6,21,20 CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,34,332,1 @@ -49,12 +47,9 @@ IDD_LOADING_DIALOG DIALOG 0, 0, 312, 82 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_VISIBLE FONT 8, "MS Sans Serif" BEGIN - CTEXT "line1",IDC_STATIC_MESSAGE1,0,41,310,10,SS_NOPREFIX | - SS_CENTERIMAGE - CTEXT "line2",IDC_STATIC_MESSAGE2,0,54,310,10,SS_NOPREFIX | - SS_CENTERIMAGE - CTEXT "line3",IDC_STATIC_MESSAGE3,0,65,310,10,SS_NOPREFIX | - SS_CENTERIMAGE + CTEXT "line1",IDC_STATIC_MESSAGE1,0,41,310,10,SS_NOPREFIX | SS_CENTERIMAGE + CTEXT "line2",IDC_STATIC_MESSAGE2,0,54,310,10,SS_NOPREFIX | SS_CENTERIMAGE + CTEXT "line3",IDC_STATIC_MESSAGE3,0,65,310,10,SS_NOPREFIX | SS_CENTERIMAGE CONTROL "",IDC_SPLASH,"Static",SS_BITMAP,0,0,310,25 END @@ -67,8 +62,7 @@ BEGIN PUSHBUTTON "Report the &Error",IDC_BUTTON_REPORT,203,73,89,15 PUSHBUTTON "&Restart Game",IDC_BUTTON_RESTART,197,95,78,15 PUSHBUTTON "&Close",IDC_BUTTON_CLOSE,278,95,50,15 - LTEXT "A crash has occurred. Diagnostic information has been saved to a file called ""crashinfo.txt"" in the game program directory.", - IDC_STATIC,8,41,312,19 + LTEXT "A crash has occurred. Diagnostic information has been saved to a file called ""crashinfo.txt"" in the game program directory.",IDC_STATIC,8,41,312,19 CONTROL "",IDC_STATIC,"Static",SS_WHITERECT,0,0,332,35 LTEXT "Program Crash",IDC_STATIC_HEADER_TEXT,5,5,249,23 ICON IDI_ICON,IDC_STATIC_ICON,296,6,20,20 @@ -76,32 +70,25 @@ BEGIN END IDD_OK DIALOGEX 0, 0, 336, 98 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | - WS_CAPTION +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION CAPTION "Prompt" FONT 8, "MS Shell Dlg", 0, 0, 0x0 BEGIN DEFPUSHBUTTON "OK",IDOK,143,77,50,14 - CONTROL "&Don't display this message again",IDC_HUSH,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,63,181,10 - EDITTEXT IDC_MESSAGE,7,7,322,55,ES_CENTER | ES_MULTILINE | - ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | - WS_VSCROLL + CONTROL "&Don't display this message again",IDC_HUSH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,63,181,10 + EDITTEXT IDC_MESSAGE,7,7,322,55,ES_CENTER | ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL END IDD_REPORT_CRASH DIALOGEX 0, 0, 287, 98 -STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | DS_CENTERMOUSE | WS_POPUP | - WS_CAPTION +STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | DS_CENTERMOUSE | WS_POPUP | WS_CAPTION CAPTION "Program Crash" FONT 8, "MS Sans Serif", 0, 0, 0x0 BEGIN PUSHBUTTON "&Send Error Report",IDC_BUTTON_AUTO_REPORT,132,79,89,15 PUSHBUTTON "&View Error Report",IDC_CRASH_SAVE,6,79,86,15 - CONTROL "",IDC_PROGRESS,"msctls_progress32",NOT WS_VISIBLE | - WS_BORDER,132,79,89,15 + CONTROL "",IDC_PROGRESS,"msctls_progress32",NOT WS_VISIBLE | WS_BORDER,132,79,89,15 PUSHBUTTON "&Don't Send",IDC_BUTTON_CLOSE,224,79,59,15 - LTEXT "The program has encountered an error. Click Send Error Report to automatically report the problem and check for updates.", - IDC_MAIN_TEXT,13,48,263,18 + LTEXT "The program has encountered an error. Click Send Error Report to automatically report the problem and check for updates.",IDC_MAIN_TEXT,13,48,263,18 CONTROL "",IDC_STATIC,"Static",SS_WHITERECT,0,0,287,35 LTEXT "Program Crash",IDC_STATIC_HEADER_TEXT,5,5,249,23 ICON IDI_ICON,IDC_STATIC_ICON,259,6,21,20 @@ -184,6 +171,7 @@ END // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. +IDI_ICON1 ICON "smzip.ico" IDI_ICON ICON "StepMania.ICO" ///////////////////////////////////////////////////////////////////////////// diff --git a/stepmania/src/archutils/Win32/smzip.ico b/stepmania/src/archutils/Win32/smzip.ico new file mode 100644 index 0000000000..dbf0f7af40 Binary files /dev/null and b/stepmania/src/archutils/Win32/smzip.ico differ