#include "wx/wx.h"
#endif
-#ifdef __WXGTK__
-#include <unistd.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#endif
#include "wx/textfile.h"
#include "wx/config.h"
#include "wx/fileconf.h"
ScoreFile::ScoreFile(const wxString& appName)
{
-#if 0
- wxString filename;
- m_configFilename << "/usr/local/share/" << appName << ".scores";
- if (access(m_configFilename, F_OK) == 0)
- {
- if (access(m_configFilename, R_OK | W_OK) != 0)
- {
- // file is not r/w - use local file instead
- m_configFilename = wxFileConfig::GetLocalFileName(appName);
- }
- }
- else
- {
- int fd = creat(m_configFilename, 0666);
-
- if (fd < 0)
- {
- // failed to create file - use local file instead
- m_configFilename = wxFileConfig::GetLocalFileName(appName);
- }
- else
- {
- // ensure created file has rw-rw-rw permissions
- close(fd);
- }
- }
-#endif
-
- m_config = new wxConfig(appName, _T("wxWidgets"), appName, wxEmptyString,
+ m_config = new wxConfig(appName, wxT("wxWidgets"), appName, wxEmptyString,
wxCONFIG_USE_LOCAL_FILE); // only local
}
ScoreFile::~ScoreFile()
{
delete m_config;
-#ifdef __WXGTK__
- // ensure score file has rw-rw-rw permissions
- // (wxFileConfig sets them to rw-------)
- chmod(m_configFilename, 0666);
-#endif
}
void ScoreFile::GetPlayerList( wxArrayString &list )
{
- m_config->SetPath(_T("/Players"));
+ m_config->SetPath(wxT("/Players"));
int length = m_config->GetNumberOfGroups();
if (length <= 0) return;
wxString ScoreFile::GetPreviousPlayer() const
{
wxString result;
- m_config->SetPath(_T("/General"));
- m_config->Read(_T("LastPlayer"), &result);
+ m_config->SetPath(wxT("/General"));
+ m_config->Read(wxT("LastPlayer"), &result);
return result;
}
games = wins = score = 0;
- m_config->SetPath(_T("/Players"));
+ m_config->SetPath(wxT("/Players"));
m_config->SetPath(player);
- 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 (m_config->Read(wxT("Score"), &myScore, 0L) &&
+ m_config->Read(wxT("Games"), &myGames, 0L) &&
+ m_config->Read(wxT("Wins"), &myWins, 0L) &&
+ m_config->Read(wxT("Check"), &check, 0L))
{
if (check != CalcCheck(player, myGames, myWins, myScore))
{
- wxMessageBox(_T("Score file corrupted"), _T("Warning"),
+ wxMessageBox(wxT("Score file corrupted"), wxT("Warning"),
wxOK | wxICON_EXCLAMATION);
}
else
void ScoreFile::WritePlayersScore(const wxString& player, int wins, int games, int score)
{
- if (player)
+ if (!player.empty())
{
- m_config->SetPath(_T("/General"));
- m_config->Write(_T("LastPlayer"), wxString(player)); // Without wxString tmp, thinks it's bool in VC++
+ m_config->SetPath(wxT("/General"));
+ m_config->Write(wxT("LastPlayer"), wxString(player)); // Without wxString tmp, thinks it's bool in VC++
- m_config->SetPath(_T("/Players"));
+ m_config->SetPath(wxT("/Players"));
m_config->SetPath(player);
- 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));
+ m_config->Write(wxT("Score"), (long)score);
+ m_config->Write(wxT("Games"), (long)games);
+ m_config->Write(wxT("Wins"), (long)wins);
+ m_config->Write(wxT("Check"), CalcCheck(player, games, wins, score));
}
}