|
From: Markus R. <god...@us...> - 2009-07-29 15:35:56
|
Module: performous
Branch: master
Commit: a088841982b759be5b3cce3908759d35f7b0f2cc
Author: Markus Raab <un...@ma...>
Date: Wed Jul 29 08:44:44 2009 +0200
input of Player only if location (was) writeable
---
game/highscore.cc | 11 +++++++++++
game/highscore.hh | 6 ++++++
game/screen_sing.cc | 4 +++-
3 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/game/highscore.cc b/game/highscore.cc
index ebfdb84..a1420f8 100644
--- a/game/highscore.cc
+++ b/game/highscore.cc
@@ -113,6 +113,13 @@ void SongHiscore::save()
out << "E" << std::endl;
}
+bool SongHiscore::isWritable()
+{
+ std::ofstream out ((m_path + m_filename).c_str());
+
+ return out.is_open();
+}
+
void SongHiscore::getInfo (std::ostream & out)
{
for (size_t i=0; i<m_scores.size();i++)
@@ -150,6 +157,10 @@ int main()
{
try {
SongHiscore hi ("", "highscore.txt");
+
+ if (hi.isWritable()) std::cout << "Is writeable" << std::endl;
+ else std::cout << "Is not writeable" << std::endl;
+
hi.load();
int new_score = 9000;
if (hi.reachedNewHiscore(new_score))
diff --git a/game/highscore.hh b/game/highscore.hh
index 7e3642e..61a5183 100644
--- a/game/highscore.hh
+++ b/game/highscore.hh
@@ -52,6 +52,12 @@ class SongHiscore {
void load();
void save();
+ /**Check if file location is writable.
+ @return true if it is.
+ @return false if you can't write at the location where path points to.
+ */
+ bool isWritable();
+
void getInfo (std::ostream & os);
/**Check if you reached a new highscore.
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 920ea63..7accaea 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -72,7 +72,9 @@ void ScreenSing::activatePlayerScreen()
std::cerr << "high.sco:" << hi.line() << " " << hi.what() << std::endl;
}
- if (m_players.scores.empty() || !hi.reachedNewHiscore(m_players.scores.front()))
+ if (m_players.scores.empty()
+ || !hi.reachedNewHiscore(m_players.scores.front())
+ || !hi.isWritable())
{
// if no highscore reached..
sm->activateScreen("Songs");
|