2005-12-10 08:23:10 +00:00
|
|
|
#define CO_EXIST_WITH_MFC
|
|
|
|
|
#include "global.h"
|
2003-07-22 02:40:23 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "SMPackageUtil.h"
|
2005-12-10 08:23:10 +00:00
|
|
|
#include "archutils/Win32/RegistryAccess.h"
|
|
|
|
|
#include "ProductInfo.h"
|
|
|
|
|
#include "RageUtil.h"
|
2003-07-22 02:40:23 +00:00
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
void SMPackageUtil::WriteStepManiaInstallDirs( const vector<RString>& asInstallDirsToWrite )
|
2003-07-22 02:40:23 +00:00
|
|
|
{
|
2005-12-10 08:23:10 +00:00
|
|
|
RString sKey = "HKEY_LOCAL_MACHINE\\Software\\StepMania\\smpackage\\Installations";
|
2003-07-22 02:40:23 +00:00
|
|
|
|
2003-07-23 00:47:23 +00:00
|
|
|
unsigned i;
|
2003-07-22 02:40:23 +00:00
|
|
|
|
|
|
|
|
for( i=0; i<100; i++ )
|
|
|
|
|
{
|
2005-12-10 08:23:10 +00:00
|
|
|
RString sName = ssprintf("%d",i);
|
2003-07-22 02:40:23 +00:00
|
|
|
// Reg.DeleteKey( sName ); // delete key is broken in this library, so just write over it with ""
|
2005-12-10 08:23:10 +00:00
|
|
|
RegistryAccess::SetRegValue( sKey, sName, RString() );
|
2003-07-22 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-23 00:47:23 +00:00
|
|
|
for( i=0; i<asInstallDirsToWrite.size(); i++ )
|
2003-07-22 02:40:23 +00:00
|
|
|
{
|
2005-12-10 08:23:10 +00:00
|
|
|
RString sName = ssprintf("%d",i);
|
|
|
|
|
RegistryAccess::SetRegValue( sKey, sName, asInstallDirsToWrite[i] );
|
2003-07-22 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
void SMPackageUtil::GetStepManiaInstallDirs( vector<RString>& asInstallDirsOut )
|
2003-07-22 02:40:23 +00:00
|
|
|
{
|
2003-07-23 00:47:23 +00:00
|
|
|
asInstallDirsOut.clear();
|
2003-07-22 02:40:23 +00:00
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
RString sKey = "HKEY_LOCAL_MACHINE\\Software\\StepMania\\smpackage\\Installations";
|
2003-07-22 02:40:23 +00:00
|
|
|
|
|
|
|
|
for( int i=0; i<100; i++ )
|
|
|
|
|
{
|
2005-12-10 08:23:10 +00:00
|
|
|
RString sName = ssprintf("%d",i);
|
2003-07-22 02:40:23 +00:00
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
RString sPath;
|
|
|
|
|
if( !RegistryAccess::GetRegValue(sKey, sName, sPath) )
|
|
|
|
|
continue;
|
2003-07-22 02:40:23 +00:00
|
|
|
|
|
|
|
|
if( sPath == "" ) // read failed
|
|
|
|
|
continue; // skip
|
|
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
RString sProgramDir = sPath+"\\Program";
|
2005-10-17 08:15:52 +00:00
|
|
|
if( !DoesFileExist(sProgramDir) )
|
|
|
|
|
continue; // skip
|
|
|
|
|
|
2003-07-23 00:47:23 +00:00
|
|
|
asInstallDirsOut.push_back( sPath );
|
2003-07-22 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// while we're at it, write to clean up stale entries
|
|
|
|
|
WriteStepManiaInstallDirs( asInstallDirsOut );
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
void SMPackageUtil::AddStepManiaInstallDir( RString sNewInstallDir )
|
2003-07-22 02:40:23 +00:00
|
|
|
{
|
2005-12-10 08:23:10 +00:00
|
|
|
vector<RString> asInstallDirs;
|
2003-07-22 02:40:23 +00:00
|
|
|
GetStepManiaInstallDirs( asInstallDirs );
|
|
|
|
|
|
|
|
|
|
bool bAlreadyInList = false;
|
2003-07-23 00:47:23 +00:00
|
|
|
for( unsigned i=0; i<asInstallDirs.size(); i++ )
|
2003-07-22 02:40:23 +00:00
|
|
|
{
|
|
|
|
|
if( asInstallDirs[i].CompareNoCase(sNewInstallDir) == 0 )
|
|
|
|
|
{
|
|
|
|
|
bAlreadyInList = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !bAlreadyInList )
|
2003-07-23 00:47:23 +00:00
|
|
|
asInstallDirs.push_back( sNewInstallDir );
|
2003-07-22 02:40:23 +00:00
|
|
|
|
|
|
|
|
WriteStepManiaInstallDirs( asInstallDirs );
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
void SMPackageUtil::SetDefaultInstallDir( int iInstallDirIndex )
|
2005-10-17 08:15:52 +00:00
|
|
|
{
|
|
|
|
|
// move the specified index to the top of the list
|
2005-12-10 08:23:10 +00:00
|
|
|
vector<RString> asInstallDirs;
|
2005-10-17 08:15:52 +00:00
|
|
|
GetStepManiaInstallDirs( asInstallDirs );
|
2005-12-10 08:23:10 +00:00
|
|
|
ASSERT( iInstallDirIndex >= 0 && iInstallDirIndex < (int)asInstallDirs.size() );
|
|
|
|
|
RString sDefaultInstallDir = asInstallDirs[iInstallDirIndex];
|
2005-10-17 08:15:52 +00:00
|
|
|
asInstallDirs.erase( asInstallDirs.begin()+iInstallDirIndex );
|
|
|
|
|
asInstallDirs.insert( asInstallDirs.begin(), sDefaultInstallDir );
|
|
|
|
|
WriteStepManiaInstallDirs( asInstallDirs );
|
|
|
|
|
}
|
2003-07-22 02:40:23 +00:00
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
void SMPackageUtil::SetDefaultInstallDir( RString sInstallDir )
|
2005-10-21 07:42:52 +00:00
|
|
|
{
|
2005-12-10 08:23:10 +00:00
|
|
|
vector<RString> asInstallDirs;
|
2005-10-21 07:42:52 +00:00
|
|
|
GetStepManiaInstallDirs( asInstallDirs );
|
|
|
|
|
|
|
|
|
|
for( unsigned i=0; i<asInstallDirs.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
if( asInstallDirs[i].CompareNoCase(sInstallDir) == 0 )
|
|
|
|
|
{
|
|
|
|
|
SetDefaultInstallDir( i );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
bool SMPackageUtil::GetPref( RString name, bool &val )
|
2003-07-22 03:07:51 +00:00
|
|
|
{
|
2005-12-10 08:23:10 +00:00
|
|
|
return RegistryAccess::GetRegValue( "HKEY_LOCAL_MACHINE\\Software\\StepMania\\smpackage", name, val );
|
2003-07-22 03:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
bool SMPackageUtil::SetPref( RString name, bool val )
|
2003-07-22 03:07:51 +00:00
|
|
|
{
|
2005-12-10 08:23:10 +00:00
|
|
|
return RegistryAccess::SetRegValue( "HKEY_LOCAL_MACHINE\\Software\\StepMania\\smpackage", name, val );
|
2003-07-22 03:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-24 01:28:53 +00:00
|
|
|
/* Get a package directory. For most paths, this is the first two components. For
|
2004-03-26 01:48:47 +00:00
|
|
|
* songs and note skins, this is the first three. */
|
2005-12-10 08:23:10 +00:00
|
|
|
RString SMPackageUtil::GetPackageDirectory(RString path)
|
2003-07-24 01:28:53 +00:00
|
|
|
{
|
|
|
|
|
if( path.Find("CVS") != -1 )
|
|
|
|
|
return ""; // skip
|
|
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
vector<RString> Parts;
|
2003-07-24 01:28:53 +00:00
|
|
|
split( path, "\\", Parts );
|
|
|
|
|
|
|
|
|
|
unsigned NumParts = 2;
|
2004-03-26 01:48:47 +00:00
|
|
|
if( !Parts[0].CompareNoCase("Songs") || !Parts[0].CompareNoCase("NoteSkins") )
|
2003-07-24 01:28:53 +00:00
|
|
|
NumParts = 3;
|
|
|
|
|
if( Parts.size() < NumParts )
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
Parts.erase(Parts.begin() + NumParts, Parts.end());
|
|
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
RString ret = join( "\\", Parts );
|
2003-07-24 01:28:53 +00:00
|
|
|
if( !IsADirectory(ret) )
|
|
|
|
|
return "";
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
bool SMPackageUtil::IsValidPackageDirectory( RString path )
|
2003-07-24 01:28:53 +00:00
|
|
|
{
|
|
|
|
|
/* Make sure the path contains only second-level directories, and doesn't
|
|
|
|
|
* contain any ".", "..", "...", etc. dirs. */
|
2005-12-10 08:23:10 +00:00
|
|
|
vector<RString> Parts;
|
2003-07-24 01:28:53 +00:00
|
|
|
split( path, "\\", Parts, true );
|
|
|
|
|
if( Parts.size() == 0 )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* Make sure we're not going to "uninstall" an entire Songs subfolder. */
|
|
|
|
|
unsigned NumParts = 2;
|
|
|
|
|
if( !Parts[0].CompareNoCase("songs") )
|
|
|
|
|
NumParts = 3;
|
|
|
|
|
if( Parts.size() < NumParts )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* Make sure the path doesn't contain any ".", "..", "...", etc. dirs. */
|
|
|
|
|
for( unsigned i = 0; i < Parts.size(); ++i )
|
|
|
|
|
if( Parts[i][0] == '.' )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-07-22 03:07:51 +00:00
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
void SMPackageUtil::LaunchGame()
|
2005-11-28 05:24:09 +00:00
|
|
|
{
|
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
STARTUPINFO si;
|
|
|
|
|
ZeroMemory( &si, sizeof(si) );
|
|
|
|
|
|
2005-12-10 08:23:10 +00:00
|
|
|
RString sFile = PRODUCT_NAME ".exe";
|
2005-12-07 20:18:21 +00:00
|
|
|
if( !DoesFileExist(sFile) )
|
|
|
|
|
{
|
|
|
|
|
sFile = "Program\\" + sFile;
|
|
|
|
|
if( !DoesFileExist(sFile) )
|
|
|
|
|
{
|
|
|
|
|
MessageBox( NULL, "Error", "Could not find " PRODUCT_NAME ".exe", MB_ICONEXCLAMATION );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-28 05:24:09 +00:00
|
|
|
CreateProcess(
|
2005-12-07 20:18:21 +00:00
|
|
|
sFile, // pointer to name of executable module
|
|
|
|
|
NULL, // pointer to command line string
|
2005-11-28 05:24:09 +00:00
|
|
|
NULL, // process security attributes
|
|
|
|
|
NULL, // thread security attributes
|
|
|
|
|
false, // handle inheritance flag
|
|
|
|
|
0, // creation flags
|
|
|
|
|
NULL, // pointer to new environment block
|
|
|
|
|
NULL, // pointer to current directory name
|
|
|
|
|
&si, // pointer to STARTUPINFO
|
|
|
|
|
&pi // pointer to PROCESS_INFORMATION
|
|
|
|
|
);
|
|
|
|
|
}
|