本文整理汇总了C++中DiskFile::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ DiskFile::Open方法的具体用法?C++ DiskFile::Open怎么用?C++ DiskFile::Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiskFile
的用法示例。
在下文中一共展示了DiskFile::Open方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendSegment
void NntpProcessor::SendSegment()
{
detail("[%i] Sending segment %s (%i=%lli:%i)", m_id, *m_filename, m_part, (long long)m_offset, m_size);
if (m_speed > 0)
{
m_start = Util::GetCurrentTicks();
}
BString<1024> fullFilename("%s/%s", m_dataDir, *m_filename);
BString<1024> cacheFileDir("%s/%s", m_cacheDir, *m_filename);
BString<1024> cacheFileName("%i=%lli-%i", m_part, (long long)m_offset, m_size);
BString<1024> cacheFullFilename("%s/%s", *cacheFileDir, *cacheFileName);
BString<1024> cacheKey("%s/%s", *m_filename, *cacheFileName);
const char* cachedData = nullptr;
int cachedSize;
if (m_cache)
{
m_cache->Find(cacheKey, cachedData, cachedSize);
}
DiskFile cacheFile;
bool readCache = !cachedData && m_cacheDir && cacheFile.Open(cacheFullFilename, DiskFile::omRead);
bool writeCache = !cachedData && m_cacheDir && !readCache;
StringBuilder cacheMem;
if (m_cache && !cachedData)
{
cacheMem.Reserve((int)(m_size * 1.1));
}
CString errmsg;
if (writeCache && !FileSystem::ForceDirectories(cacheFileDir, errmsg))
{
error("Could not create directory %s: %s", *cacheFileDir, *errmsg);
}
if (writeCache && !cacheFile.Open(cacheFullFilename, DiskFile::omWrite))
{
error("Could not create file %s: %s", *cacheFullFilename, *FileSystem::GetLastErrorMessage());
}
if (!cachedData && !readCache && !FileSystem::FileExists(fullFilename))
{
m_connection->WriteLine(CString::FormatStr("430 Article not found\r\n"));
return;
}
YEncoder encoder(fullFilename, m_part, m_offset, m_size,
[proc = this, writeCache, &cacheFile, &cacheMem](const char* buf, int size)
{
if (proc->m_cache)
{
cacheMem.Append(buf);
}
if (writeCache)
{
cacheFile.Write(buf, size);
}
proc->SendData(buf, size);
});
if (!cachedData && !readCache && !encoder.OpenFile(errmsg))
{
m_connection->WriteLine(CString::FormatStr("403 %s\r\n", *errmsg));
return;
}
m_connection->WriteLine(CString::FormatStr("%i, 0 %s\r\n", m_sendHeaders ? 222 : 220, m_messageid));
if (m_sendHeaders)
{
m_connection->WriteLine(CString::FormatStr("Message-ID: %s\r\n", m_messageid));
m_connection->WriteLine(CString::FormatStr("Subject: \"%s\"\r\n", FileSystem::BaseFileName(m_filename)));
m_connection->WriteLine("\r\n");
}
if (cachedData)
{
SendData(cachedData, cachedSize);
}
else if (readCache)
{
cacheFile.Seek(0, DiskFile::soEnd);
int size = (int)cacheFile.Position();
CharBuffer buf(size);
cacheFile.Seek(0);
if (cacheFile.Read((char*)buf, size) != size)
{
error("Could not read file %s: %s", *cacheFullFilename, *FileSystem::GetLastErrorMessage());
}
if (m_cache)
{
cacheMem.Append(buf, size);
}
SendData(buf, size);
}
else
{
encoder.WriteSegment();
}
//.........这里部分代码省略.........
示例2: memset
// Read source data, process it through the RS matrix and write it to disk.
bool Par2Creator::ProcessData(u64 blockoffset, size_t blocklength)
{
// Clear the output buffer
memset(outputbuffer, 0, chunksize * recoveryblockcount);
// If we have defered computation of the file hash and block crc and hashes
// sourcefile and sourceindex will be used to update them during
// the main recovery block computation
vector<Par2CreatorSourceFile*>::iterator sourcefile = sourcefiles.begin();
u32 sourceindex = 0;
vector<DataBlock>::iterator sourceblock;
u32 inputblock;
DiskFile *lastopenfile = NULL;
// For each input block
for ((sourceblock=sourceblocks.begin()),(inputblock=0);
sourceblock != sourceblocks.end();
++sourceblock, ++inputblock)
{
// Are we reading from a new file?
if (lastopenfile != (*sourceblock).GetDiskFile())
{
// Close the last file
if (lastopenfile != NULL)
{
lastopenfile->Close();
}
// Open the new file
lastopenfile = (*sourceblock).GetDiskFile();
if (!lastopenfile->Open())
{
return false;
}
}
// Read data from the current input block
if (!sourceblock->ReadData(blockoffset, blocklength, inputbuffer))
return false;
if (deferhashcomputation)
{
assert(blockoffset == 0 && blocklength == blocksize);
assert(sourcefile != sourcefiles.end());
(*sourcefile)->UpdateHashes(sourceindex, inputbuffer, blocklength);
}
// Function that does the subtask in multiple threads if appropriate.
if (!this->CreateParityBlocks (blocklength, inputblock))
return false;
// Work out which source file the next block belongs to
if (++sourceindex >= (*sourcefile)->BlockCount())
{
sourceindex = 0;
++sourcefile;
}
}
// Close the last file
if (lastopenfile != NULL)
{
lastopenfile->Close();
}
if (noiselevel > CommandLine::nlQuiet)
cout << "Writing recovery packets\r";
// For each output block
for (u32 outputblock=0; outputblock<recoveryblockcount;outputblock++)
{
// Select the appropriate part of the output buffer
char *outbuf = &((char*)outputbuffer)[chunksize * outputblock];
// Write the data to the recovery packet
if (!recoverypackets[outputblock].WriteData(blockoffset, blocklength, outbuf))
return false;
}
if (noiselevel > CommandLine::nlQuiet)
cout << "Wrote " << recoveryblockcount * blocklength << " bytes to disk" << endl;
return true;
}
示例3:
// Attempt to verify all of the source files
bool Par1Repairer::VerifySourceFiles(void) {
bool finalresult = true;
u32 filenumber = 0;
vector<Par1RepairerSourceFile*>::iterator sourceiterator = sourcefiles.begin();
while (sourceiterator != sourcefiles.end()) {
Par1RepairerSourceFile *sourcefile = *sourceiterator;
string filename = sourcefile->FileName();
// Check to see if we have already used this file
if (diskfilemap.Find(filename) != 0) {
string path;
string name;
DiskFile::SplitRelativeFilename(filename, path, name);
// The file has already been used!
// cerr << "Source file " << filenumber+1 << " is a duplicate." << endl; // Original
cerr << "Source file " << name << " is a duplicate." << endl; // Imported
finalresult = false;
} else {
DiskFile *diskfile = new DiskFile;
// Does the target file exist
if (diskfile->Open(filename)) {
// Yes. Record that fact.
sourcefile->SetTargetExists(true);
// Remember that the DiskFile is the target file
sourcefile->SetTargetFile(diskfile);
// Remember that we have processed this file
bool success = diskfilemap.Insert(diskfile);
assert(success);
// Do the actual verification
if (!VerifyDataFile(diskfile, sourcefile))
finalresult = false;
// We have finished with the file for now
diskfile->Close();
// Find out how much data we have found
UpdateVerificationResults();
} else {
// The file does not exist.
delete diskfile;
if (noiselevel > CommandLine::nlSilent) {
string path;
string name;
DiskFile::SplitFilename(filename, path, name);
cout << "Target: \"" << name << "\" - missing." << endl;
}
}
}
++sourceiterator;
++filenumber;
}
return finalresult;
}
示例4: offsetof
bool Par1Repairer::LoadRecoveryFile(string filename) {
// Skip the file if it has already been processed
if (diskfilemap.Find(filename) != 0) {
return true;
}
DiskFile *diskfile = new DiskFile;
// Open the file
if (!diskfile->Open(filename)) {
// If we could not open the file, ignore the error and
// proceed to the next file
delete diskfile;
return true;
}
if (noiselevel > CommandLine::nlSilent) {
string path;
string name;
DiskFile::SplitFilename(filename, path, name);
cout << "Loading \"" << name << "\"." << endl;
}
parlist.push_back(filename);
bool havevolume = false;
u32 volumenumber = 0;
// How big is the file
u64 filesize = diskfile->FileSize();
if (filesize >= sizeof(PAR1FILEHEADER)) {
// Allocate a buffer to read data into
size_t buffersize = (size_t)min((u64)1048576, filesize);
u8 *buffer = new u8[buffersize];
do {
PAR1FILEHEADER fileheader;
if (!diskfile->Read(0, &fileheader, sizeof(fileheader)))
break;
// Is this really a PAR file?
if (fileheader.magic != par1_magic)
break;
// Is the version number correct?
if (fileheader.fileversion != 0x00010000)
break;
ignore16kfilehash = (fileheader.programversion == smartpar11);
// Prepare to carry out MD5 Hash check of the Control Hash
MD5Context context;
u64 offset = offsetof(PAR1FILEHEADER, sethash);
// Process until the end of the file is reached
while (offset < filesize) {
// How much data should we read?
size_t want = (size_t)min((u64)buffersize, filesize-offset);
if (!diskfile->Read(offset, buffer, want))
break;
context.Update(buffer, want);
offset += want;
}
// Did we read the whole file
if (offset < filesize)
break;
// Compute the hash value
MD5Hash hash;
context.Final(hash);
// Is it correct?
if (hash != fileheader.controlhash)
break;
// Check that the volume number is ok
if (fileheader.volumenumber >= 256)
break;
// Are there any files?
if (fileheader.numberoffiles == 0 ||
fileheader.filelistoffset < sizeof(PAR1FILEHEADER) ||
fileheader.filelistsize == 0)
break;
// Verify that the file list and data offsets are ok
if ((fileheader.filelistoffset + fileheader.filelistsize > filesize)
||
(fileheader.datasize && (fileheader.dataoffset < sizeof(fileheader) || fileheader.dataoffset + fileheader.datasize > filesize))
||
(fileheader.datasize && ((fileheader.filelistoffset <= fileheader.dataoffset && fileheader.dataoffset < fileheader.filelistoffset+fileheader.filelistsize) || (fileheader.dataoffset <= fileheader.filelistoffset && fileheader.filelistoffset < fileheader.dataoffset + fileheader.datasize))))
break;
// Check the size of the file list
if (fileheader.filelistsize > 200000)
break;
//.........这里部分代码省略.........
示例5: memset
// Read source data, process it through the RS matrix and write it to disk.
bool Par2Creator::ProcessData(u64 blockoffset, size_t blocklength)
{
// Clear the output buffer
memset(outputbuffer, 0, chunksize * recoveryblockcount);
// If we have defered computation of the file hash and block crc and hashes
// sourcefile and sourceindex will be used to update them during
// the main recovery block computation
vector<Par2CreatorSourceFile*>::iterator sourcefile = sourcefiles.begin();
u32 sourceindex = 0;
vector<DataBlock>::iterator sourceblock;
u32 inputblock;
DiskFile *lastopenfile = NULL;
// For each input block
for ((sourceblock=sourceblocks.begin()),(inputblock=0);
sourceblock != sourceblocks.end();
++sourceblock, ++inputblock)
{
// Are we reading from a new file?
if (lastopenfile != (*sourceblock).GetDiskFile())
{
// Close the last file
if (lastopenfile != NULL)
{
lastopenfile->Close();
}
// Open the new file
lastopenfile = (*sourceblock).GetDiskFile();
if (!lastopenfile->Open())
{
return false;
}
}
// Read data from the current input block
if (!sourceblock->ReadData(blockoffset, blocklength, inputbuffer))
return false;
if (deferhashcomputation)
{
assert(blockoffset == 0 && blocklength == blocksize);
assert(sourcefile != sourcefiles.end());
(*sourcefile)->UpdateHashes(sourceindex, inputbuffer, blocklength);
}
// For each output block
#pragma omp parallel for
for (u32 outputblock=0; outputblock<recoveryblockcount; outputblock++)
{
// Select the appropriate part of the output buffer
void *outbuf = &((u8*)outputbuffer)[chunksize * outputblock];
// Process the data through the RS matrix
rs.Process(blocklength, inputblock, inputbuffer, outputblock, outbuf);
if (noiselevel > CommandLine::nlQuiet)
{
// Update a progress indicator
u32 oldfraction = (u32)(1000 * progress / totaldata);
#pragma omp atomic
progress += blocklength;
u32 newfraction = (u32)(1000 * progress / totaldata);
if (oldfraction != newfraction)
{
#pragma omp critical
cout << "Processing: " << newfraction/10 << '.' << newfraction%10 << "%\r" << flush;
}
}
}
// Work out which source file the next block belongs to
if (++sourceindex >= (*sourcefile)->BlockCount())
{
sourceindex = 0;
++sourcefile;
}
}
// Close the last file
if (lastopenfile != NULL)
{
lastopenfile->Close();
}
if (noiselevel > CommandLine::nlQuiet)
cout << "Writing recovery packets\r";
// For each output block
for (u32 outputblock=0; outputblock<recoveryblockcount;outputblock++)
{
// Select the appropriate part of the output buffer
char *outbuf = &((char*)outputbuffer)[chunksize * outputblock];
//.........这里部分代码省略.........
示例6: FlushCache
void ArticleWriter::FlushCache()
{
detail("Flushing cache for %s", *m_infoName);
bool directWrite = g_Options->GetDirectWrite() && m_fileInfo->GetOutputInitialized();
DiskFile outfile;
bool needBufFile = false;
int flushedArticles = 0;
int64 flushedSize = 0;
{
ArticleCache::FlushGuard flushGuard = g_ArticleCache->GuardFlush();
std::vector<ArticleInfo*> cachedArticles;
{
Guard contentGuard = g_ArticleCache->GuardContent();
if (m_fileInfo->GetFlushLocked())
{
return;
}
m_fileInfo->SetFlushLocked(true);
cachedArticles.reserve(m_fileInfo->GetArticles()->size());
for (ArticleInfo* pa : m_fileInfo->GetArticles())
{
if (pa->GetSegmentContent())
{
cachedArticles.push_back(pa);
}
}
}
for (ArticleInfo* pa : cachedArticles)
{
if (m_fileInfo->GetDeleted() && !m_fileInfo->GetNzbInfo()->GetParking())
{
// the file was deleted during flushing: stop flushing immediately
break;
}
if (directWrite && !outfile.Active())
{
if (!outfile.Open(m_fileInfo->GetOutputFilename(), DiskFile::omReadWrite))
{
m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
"Could not open file %s: %s", m_fileInfo->GetOutputFilename(),
*FileSystem::GetLastErrorMessage());
// prevent multiple error messages
pa->DiscardSegment();
flushedArticles++;
break;
}
needBufFile = true;
}
BString<1024> destFile;
if (!directWrite)
{
destFile.Format("%s.tmp", pa->GetResultFilename());
if (!outfile.Open(destFile, DiskFile::omWrite))
{
m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
"Could not create file %s: %s", *destFile,
*FileSystem::GetLastErrorMessage());
// prevent multiple error messages
pa->DiscardSegment();
flushedArticles++;
break;
}
needBufFile = true;
}
if (outfile.Active() && needBufFile)
{
SetWriteBuffer(outfile, 0);
needBufFile = false;
}
if (directWrite)
{
outfile.Seek(pa->GetSegmentOffset());
}
if (!g_Options->GetSkipWrite())
{
outfile.Write(pa->GetSegmentContent(), pa->GetSegmentSize());
}
flushedSize += pa->GetSegmentSize();
flushedArticles++;
pa->DiscardSegment();
if (!directWrite)
{
outfile.Close();
//.........这里部分代码省略.........
示例7: CompleteFileParts
void ArticleWriter::CompleteFileParts()
{
debug("Completing file parts");
debug("ArticleFilename: %s", m_fileInfo->GetFilename());
bool directWrite = (g_Options->GetDirectWrite() || m_fileInfo->GetForceDirectWrite()) && m_fileInfo->GetOutputInitialized();
BString<1024> nzbName;
BString<1024> nzbDestDir;
BString<1024> filename;
{
GuardedDownloadQueue guard = DownloadQueue::Guard();
nzbName = m_fileInfo->GetNzbInfo()->GetName();
nzbDestDir = m_fileInfo->GetNzbInfo()->GetDestDir();
filename = m_fileInfo->GetFilename();
}
BString<1024> infoFilename("%s%c%s", *nzbName, PATH_SEPARATOR, *filename);
bool cached = m_fileInfo->GetCachedArticles() > 0;
if (g_Options->GetRawArticle())
{
detail("Moving articles for %s", *infoFilename);
}
else if (directWrite && cached)
{
detail("Writing articles for %s", *infoFilename);
}
else if (directWrite)
{
detail("Checking articles for %s", *infoFilename);
}
else
{
detail("Joining articles for %s", *infoFilename);
}
// Ensure the DstDir is created
CString errmsg;
if (!FileSystem::ForceDirectories(nzbDestDir, errmsg))
{
m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
"Could not create directory %s: %s", *nzbDestDir, *errmsg);
return;
}
CString ofn;
if (m_fileInfo->GetForceDirectWrite())
{
ofn.Format("%s%c%s", *nzbDestDir, PATH_SEPARATOR, *filename);
}
else
{
ofn = FileSystem::MakeUniqueFilename(nzbDestDir, *filename);
}
DiskFile outfile;
BString<1024> tmpdestfile("%s.tmp", *ofn);
if (!g_Options->GetRawArticle() && !directWrite)
{
FileSystem::DeleteFile(tmpdestfile);
if (!outfile.Open(tmpdestfile, DiskFile::omWrite))
{
m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
"Could not create file %s: %s", *tmpdestfile, *FileSystem::GetLastErrorMessage());
return;
}
}
else if (directWrite && cached)
{
if (!outfile.Open(m_outputFilename, DiskFile::omReadWrite))
{
m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
"Could not open file %s: %s", *m_outputFilename, *FileSystem::GetLastErrorMessage());
return;
}
tmpdestfile = *m_outputFilename;
}
else if (g_Options->GetRawArticle())
{
FileSystem::DeleteFile(tmpdestfile);
if (!FileSystem::CreateDirectory(ofn))
{
m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
"Could not create directory %s: %s", *ofn, *FileSystem::GetLastErrorMessage());
return;
}
}
if (outfile.Active())
{
SetWriteBuffer(outfile, 0);
}
uint32 crc = 0;
{
//.........这里部分代码省略.........