From b3a48455db2a13a740f4c4241c9a9c09c681c7bd Mon Sep 17 00:00:00 2001 From: Lars Persson Date: Sun, 7 Sep 2008 13:40:30 +0000 Subject: Updated readme about usage of snprintf source Added vsnprintf implementation. Cleanout SymbianOS.cpp from old file functions. svn-id: r34407 --- backends/platform/symbian/src/SymbianOS.cpp | 258 ++++------------------------ 1 file changed, 38 insertions(+), 220 deletions(-) (limited to 'backends/platform/symbian/src/SymbianOS.cpp') diff --git a/backends/platform/symbian/src/SymbianOS.cpp b/backends/platform/symbian/src/SymbianOS.cpp index 5a5c681e2e..4fb5087b4b 100644 --- a/backends/platform/symbian/src/SymbianOS.cpp +++ b/backends/platform/symbian/src/SymbianOS.cpp @@ -24,6 +24,7 @@ #include // for CEikonEnv::Static() @ Symbian::FatalError() #include // for CSDLApp::GetExecutablePathCStr() @ Symbian::GetExecutablePath() +#include #include "backends/fs/symbian/symbian-fs-factory.h" #include "backends/platform/symbian/src/SymbianOS.h" @@ -45,16 +46,7 @@ #define DEFAULT_CONFIG_FILE "scummvm.ini" - - -#define KInputBufferLength 128 -// Symbian libc file functionality in order to provide shared file handles -struct TSymbianFileEntry { - RFile iFileHandle; - char iInputBuffer[KInputBufferLength]; - TInt iInputBufferLen; - TInt iInputPos; -}; +#define DEFAULT_SAVE_PATH "Savegames" #define FILE void @@ -151,7 +143,28 @@ OSystem_SDL_Symbian::OSystem_SDL_Symbian() :_channels(0),_stereo_mix_buffer(0) { } void OSystem_SDL_Symbian::initBackend() { + // First set the extrapath (for installed dat files etc) ConfMan.set("extrapath", Symbian::GetExecutablePath()); + + // Calculate the default savepath + Common::String savePath; + savePath = Symbian::GetExecutablePath(); + savePath += DEFAULT_SAVE_PATH "\\"; + ConfMan.registerDefault("savepath", savePath); + + // If savepath has not already been set then set it + if (!ConfMan.hasKey("savepath")) { + ConfMan.set("savepath", savePath); + + } + + // Ensure that the current set path (might have been altered by the user) exists + Common::String currentPath = ConfMan.get("savepath"); + TFileName fname; + TPtrC8 ptr((const unsigned char*)currentPath.c_str(),currentPath.size()); + fname.Copy(ptr); + BaflUtils::EnsurePathExistsL(static_cast(g_system)->FsSession(), fname); + ConfMan.setBool("FM_high_quality", false); #if !defined(S60) || defined(S60V3) // S60 has low quality as default ConfMan.setBool("FM_medium_quality", true); @@ -499,231 +512,36 @@ void* scumm_bsearch(const void *key, const void *base, size_t nmemb, size_t size return NULL; } -FILE* symbian_fopen(const char* name, const char* mode) { - TSymbianFileEntry* fileEntry = new TSymbianFileEntry; - fileEntry->iInputPos = KErrNotFound; - - if (fileEntry != NULL) { - TInt modeLen = strlen(mode); - - TPtrC8 namePtr((unsigned char*) name, strlen(name)); - TFileName tempFileName; - tempFileName.Copy(namePtr); - - TInt fileMode = EFileRead; - - if (mode[0] == 'a') - fileMode = EFileWrite; - - if (!((modeLen > 1 && mode[1] == 'b') || (modeLen > 2 && mode[2] == 'b'))) { - fileMode |= EFileStreamText; - } - - if ((modeLen > 1 && mode[1] == '+') || (modeLen > 2 && mode[2] == '+')) { - fileMode = fileMode| EFileWrite; - } - - fileMode = fileMode| EFileShareAny; - - switch(mode[0]) { - case 'a': - if (fileEntry->iFileHandle.Open(static_cast(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) { - if (fileEntry->iFileHandle.Create(static_cast(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) { - delete fileEntry; - fileEntry = NULL; - } - } - break; - case 'r': - if (fileEntry->iFileHandle.Open(static_cast(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) { - delete fileEntry; - fileEntry = NULL; - } - break; - - case 'w': - if (fileEntry->iFileHandle.Replace(static_cast(g_system)->FsSession(), tempFileName, fileMode) != KErrNone) { - delete fileEntry; - fileEntry = NULL; - } - break; - } - } - return (FILE*) fileEntry; -} - -void symbian_fclose(FILE* handle) { - ((TSymbianFileEntry*)(handle))->iFileHandle.Close(); - - delete (TSymbianFileEntry*)(handle); -} - -size_t symbian_fread(const void* ptr, size_t size, size_t numItems, FILE* handle) { - TSymbianFileEntry* entry = ((TSymbianFileEntry*)(handle)); - TUint32 totsize = size*numItems; - TPtr8 pointer ( (unsigned char*) ptr, totsize); - - // Nothing cached and we want to load at least KInputBufferLength bytes - if(totsize >= KInputBufferLength) { - TUint32 totLength = 0; - if(entry->iInputPos != KErrNotFound) - { - TPtr8 cacheBuffer( (unsigned char*) entry->iInputBuffer+entry->iInputPos, entry->iInputBufferLen - entry->iInputPos, KInputBufferLength); - pointer.Append(cacheBuffer); - entry->iInputPos = KErrNotFound; - totLength+=pointer.Length(); - pointer.Set(totLength+(unsigned char*) ptr, 0, totsize-totLength); - } - - entry->iFileHandle.Read(pointer); - totLength+=pointer.Length(); - - pointer.Set((unsigned char*) ptr, totLength, totsize); - - } - else { - // Nothing in buffer - if(entry->iInputPos == KErrNotFound) { - TPtr8 cacheBuffer( (unsigned char*) entry->iInputBuffer, KInputBufferLength); - entry->iFileHandle.Read(cacheBuffer); - - if(cacheBuffer.Length() >= totsize) { - pointer.Copy(cacheBuffer.Left(totsize)); - entry->iInputPos = totsize; - entry->iInputBufferLen = cacheBuffer.Length(); - } - else { - pointer.Copy(cacheBuffer); - entry->iInputPos = KErrNotFound; - } - - } - else { - TPtr8 cacheBuffer( (unsigned char*) entry->iInputBuffer, entry->iInputBufferLen, KInputBufferLength); - - if(entry->iInputPos+totsize < entry->iInputBufferLen) { - pointer.Copy(cacheBuffer.Mid(entry->iInputPos, totsize)); - entry->iInputPos+=totsize; - } - else { - - pointer.Copy(cacheBuffer.Mid(entry->iInputPos, entry->iInputBufferLen-entry->iInputPos)); - cacheBuffer.SetLength(0); - entry->iFileHandle.Read(cacheBuffer); - - if(cacheBuffer.Length() >= totsize-pointer.Length()) { - TUint32 restSize = totsize-pointer.Length(); - pointer.Append(cacheBuffer.Left(restSize)); - entry->iInputPos = restSize; - entry->iInputBufferLen = cacheBuffer.Length(); - } - else { - pointer.Append(cacheBuffer); - entry->iInputPos = KErrNotFound; - } - } - } - } - - return pointer.Length()/size; -} - -size_t symbian_fwrite(const void* ptr, size_t size, size_t numItems, FILE* handle) { - TPtrC8 pointer( (unsigned char*) ptr, size*numItems); - - ((TSymbianFileEntry*)(handle))->iInputPos = KErrNotFound; - if (((TSymbianFileEntry*)(handle))->iFileHandle.Write(pointer) == KErrNone) { - return numItems; - } - - return 0; -} - -bool symbian_feof(FILE* handle) { - TInt pos = 0; - TSymbianFileEntry* entry = ((TSymbianFileEntry*)(handle)); - - if (entry->iFileHandle.Seek(ESeekCurrent, pos) == KErrNone) { - - TInt size = 0; - if (entry->iFileHandle.Size(size) == KErrNone) { - if(entry->iInputPos == KErrNotFound && pos == size) - return true; - - if(entry->iInputPos != KErrNotFound && pos == size && entry->iInputPos == entry->iInputBufferLen) - return true; - - return false; - } - } - return true; -} - -long int symbian_ftell(FILE* handle) { - TInt pos = 0; - TSymbianFileEntry* entry = ((TSymbianFileEntry*)(handle)); - - entry->iFileHandle.Seek(ESeekCurrent, pos); - if(entry->iInputPos != KErrNotFound) - { - pos+=(entry->iInputPos - entry->iInputBufferLen); - } - return pos; -} - -int symbian_fseek(FILE* handle, long int offset, int whence) { - - TSeek seekMode = ESeekStart; - TInt pos = offset; - TSymbianFileEntry* entry = ((TSymbianFileEntry*)(handle)); - - switch(whence) { - case SEEK_SET: - seekMode = ESeekStart; - break; - case SEEK_CUR: - seekMode = ESeekCurrent; - if(entry->iInputPos != KErrNotFound) { - pos+=(entry->iInputPos - entry->iInputBufferLen); - } - break; - case SEEK_END: - seekMode = ESeekEnd; - break; - - } - - entry->iInputPos = KErrNotFound; - - return entry->iFileHandle.Seek(seekMode, pos); -} - -void symbian_clearerr(FILE* /*handle*/) { -} - -void symbian_fflush(FILE* handle) { - ((TSymbianFileEntry*)(handle))->iFileHandle.Flush(); -} - -int symbian_ferror(FILE* /*handle*/) { - return 0; +extern "C" +{ +// Include the snprintf and vsnprintf implementations as 'C' code +#include "vsnprintf.h" } /** Vibration support */ #ifdef USE_VIBRA_SE_PXXX void OSystem_SDL_Symbian::initializeVibration() { - _vibrationApi = SonyEricsson::CVibration::NewL(); +#ifdef UIQ3 +#else +#endif } void OSystem_SDL_Symbian::vibrationOn(int vibraLength) { - // initialize? +#ifdef UIQ3 + // initialize? if (!_vibrationApi) _vibrationApi = SonyEricsson::CVibration::NewL(); // do it! _vibrationApi->VibrationOn(1, 1, vibraLength); +#else + +#endif } void OSystem_SDL_Symbian::vibrationOff() { +#ifdef UIQ3 +#else _vibrationApi->VibrationOff(); +#endif } #endif // USE_SE_PXX_VIBRA -- cgit v1.2.3