]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Account.cpp
Mention devtools option in man page
[lugaru.git] / Source / Account.cpp
index 1ee3242bf0ec3779dc03ed369899bfb0cef681fd..bfaa3d4ba2aa520782726fc2b1340c1343c79676 100644 (file)
@@ -1,6 +1,6 @@
 /*
 Copyright (C) 2003, 2010 - Wolfire Games
-Copyright (C) 2010 - Côme <MCMic> BERNIGAUD
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
 
 This file is part of Lugaru.
 
@@ -23,10 +23,11 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include <fstream>
 #include "MacCompatibility.h"
 #include "string.h"
+#include <iostream>
 
 using namespace std;
 
-extern bool debugmode;
+extern bool devtools;
 
 vector<Account*> Account::accounts = vector<Account*>();
 
@@ -74,7 +75,7 @@ Account* Account::destroy(Account* a)
             return NULL;
         }
     }
-    printf("Unexpected error : User %s not found\n", a->getName());
+    printf("Unexpected error : User %s not found\n", a->getName().c_str());
     return accounts.front();
 }
 
@@ -99,7 +100,7 @@ void Account::winCampaignLevel(int choice, float score, float time)
 
 void Account::winLevel(int level, float score, float time)
 {
-    if (!debugmode) {
+    if (!devtools) {
         if (score > highscore[level])
             highscore[level] = score;
         if (time < fasttime[level] || fasttime[level] == 0)
@@ -114,8 +115,9 @@ Account* Account::loadFile(string filename)
     FILE *tfile;
     int numaccounts;
     int accountactive;
+    errno = 0;
 
-    tfile = fopen(ConvertFileName(filename.c_str()), "rb" );
+    tfile = fopen(filename.c_str(), "rb" );
 
     if (tfile) {
         funpackf(tfile, "Bi", &numaccounts);
@@ -128,7 +130,6 @@ Account* Account::loadFile(string filename)
             funpackf(tfile, "Bi", &(acc->progress));
             int nbCampaigns;
             funpackf(tfile, "Bi", &nbCampaigns);
-            //~ printf("loading %d campaign progress info\n",nbCampaigns);
 
             for (int k = 0; k < nbCampaigns; ++k) {
                 string campaignName = "";
@@ -139,7 +140,6 @@ Account* Account::loadFile(string filename)
                     funpackf(tfile, "Bb",  &c);
                     campaignName.append(1, c);
                 }
-                //~ printf("loading %s campaign progress info\n",campaignName.c_str());
                 funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].time));
                 funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].score));
                 funpackf(tfile, "Bf", &(acc->campaignProgress[campaignName].fasttime));
@@ -187,7 +187,7 @@ Account* Account::loadFile(string filename)
         fclose(tfile);
         return get(accountactive);
     } else {
-        printf("filenotfound\n");
+        perror(("Couldn't load users from " + filename).c_str());
         return NULL;
     }
 }
@@ -195,16 +195,16 @@ Account* Account::loadFile(string filename)
 void Account::saveFile(string filename, Account* accountactive)
 {
     FILE *tfile;
+    errno = 0;
 
-    tfile = fopen(ConvertFileName(filename.c_str(), "wb"), "wb" );
+    tfile = fopen(filename.c_str(), "wb" );
     if (tfile) {
-        printf("writing %d accounts :\n", getNbAccounts());
         fpackf(tfile, "Bi", getNbAccounts());
         fpackf(tfile, "Bi", indice(accountactive));
 
         for (int i = 0; i < getNbAccounts(); i++) {
             Account* a = Account::get(i);
-            printf("writing account %d/%d (%s)\n", i + 1, getNbAccounts(), a->getName());
+            printf("writing account %d/%d (%s)\n", i + 1, getNbAccounts(), a->getName().c_str());
             fpackf(tfile, "Bi", a->difficulty);
             fpackf(tfile, "Bi", a->progress);
             fpackf(tfile, "Bi", a->campaignProgress.size());
@@ -245,6 +245,8 @@ void Account::saveFile(string filename, Account* accountactive)
         }
 
         fclose(tfile);
+    } else {
+        perror(("Couldn't save users in " + filename).c_str());
     }
 }