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