installationservices/swinstallationfw/source/siflauncher.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
       
     2 * Copyright (c) 2008-2009 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 the License "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 * Implements  a built-in SIF launcher that integrates the SIF API with AppArc.
       
    16 * Thanks to this integration,  generic applications may launch installation of
       
    17 * a common scenario widely used, for example by file and web browsers, when
       
    18 * the user clicks on a file or link.
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 /**
       
    24  a software component using @see RApaLsSession::StartDocument. This is
       
    25 */
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <apgcli.h>
       
    29 #include <apacmdln.h>
       
    30 #include <f32file.h>
       
    31 #include <usif/sif/sif.h>
       
    32 #include "usiflog.h"
       
    33 
       
    34 using namespace Usif;
       
    35 
       
    36 LOCAL_C void LaunchInstallL();
       
    37 
       
    38 /** main function called by E32 */
       
    39 GLDEF_C TInt E32Main()
       
    40 	{
       
    41 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    42 
       
    43 	__UHEAP_MARK;
       
    44 	TRAPD(err,LaunchInstallL());
       
    45 	__UHEAP_MARKEND;
       
    46 
       
    47 	delete cleanup;
       
    48 	return err;
       
    49 	}
       
    50 
       
    51 LOCAL_C void LaunchInstallL()
       
    52     {
       
    53 	// Get the command line object with data as attached to the process by AppArc.
       
    54 	CApaCommandLine* commandLine = NULL;
       
    55 	TInt err = CApaCommandLine::GetCommandLineFromProcessEnvironment(commandLine);
       
    56 	DEBUG_PRINTF2(_L8("SIF Launcher: CApaCommandLine::GetCommandLineFromProcessEnvironment result = %d\n"),err);
       
    57 	User::LeaveIfError(err);
       
    58 	
       
    59 	CleanupStack::PushL(commandLine);
       
    60 	
       
    61 	switch (commandLine->Command())
       
    62 		{
       
    63 		case EApaCommandOpen:
       
    64 			{
       
    65 			// Open the file and use the handle to install it
       
    66 			RFile fileHandle;
       
    67 			CleanupClosePushL(fileHandle);
       
    68 			commandLine->GetFileByHandleL(fileHandle);
       
    69 
       
    70 			// Establish a connection with the SIF server
       
    71 			RSoftwareInstall sif;
       
    72 			err = sif.Connect();
       
    73 			if (err != KErrNone)
       
    74 				{
       
    75 				DEBUG_PRINTF2(_L8("SIF Launcher: RSoftwareInstall::Connect() failed, error = %d\n"),err);
       
    76 				User::Leave(err);
       
    77 				}
       
    78 
       
    79 			CleanupClosePushL(sif);
       
    80 			TRequestStatus status;
       
    81 			
       
    82 			if (fileHandle.SubSessionHandle() != KNullHandle)
       
    83 				{
       
    84 				// We've got a working file handle, so use it...
       
    85 				DEBUG_PRINTF(_L8("SIF Launcher: installation by file handle...\n"));
       
    86 				sif.Install(fileHandle, status);
       
    87 				}
       
    88 			else
       
    89 				{
       
    90 				// ...otherwise the file name of a package
       
    91 				DEBUG_PRINTF(_L8("SIF Launcher: installation by file name...\n"));
       
    92 				sif.Install(commandLine->DocumentName(), status);
       
    93 				}
       
    94 				
       
    95 			User::WaitForRequest(status);
       
    96 			DEBUG_PRINTF2(_L8("SIF Launcher: installation finished with err = %d\n"),status.Int());
       
    97 			CleanupStack::PopAndDestroy(2, &fileHandle);
       
    98 			break;
       
    99 			}
       
   100 			
       
   101 		/* SIF Launcher doesn't support the following commands:
       
   102 		- EApaCommandCreate,
       
   103 		- EApaCommandRun,
       
   104 		- EApaCommandBackground,
       
   105 		- EApaCommandViewActivate,
       
   106 		- EApaCommandRunWithoutViews,
       
   107 		- EApaCommandBackgroundAndWithoutViews */
       
   108 		default:
       
   109 			User::Leave(KErrNotSupported);
       
   110 			break;
       
   111 		}
       
   112 
       
   113 	CleanupStack::PopAndDestroy(commandLine);
       
   114 	}