From 4c2e610eaaa3873db492b894b6578ea836e1de4f Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 9 Dec 2005 19:21:38 +0000 Subject: [PATCH] eliminate the dupe copies of things in smpackage (registry, RageUtil) and share some of the directory logic --- .../src/{smpackage => }/smpackage-net2003.sln | 33 +- stepmania/src/smpackage-net2003.vcproj | 328 +++++++ stepmania/src/smpackage/IniFile.cpp | 319 ------- stepmania/src/smpackage/IniFile.h | 111 --- stepmania/src/smpackage/RageUtil.cpp | 623 -------------- stepmania/src/smpackage/RageUtil.h | 176 ---- stepmania/src/smpackage/Registry.cpp | 804 ------------------ stepmania/src/smpackage/Registry.h | 71 -- .../src/smpackage/smpackage-net2003.vcproj | 613 ------------- 9 files changed, 344 insertions(+), 2734 deletions(-) rename stepmania/src/{smpackage => }/smpackage-net2003.sln (68%) create mode 100644 stepmania/src/smpackage-net2003.vcproj delete mode 100644 stepmania/src/smpackage/IniFile.cpp delete mode 100644 stepmania/src/smpackage/IniFile.h delete mode 100644 stepmania/src/smpackage/RageUtil.cpp delete mode 100644 stepmania/src/smpackage/RageUtil.h delete mode 100644 stepmania/src/smpackage/Registry.cpp delete mode 100644 stepmania/src/smpackage/Registry.h delete mode 100644 stepmania/src/smpackage/smpackage-net2003.vcproj diff --git a/stepmania/src/smpackage/smpackage-net2003.sln b/stepmania/src/smpackage-net2003.sln similarity index 68% rename from stepmania/src/smpackage/smpackage-net2003.sln rename to stepmania/src/smpackage-net2003.sln index 996c03e31d..978a5a3529 100644 --- a/stepmania/src/smpackage/smpackage-net2003.sln +++ b/stepmania/src/smpackage-net2003.sln @@ -1,11 +1,10 @@ Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZipArchive", "ZipArchive\ZipArchive-net2003.vcproj", "{A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "smpackage", "smpackage-net2003.vcproj", "{6B369A92-8DDF-487C-A589-614987544197}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "smpackage", "smpackage-net2003.vcproj", "{6B369A92-8DDF-487C-A589-614987544197}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZipArchive", "smpackage\ZipArchive\ZipArchive-net2003.vcproj", "{F8FE2773-87CB-402F-8DC8-A80837C3E24C}" ProjectSection(ProjectDependencies) = postProject - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1} = {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1} EndProjectSection EndProject Global @@ -19,20 +18,6 @@ Global Unicode Static Release = Unicode Static Release EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Debug.ActiveCfg = Debug|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Debug.Build.0 = Debug|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Release.ActiveCfg = Release|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Release.Build.0 = Release|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Static Debug.ActiveCfg = Static Debug|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Static Debug.Build.0 = Static Debug|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Static Release.ActiveCfg = Static Release|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Static Release.Build.0 = Static Release|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Unicode Debug.ActiveCfg = Unicode Debug|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Unicode Debug.Build.0 = Unicode Debug|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Unicode Release.ActiveCfg = Unicode Release|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Unicode Release.Build.0 = Unicode Release|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Unicode Static Release.ActiveCfg = Unicode Static Release|Win32 - {A72BC5D6-08F5-453F-B8D2-1278A6DF60A1}.Unicode Static Release.Build.0 = Unicode Static Release|Win32 {6B369A92-8DDF-487C-A589-614987544197}.Debug.ActiveCfg = Debug|Win32 {6B369A92-8DDF-487C-A589-614987544197}.Debug.Build.0 = Debug|Win32 {6B369A92-8DDF-487C-A589-614987544197}.Release.ActiveCfg = Release|Win32 @@ -47,6 +32,20 @@ Global {6B369A92-8DDF-487C-A589-614987544197}.Unicode Release.Build.0 = Release|Win32 {6B369A92-8DDF-487C-A589-614987544197}.Unicode Static Release.ActiveCfg = Release|Win32 {6B369A92-8DDF-487C-A589-614987544197}.Unicode Static Release.Build.0 = Release|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Debug.ActiveCfg = Debug|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Debug.Build.0 = Debug|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Release.ActiveCfg = Release|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Release.Build.0 = Release|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Static Debug.ActiveCfg = Static Debug|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Static Debug.Build.0 = Static Debug|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Static Release.ActiveCfg = Static Release|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Static Release.Build.0 = Static Release|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Unicode Debug.ActiveCfg = Unicode Debug|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Unicode Debug.Build.0 = Unicode Debug|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Unicode Release.ActiveCfg = Unicode Release|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Unicode Release.Build.0 = Unicode Release|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Unicode Static Release.ActiveCfg = Unicode Static Release|Win32 + {F8FE2773-87CB-402F-8DC8-A80837C3E24C}.Unicode Static Release.Build.0 = Unicode Static Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/stepmania/src/smpackage-net2003.vcproj b/stepmania/src/smpackage-net2003.vcproj new file mode 100644 index 0000000000..3baf0e74f6 --- /dev/null +++ b/stepmania/src/smpackage-net2003.vcproj @@ -0,0 +1,328 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stepmania/src/smpackage/IniFile.cpp b/stepmania/src/smpackage/IniFile.cpp deleted file mode 100644 index 2b1b8040fe..0000000000 --- a/stepmania/src/smpackage/IniFile.cpp +++ /dev/null @@ -1,319 +0,0 @@ -/* ------------------------------------------------------------------------------ - File: IniFile.h - - Desc: Wrapper for reading and writing an .ini file. - - Copyright (c) 2001-2002 by the persons listed below. All rights reserved. ------------------------------------------------------------------------------ -*/ - -#include "stdafx.h" -#include "IniFile.h" -#include "RageUtil.h" - - -//constructor, can specify pathname here instead of using SetPath later -IniFile::IniFile(CString inipath) -{ - path = inipath; -} - -//default destructor -IniFile::~IniFile() -{ - -} - -// sets path of ini file to read and write from -void IniFile::SetPath(CString newpath) -{ - path = newpath; -} - - -void IniFile::ReadBuf( const CString &buf ) -{ - CString keyname; - CStringArray lines; - split(buf, "\n", lines, true); - for( unsigned i = 0; i < lines.size(); ++i ) - { - CString line = lines[i]; - - if(line.GetLength() >= 3 && - line[0] == '\xef' && - line[1] == '\xbb' && - line[2] == '\xbf' - ) - { - /* Obnoxious NT marker for UTF-8. Remove it. */ - line.Delete(0, 3); - } - - StripCrnl(line); - - if( line.IsEmpty() ) - continue; - if ((line.GetLength() >= 2 && line[0] == '/' && line[1] == '/') ) - continue; /* comment */ - if( line[0] == '#') - continue; /* comment */ - - if (line[0] == '[' && line[line.GetLength()-1] == ']') //if a section heading - { - keyname = line; - keyname.Delete(0); - keyname.Delete(keyname.GetLength()-1); - } - else //if a value - { - int iEqualIndex = line.Find("="); - if( iEqualIndex != -1 ) - { - CString valuename = line.Left(iEqualIndex); - CString value = line.Right(line.GetLength()-valuename.GetLength()-1); - SetValue(keyname,valuename,value); - } - } - } -} - -void IniFile::WriteBuf( CString &buf ) const -{ - buf = ""; - for (keymap::const_iterator k = keys.begin(); k != keys.end(); ++k) - { - if (k->second.empty()) - continue; - - buf += ssprintf( "[%s]\r\n", (const char *) k->first ); - - for (key::const_iterator i = k->second.begin(); i != k->second.end(); ++i) - buf += ssprintf( "%s=%s\r\n", (const char *)i->first, (const char *)i->second ); - - buf += ssprintf( "\r\n" ); - } -} - - -// reads ini file specified using IniFile::SetPath() -// returns true if successful, false otherwise -bool IniFile::ReadFile() -{ - FILE *f = fopen(path, "rb"); - - if (f == NULL) - { - error = ssprintf("Unable to open ini file: %s", strerror(errno)); - return 0; - } - - int size = GetFileSizeInBytes(path); - char *buf = new char[size+1]; - int ret = fread(buf, 1, size, f); - if ( ret != size ) - { - if( ferror(f) ) - error = ssprintf("Unable to read ini file: %s", strerror(errno)); - else - error = ssprintf("Unexpected eof in INI"); - delete[] buf; - fclose(f); - - return false; - } - - ReadBuf(buf); - - delete[] buf; - fclose(f); - return true; -} - -// writes data stored in class to ini file -void IniFile::WriteFile() -{ - CString buf; - WriteBuf( buf ); - FILE* fp = fopen( path, "wb" ); - - if( fp == NULL ) - return; - - fwrite(buf.GetBuffer(0), buf.GetLength(), 1, fp); - fclose( fp ); -} - -// deletes all stored ini data -void IniFile::Reset() -{ - keys.clear(); -} - -// returns number of keys currently in the ini -int IniFile::GetNumKeys() const -{ - return keys.size(); -} - -// returns number of values stored for specified key, or -1 if key not found -int IniFile::GetNumValues(const CString &keyname) const -{ - keymap::const_iterator k = keys.find(keyname); - if (k == keys.end()) - return -1; - - return k->second.size(); -} - -// gets value of [keyname] valuename = -bool IniFile::GetValue(const CString &keyname, const CString &valuename, CString& value) const -{ - keymap::const_iterator k = keys.find(keyname); - if (k == keys.end()) - { - error = "Unable to locate specified key."; - return false; - } - - key::const_iterator i = k->second.find(valuename); - - if (i == k->second.end()) - { - error = "Unable to locate specified value."; - return false; - } - - value = i->second; - return true; -} - -// gets value of [keyname] valuename = -bool IniFile::GetValueI(const CString &keyname, const CString &valuename, int& value) const -{ - CString sValue; - if( !GetValue(keyname,valuename,sValue) ) - return false; - sscanf( sValue, "%d", &value ); - return true; -} - -bool IniFile::GetValueU(const CString &keyname, const CString &valuename, unsigned &value) const -{ - CString sValue; - if( !GetValue(keyname,valuename,sValue) ) - return false; - sscanf( sValue, "%u", &value ); - return true; -} - -// gets value of [keyname] valuename = -bool IniFile::GetValueF(const CString &keyname, const CString &valuename, float& value) const -{ - CString sValue; - if( !GetValue(keyname,valuename,sValue) ) - return false; - sscanf( sValue, "%f", &value ); - return true; -} - -// gets value of [keyname] valuename = -bool IniFile::GetValueB(const CString &keyname, const CString &valuename, bool& value) const -{ - CString sValue; - if( !GetValue(keyname,valuename,sValue) ) - return false; - value = atoi(sValue) != 0; - return true; -} - -// sets value of [keyname] valuename =. -// specify the optional paramter as false (0) if you do not want it to create -// the key if it doesn't exist. Returns true if data entered, false otherwise -bool IniFile::SetValue(const CString &keyname, const CString &valuename, const CString &value, bool create) -{ - if (!create && keys.find(keyname) == keys.end()) //if key doesn't exist - return false; // stop entering this key - - // find value - if (!create && keys[keyname].find(valuename) == keys[keyname].end()) - return false; - - keys[keyname][valuename] = value; - return true; -} - -// sets value of [keyname] valuename =. -// specify the optional paramter as false (0) if you do not want it to create -// the key if it doesn't exist. Returns true if data entered, false otherwise -bool IniFile::SetValueI(const CString &keyname, const CString &valuename, int value, bool create) -{ - return SetValue(keyname, valuename, ssprintf("%d",value), create); -} - -bool IniFile::SetValueU(const CString &keyname, const CString &valuename, unsigned value, bool create) -{ - return SetValue(keyname, valuename, ssprintf("%u",value), create); -} - -bool IniFile::SetValueF(const CString &keyname, const CString &valuename, float value, bool create) -{ - return SetValue(keyname, valuename, ssprintf("%f",value), create); -} - -bool IniFile::SetValueB(const CString &keyname, const CString &valuename, bool value, bool create) -{ - return SetValue(keyname, valuename, ssprintf("%d",value), create); -} - -// deletes specified value -// returns true if value existed and deleted, false otherwise -bool IniFile::DeleteValue(const CString &keyname, const CString &valuename) -{ - keymap::iterator k = keys.find(keyname); - if (k == keys.end()) - return false; - - key::iterator i = k->second.find(valuename); - if(i == k->second.end()) - return false; - - k->second.erase(i); - return true; -} - -// deletes specified key and all values contained within -// returns true if key existed and deleted, false otherwise -bool IniFile::DeleteKey(const CString &keyname) -{ - keymap::iterator k = keys.find(keyname); - if (k == keys.end()) - return false; - - keys.erase(k); - return true; -} - -const IniFile::key *IniFile::GetKey(const CString &keyname) const -{ - keymap::const_iterator i = keys.find(keyname); - if(i == keys.end()) return NULL; - return &i->second; -} - -void IniFile::SetValue(const CString &keyname, const key &key) -{ - keys[keyname]=key; -} - -void IniFile::RenameKey(const CString &from, const CString &to) -{ - if(keys.find(from) == keys.end()) - return; - if(keys.find(to) != keys.end()) - return; - - keys[to] = keys[from]; - keys.erase(from); -} diff --git a/stepmania/src/smpackage/IniFile.h b/stepmania/src/smpackage/IniFile.h deleted file mode 100644 index d6c9e39ae4..0000000000 --- a/stepmania/src/smpackage/IniFile.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef INIFILE_H -#define INIFILE_H -/* ------------------------------------------------------------------------------ - Class: IniFile - - Desc: Wrapper for reading and writing an .ini file. - - Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. - Adam Clauss - Chris Danford ------------------------------------------------------------------------------ -*/ - -#include -using namespace std; - -class IniFile -{ -public: - // all keys are of this type - - typedef map key; - typedef map keymap; - - typedef keymap::const_iterator const_iterator; - const_iterator begin() const { return keys.begin(); } - const_iterator end() const { return keys.end(); } - -private: - //stores pathname of ini file to read/write - CString path; - - // keys in ini - keymap keys; - - -public: - - //will contain error info if one occurs - //ended up not using much, just in ReadFile and GetValue - mutable CString error; - - //constructor, can specify pathname here instead of using SetPath later - IniFile(CString inipath = ""); - - //default destructor - virtual ~IniFile(); - - //sets path of ini file to read and write from - void SetPath(CString newpath); - CString GetPath() const { return path; } - - //reads ini file specified using IniFile::SetPath() - //returns true if successful, false otherwise - bool ReadFile(); - - //writes data stored in class to ini file - void WriteFile(); - - void ReadBuf( const CString &buf ); - void WriteBuf( CString &buf ) const; - - //deletes all stored ini data - void Reset(); - - //returns number of keys currently in the ini - int GetNumKeys() const; - - //returns number of values stored for specified key - int GetNumValues(const CString &keyname) const; - - //gets value of [keyname] valuename = - //returns "", or 0 if key/value not found. Sets error member to show problem - bool GetValue(const CString &key, const CString &valuename, CString& value) const; - bool GetValueI(const CString &key, const CString &valuename, int& value) const; - bool GetValueU(const CString &key, const CString &valuename, unsigned& value) const; - bool GetValueF(const CString &key, const CString &valuename, float& value) const; - bool GetValueB(const CString &key, const CString &valuename, bool& value) const; - bool GetValue(const CString &key, const CString &valuename, int& value) const { return GetValueI(key, valuename, value); } - bool GetValue(const CString &key, const CString &valuename, float& value) const { return GetValueF(key, valuename, value); } - bool GetValue(const CString &key, const CString &valuename, bool& value) const { return GetValueB(key, valuename, value); } - - //sets value of [keyname] valuename =. - //specify the optional paramter as false (0) if you do not want it to create - //the key if it doesn't exist. Returns true if data entered, false otherwise - bool SetValue(const CString &key, const CString &valuename, const CString &value, bool create = 1); - bool SetValueI(const CString &key, const CString &valuename, int value, bool create = 1); - bool SetValueU(const CString &key, const CString &valuename, unsigned value, bool create = 1); - bool SetValueF(const CString &key, const CString &valuename, float value, bool create = 1); - bool SetValueB(const CString &key, const CString &valuename, bool value, bool create = 1); - bool SetValue(const CString &key, const CString &valuename, int value, bool create = 1) { return SetValueI(key, valuename, value, create); } - - //deletes specified value - //returns true if value existed and deleted, false otherwise - bool DeleteValue(const CString &keyname, const CString &valuename); - - //deletes specified key and all values contained within - //returns true if key existed and deleted, false otherwise - bool DeleteKey(const CString &keyname); - - const key *GetKey(const CString &keyname) const; - void SetValue(const CString &keyname, const key &key); - - /* Rename a key. For example, call RenameKey("foo", "main") after - * reading an INI where [foo] is an alias to [main]. If to already - * exists, nothing happens. */ - void RenameKey(const CString &from, const CString &to); -}; - -#endif diff --git a/stepmania/src/smpackage/RageUtil.cpp b/stepmania/src/smpackage/RageUtil.cpp deleted file mode 100644 index 829841b21b..0000000000 --- a/stepmania/src/smpackage/RageUtil.cpp +++ /dev/null @@ -1,623 +0,0 @@ -#include "stdafx.h" -/* ------------------------------------------------------------------------------ - File: RageUtil - - Desc: See header. - - Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. - Chris Danford - Peter S. May (GetHashForString implementation) ------------------------------------------------------------------------------ -*/ - -#include "RageUtil.h" -#include - -ULONG randseed = time(NULL); - - - -bool IsAnInt( LPCTSTR s ) -{ - if( strlen(s) == 0 ) - return false; - - for( UINT i=0; i '9' ) - return false; - - return true; -} - -float TimeToSeconds( CString sHMS ) -{ - CStringArray arrayBits; - split( sHMS, ":", arrayBits, false ); - - while( arrayBits.size() < 3 ) - arrayBits.insert(arrayBits.begin(), "0" ); // pad missing bits - - float fSeconds = 0; - fSeconds += atoi( arrayBits[0] ) * 60 * 60; - fSeconds += atoi( arrayBits[1] ) * 60; - fSeconds += (float)atof( arrayBits[2] ); - - return fSeconds; -} - -CString SecondsToTime( float fSecs ) -{ - int iMinsDisplay = (int)fSecs/60; - int iSecsDisplay = (int)fSecs - iMinsDisplay*60; - int iLeftoverDisplay = int( (fSecs - iMinsDisplay*60 - iSecsDisplay) * 100 ); - return ssprintf( "%02d:%02d:%02d", iMinsDisplay, iSecsDisplay, iLeftoverDisplay ); -} - -//----------------------------------------------------------------------------- -// Name: ssprintf() -// Desc: -//----------------------------------------------------------------------------- -CString ssprintf( LPCTSTR fmt, ...) -{ - va_list va; - va_start(va, fmt); - return vssprintf(fmt, va); -} - - -//----------------------------------------------------------------------------- -// Name: vssprintf() -// Desc: -//----------------------------------------------------------------------------- -CString vssprintf( LPCTSTR fmt, va_list argList) -{ - CString str; - str.FormatV(fmt, argList); - return str; -} - - - -//----------------------------------------------------------------------------- -// Name: join() -// Desc: -//----------------------------------------------------------------------------- -CString join( const CString &Deliminator, const CStringArray& Source) -{ - if( Source.empty() ) - return ""; - - CString csTmp; - - // Loop through the Array and Append the Deliminator - for( unsigned iNum = 0; iNum < Source.size()-1; iNum++ ) { - csTmp += Source[iNum]; - csTmp += Deliminator; - } - csTmp += Source.back(); - return csTmp; -} - -//----------------------------------------------------------------------------- -// Name: split() -// Desc: -//----------------------------------------------------------------------------- -void split( const CString &Source, const CString &Deliminator, CStringArray& AddIt, const bool bIgnoreEmpty ) -{ - CString newCString; - CString tmpCString; - CString AddCString; - - int pos1 = 0; - int pos = 0; - - newCString = Source; - do { - pos1 = 0; - pos = newCString.Find(Deliminator, pos1); - if ( pos != -1 ) { - CString AddCString = newCString.Left(pos); - if( newCString.IsEmpty() && bIgnoreEmpty ) - ; // do nothing - else - AddIt.push_back(AddCString); - - tmpCString = newCString.Mid(pos + Deliminator.GetLength()); - newCString = tmpCString; - } - } while ( pos != -1 ); - - if( newCString.IsEmpty() && bIgnoreEmpty ) - ; // do nothing - else - AddIt.push_back(newCString); -} - - - - -//----------------------------------------------------------------------------- -// Name: splitpath() -// Desc: -//----------------------------------------------------------------------------- -void splitpath( const bool UsingDirsOnly, const CString &Path, CString& Drive, CString& Dir, CString& FName, CString& Ext ) -{ - - int nSecond; - - // Look for a UNC Name! - if (Path.Left(2) == "\\\\") - { - int nFirst = Path.Find("\\",3); - nSecond = Path.Find("\\",nFirst + 1); - if (nSecond == -1) { - Drive = Path; - Dir = ""; - FName = ""; - Ext = ""; - } - else if (nSecond > nFirst) - Drive = Path.Left(nSecond); - } - else if (Path.Mid(1,1) == ":" ) // normal Drive Structure - { - nSecond = 2; - Drive = Path.Left(2); - } - else // no UNC or drive letter - { - nSecond = -1; - } - - - if (UsingDirsOnly) { - Dir = Path.Right((Path.GetLength() - nSecond) - 1); - FName = ""; - Ext = ""; - } - else { - int nDirEnd = Path.ReverseFind('\\'); - if (nDirEnd == Path.GetLength()) { - Dir = ""; - FName = ""; - Ext = ""; - } - else { - - Dir = Path.Mid(nSecond + 1, (nDirEnd - nSecond) - 1); - - int nFileEnd = Path.ReverseFind('.'); - if (nFileEnd != -1) { - - if (nDirEnd > nFileEnd) { - FName = Path.Right(Path.GetLength() - nDirEnd); - Ext = ""; - } - else { - FName = Path.Mid(nDirEnd + 1, (nFileEnd - nDirEnd) - 1); - Ext = Path.Right((Path.GetLength() - nFileEnd) - 1); - } - } - else { - FName = Path.Right((Path.GetLength() - nDirEnd) - 1); - Ext = ""; - } - } - } -} - -//----------------------------------------------------------------------------- -// Name: splitpath() -// Desc: -//----------------------------------------------------------------------------- -void splitrelpath( const CString &Path, CString& Dir, CString& FName, CString& Ext ) -{ - /* Find the last slash or backslash. */ - int Last = max(Path.ReverseFind('/'), Path.ReverseFind('\\')); - - /* Set 'Last' to the first character of the filename. If we have - * no directory separators, this is the entire string, so set it - * to 0. */ - if(Last == -1) Last = 0; - else Last++; - - CString sFNameAndExt = Path.Right(Path.GetLength()-Last); - - // subtract the FNameAndExt from Path - Dir = Path.Left( Path.GetLength()-sFNameAndExt.GetLength() ); // don't subtract out the trailing slash - - CStringArray sFNameAndExtBits; - split( sFNameAndExt, ".", sFNameAndExtBits, false ); - - if( sFNameAndExt.GetLength() == 0 ) // no file at the end of this path - { - FName = ""; - Ext = ""; - } - else if( sFNameAndExtBits.size() == 1 ) // file doesn't have extension - { - FName = sFNameAndExtBits[0]; - Ext = ""; - } - else if( sFNameAndExtBits.size() > 1 ) // file has extension and possibly multiple periods - { - Ext = sFNameAndExtBits[ sFNameAndExtBits.size()-1 ]; - - // subtract the Ext and last period from FNameAndExt - FName = sFNameAndExt.Left( sFNameAndExt.GetLength()-Ext.GetLength()-1 ); - } -} - - -void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ) -{ - CString sDir, sThrowAway; - splitrelpath( sPath, sDir, sThrowAway, sThrowAway ); - - WIN32_FIND_DATA fd; - HANDLE hFind = ::FindFirstFile( sPath, &fd ); - - if( INVALID_HANDLE_VALUE == hFind ) // no files found - return; - - do - { - if( bOnlyDirs && !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) - continue; // skip - - CString sDirName( fd.cFileName ); - - if( sDirName == "." || sDirName == ".." ) - continue; - - if( bReturnPathToo ) - AddTo.push_back( sDir + sDirName ); - else - AddTo.push_back( sDirName ); - - - } while( ::FindNextFile( hFind, &fd ) ); - ::FindClose( hFind ); -} - -//----------------------------------------------------------------------------- -// Name: GetHashForString( CString s ) -// Desc: This new version of GetHashForString uses a stronger hashing algorithm -// than the former, assuring to a greater degree that two distinct -// strings do not produce the same result. -// The hashing algorithm is a modified CRC-32 (modified in that the -// characters in the CString are recast as unsigned char and that the -// unsigned int result from the hash is recast as a signed int). -//----------------------------------------------------------------------------- -int GetHashForString ( CString string ) -{ -/* - * RageCRC32.cpp - * - * Original code - * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or - * code or tables extracted from it, as desired without restriction. - * - * Code was extracted from IETF Internet Draft - * draft-ietf-tsvwg-sctpcsum-00 at URI - * http://www.ietf.org/proceedings/01dec/I-D/draft-ietf-tsvwg-sctpcsum-00.txt - * - * Adaptation - * Copyright (C) 2002 Peter S. May. - * SourceForge ID: drokulix - * - * - Header file added - * - Name of function changed to GetCrc32 - * - Values in table changed from long int to int - * - * Chris: - * Moved this code out of RageCRC32 since it's not terribly long. Thanks Dro Kulix! - */ - -/* - * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or - * code or tables extracted from it, as desired without restriction. - * - * First, the polynomial itself and its table of feedback terms. The - * polynomial is - * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 - * - * Note that we take it "backwards" and put the highest-order term in - * the lowest-order bit. The X^32 term is "implied"; the LSB is the - * X^31 term, etc. The X^0 term (usually shown as "+1") results in - * the MSB being 1 - * - * Note that the usual hardware shift register implementation, which - * is what we're using (we're merely optimizing it by doing eight-bit - * chunks at a time) shifts bits into the lowest-order term. In our - * implementation, that means shifting towards the right. Why do we - * do it this way? Because the calculated CRC must be transmitted in - * order from highest-order term to lowest-order term. UARTs transmit - * characters in order from LSB to MSB. By storing the CRC this way - * we hand it to the UART in the order low-byte to high-byte; the UART - * sends each low-bit to hight-bit; and the result is transmission bit - * by bit from highest- to lowest-order term without requiring any bit - * shuffling on our part. Reception works similarly - * - * The feedback terms table consists of 256, 32-bit entries. Notes - * - * The table can be generated at runtime if desired; code to do so - * is shown later. It might not be obvious, but the feedback - * terms simply represent the results of eight shift/xor opera - * tions for all combinations of data and CRC register values - * - * The values must be right-shifted by eight bits by the "updcrc - * logic; the shift must be unsigned (bring in zeroes). On some - * hardware you could probably optimize the shift in assembler by - * using byte-swap instructions - * polynomial $edb88320 - */ - -static const unsigned int crc32_tab[] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, - 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, - 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, - 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, - 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, - 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, - 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, - 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, - 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, - 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, - 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, - 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, - 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, - 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, - 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, - 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, - 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, - 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, - 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, - 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, - 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, - 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, - 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, - 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, - 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, - 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, - 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, - 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, - 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, - 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, - 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, - 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, - 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, - 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, - 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, - 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, - 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, - 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, - 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, - 0x2d02ef8d -}; - -/* Return a 32-bit CRC of the contents of the buffer. */ - -//unsigned int -//GetCrc32(const unsigned char *s, unsigned int len) -//{ - const char* s = string; - int len = string.GetLength(); - - unsigned int crc32val = 0; - for( int i=0; i> 8); - - return crc32val; -//} -} - -int GetHashForFile( CString sPath ) -{ - int hash = 0; - - hash += GetHashForString( sPath ); - - hash += GetFileSizeInBytes( sPath ); - - CFileStatus status; - if( CFile::GetStatus(sPath, status) ) - hash += status.m_mtime.GetHour() * 3600 + status.m_mtime.GetMinute() * 60 + status.m_mtime.GetSecond(); - - return abs(hash); -} - -int GetHashForDirectory( CString sDir ) -{ - int hash = 0; - - hash += GetHashForFile( sDir ); - - CStringArray arrayFiles; - GetDirListing( sDir+"\\*.*", arrayFiles, false ); - for( unsigned i=0; i 0; -} - -void SortCStringArray( CStringArray &arrayCStrings, const bool bSortAscending ) -{ - sort( arrayCStrings.begin(), arrayCStrings.end(), - CompareCStringsDesc); -} - -void StripCrnl(CString &s) -{ - while( s.GetLength() && (s[s.GetLength()-1] == '\r' || s[s.GetLength()-1] == '\n') ) - s.Delete(s.GetLength()-1); -} - -LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata) -{ - HKEY hkey; - LONG retval = RegOpenKeyEx(key, subkey, 0, KEY_QUERY_VALUE, &hkey); - - if (retval == ERROR_SUCCESS) { - long datasize = MAX_PATH; - TCHAR data[MAX_PATH]; - RegQueryValue(hkey, "Favorites", data, &datasize); - lstrcpy(retdata,data); - RegCloseKey(hkey); - } - - return retval; -} - -HINSTANCE GotoURL(LPCTSTR url) -{ - TCHAR key[MAX_PATH + MAX_PATH]; - - // First try ShellExecute() - HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL, SW_SHOWDEFAULT); - - // If it failed, get the .htm regkey and lookup the program - if ((UINT)result <= HINSTANCE_ERROR) { - - if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), key) == ERROR_SUCCESS) { - lstrcat(key, _T("\\shell\\open\\command")); - - if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS) { - TCHAR *pos; - pos = _tcsstr(key, _T("\"%1\"")); - if (pos == NULL) { // No quotes found - pos = strstr(key, _T("%1")); // Check for %1, without quotes - if (pos == NULL) // No parameter at all... - pos = key+lstrlen(key)-1; - else - *pos = '\0'; // Remove the parameter - } - else - *pos = '\0'; // Remove the parameter - - lstrcat(pos, _T(" ")); - lstrcat(pos, url); - result = (HINSTANCE) WinExec(key,SW_SHOWDEFAULT); - } - } - } - - return result; -} - -void WriteStringToFile( FILE* file, CString s ) -{ - if( s == "" ) - s = "_"; - fprintf( file, "%s\n", s ); -} - -void ReadStringFromFile( FILE* file, CString& s ) -{ - char szTemp[MAX_PATH]; - fscanf( file, "%[^\n]\n", szTemp ); - s = szTemp; - if( s == "_" ) - s = ""; -} - - -void WriteIntToFile( FILE* file, int i ) -{ - fprintf( file, "%d\n", i ); -} - -void ReadIntFromFile( FILE* file, int& i ) -{ - fscanf( file, "%d\n", &i ); -} - - -void WriteFloatToFile( FILE* file, float f ) -{ - fprintf( file, "%f\n", f ); -} - -void ReadFloatFromFile( FILE* file, float& f ) -{ - fscanf( file, "%f\n", &f ); -} - - - -void WriteUlongToFile( FILE* file, ULONG u ) -{ - fprintf( file, "%u\n", u ); -} - -void ReadUlongFromFile( FILE* file, ULONG& u ) -{ - fscanf( file, "%u\n", &u ); -} - - - diff --git a/stepmania/src/smpackage/RageUtil.h b/stepmania/src/smpackage/RageUtil.h deleted file mode 100644 index f547073d59..0000000000 --- a/stepmania/src/smpackage/RageUtil.h +++ /dev/null @@ -1,176 +0,0 @@ -#pragma once -/* ------------------------------------------------------------------------------ - File: RageUtil - - Desc: Miscellaneous helper macros and functions. - - Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. - Chris Danford ------------------------------------------------------------------------------ -*/ - - -//----------------------------------------------------------------------------- -// SAFE_ Macros -//----------------------------------------------------------------------------- -#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } -#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } } -#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } } - -#define ZERO(x) memset(&x, 0, sizeof(x)) -#define COPY(a,b) { ASSERT(sizeof(a)==sizeof(b)); memcpy(&a, &b, sizeof(a)); } -#define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0])) - -#define RECTWIDTH(rect) ((rect).right - (rect).left) -#define RECTHEIGHT(rect) ((rect).bottom - (rect).top) -inline int RECTCENTERX(RECT rect) { return rect.left + (rect.right-rect.left)/2; } -inline int RECTCENTERY(RECT rect) { return rect.top + (rect.bottom-rect.top)/2; } - -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#endif - -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -#ifndef MAX -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) -#endif - -#ifndef MIN -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -#define clamp(val,low,high) ( max( (low), min((val),(high)) ) ) - -#define PI D3DX_PI -#define DEG (PI / 180.0f) -#define RAD (180.0f / PI) -// Scales x so that l1 corresponds to l2 and h1 corresponds to h2. Does not modify x, MUST assign the result to something! -#define SCALE(x, l1, h1, l2, h2) (((x) - (l1)) / ((h1) - (l1)) * ((h2) - (l2)) + (l2)) -// Clamps x -#define CLAMP(x, l, h) {if (x > h) x = h; else if (x < l) x = l;} - - -//----------------------------------------------------------------------------- -// Misc helper functions -//----------------------------------------------------------------------------- - -// Fast random number generators -// Taken from "Numerical Recipes in C" - -extern ULONG randseed; - -inline ULONG Random() -{ - randseed = 1664525L * randseed + 1013904223L; - return randseed; -} - -inline float RandomFloat() -{ - randseed = 1664525L * randseed + 1013904223L; - ULONG itemp = 0x3f800000 | (0x007fffff & randseed); - return (*(float *)&itemp) - 1.0f; -} - -// Returns a float between dLow and dHigh inclusive -inline float RandomFloat(float fLow, float fHigh) -{ - return RandomFloat() * (fHigh - fLow) + fLow; -} - -// Returns an integer between nLow and nHigh inclusive -inline int RandomInt(int nLow, int nHigh) -{ - return ((Random() >> 2) % (nHigh - nLow + 1)) + nLow; -} - -// Debug new for memory leak tracing -//#ifdef _DEBUG -//#define new new(_NORMAL_BLOCK, __FILE__, __LINE__) -//#endif - - -// Simple function for generating random numbers -inline float randomf( const float low=-1.0f, const float high=1.0f ) -{ - return low + ( high - low ) * ( (FLOAT)rand() ) / RAND_MAX; -} -inline int roundf( const float f ) { return (int)((f)+0.5f); }; -inline int roundf( const double f ) { return (int)((f)+0.5); }; -inline float froundf( const float f, const float fRoundInterval ) -{ - return int( (f + fRoundInterval/2)/fRoundInterval ) * fRoundInterval; -} - -bool IsAnInt( LPCTSTR s ); -float TimeToSeconds( CString sHMS ); -CString SecondsToTime( float fSecs ); - -CString ssprintf( LPCTSTR fmt, ...); -CString vssprintf( LPCTSTR fmt, va_list argList ); - - -// Splits a Path into 4 parts (Directory, Drive, Filename, Extention). Supports UNC path names. -// param1: Whether the Supplied Path (PARAM2) contains a directory name only -// or a file name (Reason: some directories will end with "xxx.xxx" -// which is like a file name). -void splitpath( - const bool UsingDirsOnly, - const CString &Path, - CString &Drive, - CString &Dir, - CString &FName, - CString &Ext -); - -void splitrelpath( - const CString &Path, - CString& Dir, - CString& FName, - CString& Ext -); - -// Splits a CString into an CStringArray according the Deliminator. -void split( - const CString &Source, - const CString &Deliminator, - CStringArray& AddIt, - const bool bIgnoreEmpty = true -); - -// Joins a CStringArray to create a CString according the Deliminator. -CString join( - const CString &Deliminator, - const CStringArray& Source -); - -void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs=false, bool bReturnPathToo=false ); -int GetHashForString( CString s ); -int GetHashForFile( CString sPath ); -int GetHashForDirectory( CString sDir ); // a hash value that remains the same as long as nothing in the directory has changed - -bool DoesFileExist( const CString &sPath ); -bool IsAFile( const CString &sPath ); -bool IsADirectory( const CString &sPath ); -DWORD GetFileSizeInBytes( const CString &sFilePath ); - -void SortCStringArray( CStringArray &AddTo, const bool bSortAcsending = true ); -void StripCrnl(CString &s); - - -LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata); -HINSTANCE GotoURL(LPCTSTR url); - -void WriteStringToFile( FILE* file, CString s ); -void ReadStringFromFile( FILE* file, CString& s ); -void WriteIntToFile( FILE* file, int i ); -void ReadIntFromFile( FILE* file, int& i ); -void WriteFloatToFile( FILE* file, float f ); -void ReadFloatFromFile( FILE* file, float& f ); -void WriteUlongToFile( FILE* file, ULONG u ); -void ReadUlongFromFile( FILE* file, ULONG& u ); - diff --git a/stepmania/src/smpackage/Registry.cpp b/stepmania/src/smpackage/Registry.cpp deleted file mode 100644 index 0d8a03ee94..0000000000 --- a/stepmania/src/smpackage/Registry.cpp +++ /dev/null @@ -1,804 +0,0 @@ - - -#include "stdafx.h" -#include -#include "Registry.h" - -#define CLASS_NAME_LENGTH 255 - -/* IMPORTANT NOTES ABOUT CREGISTRY: - - CRegistry never keeps a key open past the end of a function call. - This is incase the application crashes before the next call to close - the registry - - INCLUDE FILES - "winreg.h" and "afxdisp.h" must be included in "stdafx.h" - - KEY NAMES: - Key names must not begin with a \ and only absolute strings are accepted - -*/ - - - -CRegistry::CRegistry() -{ - m_hRootKey = HKEY_CURRENT_USER; - m_bLazyWrite = TRUE; - m_nLastError = ERROR_SUCCESS; -} - -CRegistry::~CRegistry() -{ - ClearKey(); -} - - -BOOL CRegistry::ClearKey() -{ - /* Call CloseKey to write the current key to the registry and close the - key. An application should not keep keys open any longer than necessary. - Calling CloseKey when there is no current key has no effect.*/ - - m_strCurrentPath.Empty(); - m_hRootKey = HKEY_CURRENT_USER; - m_bLazyWrite = TRUE; - return TRUE; -} - - - -BOOL CRegistry::SetRootKey(HKEY hRootKey) -{ - // sets the root key - // make sure to set it to a valid key - if (hRootKey != HKEY_CLASSES_ROOT && - hRootKey != HKEY_CURRENT_USER && - hRootKey != HKEY_LOCAL_MACHINE && - hRootKey != HKEY_USERS) return FALSE; - - m_hRootKey = hRootKey; - return TRUE; -} - - -BOOL CRegistry::CreateKey(CString strKey) -{ - /* Use CreateKey to add a new key to the registry. - Key is the name of the key to create. Key must be - an absolute name. An absolute key - begins with a backslash (\) and is a subkey of - the root key. */ - - ASSERT(strKey[0] != '\\'); - HKEY hKey; - - DWORD dwDisposition = 0; - - if (::RegCreateKeyEx(m_hRootKey, LPCTSTR(strKey), 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, - &dwDisposition) != ERROR_SUCCESS) return FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - m_strCurrentPath = strKey; - return TRUE; -} - - -BOOL CRegistry::DeleteKey(CString strKey) -{ - /* Call DeleteKey to remove a specified key and its associated data, - if any, from the registry. Returns FALSE is there are subkeys - Subkeys must be explicitly deleted by separate calls to DeleteKey. - DeleteKey returns True if key deletion is successful. On error, - DeleteKey returns False. */ - - // need to open the key first with RegOpenKeyEx -// ASSERT(FALSE); // not yet implemented -// ASSERT(strKey[0] != '\\'); - - if (!KeyExists(strKey)) return TRUE; - if (::RegDeleteKey(m_hRootKey, strKey) != ERROR_SUCCESS) return FALSE; - return TRUE; -} - - - -BOOL CRegistry::DeleteValue(CString strName) -{ - /* Call DeleteValue to remove a specific data value - associated with the current key. Name is string - containing the name of the value to delete. Keys can contain - multiple data values, and every value associated with a key - has a unique name. */ - - ASSERT(m_strCurrentPath.GetLength() > 0); - HKEY hKey; - LONG lResult; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_SET_VALUE, &hKey) != ERROR_SUCCESS) return FALSE; - - lResult = ::RegDeleteValue(hKey, LPCTSTR(strName)); - ::RegCloseKey(hKey); - - if (lResult == ERROR_SUCCESS) return TRUE; - return FALSE; -} - - -int CRegistry::GetDataSize(CString strValueName) -{ - /* Call GetDataSize to determine the size, in bytes, of - a data value associated with the current key. ValueName - is a string containing the name of the data value to query. - On success, GetDataSize returns the size of the data value. - On failure, GetDataSize returns -1. */ - - HKEY hKey; - ASSERT(m_strCurrentPath.GetLength() > 0); - LONG lResult; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) return -1; - - DWORD dwSize = 1; - lResult = ::RegQueryValueEx(hKey, LPCTSTR(strValueName), - NULL, NULL, NULL, &dwSize); - ::RegCloseKey(hKey); - - if (lResult != ERROR_SUCCESS) return -1; - return (int)dwSize; -} - -DWORD CRegistry::GetDataType(CString strValueName) -{ - HKEY hKey; - ASSERT(m_strCurrentPath.GetLength() > 0); - - m_nLastError = ::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_QUERY_VALUE, &hKey); - - if (m_nLastError != ERROR_SUCCESS) return 0; - - DWORD dwType = 1; - m_nLastError = ::RegQueryValueEx(hKey, LPCTSTR(strValueName), - NULL, &dwType, NULL, NULL); - ::RegCloseKey(hKey); - - if (m_nLastError == ERROR_SUCCESS) return dwType; - - return 0; -} - - - -int CRegistry::GetSubKeyCount() -{ - /* Call this function to determine the number of subkeys. - the function returns -1 on error */ - HKEY hKey; - ASSERT(m_strCurrentPath.GetLength() > 0); - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) return -1; - - LONG lResult; - DWORD dwSubKeyCount, dwValueCount, dwClassNameLength, - dwMaxSubKeyName, dwMaxValueName, dwMaxValueLength; - FILETIME ftLastWritten; - - _TCHAR szClassBuffer[CLASS_NAME_LENGTH]; - - dwClassNameLength = CLASS_NAME_LENGTH; - lResult = ::RegQueryInfoKey(hKey, szClassBuffer, &dwClassNameLength, - NULL, &dwSubKeyCount, &dwMaxSubKeyName, NULL, &dwValueCount, - &dwMaxValueName, &dwMaxValueLength, NULL, &ftLastWritten); - - ::RegCloseKey(hKey); - if (lResult != ERROR_SUCCESS) return -1; - - return (int)dwSubKeyCount; -} - - -int CRegistry::GetValueCount() -{ - /* Call this function to determine the number of subkeys. - the function returns -1 on error */ - HKEY hKey; - ASSERT(m_strCurrentPath.GetLength() > 0); - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) return -1; - - LONG lResult; - DWORD dwSubKeyCount, dwValueCount, dwClassNameLength, - dwMaxSubKeyName, dwMaxValueName, dwMaxValueLength; - FILETIME ftLastWritten; - - _TCHAR szClassBuffer[CLASS_NAME_LENGTH]; - - dwClassNameLength = CLASS_NAME_LENGTH; - lResult = ::RegQueryInfoKey(hKey, szClassBuffer, &dwClassNameLength, - NULL, &dwSubKeyCount, &dwMaxSubKeyName, NULL, &dwValueCount, - &dwMaxValueName, &dwMaxValueLength, NULL, &ftLastWritten); - - ::RegCloseKey(hKey); - if (lResult != ERROR_SUCCESS) return -1; - - return (int)dwValueCount; -} - - -BOOL CRegistry::KeyExists(CString strKey, HKEY hRootKey) -{ - /* Call KeyExists to determine if a key of a specified name exists. - Key is the name of the key for which to search. */ - - ASSERT(strKey[0] != '\\'); - HKEY hKey; - - if (hRootKey == NULL) hRootKey = m_hRootKey; - - LONG lResult = ::RegOpenKeyEx(hRootKey, LPCTSTR(strKey), 0, - KEY_ALL_ACCESS, &hKey); - ::RegCloseKey(hKey); - if (lResult == ERROR_SUCCESS) return TRUE; - return FALSE; -} - -BOOL CRegistry::SetKey(CString strKey, BOOL bCanCreate) -{ - /* Call SetKey to make a specified key the current key. Key is the - name of the key to open. If Key is null, the CurrentKey property - is set to the key specified by the RootKey property. - - CanCreate specifies whether to create the specified key if it does - not exist. If CanCreate is True, the key is created if necessary. - - Key is opened or created with the security access value KEY_ALL_ACCESS. - OpenKey only creates non-volatile keys, A non-volatile key is stored in - the registry and is preserved when the system is restarted. - - OpenKey returns True if the key is successfully opened or created */ - - ASSERT(strKey[0] != '\\'); - HKEY hKey; - - - // close the current key if it is open - if (strKey.GetLength() == 0) - { - m_strCurrentPath.Empty(); - return TRUE; - } - - DWORD dwDisposition; - if (bCanCreate) // open the key with RegCreateKeyEx - { - if (::RegCreateKeyEx(m_hRootKey, LPCTSTR(strKey), 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, - &dwDisposition) != ERROR_SUCCESS) return FALSE; - m_strCurrentPath = strKey; - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return TRUE; - } - - // otherwise, open the key without creating - // open key requires no initial slash - m_nLastError = ::RegOpenKeyEx(m_hRootKey, LPCTSTR(strKey), 0, - KEY_ALL_ACCESS, &hKey); - if (m_nLastError != ERROR_SUCCESS) return FALSE; - m_strCurrentPath = strKey; - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return TRUE; -} - - -BOOL CRegistry::ValueExists(CString strName) -{ - /* Call ValueExists to determine if a particular key exists in - the registry. Calling Value Exists is especially useful before - calling other TRegistry methods that operate only on existing keys. - - Name is the name of the data value for which to check. - ValueExists returns True if a match if found, False otherwise. */ - - HKEY hKey; - LONG lResult; - ASSERT(m_strCurrentPath.GetLength() > 0); - - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) return FALSE; - - lResult = ::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - NULL, NULL, NULL); - ::RegCloseKey(hKey); - - if (lResult == ERROR_SUCCESS) return TRUE; - return FALSE; -} - - -void CRegistry::RenameValue(CString strOldName, CString strNewName) -{ - /* Call RenameValue to change the name of a data value associated - with the current key. OldName is a string containing the current - name of the data value. NewName is a string containing the replacement - name for the data value. - - If OldName is the name of an existing data value for the current key, - and NewName is not the name of an existing data value for the current - key, RenameValue changes the data value name as specified. Otherwise - the current name remains unchanged. - */ - ASSERT(FALSE); // functionality not yet implemented -} - - - - -COleDateTime CRegistry::ReadDateTime(CString strName, COleDateTime dtDefault) -{ - /* Call ReadDate to read a date value from a specified data value - associated with the current key. Name is the name of the data value to read. - If successful, ReadDate returns a Delphi TDateTime value. The integral part - of a TDateTime value is the number of days that have passed since 12/30/1899. - The fractional part of a TDateTime value is the time of day. - On error, an exception is raised, and the value returned by this function - should be discarded. */ - - DWORD dwType = REG_BINARY; - COleDateTime dt; - DWORD dwSize = sizeof(dt); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return dtDefault; - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&dt, &dwSize) != ERROR_SUCCESS) dt = dtDefault; - ::RegCloseKey(hKey); - return dt; -} - - -double CRegistry::ReadFloat(CString strName, double fDefault) -{ - /* Call ReadFloat to read a float value from a specified - data value associated with the current key. Name is the name - of the data value to read. - - If successful, ReadFloat returns a double value. - On error, an exception is raised, and the value returned by - this function should be discarded. */ - - DWORD dwType = REG_BINARY; - double d; - DWORD dwSize = sizeof(d); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return fDefault; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&d, &dwSize) != ERROR_SUCCESS) d = fDefault; - ::RegCloseKey(hKey); - return d; -} - -CString CRegistry::ReadString(CString strName, CString strDefault) -{ - DWORD dwType = REG_SZ; - DWORD dwSize = 255; - BOOL bSuccess = TRUE; - _TCHAR sz[255]; - HKEY hKey; - - - ASSERT(m_strCurrentPath.GetLength() > 0); - - // make sure it is the proper type - dwType = GetDataType(strName); - - if (dwType != REG_SZ && dwType != REG_EXPAND_SZ) - { - return strDefault; - } - - m_nLastError = ::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey); - if (m_nLastError != ERROR_SUCCESS) return strDefault; - - m_nLastError = ::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)sz, &dwSize); - if (m_nLastError != ERROR_SUCCESS) bSuccess = FALSE; - ::RegCloseKey(hKey); - - if (!bSuccess) return strDefault; - return CString((LPCTSTR)sz); -} - -DWORD CRegistry::ReadDword(CString strName, DWORD dwDefault) -{ - DWORD dwType = REG_DWORD; - DWORD dw; - DWORD dwSize = sizeof(dw); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return dwDefault; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&dw, &dwSize) != ERROR_SUCCESS) dw = dwDefault; - ::RegCloseKey(hKey); - return dw; -} - - - -int CRegistry::ReadInt(CString strName, int nDefault) -{ - DWORD dwType = REG_BINARY; - int n; - DWORD dwSize = sizeof(n); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return nDefault; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&n, &dwSize) != ERROR_SUCCESS) n = nDefault; - ::RegCloseKey(hKey); - return n; -} - -bool CRegistry::Read(CString strName, bool &result) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - HKEY hKey; - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) - return false; - - BOOL b; - DWORD dwSize = sizeof(b); - DWORD dwType = REG_BINARY; - int ret = ::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, &dwType, (LPBYTE)&b, &dwSize); - ::RegCloseKey(hKey); - - if ( ret != ERROR_SUCCESS ) - return false; - - result = !!b; - - return true; -} - - -COLORREF CRegistry::ReadColor(CString strName, COLORREF rgbDefault) -{ - DWORD dwType = REG_BINARY; - COLORREF rgb; - DWORD dwSize = sizeof(rgb); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return rgbDefault; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&rgb, &dwSize) != ERROR_SUCCESS) rgb = rgbDefault; - ::RegCloseKey(hKey); - return rgb; -} - -BOOL CRegistry::ReadFont(CString strName, CFont* pFont) -{ - DWORD dwType = REG_BINARY; - DWORD dwSize = sizeof(LOGFONT); - BOOL bSuccess = TRUE; - HKEY hKey; - LOGFONT lf; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&lf, &dwSize) != ERROR_SUCCESS) bSuccess = FALSE; - ::RegCloseKey(hKey); - if (bSuccess) - { - pFont->Detach(); - pFont->CreateFontIndirect(&lf); - } - return bSuccess; -} - - -BOOL CRegistry::ReadPoint(CString strName, CPoint* pPoint) -{ - DWORD dwType = REG_BINARY; - DWORD dwSize = sizeof(CPoint); - BOOL bSuccess = TRUE; - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)pPoint, &dwSize) != ERROR_SUCCESS) bSuccess = FALSE; - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::ReadSize(CString strName, CSize* pSize) -{ - DWORD dwType = REG_BINARY; - DWORD dwSize = sizeof(CSize); - BOOL bSuccess = TRUE; - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)pSize, &dwSize) != ERROR_SUCCESS) bSuccess = FALSE; - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::ReadRect(CString strName, CRect* pRect) -{ - DWORD dwType = REG_BINARY; - DWORD dwSize = sizeof(CRect); - BOOL bSuccess = TRUE; - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)pRect, &dwSize) != ERROR_SUCCESS) bSuccess = FALSE; - ::RegCloseKey(hKey); - return bSuccess; -} - - - - -BOOL CRegistry::WriteBool(CString strName, BOOL bValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&bValue, sizeof(bValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) - ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::WriteDateTime(CString strName, COleDateTime dtValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&dtValue, sizeof(dtValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - - -BOOL CRegistry::WriteString(CString strName, CString strValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - _TCHAR sz[255]; - - if (strValue.GetLength() > 254) return FALSE; - -#ifdef _UNICODE - wstrcpy(sz, LPCTSTR(strValue)); -#else - strcpy(sz, LPCTSTR(strValue)); -#endif - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - -#ifdef _UNICODE - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_SZ, (LPBYTE)sz, wstrlen(sz) + 1) - != ERROR_SUCCESS) bSuccess = FALSE; -#else - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_SZ, (LPBYTE)sz, strlen(sz) + 1) - != ERROR_SUCCESS) bSuccess = FALSE; -#endif - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - - -BOOL CRegistry::WriteFloat(CString strName, double fValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&fValue, sizeof(fValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::WriteInt(CString strName, int nValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&nValue, sizeof(nValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::WriteDword(CString strName, DWORD dwValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&dwValue, sizeof(dwValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::WriteColor(CString strName, COLORREF rgbValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&rgbValue, sizeof(rgbValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - - -BOOL CRegistry::WriteFont(CString strName, CFont* pFont) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - LOGFONT lf; - pFont->GetLogFont(&lf); - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&lf, sizeof(lf)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - - -BOOL CRegistry::WritePoint(CString strName, CPoint* pPoint) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)pPoint, sizeof(CPoint)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - - -BOOL CRegistry::WriteSize(CString strName, CSize* pSize) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)pSize, sizeof(CSize)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::WriteRect(CString strName, CRect* pRect) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)pRect, sizeof(CRect)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - diff --git a/stepmania/src/smpackage/Registry.h b/stepmania/src/smpackage/Registry.h deleted file mode 100644 index 21dd72a51e..0000000000 --- a/stepmania/src/smpackage/Registry.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef REGISTRY_H -#define REGISTRY_H - -class CRegistry -{ -public: - CRegistry(); - ~CRegistry(); - - int m_nLastError; - -// CRegistry properties -protected: - HKEY m_hRootKey; - BOOL m_bLazyWrite; - CString m_strCurrentPath; - -public: - inline BOOL PathIsValid() const { return m_strCurrentPath.GetLength() > 0; } - inline CString GetCurrentPath() const { return m_strCurrentPath; } - inline HKEY GetRootKey() const { return m_hRootKey; } - -public: - BOOL ClearKey(); - BOOL SetRootKey(HKEY hRootKey); - BOOL CreateKey(CString strKey); - BOOL DeleteKey(CString strKey); - BOOL DeleteValue(CString strName); - int GetDataSize(CString strValueName); - DWORD GetDataType(CString strValueName); - int GetSubKeyCount(); - int GetValueCount(); - BOOL KeyExists(CString strKey, HKEY hRootKey = NULL); - BOOL SetKey(CString strKey, BOOL bCanCreate); - BOOL ValueExists(CString strName); - void RenameValue(CString strOldName, CString strNewName); - - // data reading functions - COleDateTime ReadDateTime(CString strName, COleDateTime dtDefault); - double ReadFloat(CString strName, double fDefault); - CString ReadString(CString strName, CString strDefault); - int ReadInt(CString strName, int nDefault); - BOOL ReadBool(CString strName, BOOL bDefault); - COLORREF ReadColor(CString strName, COLORREF rgbDefault); - BOOL ReadFont(CString strName, CFont* pFont); - BOOL ReadPoint(CString strName, CPoint* pPoint); - BOOL ReadSize(CString strName, CSize* pSize); - BOOL ReadRect(CString strName, CRect* pRect); - DWORD ReadDword(CString strName, DWORD dwDefault); - - /* Readers converted to a less silly mechanism below (do these as needed): - * return the value in result if found, otherwise return false. */ - bool Read(CString strName, bool &result); - - // data writing functions - BOOL WriteBool(CString strName, BOOL bValue); - BOOL WriteDateTime(CString strName, COleDateTime dtValue); - BOOL WriteString(CString strName, CString strValue); - BOOL WriteFloat(CString strName, double fValue); - BOOL WriteInt(CString strName, int nValue); - BOOL WriteColor(CString strName, COLORREF rgbValue); - BOOL WriteFont(CString strName, CFont* pFont); - BOOL WritePoint(CString strName, CPoint* pPoint); - BOOL WriteSize(CString strName, CSize* pSize); - BOOL WriteRect(CString strName, CRect* pRect); - BOOL WriteDword(CString strName, DWORD dwValue); - -};// end of CRegistry class definition - - -#endif \ No newline at end of file diff --git a/stepmania/src/smpackage/smpackage-net2003.vcproj b/stepmania/src/smpackage/smpackage-net2003.vcproj deleted file mode 100644 index facc1675a5..0000000000 --- a/stepmania/src/smpackage/smpackage-net2003.vcproj +++ /dev/null @@ -1,613 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -