Backported Unicode compilation fixes for demos and exec sample.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18693 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -56,7 +56,7 @@ FortyCanvas::FortyCanvas(wxWindow* parent, int x, int y, int w, int h) :
|
||||
m_arrowCursor = new wxCursor(wxCURSOR_ARROW);
|
||||
|
||||
wxString name = wxTheApp->GetAppName();
|
||||
if (name.Length() <= 0) name = "forty";
|
||||
if (name.Length() <= 0) name = _T("forty");
|
||||
m_scoreFile = new ScoreFile(name);
|
||||
m_game = new Game(0, 0, 0);
|
||||
m_game->Deal();
|
||||
@@ -159,8 +159,8 @@ Called when the main frame is closed
|
||||
bool FortyCanvas::OnCloseCanvas()
|
||||
{
|
||||
if (m_game->InPlay() &&
|
||||
wxMessageBox("Are you sure you want to\nabandon the current game?",
|
||||
"Warning", wxYES_NO | wxICON_QUESTION) == wxNO)
|
||||
wxMessageBox(_T("Are you sure you want to\nabandon the current game?"),
|
||||
_T("Warning"), wxYES_NO | wxICON_QUESTION) == wxNO)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
@@ -67,25 +67,25 @@ Card::Card(int value, WayUp way_up) :
|
||||
if (!m_symbolBmap)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
m_symbolBmap = new wxBitmap("CardSymbols", wxBITMAP_TYPE_BMP_RESOURCE);
|
||||
m_symbolBmap = new wxBitmap(_T("CardSymbols"), wxBITMAP_TYPE_BMP_RESOURCE);
|
||||
#else
|
||||
m_symbolBmap = new wxBitmap(Symbols_bits, Symbols_width, Symbols_height);
|
||||
#endif
|
||||
if (!m_symbolBmap->Ok())
|
||||
{
|
||||
::wxMessageBox("Failed to load bitmap CardSymbols", "Error");
|
||||
::wxMessageBox(_T("Failed to load bitmap CardSymbols"), _T("Error"));
|
||||
}
|
||||
}
|
||||
if (!m_pictureBmap)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
m_pictureBmap = new wxBitmap("CardPictures", wxBITMAP_TYPE_BMP_RESOURCE);
|
||||
m_pictureBmap = new wxBitmap(_T("CardPictures"), wxBITMAP_TYPE_BMP_RESOURCE);
|
||||
#else
|
||||
m_pictureBmap = new wxBitmap(Pictures);
|
||||
#endif
|
||||
if (!m_pictureBmap->Ok())
|
||||
{
|
||||
::wxMessageBox("Failed to load bitmap CardPictures", "Error");
|
||||
::wxMessageBox(_T("Failed to load bitmap CardPictures"), _T("Error"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ void Card::Draw(wxDC& dc, int x, int y)
|
||||
dc.SetBackground(* wxRED_BRUSH);
|
||||
dc.SetBackgroundMode(wxSOLID);
|
||||
wxBrush* brush = wxTheBrushList->FindOrCreateBrush(
|
||||
"BLACK", wxCROSSDIAG_HATCH
|
||||
_T("BLACK"), wxCROSSDIAG_HATCH
|
||||
);
|
||||
dc.SetBrush(* brush);
|
||||
|
||||
|
@@ -76,7 +76,7 @@ bool FortyApp::OnInit()
|
||||
bool largecards = FALSE;
|
||||
wxSize size(668,510);
|
||||
|
||||
if ((argc > 1) && (!wxStrcmp(argv[1],"-L")))
|
||||
if ((argc > 1) && (!wxStrcmp(argv[1],_T("-L"))))
|
||||
{
|
||||
largecards = TRUE;
|
||||
size = wxSize(1000,750);
|
||||
@@ -84,7 +84,7 @@ bool FortyApp::OnInit()
|
||||
|
||||
FortyFrame* frame = new FortyFrame(
|
||||
0,
|
||||
"Forty Thieves",
|
||||
_T("Forty Thieves"),
|
||||
-1, -1, size.x, size.y,largecards
|
||||
);
|
||||
|
||||
@@ -120,14 +120,14 @@ const wxColour& FortyApp::TextColour()
|
||||
{
|
||||
if (!m_textColour)
|
||||
{
|
||||
m_textColour = new wxColour("BLACK");
|
||||
m_textColour = new wxColour(_T("BLACK"));
|
||||
}
|
||||
|
||||
return *m_textColour;
|
||||
}
|
||||
|
||||
// My frame constructor
|
||||
FortyFrame::FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h,bool largecards):
|
||||
FortyFrame::FortyFrame(wxFrame* frame, const wxString& title, int x, int y, int w, int h,bool largecards):
|
||||
wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
|
||||
{
|
||||
#ifdef __WXMAC__
|
||||
@@ -136,7 +136,7 @@ FortyFrame::FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h,b
|
||||
#endif
|
||||
// set the icon
|
||||
#ifdef __WXMSW__
|
||||
SetIcon(wxIcon("CardsIcon"));
|
||||
SetIcon(wxIcon(_T("CardsIcon")));
|
||||
#else
|
||||
#ifdef GTK_TBD
|
||||
SetIcon(wxIcon(Cards_bits, Cards_width, Cards_height));
|
||||
@@ -145,28 +145,28 @@ FortyFrame::FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h,b
|
||||
|
||||
// Make a menu bar
|
||||
wxMenu* gameMenu = new wxMenu;
|
||||
gameMenu->Append(NEW_GAME, "&New", "Start a new game");
|
||||
gameMenu->Append(SCORES, "&Scores...", "Displays scores");
|
||||
gameMenu->Append(EXIT, "E&xit", "Exits Forty Thieves");
|
||||
gameMenu->Append(NEW_GAME, _T("&New"), _T("Start a new game"));
|
||||
gameMenu->Append(SCORES, _T("&Scores..."), _T("Displays scores"));
|
||||
gameMenu->Append(EXIT, _T("E&xit"), _T("Exits Forty Thieves"));
|
||||
|
||||
wxMenu* editMenu = new wxMenu;
|
||||
editMenu->Append(UNDO, "&Undo", "Undo the last move");
|
||||
editMenu->Append(REDO, "&Redo", "Redo a move that has been undone");
|
||||
editMenu->Append(UNDO, _T("&Undo"), _T("Undo the last move"));
|
||||
editMenu->Append(REDO, _T("&Redo"), _T("Redo a move that has been undone"));
|
||||
|
||||
wxMenu* optionsMenu = new wxMenu;
|
||||
optionsMenu->Append(RIGHT_BUTTON_UNDO,
|
||||
"&Right button undo",
|
||||
"Enables/disables right mouse button undo and redo",
|
||||
_T("&Right button undo"),
|
||||
_T("Enables/disables right mouse button undo and redo"),
|
||||
TRUE
|
||||
);
|
||||
optionsMenu->Append(HELPING_HAND,
|
||||
"&Helping hand",
|
||||
"Enables/disables hand cursor when a card can be moved",
|
||||
_T("&Helping hand"),
|
||||
_T("Enables/disables hand cursor when a card can be moved"),
|
||||
TRUE
|
||||
);
|
||||
optionsMenu->Append(LARGE_CARDS,
|
||||
"&Large cards",
|
||||
"Enables/disables large cards for high resolution displays",
|
||||
_T("&Large cards"),
|
||||
_T("Enables/disables large cards for high resolution displays"),
|
||||
TRUE
|
||||
);
|
||||
optionsMenu->Check(HELPING_HAND, TRUE);
|
||||
@@ -174,13 +174,13 @@ FortyFrame::FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h,b
|
||||
optionsMenu->Check(LARGE_CARDS, largecards ? TRUE : FALSE);
|
||||
|
||||
wxMenu* helpMenu = new wxMenu;
|
||||
helpMenu->Append(ABOUT, "&About...", "Displays information about the game");
|
||||
helpMenu->Append(ABOUT, _T("&About..."), _T("Displays information about the game"));
|
||||
|
||||
m_menuBar = new wxMenuBar;
|
||||
m_menuBar->Append(gameMenu, "&Game");
|
||||
m_menuBar->Append(editMenu, "&Edit");
|
||||
m_menuBar->Append(optionsMenu, "&Options");
|
||||
m_menuBar->Append(helpMenu, "&Help");
|
||||
m_menuBar->Append(gameMenu, _T("&Game"));
|
||||
m_menuBar->Append(editMenu, _T("&Edit"));
|
||||
m_menuBar->Append(optionsMenu, _T("&Options"));
|
||||
m_menuBar->Append(helpMenu, _T("&Help"));
|
||||
|
||||
SetMenuBar(m_menuBar);
|
||||
|
||||
@@ -243,14 +243,14 @@ FortyFrame::About(wxCommandEvent&)
|
||||
#endif
|
||||
{
|
||||
wxMessageBox(
|
||||
"Forty Thieves\n\n"
|
||||
"A freeware program using the wxWindows\n"
|
||||
"portable C++ GUI toolkit.\n"
|
||||
"http://www.wxwindows.org\n"
|
||||
"http://www.freiburg.linux.de/~wxxt\n\n"
|
||||
"Author: Chris Breeze (c) 1992-1998\n"
|
||||
"email: chris.breeze@iname.com",
|
||||
"About Forty Thieves",
|
||||
_T("Forty Thieves\n\n")
|
||||
_T("A freeware program using the wxWindows\n")
|
||||
_T("portable C++ GUI toolkit.\n")
|
||||
_T("http://www.wxwindows.org\n")
|
||||
_T("http://www.freiburg.linux.de/~wxxt\n\n")
|
||||
_T("Author: Chris Breeze (c) 1992-1998\n")
|
||||
_T("email: chris.breeze@iname.com"),
|
||||
_T("About Forty Thieves"),
|
||||
wxOK, this
|
||||
);
|
||||
}
|
||||
@@ -331,7 +331,7 @@ bool FortyAboutDialog::AddControls(wxWindow* parent)
|
||||
wxFile file;
|
||||
file.Open(htmlFile, wxFile::read);
|
||||
long len = file.Length();
|
||||
char* buf = htmlText.GetWriteBuf(len + 1);
|
||||
wxChar* buf = htmlText.GetWriteBuf(len + 1);
|
||||
file.Read(buf, len);
|
||||
buf[len] = 0;
|
||||
htmlText.UngetWriteBuf();
|
||||
@@ -349,7 +349,7 @@ bool FortyAboutDialog::AddControls(wxWindow* parent)
|
||||
verString.Printf("%.2f", stVERSION_NUMBER);
|
||||
htmlText.Replace(wxT("$VERSION$"), verString);
|
||||
#endif
|
||||
htmlText.Replace(wxT("$DATE$"), __DATE__);
|
||||
htmlText.Replace(wxT("$DATE$"), _T(__DATE__));
|
||||
|
||||
wxSize htmlSize(400, 290);
|
||||
|
||||
@@ -373,7 +373,7 @@ bool FortyAboutDialog::AddControls(wxWindow* parent)
|
||||
wxASSERT( item1 );
|
||||
item0->Add( item1, 0, wxALIGN_CENTRE|wxALL, 5 );
|
||||
|
||||
wxButton *item2 = new wxButton( parent, wxID_CANCEL, "&Close", wxDefaultPosition, wxDefaultSize, 0 );
|
||||
wxButton *item2 = new wxButton( parent, wxID_CANCEL, _T("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
item2->SetDefault();
|
||||
item2->SetFocus();
|
||||
|
||||
|
@@ -34,7 +34,7 @@ class FortyCanvas;
|
||||
class FortyFrame: public wxFrame
|
||||
{
|
||||
public:
|
||||
FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h,bool largecards);
|
||||
FortyFrame(wxFrame* frame, const wxString& title, int x, int y, int w, int h,bool largecards);
|
||||
virtual ~FortyFrame();
|
||||
|
||||
void OnCloseWindow(wxCloseEvent& event);
|
||||
|
@@ -163,7 +163,7 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest)
|
||||
{
|
||||
if (src == dest)
|
||||
{
|
||||
wxMessageBox("Game::DoMove() src == dest", "Debug message",
|
||||
wxMessageBox(_T("Game::DoMove() src == dest"), _T("Debug message"),
|
||||
wxOK | wxICON_EXCLAMATION);
|
||||
}
|
||||
m_moves[m_moveIndex].src = src;
|
||||
@@ -175,7 +175,7 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest)
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMessageBox("Game::DoMove() Undo buffer full", "Debug message",
|
||||
wxMessageBox(_T("Game::DoMove() Undo buffer full"), _T("Debug message"),
|
||||
wxOK | wxICON_EXCLAMATION);
|
||||
}
|
||||
|
||||
@@ -203,8 +203,8 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest)
|
||||
// Redraw the score box to update games won
|
||||
DisplayScore(dc);
|
||||
|
||||
if (wxMessageBox("Do you wish to play again?",
|
||||
"Well Done, You have won!", wxYES_NO | wxICON_QUESTION) == wxYES)
|
||||
if (wxMessageBox(_T("Do you wish to play again?"),
|
||||
_T("Well Done, You have won!"), wxYES_NO | wxICON_QUESTION) == wxYES)
|
||||
{
|
||||
Deal();
|
||||
canvas->Refresh();
|
||||
@@ -241,25 +241,25 @@ void Game::DisplayScore(wxDC& dc)
|
||||
int w, h;
|
||||
{
|
||||
long width, height;
|
||||
dc.GetTextExtent("Average score:m_x", &width, &height);
|
||||
dc.GetTextExtent(_T("Average score:m_x"), &width, &height);
|
||||
w = width;
|
||||
h = height;
|
||||
}
|
||||
dc.DrawRectangle(x + w, y, 20, 4 * h);
|
||||
|
||||
char str[80];
|
||||
sprintf(str, "%d", m_currentScore);
|
||||
dc.DrawText("Score:", x, y);
|
||||
wxString str;
|
||||
str.Printf(_T("%d"), m_currentScore);
|
||||
dc.DrawText(_T("Score:"), x, y);
|
||||
dc.DrawText(str, x + w, y);
|
||||
y += h;
|
||||
|
||||
sprintf(str, "%d", m_numGames);
|
||||
dc.DrawText("Games played:", x, y);
|
||||
str.Printf(_T("%d"), m_numGames);
|
||||
dc.DrawText(_T("Games played:"), x, y);
|
||||
dc.DrawText(str, x + w, y);
|
||||
y += h;
|
||||
|
||||
sprintf(str, "%d", m_numWins);
|
||||
dc.DrawText("Games won:", x, y);
|
||||
str.Printf(_T("%d"), m_numWins);
|
||||
dc.DrawText(_T("Games won:"), x, y);
|
||||
dc.DrawText(str, x + w, y);
|
||||
y += h;
|
||||
|
||||
@@ -268,8 +268,8 @@ void Game::DisplayScore(wxDC& dc)
|
||||
{
|
||||
average = (2 * (m_currentScore + m_totalScore) + m_numGames ) / (2 * m_numGames);
|
||||
}
|
||||
sprintf(str, "%d", average);
|
||||
dc.DrawText("Average score:", x, y);
|
||||
str.Printf(_T("%d"), average);
|
||||
dc.DrawText(_T("Average score:"), x, y);
|
||||
dc.DrawText(str, x + w, y);
|
||||
}
|
||||
|
||||
@@ -798,8 +798,8 @@ void Pack::Redraw(wxDC& dc)
|
||||
{
|
||||
Pile::Redraw(dc);
|
||||
|
||||
char str[10];
|
||||
sprintf(str, "%d ", m_topCard + 1);
|
||||
wxString str;
|
||||
str.Printf(_T("%d "), m_topCard + 1);
|
||||
|
||||
dc.SetBackgroundMode( wxSOLID );
|
||||
dc.SetTextBackground(FortyApp::BackgroundColour());
|
||||
@@ -816,7 +816,7 @@ void Pack::AddCard(Card* card)
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMessageBox("Pack::AddCard() Undo error", "Forty Thieves: Warning",
|
||||
wxMessageBox(_T("Pack::AddCard() Undo error"), _T("Forty Thieves: Warning"),
|
||||
wxOK | wxICON_EXCLAMATION);
|
||||
}
|
||||
card->TurnCard(facedown);
|
||||
|
@@ -44,7 +44,7 @@ PlayerSelectionDialog::PlayerSelectionDialog(
|
||||
wxWindow* parent,
|
||||
ScoreFile* file
|
||||
) :
|
||||
wxDialog(parent, -1, "Player Selection",
|
||||
wxDialog(parent, -1, _T("Player Selection"),
|
||||
wxDefaultPosition, wxSize(320, 200),
|
||||
wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE),
|
||||
m_scoreFile(file)
|
||||
@@ -52,7 +52,7 @@ PlayerSelectionDialog::PlayerSelectionDialog(
|
||||
// enable constraints
|
||||
SetAutoLayout (TRUE);
|
||||
|
||||
wxStaticText* msg = new wxStaticText(this, -1, "Please select a name or type a new one:");
|
||||
wxStaticText* msg = new wxStaticText(this, -1, _T("Please select a name or type a new one:"));
|
||||
|
||||
wxListBox* list = new wxListBox(
|
||||
this, ID_LISTBOX,
|
||||
@@ -68,10 +68,10 @@ PlayerSelectionDialog::PlayerSelectionDialog(
|
||||
list->Append(players[i]);
|
||||
}
|
||||
|
||||
m_textField = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, 0);
|
||||
m_textField = new wxTextCtrl(this, -1, _T(""), wxDefaultPosition, wxDefaultSize, 0);
|
||||
|
||||
m_OK = new wxButton(this, wxID_OK, "OK");
|
||||
m_cancel = new wxButton(this, wxID_CANCEL, "Cancel");
|
||||
m_OK = new wxButton(this, wxID_OK, _T("OK"));
|
||||
m_cancel = new wxButton(this, wxID_CANCEL, _T("Cancel"));
|
||||
|
||||
wxLayoutConstraints* layout;
|
||||
|
||||
@@ -149,7 +149,7 @@ const wxString& PlayerSelectionDialog::GetPlayersName()
|
||||
|
||||
void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent& event)
|
||||
{
|
||||
m_player = "";
|
||||
m_player = _T("");
|
||||
EndModal(wxID_CANCEL);
|
||||
}
|
||||
|
||||
@@ -169,9 +169,9 @@ void PlayerSelectionDialog::ButtonCallback(wxCommandEvent& event)
|
||||
wxString name = m_textField->GetValue();
|
||||
if (!name.IsNull() && name.Length() > 0)
|
||||
{
|
||||
if (name.Contains('@'))
|
||||
if (name.Contains(_T('@')))
|
||||
{
|
||||
wxMessageBox("Names should not contain the '@' character", "Forty Thieves");
|
||||
wxMessageBox(_T("Names should not contain the '@' character"), _T("Forty Thieves"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -181,12 +181,12 @@ void PlayerSelectionDialog::ButtonCallback(wxCommandEvent& event)
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMessageBox("Please enter your name", "Forty Thieves");
|
||||
wxMessageBox(_T("Please enter your name"), _T("Forty Thieves"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_player = "";
|
||||
m_player = _T("");
|
||||
EndModal(wxID_CANCEL);
|
||||
}
|
||||
}
|
||||
|
@@ -86,7 +86,7 @@ void ScoreCanvas::OnDraw(wxDC& dc)
|
||||
{
|
||||
dc.SetFont(* m_font);
|
||||
|
||||
const char* str = m_text;
|
||||
const wxChar* str = m_text;
|
||||
unsigned int tab = 0;
|
||||
unsigned int tabstops[] = { 5, 100, 150, 200 };
|
||||
|
||||
@@ -94,29 +94,29 @@ void ScoreCanvas::OnDraw(wxDC& dc)
|
||||
int lineSpacing;
|
||||
{
|
||||
long w, h;
|
||||
dc.GetTextExtent("Testing", &w, &h);
|
||||
dc.GetTextExtent(_T("Testing"), &w, &h);
|
||||
lineSpacing = (int)h;
|
||||
}
|
||||
|
||||
int y = 0;
|
||||
while (*str)
|
||||
{
|
||||
char text[256];
|
||||
char* dest = text;
|
||||
wxChar text[256];
|
||||
wxChar* dest = text;
|
||||
|
||||
while (*str && *str >= ' ') *dest++ = *str++;
|
||||
*dest = '\0';
|
||||
while (*str && *str >= _T(' ')) *dest++ = *str++;
|
||||
*dest = _T('\0');
|
||||
|
||||
dc.DrawText(text, tabstops[tab], y);
|
||||
|
||||
if (*str == '\t')
|
||||
if (*str == _T('\t'))
|
||||
{
|
||||
if (tab < sizeof(tabstops) / sizeof(tabstops[0]) - 1)
|
||||
{
|
||||
tab++;
|
||||
}
|
||||
}
|
||||
else if (*str == '\n')
|
||||
else if (*str == _T('\n'))
|
||||
{
|
||||
tab = 0;
|
||||
y += lineSpacing;
|
||||
@@ -133,7 +133,7 @@ ScoreDialog::ScoreDialog(
|
||||
wxWindow* parent,
|
||||
ScoreFile* file
|
||||
) :
|
||||
wxDialog(parent, -1, "Scores",
|
||||
wxDialog(parent, -1, _T("Scores"),
|
||||
wxDefaultPosition, wxSize(310, 200),
|
||||
wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE),
|
||||
m_scoreFile(file)
|
||||
@@ -142,7 +142,7 @@ ScoreDialog::ScoreDialog(
|
||||
SetAutoLayout (TRUE);
|
||||
|
||||
ScoreCanvas* list = new ScoreCanvas(this, m_scoreFile);
|
||||
m_OK = new wxButton(this, wxID_OK, "OK");
|
||||
m_OK = new wxButton(this, wxID_OK, _T("OK"));
|
||||
|
||||
wxLayoutConstraints* layout;
|
||||
|
||||
|
@@ -38,7 +38,7 @@
|
||||
|
||||
#include "scorefil.h"
|
||||
|
||||
ScoreFile::ScoreFile(const char* appName)
|
||||
ScoreFile::ScoreFile(const wxString& appName)
|
||||
{
|
||||
#if 0
|
||||
wxString filename;
|
||||
@@ -68,7 +68,8 @@ ScoreFile::ScoreFile(const char* appName)
|
||||
}
|
||||
#endif
|
||||
|
||||
m_config = new wxConfig(appName, "wxWindows", appName, "", wxCONFIG_USE_LOCAL_FILE); // only local
|
||||
m_config = new wxConfig(appName, _T("wxWindows"), appName, _T(""),
|
||||
wxCONFIG_USE_LOCAL_FILE); // only local
|
||||
}
|
||||
|
||||
ScoreFile::~ScoreFile()
|
||||
@@ -84,7 +85,7 @@ ScoreFile::~ScoreFile()
|
||||
|
||||
void ScoreFile::GetPlayerList( wxArrayString &list )
|
||||
{
|
||||
m_config->SetPath("/Players");
|
||||
m_config->SetPath(_T("/Players"));
|
||||
int length = m_config->GetNumberOfGroups();
|
||||
|
||||
if (length <= 0) return;
|
||||
@@ -106,12 +107,14 @@ void ScoreFile::GetPlayerList( wxArrayString &list )
|
||||
|
||||
// Calculate an encrypted check number to prevent tampering with
|
||||
// score file
|
||||
long ScoreFile::CalcCheck(const char* name, int p1, int p2, int p3)
|
||||
long ScoreFile::CalcCheck(const wxString& name, int p1, int p2, int p3)
|
||||
{
|
||||
long check = 0;
|
||||
while (*name)
|
||||
size_t i, max = name.length();
|
||||
|
||||
for(i = 0; i < max; ++i )
|
||||
{
|
||||
check = (check << 1) ^ (long)*name++;
|
||||
check = (check << 1) ^ (long)name[i];
|
||||
check = ((check >> 23) ^ check) & 0xFFFFFF;
|
||||
}
|
||||
check = (check << 1) ^ (long)p1;
|
||||
@@ -126,13 +129,13 @@ long ScoreFile::CalcCheck(const char* name, int p1, int p2, int p3)
|
||||
wxString ScoreFile::GetPreviousPlayer() const
|
||||
{
|
||||
wxString result;
|
||||
m_config->SetPath("/General");
|
||||
m_config->Read("LastPlayer", &result);
|
||||
m_config->SetPath(_T("/General"));
|
||||
m_config->Read(_T("LastPlayer"), &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ScoreFile::ReadPlayersScore(
|
||||
const char* player,
|
||||
const wxString& player,
|
||||
int& wins,
|
||||
int& games,
|
||||
int& score)
|
||||
@@ -142,17 +145,17 @@ void ScoreFile::ReadPlayersScore(
|
||||
|
||||
games = wins = score = 0;
|
||||
|
||||
m_config->SetPath("/Players");
|
||||
m_config->SetPath(_T("/Players"));
|
||||
m_config->SetPath(player);
|
||||
if (m_config->Read("Score", &myScore, 0L) &&
|
||||
m_config->Read("Games", &myGames, 0L) &&
|
||||
m_config->Read("Wins", &myWins, 0L) &&
|
||||
m_config->Read("Check", &check, 0L))
|
||||
if (m_config->Read(_T("Score"), &myScore, 0L) &&
|
||||
m_config->Read(_T("Games"), &myGames, 0L) &&
|
||||
m_config->Read(_T("Wins"), &myWins, 0L) &&
|
||||
m_config->Read(_T("Check"), &check, 0L))
|
||||
{
|
||||
if (check != CalcCheck(player, myGames, myWins, myScore))
|
||||
{
|
||||
wxMessageBox("Score file corrupted", "Warning",
|
||||
wxOK | wxICON_EXCLAMATION);
|
||||
wxMessageBox(_T("Score file corrupted"), _T("Warning"),
|
||||
wxOK | wxICON_EXCLAMATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -165,18 +168,18 @@ void ScoreFile::ReadPlayersScore(
|
||||
}
|
||||
|
||||
|
||||
void ScoreFile::WritePlayersScore(const char* player, int wins, int games, int score)
|
||||
void ScoreFile::WritePlayersScore(const wxString& player, int wins, int games, int score)
|
||||
{
|
||||
if (player)
|
||||
{
|
||||
m_config->SetPath("/General");
|
||||
m_config->Write("LastPlayer", wxString(player)); // Without wxString tmp, thinks it's bool in VC++
|
||||
m_config->SetPath(_T("/General"));
|
||||
m_config->Write(_T("LastPlayer"), wxString(player)); // Without wxString tmp, thinks it's bool in VC++
|
||||
|
||||
m_config->SetPath("/Players");
|
||||
m_config->SetPath(_T("/Players"));
|
||||
m_config->SetPath(player);
|
||||
m_config->Write("Score", (long)score);
|
||||
m_config->Write("Games", (long)games);
|
||||
m_config->Write("Wins", (long)wins);
|
||||
m_config->Write("Check", CalcCheck(player, games, wins, score));
|
||||
m_config->Write(_T("Score"), (long)score);
|
||||
m_config->Write(_T("Games"), (long)games);
|
||||
m_config->Write(_T("Wins"), (long)wins);
|
||||
m_config->Write(_T("Check"), CalcCheck(player, games, wins, score));
|
||||
}
|
||||
}
|
||||
|
@@ -24,17 +24,17 @@
|
||||
|
||||
class ScoreFile {
|
||||
public:
|
||||
ScoreFile(const char* appName);
|
||||
ScoreFile(const wxString& appName);
|
||||
virtual ~ScoreFile();
|
||||
|
||||
void GetPlayerList( wxArrayString &list );
|
||||
wxString GetPreviousPlayer() const;
|
||||
|
||||
void ReadPlayersScore(const char* player, int& wins, int& games, int &score);
|
||||
void WritePlayersScore(const char* player, int wins, int games, int score);
|
||||
void ReadPlayersScore(const wxString& player, int& wins, int& games, int &score);
|
||||
void WritePlayersScore(const wxString& player, int wins, int games, int score);
|
||||
|
||||
private:
|
||||
long CalcCheck(const char* name, int p1, int p2, int p3);
|
||||
long CalcCheck(const wxString& name, int p1, int p2, int p3);
|
||||
wxString m_configFilename;
|
||||
wxConfig* m_config;
|
||||
};
|
||||
|
Reference in New Issue
Block a user