int CConfigFileReader::SetConfigValue(const char* name, const char* value) { if (!m_load_ok) return -1; map<string, string>::iterator it = m_config_map.find(name); if (it != m_config_map.end()) { it->second = value; } else { m_config_map.insert(make_pair(name, value)); } return _WriteFile(); }
bool GeneralEncriptyMaker::MakePackage(string& strPackageName, string& strFolderName, DWORD dwKey1, DWORD dwKey2, GeneralSafetyFunc pfEncodeFunc){ m_nWholeFilePathLength = 0; m_nPreGraphLength = 0; m_nRecordedGraphLength = 0; m_nCmpedSize = 0; m_strFolderName = strFolderName; m_strPackageName = strPackageName; m_pfEncodeFunc = pfEncodeFunc; m_dwKey1 = dwKey1; m_dwKey2 = dwKey2; _MakeHeader(); cout << "Path Processing..." << endl; if (!_PathRecord(m_strFolderName.c_str())) return false; cout << "Completed !" << endl; cout << "Index And File Path Processing..." << endl; if (!_IndexAndFilePathDataMake()) return false; cout << "Completed !" << endl; cout << "Write Data..." << endl; if (!_WriteFile()) return false; cout << "Completed !" << endl; return true; }
void MainTask(void) { unsigned i; U32 Space; U32 NumLoops; U32 NumBytes; U32 NumBytesAtOnce; FS_FILE * pFile; I32 t; FS_Init(); _TestNo = -1; // // Check if we need to low-level format the volume // if (FS_IsLLFormatted(VOLUME_NAME) == 0) { FS_X_Log("Low level formatting\n"); FS_FormatLow(VOLUME_NAME); /* Erase & Low-level format the flash */ } // // Volume is always high level formatted // before doing any performance tests. // FS_X_Log("High level formatting\n"); #if FS_SUPPORT_FAT if (FS_FormatSD(VOLUME_NAME) == 0) { #else if (FS_Format(VOLUME_NAME, NULL) == 0) { #endif // // Disable that the directory entry is every time // updated after a write operation // FS_ConfigUpdateDirOnWrite(0); // // Fill the buffer with data // FS_MEMSET((void*)_aBuffer, 'a', sizeof(_aBuffer)); // // Get some general info // Space = FS_GetVolumeFreeSpace(VOLUME_NAME); Space = MIN(Space, FILE_SIZE); NumBytes = BLOCK_SIZE * NUM_BLOCKS_MEASURE; NumBytesAtOnce = BLOCK_SIZE; NumLoops = Space / NumBytes; // // Create file of full size // _StartTest("W", NumBytes); pFile = FS_FOpen(FILE_NAME, "w"); // // Preallocate the file, setting the file pointer to the highest position // and declare it as the end of the file. // FS_SetFilePos(pFile, Space, FS_FILE_BEGIN); FS_SetEndOfFile(pFile); // // Set file position to the beginning // FS_SetFilePos(pFile, 0, FS_FILE_BEGIN); // // Check write performance with clusters/file size preallocated // sprintf(_ac, "Writing %lu chunks of %lu Bytes: ", NumLoops, NumBytes); FS_X_Log(_ac); for (i = 0; i < NumLoops ; i++) { t = _WriteFile(pFile, &_aBuffer[0], NumBytesAtOnce); _StoreResult(t); FS_X_Log("."); } FS_X_Log("OK\n"); FS_FClose(pFile); // // Check read performance // _StartTest("R", NumBytes); sprintf(_ac, "Reading %lu chunks of %lu Bytes: " , NumLoops, NumBytes); FS_X_Log(_ac); pFile = FS_FOpen(FILE_NAME, "r"); for (i = 0; i < NumLoops; i++) { t = _ReadFile(pFile, _aBuffer, NumBytesAtOnce); _StoreResult(t); FS_X_Log("."); } FS_X_Log("OK\n\n"); FS_FClose(pFile); // // Show results for performance list // for (i = 0; i <= (unsigned)_TestNo; i++) { sprintf(_ac, "%s Speed: %f kByte/s\n", _aResult[i].sName, _GetAverage(i)); FS_X_Log(_ac); } FS_X_Log("Finished\n"); FS_Unmount(VOLUME_NAME); } else { FS_X_Log("Volume could not be formatted!\n"); } while (1) { ; } }
VError VArchiveStream::Proceed() { bool userAbort = false; VError result = VE_OK; //Iterate over our various list and check for duplicates /* ACI0077162, Jul 11th 2012, O.R.: add some calls to the progress callback here in order to allow user feedback, in case of lengthy process (e.g. many files/folders to add)*/ if (fCallBack) { fCallBack(CB_OpenProgressUndetermined,0,0,userAbort); } VectorOfPaths::iterator folderIterator = fFolderPathList.begin(); VectorOfVString::iterator folderInfoIterator = fFolderExtra.begin(); xbox_assert(fFolderPathList.size() == fFolderExtra.size()); for ( uLONG i = 0; i < fFolderPathList.size() && result == VE_OK && !userAbort; i++ ) { const VFilePath& folderPath = fFolderPathList[i];//(*folderIterator); const VFilePath& sourceFolderPath = fSourceFolderForFolders[i];//(*folderIterator); const VString& folderExtraInfo = folderInfoIterator[i];//(*folderInfoIterator); VFolder currentFolder(folderPath); result = _AddOneFolder(currentFolder,sourceFolderPath,folderExtraInfo); } if ( fStream && result == VE_OK && !userAbort) { result = fStream->OpenWriting(); if ( result == VE_OK ) { sLONG8 offset; sLONG8 fileSize; sLONG8 byteCount; uLONG8 totalByteCount = 0; uLONG8 partialByteCount = 0; /* put the backup file signature */ fStream->PutLong('FPBK'); /* put the current version of the file */ fStream->PutByte(4); /* put the number of file stored in this archive */ sLONG8 storedObjCount = (sLONG8)fFileList.size(); storedObjCount += (sLONG8)fFileDescList.size(); fStream->PutLong8(storedObjCount /*(sLONG8)(fFileList.size()+fFileDescList.size())*/); /* put the header of the file listing */ fStream->PutLong('LIST'); for ( uLONG i = 0; i < fFileDescList.size() && result == VE_OK && !userAbort; i++ ) { result = _WriteCatalog(fFileDescList[i]->GetParentVFile(),fSourceFolderForFileDescs[i],fFileDescExtra[i],totalByteCount); if ( fCallBack ) { fCallBack(CB_UpdateProgress,0,0,userAbort); } } for ( uLONG i = 0; i < fFileList.size() && result == VE_OK && !userAbort; i++ ) { result = _WriteCatalog(fFileList[i],fSourceFolderForFiles[i],fFileExtra[i],totalByteCount); if ( fCallBack ) { fCallBack(CB_UpdateProgress,0,0,userAbort); } } //ACI0077162, Jul 11th 2012, O.R.: Close unbound session and open a bounded one for file processing if ( fCallBack ) { fCallBack(CB_CloseProgress,0,0,userAbort); fCallBack(CB_OpenProgress,partialByteCount,totalByteCount,userAbort); } VSize bufferSize = 1024*1024; char *buffer = new char[bufferSize]; /* writing file descriptor that we have to the archive files */ /* nota : filedesc passed to the archivestream is considered as data fork */ //ACI0077162, Jul 11th 2012, O.R.: _WriteFile() in charge of calling progress CB to give reactivity to upper layers for( VectorOfVFileDesc::iterator i = fFileDescList.begin() ; result == VE_OK && i != fFileDescList.end() && !userAbort ; ++i) { StErrorContextInstaller errors( false); result = fStream->PutLong('Fdat'); if ( result == VE_OK ) { result = (*i)->SetPos(0); if ( result == VE_OK ) result = _WriteFile( (*i), buffer, bufferSize, partialByteCount, totalByteCount ); } if ( result == VE_OK ) result = fStream->PutLong('Frez'); if ( result == VE_OK ) result = fStream->PutLong8(0); } for( VectorOfVFile::iterator i = fFileList.begin() ; result == VE_OK && i != fFileList.end() && !userAbort ; ++i ) { StErrorContextInstaller errors( false); VFileDesc *fileDesc = NULL; result = fStream->PutLong('Fdat'); if ( result == VE_OK ) { result = (*i)->Open(FA_READ,&fileDesc); if ( fileDesc ) { result = _WriteFile( fileDesc, buffer, bufferSize, partialByteCount, totalByteCount ); delete fileDesc; fileDesc = NULL; } else { result = fStream->PutLong8(0); } } if ( result == VE_OK ) result = fStream->PutLong('Frez'); if ( result == VE_OK ) { #if VERSIONMAC result = (*i)->Open(FA_READ,&fileDesc,FO_OpenResourceFork); if ( fileDesc ) { result = _WriteFile( fileDesc, buffer, bufferSize, partialByteCount, totalByteCount ); delete fileDesc; fileDesc = NULL; } else #endif { result = fStream->PutLong8(0); } } } delete[] buffer; fStream->CloseWriting(); } } //ACI0077162, Jul 11th 2012, O.R.: close remaining session (either unbounded one for check files or bounded one for processing files) if ( fCallBack ) fCallBack(CB_CloseProgress,0,0,userAbort); if (userAbort) { result = XBOX::VE_STREAM_USER_ABORTED; } return result; }
_ssize_t _write_r(struct _reent *reent, int fd, const void *buf, size_t count){ int nwritten = 0; int werr; WCETRACE(WCE_IO, "write(%d, %d, %x)", fd, count, _fdtab[fd].hnd); EnterCriticalSection(&critsect); if (WCETRACING(WCE_IO)) { if (fd == 2 || fd == 1) { char fmt[30]; snprintf(fmt, 29, "%s : %%.%ds", fd == 2?"stderr":"stdout", count); WCETRACE(WCE_IO, fmt, buf); } } /* until we can call console stuff inside the PE loader */ if ((!__StdioInited) && (fd >= 0) && (fd <= 2)) { WCETRACE(WCE_IO, "write to fd = %d with stdio uninitialized", fd); LeaveCriticalSection(&critsect); return count; } if (_fdtab[fd].devops == NULL) { if (_fdtab[fd].type == IO_FILE_TYPE_FILE || _fdtab[fd].type == IO_FILE_TYPE_CONSOLE) { if (_WriteFile(_fdtab[fd].hnd, buf, count, (DWORD *)&nwritten, NULL) == FALSE) { if ((fd == 1 || fd == 2) && (_fdtab[fd].hnd == (HANDLE)-1)) { /* ignore writting errors to stdout and stderr. happens when we don't have a console installed */ /* ### TODO replace this with something better */ nwritten = count; } else { WCETRACE(WCE_IO, "_WriteFile: hnd %x error %d\n", _fdtab[fd].hnd, GetLastError()); errno = EIO; LeaveCriticalSection(&critsect); return(-1); } } } else if (_fdtab[fd].type == IO_FILE_TYPE_SOCKET) { if ((nwritten = (int)send(fd, buf, count, 0)) == SOCKET_ERROR) { /* werr = WSAGetLastError(); */ werr = 1; WCETRACE(WCE_IO, "send: sock %d error %d", _fdtab[fd].hnd, werr); errno = _winerr2errno(werr); LeaveCriticalSection(&critsect); return(-1); } } else if (_fdtab[fd].type == IO_FILE_TYPE_NULL) { // pretty normal, no? // WCETRACE(WCE_IO, "warning - write called w/IO_FILE_TYPE_NULL"); nwritten = count; } } else { nwritten = _fdtab[fd].devops->write_r(reent, _fdtab[fd].fd, buf, count, _fdtab[fd].cxt); } LeaveCriticalSection(&critsect); return nwritten; }