コード例 #1
0
ファイル: ex_nfile.cpp プロジェクト: orpiske/nus
int main(void) { 
	NFile tmp;
	
	tmp.setFileName("testfile.tmp");
	if (tmp.exists()) { 
		NMessage::print() << "File " << tmp.getFileName() << " does not exist";
	}
	
	try {
		// Opening a file may throw a NIOException exception 
		// Put file in read-only mode to see it happening
		tmp.open(NIODevice::ReadWrite);
		
		// If the file was openned, write something to it
		tmp.write("test");
	} 
	catch (NIOException &e) { 
		NMessage::print() << "Error: " << e.getDescription();
		
		if (e.getResource() == NIOException::FILE) {
			NMessage::print() << "On file: " << e.getResourceName();
		}
		
		if (e.getFlag() == NIOException::IO_ACCESS_DENIED) {
			NWarning::print() << "Access Denied";
		}
	
		exit(1);
	}

	return 0;
}
コード例 #2
0
ファイル: nfilecreator.cpp プロジェクト: orpiske/nus
void create_if_not_exists(const NString &name, const NString &license, 
	bool force) 
{
	NFile outf; 
	NDataStream content;

	if (NFile::exists(name) && !force) { 
		NMessage::print() << "File " << name << " already exists.";

		return;
	}

	outf.setFileName(name);
	outf.open(NIODevice::Truncate);

	if (license != "") {
		content = content + license + "\n";
	}
	
	content = content + "// Source code file created by nproj " 
		+ N_TOOLS_VERSION + " with NUS version " 
		+ N_VERSION  + "\n";
	
	outf.write(content);
	outf.closeDevice();
}
コード例 #3
0
ファイル: saveadapter.cpp プロジェクト: mdl8bit/caesaria-game
bool SaveAdapter::save( const VariantMap& options, const vfs::Path& filename )
{
  std::string data = Json::serialize( options.toVariant(), " " );
  if( !data.empty() )
  {
    NFile f = NFile::open( filename, Entity::fmWrite );
    f.write( data.c_str(), data.size() );
    f.flush();
  }

  return true;
}