appinstaller/AppinstUi/sisxsifplugin/tsrc/testinstaller/activerunner_symbian.cpp
changeset 25 98b66e4fb0be
child 29 26b6f0522fd8
equal deleted inserted replaced
24:84a16765cd86 25:98b66e4fb0be
       
     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 
       
    22 ActiveRunnerPrivate::ActiveRunnerPrivate(ActiveRunner *aRunner) :
       
    23         CActive( CActive::EPriorityStandard ), q_ptr( aRunner )
       
    24 {
       
    25     CActiveScheduler::Add(this);
       
    26 }
       
    27 
       
    28 ActiveRunnerPrivate::~ActiveRunnerPrivate()
       
    29 {
       
    30     Cancel();
       
    31     if( iUseSif )
       
    32         {
       
    33         iSoftwareInstall.Close();
       
    34         }
       
    35     else
       
    36         {
       
    37         iSWInstLauncher.Close();
       
    38         }
       
    39     delete iFileName;
       
    40     delete iArguments;
       
    41     delete iResults;
       
    42 }
       
    43 
       
    44 TInt ActiveRunnerPrivate::Initialize( bool aUseSif )
       
    45 {
       
    46     iUseSif = aUseSif;
       
    47     TInt ret = KErrNone;
       
    48     if( iUseSif )
       
    49         {
       
    50         ret = iSoftwareInstall.Connect();
       
    51         }
       
    52     else
       
    53         {
       
    54         ret = iSWInstLauncher.Connect();
       
    55         }
       
    56     return ret;
       
    57 }
       
    58 
       
    59 TInt ActiveRunnerPrivate::Install( const QString& aFileName, bool aSilent )
       
    60 {
       
    61     TRAPD( err, DoInstallL( aFileName, aSilent ) );
       
    62     return err;
       
    63 }
       
    64 
       
    65 void ActiveRunnerPrivate::DoCancel()
       
    66 {
       
    67     if( iUseSif )
       
    68         {
       
    69         iSoftwareInstall.CancelOperation();
       
    70         }
       
    71     else
       
    72         {
       
    73         iSWInstLauncher.CancelAsyncRequest( SwiUI::ERequestInstall );
       
    74         }
       
    75 }
       
    76 
       
    77 void ActiveRunnerPrivate::RunL()
       
    78 {
       
    79     User::LeaveIfError( iStatus.Int() );
       
    80 
       
    81     RDebug::Printf( "USIFTestInstaller: Installation completed" );
       
    82     if( q_ptr ) {
       
    83         q_ptr->handleCompletion();
       
    84     }
       
    85 }
       
    86 
       
    87 TInt ActiveRunnerPrivate::RunError( TInt aError )
       
    88 {
       
    89     RDebug::Printf( "USIFTestInstaller: Error %d", aError );
       
    90     if( q_ptr ) {
       
    91         q_ptr->handleError( aError );
       
    92     }
       
    93     return KErrNone;
       
    94 }
       
    95 
       
    96 void ActiveRunnerPrivate::DoInstallL( const QString& aFileName, bool aSilent )
       
    97     {
       
    98     if( iFileName )
       
    99         {
       
   100         delete iFileName;
       
   101         iFileName = NULL;
       
   102         }
       
   103     iFileName = HBufC16::NewL( aFileName.length() );
       
   104     TPtr16 fileName( iFileName->Des() );
       
   105     fileName.Copy( reinterpret_cast<const TText*>( aFileName.constData() ) );
       
   106 
       
   107     // Convert forward-slashes to backward-slashes
       
   108     const TChar KBackSlash = '\\';
       
   109     const TChar KSlash = '/';
       
   110     for( TInt i = 0; i < fileName.Length(); ++i )
       
   111         {
       
   112         if( fileName[i] == KSlash )
       
   113             {
       
   114             fileName[i] = KBackSlash;
       
   115             }
       
   116         }
       
   117 
       
   118     if( iUseSif )
       
   119         {
       
   120         if( aSilent )
       
   121             {
       
   122             delete iArguments;
       
   123             iArguments = NULL;
       
   124             iArguments = Usif::COpaqueNamedParams::NewL();
       
   125             iArguments->AddIntL( Usif::KSifInParam_InstallSilently, 1 );
       
   126 
       
   127             delete iResults;
       
   128             iResults = NULL;
       
   129             iResults = Usif::COpaqueNamedParams::NewL();
       
   130 
       
   131             iSoftwareInstall.Install( fileName, *iArguments, *iResults, iStatus );
       
   132             }
       
   133         else
       
   134             {
       
   135             iSoftwareInstall.Install( fileName, iStatus );
       
   136             }
       
   137         }
       
   138     else
       
   139         {
       
   140         if( aSilent )
       
   141             {
       
   142             SwiUI::TInstallOptions defaultOptions;
       
   143             SwiUI::TInstallOptionsPckg optPckg( defaultOptions );
       
   144             iSWInstLauncher.SilentInstall( iStatus, fileName, optPckg );
       
   145             }
       
   146         else
       
   147             {
       
   148             iSWInstLauncher.Install( iStatus, fileName );
       
   149             }
       
   150         }
       
   151     SetActive();
       
   152     }
       
   153