//The initialization function.
bool Log::initialize(string _filename, bool overwrite_existing, int _newline_mode)
{
   filename = _filename; //Assign the filepath.

   newline_mode = _newline_mode; //Set the newline mode

   //check If it is to append the output to the end of the log file rather than
   //to overwrite the file.
   if(!overwrite_existing)
   {
      //Yes, it is to append.

      //Open the file in append mode. With error checking.
      if(!LCSOpenFileCPP(filename, ios::out | ios::app, LCSIO_PRE_HOME, file))
      {
         return false; //Failed to open file.
      }
   }
   else //overwrite_existing = true. Overwrite the file.
   {
      //Open the file. Use the trunc parameter to ensure the file is going to be overwritten.
      if(!LCSOpenFileCPP(filename, ios::out | ios::trunc, LCSIO_PRE_HOME, file)) //With error checking.
      {
         return false; //Failed to open file.
      }
   }
   //File's open and everything. Okay to proceed.

   initialized = true; //The logger is now initialized.

   return true; //*super smash brothers melee announcer* Success!
}
Beispiel #2
0
void loadinitfile(void) {
    std::fstream file;

    if (LCSOpenFileCPP("init.txt", ios::in, LCSIO_PRE_HOME, file)) {
        std::string str;
        int posequal;

        while(getline(file, str)) {
            str.erase(std::remove(str.begin(), str.end(), '\r'), str.end());
            str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
            str.erase(std::remove(str.begin(), str.end(), ' '), str.end());
            str.erase(std::remove(str.begin(), str.end(), '\t'), str.end());

            if (!str.length())
                continue;

            if (str[0] == '#')
                continue;

            if (str[0] == ';')
                continue;

            posequal = str.find('=');

            if(posequal == (int)string::npos)
                continue;

            setconfigoption(str.substr(0, posequal), str.substr(posequal + 1));
        }
    }

    file.close();

#ifdef WIN32
    begin_cleartype_fix(); // won't do anything unless fixcleartype is true
#endif
}