forked from scott/threaded_network_chat
fix bug where starting without an existing log breaks everything
This commit is contained in:
24
log.cc
24
log.cc
@@ -1,9 +1,10 @@
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <ios>
|
||||
|
||||
#include "public.h"
|
||||
#include "log.h"
|
||||
#include "public.h"
|
||||
|
||||
// gets the number of lines in a file. returns -1 if there was an error.
|
||||
int
|
||||
@@ -29,21 +30,24 @@ int
|
||||
writeToFile(string path, string line, bool incLineNum)
|
||||
{
|
||||
ofstream file;
|
||||
struct stat s;
|
||||
|
||||
/*
|
||||
* Hopefully this fixes the program messing up where the server/client
|
||||
* doesn't start if the file wasn't created by a previous session.
|
||||
* It APPEARS this fixes our problem where the program has to be run twice to work correctly.
|
||||
*/
|
||||
file.open(path, ios_base::out|ios_base::app);
|
||||
if (stat(path.c_str(), &s) != 0) {
|
||||
file.open(path, ios_base::out);
|
||||
file << "SYSTEM: No log file found. Created a new one." << endl;
|
||||
file.close();
|
||||
linePos += 5; /* This seems to be what actually fixes everything. Not sure. */
|
||||
}
|
||||
|
||||
file.open(path, ios_base::app);
|
||||
|
||||
if (file.is_open()) {
|
||||
file << line << endl;
|
||||
file.close();
|
||||
// this probably would help but theres too much broken stuff
|
||||
// right now to be sure if (incLineNum)
|
||||
//{
|
||||
// linePos++;
|
||||
// }
|
||||
//linePos++ // We might also want this here at some point?
|
||||
return 0;
|
||||
} else {
|
||||
// do something if it didn't work
|
||||
|
||||
Reference in New Issue
Block a user