javaextensions/wma/sms_cbs/pushplugin/src/serverconnectionbase.cpp
changeset 78 71ad690e91f5
parent 23 98ccebc37403
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    80 {
    80 {
    81     JELOG2(EWMA);
    81     JELOG2(EWMA);
    82     return mMessagesOnStore;
    82     return mMessagesOnStore;
    83 }
    83 }
    84 
    84 
    85 int ServerConnectionBase::createMessageStore(std::wstring aDirectoryPath)
    85 int ServerConnectionBase::createMessageStore(std::wstring aDirectoryPath, bool aDeleteStore)
    86 {
    86 {
    87     JELOG2(EWMA);
    87     JELOG2(EWMA);
    88     aDirectoryPath += JavaCommonUtils::intToWstring(mPort);
    88     aDirectoryPath += JavaCommonUtils::intToWstring(mPort);
    89     aDirectoryPath +=L"\\" ;
    89     // If not push connection delete the message store.
    90     mMessageStoreDirName = aDirectoryPath;
    90     if (aDeleteStore)
       
    91        removeDir(aDirectoryPath);
       
    92     mMessageStoreDirName = aDirectoryPath + L"\\";
    91     LOG1(EWMA, EInfo , " Creating message store in path %S",
    93     LOG1(EWMA, EInfo , " Creating message store in path %S",
    92          mMessageStoreDirName.c_str());
    94          mMessageStoreDirName.c_str());
    93     // See if directory is present
    95     // See if directory is present
    94     if (FileUtilities::isDirectory(mMessageStoreDirName))
    96     if (FileUtilities::isDirectory(aDirectoryPath))
    95     {
    97     {
    96         std::list<std::wstring> dirList = FileUtilities::getDirContentsList
    98         std::list<std::wstring> dirList = FileUtilities::getDirContentsList
    97                                           (mMessageStoreDirName);
    99                                           (aDirectoryPath);
    98         mMessagesOnStore = dirList.size();
   100         mMessagesOnStore = dirList.size();
    99         if (mMessagesOnStore> 0)
   101         if (mMessagesOnStore> 0)
   100         {
   102         {
   101             // Get the id of the first message in the store
   103             // Get the id of the first message in the store
   102             dirList.sort();
   104             dirList.sort();
   136         char *dirName =0;
   138         char *dirName =0;
   137         try 
   139         try 
   138         {
   140         {
   139            dirName = JavaCommonUtils::wstringToUtf8(path);
   141            dirName = JavaCommonUtils::wstringToUtf8(path);
   140         }
   142         }
   141         catch (ExceptionBase ex)
   143         catch (ExceptionBase &ex)
   142         {
   144         {
   143            delete[] stringToTokenize;
   145            delete[] stringToTokenize;
   144            return -1;
   146            return -1;
   145         }
   147         }
   146         if (ableToOpen)
   148         if (ableToOpen)
   196         std::list<std::wstring>::iterator it;
   198         std::list<std::wstring>::iterator it;
   197         if (dirList.size())
   199         if (dirList.size())
   198         {
   200         {
   199             for (it = dirList.begin(); it != dirList.end(); it++)
   201             for (it = dirList.begin(); it != dirList.end(); it++)
   200             {
   202             {
   201                 std::wstring element(aDirPath);
   203                 std::wstring element(aDirPath + L"\\");
   202                 element += *it;
   204                 element += *it;
   203                 char *fileName = JavaCommonUtils::wstringToUtf8(element);
   205                 char *fileName = JavaCommonUtils::wstringToUtf8(element);
   204                 if ((error = remove(fileName)) != 0)
   206                 if ((error = remove(fileName)) != 0)
   205                 {
   207                 {
   206                     ELOG1(EWMA, "WMA : Removing File  Failed : %s", fileName);
   208                     ELOG1(EWMA, "WMA : Removing File  Failed : %s", fileName);
   217             delete[] path;
   219             delete[] path;
   218             return error;
   220             return error;
   219         }
   221         }
   220         delete[] path;
   222         delete[] path;
   221     }
   223     }
   222     catch (ExceptionBase ex)
   224     catch (ExceptionBase &ex)
   223     {
   225     {
   224         delete[] path;
   226         delete[] path;
   225         ELOG(EWMA,"WMA : Cought an exception while removing Dir");
   227         ELOG(EWMA,"WMA : Cought an exception while removing Dir");
   226         return -1;
   228         return -1;
   227     }
   229     }