本文整理汇总了C++中FileReader::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ FileReader::Open方法的具体用法?C++ FileReader::Open怎么用?C++ FileReader::Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader::Open方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BuildPath
/* This is meant to find and open files for reading. */
FileReader *open_filereader(const char *name, int open, int *plumpnum)
{
FileReader *fp;
FString current_filename;
if (!name || !(*name))
{
return 0;
}
/* First try the given name */
current_filename = name;
FixPathSeperator(current_filename);
int lumpnum = Wads.CheckNumForFullName(current_filename);
if (open != OM_FILE)
{
if (lumpnum >= 0)
{
fp = Wads.ReopenLumpNum(lumpnum);
if (plumpnum) *plumpnum = lumpnum;
return fp;
}
if (open == OM_LUMP) // search the path list when not loading the main config
{
for (unsigned int plp = PathList.Size(); plp-- != 0; )
{ /* Try along the path then */
current_filename = BuildPath(PathList[plp], name);
lumpnum = Wads.CheckNumForFullName(current_filename);
if (lumpnum >= 0)
{
fp = Wads.ReopenLumpNum(lumpnum);
if (plumpnum) *plumpnum = lumpnum;
return fp;
}
}
return NULL;
}
}
if (plumpnum) *plumpnum = -1;
fp = new FileReader;
if (fp->Open(current_filename)) return fp;
if (name[0] != '/')
{
for (unsigned int plp = PathList.Size(); plp-- != 0; )
{ /* Try along the path then */
current_filename = BuildPath(PathList[plp], name);
if (fp->Open(current_filename)) return fp;
}
}
delete fp;
/* Nothing could be opened. */
current_filename = "";
return NULL;
}
示例2: EasyEncrypt
// 文件加密函数
// 这个函数有点长,但是基本上都是检错的代码。逻辑还是很清晰的。
errno_t EasyEncrypt(const string& inFilename, const string& outFilename, const string& key)
{
LOGPOS();
FileReader fileReader;
FilePath inFilePath(inFilename);
if (fileReader.Open(inFilePath.value()) != CPT_OK) {
LOGW("Open file %s failed!", inFilePath.value().c_str());
return CPT_ERROR;
}
Encrypt encrypt;
if (encrypt.SetReader(dynamic_cast<Reader*>(&fileReader)) != CPT_OK) {
LOGW("Encrypt Set Reader failed");
return CPT_ERROR;
}
FileHeader *fileHeader = encrypt.GenrHeader();
if (fileHeader == NULL) {
LOGW("Generate file header failed!");
return CPT_ERROR;
}
fileHeader->SetFormat(inFilePath.Extension());
if (encrypt.EncryptHeader(key.c_str(), key.length()) != CPT_OK) {
LOGW("Encrypt file header failed");
return CPT_ERROR;
}
FileWriter writer;
if (writer.Open(outFilename) != CPT_OK) {
LOGW("Create file %s failed!", outFilename.c_str());
return CPT_ERROR;
}
if (encrypt.SetWriter(dynamic_cast<Writer*>(&writer)) != CPT_OK) {
LOGW("encrypt set writer failed!");
return CPT_ERROR;
}
if (encrypt.WriteHeader() != CPT_OK) {
LOGW("Encrypt write header failed!");
return CPT_ERROR;
}
int err = encrypt.PreEncrypt();
ASSERT(err == CPT_OK);
if (encrypt.DoEncrypt(key.c_str(), key.length()) != CPT_OK) {
LOGW("Encrypt encrypt failed!");
return CPT_ERROR;
}
err = encrypt.PostEncrypt();
ASSERT(err == CPT_OK);
return CPT_OK;
}
示例3: EasyDecrypt
errno_t EasyDecrypt(const string& filename, const string& key, string *outFilename)
{
LOGPOS();
FilePath inFilePath(filename);
FileReader reader;
if (reader.Open(inFilePath.value()) != CPT_OK) {
LOGW("Open file %s failed!", inFilePath.value().c_str());
return CPT_ERROR;
}
Decrypt decrypt;
if (decrypt.SetReader(&reader) != CPT_OK) {
LOGW("Decrypt set reader failed!");
return CPT_ERROR;
}
if (decrypt.LoadHeader() != CPT_OK) {
LOGW("Decrypt load header failed!");
return CPT_ERROR;
}
FileHeader *fileHeader = decrypt.DecryptHeader(key.c_str(), key.length());
if (fileHeader == NULL) {
LOGW("LoadHeader error");
return CPT_ERROR;
}
FilePath outFilePath = inFilePath.ReplaceExtension(fileHeader->GetFormat());
*outFilename = outFilePath.value();
FileWriter writer;
if (writer.Open(outFilePath.value()) != CPT_OK) {
LOGW("Create file %s failed!", outFilePath.value().c_str());
return CPT_ERROR;
}
if (decrypt.SetWriter(dynamic_cast<Writer*>(&writer)) != CPT_OK) {
LOGW("Decrypt set writer failed!");
return CPT_ERROR;
}
int err = decrypt.PreDecrypt();
ASSERT(err == CPT_OK);
if (decrypt.DoDecrypt(key.c_str(), key.length())) {
LOGW("Decrypt decrypt file failed!");
return CPT_ERROR;
}
err = decrypt.PostDecrypt();
ASSERT(err == CPT_OK);
return CPT_OK;
}
示例4: EasyDecryptInMemory
errno_t EasyDecryptInMemory(const string& filename, const string& key, MemoryWriter *writer)
{
LOGPOS();
FilePath inFilePath(filename);
FileReader reader;
if (reader.Open(inFilePath.value()) != CPT_OK) {
LOGW("Open file %s failed!", inFilePath.value().c_str());
return CPT_ERROR;
}
uint64_t u64 = 0;
reader.GetLength(&u64);
if (writer->Reserve(u64) != CPT_OK) {
LOGW("MemoryWriter SetLength failed!");
return CPT_ERROR;
}
Decrypt decrypt;
if (decrypt.SetReader(&reader) != CPT_OK) {
LOGW("Decrypt set reader failed!");
return CPT_ERROR;
}
if (decrypt.LoadHeader() != CPT_OK) {
LOGW("Decrypt LoadHeader error");
return CPT_ERROR;
}
if (decrypt.DecryptHeader(key.c_str(), key.length()) == NULL) {
LOGW("LoadHeader error");
return CPT_ERROR;
}
if (decrypt.SetWriter(writer) != CPT_OK) {
LOGW("Decrypt set writer failed!");
return CPT_ERROR;
}
int err = decrypt.PreDecrypt();
ASSERT(err == CPT_OK);
if (decrypt.DoDecrypt(key.c_str(), key.length())) {
LOGW("Decrypt decrypt file failed!");
return CPT_ERROR;
}
err = decrypt.PostDecrypt();
ASSERT(err == CPT_OK);
return CPT_OK;
}
示例5: ReadCheckFile
void SPAuthCheckPrv::ReadCheckFile()
{
// Read check prevention file
mGameSecondsBeforeNextCheck = 1; // default -> check
try
{
FileReader aReader;
if(!aReader.Open(gSPAuthCheck_FileName))
return;
unsigned short aNumBytes = aReader.ReadShort();
if(aNumBytes==0 || aReader.Available()<aNumBytes)
return;
char *aBuf = new char[aNumBytes];
std::auto_ptr<char> aDelBuf(aBuf);
aReader.ReadBytes(aBuf,aNumBytes);
aReader.Close();
ByteBufferPtr aDecrypt = mEncryptKey.Decrypt(aBuf,aNumBytes);
if(aDecrypt.get()==NULL)
return;
WONFile aFile(gSPAuthCheck_FileName);
ReadBuffer aReadBuf(aDecrypt->data(),aDecrypt->length());
std::string aSig;
aReadBuf.ReadString(aSig);
if(aSig!="magic")
return;
time_t aCreateTime = aFile.GetCreateTime();
time_t aCompareCreateTime = aReadBuf.ReadLong();
if(aCompareCreateTime != aCreateTime)
return;
mGameSecondsBeforeNextCheck = aReadBuf.ReadLong();
if(mGameSecondsBeforeNextCheck==0) // don't remove file in this case
return;
aFile.Remove();
}
catch(FileReaderException&)
{
}
catch(ReadBufferException&)
{
}
}
示例6: Open
bool RPCFile::Open(const char* path)
{
FileReader* file = new FileReader();
if(!file->Open(path))
{
delete file;
return false;
}
bool ret = Open(file);
m_ownFile = true;
return ret;
}
示例7: catch
bool
GastofDQM(unsigned int address, string filename, vector<string>* outputs)
{
cout << "filename: " << filename << endl;
FileReader reader;
try { reader.Open(filename); } catch (Exception& e) { throw e; }
if (!reader.IsOpen()) throw Exception(__PRETTY_FUNCTION__, "Failed to build FileReader", JustWarning);
cout << "Run/Burst Id = " << reader.GetRunId() << " / " << reader.GetBurstId() << endl;
const unsigned int num_channels = 32;
double mean_num_events[num_channels], mean_tot[num_channels];
int trigger_td;
unsigned int num_events[num_channels];
enum plots {
kDensity,
kMeanToT,
//kTriggerTimeDiff,
kNumPlots
};
const unsigned short num_plots = kNumPlots;
DQM::GastofCanvas* canv[num_plots];
canv[kDensity] = new DQM::GastofCanvas(Form("gastof_%d_%d_%d_channels_density", reader.GetRunId(), reader.GetBurstId(), address), "Channels density");
canv[kMeanToT] = new DQM::GastofCanvas(Form("gastof_%d_%d_%d_mean_tot", reader.GetRunId(), reader.GetBurstId(), address), "Mean ToT (ns)");
//canv[kTriggerTimeDiff] = new DQM::GastofCanvas(Form("gastof_%d_%d_%d_trigger_time_difference", reader.GetRunId(), reader.GetBurstId(), address), "Time btw. each trigger (ns)");
VME::TDCMeasurement m;
for (unsigned int i=0; i<num_channels; i++) {
unsigned short nino_board, ch_id;
mean_num_events[i] = mean_tot[i] = 0.;
num_events[i] = 0;
trigger_td = 0;
try {
if (i<32) { nino_board = 1; ch_id = i; }
else { nino_board = 0; ch_id = i-32; }
while (true) {
if (!reader.GetNextMeasurement(i, &m)) break;
//if (trigger_td!=0) { canv[kTriggerTimeDiff]->FillChannel(nino_board, ch_id, (m.GetLeadingTime(0)-trigger_td)*25./1.e3); }
trigger_td = m.GetLeadingTime(0);
for (unsigned int j=0; j<m.NumEvents(); j++) {
mean_tot[i] += m.GetToT(j)*25./1.e3/m.NumEvents();
}
mean_num_events[i] += m.NumEvents();
if (m.NumEvents()!=0) num_events[i] += 1;
}
if (num_events[i]>0) {
mean_num_events[i] /= num_events[i];
mean_tot[i] /= num_events[i];
}
canv[kDensity]->FillChannel(nino_board, ch_id, mean_num_events[i]);
canv[kMeanToT]->FillChannel(nino_board, ch_id, mean_tot[i]);
cout << dec;
cout << "Finished extracting channel " << i << ": " << num_events[i] << " measurements, "
<< "mean number of hits: " << mean_num_events[i] << ", "
<< "mean tot: " << mean_tot[i] << endl;
reader.Clear();
} catch (Exception& e) {
e.Dump();
if (e.ErrorNumber()<41000) throw e;
}
}
for (unsigned int i=0; i<num_plots; i++) {
canv[i]->SetRunInfo(address, reader.GetRunId(), reader.GetBurstId(), TDatime().AsString());
canv[i]->Save("png", DQM_OUTPUT_DIR);
outputs->push_back(canv[i]->GetName());
}
return true;
}
示例8: ProcessDemoFile
bool ProcessDemoFile(const char* filePath)
{
for(u32 i = 0; i < ID_MAX_CLIENTS; ++i)
{
_players[i].Name.clear();
_players[i].Valid = false;
}
FileReader reader;
if(!reader.Open(filePath))
{
return false;
}
udtCuContext* const cuContext = _cuContext;
const u32 protocol = udtGetProtocolByFilePath(filePath);
const s32 firstPlayerIdx = udtGetIdConfigStringIndex((u32)udtConfigStringIndex::FirstPlayer, protocol);
if(firstPlayerIdx < 0)
{
PrintError("Failed to get the first index of player config strings");
return false;
}
_protocol = (udtProtocol::Id)protocol;
_protocolFirstPlayerCsIdx = firstPlayerIdx;
s32 errorCode = udtCuStartParsing(cuContext, protocol);
if(errorCode != udtErrorCode::None)
{
PrintError("udtCuStartParsing failed: %s", udtGetErrorCodeString(errorCode));
return false;
}
udtCuMessageInput input;
udtCuMessageOutput output;
u32 continueParsing = 0;
for(;;)
{
if(!reader.Read(&input.MessageSequence, 4))
{
PrintWarning("Demo is truncated");
return true;
}
if(!reader.Read(&input.BufferByteCount, 4))
{
PrintWarning("Demo is truncated");
return true;
}
if(input.MessageSequence == -1 &&
input.BufferByteCount == u32(-1))
{
// End of demo file.
break;
}
if(input.BufferByteCount > ID_MAX_MSG_LENGTH)
{
PrintError("Corrupt input: the buffer length exceeds the maximum allowed");
return false;
}
if(!reader.Read(_inMsgData, input.BufferByteCount))
{
PrintWarning("Demo is truncated");
return true;
}
input.Buffer = _inMsgData;
errorCode = udtCuParseMessage(cuContext, &output, &continueParsing, &input);
if(errorCode != udtErrorCode::None)
{
PrintError("udtCuParseMessage failed: %s", udtGetErrorCodeString(errorCode));
return false;
}
if(continueParsing == 0)
{
break;
}
AnalyzeMessage(output);
}
return true;
}
示例9: BenchmarkDArray
void BenchmarkDArray(Sorter<char *> &sorter)
{
DArray<char *> data, rdata;
Stopwatch sw;
char buffer[512], format[64];
sprintf(format, "%s", "%4.3lfs");
FileReader file;
file.SetLineEndings(CC_LN_LF);
file.Open("dataset");
if (file.IsOpen()) {
data.setStepDouble();
rdata.setStepDouble();
console->Write("Loading... ");
sw.Start();
/* Load the file into the data DArray */
while (file.ReadLine(buffer, sizeof(buffer)) >= 0)
data.insert(cc_strdup(buffer));
sw.Stop();
console->WriteLine(format, sw.Elapsed());
file.Close();
console->WriteLine("Loaded %d items.", data.used());
console->Write("Random: ");
sw.Start();
data.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
/* Create a reverse-sorted DArray */
for (long i = (long)data.size(); i >= 0; i--) {
if (data.valid(i)) {
rdata.insert(data.get(i));
}
}
console->Write("Pre-sorted: ");
sw.Start();
data.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
console->Write("Reverse-sorted: ");
sw.Start();
rdata.sort(sorter);
sw.Stop();
console->WriteLine(format, sw.Elapsed());
for (size_t i = 0; i < data.size(); i++) {
if (data.valid(i)) {
free(data.get(i));
data.remove(i);
}
}
data.empty();
rdata.empty();
} else {
console->WriteLine("Dataset not found.");
}
}
示例10: ParseReplay
bool ParseReplay(const char *pszFilename, DWORD dwFlags)
{
// Open replay file
FileReader fr;
if ( !fr.Open(pszFilename) )
return false;
///////////////////// Header
// Read replay resource identifier
DWORD dwRepResourceID = 0;
// Best guess: "reRS" is "replay RESOURCE"
if ( !DecompressRead(&dwRepResourceID, sizeof(dwRepResourceID), fr) || dwRepResourceID != mmioFOURCC('r','e','R','S') )
return errSimple("No Replay resource ID found.");
// Read replay resource header
if ( !DecompressRead(&replayHeader, sizeof(replayHeader), fr) )
return errSimple("Unable to read replay header.");
////////////////// Actions
// Read replay actions section size
DWORD dwActionBufferSize = 0;
if ( !DecompressRead(&dwActionBufferSize, 4, fr) )
return errSimple("Unable to read actions size.");
// Allocate and Read replay actions
void *pActionBuffer = malloc(dwActionBufferSize);
FileReader frActions(pActionBuffer, dwActionBufferSize);
if ( dwActionBufferSize && !DecompressRead(pActionBuffer, dwActionBufferSize, fr) )
return errSimple("Decompressing actions failed.");
/////////////////// Map Chk
// get map chunk data size
DWORD dwChkBufferSize = 0;
if ( !DecompressRead(&dwChkBufferSize, 4, fr) )
return errSimple("Unable to read chk size.");
// Allocate and Read chk data
void *pChkBuffer = malloc(dwChkBufferSize);
//FileReader frChk(pChkBuffer, dwChkBufferSize);
if ( dwChkBufferSize && !DecompressRead(pChkBuffer, dwChkBufferSize, fr) )
return errSimple("Decompressing map failed.");
// Write extracted replay data
if ( dwFlags & RFLAG_EXTRACT )
{
WriteBuffer("%s.hdr", pszFilename, &replayHeader, sizeof(replayHeader));
WriteBuffer("%s.act", pszFilename, pActionBuffer, dwActionBufferSize);
WriteBuffer("%s.chk", pszFilename, pChkBuffer, dwChkBufferSize);
}
// parse data for repair
if ( dwFlags & RFLAG_REPAIR )
{
// Parse replay actions
ParseActions(frActions);
if ( replayHeader.dwFrameCount < g_dwHighestFrame )
{
char szTmp[256];
sprintf(szTmp, "Fixed replay with %u frames. Desired: %u frames.", replayHeader.dwFrameCount, g_dwHighestFrame);
MessageBox(NULL, szTmp, "Fixed", 0);
//replayHeader.dwFrameCount = g_dwHighestFrame + 10;
}
FileWriter fw;
fw.Open(pszFilename);
// write rep resource id
dwRepResourceID = mmioFOURCC('r','e','R','S');
CompressWrite(&dwRepResourceID, sizeof(dwRepResourceID), fw);
// write header
CompressWrite(&replayHeader, sizeof(replayHeader), fw);
// write actions
CompressWrite(&dwActionBufferSize, sizeof(dwActionBufferSize), fw);
if ( dwActionBufferSize )
CompressWrite(pActionBuffer, dwActionBufferSize, fw);
// write chk
CompressWrite(&dwChkBufferSize, sizeof(dwChkBufferSize), fw);
if ( dwChkBufferSize )
CompressWrite(pChkBuffer, dwChkBufferSize, fw);
}
return true;
}