]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Account.cpp
Replaced as much char* as possible by std::strings
[lugaru.git] / Source / Account.cpp
index 11483f89c2eb39ec7a40bd2a503d3cdfe66c786f..b3d42c7d320eb55bb120848428338baa45d7e719 100644 (file)
@@ -23,6 +23,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include <fstream>
 #include "MacCompatibility.h"
 #include "string.h"
+#include <iostream>
 
 using namespace std;
 
@@ -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();
 }
 
@@ -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);
@@ -185,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;
     }
 }
@@ -193,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());
@@ -243,6 +245,8 @@ void Account::saveFile(string filename, Account* accountactive)
         }
 
         fclose(tfile);
+    } else {
+        perror(("Couldn't save users in " + filename).c_str());
     }
 }