本文整理汇总了C++中COFile::open方法的典型用法代码示例。如果您正苦于以下问题:C++ COFile::open方法的具体用法?C++ COFile::open怎么用?C++ COFile::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类COFile
的用法示例。
在下文中一共展示了COFile::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_saveAsPushButton_clicked
void CTile_edit_dlg::on_saveAsPushButton_clicked()
{
QFileDialog::Options options;
QString selectedFilter;
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Bank"), this->mainFile.absoluteFilePath(), tr("NeL tile bank files (*.bank);;All Files (*.*);;"), &selectedFilter, options);
if (!fileName.isEmpty())
{
// Set MainFile
mainFile = QFileInfo(fileName);
ui.savePushButton->setEnabled(true);
string fullPath = this->mainFile.absoluteFilePath().toUtf8();
if ( !fullPath.empty() )
{
COFile stream;
if ( stream.open( fullPath.c_str() ) )
{
tileBank.serial (stream);
QString s = tr("Bank %1 saved").arg( QString( fullPath.c_str() ) );
QMessageBox::information(this, tr("Bank Saved"), s);
return;
}
}
QMessageBox::information(this, tr("Error"), tr("Can't Save Bank, check the path"));
}
}
示例2: on_exportPushButton_clicked
void CTile_edit_dlg::on_exportPushButton_clicked()
{
QFileDialog::Options options;
QString selectedFilter;
QString fileName = QFileDialog::getSaveFileName(this, tr("Export Bank"), this->mainFile.absolutePath() + QDir::separator() + tr("*.smallbank"), tr("NeL tile small bank files (*.smallbank);;All Files (*.*);;"), &selectedFilter, options);
if (!fileName.isEmpty())
{
// Copy the bank
CTileBank copy=tileBank;
// Remove unused data
copy.cleanUnusedData ();
QFileInfo fileInfo(fileName);
string fullPath = fileInfo.absoluteFilePath().toUtf8();
if ( !fullPath.empty() )
{
COFile stream;
if ( stream.open( fullPath.c_str() ) )
{
copy.serial (stream);
QString s = tr("Bank %1 exported").arg( QString( fullPath.c_str() ) );
QMessageBox::information(this, tr("Bank Saved"), s);
return;
}
}
QMessageBox::information(this, tr("Error"), tr("Can't Export the Bank, check the path"));
}
}
示例3: exportVegetable
bool CNelExport::exportVegetable (const char *sPath, INode& node, TimeValue time)
{
bool bRet=false;
// Build a vegetable
NL3D::CVegetableShape vegetable;
if (_ExportNel->buildVegetableShape (vegetable, node, time))
{
// Open a file
COFile file;
if (file.open (sPath))
{
try
{
// Serial the shape
vegetable.serial (file);
// All is good
bRet=true;
}
catch (Exception &e)
{
// Message box
const char *message = e.what();
_ExportNel->outputErrorMessage ("Error during vegetable serialisation");
}
}
}
return bRet;
}
示例4: save
void CSoundAnimation::save()
{
// File stream
COFile file;
vector<NLMISC::CSheetId> sounds;
// Open the file
if (!file.open(_Filename.c_str()))
{
throw NLMISC::Exception("Can't open the file for writing");
}
// Create the XML stream
COXml output;
// Init
if (output.init (&file, "1.0"))
{
xmlDocPtr xmlDoc = output.getDocument();
// Create the first node
xmlNodePtr root = xmlNewDocNode (xmlDoc, NULL, (const xmlChar*)"SOUNDANIMATION", NULL);
xmlDocSetRootElement (xmlDoc, root);
vector<CSoundAnimMarker*>::iterator iter;
for (iter = _Markers.begin(); iter != _Markers.end(); iter++)
{
CSoundAnimMarker* marker = (*iter);
set<string>::iterator iter;
char s[64];
smprintf(s, 64, "%f", marker->getTime());
xmlNodePtr markerNode = xmlNewChild (root, NULL, (const xmlChar*)"MARKER", NULL);
xmlSetProp (markerNode, (const xmlChar*) "time", (const xmlChar*) s);
marker->getSounds(sounds);
vector<NLMISC::CSheetId>::iterator iter2;
for (iter2 = sounds.begin(); iter2 != sounds.end(); iter2++)
{
xmlNodePtr soundNode = xmlNewChild ( markerNode, NULL, (const xmlChar*)"SOUND", NULL );
xmlSetProp (soundNode, (const xmlChar*)"name", (const xmlChar*)iter2->toString().c_str() /*CStringMapper::unmap(*iter2).c_str()*/);
}
sounds.clear();
}
// Flush the stream, write all the output file
output.flush ();
}
// Close the file
file.close ();
_Dirty = false;
}
示例5: main
int main(int argc, char* argv[])
{
// Arg ?
if (argc<3)
{
// Doc
printf ("build_smallbank [input.bank] [output.smallbank] [new_absolute_path]\n");
}
else
{
try
{
// Load the bank
CTileBank bank;
// Input file
CIFile input;
if (input.open (argv[1]))
{
// Serial the bank
bank.serial (input);
// Make a small bank
bank.cleanUnusedData ();
// Absolute path ?
if (argc>3)
bank.setAbsPath (argv[3]);
// Output file
COFile output;
if (output.open (argv[2]))
{
// Serial the bank
bank.serial (output);
}
else
{
// Error
nlwarning ("ERROR can't open the file %s for writing", argv[2]);
}
}
else
{
// Error
nlwarning ("ERROR can't open the file %s for reading", argv[1]);
}
}
catch (const Exception& e)
{
// Error
nlwarning ("ERROR fatal error: %s", e.what());
}
}
return 0;
}
示例6: main
int main(int argc, char *argv[])
{
if(argc != 4)
{
usage();
return -1;
}
else
{
CBitmap btmp;
CIFile inFile;
COFile outFile;
uint divideRatio;
NLMISC::fromString(argv[3], divideRatio);
if(divideRatio==0 || !isPowerOf2(divideRatio))
{
printf("divideRatio must be a powerOf2 (1, 2, 4, 8 ...) \n");
return 0;
}
try
{
// read.
if (!inFile.open(argv[1]))
{
printf("Can't open input file %s \n", argv[1]);
return -1;
}
uint8 depth= btmp.load(inFile);
if(depth==0)
throw Exception("Bad File Format");
inFile.close();
// resize.
btmp.resample(btmp.getWidth() / divideRatio, btmp.getHeight() / divideRatio);
// output.
if (!outFile.open(argv[2]))
{
printf("Can't open output file %s \n", argv[2]);
return -1;
}
btmp.writeTGA(outFile, depth);
}
catch (const Exception &e)
{
printf("Error: %s\n", e.what());
return -1;
}
return 0;
}
}
示例7: generateSpellList
/** Generate list of spell
*/
static void generateSpellList(CConfigFile &cf, const std::string &sheetName)
{
CConfigFile::CVar *spellList = cf.getVarPtr("spell_list");
if (!spellList)
{
nlwarning("Can't read spell list");
return;
}
COFile f;
if (!f.open(sheetName, false, true))
{
nlwarning("Can't write %s", sheetName.c_str());
return;
}
try
{
COXml xmlStreamOut;
xmlStreamOut.init(&f);
xmlStreamOut.xmlPush("FORM");
IStream &xmlStream = xmlStreamOut;
xmlStream.xmlPush("STRUCT");
xmlStream.xmlPushBegin("ARRAY");
xmlStream.xmlSetAttrib("Name");
std::string name = "List";
xmlStream.serial(name);
xmlStream.xmlPushEnd();
for(uint k = 0; k < (uint) spellList->size(); ++k)
{
std::vector<std::string> result;
NLMISC::splitString(spellList->asString(k), "|", result);
if (result.size() < 2)
{
nlwarning("Should provide at list spell name and id");
}
xmlStream.xmlPush("STRUCT");
writeAtom(xmlStream, "ID", result[1]);
writeAtom(xmlStream, "SheetBaseName", result[0]);
xmlStream.xmlPop();
}
xmlStream.xmlPop(); // STRUCT
xmlStream.xmlPop(); // FORM
}
catch(const EStream &)
{
nlwarning("Cant write %s", sheetName.c_str());
}
}
示例8: MakeTyp
// ---------------------------------------------------------------------------
void CGeorgesImpl::MakeTyp( const std::string& filename, TType type, TUI ui, const std::string& _min, const std::string& _max, const std::string& _default, const std::vector< std::pair< std::string, std::string > >* const _pvpredef )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// Create a type
CType t;
t.Type = (CType::TType)type;
t.UIType = (CType::TUI)ui;
t.Min= _min;
t.Max = _max;
t.Default = _default;
if (_pvpredef)
{
t.Definitions.resize (_pvpredef->size ());
uint i;
for (i=0; i<_pvpredef->size (); i++)
{
t.Definitions[i].Label = (*_pvpredef)[i].first;
t.Definitions[i].Value = (*_pvpredef)[i].second;
}
}
// Save the type
COFile output;
if (output.open (filename))
{
try
{
// XML stream
COXml outputXml;
outputXml.init (&output);
// Write
t.write (outputXml.getDocument ());
}
catch (Exception &e)
{
nlwarning ("Error during writing file '%s' : ", filename.c_str (), e.what ());
}
}
else
{
nlwarning ("Can't open the file %s for writing", filename.c_str ());
}
}
示例9: on_savePushButton_clicked
void CTile_edit_dlg::on_savePushButton_clicked()
{
string fullPath = this->mainFile.absoluteFilePath().toUtf8();
if ( !fullPath.empty() )
{
COFile stream;
if ( stream.open( fullPath.c_str() ) )
{
tileBank.serial (stream);
QString s = tr("Bank %1 saved").arg( QString( fullPath.c_str() ) );
QMessageBox::information(this, tr("Bank Saved"), s);
return;
}
}
QMessageBox::information(this, tr("Error"), tr("Can't Save Bank, check the path"));
}
示例10: createInstanceFile
// ---------------------------------------------------------------------------
void CGeorgesImpl::createInstanceFile (const std::string &_sxFullnameWithoutExt, const std::string &_dfnname)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CFormLoader formLoader;
CFormDfn *dfn = formLoader.loadFormDfn (_dfnname.c_str(), false);
if (!dfn)
{
char msg[512];
smprintf (msg, 512, "Can't load DFN '%s'", _dfnname);
theApp.outputError (msg);
return;
}
NLMISC::CSmartPtr<NLGEORGES::UForm> Form = new CForm;
std::string fullName;
fullName = _sxFullnameWithoutExt + ".";
int i = 0;
if (_dfnname[i] == '.') ++i;
for (; i < (int)_dfnname.size(); ++i)
{
if (_dfnname[i] == '.') break;
fullName += _dfnname[i];
}
((CFormElmStruct*)&Form->getRootNode ())->build (dfn);
COFile f;
COXml ox;
if (f.open (fullName))
{
ox.init(&f);
((NLGEORGES::CForm*)((UForm*)Form))->write (ox.getDocument(), _sxFullnameWithoutExt.c_str ());
ox.flush();
f.close();
}
else
{
char msg[512];
smprintf (msg, 512, "Can't write '%s'", fullName);
theApp.outputError (msg);
return;
}
}
示例11: setDebugOutput
//-----------------------------------------------
// setDebugOutput :
// Set an output file to log debugs.
//-----------------------------------------------
void setDebugOutput(const std::string &filename)
{
// Remove output
if(filename.empty())
{
DebugFile.close();
IsDebugFile = false;
return;
}
// Open The Item Association File
if(!DebugFile.open(filename, false, true))
{
nlwarning("setDebugOutput: Cannot Open the '%s'.", filename.c_str());
IsDebugFile = false;
}
else
IsDebugFile = true;
}// setDebugOutput //
示例12:
/*
* Save a Reference index file
*/
bool CRefIndex::save(const string& filename)
{
COFile reffile;
COXml oxml;
if (!reffile.open(filename) || !oxml.init(&reffile))
return false;
try
{
serial(oxml);
}
catch (const Exception&)
{
return false;
}
return true;
}
示例13: load
//-----------------------------------------------
// load :
// Load all sheets.
//-----------------------------------------------
void CSheetManager::load(NLMISC::IProgressCallback &callBack, bool updatePackedSheet, bool needComputeVS, bool dumpVSIndex)
{
// Open The Item Association File
if(!fItemAssoc.open("item_association.dbg", false, true))
nlwarning("CSheetManager::load: Cannot Open the 'item_association.txt'.");
else
ItemAssocFileOpen = true;
// Initialize the Sheet DB.
loadAllSheet(callBack, updatePackedSheet, needComputeVS, dumpVSIndex);
// Close the Item Association File.
fItemAssoc.close();
ItemAssocFileOpen = false;
// Optimize memory taken by all strings of all sheets
ClientSheetsStrings.memoryCompress();
return;
}// load //
示例14: getUserDirectory
void CMailForumService::openSession( uint32 shardid, string username, string cookie )
{
string sessionfile = getUserDirectory(shardid, username) + "session";
string checkmailfile = getUserDirectory(shardid, username) + "new_mails";
COFile ofile;
if (ofile.open(sessionfile))
{
cookie += "\n";
ofile.serialBuffer((uint8*)(&cookie[0]), (uint)cookie.size());
}
if (CFile::fileExists(checkmailfile))
{
CFile::deleteFile(checkmailfile);
CMessage msgout("MAIL_NOTIF");
msgout.serial(shardid, username);
CUnifiedNetwork::getInstance()->send("EGS", msgout);
}
}
示例15: fileName
/*
* Save State
*/
bool CDatabaseState::save(CRefIndex& ref)
{
COFile f;
COXml oxml;
string filename = fileName(ref);
if (!f.open(filename) || !oxml.init(&f))
return false;
try
{
serial(oxml);
}
catch (const Exception&)
{
return false;
}
return true;
}