|
1 /* |
|
2 * Copyright (c) 2005-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 #include "options.h" |
|
20 #include <iostream> |
|
21 #include <windows.h> |
|
22 |
|
23 void Options::DisplayError (const Exceptions& aErr) |
|
24 { |
|
25 const char* msg; |
|
26 switch (aErr) |
|
27 { |
|
28 case EUnknownOption: |
|
29 msg = "Unknown option specified"; |
|
30 DisplayUsage (); |
|
31 break; |
|
32 case EMissingRegistryEntry: |
|
33 msg = "One of the registry entry (PkgUID ,PkgName and VendorName ) not specified"; |
|
34 DisplayUsage (); |
|
35 break; |
|
36 case EMissingPkgUID: |
|
37 msg = "Package UID not specified "; |
|
38 DisplayUsage (); |
|
39 break; |
|
40 case EInvalidOption: |
|
41 msg = "Invalid option specified "; |
|
42 DisplayUsage (); |
|
43 break; |
|
44 case EInvalidPackageUID: |
|
45 msg = "Invalid Package UID"; |
|
46 break; |
|
47 case ESetEnvironmentVariable: |
|
48 msg = "Set the environment variable or \nspecify registry file path"; |
|
49 break; |
|
50 case EInvalidFile: |
|
51 msg = "Registry format not supported ."; |
|
52 break; |
|
53 default: |
|
54 msg = "Unknown error"; |
|
55 break; |
|
56 } |
|
57 |
|
58 cerr << CommandName () << ": Error : " << msg << endl; |
|
59 } |
|
60 |
|
61 |
|
62 void Options::DisplayVersion() |
|
63 { |
|
64 cout << "\nDumpSWIRegistry Utility Version " << KMajorVersion << '.' \ |
|
65 << setw(2) << KMinorVersion << setfill('0') << "\nCopyright (c) 2005-2006 Symbian Software Limited . All rights reserved.\n\n" << flush; |
|
66 } |
|
67 |
|
68 |
|
69 void Options::DisplayUsage() |
|
70 { |
|
71 cout << "Usage: DumpSWIRegistryTool [-v] [-h] [RegistryPath] [-p PackageUid] " |
|
72 "\n\t\t\t[-r PackageUid PackageName VendorName] \n\n" \ |
|
73 " -v specifies the version of the tool \n" \ |
|
74 " -h Prints the help message\n" \ |
|
75 " -p interpret package information by specifying packageuid \n\n" \ |
|
76 " -r Displays controller information about a particular package ," |
|
77 "\n\t\twhen it's registry entry(package uid,package name & vendor name" |
|
78 "\n\t\t)are specified." |
|
79 "\n\t\tThe registry entry can be chosen from the information displayed" |
|
80 "\n\t\tby -p option.\n\n" \ |
|
81 "RegistryPath swiregistry path - OPTIONAL if Environment PATH is set \n" \ |
|
82 "PackageUid UID of the package. \n" \ |
|
83 "PackageName Name of the package obtained when -p option is used \n" \ |
|
84 "VendorName Name of the vendor obtained when -p option is used \n\n" \ |
|
85 "Set the environment variable DUMPSWIREGISTRY to the sisregistry path - DEFAULT: \n" \ |
|
86 "DUMPSWIREGISTRY=\\epoc32\\<platform>\\c\\sys\\install\\sisregistry\\ \n" \ |
|
87 "All inputs must be specified in the same order as mentioned above. \n\n" << flush; |
|
88 } |
|
89 |
|
90 |
|
91 Options::Options (int argc, char** argv) |
|
92 :iVersion (false), |
|
93 iHelpFlag (false), |
|
94 iPkgUIDSpecified (false), |
|
95 iRegistryEntrySpecified (false) |
|
96 { |
|
97 int argCount = argc; |
|
98 const char* buffer = getenv("DUMPSWIREGISTRY"); |
|
99 if(buffer) |
|
100 { |
|
101 string regPath(buffer); |
|
102 iRegistryFilePath = regPath; |
|
103 } |
|
104 |
|
105 ++argv; |
|
106 //check whether the first argument is a registry path |
|
107 if((**argv != '-') && (**argv != '/')) |
|
108 { |
|
109 iRegistryFilePath = *argv; |
|
110 ++argv; |
|
111 --argc; |
|
112 } |
|
113 |
|
114 if(*argv != NULL) |
|
115 { |
|
116 if ((**argv != '-') && (**argv != '/')) |
|
117 { |
|
118 throw EInvalidOption; |
|
119 } |
|
120 |
|
121 switch ((*argv)[1]) |
|
122 { |
|
123 case 'h': |
|
124 case 'H': |
|
125 case '?': |
|
126 { |
|
127 iHelpFlag = true; |
|
128 DisplayUsage(); |
|
129 break; |
|
130 } |
|
131 case 'v': |
|
132 case 'V': |
|
133 { |
|
134 iVersion = true; |
|
135 DisplayVersion(); |
|
136 break; |
|
137 } |
|
138 |
|
139 case 'p': |
|
140 case 'P': |
|
141 { |
|
142 iPkgUIDSpecified = true; |
|
143 if(iRegistryFilePath.length() == 0) |
|
144 { |
|
145 throw ESetEnvironmentVariable; |
|
146 } |
|
147 |
|
148 if(argc !=3) |
|
149 { |
|
150 throw EInvalidOption; |
|
151 } |
|
152 |
|
153 iPkgUID = *++argv; |
|
154 break; |
|
155 } |
|
156 |
|
157 case 'r': |
|
158 case 'R': |
|
159 { |
|
160 iRegistryEntrySpecified = true; |
|
161 if(iRegistryFilePath.length() == 0) |
|
162 { |
|
163 throw ESetEnvironmentVariable; |
|
164 } |
|
165 |
|
166 if(argc != 5) |
|
167 { |
|
168 throw EInvalidOption; |
|
169 } |
|
170 |
|
171 iPkgUID = *++argv; |
|
172 iPkgName = *++argv; |
|
173 iVendorName = *++argv; |
|
174 break; |
|
175 } |
|
176 |
|
177 default: |
|
178 { |
|
179 throw EInvalidOption; |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 else |
|
185 { |
|
186 throw EInvalidOption; |
|
187 } |
|
188 |
|
189 CheckCmdLineExceptions(); |
|
190 } |
|
191 |
|
192 |
|
193 void Options::CheckCmdLineExceptions() |
|
194 { |
|
195 //if -p is specified |
|
196 if (iPkgUIDSpecified) |
|
197 { |
|
198 if(iPkgUID.length()==0) |
|
199 { |
|
200 throw EMissingPkgUID; |
|
201 } |
|
202 //check whether a valid pkg uid is specified |
|
203 else if((iPkgUID.length()<8) || (iPkgUID.length()>8)) |
|
204 { |
|
205 throw EInvalidPackageUID; |
|
206 } |
|
207 else |
|
208 { |
|
209 //handles both ways of specifying registrypath(for instance:\c\sys\install\sisregistry or \c\sys\install\sisregistry\) |
|
210 int pos = iRegistryFilePath.find_last_of("\\" ,iRegistryFilePath.length()); |
|
211 if(pos != (iRegistryFilePath.length()-1)) |
|
212 { |
|
213 iRegistryFilePath.append("\\"); |
|
214 } |
|
215 iRegistryFilePath.append(iPkgUID); |
|
216 iPkgUID = iRegistryFilePath; |
|
217 } |
|
218 } |
|
219 |
|
220 //if -r is specified and any one of the entries are missing |
|
221 if(iRegistryEntrySpecified) |
|
222 { |
|
223 if(((iRegistryFilePath.length())== 0) || ((iPkgName.length())== 0) || ((iVendorName.length())== 0)) |
|
224 { |
|
225 throw EMissingRegistryEntry; |
|
226 } |
|
227 else |
|
228 { |
|
229 int pos = iRegistryFilePath.find_last_of("\\" , iRegistryFilePath.length()); |
|
230 if(pos != (iRegistryFilePath.length()-1)) |
|
231 { |
|
232 iRegistryFilePath.append("\\"); |
|
233 } |
|
234 iRegistryFilePath.append(iPkgUID); |
|
235 } |
|
236 } |
|
237 } |
|
238 |
|
239 Options::~Options() |
|
240 { |
|
241 } |
|
242 |