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 <ios>
|
||||||
|
|
||||||
#include "public.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "public.h"
|
||||||
|
|
||||||
// gets the number of lines in a file. returns -1 if there was an error.
|
// gets the number of lines in a file. returns -1 if there was an error.
|
||||||
int
|
int
|
||||||
@@ -29,21 +30,24 @@ int
|
|||||||
writeToFile(string path, string line, bool incLineNum)
|
writeToFile(string path, string line, bool incLineNum)
|
||||||
{
|
{
|
||||||
ofstream file;
|
ofstream file;
|
||||||
|
struct stat s;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hopefully this fixes the program messing up where the server/client
|
* It APPEARS this fixes our problem where the program has to be run twice to work correctly.
|
||||||
* doesn't start if the file wasn't created by a previous session.
|
|
||||||
*/
|
*/
|
||||||
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()) {
|
if (file.is_open()) {
|
||||||
file << line << endl;
|
file << line << endl;
|
||||||
file.close();
|
file.close();
|
||||||
// this probably would help but theres too much broken stuff
|
//linePos++ // We might also want this here at some point?
|
||||||
// right now to be sure if (incLineNum)
|
|
||||||
//{
|
|
||||||
// linePos++;
|
|
||||||
// }
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
// do something if it didn't work
|
// do something if it didn't work
|
||||||
|
|||||||
Reference in New Issue
Block a user