diff -r e5618cc85d74 -r 6c158198356e javacommons/utils/src/javacommonutils.cpp --- a/javacommons/utils/src/javacommonutils.cpp Thu Jul 15 18:31:06 2010 +0300 +++ b/javacommons/utils/src/javacommonutils.cpp Thu Aug 19 09:48:13 2010 +0300 @@ -15,9 +15,11 @@ * */ - +#include +#include #include #include +#include #include #include @@ -33,6 +35,16 @@ using namespace java::util; +// In Symbian working directory should be initalized to C:\private\ by OpenC +// But for some reason this does not seem to work if process binary is in rom. +#ifdef __SYMBIAN32__ +const char* const FIRST_BOOT_FILE = "c:\\private\\102033E6\\first_boot_done.dat"; +#else +const char* const FIRST_BOOT_FILE = "first_boot_done.dat"; +#endif /* __SYMBIAN32__ */ + +bool JavaCommonUtils::mFirstBoot = false; + OS_EXPORT int JavaCommonUtils::stringToInt(const std::string& str) { // JELOG2(EUtils); @@ -277,6 +289,34 @@ return result; } +OS_EXPORT std::wstring JavaCommonUtils::wbase64encode(const std::wstring& aData) +{ + BIO* b64 = BIO_new(BIO_f_base64()); + if (NULL == b64) + { + return L""; + } + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); + BIO* bmem = BIO_new(BIO_s_mem()); + + b64 = BIO_push(b64, bmem); + BIO_write(b64, aData.c_str(), aData.length() * 2); + BIO_flush(b64); + + BUF_MEM* bptr; + BIO_get_mem_ptr(b64, &bptr); + + std::wstring result; + // convert each char to wchar + for (int i = 0; i < bptr->length; i++) + { + result.push_back((wchar_t)*(bptr->data + i)); + } + BIO_free_all(b64); + + return result; +} + OS_EXPORT std::string JavaCommonUtils::base64decode(const std::string& aData) { BIO* b64 = BIO_new(BIO_f_base64()); @@ -344,6 +384,40 @@ } +OS_EXPORT int JavaCommonUtils::initIsFirstBoot() +{ + struct stat fileStatBuf; + if (stat(FIRST_BOOT_FILE, &fileStatBuf) == 0) + { + mFirstBoot = false; + } + else + { + mFirstBoot = true; + + // Create flag file so that next time we detect that first boot + // has already been done + int fd = open(FIRST_BOOT_FILE, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (fd < 0) + { + return errno; + } + else + { + close(fd); + } + } + + return 0; +} + + +OS_EXPORT bool JavaCommonUtils::isFirstBoot() +{ + return mFirstBoot; +} + + char JavaCommonUtils::decodeOnePercentSeq(wchar_t first, wchar_t sec) { // Handle one encoded %XY