INT32 GetNumberOfHistoryPages() { HWFILE hFileHandle; UINT32 uiFileSize=0; UINT32 uiSizeOfRecordsOnEachPage = 0; INT32 iNumberOfHistoryPages = 0; if ( ! (FileExists( HISTORY_DATA_FILE ) ) ) return( 0 ); // open file hFileHandle=FileOpen( HISTORY_DATA_FILE,( FILE_OPEN_EXISTING | FILE_ACCESS_READ ), FALSE ); // failed to get file, return if(!hFileHandle) { return( 0 ); } // make sure file is more than 0 length if ( FileGetSize( hFileHandle ) == 0 ) { FileClose( hFileHandle ); return( 0 ); } uiFileSize = FileGetSize( hFileHandle ) - 1; uiSizeOfRecordsOnEachPage = ( NUM_RECORDS_PER_PAGE * ( sizeof( UINT8 ) + sizeof( UINT32 ) + 3*sizeof( UINT8 )+ sizeof(INT16) + sizeof( INT16 ) ) ); iNumberOfHistoryPages = (INT32)( uiFileSize / uiSizeOfRecordsOnEachPage ); FileClose( hFileHandle ); return( iNumberOfHistoryPages ); }
BOOLEAN ReadInFoodOpinionStats(STR fileName) { HWFILE hFile; UINT32 uiBytesRead; UINT32 uiFSize; CHAR8 * lpcBuffer; XML_Parser parser = XML_ParserCreate(NULL); foodopinionParseData pData; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading FoodOpinion.xml" ); // Open file hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); // if the file does not exist, exit // Flugente: no need to quit the game if the xml does not exist - this data just won't be there, but the game will still work if ( !hFile ) return( TRUE ); uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); //Read in block if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); XML_SetElementHandler(parser, foodopinionStartElementHandle, foodopinionEndElementHandle); XML_SetCharacterDataHandler(parser, foodopinionCharacterDataHandle); memset(&pData,0,sizeof(pData)); pData.curArray = FoodOpinions; pData.maxArraySize = NUM_PROFILES; XML_SetUserData(parser, &pData); if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; sprintf(errorBuf, "XML Parser Error in FoodOpinion.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); LiveMessage(errorBuf); MemFree(lpcBuffer); return FALSE; } MemFree(lpcBuffer); XML_ParserFree(parser); return( TRUE ); }
long FileNameGetSize(char *name) { FILE *f = fopen(name, "r"); long size = FileGetSize(f); fclose(f); return size; }
bool OverwriteDlg::_SetStaticText(Window &Wnd, CTSTRING &tsFileName) { bool r = false; FILESIZE fs; if (FileGetSize(tsFileName, fs)) { FILETIMES ft; if (FileGetTime(tsFileName, ft)) { /* * Set the text of the static control as follows: * * [size in bytes] [formatted size] * [created date] * [modified date] */ TSTRING tsTemp; TSTRING tsFormatBytes = _GetNumberFormat(fs.ui64Bytes); sprintf(tsTemp, _T("%s Bytes (%s)\nCreated: %s\nModified: %s"), tsFormatBytes.c_str(), fs.tsStrFmt.c_str(), ft.tsLongCreated.c_str(), ft.tsLongModified.c_str()); Wnd.SetWindowText(tsTemp); r = true; } } return r; }
int tga_t::Load(const char *name) { FILE *iFile = 0; byte *buffer = 0; uint fSize; if (!(iFile = fopen(name, "rb"))) return notFound; fSize = FileGetSize(iFile); if (!(buffer = new byte[fSize + 1])) { fclose(iFile); return badData; } fread(buffer, 1, fSize, iFile); fclose(iFile); int ret = ParseBuffer(buffer); delete [] buffer; return ret; }
void LoadSettings(){ char settings[]="000100"; char str[100]; File MyFile; if (FileOpen(&MyFile, "/rxTools/data/system.txt", 0)) { if (FileGetSize(&MyFile) == 6) { FileRead(&MyFile, settings, 6, 0); bootGUI = (settings[0] == '1'); agb_bios = (settings[2] == '1'); theme_3d = (settings[3] == '1'); silent_boot = (settings[4] == '1'); /* Disable autostart after the first boot */ if (first_boot && !bootGUI) bootGUI = true; /* Check if the Theme Number is valid */ unsigned char theme_num = (settings[0] - 0x30); if (theme_num >= 0 && theme_num <= 9) { File Menu0; sprintf(str, "/rxTools/Theme/%c/menu0.bin", settings[1]); if (FileOpen(&Menu0, str, 0)) { Theme = settings[1]; //check if the theme exists, else load theme 0 (default) FileClose(&Menu0); } else Theme = '0'; } else { Theme = '0'; FileWrite(&MyFile, &Theme, 1, 1); } /* Check if the Language Number is valid */ if(settings[5] - 0x30 >= 0 && settings[5] - 0x30 <= N_LANG) language = settings[5] - 0x30; else language = 0; FileClose(&MyFile); return; } else { FileClose(&MyFile); } } /* Disable autostart after the first boot */ bootGUI = first_boot; Theme = '0'; agb_bios = false; /* Create system.txt */ if (FileOpen(&MyFile, "/rxTools/data/system.txt", 1)) { FileWrite(&MyFile, settings, 6, 0); FileClose(&MyFile); } }
/* static bool checkFileHash(wchar_t *path, uint8_t *checkhash) { FIL fil; uint8_t *buf; uint8_t hash[32]; size_t size; mbedtls_sha256_context ctx; if (!FileOpen(&fil, path, false) || ((FileGetSize(&fil)) == 0 && (FileClose(&fil) || true))) return false; buf = __builtin_alloca(BUF_SIZE); mbedtls_sha256_init(&ctx); mbedtls_sha256_starts(&ctx, 0); while ((size = FileRead2(&fil, buf, BUF_SIZE))) mbedtls_sha256_update(&ctx, buf, size); FileClose(&fil); mbedtls_sha256_finish(&ctx, hash); return !memcmp(hash, checkhash, sizeof(hash)); } */ uint_fast8_t tmdValidateChunk(tmd_data *data, wchar_t *path, uint_fast16_t content_index, uint_fast8_t drive) { //validates loaded tmd content chunk records FIL fil; size_t size; wchar_t apppath[_MAX_LFN + 1]; uint8_t hash[SHA_256_SIZE]; uint8_t *buf = __builtin_alloca(BUF_SIZE); uint_fast16_t content_count; content_count = __builtin_bswap16(data->header.content_count); if (!data->content_chunk && (data->content_chunk = __builtin_alloca(content_count * sizeof(tmd_content_chunk))) && !tmdPreloadChunk(data, path, content_index) ) return 0; for (uint_fast16_t info_index = 0, chunk_index = 0; chunk_index < content_count; info_index++) { for (uint_fast16_t chunk_count = __builtin_bswap16(data->content_info[info_index].content_command_count); chunk_count > 0; chunk_index++, chunk_count--) { if (content_index == CONTENT_INDEX_ALL || content_index == data->content_chunk[chunk_index].content_index) { sha_start(SHA_256_MODE, NULL); swprintf(apppath, _MAX_LFN + 1, L"%.*ls/%08lx%s", wcsrchr(path, L'/') - path, path, __builtin_bswap32(data->content_chunk[chunk_index].content_id), APP_EXT); size = __builtin_bswap32(data->content_chunk[chunk_index].content_size_lo); if (FileOpen(&fil, apppath, 0) && (FileGetSize(&fil) == size || (FileClose(&fil) && 0))) { while ((size = FileRead2(&fil, buf, BUF_SIZE))) sha_update(buf, size); } else if (!(apppath[wcslen(apppath) - strlen(APP_EXT)] = 0) && FileOpen(&fil, apppath, 0) && (FileGetSize(&fil) == size || (FileClose(&fil) && 0)) ) { aes_key Key = {&(aes_key_data){{0}}, AES_CNT_INPUT_BE_NORMAL, 0x2C, NORMALKEY}; getTitleKey2(&Key, data->header.title_id, drive); aes_ctr ctr = {{{0}}, AES_CNT_INPUT_BE_NORMAL}; aes_set_key(&Key); while ((size = FileRead2(&fil, buf, BUF_SIZE))) { aes(buf, buf, size, &ctr, AES_CBC_DECRYPT_MODE | AES_CNT_INPUT_BE_NORMAL | AES_CNT_OUTPUT_BE_NORMAL); sha_update(buf, size); } } else return 0; FileClose(&fil); sha_finish(hash); if (memcmp(hash, data->content_chunk[chunk_index].content_hash, sizeof(hash))) return 0; } } } return 1; }
BOOLEAN ReadInPatrolInfo(STR fileName) { HWFILE hFile; UINT32 uiBytesRead; UINT32 uiFSize; CHAR8 * lpcBuffer; XML_Parser parser = XML_ParserCreate(NULL); patrolParseData pData; // Open weapons file hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); if ( !hFile ) return( FALSE ); uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); //Read in block if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); XML_SetElementHandler(parser, patrolStartElementHandle, patrolEndElementHandle); XML_SetCharacterDataHandler(parser, patrolCharacterDataHandle); memset(&pData,0,sizeof(pData)); XML_SetUserData(parser, &pData); iOrigPatrolArraySize = 0; if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; sprintf(errorBuf, "XML Parser Error in PatrolGroups.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); LiveMessage(errorBuf); MemFree(lpcBuffer); return FALSE; } MemFree(lpcBuffer); XML_ParserFree(parser); return TRUE; }
u32 ScrollOutput() { u32 log_start = LogWrite(NULL); // careful, these areas are used by other functions in Decrypt9 char** logptr = (char**) 0x20316000; char* logtext = (char*) 0x20400000; u32 log_size = 0; // log size u32 l_total = 0; // total lines u32 l_curr = 0; // current line if (!FileOpen(LOG_FILE)) return 0; log_size = FileGetSize(); if ((log_size <= log_start) || (log_size - log_start >= 1024 * 1024)) { FileClose(); return 0; // allow 1MB of text max } log_size -= log_start; if (!FileRead(logtext, log_size, log_start)) { FileClose(); return 0; } FileClose(); // read lines logtext[log_size - 1] = '\0'; logptr[l_total++] = logtext; for (char* line = strchr(logtext, '\n'); line != NULL && l_total < 4000; line = strchr(line, '\n')) { *line = '\0'; logptr[l_total++] = ++line; } if (l_total >= 4000) // allow 4000 lines of text max return 0; for (; l_total < DBG_N_CHARS_Y; logptr[l_total++] = logtext + log_size - 1); // here, the actual output starts l_curr = l_total - DBG_N_CHARS_Y ; if (l_curr > 0) l_curr--; // start at the line before the last while (true) { DebugSet((const char**) logptr + l_curr); u32 pad_state = InputWait(); if (pad_state & BUTTON_X) { Screenshot(NULL); } else if ((pad_state & BUTTON_UP) && (l_curr > 0)) { l_curr--; } else if ((pad_state & BUTTON_DOWN) && (l_curr < l_total - DBG_N_CHARS_Y)) { l_curr++; } else if (pad_state & (BUTTON_B | BUTTON_START)) { return pad_state; } } return 0; }
int loadStrings() { const size_t tokenNum = 1 + STR_NUM * 2; jsmntok_t t[tokenNum]; char buf[8192]; jsmn_parser p; unsigned int i, j, k; const char *s; int l, r, len; File fd; sprintf(buf, "%s/%s", langPath, cfgs[CFG_LANG].val.s); if (!FileOpen(&fd, buf, 0)) return 1; len = FileGetSize(&fd); if (len > sizeof(buf)) return 1; FileRead(&fd, buf, len, 0); FileClose(&fd); jsmn_init(&p); r = jsmn_parse(&p, buf, len, t, tokenNum); if (r < 0) return r; for (i = 1; i < r; i++) { for (j = 0; j < STR_NUM; j++) { s = buf + t[i].start; len = t[i].end - t[i].start; if (!memcmp(s, keys[j], len) && !keys[j][len]) { i++; len = t[i].end - t[i].start; s = buf + t[i].start; for (k = 0; k + 1 < STR_MAX_LEN && len > 0; k++) { l = mbtowc(strings[j] + k, s, len); if (l < 0) break; len -= l; s += l; } strings[j][k] = 0; mbtowc(NULL, NULL, 0); break; } } } return 0; }
BOOLEAN ReadInCreaturePlacements(STR fileName) { HWFILE hFile; UINT32 uiBytesRead; UINT32 uiFSize; CHAR8 * lpcBuffer; XML_Parser parser = XML_ParserCreate(NULL); CreatureParseData pData; hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); if ( !hFile ) return( FALSE ); uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); //Read in block if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); XML_SetElementHandler(parser, creatureplacementStartElementHandle, creatureplacementEndElementHandle); XML_SetCharacterDataHandler(parser, creatureplacementCharacterDataHandle); memset(&pData,0,sizeof(pData)); NUMBER_OF_INFECTIBLE_SITES = 0; NUMBER_OF_CREATURE_COMPOSITIONS = 0; XML_SetUserData(parser, &pData); if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; sprintf(errorBuf, "XML Parser Error in CreaturePlacements.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); LiveMessage(errorBuf); MemFree(lpcBuffer); return FALSE; } MemFree(lpcBuffer); XML_ParserFree(parser); return TRUE; }
UINT32 ReadInLastElementOfHistoryListAndReturnIdNumber( void ) { // this function will read in the last unit in the history list, to grab it's id number HWFILE hFileHandle; INT32 iBytesRead=0; INT32 iFileSize = 0; // no file, return if ( ! (FileExists( HISTORY_DATA_FILE ) ) ) return 0; // open file hFileHandle=FileOpen( HISTORY_DATA_FILE,( FILE_OPEN_EXISTING | FILE_ACCESS_READ ), FALSE ); // failed to get file, return if(!hFileHandle) { return 0; } // make sure file is more than balance size + length of 1 record - 1 byte if ( FileGetSize( hFileHandle ) < SIZE_OF_HISTORY_FILE_RECORD ) { FileClose( hFileHandle ); return 0; } // size is? iFileSize = FileGetSize( hFileHandle ); // done with file, close it FileClose( hFileHandle ); // file size / sizeof record in bytes is id return ( ( iFileSize ) / ( SIZE_OF_HISTORY_FILE_RECORD ) ); }
int FileCopy(char* dest, char* source) { File out; File in; if (!FileOpen(&in, source, 0)) return -1; if (!FileOpen(&out, dest, 1)) return -1; unsigned int size = FileGetSize(&in); if (size == 0) { FileClose(&in); FileClose(&out); return -1; } int pos = 0, res = 1; unsigned int i, chunk_size = 0x4000; unsigned char* buf = 0x26000200; for (i = 0; i < size; i += chunk_size) { if (chunk_size > (size - i)) chunk_size = (size - i); int rb = FileRead(&in, buf, chunk_size, i); if (rb != chunk_size) { /* error or eof */ res = -1; break; } int wb = FileWrite(&out, buf, chunk_size, i); if (wb != chunk_size) { /* error or disk full */ res = -2; break; } pos += wb; } FileClose(&in); FileClose(&out); return res; }
BOOLEAN ReadInSoundArray(STR fileName) { HWFILE hFile; UINT32 uiBytesRead; UINT32 uiFSize; CHAR8 * lpcBuffer; XML_Parser parser = XML_ParserCreate(NULL); soundParseData pData; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, String("Loading %s",SOUNDSFILENAME ) ); // Open sounds file hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); if ( !hFile ) return( FALSE ); uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); //Read in block if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); XML_SetElementHandler(parser, soundStartElementHandle, soundEndElementHandle); XML_SetCharacterDataHandler(parser, soundCharacterDataHandle); memset(&pData,0,sizeof(pData)); pData.maxArraySize = MAX_SAMPLES; pData.curIndex = -1; XML_SetUserData(parser, &pData); if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; sprintf(errorBuf, "XML Parser Error in %s.xml: %s at line %d", SOUNDSFILENAME, XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); LiveMessage(errorBuf); MemFree(lpcBuffer); return FALSE; } MemFree(lpcBuffer); XML_ParserFree(parser); return( TRUE ); }
byte *FileReadAll(FILE *in, long &size) { byte *b = 0; size = FileGetSize(in); if (!size) return 0; b = new byte[size + 1]; memset(b, '\0', size + 1); if (!b) return 0; fread(b, 1, size, in); // check return with size? return b; }
T_void *FileLoad(T_byte8 *p_filename, T_word32 *p_size) { T_byte8 *p_data ; T_file file ; DebugRoutine("FileLoad") ; DebugCheck(p_filename != NULL) ; DebugCheck(p_size != NULL) ; /* See how big the file is so we know how much memory to allocate. */ *p_size = FileGetSize(p_filename) ; #ifdef COMPILE_OPTION_FILE_OUTPUT printf("!A 1 file_%s\n", p_filename) ; printf("!A 1 file_r_%s\n", DebugGetCallerName()) ; #endif if (*p_size) { /* Allocate the memory for the file. */ p_data = MemAlloc(*p_size) ; DebugCheck(p_data != NULL) ; /* Make sure we got the memory. */ if (p_data != NULL) { /* If memory was allocated, read in the file into this memory. */ file = FileOpen(p_filename, FILE_MODE_READ) ; FileRead(file, p_data, *p_size) ; FileClose(file) ; } else { /* If memory was not allocated, return with a zero length. */ *p_size = 0 ; } } else { *p_size = 0 ; p_data = NULL ; } DebugEnd() ; /* Return the pointer to the data. */ return p_data ; }
void trySetLangFromTheme(){ File MyFile; char str[100]; unsigned int i; sprintf(str, "/rxTools/Theme/%u/LANG.txt", cfgs[CFG_THEME].val.i); if (!FileOpen(&MyFile, str, 0)) return; if (FileGetSize(&MyFile) > 0) { FileRead(&MyFile, cfgs[CFG_LANG].val.s, CFG_STR_MAX_LEN, 0); for (i = 0; i + 1 < CFG_STR_MAX_LEN && cfgs[CFG_LANG].val.s[i] != '\r' && cfgs[CFG_LANG].val.s[i] != '\n'; i++); str[i] = 0; loadStrings(); } FileClose(&MyFile); }
void PhoneGapFile::actionWrite(JSONMessage& message) { String callbackID = message.getParam("PhoneGapCallBackId"); String fullPath = message.getArgsField("fileName"); String data = message.getArgsField("data"); int position = message.getArgsFieldInt("position"); int result = FileWrite(fullPath, data, position); if (result < 0) { callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR); return; } // Send back the new file size. char sizeBuf[32]; sprintf(sizeBuf, "%i", FileGetSize(fullPath)); callSuccess( callbackID, sizeBuf); }
/** * Return a File object. */ void PhoneGapFile::actionGetFileMetadata(JSONMessage& message) { String callbackID = message.getParam("PhoneGapCallBackId"); String fullPath = message.getArgsField("fullPath"); char sizeBuf[64]; sprintf(sizeBuf, "%i", FileGetSize(fullPath)); String file = emitFile( FileGetName(fullPath), fullPath, FileGetMimeType(fullPath), FileGetDate(fullPath), sizeBuf); // Note that _castDate also casts a File object. callSuccess( callbackID, file, "window.localFileSystem._castDate"); }
void SetLastPageInHistoryRecords( void ) { // grabs the size of the file and interprets number of pages it will take up HWFILE hFileHandle; INT32 iBytesRead=0; // no file, return if ( ! (FileExists( HISTORY_DATA_FILE ) ) ) return; // open file hFileHandle=FileOpen( HISTORY_DATA_FILE,( FILE_OPEN_EXISTING | FILE_ACCESS_READ ), FALSE ); // failed to get file, return if(!hFileHandle) { guiLastPageInHistoryRecordsList = 1; return; } // make sure file is more than 0 length if ( FileGetSize( hFileHandle ) == 0 ) { FileClose( hFileHandle ); guiLastPageInHistoryRecordsList = 1; return; } // done with file, close it FileClose( hFileHandle ); guiLastPageInHistoryRecordsList = ReadInLastElementOfHistoryListAndReturnIdNumber( ) / NUM_RECORDS_PER_PAGE; return; }
/** * Event handler for capture events * @param event the event struct. */ void PhoneGapCapture::customEvent(const MAEvent &event) { char pathBuffer[1024]; char messageBuffer[1024]; if (event.type == EVENT_TYPE_CAPTURE) { MACaptureEventData eventData = event.captureData; switch (eventData.type) { case MA_CAPTURE_EVENT_TYPE_VIDEO: // Videos are already stored, we need the filepath maCaptureGetVideoPath( eventData.handle, pathBuffer, sizeof(pathBuffer)); sprintf( messageBuffer, "[{\"fullPath\":\"%s\",\"name\":\"%s\"}]", pathBuffer, FileNameFromPath(pathBuffer)); mMessageHandler->callSuccess( mCaptureCallBack, PHONEGAP_CALLBACK_STATUS_OK, messageBuffer, false); maCaptureDestroyData(eventData.handle); break; case MA_CAPTURE_EVENT_TYPE_IMAGE: { char deviceOS[64]; String extension; maGetSystemProperty( "mosync.device.OS", deviceOS, sizeof(deviceOS)); // File format is different on different platforms. // TODO: What about WP? if (strcmp(deviceOS, "iPhone OS") == 0) { extension = "png"; } else if(strcmp(deviceOS, "Android") == 0) { extension = "jpg"; } else { // TODO: What to use as default? extension = "image"; } // Images need to be stored. We use maLocalTime to // get a unique number for the filename. String localPath = (mMessageHandler->getFileUtil())->getAppPath(); sprintf( pathBuffer, "%simg%d.%s", localPath.c_str(), maLocalTime(), extension.c_str()); int result = maCaptureWriteImage( eventData.handle, pathBuffer, sizeof(pathBuffer)); // TODO: What should we do if FileGetSize fails? // Return an error? // Set size to zero for now. int size = FileGetSize(pathBuffer); if (size < 0) { size = 0; } char sizeBuf[64]; sprintf(sizeBuf, "%i", size); sprintf( messageBuffer, "[{\"fullPath\":\"%s\",\"name\":\"%s\",\"lastModifiedDate\":\"%s\",\"size\":\"%s\",\"type\":\"%s\"}]", pathBuffer, FileNameFromPath(pathBuffer), FileGetDate(pathBuffer).c_str(), sizeBuf, FileGetMimeType(pathBuffer).c_str()); if (result == MA_CAPTURE_RES_OK) { mMessageHandler->callSuccess( mCaptureCallBack, PHONEGAP_CALLBACK_STATUS_OK, messageBuffer, false); } else { mMessageHandler->callError( mCaptureCallBack, PHONEGAP_CALLBACK_STATUS_ERROR, "{\"code\":\"CAPTURE_INTERNAL_ERR\"}", false); } // Free capture data. maCaptureDestroyData(eventData.handle); break; } case MA_CAPTURE_EVENT_TYPE_CANCEL: mMessageHandler->callError( mCaptureCallBack, PHONEGAP_CALLBACK_STATUS_ERROR, "{\"code\":\"CAPTURE_NO_MEDIA_FILES\"}", false); break; } // switch } }
void OpenAndReadHistoryFile( void ) { // this procedure will open and read in data to the History list HWFILE hFileHandle; UINT8 ubCode, ubSecondCode; UINT32 uiDate; INT16 sSectorX, sSectorY; INT8 bSectorZ = 0; UINT8 ubColor; INT32 iBytesRead=0; UINT32 uiByteCount=0; // clear out the old list ClearHistoryList( ); // no file, return if ( ! (FileExists( HISTORY_DATA_FILE ) ) ) return; // open file hFileHandle=FileOpen( HISTORY_DATA_FILE,( FILE_OPEN_EXISTING | FILE_ACCESS_READ ), FALSE ); // failed to get file, return if(!hFileHandle) { return; } // make sure file is more than 0 length if ( FileGetSize( hFileHandle ) == 0 ) { FileClose( hFileHandle ); return; } // file exists, read in data, continue until file end while( FileGetSize( hFileHandle ) > uiByteCount) { // read in other data FileRead( hFileHandle, &ubCode, sizeof(UINT8), &iBytesRead ); FileRead( hFileHandle, &ubSecondCode, sizeof(UINT8), &iBytesRead ); FileRead( hFileHandle, &uiDate, sizeof(UINT32), &iBytesRead ); FileRead( hFileHandle, &sSectorX, sizeof(INT16), &iBytesRead ); FileRead( hFileHandle, &sSectorY, sizeof(INT16), &iBytesRead ); FileRead( hFileHandle, &bSectorZ, sizeof(INT8), &iBytesRead ); FileRead( hFileHandle, &ubColor, sizeof( UINT8 ), &iBytesRead ); #ifdef JA2TESTVERSION //perform a check on the data to see if it is pooched PerformCheckOnHistoryRecord( 1, sSectorX, sSectorY, bSectorZ ); #endif // add transaction ProcessAndEnterAHistoryRecord( ubCode, uiDate, ubSecondCode, sSectorX, sSectorY, bSectorZ, ubColor ); // increment byte counter uiByteCount += SIZE_OF_HISTORY_FILE_RECORD; } // close file FileClose( hFileHandle ); return; }
BOOLEAN ReadInHiddenNamesStats(HIDDEN_NAMES_VALUES *pHiddenNames, STR fileName) { HWFILE hFile; UINT32 uiBytesRead; UINT32 uiFSize; CHAR8 * lpcBuffer; XML_Parser parser = XML_ParserCreate(NULL); hiddenNamesParseData pData; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading HiddenNames.xml" ); // Open file hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); if ( !hFile ) return( FALSE ); uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); //Read in block if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); XML_SetElementHandler(parser, hiddenNamesStartElementHandle, hiddenNamesEndElementHandle); XML_SetCharacterDataHandler(parser, hiddenNamesCharacterDataHandle); memset(&pData,0,sizeof(pData)); pData.curArray = pHiddenNames; pData.maxArraySize = 500; XML_SetUserData(parser, &pData); if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; sprintf(errorBuf, "XML Parser Error in HiddenNames.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); LiveMessage(errorBuf); MemFree(lpcBuffer); return FALSE; } MemFree(lpcBuffer); XML_ParserFree(parser); return( TRUE ); }
u32 CreatePad(PadInfo *info) { u8* buffer = BUFFER_ADDRESS; u32 size_byte = (info->size_mb) ? info->size_mb * 1024*1024 : info->size_b; u32 result = 0; if (!DebugCheckFreeSpace(size_byte)) return 1; if (!FileCreate(info->filename, true)) // No DebugFileCreate() here - messages are already given return 1; CryptBufferInfo decryptInfo = {.keyslot = info->keyslot, .setKeyY = info->setKeyY, .mode = info->mode, .buffer = buffer}; memcpy(decryptInfo.ctr, info->ctr, 16); memcpy(decryptInfo.keyY, info->keyY, 16); for (u32 i = 0; i < size_byte; i += BUFFER_MAX_SIZE) { u32 curr_block_size = min(BUFFER_MAX_SIZE, size_byte - i); decryptInfo.size = curr_block_size; memset(buffer, 0x00, curr_block_size); ShowProgress(i, size_byte); CryptBuffer(&decryptInfo); if (!DebugFileWrite((void*)buffer, curr_block_size, i)) { result = 1; break; } } ShowProgress(0, 0); FileClose(); return result; } u32 SdInfoGen(SdInfo* info, const char* base_path) { char* filelist = (char*)0x20400000; // check the base path for validity if ((strncmp(base_path, "/Nintendo 3DS", 13) != 0 ) || (strncmp(base_path, "/Nintendo 3DS/Private/", 22) == 0) || (strnlen(base_path, 255) < 13 + 33 + 33)) { Debug("Invalid base path given"); return 1; } Debug("Generating SDinfo.bin in memory..."); if (!GetFileList(base_path, filelist, 0x100000, true, true, false)) { Debug("Failed retrieving the filelist"); return 1; } u32 n_entries = 0; SdInfoEntry* entries = info->entries; for (char* path = strtok(filelist, "\n"); path != NULL; path = strtok(NULL, "\n")) { u32 plen = strnlen(path, 255); // get size in MB if (!FileOpen(path)) continue; entries[n_entries].size_mb = (FileGetSize() + (1024 * 1024) - 1) / (1024 * 1024); FileClose(); // skip to relevant part of path path += 13 + 33 + 33; // length of ("/Nintendo 3DS" + "/<id0>" + "/<id1>") plen -= 13 + 33 + 33; if ((strncmp(path, "/dbs", 4) != 0) && (strncmp(path, "/extdata", 8) != 0) && (strncmp(path, "/title", 6) != 0)) continue; // get filename char* filename = entries[n_entries].filename; filename[0] = '/'; for (u32 i = 1; i < 180 && path[i] != 0; i++) filename[i] = (path[i] == '/') ? '.' : path[i]; strncpy(filename + plen, ".xorpad", (180 - 1) - plen); // get AES counter GetSdCtr(entries[n_entries].ctr, path); if (++n_entries >= MAX_ENTRIES) break; } info->n_entries = n_entries; return (n_entries > 0) ? 0 : 1; }
BOOLEAN ReadInEnemyExplosiveDropsStats(EXPLOSIVE_DROPS *pEnemyExplosiveDrops, STR fileName) { HWFILE hFile; UINT32 uiBytesRead; UINT32 uiFSize; CHAR8 * lpcBuffer; XML_Parser parser = XML_ParserCreate(NULL); explosiveDropParseData pData; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading EnemyExplosiveDrops.xml" ); // Open inventory file hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); if ( !hFile ) return( FALSE ); uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); //Read in block if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); XML_SetElementHandler(parser, explosiveDropStartElementHandle, explosiveDropEndElementHandle); XML_SetCharacterDataHandler(parser, explosiveDropCharacterDataHandle); memset(&pData,0,sizeof(pData)); pData.curArray = pEnemyExplosiveDrops; pData.maxArraySize = MAX_DROP_ITEMS; XML_SetUserData(parser, &pData); if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; sprintf(errorBuf, "XML Parser Error in EnemyExplosiveDrops.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); LiveMessage(errorBuf); MemFree(lpcBuffer); return FALSE; } MemFree(lpcBuffer); XML_ParserFree(parser); return( TRUE ); }
BOOLEAN ReadInLBEPocketPopups(STR fileName) { HWFILE hFile; UINT32 uiBytesRead; UINT32 uiFSize; CHAR8 * lpcBuffer; XML_Parser parser = XML_ParserCreate(NULL); pocketPopupParseData pData; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading pocketPopups.xml" ); hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); if ( !hFile ) return( FALSE ); uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); //Read in block if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); XML_SetElementHandler(parser, pocketPopupStartElementHandle, pocketPopupEndElementHandle); XML_SetCharacterDataHandler(parser, pocketPopupCharacterDataHandle); memset(&pData,0,sizeof(pData)); XML_SetUserData(parser, &pData); XML_SetUserData(parser, &pData); if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; sprintf(errorBuf, "XML Parser Error in Pocket.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); LiveMessage(errorBuf); MemFree(lpcBuffer); return FALSE; } /* // dummy popup popupDef* popup = new popupDef(); popup->addOption(new std::wstring(L"Option one"),NULL,NULL); popup->addOption(new std::wstring(L"Option two"),NULL,NULL); popup->addOption(new std::wstring(L"Option three"),NULL,NULL); LBEPocketPopup[5] = *popup; */ MemFree(lpcBuffer); XML_ParserFree(parser); return( TRUE ); }
int loadStrings() { const size_t tokenNum = 1 + STR_NUM * 2; jsmntok_t t[tokenNum]; char buf[8192]; wchar_t path[_MAX_LFN]; jsmn_parser p; unsigned int i, j, k; const char *s; int l, r, len; File fd; swprintf(path, _MAX_LFN, L"%ls/%s", langPath, fontIsLoaded ? cfgs[CFG_LANG].val.s : "en.json"); if (!FileOpen(&fd, path, 0)) return 1; len = FileGetSize(&fd); if (len > sizeof(buf)) return 1; FileRead(&fd, buf, len, 0); FileClose(&fd); jsmn_init(&p); r = jsmn_parse(&p, buf, len, t, tokenNum); if (r < 0) return r; for (i = 1; i < r; i++) { for (j = 0; j < STR_NUM; j++) { s = buf + t[i].start; len = t[i].end - t[i].start; if (!memcmp(s, keys[j], len) && !keys[j][len]) { i++; len = t[i].end - t[i].start; s = buf + t[i].start; for (k = 0; k + 1 < STR_MAX_LEN && len > 0; k++) { if (s[0] == '\\' && s[1] == 'n') { strings[j][k] = '\n'; l = 2; } else { l = mbtowc(strings[j] + k, s, len); if (l < 0) break; } len -= l; s += l; } strings[j][k] = 0; mbtowc(NULL, NULL, 0); break; } } } return 0; }
int readCfg() { const size_t tokenNum = 1 + CFG_NUM * 2; jsmntok_t t[tokenNum]; char buf[128]; jsmn_parser parser; File fd; unsigned int i, j, k; int r; size_t len; if (!FileOpen(&fd, jsonPath, 0)) return 1; len = FileGetSize(&fd); if (len > sizeof(buf)) return 1; FileRead(&fd, buf, len, 0); FileClose(&fd); jsmn_init(&parser); r = jsmn_parse(&parser, buf, len, t, tokenNum); if (r < 0) return r; if (r < 1) return 1; /* Loop over all keys of the root object */ for (i = 1; i < r; i++) { for (j = 0; jsoneq(buf, &t[i], cfgs[j].key) != 0; j++) if (j >= CFG_NUM) return 1; i++; switch (cfgs[j].type) { case CFG_TYPE_INT: cfgs[j].val.i = 0; for (k = t[i].start; k < t[i].end; k++) { cfgs[j].val.i *= 10; cfgs[j].val.i += buf[k] - 48; } break; case CFG_TYPE_BOOLEAN: len = t[i].end - t[i].start; cfgs[j].val.i = buf[t[i].start] == 't'; break; case CFG_TYPE_STRING: len = t[i].end - t[i].start; if (len + 1 > CFG_STR_MAX_LEN) break; #ifdef DEBUG if (cfgs[j].val.s == NULL) break; #endif memcpy(cfgs[j].val.s, buf + t[i].start, len); cfgs[j].val.s[len] = 0; } } return 0; }
BOOLEAN ReadInEmailOther(STR fileName, BOOLEAN localizedVersion) { HWFILE hFile; UINT32 uiBytesRead; UINT32 uiFSize; CHAR8 * lpcBuffer; XML_Parser parser = XML_ParserCreate(NULL); EmailOtherParseData pData; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading EmailOther.xml" ); EmailOther_TextOnly = localizedVersion; // Open file hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE ); if ( !hFile ) return( localizedVersion ); uiFSize = FileGetSize(hFile); lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1); //Read in block if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) ) { MemFree(lpcBuffer); return( FALSE ); } lpcBuffer[uiFSize] = 0; //add a null terminator FileClose( hFile ); XML_SetElementHandler(parser, EmailOtherStartElementHandle, EmailOtherEndElementHandle); XML_SetCharacterDataHandler(parser, EmailOtherCharacterDataHandle); memset(&pData,0,sizeof(pData)); XML_SetUserData(parser, &pData); if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; sprintf(errorBuf, "XML Parser Error in EmailOther.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); LiveMessage(errorBuf); MemFree(lpcBuffer); return FALSE; } MemFree(lpcBuffer); XML_ParserFree(parser); return( TRUE ); }
BOOLEAN IncrementCurrentPageHistoryDisplay( void ) { // run through list, from pCurrentHistory, to NUM_RECORDS_PER_PAGE +1 HistoryUnits HistoryUnitPtr pTempHistory=pCurrentHistory; BOOLEAN fOkToIncrementPage=FALSE; INT32 iCounter=0; HWFILE hFileHandle; UINT32 uiFileSize=0; UINT32 uiSizeOfRecordsOnEachPage = 0; if ( ! (FileExists( HISTORY_DATA_FILE ) ) ) return( FALSE ); // open file hFileHandle=FileOpen( HISTORY_DATA_FILE,( FILE_OPEN_EXISTING | FILE_ACCESS_READ ), FALSE ); // failed to get file, return if(!hFileHandle) { return( FALSE ); } // make sure file is more than 0 length if ( FileGetSize( hFileHandle ) == 0 ) { FileClose( hFileHandle ); return( FALSE ); } uiFileSize = FileGetSize( hFileHandle ) - 1; uiSizeOfRecordsOnEachPage = ( NUM_RECORDS_PER_PAGE * ( sizeof( UINT8 ) + sizeof( UINT32 ) + 3*sizeof( UINT8 )+ sizeof(INT16) + sizeof( INT16 ) ) ); // is the file long enough? // if( ( FileGetSize( hFileHandle ) - 1 ) / ( NUM_RECORDS_PER_PAGE * ( sizeof( UINT8 ) + sizeof( UINT32 ) + 3*sizeof( UINT8 )+ sizeof(INT16) + sizeof( INT16 ) ) ) + 1 < ( UINT32 )( iCurrentHistoryPage + 1 ) ) if( uiFileSize / uiSizeOfRecordsOnEachPage + 1 < ( UINT32 )( iCurrentHistoryPage + 1 ) ) { // nope FileClose( hFileHandle ); return( FALSE ); } else { iCurrentHistoryPage++; FileClose( hFileHandle ); } /* // haven't reached end of list and not yet at beginning of next page while( ( pTempHistory )&&( ! fOkToIncrementPage ) ) { // found the next page, first record thereof if(iCounter==NUM_RECORDS_PER_PAGE+1) { fOkToIncrementPage=TRUE; pCurrentHistory=pTempHistory->Next; } //next record pTempHistory=pTempHistory->Next; iCounter++; } */ // if ok to increment, increment return( TRUE ); }