widgets/widgetinstaller/src/WidgetUIOperationsWatcher.cpp
changeset 0 dd21522fd290
child 10 a359256acfc6
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006, 2008 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:  This file contains the header file of the CMidletUI class.
       
    15 *
       
    16 *                This class implements the ECom SWInstUIPluginAPI interface
       
    17 *                for midlet installation.
       
    18 *
       
    19 *
       
    20 */
       
    21 
       
    22 #include <f32file.h>
       
    23 #include <SWInstDefs.h>
       
    24 #include <zipfile.h>
       
    25 
       
    26 #include <SWInstTaskManager.h>
       
    27 #include <SWInstTask.h>
       
    28 #include <SWInstLogTaskParam.h>
       
    29 
       
    30 
       
    31 
       
    32 #include "WidgetUIOperationsWatcher.h"
       
    33 #include "WidgetUIConfigHandler.h" // info.plist parser
       
    34 #include "WidgetRegistrationManager.h" // interface to "shell"
       
    35 
       
    36 // CONSTANTS
       
    37 _LIT( KInfoPlist,"Info.plist" );
       
    38 _LIT( KIconFile, "Icon.png" );
       
    39 _LIT( KMBMExt, ".mbm");
       
    40 _LIT( KLprojExt, ".lproj" );
       
    41 _LIT( KInfoPlistStrings, "InfoPlist.strings" );
       
    42 _LIT( KWidgetAppDir, "\\private\\10282822\\" );
       
    43 _LIT( KCookieFile, "c:\\private\\101f8530\\cookies.dat" );
       
    44 
       
    45 
       
    46 const TUint KMaxDescLength = 0x0fffffffu;
       
    47 
       
    48 // Note about filenames: All file name matching is case insensitive
       
    49 // the EDriveName is stored as "c:" (withou a trailing backslash) all
       
    50 // filenames are kept as complete pathnames (drive + path + filename)
       
    51 // except when working with the widget bundle where the bundle
       
    52 // contains relative paths
       
    53 
       
    54 // TODO
       
    55 // filenames are kept as drive relative pathnames (path + filename but
       
    56 // not drive).  The widget bundle must contain relative paths.  The
       
    57 // drive letter is separated because support for multiple drives and
       
    58 // removable memory cards means that drive letters may change.
       
    59 
       
    60 
       
    61 using namespace SwiUI;
       
    62 
       
    63 // =========================== MEMBER FUNCTIONS ===============================
       
    64 
       
    65 
       
    66 // ============================================================================
       
    67 // CWidgetUIOperationsWatcher::NewL()
       
    68 // two-phase constructor
       
    69 //
       
    70 // @since 3.1
       
    71 // @return pointer to CWidgetUIOperationsWatcher
       
    72 // ============================================================================
       
    73 //
       
    74 CWidgetUIOperationsWatcher* CWidgetUIOperationsWatcher::NewL()
       
    75     {
       
    76     CWidgetUIOperationsWatcher* self
       
    77         = new (ELeave) CWidgetUIOperationsWatcher();
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL();
       
    80     CleanupStack::Pop( self );
       
    81     return self;
       
    82     }
       
    83 
       
    84 // ============================================================================
       
    85 // CWidgetUIOperationsWatcher::CWidgetUIOperationsWatcher()
       
    86 // C++ constructor
       
    87 //
       
    88 // @since 3.1
       
    89 // ============================================================================
       
    90 //
       
    91 CWidgetUIOperationsWatcher::CWidgetUIOperationsWatcher()
       
    92     : CActive( CActive::EPriorityStandard ),
       
    93       iPropertyValues( EWidgetPropertyIdCount )
       
    94     {
       
    95     CActiveScheduler::Add( this );
       
    96     }
       
    97 
       
    98 // ============================================================================
       
    99 // CWidgetUIOperationsWatcher::ConstructL()
       
   100 // Symbian second phase constructor
       
   101 //
       
   102 // @since 3.1
       
   103 // ============================================================================
       
   104 //
       
   105 void CWidgetUIOperationsWatcher::ConstructL()
       
   106     {
       
   107     User::LeaveIfError( iRfs.Connect() );
       
   108     User::LeaveIfError( iRfs.ShareProtected() );
       
   109     iFileMgr = CFileMan::NewL( iRfs );
       
   110 
       
   111     iAppManager = CWidgetRegistrationManager::NewL( iRfs );
       
   112     iWidgetConfigHandler = CWidgetUIConfigHandler::NewL();
       
   113 
       
   114     User::LeaveIfError( iRegistry.Connect() );
       
   115     iServerConnected = ETrue;
       
   116 
       
   117     TInt i = 0;
       
   118     // empty values
       
   119     for ( ; i < EWidgetPropertyIdCount; ++i )
       
   120         {
       
   121         CWidgetPropertyValue* value = CWidgetPropertyValue::NewL();
       
   122         User::LeaveIfError( iPropertyValues.Insert( value, i ) );
       
   123         }
       
   124     *(iPropertyValues[EWidgetPropertyListVersion]) = WIDGETPROPERTYLISTVERSION;
       
   125 
       
   126     iTaskManager = CTaskManager::NewL();
       
   127     }
       
   128 
       
   129 // ============================================================================
       
   130 // CWidgetUIOperationsWatcher::~CWidgetUIOperationsWatcher()
       
   131 // destructor
       
   132 //
       
   133 // @since 3.1
       
   134 // ============================================================================
       
   135 //
       
   136 CWidgetUIOperationsWatcher::~CWidgetUIOperationsWatcher()
       
   137     {
       
   138     CActive::Cancel();
       
   139 
       
   140     TInt i = 0;
       
   141     for ( ; i < EWidgetPropertyIdCount; ++i )
       
   142         {
       
   143         delete iPropertyValues[i];
       
   144         }
       
   145     iPropertyValues.Close();
       
   146 
       
   147     delete iMembers;
       
   148     delete iZipFile;
       
   149 
       
   150     delete iFileMgr;
       
   151     iRfs.Close();
       
   152 
       
   153     delete iUIHandler;
       
   154     delete iWidgetConfigHandler;
       
   155     delete iAppManager;
       
   156     delete iIconConverter;
       
   157 
       
   158     if ( iServerConnected )
       
   159         {
       
   160         iRegistry.Disconnect();
       
   161         }
       
   162 
       
   163     delete iTaskManager;
       
   164     }
       
   165 
       
   166 // ============================================================================
       
   167 // CWidgetUIOperationsWatcher::SilentInstallL()
       
   168 // Handle silent install request.
       
   169 //
       
   170 // @since 3.1
       
   171 // ============================================================================
       
   172 //
       
   173 void CWidgetUIOperationsWatcher::SilentInstallL(
       
   174     RFile& aFile,
       
   175     const TDesC8& aMIME,
       
   176     TRequestStatus& aRequestStatus )
       
   177     {
       
   178     iSilent = ETrue;
       
   179     InstallL( aFile, aMIME, aRequestStatus );
       
   180     }
       
   181 
       
   182 // ============================================================================
       
   183 // CWidgetUIOperationsWatcher::InstallSubfunctionL()
       
   184 // Breaks out some install work inside trap macro because trap macro
       
   185 // intereferes with some debuggers.
       
   186 //
       
   187 // @since 5.0
       
   188 // ============================================================================
       
   189 //
       
   190 void CWidgetUIOperationsWatcher::InstallSubfunctionL(
       
   191     RFile& aFile,
       
   192     TBool& userCancel,
       
   193     TRequestStatus& aRequestStatus )
       
   194     {
       
   195     iZipFile = CZipFile::NewL( iRfs, aFile );
       
   196 
       
   197     // do initial bundle processing (parse and validate, total size,
       
   198     // check if replacing existing widget with same bundle ID, etc.)
       
   199     //
       
   200     // this step doesn't do anything that would need to be undone
       
   201     TBool replaceExisting = PreprocessWidgetBundleL();
       
   202 
       
   203     if ( PromptUserForInstallL( replaceExisting )
       
   204          && PromptUserForUntrustedWidgetL( ) )
       
   205         {
       
   206         // reinitialize
       
   207         delete iMembers;
       
   208         iMembers = NULL;
       
   209         iMembers = iZipFile->GetMembersL();
       
   210 
       
   211         // now that install location is known, update MainHTML
       
   212         const TDesC& base = *(iPropertyValues[EBasePath]);
       
   213         const TDesC& main = *(iPropertyValues[EMainHTML]);
       
   214         if ( KMaxFileName < (base.Length() + main.Length()) )
       
   215             {
       
   216             User::Leave( KErrCorrupt );
       
   217             }
       
   218         TFileName tempFile;
       
   219         tempFile.Copy( base );
       
   220         tempFile.Append( main );
       
   221         *(iPropertyValues[EMainHTML]) = tempFile;
       
   222 
       
   223 
       
   224         // diplay explanation: 1. The progress display only comes up
       
   225         // if the total size is over 1 kilobyte (this
       
   226         // conditionalization is in UIHandler). 2. The displays stack
       
   227         // on top of each other so if progress display comes up it
       
   228         // will hide the finalize and then when progesss is removed,
       
   229         // the finalize will be revealed.  3. Also, finalize failed to
       
   230         // come up when triggered at the end of RunL() on a tiny
       
   231         // widget file with no icon.  Why, I'm not sure but probably
       
   232         // had to do with this active object blocking display
       
   233         // processing.  So here is a good place to put up the displays
       
   234         // (before RunL() is invoked) which lets other objects run.
       
   235 
       
   236         iUIHandler->DisplayFinalizeDialogL(); // a dialog without a cancel option
       
   237         iUIHandler->DisplayProgressDialogL(); // progress bar
       
   238 
       
   239         if ( replaceExisting )
       
   240             {
       
   241             BackupL(); // nothing need be undone if backup leaves
       
   242             // backup will gaurantee that install dir is empty
       
   243 
       
   244             // now don't execute any leaving code before starting RunL
       
   245             }
       
   246         else
       
   247             {
       
   248             // new widget, allocate a UID for this widget
       
   249             const TDesC& drive = *(iPropertyValues[EDriveName]);
       
   250             *(iPropertyValues[EUid]) = iRegistry.GetAvailableUidL(drive[0]).iUid;
       
   251 
       
   252             // check that install location is empty and remove what is
       
   253             // there if it isn't
       
   254             TUint attributes = 0;
       
   255             TInt e = iRfs.Att( base, attributes );
       
   256             if ( (KErrNotFound != e)
       
   257                  && (KErrPathNotFound != e) )
       
   258                 {
       
   259                 (void)iFileMgr->RmDir( base );
       
   260                 }
       
   261             }
       
   262         }
       
   263     else
       
   264         {
       
   265         userCancel = ETrue;
       
   266         iUIHandler->DisplayCancelL();
       
   267         TRequestStatus* status = &aRequestStatus;
       
   268         User::RequestComplete( status, KErrNone );
       
   269         }
       
   270     }
       
   271 
       
   272 // ============================================================================
       
   273 // CWidgetUIOperationsWatcher::InstallL()
       
   274 // NORMAL INSTALL STEPS:
       
   275 // 1. open zip file
       
   276 // 2. get metadata file (e.g. Info.plist) and parse it
       
   277 // 3. prompt user to install (or replace identically named existing widget)
       
   278 // 4. prompt user for install location (built-in mem or mem card)
       
   279 //    and do free space check
       
   280 // 5. if replacing existing widget then move currently installed files
       
   281 //    to backup for possible restore on install error
       
   282 // 6. continue install in an active object runl to make install
       
   283 //    cancellable also do icon processing in a separate active object
       
   284 //   (the icon processing active object is a questionable design because
       
   285 //    it doesn't follow the conventional CActive request/response pattern
       
   286 //    and might as well be done here in the RunL)
       
   287 //
       
   288 // @since 3.1
       
   289 // ============================================================================
       
   290 //
       
   291 void CWidgetUIOperationsWatcher::InstallL(
       
   292     RFile& aFile,
       
   293     const TDesC8& /*aMIME*/,
       
   294     TRequestStatus& aRequestStatus )
       
   295     {
       
   296     // Wrapper CWidgetInstallerUI::InstallL() guards against
       
   297     // a second install request while currently installing.
       
   298 
       
   299     iCancelled = EFalse;
       
   300 
       
   301     // These three bools will be flase until doing something that
       
   302     // needs to be cleaned up on error/cancel.
       
   303     iUnzipping = EFalse;
       
   304     iOverwriting = EFalse;
       
   305     iProcessingIcon = EFalse;
       
   306 
       
   307     iIconSearchFinished = EFalse;
       
   308     iIconError = KErrNone;
       
   309 
       
   310     // outside trap because without a UI we can't display an error message
       
   311     iUIHandler =
       
   312         CWidgetUIHandler::NewL( CWidgetUIHandler::EModeInstall, this );
       
   313 
       
   314     TBool userCancel = EFalse;
       
   315     TRAPD( error, InstallSubfunctionL( aFile, userCancel, aRequestStatus ) );
       
   316     if ( KErrNone != error )
       
   317         {
       
   318         iUIHandler->DisplayErrorL( error );
       
   319         User::Leave( error );
       
   320         }
       
   321     else if ( userCancel )
       
   322         {
       
   323         return; // can't do return inside trap
       
   324         }
       
   325 
       
   326     // start putting bundle files in install area, registy won't be
       
   327     // changed until done unzipping and processing icon (if present)
       
   328     iUnzipping = ETrue;
       
   329 
       
   330     // set client request to pending state
       
   331     iRequestStatus = &aRequestStatus;
       
   332     *iRequestStatus = KRequestPending;
       
   333 
       
   334     // start RunL
       
   335     TRequestStatus* status = &iStatus;
       
   336     User::RequestComplete( status, KErrNone );
       
   337     SetActive();
       
   338     }
       
   339 
       
   340 // ============================================================================
       
   341 // CWidgetUIOperationsWatcher::PreprocessWidgetBundleL()
       
   342 // Handles parsing and creating widget
       
   343 //
       
   344 // @since 3.1
       
   345 // ============================================================================
       
   346 //
       
   347 TBool CWidgetUIOperationsWatcher::PreprocessWidgetBundleL()
       
   348     {
       
   349     TBool found = EFalse;
       
   350 
       
   351     TFileName tempFile;
       
   352     TFileName bundleRoot; // root dir in widget bundle (not install root)
       
   353     TUint32 zipfileUncompressedSize = 0;
       
   354 
       
   355     iMembers = iZipFile->GetMembersL();
       
   356     if ( NULL == iMembers )
       
   357         {
       
   358         User::Leave( KErrNotSupported );
       
   359         }
       
   360     // compute total installed (uncompressed) size for use in progress
       
   361     // meter (doesn't account for some derived things like scaled
       
   362     // icons and registry data)
       
   363     CZipFileMember* member = iMembers->NextL();
       
   364     for ( ; member ; member = iMembers->NextL() )
       
   365         {
       
   366         zipfileUncompressedSize += member->UncompressedSize();
       
   367         delete member;
       
   368         }
       
   369     if ( 0 == zipfileUncompressedSize )
       
   370         {
       
   371         User::Leave( KErrNotSupported );
       
   372         }
       
   373     *(iPropertyValues[EFileSize]) = zipfileUncompressedSize;
       
   374 
       
   375     // find the top-level directory under which to get metadata
       
   376     // TODO this isn't robust, check cases where there are multiple
       
   377     // top-level dirs and no top-level dirs.
       
   378     delete iMembers;
       
   379     iMembers = NULL;
       
   380     iMembers = iZipFile->GetMembersL();
       
   381     member = iMembers->NextL();
       
   382     TPtrC fName( *member->Name() );
       
   383     TInt pos = fName.Locate( KPathDelimiter );
       
   384     if ( (KErrNotFound == pos) || (KMaxFileName < pos) )
       
   385         {
       
   386         User::Leave( KErrNotSupported );
       
   387         }
       
   388     bundleRoot.Copy( fName.Left( pos ) );
       
   389     delete member;
       
   390     delete iMembers;
       
   391     iMembers = NULL;
       
   392 
       
   393     // metadata file: "WeatherBug.wdgt\Info.plist"
       
   394     if ( KMaxFileName
       
   395          < (bundleRoot.Length() + 1 /* slash */ + KInfoPlist().Length()) )
       
   396         {
       
   397         User::Leave( KErrCorrupt );
       
   398         }
       
   399     tempFile.Copy( bundleRoot );
       
   400     tempFile.Append( KPathDelimiter );
       
   401     tempFile.Append( KInfoPlist );
       
   402     CZipFileMember* infoFileMember =
       
   403         iZipFile->CaseInsensitiveMemberL( tempFile );
       
   404     if ( NULL == infoFileMember )
       
   405         {
       
   406         // missing metadata file
       
   407         User::Leave( KErrNotSupported );
       
   408         }
       
   409     CleanupStack::PushL( infoFileMember );
       
   410 
       
   411     // we will use descriptors to handle the Info.plist contents so
       
   412     // the file may not be larger than a descriptor can handle
       
   413     if ( KMaxDescLength < infoFileMember->UncompressedSize() )
       
   414         {
       
   415         User::Leave( KErrCorrupt );
       
   416         }
       
   417 
       
   418     // extract Info.plist from zip into a buffer
       
   419     RZipFileMemberReaderStream* stream;
       
   420     iZipFile->GetInputStreamL( infoFileMember, stream );
       
   421     CleanupStack::PushL( stream );
       
   422     HBufC8* buffer = HBufC8::NewLC( infoFileMember->UncompressedSize() );
       
   423     TPtr8 bufferPtr( buffer->Des() );
       
   424     User::LeaveIfError(
       
   425         stream->Read( bufferPtr, infoFileMember->UncompressedSize() ) );
       
   426 
       
   427     // METADATA PARSE
       
   428     iWidgetConfigHandler->ParseValidateBundleMetadataL(
       
   429         bufferPtr, iPropertyValues, iRfs );
       
   430 
       
   431     CleanupStack::PopAndDestroy( 3 ); // infoFileMember, stream, buffer
       
   432 
       
   433     // EXISTING WIDGET?
       
   434     if( iRegistry.WidgetExistsL( *(iPropertyValues[EBundleIdentifier]) ) )
       
   435         {
       
   436         // replacement for currently installed widget
       
   437         *(iPropertyValues[EUid]) = iRegistry.GetWidgetUidL(
       
   438             *(iPropertyValues[EBundleIdentifier]));
       
   439         found = ETrue;
       
   440         if ( iRegistry.IsWidgetRunning( 
       
   441                 TUid::Uid( *(iPropertyValues[EUid]) )) )
       
   442             {
       
   443             iUIHandler->CloseProgressDialogL();
       
   444             User::Leave( KErrInUse );
       
   445             }
       
   446         // get original install dir from registry in case user
       
   447         // decides to "overrite" to another memory location
       
   448         iOriginalDir = *( iRegistry.GetWidgetPropertyValueL(
       
   449                               TUid::Uid( *(iPropertyValues[EUid]) ),
       
   450                               EBasePath ) );
       
   451         }
       
   452     // uid for a new widget will be gotten once install location (c: or
       
   453     // e:) is selected
       
   454 
       
   455     // see if main.html is in zip bundle
       
   456     const TDesC& main = *(iPropertyValues[EMainHTML]);
       
   457     if ( KMaxFileName
       
   458          < (bundleRoot.Length() + 1 /* slash */ + main.Length()) )
       
   459         {
       
   460         User::Leave( KErrCorrupt );
       
   461         }
       
   462     tempFile.Copy( bundleRoot );
       
   463     tempFile.Append( KPathDelimiter );
       
   464     tempFile.Append( main );
       
   465     CZipFileMember* mainFileMember
       
   466         = iZipFile->CaseInsensitiveMemberL( tempFile );
       
   467     if ( !mainFileMember )
       
   468         {
       
   469         // missing main html file
       
   470         User::Leave( KErrCorrupt );
       
   471         }
       
   472     delete mainFileMember;
       
   473     mainFileMember = NULL;
       
   474     // save MainHTML partial path to combine with base path when
       
   475     // install location is selected
       
   476     *(iPropertyValues[EMainHTML]) = tempFile;
       
   477 
       
   478     // see if there is an Icon.png in root and get partial path
       
   479     if ( KMaxFileName
       
   480          < (bundleRoot.Length() + 1 /* slash */ + KIconFile().Length()) )
       
   481         {
       
   482         User::Leave( KErrCorrupt );
       
   483         }
       
   484     tempFile.Copy( bundleRoot );
       
   485     tempFile.Append( KPathDelimiter );
       
   486     tempFile.Append( KIconFile );
       
   487     CZipFileMember* iconFileMember
       
   488         = iZipFile->CaseInsensitiveMemberL( tempFile );
       
   489     if ( iconFileMember )
       
   490         {
       
   491         // save this partial path to identify Icon.png during unzip
       
   492         *(iPropertyValues[EIconPath]) = tempFile;
       
   493         }
       
   494     else
       
   495         {
       
   496         iIconSearchFinished = ETrue;
       
   497         }
       
   498 
       
   499     // ex. infoLocFile pathname "WeatherBug.wdgt\en.lproj\InfoPlist.strings"
       
   500     TBuf<32> lproj;
       
   501     iRegistry.GetLprojName( lproj ); // e.g. "en", "fr", "zh_Hans" ...
       
   502     if ( KMaxFileName
       
   503          < (bundleRoot.Length() + 1 /* slash */ + lproj.Length()
       
   504             + KLprojExt().Length() + 1 /* slash */
       
   505             + KInfoPlistStrings().Length()) )
       
   506         {
       
   507         User::Leave( KErrCorrupt );
       
   508         }
       
   509     TFileName infoLocFile( bundleRoot );
       
   510     infoLocFile.Append( KPathDelimiter );
       
   511     infoLocFile.Append( lproj );
       
   512     infoLocFile.Append( KLprojExt );
       
   513     infoLocFile.Append( KPathDelimiter );
       
   514     infoLocFile.Append( KInfoPlistStrings );
       
   515 
       
   516     CZipFileMember* infoLocFileMember =
       
   517         iZipFile->CaseInsensitiveMemberL( infoLocFile );
       
   518     if ( infoLocFileMember )
       
   519         {
       
   520         CleanupStack::PushL( infoLocFileMember );
       
   521         RZipFileMemberReaderStream* stream;
       
   522         iZipFile->GetInputStreamL( infoLocFileMember, stream );
       
   523         CleanupStack::PushL( stream );
       
   524 
       
   525         // we will use descriptors to handle the l10n contents so
       
   526         // the file may not be larger than a descriptor can handle
       
   527         if ( KMaxDescLength < infoLocFileMember->UncompressedSize() )
       
   528             {
       
   529             User::Leave( KErrCorrupt );
       
   530             }
       
   531         HBufC8* buffer
       
   532             = HBufC8::NewLC( infoLocFileMember->UncompressedSize() );
       
   533         TPtr8 bufferPtr( buffer->Des() );
       
   534         User::LeaveIfError(
       
   535             stream->Read( bufferPtr, infoLocFileMember->UncompressedSize() ) );
       
   536 
       
   537         // parse the l10n file and localize the bundle display name
       
   538         iWidgetConfigHandler->ParseInfoLocL(
       
   539             bufferPtr, iRfs, *(iPropertyValues[EBundleDisplayName]) );
       
   540 
       
   541         CleanupStack::PopAndDestroy( 3 ); // buffer, stream, infoLocFileMember
       
   542         }
       
   543 
       
   544     return found;
       
   545     }
       
   546 
       
   547 // ============================================================================
       
   548 // CWidgetUIOperationsWatcher::RunL()
       
   549 // RunL is called only for Intall/Overwrite.  It's sole resposibilty is
       
   550 // unzipping the bundle files into the widget subdir.
       
   551 //
       
   552 // @since 3.1
       
   553 // ============================================================================
       
   554 //
       
   555 void CWidgetUIOperationsWatcher::RunL()
       
   556     {
       
   557     if ( !iCancelled )
       
   558         {
       
   559         CZipFileMember* member = iMembers->NextL();
       
   560         if ( member )
       
   561             {
       
   562             CleanupStack::PushL( member );
       
   563 
       
   564             // build up the install pathname
       
   565             TPtrC zipedFileName( *member->Name() );
       
   566             TFileName zipedFileNameAndPath;
       
   567             const TDesC& base = *(iPropertyValues[EBasePath]);
       
   568             if ( KMaxFileName < (base.Length() + zipedFileName.Length()) )
       
   569                 {
       
   570                 User::Leave( KErrCorrupt );
       
   571                 }
       
   572             zipedFileNameAndPath.Copy( base );
       
   573             zipedFileNameAndPath.Append( zipedFileName );
       
   574 
       
   575             // index is supposed to separate the path from the
       
   576             // basename, unless it is just a directory
       
   577             TInt index = zipedFileNameAndPath.LocateReverse( KPathDelimiter );
       
   578             TPtrC path = zipedFileNameAndPath.Left( index + 1 /* slash */ );
       
   579 
       
   580             // make the directory, it's dumb and will try to create
       
   581             // directories that it has already created
       
   582             TInt e = iRfs.MkDirAll( path );
       
   583             if ( (KErrNone != e)
       
   584                  && (KErrAlreadyExists != e) )
       
   585                 {
       
   586                 User::Leave( KErrCorrupt );
       
   587                 }
       
   588 
       
   589             // a member can be just a directory name but if it is a file
       
   590             // then uncompress the contents
       
   591             if ( zipedFileNameAndPath[zipedFileNameAndPath.Length()-1]
       
   592                  != KPathDelimiter )  // skip directory paths
       
   593                 {
       
   594                 // uncompress the compressed file into a buffer
       
   595                 RZipFileMemberReaderStream* stream;
       
   596                 iZipFile->GetInputStreamL( member, stream );
       
   597                 CleanupStack::PushL( stream );
       
   598                 TUint32 fileSize = member->UncompressedSize();
       
   599                 if ( KMaxDescLength < fileSize )
       
   600                     {
       
   601                     User::Leave( KErrCorrupt );
       
   602                     }
       
   603                 HBufC8* buffer = HBufC8::NewLC( member->UncompressedSize() );
       
   604                 TPtr8 bufferPtr( buffer->Des() );
       
   605                 User::LeaveIfError(
       
   606                     stream->Read( bufferPtr, member->UncompressedSize() ) );
       
   607 
       
   608                 // write the buffer into a file
       
   609                 RFile file;
       
   610                 CleanupClosePushL( file );
       
   611                 User::LeaveIfError(
       
   612                     file.Create( iRfs, zipedFileNameAndPath, EFileWrite ) );
       
   613                 if ( fileSize > 0 )
       
   614                     {
       
   615                     User::LeaveIfError( file.Write( *buffer ) );
       
   616                     }
       
   617                 CleanupStack::PopAndDestroy( 3 ); // file, buffer, stream
       
   618                 }
       
   619 
       
   620             // more progress!!!
       
   621             if ( member->UncompressedSize() )
       
   622                 {
       
   623                 iUIHandler->UpdateProgressDialogL( member->UncompressedSize() );
       
   624                 }
       
   625 
       
   626             // if this is the icon file, then start icon processing
       
   627             if ( EFalse == iIconSearchFinished )
       
   628                 {
       
   629                 const TDesC& icon = *(iPropertyValues[EIconPath]);
       
   630                 if ( 0 == icon.CompareF( zipedFileName ) )
       
   631                     {
       
   632                     iIconSearchFinished = ETrue;
       
   633                     const TPtrC& path =
       
   634                         zipedFileNameAndPath.Left(index + 1 /* slash */ );
       
   635                     *(iPropertyValues[EIconPath]) = path;
       
   636                     TUid uid = TUid::Uid( *(iPropertyValues[EUid]) );
       
   637                     TRAPD( error, ConvertIconL( uid, path ) );
       
   638                     if ( KErrNone != error )
       
   639                         {
       
   640                         // forget the provided icon and proceed
       
   641                         iPropertyValues[EIconPath]->Reset();
       
   642                         }
       
   643                     }
       
   644                 }
       
   645 
       
   646             CleanupStack::PopAndDestroy(); // member
       
   647 
       
   648             // done with that file from the zip, go to next
       
   649             TRequestStatus* stat = &iStatus;
       
   650             User::RequestComplete( stat, KErrNone );
       
   651             SetActive();
       
   652             }
       
   653         else // done with zip archive
       
   654             {
       
   655             iUIHandler->CloseProgressDialogL();
       
   656             // and reveal finalize dialog underneath
       
   657 
       
   658             // finished unzip
       
   659             iUnzipping = EFalse;
       
   660 
       
   661             if ( !iProcessingIcon )
       
   662                 {
       
   663                 FinishInstallL();
       
   664                 }
       
   665             // if we are processing icons, then we wait for icon
       
   666             // processing to complete
       
   667 
       
   668             // don't call RequestComplete on installer status (the
       
   669             // higher level caller's status) here because we are not
       
   670             // done
       
   671             }
       
   672         }
       
   673     else // user cancel (not DoCancel)
       
   674         {
       
   675         iUIHandler->CloseProgressDialogL();
       
   676         iUIHandler->CloseFinalizeDialogL();
       
   677         iUIHandler->DisplayCancelL();
       
   678 
       
   679         // stop icon conversion (if there is a converter)
       
   680         delete iIconConverter;
       
   681         iIconConverter = NULL;
       
   682         iProcessingIcon = EFalse;
       
   683         iIconError = KErrNone;
       
   684 
       
   685         iUnzipping = EFalse;
       
   686 
       
   687         FinishInstallL();
       
   688         }
       
   689     }
       
   690 
       
   691 // ============================================================================
       
   692 // CWidgetUIOperationsWatcher::NotifyCompletionL()
       
   693 // Icon conversion calls this when it is complete.
       
   694 //
       
   695 // @since 3.1
       
   696 // ============================================================================
       
   697 //
       
   698 void CWidgetUIOperationsWatcher::NotifyCompletionL( TInt aErr )
       
   699     {
       
   700     iProcessingIcon = EFalse;
       
   701     iIconError = aErr;
       
   702 
       
   703     if ( KErrNone != iIconError )
       
   704         {
       
   705         iPropertyValues[EIconPath]->Reset();
       
   706         }
       
   707 
       
   708     // don't really need iCancelled in test as that combination
       
   709     // shouldn't be possible
       
   710     if ( !(iUnzipping || iCancelled) )
       
   711         {
       
   712         // NotifyCompletionL shouldn't ever leave since the caller
       
   713         // is IconConverter and that is just a utility module.
       
   714         TRAP_IGNORE( FinishInstallL() );
       
   715         }
       
   716     }
       
   717 
       
   718 // ============================================================================
       
   719 // CWidgetUIOperationsWatcher::FinishInstallL()
       
   720 //
       
   721 // @since 3.1
       
   722 // ============================================================================
       
   723 //
       
   724 void CWidgetUIOperationsWatcher::FinishInstallL()
       
   725     {
       
   726     if ( !iCancelled )
       
   727         {
       
   728         if ( iOverwriting )
       
   729             {
       
   730             TUid uid = TUid::Uid( *(iPropertyValues[EUid]) );
       
   731             iRegistry.DeRegisterWidgetL( uid );
       
   732             iAppManager->DeregisterWidgetL( uid );
       
   733             }
       
   734 
       
   735         // TODO if registration steps fail does it leave inconsistent state???
       
   736 
       
   737         iRegistry.RegisterWidgetL( iPropertyValues );
       
   738 
       
   739         iAppManager->RegisterWidgetL( *(iPropertyValues[EMainHTML]),
       
   740                                       *(iPropertyValues[EBundleDisplayName]),
       
   741                                       *(iPropertyValues[EIconPath]),
       
   742                                       *(iPropertyValues[EDriveName]),
       
   743                                       TUid::Uid( *(iPropertyValues[EUid]) ) );
       
   744 
       
   745         if ( iOverwriting )
       
   746             {
       
   747             // delete backup
       
   748             (void)iFileMgr->RmDir( iBackupDir );
       
   749             }
       
   750 
       
   751         iUIHandler->CloseFinalizeDialogL();
       
   752         iUIHandler->DisplayCompleteL();
       
   753 
       
   754         HandleLogsL(*(iPropertyValues[EBundleDisplayName]), TUid::Uid( *(iPropertyValues[EUid]) ), *(iPropertyValues[ENokiaWidget]), SwiUI::ELogTaskActionInstall);
       
   755         }
       
   756     else // cancelled
       
   757         {
       
   758         // delete what was being installed, and restore previous
       
   759         (void)iFileMgr->RmDir( *(iPropertyValues[EBasePath]) );
       
   760 
       
   761         if ( iOverwriting )
       
   762             {
       
   763             RestoreL();
       
   764             }
       
   765         }
       
   766 
       
   767     User::RequestComplete( iRequestStatus, KErrNone );
       
   768     iRequestStatus = NULL;
       
   769 
       
   770     iUnzipping = EFalse;
       
   771     iOverwriting = EFalse;
       
   772     iProcessingIcon = EFalse;
       
   773     iIconError = KErrNone;
       
   774     iCancelled = EFalse;
       
   775     }
       
   776 
       
   777 // ============================================================================
       
   778 // CWidgetUIOperationsWatcher::UserCancelL()
       
   779 // If user selects cancel softkey on progress dialog only.
       
   780 //
       
   781 // @since 3.1
       
   782 // ============================================================================
       
   783 //
       
   784 void CWidgetUIOperationsWatcher::UserCancelL( TBool /*aCancelImmediately*/ )
       
   785     {
       
   786     // It is only possible to get here while we have the progress
       
   787     // dialog up during unzipping (iUnzipping is set).  When unzipping
       
   788     // finishes but icon processing is not finished, we display a
       
   789     // finalize dialog without a cancel option.
       
   790 
       
   791     iCancelled = ETrue;
       
   792 
       
   793     // don't do anything other than set the flag as it will be tested
       
   794     // while processing
       
   795     }
       
   796 
       
   797 // ============================================================================
       
   798 // CWidgetUIOperationsWatcher::DoCancel()
       
   799 // This should not be called directly.  This function is called by
       
   800 // CActive when Cancel() is called on this object IF there is a
       
   801 // request outstanding.  So indirectly it handles canceling the
       
   802 // install operation.  Icon converter doesn't ever directly cause a
       
   803 // Cancel() even when it errors out because it is a service provider
       
   804 // to this object.  If this method is called then RunL is not called
       
   805 // (they are mutually exclusive).
       
   806 //
       
   807 // @since 3.1
       
   808 // ============================================================================
       
   809 //
       
   810 void CWidgetUIOperationsWatcher::DoCancel()
       
   811     {
       
   812     // can't cancel uninstall because that is synchronous and runs in
       
   813     // one step and this is only called by CActive if there is an
       
   814     // outstanding request, that means we are in the prcess of
       
   815     // unzipping the archive (but not in RunL presently), also note
       
   816     // that this is not a user cancel (see separate function for that)
       
   817 
       
   818     iCancelled = ETrue;
       
   819 
       
   820     TRAP_IGNORE(
       
   821         {
       
   822         iUIHandler->CloseProgressDialogL();
       
   823         iUIHandler->CloseFinalizeDialogL();
       
   824         iUIHandler->DisplayCancelL();
       
   825 
       
   826         // stop icon conversion (if there is a converter)
       
   827         delete iIconConverter;
       
   828         iIconConverter = NULL;
       
   829         iProcessingIcon = EFalse;
       
   830         iIconError = KErrNone;
       
   831 
       
   832         iUnzipping = EFalse;
       
   833 
       
   834         FinishInstallL();
       
   835         }
       
   836         );
       
   837     }
       
   838 
       
   839 // ============================================================================
       
   840 // CWidgetUIOperationsWatcher::RunError()
       
   841 // This should not be called directly.  It is called by CActive when
       
   842 // RunL leaves.  RunL is only for installing so this handles leaving
       
   843 // errors during installing widget.
       
   844 //
       
   845 // @since 3.1
       
   846 // ============================================================================
       
   847 //
       
   848 TInt CWidgetUIOperationsWatcher::RunError( TInt aError )
       
   849     {
       
   850     iCancelled = ETrue;
       
   851     iUnzipping = EFalse;
       
   852 
       
   853     TRAP_IGNORE(
       
   854         {
       
   855         iUIHandler->CloseProgressDialogL();
       
   856         iUIHandler->CloseFinalizeDialogL();
       
   857         iUIHandler->DisplayErrorL( aError );
       
   858 
       
   859         // stop icon conversion (if there is a converter)
       
   860         delete iIconConverter;
       
   861         iIconConverter = NULL;
       
   862         iProcessingIcon = EFalse;
       
   863         iIconError = KErrNone;
       
   864 
       
   865         FinishInstallL();
       
   866         }
       
   867         );
       
   868 
       
   869     return KErrNone; // indicates error was handled
       
   870     }
       
   871 
       
   872 // ============================================================================
       
   873 // CWidgetUIOperationsWatcher::SilentUninstallL()
       
   874 // Handle silent uninstall request.
       
   875 //
       
   876 // @since 3.1
       
   877 // ============================================================================
       
   878 //
       
   879 void CWidgetUIOperationsWatcher::SilentUninstallL(
       
   880     const TUid& aUid,
       
   881     TRequestStatus& aRequestStatus )
       
   882     {
       
   883     iSilent = ETrue;
       
   884     UninstallL( aUid, aRequestStatus );
       
   885     }
       
   886 
       
   887 // ============================================================================
       
   888 // CWidgetUIOperationsWatcher::UninstallL()
       
   889 // Handle uninstall request.
       
   890 //
       
   891 // @since 3.1
       
   892 // ============================================================================
       
   893 //
       
   894 void CWidgetUIOperationsWatcher::UninstallL(
       
   895     const TUid& aUid,
       
   896     TRequestStatus& aRequestStatus )
       
   897     {
       
   898     // initialize state
       
   899     iCancelled = EFalse;
       
   900     iUnzipping = EFalse;
       
   901     iOverwriting = EFalse;
       
   902     iProcessingIcon = EFalse;
       
   903     iIconError = KErrNone;
       
   904 
       
   905     // outside trap because without a UI we can't display an error message
       
   906     iUIHandler =
       
   907         CWidgetUIHandler::NewL( CWidgetUIHandler::EModeUninstall, this );
       
   908 
       
   909     // save client status to use in finish uninstall
       
   910     iRequestStatus = &aRequestStatus;
       
   911 
       
   912     // TODO currently don't uninstall if running but in future should
       
   913     // stop widget and then uninstall
       
   914     if ( iRegistry.IsWidgetRunning( aUid ) )
       
   915         {
       
   916         FinishUninstallL( KErrInUse );
       
   917         return;
       
   918         }
       
   919 
       
   920     TBuf<KWidgetRegistryVal> bundleName;
       
   921     iRegistry.GetWidgetBundleName( aUid, bundleName );
       
   922 
       
   923     if( bundleName.Length() <= 0 )
       
   924         {
       
   925         FinishUninstallL( KErrCorrupt );
       
   926         return;
       
   927         }
       
   928 
       
   929     // prompt user to uninstall
       
   930     if( iUIHandler->DisplayUninstallL( bundleName ) )
       
   931         {
       
   932         iUIHandler->DisplayUninstallInProgressL();
       
   933         TBuf<KWidgetRegistryVal> widgetPath;
       
   934         iRegistry.GetWidgetPath( aUid, widgetPath );
       
   935         TBool aVendor = *(iRegistry.GetWidgetPropertyValueL(aUid, ENokiaWidget));
       
   936         
       
   937 
       
   938         // TODO if any of next steps leave does state become inconsistent?
       
   939 
       
   940         // remove the dir for the widget
       
   941         // TODO why this validation?
       
   942         if ( widgetPath.Length() > 0 )
       
   943             {
       
   944             iFileMgr->RmDir( widgetPath );
       
   945             //Widget should delete any cookie it created
       
   946             HBufC* fileName = HBufC::NewLC(KMaxFileName);            
       
   947             TPtr ptr(fileName->Des());
       
   948             TBuf<8> buf1; 
       
   949             ptr = KCookieFile;
       
   950             TInt pos = ptr.LocateReverse('.');            
       
   951             buf1.AppendNum(aUid.iUid,EHex);
       
   952             ptr.Insert(pos,_L("_"));
       
   953             ptr.Insert(pos+1,buf1);
       
   954             iRfs.Delete(ptr);
       
   955             CleanupStack::PopAndDestroy(fileName);
       
   956             }
       
   957 
       
   958         iRegistry.DeRegisterWidgetL( aUid );
       
   959         iAppManager->DeregisterWidgetL( aUid );
       
   960         TInt err = KErrNone;
       
   961         TRAP(err, FinishUninstallL( KErrNone ));
       
   962         if(err == KErrNone)
       
   963            {
       
   964            HandleLogsL(bundleName, aUid, aVendor, SwiUI::ELogTaskActionUninstall);
       
   965            }
       
   966         }
       
   967     else
       
   968         {
       
   969         iUIHandler->DisplayCancelL();
       
   970 
       
   971         // must return cancel because upper-levels will take uninstall
       
   972         // actions (remove widget from applications list) if we return KErrNone
       
   973         User::RequestComplete( iRequestStatus, KErrCancel );
       
   974         return;
       
   975         }
       
   976     }
       
   977 
       
   978 // ============================================================================
       
   979 // CWidgetUIOperationsWatcher::FinishUninstallL()
       
   980 //
       
   981 // @since 3.1
       
   982 // ============================================================================
       
   983 //
       
   984 void CWidgetUIOperationsWatcher::FinishUninstallL( TInt aErr )
       
   985     {
       
   986     iUIHandler->CloseUninstallInProgressDialogL();
       
   987     if ( aErr )
       
   988         {
       
   989         iUIHandler->DisplayErrorL( aErr );
       
   990         User::Leave( aErr );
       
   991         }
       
   992     iUIHandler->DisplayCompleteL();
       
   993     User::RequestComplete( iRequestStatus, KErrNone );
       
   994     iRequestStatus = NULL;
       
   995     }
       
   996 
       
   997 // ============================================================================
       
   998 // CWidgetUIOperationsWatcher::IsShowingDialog()
       
   999 //
       
  1000 // @since 3.1
       
  1001 // ============================================================================
       
  1002 //
       
  1003 TBool CWidgetUIOperationsWatcher::IsShowingDialog()
       
  1004     {
       
  1005     return ETrue;
       
  1006     }
       
  1007 
       
  1008 // ============================================================================
       
  1009 // CWidgetUIOperationsWatcher::CancelEngine()
       
  1010 //
       
  1011 // @since 3.1
       
  1012 // ============================================================================
       
  1013 //
       
  1014 void CWidgetUIOperationsWatcher::CancelEngine()
       
  1015     {
       
  1016     // TODO ???
       
  1017     }
       
  1018 
       
  1019 // ============================================================================
       
  1020 // CWidgetUIOperationsWatcher::ForceCancel()
       
  1021 //
       
  1022 // @since 3.1
       
  1023 // ============================================================================
       
  1024 //
       
  1025 void CWidgetUIOperationsWatcher::ForceCancel()
       
  1026     {
       
  1027     // TODO ???
       
  1028     }
       
  1029 
       
  1030 // ============================================================================
       
  1031 // CWidgetUIOperationsWatcher::StartedCancellingL()
       
  1032 //
       
  1033 // @since 3.1
       
  1034 // ============================================================================
       
  1035 //
       
  1036 void CWidgetUIOperationsWatcher::StartedCancellingL()
       
  1037     {
       
  1038     // TODO ???
       
  1039     }
       
  1040 
       
  1041 // ============================================================================
       
  1042 // CWidgetUIOperationsWatcher::SelectMemoryL()
       
  1043 //
       
  1044 // @since 3.1
       
  1045 // ============================================================================
       
  1046 //
       
  1047 TBool CWidgetUIOperationsWatcher::SelectMemoryL()
       
  1048     {
       
  1049     TDriveUnit selectedDrive;
       
  1050     TBool isSufficient = EFalse;
       
  1051 
       
  1052     if ( !iUIHandler->SelectDriveL( iRfs,
       
  1053                                     selectedDrive, isSufficient,
       
  1054                                     *(iPropertyValues[EFileSize] )) )
       
  1055         {
       
  1056         UserCancelL();
       
  1057         return EFalse;
       
  1058         }
       
  1059     else if ( !isSufficient )
       
  1060         {
       
  1061         User::Leave( KErrNoMemory );
       
  1062         }
       
  1063 
       
  1064     UpdateWidgetBasePathL( selectedDrive );
       
  1065     *(iPropertyValues[EDriveName]) = selectedDrive.Name();
       
  1066 
       
  1067     return ETrue;
       
  1068     }
       
  1069 
       
  1070 // ============================================================================
       
  1071 // CWidgetUIOperationsWatcher::UpdateWidgetBasePathL()
       
  1072 //
       
  1073 // @since 3.1
       
  1074 // ============================================================================
       
  1075 //
       
  1076 void CWidgetUIOperationsWatcher::UpdateWidgetBasePathL( TDriveUnit& aDrive )
       
  1077     {
       
  1078     const TDesC& bundleId = *(iPropertyValues[EBundleIdentifier]);
       
  1079     HBufC* basePath = HBufC::NewL(
       
  1080         aDrive.Name().Length() + KWidgetAppDir().Length()
       
  1081         + bundleId.Length() + 1 /* slash */ );
       
  1082     basePath->Des().Append( aDrive.Name() );
       
  1083     basePath->Des().Append( KWidgetAppDir );
       
  1084     basePath->Des().Append( *(iPropertyValues[EBundleIdentifier]) );
       
  1085     basePath->Des().Append( KPathDelimiter );
       
  1086 
       
  1087     *(iPropertyValues[EBasePath]) = *basePath;
       
  1088     delete basePath;
       
  1089     }
       
  1090 
       
  1091 
       
  1092 // ============================================================================
       
  1093 // CWidgetUIOperationsWatcher::ConvertIconL()
       
  1094 // Convert icon.png into mbm format for widget
       
  1095 //
       
  1096 // @since 3.1
       
  1097 // ============================================================================
       
  1098 //
       
  1099 void CWidgetUIOperationsWatcher::ConvertIconL(
       
  1100     TUid& aUid,
       
  1101     const TDesC& aIconPath )
       
  1102     {
       
  1103     delete iIconConverter;
       
  1104     iIconConverter = NULL;
       
  1105 
       
  1106     iIconConverter = CIconConverter::NewL( this, iRfs );
       
  1107 
       
  1108     TFileName pngIcon;
       
  1109     pngIcon.Copy( aIconPath );
       
  1110 
       
  1111     if ( pngIcon.Length() )
       
  1112         {
       
  1113         pngIcon.Append( KIconFile );
       
  1114         TFileName mbmIcon;
       
  1115         mbmIcon.Copy( aIconPath );
       
  1116         mbmIcon.Append( aUid.Name() );
       
  1117         mbmIcon.Append( KMBMExt() );
       
  1118 
       
  1119         iIconConverter->StartToDecodeL( pngIcon, mbmIcon );
       
  1120         iProcessingIcon = ETrue;
       
  1121         }
       
  1122     }
       
  1123 
       
  1124 // ============================================================================
       
  1125 // CWidgetUIOperationsWatcher::PromptUserForInstallL()
       
  1126 // Prompt to confirm install and where to install. SetActive() has not
       
  1127 // been called yet.
       
  1128 //
       
  1129 // @since 3.1
       
  1130 // ============================================================================
       
  1131 //
       
  1132 TBool CWidgetUIOperationsWatcher::PromptUserForInstallL( TBool aOverwrite )
       
  1133     {
       
  1134     TBool userAnswer;
       
  1135 
       
  1136     if ( aOverwrite )
       
  1137         {
       
  1138         userAnswer =
       
  1139             iUIHandler->DisplayOverwriteL( *(iPropertyValues[EBundleDisplayName]) );
       
  1140         }
       
  1141     else
       
  1142         {
       
  1143         userAnswer =
       
  1144             iUIHandler->DisplayInstallL( *(iPropertyValues[EBundleDisplayName]) );
       
  1145         }
       
  1146     if ( userAnswer )
       
  1147         {
       
  1148         userAnswer = SelectMemoryL();
       
  1149         }
       
  1150     return userAnswer;
       
  1151     }
       
  1152 
       
  1153 // ============================================================================
       
  1154 // CWidgetUIOperationsWatcher::PromptUserForUntrustedWidgetL()
       
  1155 // Prompt to confirm install of untrusted widget. SetActive() has not
       
  1156 // been called yet.
       
  1157 //
       
  1158 // @since 3.1
       
  1159 // ============================================================================
       
  1160 //
       
  1161 TBool CWidgetUIOperationsWatcher::PromptUserForUntrustedWidgetL( )
       
  1162     {
       
  1163     TBool userAnswer(ETrue);
       
  1164 
       
  1165     if ( !iSilent )
       
  1166         {
       
  1167         userAnswer = iUIHandler->DisplayUntrustedSecurityDialogL();
       
  1168         }
       
  1169 
       
  1170     return userAnswer;
       
  1171     }
       
  1172 
       
  1173 // ============================================================================
       
  1174 // CWidgetUIOperationsWatcher::BackupL()
       
  1175 // When overwriting an installed widget, backup so can restore on error.
       
  1176 //
       
  1177 // @since 3.1
       
  1178 // ============================================================================
       
  1179 //
       
  1180 void CWidgetUIOperationsWatcher::BackupL()
       
  1181     {
       
  1182     // if backup leaves, there is nothing caller needs to do to clean up
       
  1183 
       
  1184     // move to backup (by renaming) the existing install dir for the widget
       
  1185 
       
  1186     // first create a "unique" backup dir on the original dir drive
       
  1187     // (same drive required since can't "rename" across drives)
       
  1188     TParse p;
       
  1189     p.Set( iOriginalDir, NULL, NULL );
       
  1190     TFileName path;
       
  1191     path.Copy( p.Drive() );
       
  1192     path.Append( KWidgetAppDir );
       
  1193     // NOT A GOOD WAY TO CREATE A UNIQUE DIRECTORY First we create a
       
  1194     // unique file and then delete it and then create a directory with
       
  1195     // same name.
       
  1196     RFile file;
       
  1197     CleanupClosePushL( file );
       
  1198     User::LeaveIfError( file.Temp( iRfs, path, iBackupDir, EFileWrite ) );
       
  1199     CleanupStack::PopAndDestroy(); // file
       
  1200     // delete the temp file and...
       
  1201     User::LeaveIfError( iFileMgr->Delete( iBackupDir ) );
       
  1202     // ...convert to dir name
       
  1203     iBackupDir.Append( KPathDelimiter );
       
  1204     // make the backup
       
  1205     User::LeaveIfError( iFileMgr->Rename( iOriginalDir, iBackupDir ) );
       
  1206     // original dir doesn't seem to be gone after rename so rmdir
       
  1207     // it...this is IMPORTANT because we want to be able to look at
       
  1208     // the list of install directories to get a list of installed
       
  1209     // widgets without checking if they are empty!
       
  1210     (void)iFileMgr->RmDir( iOriginalDir );
       
  1211     // overwriting boolean is only true when backup is successful
       
  1212     iOverwriting = ETrue;
       
  1213     }
       
  1214 
       
  1215 // ============================================================================
       
  1216 // CWidgetUIOperationsWatcher::RestoreL()
       
  1217 //
       
  1218 // @since 3.1
       
  1219 // ============================================================================
       
  1220 //
       
  1221 void CWidgetUIOperationsWatcher::RestoreL()
       
  1222     {
       
  1223     // move (by renaming) the backup copy to the install dir for the widget
       
  1224 
       
  1225     // to assure a clean destination, try deleting install dir first
       
  1226     (void)iFileMgr->RmDir( iOriginalDir );
       
  1227 
       
  1228     // TODO if this fails then do some cleanup, maybe unregister?
       
  1229     User::LeaveIfError( iFileMgr->Rename( iBackupDir, iOriginalDir ) );
       
  1230     // backup dir doesn't seem to be gone so rmdir it
       
  1231     (void)iFileMgr->RmDir( iBackupDir );
       
  1232 
       
  1233     // restore complete
       
  1234     iOverwriting = EFalse;
       
  1235     }
       
  1236 
       
  1237 
       
  1238 // ============================================================================
       
  1239 //
       
  1240 // CWidgetUIOperationsWatcher::HandleLogsL
       
  1241 //
       
  1242 // ============================================================================
       
  1243 void CWidgetUIOperationsWatcher::HandleLogsL(const TDesC& aWidgetName, const TUid &aUid, TBool aVender, SwiUI::TLogTaskAction aAction)
       
  1244     {
       
  1245     CTask* task = CTask::NewL( KLogTaskImplUid, EFalse );
       
  1246     CleanupStack::PushL(task);
       
  1247 
       
  1248     TLogTaskParam params;
       
  1249     params.iName.Copy(aWidgetName);
       
  1250     params.iUid = aUid;
       
  1251     params.iAction = aAction;
       
  1252     params.iVendor.Copy((aVender ? _L("Nokia") : _L("Non-Nokia")));
       
  1253     
       
  1254     TTime time;
       
  1255     time.UniversalTime();
       
  1256     params.iTime = time;
       
  1257 
       
  1258     TLogTaskParamPckg pckg( params );
       
  1259     task->SetParameterL( pckg, 0 );
       
  1260     iTaskManager->AddTaskL( task );
       
  1261     iTaskManager->CommitL();
       
  1262     
       
  1263     CleanupStack::Pop(task);
       
  1264     }
       
  1265 //  End of File