Guest User

Untitled

a guest
Apr 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. /*
  2. * ============================================================================
  3. * Name : CAppUidViewerEngine from AppUidViewerEngine.cpp
  4. * Part of : Application Uid viewer
  5. * Created : 09/26/2005 by Forum Nokia
  6. * Version : 1.0
  7. * Copyright: Nokia Corporation
  8. * ============================================================================
  9. */
  10.  
  11. // INCLUDE FILES
  12. #include "AppUidViewerEngine.h"
  13.  
  14.  
  15. // CONSTANTS
  16. _LIT(KFileName, "c:\\Nokia\\applications.txt");
  17. _LIT(KFileName3rd, "c:\\Data\\Nokia\\applications.txt");
  18. _LIT(KFileDir3rd, "c:\\Data\\Nokia\\");
  19. const TInt KMaxSize = 512;
  20. const TInt KUidWidth = 8;
  21.  
  22. // ================= MEMBER FUNCTIONS =======================
  23.  
  24. // Constructor
  25. CAppUidViewerEngine::CAppUidViewerEngine(MAppUidObserver& aObserver)
  26. : iObserver(aObserver)
  27. {
  28.  
  29. }
  30.  
  31. // Destructor
  32. CAppUidViewerEngine::~CAppUidViewerEngine()
  33. {
  34. iLsSession.Close();
  35. iFs.Close();
  36. iApps.Close();
  37. }
  38.  
  39. // ----------------------------------------------------
  40. // CAppUidViewerEngine::NewL()
  41. // Two-phased constructor.
  42. // ----------------------------------------------------
  43. //
  44. CAppUidViewerEngine* CAppUidViewerEngine::NewL(MAppUidObserver& aObserver)
  45. {
  46. CAppUidViewerEngine* self = new (ELeave) CAppUidViewerEngine(aObserver);
  47. CleanupStack::PushL(self);
  48. self->ConstructL();
  49. CleanupStack::Pop(self);
  50. return self;
  51. }
  52.  
  53. // ----------------------------------------------------
  54. // CAppUidViewerEngine::ConstructL()
  55. // Symbian OS default constructor can leave.
  56. // ----------------------------------------------------
  57. //
  58. void CAppUidViewerEngine::ConstructL()
  59. {
  60. User::LeaveIfError(iFs.Connect());
  61. User::LeaveIfError(iLsSession.Connect());
  62. }
  63.  
  64. // ----------------------------------------------------
  65. // CAppUidViewerEngine::AppsToFileL()
  66. // Writes applications and their uids in to a text file.
  67. // ----------------------------------------------------
  68. //
  69. void CAppUidViewerEngine::AppsToFileL()
  70. {
  71. RFile file;
  72. CleanupClosePushL(file);
  73.  
  74. #ifdef __SERIES60_3X__ //////////// 3rd Ed
  75.  
  76. // C:\Nokia Folder does not exist in S60 3.x,
  77. // PC Suite does not show other than C:\Data folders in S60 3.x devices
  78. iFs.MkDir( KFileDir3rd );
  79. User::LeaveIfError( file.Replace(iFs, KFileName3rd, EFileWrite | EFileStreamText) );
  80.  
  81. #else
  82.  
  83. User::LeaveIfError(file.Replace(iFs, KFileName, EFileWrite | EFileStreamText));
  84.  
  85. #endif
  86.  
  87.  
  88. TBuf<KMaxSize> buf;
  89. TBuf8<KMaxSize> fileBuf;
  90.  
  91.  
  92. // Get info on all apps, then iterate through each app
  93. // and write its info (caption, name, uid) to file
  94. User::LeaveIfError(iLsSession.GetAllApps());
  95.  
  96. TApaAppInfo* appInfo = new (ELeave) TApaAppInfo;
  97. CleanupStack::PushL( appInfo );
  98.  
  99. while(iLsSession.GetNextApp(*appInfo) == KErrNone)
  100. {
  101. buf.Zero();
  102. buf.AppendNumFixedWidth(appInfo->iUid.iUid, EHex, KUidWidth);
  103. buf.Append(_L("\t"));
  104. buf.Append(appInfo->iCaption);
  105. buf.Append(_L("\t"));
  106. buf.Append(appInfo->iFullName);
  107. buf.Append(_L("\r\n"));
  108. fileBuf.Copy(buf);
  109. file.Write(fileBuf);
  110. }
  111. CleanupStack::PopAndDestroy( appInfo );
  112. CleanupStack::PopAndDestroy( &file );
  113.  
  114. iObserver.DoneL();
  115.  
  116. }
  117.  
  118. // ----------------------------------------------------
  119. // CAppUidViewerEngine::AppsToUiL()
  120. // Collects all applications and their uids and passes
  121. // this list to an observer.
  122. // ----------------------------------------------------
  123. //
  124. void CAppUidViewerEngine::AppsToUiL()
  125. {
  126. TApaAppInfo apaAppInfo;
  127. TAppInfo appInfo;
  128. iApps.Reset();
  129.  
  130. // Get info on all apps, then iterate through each app
  131. User::LeaveIfError(iLsSession.GetAllApps());
  132. while(iLsSession.GetNextApp(apaAppInfo) == KErrNone)
  133. {
  134. appInfo.iAppCaption = apaAppInfo.iCaption;
  135. appInfo.iAppUid = apaAppInfo.iUid.iUid;
  136. User::LeaveIfError(iApps.Append(appInfo));
  137. }
  138.  
  139. iObserver.AppsFoundL(iApps);
  140. }
  141.  
  142. // End of file
Add Comment
Please, Sign In to add comment