|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #pragma warning (disable: 4786) |
|
20 |
|
21 #include <iostream> |
|
22 #include <sstream> |
|
23 |
|
24 |
|
25 #include "uninstaller.h" |
|
26 #include "errors.h" |
|
27 |
|
28 |
|
29 Uninstaller::Uninstaller( SisRegistry& aReg, const CParameterList& aParamList ) |
|
30 : iRegistry(aReg), iParamList(aParamList) |
|
31 { |
|
32 } |
|
33 |
|
34 |
|
35 void Uninstaller::Uninstall() |
|
36 { |
|
37 const CParameterList::OptionList& uids = iParamList.PkgUidsToRemove(); |
|
38 |
|
39 // Get the package UID |
|
40 for (CParameterList::OptionList::const_iterator curr = uids.begin(); curr != uids.end(); ++curr) |
|
41 { |
|
42 TUint32 uid; |
|
43 |
|
44 bool convertedOk = false; |
|
45 |
|
46 std::wstring temp= *curr; |
|
47 std::wistringstream stringStream( temp ); |
|
48 |
|
49 // Check for hex prefix |
|
50 if ( (temp.substr( 0, 2 ) == (L"0x") || temp.substr( 0, 2 ) == (L"0X")) && |
|
51 curr->length() > 2 ) |
|
52 { |
|
53 // The UID is in Hex, skip "0x" prefix |
|
54 stringStream.ignore( 2 ); |
|
55 stringStream >> std::hex >> uid; |
|
56 convertedOk = ( !stringStream.fail() ); |
|
57 } |
|
58 else |
|
59 { |
|
60 // The UID is in Decimal |
|
61 stringStream >> uid; |
|
62 convertedOk = ( !stringStream.fail() ); |
|
63 } |
|
64 |
|
65 if (convertedOk) |
|
66 { |
|
67 RemovePkg(uid); |
|
68 } |
|
69 else |
|
70 { |
|
71 std::wostringstream os; |
|
72 |
|
73 os << L" Invalid Package UID " << std::hex << uid; |
|
74 std::wstring msg = os.str(); |
|
75 throw InterpretSisError( msg, CMDLINE_ERROR ); |
|
76 } |
|
77 } |
|
78 |
|
79 // Regenerate SIS stub registries |
|
80 iRegistry.GenerateStubRegistry(); |
|
81 } |
|
82 |
|
83 |
|
84 void Uninstaller::RemovePkg(const TUint32 aUid) |
|
85 { |
|
86 if (iRegistry.IsInstalled(aUid)) |
|
87 { |
|
88 LINFO(L"Removing UID 0x" << std::hex << aUid); |
|
89 iRegistry.RemovePkg(aUid); |
|
90 } |
|
91 else |
|
92 { |
|
93 // No SisRegistry file found!! |
|
94 std::wostringstream os; |
|
95 |
|
96 os << L" SIS Registry entry for 0x" << std::hex << aUid << L" Not found"; |
|
97 std::wstring msg = os.str(); |
|
98 throw InterpretSisError( msg, PACKAGE_NOT_FOUND ); |
|
99 } |
|
100 } |