Ejemplo n.º 1
0
bool ConfigManager::save() {
	if (!_config)
		return true;

	if (!getBool("saveconf", true))
		return true;

	// Create the directories in the path, if necessary
	UString file = FilePath::canonicalize(getConfigFile());

	try {
		FilePath::createDirectories(FilePath::getDirectory(file));

		// Open and save the config
		WriteFile config;
		if (!config.open(file))
			throw Exception(kOpenError);

		save(config, true);

	} catch (...) {
		exceptionDispatcherWarning("Failed saving config file \"%s\"", file.c_str());
		return false;
	}

	return true;
}
Ejemplo n.º 2
0
void render(BelaContext *context, void *userData)
{
	for(unsigned int n = 0; n < context->analogFrames; ++n) {
		file1.log(&(context->analogIn[n*context->analogFrames]), 2); // log an array of values
		file2.log(context->analogIn[n*context->analogFrames]); // log a single value
	}
}
Ejemplo n.º 3
0
int main()
{
   String* str = new String("Insomnium");
   str->displayString();
   std::cout << std::endl;

   Tokens* tokens = new Tokens(str, 'n');
   tokens->displayTokens();

   int num_tokens = tokens->getNumTokens();
   for (int i = 0; i < num_tokens; i++)
   {
      String* token = tokens->getToken(i);
      delete token;
   }
   delete tokens;  //does not delete the individual tokens
   delete str;

   ReadFile* rf = new ReadFile("cds.txt");
   WriteFile* wf = new WriteFile("out.txt");

   while(!rf->eof())
   {
      String* line = rf->readLine();
      wf->writeLine(line);
      delete line;
   }

   rf->close();
   wf->close();
   delete rf;
   delete wf;

   return 0;
}
Ejemplo n.º 4
0
// saveTable
//---------------------------------------------------------------------------
void ColorTable::saveTable(const char *filename) const
{
    WriteFile *file = FileSystem::openWrite(filename);

    if (file->write(&Palette::color, 768, 1) != 1
            || file->write(colorArray, colorCount, 1) != 1) {
        throw Exception("error while writing to file '%s' (disk full?)",
                        filename);
    }

    delete file;
} // end ColorTable::saveTable
Ejemplo n.º 5
0
    static int write(void* context, const char* buffer, int len)
    {
        WriteFile* file = (WriteFile*) context;

        try {
            if(file->write(buffer, len, 1) != 1) {
                LOGGER.warning("Write error while saving xml");
                return 0;
            }
        } catch(...) {
            LOGGER.warning("Write error while saving xml");
            return 0;
        }
        return len;
    }
Ejemplo n.º 6
0
bool setup(BelaContext *context, void *userData)
{
	file1.init("out.bin"); //set the file name to write to
	file1.setEchoInterval(10000); // only print to the console every 10000 calls to log
	file1.setFileType(kBinary);
	// set the format that you want to use for your output.
	// Please use %f only (with modifiers).
	// When in binary mode, this is used only for echoing to console
	file1.setFormat("binary: %.4f %.4f\n"); 
	file2.init("out.m"); //set the file name to write to
	file2.setHeader("myvar=[\n"); //set one or more lines to be printed at the beginning of the file
	file2.setFooter("];\n"); //set one or more lines to be printed at the end of the file
	file2.setFormat("%.4f\n"); // set the format that you want to use for your output. Please use %f only (with modifiers)
	file2.setFileType(kText);
	file2.setEchoInterval(10000); // only print to the console 1 line every other 10000
	return true; 
}
Ejemplo n.º 7
0
int main()
{
   ReadFile* rf = new ReadFile("cds.txt");
   WriteFile* wf = new WriteFile("out.txt");

   while(!rf->eof())
   {
      String* line = rf->readLine();
      wf->writeLine(line);
      delete line;
   }

   rf->close();
   wf->close();
   delete rf;
   delete wf;

   return 0;
}
Ejemplo n.º 8
0
    int do_vprint(WriteFile& out, const char *fmt, va_list ap)
    {
        int len;
        {
            va_list ap2;
            va_copy(ap2, ap);
            len = vsnprintf(nullptr, 0, fmt, ap2);
            va_end(ap2);
        }
        char buffer[len + 1];
        vsnprintf(buffer, len + 1, fmt, ap);

        out.really_put(buffer, len);
        return len;
    }
Ejemplo n.º 9
0
void GameConfig::saveConfig()
{
    WriteFile* file = FileSystem::openWrite(configfile.c_str());

    file->writeSLE16(CONFIG_VERSION);

    file->write8(UnitColor);
    file->write8(GameMode);
    file->write8(GameType);
    file->writeSLE16(NumberPlayers);
    file->writeSLE16(NumberUnits);
    file->writeSLE16(NumberInitialUnits);

    // TODO lots of other stuff :)
    file->writeSLE32(screen_resolution);
    file->write8(screen_fullscreen);
    file->write8(display_shadows_flag);
    file->write8(display_unit_flags);

    delete file;
}