javamanager/javainstaller/installcopier/src/javainstallcopier.cpp
changeset 61 bf7ee68962da
equal deleted inserted replaced
48:e0d6e9bd3ca7 61:bf7ee68962da
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 * JavaInstallCopier.exe is a utility for copying Java installation
       
    17 * files from other processes private data cages to JavaInstaller's
       
    18 * private data cage. JavaSifPlugin calls JavaInstallCopier if
       
    19 * installation is started from a file which resides in a private
       
    20 * data cage which JavaInstaller cannot access.
       
    21 *
       
    22 */
       
    23 
       
    24 
       
    25 #ifdef __SYMBIAN32__
       
    26 #include <f32file.h>
       
    27 #include <utf.h>
       
    28 #endif // __SYMBIAN32__
       
    29 
       
    30 #include "exceptionbase.h"
       
    31 #include "javaoslayer.h"
       
    32 #include "logger.h"
       
    33 #include "runtimeexception.h"
       
    34 
       
    35 using namespace java::runtime;
       
    36 using namespace java::util;
       
    37 
       
    38 int isCopyAllowed()
       
    39 {
       
    40     int result = 0;
       
    41 #ifdef __SYMBIAN32__
       
    42     // Only SifServer (0x10285BCB) is allowed to launch JavaInstallCopier.
       
    43     TSecureId creatorSecId(User::CreatorSecureId());
       
    44     if (0x10285BCB != creatorSecId.iId)
       
    45     {
       
    46         ELOG1(EJavaInstaller,
       
    47               "INSTALLCOPIER: Process 0x%x is not allowed to "
       
    48               "launch JavaInstallCopier", creatorSecId.iId);
       
    49         result = KErrPermissionDenied;
       
    50     }
       
    51 #endif // __SYMBIAN32__
       
    52     return result;
       
    53 }
       
    54 
       
    55 int copyToInstallerDir(int argc, char *argv[])
       
    56 {
       
    57     int result = 0;
       
    58 
       
    59 #ifdef __SYMBIAN32__
       
    60     RFs rfs;
       
    61     result = rfs.Connect();
       
    62     if (KErrNone != result)
       
    63     {
       
    64         ELOG1(EJavaInstaller,
       
    65               "INSTALLCOPIER: Connecting to RFs failed, err=%d", result);
       
    66         return result;
       
    67     }
       
    68 
       
    69     CFileMan* fm = NULL;
       
    70     TRAP(result, fm = CFileMan::NewL(rfs));
       
    71     if (KErrNone != result)
       
    72     {
       
    73         ELOG1(EJavaInstaller,
       
    74               "INSTALLCOPIER: Creating CFileMan failed, err=%d", result);
       
    75         return result;
       
    76     }
       
    77 
       
    78     _LIT(KJavaInstallerTmp, "\\private\\102033E6\\installer\\tmp\\");
       
    79     for (int i = 1; i < argc && KErrNone == result; i++)
       
    80     {
       
    81         TPtrC8 srcPtr((const TText8*)argv[i]);
       
    82         TFileName srcPath;
       
    83         CnvUtfConverter::ConvertToUnicodeFromUtf8(srcPath, srcPtr);
       
    84         // Get the drive from the srcPath...
       
    85         TParse fp;
       
    86         rfs.Parse(srcPath, fp);
       
    87         // ...and prefix it to KJavaInstallerTmp path.
       
    88         TFileName dstPath = fp.Drive();
       
    89         dstPath.Append(KJavaInstallerTmp);
       
    90 
       
    91         result = fm->Copy(srcPath, dstPath, CFileMan::ERecurse|CFileMan::EOverWrite);
       
    92 
       
    93         std::wstring srcWs((wchar_t*)srcPath.Ptr(), srcPath.Length());
       
    94         std::wstring dstWs((wchar_t*)dstPath.Ptr(), dstPath.Length());
       
    95         if (KErrNone == result)
       
    96         {
       
    97             ILOG2(EJavaInstaller, "INSTALLCOPIER: Copied %S to %S",
       
    98                   srcWs.c_str(), dstWs.c_str());
       
    99         }
       
   100         else
       
   101         {
       
   102             ELOG3(EJavaInstaller,
       
   103                   "INSTALLCOPIER: Copying %S to %S failed, err=%d",
       
   104                   srcWs.c_str(), dstWs.c_str(), result);
       
   105         }
       
   106     }
       
   107 
       
   108     delete fm;
       
   109     fm = NULL;
       
   110     rfs.Close();
       
   111 #else // __SYMBIAN32__
       
   112     for (int i = 1; i < argc && result == 0; i++)
       
   113     {
       
   114         WLOG1(EJavaInstaller, "INSTALLCOPIER: Ignored %s", argv[i]);
       
   115     }
       
   116 #endif // __SYMBIAN32__
       
   117 
       
   118     return result;
       
   119 }
       
   120 
       
   121 int main(int argc, char *argv[])
       
   122 {
       
   123     //ILOG(EJavaInstaller, "INSTALLCOPIER main()");
       
   124     JavaOsLayer::startUpTrace("INSTALLCOPIER main() start", -1, -1);
       
   125 
       
   126     int result = 0;
       
   127     try
       
   128     {
       
   129         result = isCopyAllowed();
       
   130         if (0 == result)
       
   131         {
       
   132             result = copyToInstallerDir(argc, argv);
       
   133         }
       
   134     }
       
   135     catch (RuntimeException& e)
       
   136     {
       
   137         ELOG1(EJavaInstaller, "INSTALLCOPIER main() RuntimeException caught: %s",
       
   138               e.toString().c_str());
       
   139     }
       
   140     catch (ExceptionBase& e)
       
   141     {
       
   142         ELOG1(EJavaInstaller, "INSTALLCOPIER main() ExceptionBase caught: %s",
       
   143               e.toString().c_str());
       
   144     }
       
   145     catch (std::exception& e)
       
   146     {
       
   147         ELOG1(EJavaInstaller, "INSTALLCOPIER main() Exception %s caught", e.what());
       
   148     }
       
   149 
       
   150     //ILOG1(EJavaInstaller, "INSTALLCOPIER main() exit %d", result);
       
   151     JavaOsLayer::startUpTrace("INSTALLCOPIER main() end", -1, -1);
       
   152     return result;
       
   153 }