appinstaller/AppinstUi/sisxsifplugin/tsrc/testinstaller/activerunner_symbian.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     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:  Test installer that uses Usif::RSoftwareInstall API.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "activerunner_symbian.h"
       
    19 #include "activerunner.h"
       
    20 
       
    21 _LIT( KDefaultOcspResponderUrl, "http://4fil30423.noe.nokia.com:45000/" );
       
    22 
       
    23 
       
    24 ActiveRunnerPrivate::ActiveRunnerPrivate( ActiveRunner *aRunner ) :
       
    25         CActive( CActive::EPriorityStandard ), q_ptr( aRunner )
       
    26     {
       
    27     CActiveScheduler::Add( this );
       
    28     }
       
    29 
       
    30 ActiveRunnerPrivate::~ActiveRunnerPrivate()
       
    31     {
       
    32     Cancel();
       
    33     if( iUseSif )
       
    34         {
       
    35         iSoftwareInstall.Close();
       
    36         }
       
    37     else
       
    38         {
       
    39         iSWInstLauncher.Close();
       
    40         }
       
    41     iFs.Close();
       
    42     delete iFileName;
       
    43     delete iArguments;
       
    44     delete iResults;
       
    45     }
       
    46 
       
    47 TInt ActiveRunnerPrivate::Initialize( bool aUseSif )
       
    48     {
       
    49     TRAPD( err, DoInitializeL( aUseSif ) );
       
    50     return err;
       
    51     }
       
    52 
       
    53 TInt ActiveRunnerPrivate::Install( const QString& aFileName, bool aSilent, bool aOpenFile, bool aOcsp )
       
    54     {
       
    55     TRAPD( err, DoInstallL( aFileName, aSilent, aOpenFile, aOcsp ) );
       
    56     return err;
       
    57     }
       
    58 
       
    59 TInt ActiveRunnerPrivate::Remove( const Usif::TComponentId& aComponentId, bool aSilent )
       
    60     {
       
    61     TRAPD( err, DoRemoveL( aComponentId, aSilent ) );
       
    62     return err;
       
    63     }
       
    64 
       
    65 TInt ActiveRunnerPrivate::Remove( const TUid& aUid, const TDesC8& aMime, bool aSilent )
       
    66     {
       
    67     TRAPD( err, DoRemoveL( aUid, aMime, aSilent ) );
       
    68     return err;
       
    69     }
       
    70 
       
    71 void ActiveRunnerPrivate::DoCancel()
       
    72     {
       
    73     if( iUseSif )
       
    74         {
       
    75         iSoftwareInstall.CancelOperation();
       
    76         }
       
    77     else
       
    78         {
       
    79         iSWInstLauncher.CancelAsyncRequest( SwiUI::ERequestInstall );
       
    80         }
       
    81     }
       
    82 
       
    83 void ActiveRunnerPrivate::RunL()
       
    84     {
       
    85     User::LeaveIfError( iStatus.Int() );
       
    86 
       
    87     RDebug::Printf( "USIFTestInstaller: Installation completed" );
       
    88     if( q_ptr )
       
    89         {
       
    90         q_ptr->handleCompletion();
       
    91         }
       
    92     }
       
    93 
       
    94 TInt ActiveRunnerPrivate::RunError( TInt aError )
       
    95     {
       
    96     RDebug::Printf( "USIFTestInstaller: Error %d", aError );
       
    97     if( q_ptr )
       
    98         {
       
    99         q_ptr->handleError( aError );
       
   100         }
       
   101     return KErrNone;
       
   102     }
       
   103 
       
   104 void ActiveRunnerPrivate::DoInitializeL( bool aUseSif )
       
   105     {
       
   106     iUseSif = aUseSif;
       
   107     User::LeaveIfError( iFs.Connect() );
       
   108     User::LeaveIfError( iFs.ShareProtected() );
       
   109     if( iUseSif )
       
   110         {
       
   111         User::LeaveIfError( iSoftwareInstall.Connect() );
       
   112         }
       
   113     else
       
   114         {
       
   115         User::LeaveIfError( iSWInstLauncher.Connect() );
       
   116         }
       
   117     }
       
   118 
       
   119 void ActiveRunnerPrivate::DoInstallL( const QString& aFileName, bool aSilent, bool aOpenFile, bool aOcsp )
       
   120     {
       
   121     if( iFileName )
       
   122         {
       
   123         delete iFileName;
       
   124         iFileName = NULL;
       
   125         }
       
   126     iFileName = HBufC16::NewL( aFileName.length() );
       
   127     TPtr16 fileName( iFileName->Des() );
       
   128     fileName.Copy( reinterpret_cast<const TText*>( aFileName.constData() ) );
       
   129 
       
   130     // Convert forward-slashes to backward-slashes
       
   131     const TChar KBackSlash = '\\';
       
   132     const TChar KSlash = '/';
       
   133     for( TInt i = 0; i < fileName.Length(); ++i )
       
   134         {
       
   135         if( fileName[i] == KSlash )
       
   136             {
       
   137             fileName[i] = KBackSlash;
       
   138             }
       
   139         }
       
   140 
       
   141     RFile fileHandle;
       
   142     if( aOpenFile )
       
   143         {
       
   144         User::LeaveIfError( fileHandle.Open( iFs, fileName, EFileRead ) );
       
   145         CleanupClosePushL( fileHandle );
       
   146         }
       
   147 
       
   148     if( iUseSif )
       
   149         {
       
   150         delete iArguments;
       
   151         iArguments = NULL;
       
   152         iArguments = Usif::COpaqueNamedParams::NewL();
       
   153 
       
   154         delete iResults;
       
   155         iResults = NULL;
       
   156         iResults = Usif::COpaqueNamedParams::NewL();
       
   157 
       
   158         if( aSilent )
       
   159             {
       
   160             iArguments->AddIntL( Usif::KSifInParam_InstallSilently, ETrue );
       
   161             }
       
   162         if( aOcsp )
       
   163             {
       
   164             iArguments->AddIntL( Usif::KSifInParam_PerformOCSP, Usif::EAllowed );
       
   165             iArguments->AddStringL( Usif::KSifInParam_OCSPUrl, KDefaultOcspResponderUrl );
       
   166             }
       
   167 
       
   168         if( aOpenFile )
       
   169             {
       
   170             iSoftwareInstall.Install( fileHandle, *iArguments, *iResults, iStatus );
       
   171             }
       
   172         else
       
   173             {
       
   174             iSoftwareInstall.Install( fileName, *iArguments, *iResults, iStatus );
       
   175             }
       
   176         }
       
   177     else
       
   178         {
       
   179         if( aSilent )
       
   180             {
       
   181             SwiUI::TInstallOptions defaultOptions;
       
   182             SwiUI::TInstallOptionsPckg optPckg( defaultOptions );
       
   183 
       
   184             if( aOpenFile )
       
   185                 {
       
   186                 iSWInstLauncher.SilentInstall( iStatus, fileHandle, optPckg );
       
   187                 }
       
   188             else
       
   189                 {
       
   190                 iSWInstLauncher.SilentInstall( iStatus, fileName, optPckg );
       
   191                 }
       
   192             }
       
   193         else
       
   194             {
       
   195             if( aOpenFile )
       
   196                 {
       
   197                 iSWInstLauncher.Install( iStatus, fileHandle );
       
   198                 }
       
   199             else
       
   200                 {
       
   201                 iSWInstLauncher.Install( iStatus, fileName  );
       
   202                 }
       
   203             }
       
   204         }
       
   205 
       
   206     if( aOpenFile )
       
   207         {
       
   208         CleanupStack::PopAndDestroy( &fileHandle );
       
   209         }
       
   210 
       
   211     SetActive();
       
   212     }
       
   213 
       
   214 void ActiveRunnerPrivate::DoRemoveL( const Usif::TComponentId& aComponentId, bool aSilent )
       
   215     {
       
   216     if( aSilent )
       
   217         {
       
   218         delete iArguments;
       
   219         iArguments = NULL;
       
   220         iArguments = Usif::COpaqueNamedParams::NewL();
       
   221         iArguments->AddIntL( Usif::KSifInParam_InstallSilently, 1 );
       
   222 
       
   223         delete iResults;
       
   224         iResults = NULL;
       
   225         iResults = Usif::COpaqueNamedParams::NewL();
       
   226 
       
   227         iSoftwareInstall.Uninstall( aComponentId, *iArguments, *iResults, iStatus );
       
   228         }
       
   229     else
       
   230         {
       
   231         iSoftwareInstall.Uninstall( aComponentId, iStatus );
       
   232         }
       
   233     SetActive();
       
   234     }
       
   235 
       
   236 void ActiveRunnerPrivate::DoRemoveL( const TUid& aUid, const TDesC8& aMime, bool aSilent )
       
   237     {
       
   238     if( aSilent )
       
   239         {
       
   240         SwiUI::TUninstallOptions defaultOptions;
       
   241         SwiUI::TUninstallOptionsPckg optPckg( defaultOptions );
       
   242         iSWInstLauncher.SilentUninstall( iStatus, aUid, optPckg, aMime );
       
   243         }
       
   244     else
       
   245         {
       
   246         iSWInstLauncher.Uninstall( iStatus, aUid, aMime );
       
   247         }
       
   248     SetActive();
       
   249     }
       
   250