예제 #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
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
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;
}