u64 CFileSystemGCWii::GetFileSize(const std::string& _rFullPath) { if (!m_Initialized) InitFileSystem(); const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); if (pFileInfo != nullptr && !pFileInfo->IsDirectory()) return pFileInfo->m_FileSize; return 0; }
u64 CFileSystemGCWii::GetFileSize(const char* _rFullPath) { if (!m_Initialized) InitFileSystem(); const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); if (pFileInfo != NULL && !pFileInfo->IsDirectory()) return pFileInfo->m_FileSize; return 0; }
size_t CARCFile::GetFileSize(const std::string& _rFullPath) { if (!m_Initialized) { return(0); } const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); if (pFileInfo != NULL) { return((size_t) pFileInfo->m_FileSize); } return(0); }
u64 CFileSystemGCWii::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) { if (!m_Initialized) InitFileSystem(); const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); if (pFileInfo == nullptr) return 0; if (pFileInfo->m_FileSize > _MaxBufferSize) return 0; DEBUG_LOG(DISCIO, "Filename: %s. Offset: %" PRIx64 ". Size: %" PRIx64, _rFullPath.c_str(), pFileInfo->m_Offset, pFileInfo->m_FileSize); m_rVolume->Read(pFileInfo->m_Offset, pFileInfo->m_FileSize, _pBuffer); return pFileInfo->m_FileSize; }
u64 CFileSystemGCWii::ReadFile(const char* _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) { if (!m_Initialized) InitFileSystem(); const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); if (pFileInfo == NULL) return 0; if (pFileInfo->m_FileSize > _MaxBufferSize) return 0; DEBUG_LOG(DISCIO, "Filename: %s. Offset: %llx. Size: %llx",_rFullPath, pFileInfo->m_Offset, pFileInfo->m_FileSize); m_rVolume->Read(pFileInfo->m_Offset, pFileInfo->m_FileSize, _pBuffer); return pFileInfo->m_FileSize; }
bool CARCFile::ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) { if (!m_Initialized) { return(false); } const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); if (pFileInfo == NULL) { return(false); } File::IOFile pFile(_rExportFilename, "wb"); return pFile.WriteBytes(&m_pBuffer[pFileInfo->m_Offset], (size_t) pFileInfo->m_FileSize); }
u64 CFileSystemGCWii::ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64 _MaxBufferSize, u64 _OffsetInFile) { if (!m_Initialized) InitFileSystem(); const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); if (pFileInfo == nullptr) return 0; if (_OffsetInFile >= pFileInfo->m_FileSize) return 0; u64 read_length = std::min(_MaxBufferSize, pFileInfo->m_FileSize - _OffsetInFile); DEBUG_LOG(DISCIO, "Reading %" PRIx64 " bytes at %" PRIx64 " from file %s. Offset: %" PRIx64 " Size: %" PRIx64, read_length, _OffsetInFile, _rFullPath.c_str(), pFileInfo->m_Offset, pFileInfo->m_FileSize); m_rVolume->Read(pFileInfo->m_Offset + _OffsetInFile, read_length, _pBuffer, m_Wii); return read_length; }
bool CFileSystemGCWii::ExportFile(const std::string& _rFullPath, const std::string& _rExportFilename) { if (!m_Initialized) InitFileSystem(); const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); if (!pFileInfo) return false; u64 remainingSize = pFileInfo->m_FileSize; u64 fileOffset = pFileInfo->m_Offset; File::IOFile f(_rExportFilename, "wb"); if (!f) return false; bool result = true; while (remainingSize) { // Limit read size to 128 MB size_t readSize = (size_t)std::min(remainingSize, (u64)0x08000000); std::vector<u8> buffer(readSize); result = m_rVolume->Read(fileOffset, readSize, &buffer[0], m_Wii); if (!result) break; f.WriteBytes(&buffer[0], readSize); remainingSize -= readSize; fileOffset += readSize; } return result; }
size_t CARCFile::ReadFile(const std::string& _rFullPath, u8* _pBuffer, size_t _MaxBufferSize) { if (!m_Initialized) { return(0); } const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); if (pFileInfo == NULL) { return(0); } if (pFileInfo->m_FileSize > _MaxBufferSize) { return(0); } memcpy(_pBuffer, &m_pBuffer[pFileInfo->m_Offset], (size_t)pFileInfo->m_FileSize); return((size_t) pFileInfo->m_FileSize); }
void QueueEditor::PrepareList(ItemList* itemList, IdList* idList, DownloadQueue::EEditAction action, int offset) { if (action == DownloadQueue::eaFileMoveTop || action == DownloadQueue::eaGroupMoveTop) { offset = -MAX_ID; } else if (action == DownloadQueue::eaFileMoveBottom || action == DownloadQueue::eaGroupMoveBottom) { offset = MAX_ID; } itemList->reserve(idList->size()); if ((offset != 0) && (action == DownloadQueue::eaFileMoveOffset || action == DownloadQueue::eaFileMoveTop || action == DownloadQueue::eaFileMoveBottom)) { // add IDs to list in order they currently have in download queue for (NzbInfo* nzbInfo : m_downloadQueue->GetQueue()) { int nrEntries = (int)nzbInfo->GetFileList()->size(); int lastDestPos = -1; int start, end, step; if (offset < 0) { start = 0; end = nrEntries; step = 1; } else { start = nrEntries - 1; end = -1; step = -1; } for (int index = start; index != end; index += step) { std::unique_ptr<FileInfo>& fileInfo = nzbInfo->GetFileList()->at(index); IdList::iterator it2 = std::find(idList->begin(), idList->end(), fileInfo->GetId()); if (it2 != idList->end()) { int workOffset = offset; int destPos = index + workOffset; if (lastDestPos == -1) { if (destPos < 0) { workOffset = -index; } else if (destPos > nrEntries - 1) { workOffset = nrEntries - 1 - index; } } else { if (workOffset < 0 && destPos <= lastDestPos) { workOffset = lastDestPos - index + 1; } else if (workOffset > 0 && destPos >= lastDestPos) { workOffset = lastDestPos - index - 1; } } lastDestPos = index + workOffset; itemList->emplace_back(fileInfo.get(), nullptr, workOffset); } } } } else if ((offset != 0) && (action == DownloadQueue::eaGroupMoveOffset || action == DownloadQueue::eaGroupMoveTop || action == DownloadQueue::eaGroupMoveBottom)) { // add IDs to list in order they currently have in download queue // per group only one FileInfo is added to the list int nrEntries = (int)m_downloadQueue->GetQueue()->size(); int lastDestPos = -1; int start, end, step; if (offset < 0) { start = 0; end = nrEntries; step = 1; } else { start = nrEntries - 1; end = -1; step = -1; } for (int index = start; index != end; index += step) { std::unique_ptr<NzbInfo>& nzbInfo = m_downloadQueue->GetQueue()->at(index); IdList::iterator it2 = std::find(idList->begin(), idList->end(), nzbInfo->GetId()); if (it2 != idList->end()) { int workOffset = offset; int destPos = index + workOffset; if (lastDestPos == -1) { if (destPos < 0) { workOffset = -index; } else if (destPos > nrEntries - 1) { workOffset = nrEntries - 1 - index; } } else { if (workOffset < 0 && destPos <= lastDestPos) { workOffset = lastDestPos - index + 1; } else if (workOffset > 0 && destPos >= lastDestPos) { workOffset = lastDestPos - index - 1; } } lastDestPos = index + workOffset; itemList->emplace_back(nullptr, nzbInfo.get(), workOffset); } } } else if (action < DownloadQueue::eaGroupMoveOffset) { // check ID range int maxId = 0; int minId = MAX_ID; for (NzbInfo* nzbInfo : m_downloadQueue->GetQueue()) { for (FileInfo* fileInfo : nzbInfo->GetFileList()) { int ID = fileInfo->GetId(); if (ID > maxId) { maxId = ID; } if (ID < minId) { minId = ID; } } } //add IDs to list in order they were transmitted in command for (int id : *idList) { if (minId <= id && id <= maxId) { FileInfo* fileInfo = FindFileInfo(id); if (fileInfo) { itemList->emplace_back(fileInfo, nullptr, offset); } } } } else { // check ID range int maxId = 0; int minId = MAX_ID; for (NzbInfo* nzbInfo : m_downloadQueue->GetQueue()) { int ID = nzbInfo->GetId(); if (ID > maxId) { maxId = ID; } if (ID < minId) { minId = ID; } } //add IDs to list in order they were transmitted in command for (int id : *idList) { if (minId <= id && id <= maxId) { for (NzbInfo* nzbInfo : m_downloadQueue->GetQueue()) { if (id == nzbInfo->GetId()) { itemList->emplace_back(nullptr, nzbInfo, offset); } } } } } }
void QueueEditor::PrepareList(DownloadQueue* pDownloadQueue, ItemList* pItemList, IDList* pIDList, bool bSmartOrder, EEditAction EEditAction, int iOffset) { if (EEditAction == eaFileMoveTop) { iOffset = -MAX_ID; } else if (EEditAction == eaFileMoveBottom) { iOffset = MAX_ID; } pItemList->reserve(pIDList->size()); if (bSmartOrder && iOffset != 0 && (EEditAction == eaFileMoveOffset || EEditAction == eaFileMoveTop || EEditAction == eaFileMoveBottom)) { //add IDs to list in order they currently have in download queue int iLastDestPos = -1; int iStart, iEnd, iStep; if (iOffset < 0) { iStart = 0; iEnd = pDownloadQueue->GetFileQueue()->size(); iStep = 1; } else { iStart = pDownloadQueue->GetFileQueue()->size() - 1; iEnd = -1; iStep = -1; } for (int iIndex = iStart; iIndex != iEnd; iIndex += iStep) { FileInfo* pFileInfo = pDownloadQueue->GetFileQueue()->at(iIndex); int iID = pFileInfo->GetID(); for (IDList::iterator it = pIDList->begin(); it != pIDList->end(); it++) { if (iID == *it) { int iWorkOffset = iOffset; int iDestPos = iIndex + iWorkOffset; if (iLastDestPos == -1) { if (iDestPos < 0) { iWorkOffset = -iIndex; } else if (iDestPos > int(pDownloadQueue->GetFileQueue()->size()) - 1) { iWorkOffset = int(pDownloadQueue->GetFileQueue()->size()) - 1 - iIndex; } } else { if (iWorkOffset < 0 && iDestPos <= iLastDestPos) { iWorkOffset = iLastDestPos - iIndex + 1; } else if (iWorkOffset > 0 && iDestPos >= iLastDestPos) { iWorkOffset = iLastDestPos - iIndex - 1; } } iLastDestPos = iIndex + iWorkOffset; pItemList->push_back(new EditItem(pFileInfo, iWorkOffset)); break; } } } } else { // check ID range int iMaxID = 0; int iMinID = MAX_ID; for (FileQueue::iterator it = pDownloadQueue->GetFileQueue()->begin(); it != pDownloadQueue->GetFileQueue()->end(); it++) { FileInfo* pFileInfo = *it; int ID = pFileInfo->GetID(); if (ID > iMaxID) { iMaxID = ID; } if (ID < iMinID) { iMinID = ID; } } //add IDs to list in order they were transmitted in command for (IDList::iterator it = pIDList->begin(); it != pIDList->end(); it++) { int iID = *it; if (iMinID <= iID && iID <= iMaxID) { FileInfo* pFileInfo = FindFileInfo(pDownloadQueue, iID); if (pFileInfo) { pItemList->push_back(new EditItem(pFileInfo, iOffset)); } } } } }