Tired of fighting with MFC; switch arrays to vector.

Update IniFile and some of RageUitl.  Can't do everything, since it's
still using MFC CString.
This commit is contained in:
Glenn Maynard
2003-07-23 00:47:23 +00:00
parent 212af912f1
commit 33a835ff31
12 changed files with 372 additions and 396 deletions
+3 -5
View File
@@ -55,7 +55,7 @@ BOOL EditInsallations::OnInitDialog()
CStringArray asInstallDirs; CStringArray asInstallDirs;
GetStepManiaInstallDirs( asInstallDirs ); GetStepManiaInstallDirs( asInstallDirs );
for( int i=0; i<asInstallDirs.GetSize(); i++ ) for( unsigned i=0; i<asInstallDirs.size(); i++ )
m_list.AddString( asInstallDirs[i] ); m_list.AddString( asInstallDirs[i] );
@@ -114,15 +114,13 @@ void EditInsallations::OnButtonAdd()
void EditInsallations::OnOK() void EditInsallations::OnOK()
{ {
// TODO: Add extra validation here m_asReturnedInstallDirs.clear();
m_asReturnedInstallDirs.RemoveAll();
for( int i=0; i<m_list.GetCount(); i++ ) for( int i=0; i<m_list.GetCount(); i++ )
{ {
CString sDir; CString sDir;
m_list.GetText( i, sDir ); m_list.GetText( i, sDir );
m_asReturnedInstallDirs.Add( sDir ); m_asReturnedInstallDirs.push_back( sDir );
} }
CDialog::OnOK(); CDialog::OnOK();
+23 -13
View File
@@ -93,33 +93,35 @@ void EditMetricsDlg::RefreshTree()
iniCombined.ReadFile(); iniCombined.ReadFile();
CStringArray asKeys; CStringArray asKeys;
asKeys.Copy( iniCombined.names ); IniFile::const_iterator it;
for( it = iniCombined.begin(); it != iniCombined.end(); ++it )
asKeys.push_back( it->first );
SortCStringArray( asKeys ); SortCStringArray( asKeys );
for( int i=0; i<asKeys.GetSize(); i++ ) for( unsigned i=0; i<asKeys.size(); i++ )
{ {
CString sKey = asKeys[i]; CString sKey = asKeys[i];
bool bInBase = iniBase.FindKey(sKey) != -1; bool bInBase = iniBase.GetKey(sKey) != NULL;
bool bInTheme = iniTheme.FindKey(sKey) != -1; bool bInTheme = iniTheme.GetKey(sKey) != NULL;
HTREEITEM item1 = m_tree.InsertItem( sKey ); HTREEITEM item1 = m_tree.InsertItem( sKey );
SET_ITEM_STYLE( item1, bInBase, bInTheme ); SET_ITEM_STYLE( item1, bInBase, bInTheme );
IniFile::key* pKey = iniCombined.GetKeyPointer( sKey ); const IniFile::key* pKey = iniCombined.GetKey( sKey );
CStringArray asNames; CStringArray asNames;
for( POSITION pos=pKey->GetStartPosition(); pos != NULL; ) for( IniFile::key::const_iterator val = pKey->begin(); val != pKey->end(); ++val )
{ {
CString sName, sValue; CString sName = val->first, sValue = val->second;
pKey->GetNextAssoc( pos, sName, sValue ); asNames.push_back( sName );
asNames.Add( sName );
} }
SortCStringArray( asNames ); SortCStringArray( asNames );
for( int j=0; j<asNames.GetSize(); j++ ) for( unsigned j=0; j<asNames.size(); j++ )
{ {
CString sName = asNames[j]; CString sName = asNames[j];
CString sValue = iniCombined.GetValue( sKey, sName ); CString sValue;
iniCombined.GetValue( sKey, sName, sValue );
CString sThrowAway; CString sThrowAway;
bool bInBase = !!iniBase.GetValue( sKey, sName, sThrowAway ); bool bInBase = !!iniBase.GetValue( sKey, sName, sThrowAway );
@@ -176,8 +178,16 @@ void EditMetricsDlg::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
m_buttonOverride.EnableWindow( bInBase && !bInTheme ); m_buttonOverride.EnableWindow( bInBase && !bInTheme );
m_buttonRemove.EnableWindow( bInTheme ); m_buttonRemove.EnableWindow( bInTheme );
m_editValue.EnableWindow( bInTheme ); m_editValue.EnableWindow( bInTheme );
m_editValue.SetWindowText( bInTheme ? iniTheme.GetValue(sKey,sName) : "" ); if( bInTheme )
m_editDefault.SetWindowText( bInBase ? iniBase.GetValue(sKey,sName) : "" ); {
CString n;
iniTheme.GetValue(sKey,sName, n);
m_editValue.SetWindowText( n );
m_editDefault.SetWindowText( n );
} else {
m_editValue.SetWindowText( "" );
m_editDefault.SetWindowText( "" );
}
*pResult = 0; *pResult = 0;
} }
+180 -195
View File
@@ -13,15 +13,6 @@
#include "RageUtil.h" #include "RageUtil.h"
/////////////////////////////////////////////////////////////////////
// Construction/Destruction
/////////////////////////////////////////////////////////////////////
//default constructor
IniFile::IniFile()
{
}
//constructor, can specify pathname here instead of using SetPath later //constructor, can specify pathname here instead of using SetPath later
IniFile::IniFile(CString inipath) IniFile::IniFile(CString inipath)
{ {
@@ -34,269 +25,263 @@ IniFile::~IniFile()
} }
///////////////////////////////////////////////////////////////////// // sets path of ini file to read and write from
// Public Functions
/////////////////////////////////////////////////////////////////////
//sets path of ini file to read and write from
void IniFile::SetPath(CString newpath) void IniFile::SetPath(CString newpath)
{ {
path = newpath; path = newpath;
} }
//reads ini file specified using IniFile::SetPath() // reads ini file specified using IniFile::SetPath()
//returns true if successful, false otherwise // returns true if successful, false otherwise
BOOL IniFile::ReadFile() bool IniFile::ReadFile()
{ {
CStdioFile file; FILE *f = fopen(path, "r");
if( !file.Open(path, CFile::modeRead) )
if (f == NULL)
{ {
error = "Unable to open ini file."; error = ssprintf("Unable to open ini file: %s", strerror(errno));
return FALSE; return 0;
} }
CString line; CString keyname;
int curkey = -1, curval = -1; char buf[10240];
CString keyname, valuename, value; while (fgets(buf, sizeof(buf), f))
while( file.ReadString(line) )
{ {
if( line != "" ) buf[sizeof(buf)-1]=0;
CString line(buf);
if(line.GetLength() >= 3 &&
line[0] == '\xef' &&
line[1] == '\xbb' &&
line[2] == '\xbf'
)
{ {
if( line[0] == '[' && line[line.GetLength()-1] == ']' ) //if a section heading /* Obnoxious NT marker for UTF-8. Remove it. */
line.Delete(0, 3);
}
if (line == "")
continue;
StripCrnl(line);
if ((line.GetLength() >= 2 && line[0] == '/' && line[1] == '/') || line[0] == '#')
continue; /* comment */
if (line[0] == '[' && line[line.GetLength()-1] == ']') //if a section heading
{ {
keyname = line; keyname = line;
keyname.TrimLeft('['); keyname.Delete(0);
keyname.TrimRight(']'); keyname.Delete(keyname.GetLength()-1);
} }
else //if a value else //if a value
{ {
int iIndexOfEqual = line.Find("="); int iEqualIndex = line.Find("=");
if( iIndexOfEqual == -1 ) // this is a malformed line if( iEqualIndex != -1 )
continue; {
valuename = line.Left( iIndexOfEqual ); CString valuename = line.Left(iEqualIndex);
value = line.Right(line.GetLength()-valuename.GetLength()-1); CString value = line.Right(line.GetLength()-valuename.GetLength()-1);
SetValue(keyname,valuename,value); SetValue(keyname,valuename,value);
} }
} }
} }
file.Close();
fclose(f);
return 1; return 1;
} }
//writes data stored in class to ini file // writes data stored in class to ini file
void IniFile::WriteFile() void IniFile::WriteFile()
{ {
CStdioFile file; FILE* fp = fopen( path, "w" );
if( !file.Open(path, CFile::modeCreate | CFile::modeWrite ) )
{ if( fp == NULL )
error = "Unable to open ini for writing.";
return; return;
}
// foreach key for (keymap::const_iterator k = keys.begin(); k != keys.end(); ++k)
for( int keynum = 0; keynum <= names.GetUpperBound(); keynum++ )
{ {
CString sTemp; if (k->second.empty())
sTemp.Format( "[%s]\n", names[keynum] ); continue;
file.WriteString( sTemp );
CMapStringToString &map = keys[keynum]; fprintf( fp, "[%s]\n", (const char *) k->first );
CStringArray as; for (key::const_iterator i = k->second.begin(); i != k->second.end(); ++i)
fprintf( fp, "%s=%s\n", (const char *)i->first, (const char *)i->second );
// for each value_name/value pair fprintf( fp, "\n" );
for( POSITION pos = map.GetStartPosition(); pos != NULL; )
{
CString value_name;
CString value;
map.GetNextAssoc( pos, value_name, value );
sTemp.Format( "%s=%s\n", value_name, value );
as.Add( sTemp );
} }
fclose( fp );
SortCStringArray( as );
for( int i=0; i<as.GetSize(); i++ )
file.WriteString( as[i] );
file.WriteString( "\n" );
}
file.Close();
} }
//deletes all stored ini data // deletes all stored ini data
void IniFile::Reset() void IniFile::Reset()
{ {
keys.SetSize(0); keys.clear();
names.SetSize(0);
} }
//returns number of keys currently in the ini // returns number of keys currently in the ini
int IniFile::GetNumKeys() int IniFile::GetNumKeys() const
{ {
return keys.GetSize(); return keys.size();
} }
//returns a pointer to the key for direct modification // returns number of values stored for specified key, or -1 if key not found
CMapStringToString* IniFile::GetKeyPointer( CString keyname ) int IniFile::GetNumValues(const CString &keyname) const
{ {
int keynum = FindKey(keyname); keymap::const_iterator k = keys.find(keyname);
if (keynum == -1) if (k == keys.end())
return NULL;
else
return &keys[keynum];
}
//returns number of values stored for specified key, or -1 if key not found
int IniFile::GetNumValues(CString keyname)
{
int keynum = FindKey(keyname);
if (keynum == -1)
return -1; return -1;
else
return keys[keynum].GetCount(); return k->second.size();
} }
//gets value of [keyname] valuename = // gets value of [keyname] valuename =
//overloaded to return CString, int, and double bool IniFile::GetValue(const CString &keyname, const CString &valuename, CString& value) const
BOOL IniFile::GetValue(CString keyname, CString valuename, CString value_out)
{ {
int keynum = FindKey(keyname);//, valuenum = FindValue(keynum,valuename); keymap::const_iterator k = keys.find(keyname);
if( keynum == -1 ) if (k == keys.end())
{ {
error = "Unable to locate specified key."; error = "Unable to locate specified key.";
return FALSE; return false;
} }
CMapStringToString &map = keys[keynum]; key::const_iterator i = k->second.find(valuename);
if( !map.Lookup(valuename, value_out) )
if (i == k->second.end())
{ {
error = "Unable to locate specified value."; error = "Unable to locate specified value.";
return FALSE; return false;
}
return TRUE;
}
//gets value of [keyname] valuename =
//overloaded to return CString, int, and double
CString IniFile::GetValue(CString keyname, CString valuename)
{
int keynum = FindKey(keyname);//, valuenum = FindValue(keynum,valuename);
if( keynum == -1 )
{
error = "Unable to locate specified key.";
return "";
} }
CMapStringToString &map = keys[keynum]; value = i->second;
CString value; return true;
if( !map.Lookup(valuename, value) )
{
error = "Unable to locate specified value.";
return "";
}
return value;
} }
//gets value of [keyname] valuename = // gets value of [keyname] valuename =
//overloaded to return CString, int, and double bool IniFile::GetValueI(const CString &keyname, const CString &valuename, int& value) const
int IniFile::GetValueI(CString keyname, CString valuename)
{ {
return atoi( GetValue(keyname,valuename) ); CString sValue;
if( !GetValue(keyname,valuename,sValue) )
return false;
sscanf( sValue, "%d", &value );
return true;
} }
//gets value of [keyname] valuename = bool IniFile::GetValueU(const CString &keyname, const CString &valuename, unsigned &value) const
//overloaded to return CString, int, and double
double IniFile::GetValueF(CString keyname, CString valuename)
{ {
return atof( GetValue(keyname, valuename) ); CString sValue;
if( !GetValue(keyname,valuename,sValue) )
return false;
sscanf( sValue, "%u", &value );
return true;
} }
//sets value of [keyname] valuename =. // gets value of [keyname] valuename =
//specify the optional paramter as false (0) if you do not want it to create bool IniFile::GetValueF(const CString &keyname, const CString &valuename, float& value) const
//the key if it doesn't exist. Returns true if data entered, false otherwise
//overloaded to accept CString, int, and double
BOOL IniFile::SetValue(CString keyname, CString valuename, CString value, BOOL create)
{ {
int keynum = FindKey(keyname); CString sValue;
if( !GetValue(keyname,valuename,sValue) )
if( keynum == -1 ) //if key doesn't exist return false;
{ sscanf( sValue, "%f", &value );
if( !create ) //and user does not want to create it, return true;
return FALSE; //stop entering this key
names.SetSize(names.GetSize()+1);
keys.SetSize(keys.GetSize()+1);
keynum = names.GetSize()-1;
names[keynum] = keyname;
}
// insert value
CMapStringToString &map = keys[keynum];
CString oldvalue;
if( !map.Lookup(valuename, oldvalue) && !create )
return FALSE;
map[valuename] = value;
return TRUE;
} }
//sets value of [keyname] valuename =. // gets value of [keyname] valuename =
//specify the optional paramter as false (0) if you do not want it to create bool IniFile::GetValueB(const CString &keyname, const CString &valuename, bool& value) const
//the key if it doesn't exist. Returns true if data entered, false otherwise
//overloaded to accept CString, int, and double
BOOL IniFile::SetValueI(CString keyname, CString valuename, int value, BOOL create)
{ {
CString temp; CString sValue;
temp.Format("%d",value); if( !GetValue(keyname,valuename,sValue) )
return SetValue(keyname, valuename, temp, create); return false;
value = atoi(sValue) != 0;
return true;
} }
//sets value of [keyname] valuename =. // sets value of [keyname] valuename =.
//specify the optional paramter as false (0) if you do not want it to create // 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 // the key if it doesn't exist. Returns true if data entered, false otherwise
//overloaded to accept CString, int, and double bool IniFile::SetValue(const CString &keyname, const CString &valuename, const CString &value, bool create)
BOOL IniFile::SetValueF(CString keyname, CString valuename, double value, BOOL create)
{ {
CString temp; if (!create && keys.find(keyname) == keys.end()) //if key doesn't exist
temp.Format("%e",value); return false; // stop entering this key
return SetValue(keyname, valuename, temp, create);
// find value
if (!create && keys[keyname].find(valuename) == keys[keyname].end())
return false;
keys[keyname][valuename] = value;
return true;
} }
//deletes specified value // sets value of [keyname] valuename =.
//returns true if value existed and deleted, false otherwise // specify the optional paramter as false (0) if you do not want it to create
BOOL IniFile::DeleteValue(CString keyname, CString valuename) // 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)
{ {
int keynum = FindKey(keyname); return SetValue(keyname, valuename, ssprintf("%d",value), create);
if( keynum == -1 )
return FALSE;
CMapStringToString &map = keys[keynum];
return map.RemoveKey( valuename );
} }
//deletes specified key and all values contained within bool IniFile::SetValueU(const CString &keyname, const CString &valuename, unsigned value, bool create)
//returns true if key existed and deleted, false otherwise
BOOL IniFile::DeleteKey(CString keyname)
{ {
int keynum = FindKey(keyname); return SetValue(keyname, valuename, ssprintf("%u",value), create);
if (keynum == -1)
return 0;
keys.RemoveAt(keynum);
names.RemoveAt(keynum);
return 1;
} }
///////////////////////////////////////////////////////////////////// bool IniFile::SetValueF(const CString &keyname, const CString &valuename, float value, bool create)
// Private Functions
/////////////////////////////////////////////////////////////////////
//returns index of specified key, or -1 if not found
int IniFile::FindKey(CString keyname)
{ {
int keynum = 0; return SetValue(keyname, valuename, ssprintf("%f",value), create);
while ( keynum < keys.GetSize() && names[keynum] != keyname)
keynum++;
if (keynum == keys.GetSize())
return -1;
return keynum;
} }
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);
}
+49 -53
View File
@@ -1,72 +1,59 @@
#ifndef INIFILE_H
#define INIFILE_H
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
File: IniFile.h Class: IniFile
Desc: Wrapper for reading and writing an .ini file. Desc: Wrapper for reading and writing an .ini file.
Copyright (c) 2001-2002 by the persons listed below. All rights reserved. Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Adam Clauss
Chris Danford
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include <map>
#ifndef _INIFILE_H_ using namespace std;
#define _INIFILE_H_
#include <afxtempl.h>
//#include <iostream.h>
class IniFile class IniFile
{ {
//all private variables
public: public:
// all keys are of this type
typedef map<CString, CString> key;
typedef map<CString, key> 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 //stores pathname of ini file to read/write
CString path; CString path;
//all keys are of this time // keys in ini
typedef CMapStringToString key; keymap keys;
//list of keys in ini
CArray<key, key> keys;
//corresponding list of keynames
CStringArray names;
//all private functions
//private:
//returns index of specified key, or -1 if not found
int FindKey(CString keyname);
//public variables
public: public:
//will contain error info if one occurs //will contain error info if one occurs
//ended up not using much, just in ReadFile and GetValue //ended up not using much, just in ReadFile and GetValue
CString error; mutable CString error;
//public functions
public:
//default constructor
IniFile();
//constructor, can specify pathname here instead of using SetPath later //constructor, can specify pathname here instead of using SetPath later
IniFile(CString inipath); IniFile(CString inipath = "");
//default destructor //default destructor
virtual ~IniFile(); virtual ~IniFile();
//sets path of ini file to read and write from //sets path of ini file to read and write from
void SetPath(CString newpath); void SetPath(CString newpath);
CString GetPath() const { return path; }
//reads ini file specified using IniFile::SetPath() //reads ini file specified using IniFile::SetPath()
//returns true if successful, false otherwise //returns true if successful, false otherwise
BOOL ReadFile(); bool ReadFile();
//writes data stored in class to ini file //writes data stored in class to ini file
void WriteFile(); void WriteFile();
@@ -75,38 +62,47 @@ public:
void Reset(); void Reset();
//returns number of keys currently in the ini //returns number of keys currently in the ini
int GetNumKeys(); int GetNumKeys() const;
//returns a pointer to the key for direct modification
CMapStringToString* GetKeyPointer( CString keyname );
//returns number of values stored for specified key //returns number of values stored for specified key
int GetNumValues( CString keyname ); int GetNumValues(const CString &keyname) const;
//gets value of [keyname] valuename = //gets value of [keyname] valuename =
//overloaded to return CString, int, and double,
//returns "", or 0 if key/value not found. Sets error member to show problem //returns "", or 0 if key/value not found. Sets error member to show problem
BOOL GetValue(CString keyname, CString valuename, CString value_out); bool GetValue(const CString &key, const CString &valuename, CString& value) const;
CString GetValue(CString keyname, CString valuename); bool GetValueI(const CString &key, const CString &valuename, int& value) const;
int GetValueI(CString keyname, CString valuename); bool GetValueU(const CString &key, const CString &valuename, unsigned& value) const;
double GetValueF(CString keyname, CString valuename); 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 =. //sets value of [keyname] valuename =.
//specify the optional paramter as false (0) if you do not want it to create //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 //the key if it doesn't exist. Returns true if data entered, false otherwise
//overloaded to accept CString, int, and double bool SetValue(const CString &key, const CString &valuename, const CString &value, bool create = 1);
BOOL SetValue(CString key, CString valuename, CString value, BOOL create = 1); bool SetValueI(const CString &key, const CString &valuename, int value, bool create = 1);
BOOL SetValueI(CString key, CString valuename, int value, BOOL create = 1); bool SetValueU(const CString &key, const CString &valuename, unsigned value, bool create = 1);
BOOL SetValueF(CString key, CString valuename, double 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 //deletes specified value
//returns true if value existed and deleted, false otherwise //returns true if value existed and deleted, false otherwise
BOOL DeleteValue(CString keyname, CString valuename); bool DeleteValue(const CString &keyname, const CString &valuename);
//deletes specified key and all values contained within //deletes specified key and all values contained within
//returns true if key existed and deleted, false otherwise //returns true if key existed and deleted, false otherwise
BOOL DeleteKey(CString keyname); 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 #endif
+38 -50
View File
@@ -12,6 +12,7 @@
*/ */
#include "RageUtil.h" #include "RageUtil.h"
#include <algorithm>
ULONG randseed = time(NULL); ULONG randseed = time(NULL);
@@ -34,8 +35,8 @@ float TimeToSeconds( CString sHMS )
CStringArray arrayBits; CStringArray arrayBits;
split( sHMS, ":", arrayBits, false ); split( sHMS, ":", arrayBits, false );
while( arrayBits.GetSize() < 3 ) while( arrayBits.size() < 3 )
arrayBits.InsertAt( 0, "0" ); // pad missing bits arrayBits.insert(arrayBits.begin(), "0" ); // pad missing bits
float fSeconds = 0; float fSeconds = 0;
fSeconds += atoi( arrayBits[0] ) * 60 * 60; fSeconds += atoi( arrayBits[0] ) * 60 * 60;
@@ -84,22 +85,20 @@ CString vssprintf( LPCTSTR fmt, va_list argList)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
CString join( const CString &Deliminator, const CStringArray& Source) CString join( const CString &Deliminator, const CStringArray& Source)
{ {
if( Source.GetSize() == 0 ) if( Source.empty() )
return ""; return "";
CString csReturn;
CString csTmp; CString csTmp;
// Loop through the Array and Append the Deliminator // Loop through the Array and Append the Deliminator
for( int iNum = 0; iNum < Source.GetSize()-1; iNum++ ) { for( unsigned iNum = 0; iNum < Source.size()-1; iNum++ ) {
csTmp += Source.GetAt(iNum); csTmp += Source[iNum];
csTmp += Deliminator; csTmp += Deliminator;
} }
csTmp += Source.GetAt( Source.GetSize()-1 ); csTmp += Source.back();
return csTmp; return csTmp;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: split() // Name: split()
// Desc: // Desc:
@@ -122,7 +121,7 @@ void split( const CString &Source, const CString &Deliminator, CStringArray& Add
if( newCString.IsEmpty() && bIgnoreEmpty ) if( newCString.IsEmpty() && bIgnoreEmpty )
; // do nothing ; // do nothing
else else
AddIt.Add(AddCString); AddIt.push_back(AddCString);
tmpCString = newCString.Mid(pos + Deliminator.GetLength()); tmpCString = newCString.Mid(pos + Deliminator.GetLength());
newCString = tmpCString; newCString = tmpCString;
@@ -132,10 +131,12 @@ void split( const CString &Source, const CString &Deliminator, CStringArray& Add
if( newCString.IsEmpty() && bIgnoreEmpty ) if( newCString.IsEmpty() && bIgnoreEmpty )
; // do nothing ; // do nothing
else else
AddIt.Add(newCString); AddIt.push_back(newCString);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Name: splitpath() // Name: splitpath()
// Desc: // Desc:
@@ -212,49 +213,36 @@ void splitpath( const bool UsingDirsOnly, const CString &Path, CString& Drive, C
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void splitrelpath( const CString &Path, CString& Dir, CString& FName, CString& Ext ) void splitrelpath( const CString &Path, CString& Dir, CString& FName, CString& Ext )
{ {
// need to split on both forward slashes and back slashes /* Find the last slash or backslash. */
CStringArray sPathBits; int Last = max(Path.ReverseFind('/'), Path.ReverseFind('\\'));
CStringArray sBackShashPathBits; /* Set 'Last' to the first character of the filename. If we have
split( Path, "\\", sBackShashPathBits, true ); * no directory separators, this is the entire string, so set it
* to 0. */
if(Last == -1) Last = 0;
else Last++;
for( int i=0; i<sBackShashPathBits.GetSize(); i++ ) // foreach backslash bit CString sFNameAndExt = Path.Right(Path.GetLength()-Last);
{
CStringArray sForwardShashPathBits;
split( sBackShashPathBits[i], "/", sForwardShashPathBits, true );
sPathBits.Append( sForwardShashPathBits );
}
if( sPathBits.GetSize() == 0 )
{
Dir = FName = Ext = "";
return;
}
CString sFNameAndExt = sPathBits[ sPathBits.GetSize()-1 ];
// subtract the FNameAndExt from Path // subtract the FNameAndExt from Path
Dir = Path.Left( Path.GetLength()-sFNameAndExt.GetLength() ); // don't subtract out the trailing slash Dir = Path.Left( Path.GetLength()-sFNameAndExt.GetLength() ); // don't subtract out the trailing slash
CStringArray sFNameAndExtBits; CStringArray sFNameAndExtBits;
split( sFNameAndExt, ".", sFNameAndExtBits, false ); split( sFNameAndExt, ".", sFNameAndExtBits, false );
if( sFNameAndExtBits.GetSize() == 0 ) // no file at the end of this path if( sFNameAndExt.GetLength() == 0 ) // no file at the end of this path
{ {
FName = ""; FName = "";
Ext = ""; Ext = "";
} }
else if( sFNameAndExtBits.GetSize() == 1 ) // file doesn't have extension else if( sFNameAndExtBits.size() == 1 ) // file doesn't have extension
{ {
FName = sFNameAndExtBits[0]; FName = sFNameAndExtBits[0];
Ext = ""; Ext = "";
} }
else if( sFNameAndExtBits.GetSize() > 1 ) // file has extension and possibly multiple periods else if( sFNameAndExtBits.size() > 1 ) // file has extension and possibly multiple periods
{ {
Ext = sFNameAndExtBits[ sFNameAndExtBits.GetSize()-1 ]; Ext = sFNameAndExtBits[ sFNameAndExtBits.size()-1 ];
// subtract the Ext and last period from FNameAndExt // subtract the Ext and last period from FNameAndExt
FName = sFNameAndExt.Left( sFNameAndExt.GetLength()-Ext.GetLength()-1 ); FName = sFNameAndExt.Left( sFNameAndExt.GetLength()-Ext.GetLength()-1 );
@@ -284,9 +272,9 @@ void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bRe
continue; continue;
if( bReturnPathToo ) if( bReturnPathToo )
AddTo.Add( sDir + sDirName ); AddTo.push_back( sDir + sDirName );
else else
AddTo.Add( sDirName ); AddTo.push_back( sDirName );
} while( ::FindNextFile( hFind, &fd ) ); } while( ::FindNextFile( hFind, &fd ) );
@@ -460,7 +448,7 @@ int GetHashForDirectory( CString sDir )
CStringArray arrayFiles; CStringArray arrayFiles;
GetDirListing( sDir+"\\*.*", arrayFiles, false ); GetDirListing( sDir+"\\*.*", arrayFiles, false );
for( int i=0; i<arrayFiles.GetSize(); i++ ) for( unsigned i=0; i<arrayFiles.size(); i++ )
{ {
const CString sFilePath = sDir + arrayFiles[i]; const CString sFilePath = sDir + arrayFiles[i];
hash += GetHashForFile( sFilePath ); hash += GetHashForFile( sFilePath );
@@ -507,27 +495,27 @@ bool IsADirectory( const CString &sPath )
} }
bool CompareCStringsAsc(const CString &str1, const CString &str2)
int CompareCStringsAsc(const void *arg1, const void *arg2)
{ {
CString str1 = *(CString *)arg1; return str1.CompareNoCase( str2 ) < 0;
CString str2 = *(CString *)arg2;
return str1.CompareNoCase( str2 );
} }
int CompareCStringsDesc(const void *arg1, const void *arg2) bool CompareCStringsDesc(const CString &str1, const CString &str2)
{ {
CString str1 = *(CString *)arg1; return str1.CompareNoCase( str2 ) > 0;
CString str2 = *(CString *)arg2;
return str2.CompareNoCase( str1 );
} }
void SortCStringArray( CStringArray &arrayCStrings, const bool bSortAcsending ) void SortCStringArray( CStringArray &arrayCStrings, const bool bSortAscending )
{ {
qsort( arrayCStrings.GetData(), arrayCStrings.GetSize(), sizeof(CString), bSortAcsending ? CompareCStringsAsc : CompareCStringsDesc ); 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) LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata)
{ {
+1 -2
View File
@@ -157,9 +157,8 @@ bool IsAFile( const CString &sPath );
bool IsADirectory( const CString &sPath ); bool IsADirectory( const CString &sPath );
DWORD GetFileSizeInBytes( const CString &sFilePath ); DWORD GetFileSizeInBytes( const CString &sFilePath );
int CompareCStringsAsc(const void *arg1, const void *arg2);
int CompareCStringsDesc(const void *arg1, const void *arg2);
void SortCStringArray( CStringArray &AddTo, const bool bSortAcsending = true ); void SortCStringArray( CStringArray &AddTo, const bool bSortAcsending = true );
void StripCrnl(CString &s);
LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata); LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata);
@@ -260,10 +260,8 @@ void CSMPackageInstallDlg::RefreshInstallationList()
CStringArray asInstallDirs; CStringArray asInstallDirs;
GetStepManiaInstallDirs( asInstallDirs ); GetStepManiaInstallDirs( asInstallDirs );
for( int i=0; i<asInstallDirs.GetSize(); i++ ) for( unsigned i=0; i<asInstallDirs.size(); i++ )
{
m_comboDir.AddString( asInstallDirs[i] ); m_comboDir.AddString( asInstallDirs[i] );
}
m_comboDir.SetCurSel( 0 ); // guaranteed to be at least one item m_comboDir.SetCurSel( 0 ); // guaranteed to be at least one item
} }
+6 -6
View File
@@ -8,7 +8,7 @@ void WriteStepManiaInstallDirs( const CStringArray& asInstallDirsToWrite )
Reg.SetRootKey(HKEY_LOCAL_MACHINE); Reg.SetRootKey(HKEY_LOCAL_MACHINE);
Reg.SetKey("Software\\StepMania\\smpackage\\Installations", TRUE); // create if not already present Reg.SetKey("Software\\StepMania\\smpackage\\Installations", TRUE); // create if not already present
int i; unsigned i;
for( i=0; i<100; i++ ) for( i=0; i<100; i++ )
{ {
@@ -17,7 +17,7 @@ void WriteStepManiaInstallDirs( const CStringArray& asInstallDirsToWrite )
Reg.WriteString( sName, "" ); Reg.WriteString( sName, "" );
} }
for( i=0; i<asInstallDirsToWrite.GetSize(); i++ ) for( i=0; i<asInstallDirsToWrite.size(); i++ )
{ {
CString sName = ssprintf("%d",i); CString sName = ssprintf("%d",i);
Reg.WriteString( sName, asInstallDirsToWrite[i] ); Reg.WriteString( sName, asInstallDirsToWrite[i] );
@@ -27,7 +27,7 @@ void WriteStepManiaInstallDirs( const CStringArray& asInstallDirsToWrite )
void GetStepManiaInstallDirs( CStringArray& asInstallDirsOut ) void GetStepManiaInstallDirs( CStringArray& asInstallDirsOut )
{ {
asInstallDirsOut.RemoveAll(); asInstallDirsOut.clear();
CRegistry Reg; CRegistry Reg;
Reg.SetRootKey(HKEY_LOCAL_MACHINE); Reg.SetRootKey(HKEY_LOCAL_MACHINE);
@@ -42,7 +42,7 @@ void GetStepManiaInstallDirs( CStringArray& asInstallDirsOut )
if( sPath == "" ) // read failed if( sPath == "" ) // read failed
continue; // skip continue; // skip
asInstallDirsOut.Add( sPath ); asInstallDirsOut.push_back( sPath );
} }
// while we're at it, write to clean up stale entries // while we're at it, write to clean up stale entries
@@ -55,7 +55,7 @@ void AddStepManiaInstallDir( CString sNewInstallDir )
GetStepManiaInstallDirs( asInstallDirs ); GetStepManiaInstallDirs( asInstallDirs );
bool bAlreadyInList = false; bool bAlreadyInList = false;
for( int i=0; i<asInstallDirs.GetSize(); i++ ) for( unsigned i=0; i<asInstallDirs.size(); i++ )
{ {
if( asInstallDirs[i].CompareNoCase(sNewInstallDir) == 0 ) if( asInstallDirs[i].CompareNoCase(sNewInstallDir) == 0 )
{ {
@@ -65,7 +65,7 @@ void AddStepManiaInstallDir( CString sNewInstallDir )
} }
if( !bAlreadyInList ) if( !bAlreadyInList )
asInstallDirs.Add( sNewInstallDir ); asInstallDirs.push_back( sNewInstallDir );
WriteStepManiaInstallDirs( asInstallDirs ); WriteStepManiaInstallDirs( asInstallDirs );
} }
+36 -32
View File
@@ -11,6 +11,10 @@
#include "smpackageUtil.h" #include "smpackageUtil.h"
#include "EditInsallations.h" #include "EditInsallations.h"
#include <vector>
#include <algorithm>
using namespace std;
#ifdef _DEBUG #ifdef _DEBUG
#define new DEBUG_NEW #define new DEBUG_NEW
#undef THIS_FILE #undef THIS_FILE
@@ -83,9 +87,9 @@ CString ReplaceInvalidFileNameChars( CString sOldFileName )
return sNewFileName; return sNewFileName;
} }
void GetFilePaths( CString sDirOrFile, CStringArray& asPathToFilesOut ) void GetFilePaths( CString sDirOrFile, vector<CString> &asPathToFilesOut )
{ {
CStringArray asDirectoriesToExplore; vector<CString> asDirectoriesToExplore;
// HACK: // HACK:
// Must use backslashes in the path, or else WinZip and WinRAR don't see the files. // Must use backslashes in the path, or else WinZip and WinRAR don't see the files.
@@ -99,18 +103,18 @@ void GetFilePaths( CString sDirOrFile, CStringArray& asPathToFilesOut )
if( IsAFile(sDirOrFile) ) if( IsAFile(sDirOrFile) )
{ {
asPathToFilesOut.Add( sDirOrFile ); asPathToFilesOut.push_back( sDirOrFile );
return; return;
} }
GetDirListing( sDirOrFile, asPathToFilesOut, false, true ); GetDirListing( sDirOrFile, asPathToFilesOut, false, true );
GetDirListing( sDirOrFile, asDirectoriesToExplore, true, true ); GetDirListing( sDirOrFile, asDirectoriesToExplore, true, true );
while( asDirectoriesToExplore.GetSize() > 0 ) while( asDirectoriesToExplore.size() > 0 )
{ {
GetDirListing( asDirectoriesToExplore[0] + "\\*.*", asPathToFilesOut, false, true ); GetDirListing( asDirectoriesToExplore[0] + "\\*.*", asPathToFilesOut, false, true );
GetDirListing( asDirectoriesToExplore[0] + "\\*.*", asDirectoriesToExplore, true, true ); GetDirListing( asDirectoriesToExplore[0] + "\\*.*", asDirectoriesToExplore, true, true );
asDirectoriesToExplore.RemoveAt( 0 ); asDirectoriesToExplore.erase( 0 );
} }
} }
@@ -163,15 +167,15 @@ bool ExportPackage( CString sPackageName, const CStringArray& asDirectoriesToExp
zip.SetGlobalComment( sComment ); zip.SetGlobalComment( sComment );
/* Find files to add to zip. */ /* Find files to add to zip. */
int i; unsigned i;
CStringArray asFilePaths; vector<CString> asFilePaths;
for( i=0; i<asDirectoriesToExport.GetSize(); i++ ) for( i=0; i<asDirectoriesToExport.size(); i++ )
GetFilePaths( asDirectoriesToExport[i], asFilePaths ); GetFilePaths( asDirectoriesToExport[i], asFilePaths );
// //
// Add files to zip // Add files to zip
// //
for( int j=0; j<asFilePaths.GetSize(); j++ ) for( unsigned j=0; j<asFilePaths.size(); j++ )
{ {
CString sFilePath = asFilePaths[j]; CString sFilePath = asFilePaths[j];
@@ -236,12 +240,12 @@ void CSmpackageExportDlg::OnButtonExportAsOne()
CStringArray asPaths; CStringArray asPaths;
GetCheckedPaths( asPaths ); GetCheckedPaths( asPaths );
if( asPaths.GetSize() == 0 ) if( asPaths.size() == 0 )
{ {
AfxMessageBox( "No items are checked" ); AfxMessageBox( "No items are checked" );
return; return;
} }
else if( asPaths.GetSize() == 1 ) else if( asPaths.size() == 1 )
{ {
OnButtonExportAsIndividual(); OnButtonExportAsIndividual();
return; return;
@@ -270,7 +274,7 @@ void CSmpackageExportDlg::OnButtonExportAsIndividual()
CStringArray asPaths; CStringArray asPaths;
GetCheckedPaths( asPaths ); GetCheckedPaths( asPaths );
if( asPaths.GetSize() == 0 ) if( asPaths.size() == 0 )
{ {
AfxMessageBox( "No items are checked" ); AfxMessageBox( "No items are checked" );
return; return;
@@ -284,7 +288,7 @@ void CSmpackageExportDlg::OnButtonExportAsIndividual()
bool bAllSucceeded = true; bool bAllSucceeded = true;
CStringArray asExportedPackages; CStringArray asExportedPackages;
CStringArray asFailedPackages; CStringArray asFailedPackages;
for( int i=0; i<asPaths.GetSize(); i++ ) for( unsigned i=0; i<asPaths.size(); i++ )
{ {
// Generate a package name for every path // Generate a package name for every path
CString sPath = asPaths[i]; CString sPath = asPaths[i];
@@ -292,21 +296,21 @@ void CSmpackageExportDlg::OnButtonExportAsIndividual()
CString sPackageName; CString sPackageName;
CStringArray asPathBits; CStringArray asPathBits;
split( sPath, "\\", asPathBits, true ); split( sPath, "\\", asPathBits, true );
sPackageName = asPathBits[ asPathBits.GetSize()-1 ] + ".smzip"; sPackageName = asPathBits[ asPathBits.size()-1 ] + ".smzip";
sPackageName = ReplaceInvalidFileNameChars( sPackageName ); sPackageName = ReplaceInvalidFileNameChars( sPackageName );
CStringArray asPathsToExport; CStringArray asPathsToExport;
asPathsToExport.Add( sPath ); asPathsToExport.push_back( sPath );
if( ExportPackage( sPackageName, asPathsToExport, sComment ) ) if( ExportPackage( sPackageName, asPathsToExport, sComment ) )
asExportedPackages.Add( sPackageName ); asExportedPackages.push_back( sPackageName );
else else
asFailedPackages.Add( sPackageName ); asFailedPackages.push_back( sPackageName );
} }
CString sMessage; CString sMessage;
if( asFailedPackages.GetSize() == 0 ) if( asFailedPackages.size() == 0 )
sMessage = ssprintf("Successfully exported the package%s '%s' to your Desktop.", asFailedPackages.GetSize()>1?"s":"", join("', '",asExportedPackages) ); sMessage = ssprintf("Successfully exported the package%s '%s' to your Desktop.", asFailedPackages.size()>1?"s":"", join("', '",asExportedPackages) );
else else
sMessage = ssprintf(" The packages %s failed to export.", join(", ",asFailedPackages) ); sMessage = ssprintf(" The packages %s failed to export.", join(", ",asFailedPackages) );
AfxMessageBox( sMessage ); AfxMessageBox( sMessage );
@@ -392,7 +396,7 @@ void CSmpackageExportDlg::GetCheckedPaths( CStringArray& aPathsOut )
sPath.TrimRight('\\'); // strip off last slash sPath.TrimRight('\\'); // strip off last slash
aPathsOut.Add( sPath ); aPathsOut.push_back( sPath );
} }
} }
@@ -416,7 +420,7 @@ void CSmpackageExportDlg::RefreshInstallationList()
CStringArray asInstallDirs; CStringArray asInstallDirs;
GetStepManiaInstallDirs( asInstallDirs ); GetStepManiaInstallDirs( asInstallDirs );
for( int i=0; i<asInstallDirs.GetSize(); i++ ) for( unsigned i=0; i<asInstallDirs.size(); i++ )
{ {
m_comboDir.AddString( asInstallDirs[i] ); m_comboDir.AddString( asInstallDirs[i] );
} }
@@ -443,7 +447,7 @@ void CSmpackageExportDlg::RefreshTree()
CStringArray as1; CStringArray as1;
HTREEITEM item1 = m_tree.InsertItem( "Announcers" ); HTREEITEM item1 = m_tree.InsertItem( "Announcers" );
GetDirListing( "Announcers\\*.*", as1, true, false ); GetDirListing( "Announcers\\*.*", as1, true, false );
for( int i=0; i<as1.GetSize(); i++ ) for( unsigned i=0; i<as1.size(); i++ )
m_tree.InsertItem( as1[i], item1 ); m_tree.InsertItem( as1[i], item1 );
} }
@@ -452,7 +456,7 @@ void CSmpackageExportDlg::RefreshTree()
CStringArray as1; CStringArray as1;
HTREEITEM item1 = m_tree.InsertItem( "Characters" ); HTREEITEM item1 = m_tree.InsertItem( "Characters" );
GetDirListing( "Characters\\*.*", as1, true, false ); GetDirListing( "Characters\\*.*", as1, true, false );
for( int i=0; i<as1.GetSize(); i++ ) for( unsigned i=0; i<as1.size(); i++ )
m_tree.InsertItem( as1[i], item1 ); m_tree.InsertItem( as1[i], item1 );
} }
@@ -461,7 +465,7 @@ void CSmpackageExportDlg::RefreshTree()
CStringArray as1; CStringArray as1;
HTREEITEM item1 = m_tree.InsertItem( "Themes" ); HTREEITEM item1 = m_tree.InsertItem( "Themes" );
GetDirListing( "Themes\\*.*", as1, true, false ); GetDirListing( "Themes\\*.*", as1, true, false );
for( int i=0; i<as1.GetSize(); i++ ) for( unsigned i=0; i<as1.size(); i++ )
m_tree.InsertItem( as1[i], item1 ); m_tree.InsertItem( as1[i], item1 );
} }
@@ -470,7 +474,7 @@ void CSmpackageExportDlg::RefreshTree()
CStringArray as1; CStringArray as1;
HTREEITEM item1 = m_tree.InsertItem( "BGAnimations" ); HTREEITEM item1 = m_tree.InsertItem( "BGAnimations" );
GetDirListing( "BGAnimations\\*.*", as1, true, false ); GetDirListing( "BGAnimations\\*.*", as1, true, false );
for( int i=0; i<as1.GetSize(); i++ ) for( unsigned i=0; i<as1.size(); i++ )
m_tree.InsertItem( as1[i], item1 ); m_tree.InsertItem( as1[i], item1 );
} }
@@ -481,7 +485,7 @@ void CSmpackageExportDlg::RefreshTree()
GetDirListing( "RandomMovies\\*.avi", as1, false, false ); GetDirListing( "RandomMovies\\*.avi", as1, false, false );
GetDirListing( "RandomMovies\\*.mpg", as1, false, false ); GetDirListing( "RandomMovies\\*.mpg", as1, false, false );
GetDirListing( "RandomMovies\\*.mpeg", as1, false, false ); GetDirListing( "RandomMovies\\*.mpeg", as1, false, false );
for( int i=0; i<as1.GetSize(); i++ ) for( unsigned i=0; i<as1.size(); i++ )
m_tree.InsertItem( as1[i], item1 ); m_tree.InsertItem( as1[i], item1 );
} }
@@ -492,7 +496,7 @@ void CSmpackageExportDlg::RefreshTree()
GetDirListing( "Visualizations\\*.avi", as1, false, false ); GetDirListing( "Visualizations\\*.avi", as1, false, false );
GetDirListing( "Visualizations\\*.mpg", as1, false, false ); GetDirListing( "Visualizations\\*.mpg", as1, false, false );
GetDirListing( "Visualizations\\*.mpeg", as1, false, false ); GetDirListing( "Visualizations\\*.mpeg", as1, false, false );
for( int i=0; i<as1.GetSize(); i++ ) for( unsigned i=0; i<as1.size(); i++ )
m_tree.InsertItem( as1[i], item1 ); m_tree.InsertItem( as1[i], item1 );
} }
@@ -501,7 +505,7 @@ void CSmpackageExportDlg::RefreshTree()
CStringArray as1; CStringArray as1;
HTREEITEM item1 = m_tree.InsertItem( "Courses" ); HTREEITEM item1 = m_tree.InsertItem( "Courses" );
GetDirListing( "Courses\\*.crs", as1, false, false ); GetDirListing( "Courses\\*.crs", as1, false, false );
for( int i=0; i<as1.GetSize(); i++ ) for( unsigned i=0; i<as1.size(); i++ )
{ {
as1[i] = as1[i].Left(as1[i].GetLength()-4); // strip off ".crs" as1[i] = as1[i].Left(as1[i].GetLength()-4); // strip off ".crs"
m_tree.InsertItem( as1[i], item1 ); m_tree.InsertItem( as1[i], item1 );
@@ -516,12 +520,12 @@ void CSmpackageExportDlg::RefreshTree()
CStringArray as1; CStringArray as1;
HTREEITEM item1 = m_tree.InsertItem( "NoteSkins" ); HTREEITEM item1 = m_tree.InsertItem( "NoteSkins" );
GetDirListing( "NoteSkins\\*.*", as1, true, false ); GetDirListing( "NoteSkins\\*.*", as1, true, false );
for( int i=0; i<as1.GetSize(); i++ ) for( unsigned i=0; i<as1.size(); i++ )
{ {
CStringArray as2; CStringArray as2;
HTREEITEM item2 = m_tree.InsertItem( as1[i], item1 ); HTREEITEM item2 = m_tree.InsertItem( as1[i], item1 );
GetDirListing( "NoteSkins\\" + as1[i] + "\\*.*", as2, true, false ); GetDirListing( "NoteSkins\\" + as1[i] + "\\*.*", as2, true, false );
for( int j=0; j<as2.GetSize(); j++ ) for( unsigned j=0; j<as2.size(); j++ )
m_tree.InsertItem( as2[j], item2 ); m_tree.InsertItem( as2[j], item2 );
} }
} }
@@ -533,12 +537,12 @@ void CSmpackageExportDlg::RefreshTree()
CStringArray as1; CStringArray as1;
HTREEITEM item1 = m_tree.InsertItem( "Songs" ); HTREEITEM item1 = m_tree.InsertItem( "Songs" );
GetDirListing( "Songs\\*.*", as1, true, false ); GetDirListing( "Songs\\*.*", as1, true, false );
for( int i=0; i<as1.GetSize(); i++ ) for( unsigned i=0; i<as1.size(); i++ )
{ {
CStringArray as2; CStringArray as2;
HTREEITEM item2 = m_tree.InsertItem( as1[i], item1 ); HTREEITEM item2 = m_tree.InsertItem( as1[i], item1 );
GetDirListing( "Songs\\" + as1[i] + "\\*.*", as2, true, false ); GetDirListing( "Songs\\" + as1[i] + "\\*.*", as2, true, false );
for( int j=0; j<as2.GetSize(); j++ ) for( unsigned j=0; j<as2.size(); j++ )
m_tree.InsertItem( as2[j], item2 ); m_tree.InsertItem( as2[j], item2 );
} }
} }
+3
View File
@@ -19,6 +19,9 @@
#include <afxcmn.h> // MFC support for Windows Common Controls #include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT #endif // _AFX_NO_AFXCMN_SUPPORT
#include <vector>
using namespace std;
#define CStringArray vector<CString>
//{{AFX_INSERT_LOCATION}} //{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+26 -31
View File
@@ -62,7 +62,7 @@ BOOL ConvertThemeDlg::OnInitDialog()
CStringArray asThemes; CStringArray asThemes;
GetDirListing( "Themes\\*.*", asThemes, true, false ); GetDirListing( "Themes\\*.*", asThemes, true, false );
for( int i=0; i<asThemes.GetSize(); i++ ) for( unsigned i=0; i<asThemes.size(); i++ )
// if( asThemes[i] != "default" ) // allow editing of default // if( asThemes[i] != "default" ) // allow editing of default
m_listThemes.AddString( asThemes[i] ); m_listThemes.AddString( asThemes[i] );
@@ -78,7 +78,7 @@ void RecursiveRename( CString sDirStart, CString sOld, CString sNew )
CStringArray asFilesAndDirs; CStringArray asFilesAndDirs;
GetDirListing( sDirStart+"*.*", asFilesAndDirs, false, false ); GetDirListing( sDirStart+"*.*", asFilesAndDirs, false, false );
for( int i=0; i<asFilesAndDirs.GetSize(); i++ ) for( unsigned i=0; i<asFilesAndDirs.size(); i++ )
{ {
CString sOldFilePath = sDirStart+asFilesAndDirs[i]; CString sOldFilePath = sDirStart+asFilesAndDirs[i];
CString sNewFilePath = sOldFilePath; CString sNewFilePath = sOldFilePath;
@@ -91,7 +91,7 @@ void RecursiveRename( CString sDirStart, CString sOld, CString sNew )
CStringArray asDirs; CStringArray asDirs;
GetDirListing( sDirStart+"*.*", asDirs, true, false ); GetDirListing( sDirStart+"*.*", asDirs, true, false );
for( i=0; i<asDirs.GetSize(); i++ ) for( i=0; i<asDirs.size(); i++ )
RecursiveRename( sDirStart+asDirs[i], sOld, sNew ); RecursiveRename( sDirStart+asDirs[i], sOld, sNew );
} }
@@ -331,9 +331,6 @@ void LaunchNotepad( CString sPathToOpen )
void ConvertThemeDlg::OnButtonAnalyze() void ConvertThemeDlg::OnButtonAnalyze()
{ {
// TODO: Add your control notification handler code here
int i;
CString sBaseDir = "Themes\\default\\"; CString sBaseDir = "Themes\\default\\";
int iSel = m_listThemes.GetCurSel(); int iSel = m_listThemes.GetCurSel();
CString sThemeName; CString sThemeName;
@@ -356,14 +353,15 @@ void ConvertThemeDlg::OnButtonAnalyze()
CStringArray asRedundant; CStringArray asRedundant;
CStringArray asWarning; CStringArray asWarning;
for( i=0; i<asThemeFilePaths.GetSize(); i++ ) unsigned i;
for( i=0; i<asThemeFilePaths.size(); i++ )
{ {
CString sThemeElement = asThemeFilePaths[i]; CString sThemeElement = asThemeFilePaths[i];
sThemeElement.Replace( sThemeDir, "" ); sThemeElement.Replace( sThemeDir, "" );
sThemeElement = StripExtension( sThemeElement ); sThemeElement = StripExtension( sThemeElement );
bool bFoundMatch = false; bool bFoundMatch = false;
for( int j=0; j<asBaseFilePaths.GetSize(); j++ ) for( unsigned j=0; j<asBaseFilePaths.size(); j++ )
{ {
CString sBaseElement = asBaseFilePaths[j]; CString sBaseElement = asBaseFilePaths[j];
sBaseElement.Replace( sBaseDir, "" ); sBaseElement.Replace( sBaseDir, "" );
@@ -373,12 +371,12 @@ void ConvertThemeDlg::OnButtonAnalyze()
{ {
bFoundMatch = true; bFoundMatch = true;
if( FilesAreIdentical( asThemeFilePaths[i], asBaseFilePaths[j] ) ) if( FilesAreIdentical( asThemeFilePaths[i], asBaseFilePaths[j] ) )
asRedundant.Add( asThemeFilePaths[i] ); asRedundant.push_back( asThemeFilePaths[i] );
break; // skip to next file in asThemeFilePaths break; // skip to next file in asThemeFilePaths
} }
} }
if( !bFoundMatch ) if( !bFoundMatch )
asWarning.Add( asThemeFilePaths[i] ); asWarning.push_back( asThemeFilePaths[i] );
} }
SortCStringArray( asRedundant ); SortCStringArray( asRedundant );
@@ -390,13 +388,13 @@ void ConvertThemeDlg::OnButtonAnalyze()
fprintf( fp, "The following elements are REDUNDANT.\n" fprintf( fp, "The following elements are REDUNDANT.\n"
" (These elements are identical to the elements in the base theme.\n" " (These elements are identical to the elements in the base theme.\n"
" They are unnecessary and should be deleted.)\n" ); " They are unnecessary and should be deleted.)\n" );
for( i=0; i<asRedundant.GetSize(); i++ ) for( i=0; i<asRedundant.size(); i++ )
fprintf( fp, asRedundant[i] + "\n" ); fprintf( fp, asRedundant[i] + "\n" );
fprintf( fp, "\n" ); fprintf( fp, "\n" );
fprintf( fp, "The following elements are possibly MISNAMED.\n" fprintf( fp, "The following elements are possibly MISNAMED.\n"
" (These files do not have a corresponding element in the base theme.\n" " (These files do not have a corresponding element in the base theme.\n"
" This likely means that there is an error in the file name.)\n" ); " This likely means that there is an error in the file name.)\n" );
for( i=0; i<asWarning.GetSize(); i++ ) for( i=0; i<asWarning.size(); i++ )
fprintf( fp, asWarning[i] + "\n" ); fprintf( fp, asWarning[i] + "\n" );
fclose( fp ); fclose( fp );
@@ -417,9 +415,6 @@ void ConvertThemeDlg::OnButtonEditMetrics()
void ConvertThemeDlg::OnButtonAnalyzeMetrics() void ConvertThemeDlg::OnButtonAnalyzeMetrics()
{ {
// TODO: Add your control notification handler code here
int i;
int iSel = m_listThemes.GetCurSel(); int iSel = m_listThemes.GetCurSel();
CString sThemeName; CString sThemeName;
m_listThemes.GetText( iSel, sThemeName ); m_listThemes.GetText( iSel, sThemeName );
@@ -433,27 +428,27 @@ void ConvertThemeDlg::OnButtonAnalyzeMetrics()
iniTheme.ReadFile(); iniTheme.ReadFile();
CMapStringToString mapBaseClassPlusNameToValue; CMapStringToString mapBaseClassPlusNameToValue;
for( i=0; i<iniBase.names.GetSize(); i++ ) unsigned i;
IniFile::const_iterator it;
for( it = iniBase.begin(); it != iniBase.end(); ++it )
{ {
CString sKey = iniBase.names[i]; CString sKey = it->first;
IniFile::key& Key = iniBase.keys[i]; const IniFile::key &Key = it->second;
for( POSITION pos=Key.GetStartPosition(); pos!=NULL; ) for( IniFile::key::const_iterator val = Key.begin(); val != Key.end(); ++val )
{ {
CString sName, sValue; CString sName = val->first, sValue = val->second;
Key.GetNextAssoc( pos, sName, sValue );
mapBaseClassPlusNameToValue[sKey+"-"+sName] = sValue; mapBaseClassPlusNameToValue[sKey+"-"+sName] = sValue;
} }
} }
CMapStringToString mapThemeClassPlusNameToValue; CMapStringToString mapThemeClassPlusNameToValue;
for( i=0; i<iniTheme.names.GetSize(); i++ ) for( it = iniTheme.begin(); it != iniTheme.end(); ++it )
{ {
CString sKey = iniTheme.names[i]; CString sKey = it->first;
IniFile::key& Key = iniTheme.keys[i]; const IniFile::key &Key = it->second;
for( POSITION pos=Key.GetStartPosition(); pos!=NULL; ) for( IniFile::key::const_iterator val = Key.begin(); val != Key.end(); ++val )
{ {
CString sName, sValue; CString sName = val->first, sValue = val->second;
Key.GetNextAssoc( pos, sName, sValue );
mapThemeClassPlusNameToValue[sKey+"-"+sName] = sValue; mapThemeClassPlusNameToValue[sKey+"-"+sName] = sValue;
} }
} }
@@ -476,12 +471,12 @@ void ConvertThemeDlg::OnButtonAnalyzeMetrics()
{ {
bFoundMatch = true; bFoundMatch = true;
if( sThemeValue == sBaseValue ) if( sThemeValue == sBaseValue )
asRedundant.Add( sThemeKey ); asRedundant.push_back( sThemeKey );
break; // skip to next file in asThemeFilePaths break; // skip to next file in asThemeFilePaths
} }
} }
if( !bFoundMatch ) if( !bFoundMatch )
asWarning.Add( sThemeKey ); asWarning.push_back( sThemeKey );
} }
SortCStringArray( asRedundant ); SortCStringArray( asRedundant );
@@ -493,13 +488,13 @@ void ConvertThemeDlg::OnButtonAnalyzeMetrics()
fprintf( fp, "The following metrics are REDUNDANT.\n" fprintf( fp, "The following metrics are REDUNDANT.\n"
" (These metrics are identical to the metrics in the base theme.\n" " (These metrics are identical to the metrics in the base theme.\n"
" They are unnecessary and should be deleted.)\n" ); " They are unnecessary and should be deleted.)\n" );
for( i=0; i<asRedundant.GetSize(); i++ ) for( i=0; i<asRedundant.size(); i++ )
fprintf( fp, asRedundant[i] + "\n" ); fprintf( fp, asRedundant[i] + "\n" );
fprintf( fp, "\n" ); fprintf( fp, "\n" );
fprintf( fp, "The following elements are possibly MISNAMED.\n" fprintf( fp, "The following elements are possibly MISNAMED.\n"
" (These metrics do not have a corresponding metric in\n" " (These metrics do not have a corresponding metric in\n"
" the base theme. This likely means that there is an error in the metric name.)\n" ); " the base theme. This likely means that there is an error in the metric name.)\n" );
for( i=0; i<asWarning.GetSize(); i++ ) for( i=0; i<asWarning.size(); i++ )
fprintf( fp, asWarning[i] + "\n" ); fprintf( fp, asWarning[i] + "\n" );
fclose( fp ); fclose( fp );
+1 -1
View File
@@ -68,7 +68,7 @@ BOOL CSmpackageApp::InitInstance()
// check if there's a .smzip command line argument // check if there's a .smzip command line argument
CStringArray arrayCommandLineBits; CStringArray arrayCommandLineBits;
split( ::GetCommandLine(), "\"", arrayCommandLineBits ); split( ::GetCommandLine(), "\"", arrayCommandLineBits );
for( int i=0; i<arrayCommandLineBits.GetSize(); i++ ) for( unsigned i=0; i<arrayCommandLineBits.size(); i++ )
{ {
CString sPath = arrayCommandLineBits[i]; CString sPath = arrayCommandLineBits[i];
sPath.TrimLeft(); sPath.TrimLeft();