|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // file sysutilfunctions.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32property.h> |
|
19 #include <f32file.h> |
|
20 #include <bafl/sysutil.h> |
|
21 #include "sysutilconstants.h" |
|
22 #include "sysutilfunctions.h" |
|
23 #include "sysutilsetup.h" |
|
24 |
|
25 /** |
|
26 Checks if the given file exists. |
|
27 |
|
28 @param aFilename The path of the file to be checked. |
|
29 @return KErrNone The file exists. |
|
30 @return KErrNotSupported The file does not exist. |
|
31 @return ... One of the other system wide error codes. |
|
32 */ |
|
33 TInt CheckIsFileExist(const TDesC& aFilename) |
|
34 { |
|
35 RFs fs; |
|
36 TInt err; |
|
37 err = fs.Connect(); |
|
38 if (err != KErrNone) |
|
39 { |
|
40 return err; |
|
41 } |
|
42 |
|
43 RFile file; |
|
44 err = file.Open(fs, aFilename, EFileRead | EFileStreamText | EFileShareReadersOnly); |
|
45 |
|
46 file.Close(); |
|
47 fs.Close(); |
|
48 |
|
49 if (err == KErrNotFound || err == KErrPathNotFound) |
|
50 { |
|
51 err = KErrNotSupported; |
|
52 } |
|
53 |
|
54 return err; |
|
55 } |
|
56 |
|
57 /** |
|
58 Deletes all the Publish and Subscribe properties. |
|
59 |
|
60 @return KErrNone If Publish and Subscribe properties where deleted successfully. |
|
61 @return ... One of the other system wide error codes. |
|
62 */ |
|
63 TInt DeletePSProperties() |
|
64 { |
|
65 _LIT( KExeName, "Z:\\sys\\bin\\sysutilsetup.exe" ); |
|
66 const TUidType KExeUid( KNullUid, KNullUid, KSysUtilSetupUid ); |
|
67 |
|
68 RProcess setupProcess; |
|
69 TInt err = setupProcess.Create( KExeName, KDeletePropertiesFlag, KExeUid ); |
|
70 if( KErrNone != err ) |
|
71 { |
|
72 return err; |
|
73 } |
|
74 |
|
75 TRequestStatus status; |
|
76 setupProcess.Rendezvous( status ); |
|
77 if( KRequestPending != status.Int() ) |
|
78 { |
|
79 setupProcess.Kill( 0 ); // Abort startup |
|
80 } |
|
81 else |
|
82 { |
|
83 setupProcess.Resume(); // Logon OK - start the server |
|
84 } |
|
85 |
|
86 User::WaitForRequest( status ); // Wait for start or death |
|
87 |
|
88 // We can't use the 'exit reason' if the server panicked as this |
|
89 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
90 // from KErrNone |
|
91 err = setupProcess.ExitType() == EExitPanic ? KErrGeneral : status.Int(); |
|
92 setupProcess.Close(); |
|
93 return err; |
|
94 } |
|
95 |
|
96 /** |
|
97 Switches the test paths on and off. The paths as as follows: |
|
98 |
|
99 Default Paths: |
|
100 Z:\\resource\\versions\\deviceattributes.ini |
|
101 Z:\\sys\\bin\\sysutilplugin.dll |
|
102 |
|
103 Test Paths: |
|
104 <system drive>:\\versions\\deviceattributes.ini |
|
105 <system drive>:\\sys\\bin\\sysutilplugin.dll |
|
106 |
|
107 @param aTestPathOn If ETrue, test paths are turned on. If EFalse, test paths are turned off. |
|
108 @return KErrNone If the test paths were turned on/off successfully. |
|
109 @return ... One of the other system wide error codes. |
|
110 */ |
|
111 TInt SetTestPath(const TBool aTestPathOn) |
|
112 { |
|
113 _LIT_SECURITY_POLICY_C1( KSecurityPolicyNone, ECapability_None ); |
|
114 |
|
115 TInt err = RProperty::Define( KUidSystemCategory, KTestFilePathsUid.iUid, RProperty::EInt, KSecurityPolicyNone, KSecurityPolicyNone ); |
|
116 if(KErrNone != err && KErrAlreadyExists != err) |
|
117 { |
|
118 return err; |
|
119 } |
|
120 err = RProperty::Set(KUidSystemCategory, KTestFilePathsUid.iUid, aTestPathOn); |
|
121 |
|
122 return err; |
|
123 } |