sign all files in a profile
make RageFile filters for use with Crypt++
This commit is contained in:
+161
-48
@@ -1,67 +1,180 @@
|
||||
#include "sha.h"
|
||||
#include "global.h"
|
||||
#include "CryptHelpers.h"
|
||||
|
||||
// crypt headers
|
||||
#include "files.h"
|
||||
#include "hex.h"
|
||||
#include "channels.h"
|
||||
#include "rsa.h"
|
||||
#include "md5.h"
|
||||
#include "randpool.h"
|
||||
#include <memory>
|
||||
|
||||
using namespace CryptoPP;
|
||||
using namespace std;
|
||||
|
||||
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void RageFileStore::StoreInitialize(const NameValuePairs ¶meters)
|
||||
{
|
||||
RandomPool randPool;
|
||||
randPool.Put((byte *)seed, strlen(seed));
|
||||
|
||||
RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);
|
||||
HexEncoder privFile(new FileSink(privFilename));
|
||||
priv.DEREncode(privFile);
|
||||
privFile.MessageEnd();
|
||||
|
||||
RSAES_OAEP_SHA_Encryptor pub(priv);
|
||||
HexEncoder pubFile(new FileSink(pubFilename));
|
||||
pub.DEREncode(pubFile);
|
||||
pubFile.MessageEnd();
|
||||
const char *fileName;
|
||||
if (parameters.GetValue("InputFileName", fileName))
|
||||
{
|
||||
if( !m_file.Open(fileName, RageFile::READ) )
|
||||
throw OpenErr(fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(0);
|
||||
}
|
||||
m_waiting = false;
|
||||
}
|
||||
|
||||
void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename)
|
||||
unsigned long RageFileStore::MaxRetrievable() const
|
||||
{
|
||||
FileSource privFile(privFilename, true, new HexDecoder);
|
||||
RSASSA_PKCS1v15_SHA_Signer priv(privFile);
|
||||
RandomNumberGenerator &rng = RandomPool();
|
||||
FileSource f(messageFilename, true, new SignerFilter(rng, priv, new HexEncoder(new FileSink(signatureFilename))));
|
||||
if( !m_file.IsOpen() )
|
||||
return 0;
|
||||
|
||||
return m_file.GetFileSize() - m_file.Tell();
|
||||
}
|
||||
|
||||
bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename)
|
||||
unsigned int RageFileStore::TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel, bool blocking)
|
||||
{
|
||||
FileSource pubFile(pubFilename, true, new HexDecoder);
|
||||
RSASSA_PKCS1v15_SHA_Verifier pub(pubFile);
|
||||
if( !m_file.IsOpen() )
|
||||
{
|
||||
transferBytes = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
FileSource signatureFile(signatureFilename, true, new HexDecoder);
|
||||
if (signatureFile.MaxRetrievable() != pub.SignatureLength())
|
||||
return false;
|
||||
SecByteBlock signature(pub.SignatureLength());
|
||||
signatureFile.Get(signature, signature.size());
|
||||
unsigned long size=transferBytes;
|
||||
transferBytes = 0;
|
||||
|
||||
VerifierFilter *verifierFilter = new VerifierFilter(pub);
|
||||
verifierFilter->Put(signature, pub.SignatureLength());
|
||||
FileSource f(messageFilename, true, verifierFilter);
|
||||
if (m_waiting)
|
||||
goto output;
|
||||
|
||||
return verifierFilter->GetLastResult();
|
||||
while( size && !m_file.AtEOF() )
|
||||
{
|
||||
{
|
||||
unsigned int spaceSize = 1024;
|
||||
m_space = HelpCreatePutSpace(target, channel, 1, (unsigned int)STDMIN(size, (unsigned long)UINT_MAX), spaceSize);
|
||||
|
||||
m_len = m_file.Read( (char *)m_space, STDMIN(size, (unsigned long)spaceSize));
|
||||
}
|
||||
unsigned int blockedBytes;
|
||||
output:
|
||||
blockedBytes = target.ChannelPutModifiable2(channel, m_space, m_len, 0, blocking);
|
||||
m_waiting = blockedBytes > 0;
|
||||
if (m_waiting)
|
||||
return blockedBytes;
|
||||
size -= m_len;
|
||||
transferBytes += m_len;
|
||||
}
|
||||
|
||||
if (!m_file.AtEOF())
|
||||
throw ReadErr();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DigestFile(const char *filename)
|
||||
|
||||
unsigned int RageFileStore::CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end, const std::string &channel, bool blocking) const
|
||||
{
|
||||
MD5 md5;
|
||||
HashFilter md5Filter(md5);
|
||||
if( !m_file.IsOpen() )
|
||||
return 0;
|
||||
|
||||
auto_ptr<ChannelSwitch> channelSwitch(new ChannelSwitch);
|
||||
channelSwitch->AddDefaultRoute(md5Filter);
|
||||
FileSource(filename, true, channelSwitch.release());
|
||||
if (begin == 0 && end == 1)
|
||||
{
|
||||
int current = m_file.Tell();
|
||||
byte result;
|
||||
m_file.Read( &result, 1 );
|
||||
if (m_file.AtEOF()) // GCC workaround: 2.95.2 doesn't have char_traits<char>::eof()
|
||||
{
|
||||
m_file.Seek( current );
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int blockedBytes = target.ChannelPut(channel, byte(result), blocking);
|
||||
begin += 1-blockedBytes;
|
||||
m_file.Seek( current );
|
||||
return blockedBytes;
|
||||
}
|
||||
m_file.Seek( current );
|
||||
}
|
||||
|
||||
HexEncoder encoder(new FileSink(cout), false);
|
||||
cout << "\nMD5: ";
|
||||
md5Filter.TransferTo(encoder);
|
||||
// TODO: figure out what happens on cin
|
||||
int current = m_file.Tell();
|
||||
int endPosition = m_file.GetFileSize();
|
||||
m_file.Seek( endPosition );
|
||||
int newPosition = current + (streamoff)begin;
|
||||
|
||||
if (newPosition >= endPosition)
|
||||
{
|
||||
m_file.Seek(current);
|
||||
return 0; // don't try to seek beyond the end of file
|
||||
}
|
||||
m_file.Seek(newPosition);
|
||||
unsigned long total = 0;
|
||||
try
|
||||
{
|
||||
assert(!m_waiting);
|
||||
unsigned long copyMax = end-begin;
|
||||
unsigned int blockedBytes = const_cast<RageFileStore *>(this)->TransferTo2(target, copyMax, channel, blocking);
|
||||
begin += copyMax;
|
||||
if (blockedBytes)
|
||||
{
|
||||
const_cast<RageFileStore *>(this)->m_waiting = false;
|
||||
return blockedBytes;
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
m_file.ClearError();
|
||||
m_file.Seek(current);
|
||||
throw;
|
||||
}
|
||||
m_file.ClearError();
|
||||
m_file.Seek(current);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RageFileSink::IsolatedInitialize(const NameValuePairs ¶meters)
|
||||
{
|
||||
const char *fileName;
|
||||
if (parameters.GetValue("OutputFileName", fileName))
|
||||
{
|
||||
ios::openmode binary = parameters.GetValueWithDefault("OutputBinaryMode", true) ? ios::binary : ios::openmode(0);
|
||||
if( !m_file.Open( fileName, RageFile::WRITE ) ) // trucates existing data
|
||||
throw OpenErr(fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
bool RageFileSink::IsolatedFlush(bool hardFlush, bool blocking)
|
||||
{
|
||||
if (!m_file.IsOpen())
|
||||
throw Err("FileSink: output stream not opened");
|
||||
|
||||
m_file.Flush();
|
||||
if( !m_file.GetError().empty() )
|
||||
throw WriteErr();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int RageFileSink::Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking)
|
||||
{
|
||||
if (!m_file.IsOpen())
|
||||
throw Err("FileSink: output stream not opened");
|
||||
|
||||
m_file.Write((const char *)inString, length);
|
||||
|
||||
if (messageEnd)
|
||||
m_file.Flush();
|
||||
|
||||
if( !m_file.GetError().empty() )
|
||||
throw WriteErr();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,83 @@
|
||||
#ifndef CryptHelpers_H
|
||||
#define CryptHelpers_H
|
||||
|
||||
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed);
|
||||
void RSASignFile(const char *privFilename, const char *messageFilename, const char *signatureFilename);
|
||||
bool RSAVerifyFile(const char *pubFilename, const char *messageFilename, const char *signatureFilename);
|
||||
void DigestFile(const char *filename);
|
||||
#include "RageFile.h"
|
||||
|
||||
// crypt headers
|
||||
#include "files.h"
|
||||
#include "filters.h"
|
||||
#include "cryptlib.h"
|
||||
|
||||
using namespace CryptoPP;
|
||||
|
||||
//! .
|
||||
class RageFileStore : public Store, private FilterPutSpaceHelper
|
||||
{
|
||||
public:
|
||||
class Err : public Exception
|
||||
{
|
||||
public:
|
||||
Err(const std::string &s) : Exception(IO_ERROR, s) {}
|
||||
};
|
||||
class OpenErr : public Err {public: OpenErr(const std::string &filename) : Err("FileStore: error opening file for reading: " + filename) {}};
|
||||
class ReadErr : public Err {public: ReadErr() : Err("FileStore: error reading file") {}};
|
||||
|
||||
RageFileStore() {}
|
||||
RageFileStore(const char *filename)
|
||||
{StoreInitialize(MakeParameters("InputFileName", filename));}
|
||||
|
||||
unsigned long MaxRetrievable() const;
|
||||
unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true);
|
||||
unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const;
|
||||
|
||||
private:
|
||||
void StoreInitialize(const NameValuePairs ¶meters);
|
||||
|
||||
mutable RageFile m_file; // mutable so that we can call RageFile::GetFileSize()
|
||||
byte *m_space;
|
||||
unsigned int m_len;
|
||||
bool m_waiting;
|
||||
};
|
||||
|
||||
//! .
|
||||
class RageFileSource : public SourceTemplate<RageFileStore>
|
||||
{
|
||||
public:
|
||||
typedef FileStore::Err Err;
|
||||
typedef FileStore::OpenErr OpenErr;
|
||||
typedef FileStore::ReadErr ReadErr;
|
||||
|
||||
RageFileSource(BufferedTransformation *attachment = NULL)
|
||||
: SourceTemplate<RageFileStore>(attachment) {}
|
||||
RageFileSource(std::istream &in, bool pumpAll, BufferedTransformation *attachment = NULL)
|
||||
: SourceTemplate<RageFileStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputStreamPointer", &in));}
|
||||
RageFileSource(const char *filename, bool pumpAll, BufferedTransformation *attachment = NULL, bool binary=true)
|
||||
: SourceTemplate<RageFileStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputFileName", filename)("InputBinaryMode", binary));}
|
||||
};
|
||||
|
||||
|
||||
//! .
|
||||
class RageFileSink : public Sink
|
||||
{
|
||||
public:
|
||||
class Err : public Exception
|
||||
{
|
||||
public:
|
||||
Err(const std::string &s) : Exception(IO_ERROR, s) {}
|
||||
};
|
||||
class OpenErr : public Err {public: OpenErr(const std::string &filename) : Err("FileSink: error opening file for writing: " + filename) {}};
|
||||
class WriteErr : public Err {public: WriteErr() : Err("FileSink: error writing file") {}};
|
||||
|
||||
RageFileSink() {}
|
||||
RageFileSink(const char *filename, bool binary=true)
|
||||
{IsolatedInitialize(MakeParameters("OutputFileName", filename)("OutputBinaryMode", binary));}
|
||||
|
||||
void IsolatedInitialize(const NameValuePairs ¶meters);
|
||||
unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking);
|
||||
bool IsolatedFlush(bool hardFlush, bool blocking);
|
||||
|
||||
private:
|
||||
RageFile m_file;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "global.h"
|
||||
#include "CryptManager.h"
|
||||
#include "RageUtil.h"
|
||||
#include "CryptHelpers.h"
|
||||
|
||||
// crypt headers
|
||||
#include "sha.h"
|
||||
#include "hex.h"
|
||||
#include "channels.h"
|
||||
#include "rsa.h"
|
||||
#include "md5.h"
|
||||
#include "randpool.h"
|
||||
#include <memory>
|
||||
|
||||
using namespace CryptoPP;
|
||||
using namespace std;
|
||||
|
||||
static const CString SIGNATURE_POSPEND = ".sig.rsa";
|
||||
static const CString PRIVATE_KEY_PATH = "private.rsa";
|
||||
static const CString PUBLIC_KEY_PATH = "public.rsa";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void CryptManager::GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed)
|
||||
{
|
||||
RandomPool randPool;
|
||||
randPool.Put((byte *)seed, strlen(seed));
|
||||
|
||||
RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);
|
||||
HexEncoder privFile(new RageFileSink(privFilename));
|
||||
priv.DEREncode(privFile);
|
||||
privFile.MessageEnd();
|
||||
|
||||
RSAES_OAEP_SHA_Encryptor pub(priv);
|
||||
HexEncoder pubFile(new RageFileSink(pubFilename));
|
||||
pub.DEREncode(pubFile);
|
||||
pubFile.MessageEnd();
|
||||
}
|
||||
|
||||
void CryptManager::SignFile( CString sPath )
|
||||
{
|
||||
CString sPrivFilename = PRIVATE_KEY_PATH;
|
||||
CString sMessageFilename = sPath;;
|
||||
CString sSignatureFilename = sPath + SIGNATURE_POSPEND;
|
||||
|
||||
if( !IsAFile(sMessageFilename) || !IsAFile(sPrivFilename) )
|
||||
return;
|
||||
|
||||
// CAREFUL: These classes can throw all kinds of exceptions. Should this
|
||||
// be wrapped in a try catch?
|
||||
|
||||
// TODO: use RageFile here
|
||||
RageFileSource privFile(sPrivFilename, true, new HexDecoder);
|
||||
RSASSA_PKCS1v15_SHA_Signer priv(privFile);
|
||||
RandomNumberGenerator &rng = RandomPool();
|
||||
RageFileSource f(sMessageFilename, true, new SignerFilter(rng, priv, new HexEncoder(new RageFileSink(sSignatureFilename))));
|
||||
}
|
||||
|
||||
bool CryptManager::VerifyFile( CString sPath )
|
||||
{
|
||||
CString sPubFilename = PUBLIC_KEY_PATH;
|
||||
CString sMessageFilename = sPath;;
|
||||
CString sSignatureFilename = sPath + SIGNATURE_POSPEND;
|
||||
|
||||
if( !IsAFile(sSignatureFilename) || !IsAFile(sPubFilename) )
|
||||
return false;
|
||||
|
||||
// CAREFUL: These classes can throw all kinds of exceptions. Should this
|
||||
// be wrapped in a try catch?
|
||||
|
||||
// TODO: use RageFile here
|
||||
RageFileSource pubFile(sPubFilename, true, new HexDecoder);
|
||||
RSASSA_PKCS1v15_SHA_Verifier pub(pubFile);
|
||||
|
||||
RageFileSource signatureFile(sSignatureFilename, true, new HexDecoder);
|
||||
if (signatureFile.MaxRetrievable() != pub.SignatureLength())
|
||||
return false;
|
||||
SecByteBlock signature(pub.SignatureLength());
|
||||
signatureFile.Get(signature, signature.size());
|
||||
|
||||
VerifierFilter *verifierFilter = new VerifierFilter(pub);
|
||||
verifierFilter->Put(signature, pub.SignatureLength());
|
||||
RageFileSource f(sMessageFilename, true, verifierFilter);
|
||||
|
||||
return verifierFilter->GetLastResult();
|
||||
}
|
||||
|
||||
void CryptManager::DigestFile(const char *filename)
|
||||
{
|
||||
// MD5 md5;
|
||||
// HashFilter md5Filter(md5);
|
||||
//
|
||||
// auto_ptr<ChannelSwitch> channelSwitch(new ChannelSwitch);
|
||||
// channelSwitch->AddDefaultRoute(md5Filter);
|
||||
// RageFileSource(filename, true, channelSwitch.release());
|
||||
//
|
||||
// HexEncoder encoder(new RageFileSink(cout), false);
|
||||
// cout << "\nMD5: ";
|
||||
// md5Filter.TransferTo(encoder);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef CryptManager_H
|
||||
#define CryptManager_H
|
||||
|
||||
class CryptManager
|
||||
{
|
||||
public:
|
||||
static void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const char *pubFilename, const char *seed);
|
||||
|
||||
static void SignFile( CString sPath );
|
||||
static bool VerifyFile( CString sPath );
|
||||
|
||||
static void DigestFile(const char *filename);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -204,7 +204,7 @@ ActorUtil.cpp ActorUtil.h BitmapText.cpp BitmapText.h Milkshape.h Model.cpp Mode
|
||||
Quad.h Sprite.cpp Sprite.h
|
||||
|
||||
GlobalSingletons = \
|
||||
AnnouncerManager.cpp AnnouncerManager.h Bookkeeper.h Bookkeeper.cpp FontManager.cpp FontManager.h GameManager.cpp GameManager.h \
|
||||
AnnouncerManager.cpp AnnouncerManager.h Bookkeeper.h Bookkeeper.cpp CryptManager.cpp CryptManager.h FontManager.cpp FontManager.h GameManager.cpp GameManager.h \
|
||||
GameState.cpp GameState.h InputFilter.cpp InputFilter.h InputMapper.cpp InputMapper.h InputQueue.cpp InputQueue.h \
|
||||
LightsManager.cpp LightsManager.h MemoryCardManager.cpp MemoryCardManager.h NoteSkinManager.cpp NoteSkinManager.h PrefsManager.cpp PrefsManager.h \
|
||||
ProfileManager.cpp ProfileManager.h ScreenManager.cpp ScreenManager.h SongManager.cpp SongManager.h ThemeManager.cpp ThemeManager.h \
|
||||
|
||||
@@ -212,6 +212,7 @@ PrefsManager::PrefsManager()
|
||||
m_iAttractSoundFrequency = 1;
|
||||
m_bAllowExtraStage = true;
|
||||
g_bAutoRestart = false;
|
||||
m_bAllowReadOldScoreFormats = true;
|
||||
|
||||
m_bEditorShowBGChangesPlay = false;
|
||||
|
||||
@@ -486,6 +487,7 @@ void PrefsManager::ReadGlobalPrefsFromDisk()
|
||||
ini.GetValue( "Options", "AttractSoundFrequency", m_iAttractSoundFrequency );
|
||||
ini.GetValue( "Options", "AllowExtraStage", m_bAllowExtraStage );
|
||||
ini.GetValue( "Options", "AutoRestart", g_bAutoRestart );
|
||||
ini.GetValue( "Options", "AllowReadOldScoreFormats", m_bAllowReadOldScoreFormats );
|
||||
|
||||
ini.GetValue( "Editor", "ShowBGChangesPlay", m_bEditorShowBGChangesPlay );
|
||||
|
||||
@@ -697,6 +699,8 @@ void PrefsManager::SaveGlobalPrefsToDisk() const
|
||||
ini.SetValue( "Options", "AttractSoundFrequency", m_iAttractSoundFrequency );
|
||||
ini.SetValue( "Options", "AllowExtraStage", m_bAllowExtraStage );
|
||||
ini.SetValue( "Options", "AutoRestart", g_bAutoRestart );
|
||||
ini.SetValue( "Options", "AllowReadOldScoreFormats", m_bAllowReadOldScoreFormats );
|
||||
|
||||
ini.SetValue( "Options", "SoundWriteAhead", m_iSoundWriteAhead );
|
||||
|
||||
ini.SetValue( "Editor", "ShowBGChangesPlay", m_bEditorShowBGChangesPlay );
|
||||
|
||||
@@ -186,6 +186,10 @@ public:
|
||||
float m_fCenterImageScaleY;
|
||||
int m_iAttractSoundFrequency; // 0 = never, 1 = every time
|
||||
bool m_bAllowExtraStage;
|
||||
|
||||
// This should be false for arcade machines since the old score format wasn't signed.
|
||||
// People can cheat easily using the old score formats
|
||||
bool m_bAllowReadOldScoreFormats;
|
||||
|
||||
/* Editor prefs: */
|
||||
bool m_bEditorShowBGChangesPlay;
|
||||
|
||||
+61
-13
@@ -25,6 +25,8 @@
|
||||
#include <time.h>
|
||||
#include "ThemeManager.h"
|
||||
#include "Bookkeeper.h"
|
||||
#include "CryptManager.h"
|
||||
#include "PrefsManager.h"
|
||||
|
||||
//
|
||||
// Old file versions for backward compatibility
|
||||
@@ -49,9 +51,9 @@ const int SM_390A12_COURSE_SCORES_VERSION = 8;
|
||||
#define STYLE_CSS "style.css"
|
||||
|
||||
|
||||
#define DEFAULT_PROFILE_NAME ""
|
||||
#define DEFAULT_PROFILE_NAME ""
|
||||
|
||||
#define STATS_TITLE THEME->GetMetric("ProfileManager","StatsTitle")
|
||||
#define STATS_TITLE THEME->GetMetric("ProfileManager","StatsTitle")
|
||||
|
||||
|
||||
void Profile::InitGeneralData()
|
||||
@@ -274,23 +276,61 @@ void Profile::IncrementCategoryPlayCount( StepsType st, RankingCategory rc )
|
||||
// Loading and saving
|
||||
//
|
||||
|
||||
bool Profile::LoadAllFromDir( CString sDir )
|
||||
{
|
||||
InitAll();
|
||||
bool bResult = LoadGeneralDataFromDir( sDir );
|
||||
if( PREFSMAN->m_bAllowReadOldScoreFormats )
|
||||
LoadSongScoresFromDirSM390a12( sDir );
|
||||
LoadSongScoresFromDir( sDir );
|
||||
if( PREFSMAN->m_bAllowReadOldScoreFormats )
|
||||
LoadCourseScoresFromDirSM390a12( sDir );
|
||||
LoadCourseScoresFromDir( sDir );
|
||||
if( PREFSMAN->m_bAllowReadOldScoreFormats )
|
||||
LoadCategoryScoresFromDirSM390a12( sDir );
|
||||
LoadCategoryScoresFromDir( sDir );
|
||||
return bResult;
|
||||
}
|
||||
|
||||
bool Profile::SaveAllToDir( CString sDir ) const
|
||||
{
|
||||
// Delete old files after saving new ones so we don't try to load old
|
||||
// and make duplicate records.
|
||||
// If the save fails, the delete will fail too... probably :-)
|
||||
bool bResult = SaveGeneralDataToDir( sDir );
|
||||
SaveSongScoresToDir( sDir );
|
||||
DeleteSongScoresFromDirSM390a12( sDir );
|
||||
SaveCourseScoresToDir( sDir );
|
||||
DeleteCourseScoresFromDirSM390a12( sDir );
|
||||
SaveCategoryScoresToDir( sDir );
|
||||
DeleteCategoryScoresFromDirSM390a12( sDir );
|
||||
SaveStatsWebPageToDir( sDir );
|
||||
return bResult;
|
||||
}
|
||||
|
||||
|
||||
#define WARN LOG->Warn("Error parsing file '%s' at %s:%d",fn.c_str(),__FILE__,__LINE__);
|
||||
#define WARN_AND_RETURN { WARN; return; }
|
||||
#define WARN_AND_CONTINUE { WARN; continue; }
|
||||
#define CRYPT_VERIFY_FILE \
|
||||
if( !CryptManager::VerifyFile(fn) ) { \
|
||||
LOG->Warn("Signature check failed for '%s' at %s:%d",fn.c_str(),__FILE__,__LINE__); return; }
|
||||
#define CRYPT_VERIFY_FILE_BOOL \
|
||||
if( !CryptManager::VerifyFile(fn) ) { \
|
||||
LOG->Warn("Signature check failed for '%s' at %s:%d",fn.c_str(),__FILE__,__LINE__); return false; }
|
||||
#define CRYPT_WRITE_SIG CryptManager::SignFile(fn);
|
||||
|
||||
bool Profile::LoadGeneralDataFromDir( CString sDir )
|
||||
{
|
||||
CString sIniPath = sDir + PROFILE_INI;
|
||||
CString fn = sDir + PROFILE_INI;
|
||||
InitGeneralData();
|
||||
|
||||
CStringArray asBits;
|
||||
split( Dirname(sIniPath), "/", asBits, true );
|
||||
CString sLastDir = asBits.back(); // this is a number name, e.g. "0000001"
|
||||
CRYPT_VERIFY_FILE_BOOL;
|
||||
|
||||
//
|
||||
// read ini
|
||||
//
|
||||
IniFile ini( sIniPath );
|
||||
IniFile ini( fn );
|
||||
if( !ini.ReadFile() )
|
||||
return false;
|
||||
|
||||
@@ -318,9 +358,9 @@ bool Profile::LoadGeneralDataFromDir( CString sDir )
|
||||
|
||||
bool Profile::SaveGeneralDataToDir( CString sDir ) const
|
||||
{
|
||||
CString sIniPath = sDir + PROFILE_INI;
|
||||
CString fn = sDir + PROFILE_INI;
|
||||
|
||||
IniFile ini( sIniPath );
|
||||
IniFile ini( fn );
|
||||
ini.SetValue( "Profile", "DisplayName", m_sName );
|
||||
ini.SetValue( "Profile", "LastUsedHighScoreName", m_sLastUsedHighScoreName );
|
||||
ini.SetValue( "Profile", "UsingProfileDefaultModifiers", m_bUsingProfileDefaultModifiers );
|
||||
@@ -340,7 +380,9 @@ bool Profile::SaveGeneralDataToDir( CString sDir ) const
|
||||
for( i=0; i<MAX_METER+1; i++ )
|
||||
ini.SetValue( "Profile", "NumSongsPlayedByMeter"+ssprintf("%d",i), m_iNumSongsPlayedByMeter[i] );
|
||||
|
||||
return ini.WriteFile();
|
||||
bool bResult = ini.WriteFile();
|
||||
CRYPT_WRITE_SIG;
|
||||
return bResult;
|
||||
}
|
||||
|
||||
void Profile::SaveSongScoresToDir( CString sDir ) const
|
||||
@@ -352,7 +394,6 @@ void Profile::SaveSongScoresToDir( CString sDir ) const
|
||||
|
||||
CString fn = sDir + SONG_SCORES_XML;
|
||||
|
||||
|
||||
XNode xml;
|
||||
xml.name = "SongScores";
|
||||
|
||||
@@ -393,6 +434,7 @@ void Profile::SaveSongScoresToDir( CString sDir ) const
|
||||
}
|
||||
|
||||
xml.SaveToFile( fn );
|
||||
CRYPT_WRITE_SIG;
|
||||
}
|
||||
|
||||
void Profile::LoadSongScoresFromDir( CString sDir )
|
||||
@@ -401,6 +443,8 @@ void Profile::LoadSongScoresFromDir( CString sDir )
|
||||
|
||||
CString fn = sDir + SONG_SCORES_XML;
|
||||
|
||||
CRYPT_VERIFY_FILE;
|
||||
|
||||
XNode xml;
|
||||
if( !xml.LoadFromFile( fn ) )
|
||||
{
|
||||
@@ -782,6 +826,7 @@ void Profile::SaveCourseScoresToDir( CString sDir ) const
|
||||
}
|
||||
|
||||
xml.SaveToFile( fn );
|
||||
CRYPT_WRITE_SIG;
|
||||
}
|
||||
|
||||
void Profile::LoadCourseScoresFromDir( CString sDir )
|
||||
@@ -790,6 +835,8 @@ void Profile::LoadCourseScoresFromDir( CString sDir )
|
||||
|
||||
CString fn = sDir + COURSE_SCORES_XML;
|
||||
|
||||
CRYPT_VERIFY_FILE;
|
||||
|
||||
XNode xml;
|
||||
if( !xml.LoadFromFile( fn ) )
|
||||
{
|
||||
@@ -831,8 +878,6 @@ void Profile::LoadCourseScoresFromDir( CString sDir )
|
||||
hsl.LoadFromNode( pHighScoreListNode );
|
||||
}
|
||||
}
|
||||
|
||||
xml.SaveToFile( fn );
|
||||
}
|
||||
|
||||
void Profile::SaveCategoryScoresToDir( CString sDir ) const
|
||||
@@ -870,6 +915,7 @@ void Profile::SaveCategoryScoresToDir( CString sDir ) const
|
||||
}
|
||||
|
||||
xml.SaveToFile( fn );
|
||||
CRYPT_WRITE_SIG;
|
||||
}
|
||||
|
||||
void Profile::LoadCategoryScoresFromDir( CString sDir )
|
||||
@@ -878,6 +924,8 @@ void Profile::LoadCategoryScoresFromDir( CString sDir )
|
||||
|
||||
CString fn = sDir + CATEGORY_SCORES_XML;
|
||||
|
||||
CRYPT_VERIFY_FILE;
|
||||
|
||||
XNode xml;
|
||||
if( !xml.LoadFromFile( fn ) )
|
||||
{
|
||||
|
||||
+2
-27
@@ -123,33 +123,8 @@ public:
|
||||
//
|
||||
// Loading and saving
|
||||
//
|
||||
bool LoadAllFromDir( CString sDir )
|
||||
{
|
||||
InitAll();
|
||||
bool bResult = LoadGeneralDataFromDir( sDir );
|
||||
LoadSongScoresFromDirSM390a12( sDir );
|
||||
LoadSongScoresFromDir( sDir );
|
||||
LoadCourseScoresFromDirSM390a12( sDir );
|
||||
LoadCourseScoresFromDir( sDir );
|
||||
LoadCategoryScoresFromDirSM390a12( sDir );
|
||||
LoadCategoryScoresFromDir( sDir );
|
||||
return bResult;
|
||||
}
|
||||
bool SaveAllToDir( CString sDir ) const
|
||||
{
|
||||
// Delete old files after saving new ones so we don't try to load old
|
||||
// and make duplicate records.
|
||||
// If the save fails, the delete will fail too... probably :-)
|
||||
bool bResult = SaveGeneralDataToDir( sDir );
|
||||
SaveSongScoresToDir( sDir );
|
||||
DeleteSongScoresFromDirSM390a12( sDir );
|
||||
SaveCourseScoresToDir( sDir );
|
||||
DeleteCourseScoresFromDirSM390a12( sDir );
|
||||
SaveCategoryScoresToDir( sDir );
|
||||
DeleteCategoryScoresFromDirSM390a12( sDir );
|
||||
SaveStatsWebPageToDir( sDir );
|
||||
return bResult;
|
||||
}
|
||||
bool LoadAllFromDir( CString sDir );
|
||||
bool SaveAllToDir( CString sDir ) const;
|
||||
|
||||
bool LoadGeneralDataFromDir( CString sDir );
|
||||
bool SaveGeneralDataToDir( CString sDir ) const;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "SDL_utils.h"
|
||||
|
||||
#include "CodeDetector.h"
|
||||
#include "CryptHelpers.h"
|
||||
#include "CryptManager.h"
|
||||
|
||||
//
|
||||
// StepMania global classes
|
||||
@@ -1131,14 +1131,8 @@ bool SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature )
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Write a signature
|
||||
//
|
||||
if( bMakeSignature )
|
||||
{
|
||||
CString sSignaturePath = sScreenshotPath + ".sig.rsa";
|
||||
RSASignFile( "private.rsa", sScreenshotPath, sSignaturePath);
|
||||
}
|
||||
CryptManager::SignFile( sScreenshotPath );
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
+57
-30
@@ -1,5 +1,5 @@
|
||||
# Microsoft Developer Studio Project File - Name="StepMania" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 60000
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Application" 0x0101
|
||||
@@ -58,14 +58,14 @@ BSC32=bscmake.exe
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 $(intdir)\verstub.obj kernel32.lib shell32.lib user32.lib gdi32.lib advapi32.lib winmm.lib /nologo /subsystem:windows /pdb:"../debug6/StepMania-debug.pdb" /map /debug /machine:I386 /nodefaultlib:"libcmtd.lib" /out:"../StepMania-debug.exe"
|
||||
# SUBTRACT BASE LINK32 /verbose /profile /pdb:none /incremental:no /nodefaultlib
|
||||
# ADD LINK32 $(intdir)\verstub.obj kernel32.lib gdi32.lib shell32.lib user32.lib advapi32.lib winmm.lib /nologo /subsystem:windows /map /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /out:"../../itg/Program/StepMania-debug.exe"
|
||||
# ADD LINK32 $(intdir)\verstub.obj kernel32.lib gdi32.lib shell32.lib user32.lib advapi32.lib winmm.lib /nologo /subsystem:windows /map /debug /machine:I386 /nodefaultlib:"msvcrt.lib" /out:"../Program/StepMania-debug.exe"
|
||||
# SUBTRACT LINK32 /verbose /profile /pdb:none /incremental:no /nodefaultlib
|
||||
# Begin Special Build Tool
|
||||
IntDir=.\../Debug6
|
||||
TargetDir=\temp\itg\Program
|
||||
TargetDir=\stepmania\stepmania\Program
|
||||
TargetName=StepMania-debug
|
||||
SOURCE="$(InputPath)"
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi
|
||||
# End Special Build Tool
|
||||
|
||||
@@ -82,23 +82,27 @@ PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania
|
||||
# PROP Intermediate_Dir "../Debug_Xbox"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
XBCP=xbecopy.exe
|
||||
# ADD BASE XBCP /NOLOGO
|
||||
# ADD XBCP /NOLOGO
|
||||
XBE=imagebld.exe
|
||||
# ADD BASE XBE /nologo /stack:0x10000 /debug
|
||||
# ADD XBE /nologo /stack:0x10000 /debug /out:"../default.xbe"
|
||||
CPP=cl.exe
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_XBOX" /D "_DEBUG" /YX /FD /G6 /Ztmp /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /I "vorbis" /D "WIN32" /D "_DEBUG" /D "_XBOX" /D "OGG_ONLY" /D "DEBUG" /FR /YX"global.h" /FD /G6 /Ztmp /c
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 xapilibd.lib d3d8d.lib d3dx8d.lib xgraphicsd.lib dsoundd.lib dmusicd.lib xnetd.lib xboxkrnl.lib /nologo /incremental:no /debug /machine:I386 /subsystem:xbox /fixed:no /TMP
|
||||
# ADD LINK32 $(intdir)\verstub.obj xapilibd.lib d3d8d.lib d3dx8d.lib xgraphicsd.lib dsoundd.lib dmusicd.lib xnetd.lib xboxkrnl.lib /nologo /map /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"../StepManiaXbox-debug.exe" /subsystem:xbox /fixed:no /TMP
|
||||
# SUBTRACT LINK32 /incremental:no
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
CPP=cl.exe
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_XBOX" /D "_DEBUG" /YX /FD /G6 /Ztmp /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /I "vorbis" /D "WIN32" /D "_DEBUG" /D "_XBOX" /D "OGG_ONLY" /D "DEBUG" /FR /YX"global.h" /FD /G6 /Ztmp /c
|
||||
XBE=imagebld.exe
|
||||
# ADD BASE XBE /nologo /stack:0x10000 /debug
|
||||
# ADD XBE /nologo /stack:0x10000 /debug /out:"../default.xbe"
|
||||
XBCP=xbecopy.exe
|
||||
# ADD BASE XBCP /NOLOGO
|
||||
# ADD XBCP /NOLOGO
|
||||
# Begin Special Build Tool
|
||||
IntDir=.\../Debug_Xbox
|
||||
TargetDir=\stepmania\stepmania
|
||||
TargetName=default
|
||||
SOURCE="$(InputPath)"
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi
|
||||
# End Special Build Tool
|
||||
|
||||
@@ -135,10 +139,10 @@ LINK32=link.exe
|
||||
# SUBTRACT LINK32 /verbose /pdb:none /debug
|
||||
# Begin Special Build Tool
|
||||
IntDir=.\../Release6
|
||||
TargetDir=\temp\stepmania\Program
|
||||
TargetDir=\stepmania\stepmania\Program
|
||||
TargetName=StepMania
|
||||
SOURCE="$(InputPath)"
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi
|
||||
# End Special Build Tool
|
||||
|
||||
@@ -156,24 +160,28 @@ PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania
|
||||
# PROP Intermediate_Dir "../Release_Xbox"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
XBCP=xbecopy.exe
|
||||
# ADD BASE XBCP /NOLOGO
|
||||
# ADD XBCP /NOLOGO
|
||||
XBE=imagebld.exe
|
||||
# ADD BASE XBE /nologo /stack:0x10000 /debug
|
||||
# ADD XBE /nologo /testid:"123456" /stack:0x10000 /debug /out:"../default.xbe"
|
||||
CPP=cl.exe
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /D "WIN32" /D "_XBOX" /D "_DEBUG" /Fr /YX"global.h" /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /I "vorbis" /D "WIN32" /D "NDEBUG" /D "_XBOX" /FR /YX /FD /c
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 $(intdir)\verstub.obj xapilibd.lib d3d8d.lib d3dx8d.lib xgraphicsd.lib dsoundd.lib dmusicd.lib xnetd.lib xboxkrnl.lib /nologo /pdb:"../debug6/StepMania-debug.pdb" /map /debug /machine:IX86 /nodefaultlib:"libcmtd.lib" /out:"../StepMania-debug.exe"
|
||||
# SUBTRACT BASE LINK32 /verbose /profile /pdb:none /incremental:no /nodefaultlib
|
||||
# ADD LINK32 $(intdir)\verstub.obj xapilib.lib d3d8.lib d3dx8.lib xgraphics.lib dsound.lib dmusic.lib xnet.lib xboxkrnl.lib libcmt.lib /nologo /incremental:no /map /machine:I386 /nodefaultlib:"libc" /nodefaultlib:"libcmtd" /out:"../StepManiaXbox.exe" /subsystem:xbox /fixed:no /TMP /OPT:REF
|
||||
# SUBTRACT LINK32 /pdb:none /debug
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
CPP=cl.exe
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /D "WIN32" /D "_XBOX" /D "_DEBUG" /Fr /YX"global.h" /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /I "vorbis" /D "WIN32" /D "NDEBUG" /D "_XBOX" /FR /YX /FD /c
|
||||
XBE=imagebld.exe
|
||||
# ADD BASE XBE /nologo /stack:0x10000 /debug
|
||||
# ADD XBE /nologo /testid:"123456" /stack:0x10000 /debug /out:"../default.xbe"
|
||||
XBCP=xbecopy.exe
|
||||
# ADD BASE XBCP /NOLOGO
|
||||
# ADD XBCP /NOLOGO
|
||||
# Begin Special Build Tool
|
||||
IntDir=.\../Release_Xbox
|
||||
TargetDir=\stepmania\stepmania
|
||||
TargetName=default
|
||||
SOURCE="$(InputPath)"
|
||||
PreLink_Cmds=disasm\verinc cl /Zl /nologo /c PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi
|
||||
# End Special Build Tool
|
||||
|
||||
@@ -5830,6 +5838,25 @@ SOURCE=.\Bookkeeper.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CryptManager.cpp
|
||||
|
||||
!IF "$(CFG)" == "StepMania - Win32 Debug"
|
||||
|
||||
!ELSEIF "$(CFG)" == "StepMania - Xbox Debug"
|
||||
|
||||
!ELSEIF "$(CFG)" == "StepMania - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "StepMania - Xbox Release"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CryptManager.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\FontManager.cpp
|
||||
|
||||
!IF "$(CFG)" == "StepMania - Win32 Debug"
|
||||
|
||||
@@ -1987,6 +1987,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\
|
||||
<File
|
||||
RelativePath="CombinedLifeMeter.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="CryptManager.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="CryptManager.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\FontManager.cpp">
|
||||
</File>
|
||||
|
||||
Reference in New Issue
Block a user