|
1 /*------------------------------------------------------------------ |
|
2 - |
|
3 * Software Name : UserEmulator |
|
4 * Version : v4.2.1309 |
|
5 * |
|
6 * Copyright (c) 2009 France Telecom. All rights reserved. |
|
7 * This software is distributed under the License |
|
8 * "Eclipse Public License - v 1.0" the text of which is available |
|
9 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
10 * |
|
11 * Initial Contributors: |
|
12 * France Telecom |
|
13 * |
|
14 * Contributors: |
|
15 *------------------------------------------------------------------ |
|
16 - |
|
17 * File Name: Settings.cpp |
|
18 * |
|
19 * Created: 13/08/2009 |
|
20 * Author(s): Marcell Kiss, Reshma Sandeep Das |
|
21 * |
|
22 * Description: |
|
23 * This class is used for storing the settings information of the application |
|
24 *------------------------------------------------------------------ |
|
25 - |
|
26 * |
|
27 */ |
|
28 |
|
29 //System Includes |
|
30 #include <coemain.h> // CCoeEnv |
|
31 #include <BAUTILS.H> |
|
32 |
|
33 //User Includes |
|
34 #include "Settings.h" |
|
35 #include "UserEmulatorApplication.h" |
|
36 #include "UserEmulator.hrh" |
|
37 |
|
38 //Constants |
|
39 _LIT(KFormat,":\\"); |
|
40 _LIT(KFakeFileName,"filename.csv"); |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CSettings::CSettings |
|
44 // Constructor |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CSettings::CSettings(CApaApplication& aApp, CEikonEnv* aEikonEnv) : iApp(aApp), iEEnv(aEikonEnv) |
|
48 { |
|
49 } |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CSettings::ConstructL |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CSettings::ConstructL() |
|
55 { |
|
56 LoadL(); |
|
57 } |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CSettings::CheckDrive |
|
60 // Function to validate the correct drive |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 TInt CSettings::CheckDrive(const TDesC& aPath) |
|
64 { |
|
65 TInt err; |
|
66 TVolumeInfo volumeInfo; |
|
67 |
|
68 TInt pos = aPath.FindF(KFormat); |
|
69 if(pos == KErrNotFound) |
|
70 return KErrNotReady; |
|
71 |
|
72 TPtrC drive = aPath.Left(pos); |
|
73 if(drive.Length()!= 1) |
|
74 err = KErrNotReady; |
|
75 else |
|
76 { |
|
77 TUint driveLetter = drive.operator [](0); |
|
78 TInt driveNumber = 0; |
|
79 iEEnv->FsSession().CharToDrive((TChar)driveLetter,driveNumber); |
|
80 if(driveNumber == EDriveD) |
|
81 return KErrNotReady; |
|
82 err = iEEnv->FsSession().Volume(volumeInfo,driveNumber); |
|
83 } |
|
84 return err; |
|
85 } |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CSettings::CheckPathL |
|
88 // Function to validate the scripts or log file path |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 TBool CSettings::CheckPathL(const TDesC& aPath) |
|
92 { |
|
93 TBuf<KBuffer256> TempPath; |
|
94 TempPath.Copy(aPath); |
|
95 // Just because of IsValidName. (Without filename it fails) |
|
96 TempPath.Append(KFakeFileName); |
|
97 if(iEEnv->FsSession().IsValidName(TempPath)) |
|
98 { |
|
99 TBuf<KBuffer256> path; |
|
100 TBuf<KBuffer256> tempPath; |
|
101 TBool space=EFalse; |
|
102 TInt pos; |
|
103 _LIT(KSpace," "); |
|
104 |
|
105 // No space before backslash in path |
|
106 tempPath.Copy(aPath); |
|
107 while((pos=tempPath.LocateReverse('\\'))!=KErrNotFound) |
|
108 { |
|
109 TPtrC a = tempPath.Mid(pos-1,1); |
|
110 if(a.Compare(KSpace)==0) |
|
111 { |
|
112 space=ETrue; |
|
113 break; |
|
114 } |
|
115 tempPath.Copy(tempPath.Left(pos)); |
|
116 } |
|
117 |
|
118 if(!space) |
|
119 { |
|
120 TInt pos=aPath.LocateReverse('\\')+1; |
|
121 if(pos!=KErrNotFound) |
|
122 path.Copy(aPath.Left(pos)); |
|
123 else |
|
124 return EFalse; |
|
125 TRAPD(err,BaflUtils::EnsurePathExistsL(iEEnv->FsSession(), path)); |
|
126 if(err==KErrNone) |
|
127 return ETrue; |
|
128 } |
|
129 } |
|
130 return EFalse; |
|
131 } |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CSettings::LoadL |
|
134 // Function to Load the User Emulator settings |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CSettings::LoadL() |
|
138 { |
|
139 CDictionaryStore* iniFile = iApp.OpenIniFileLC(CCoeEnv::Static()->FsSession()); |
|
140 |
|
141 if (iniFile->IsPresentL(KUidUserEmulatorApp)) |
|
142 { |
|
143 RDictionaryReadStream readStream; |
|
144 readStream.OpenLC(*iniFile, KUidUserEmulatorApp); |
|
145 |
|
146 TInt len = static_cast<TInt> (readStream.ReadInt32L()); |
|
147 readStream.ReadL(iScriptsPath,len); |
|
148 |
|
149 TInt ScriptPath = CheckDrive(iScriptsPath); |
|
150 if(ScriptPath == KErrNotReady) |
|
151 iScriptsPath = KDefaultPath; |
|
152 |
|
153 iLogStatus = static_cast<TBool> (readStream.ReadInt8L()); |
|
154 TInt logLen = static_cast<TInt> (readStream.ReadInt32L()); |
|
155 readStream.ReadL(iLogPath,logLen); |
|
156 |
|
157 TInt err = CheckDrive(iLogPath); |
|
158 |
|
159 if(err == KErrNotReady) |
|
160 iLogPath = KDefaultLogPath; |
|
161 |
|
162 iRandomTestAppIdStatus = static_cast<TBool> (readStream.ReadInt8L()); |
|
163 TInt IDLen = static_cast<TInt> (readStream.ReadInt32L()); |
|
164 readStream.ReadL(iRandomTestAppID,IDLen); |
|
165 |
|
166 CleanupStack::PopAndDestroy(&readStream); |
|
167 } |
|
168 else |
|
169 { |
|
170 iScriptsPath = KDefaultPath; |
|
171 iLogStatus = ETrue; |
|
172 iLogPath = KDefaultLogPath; |
|
173 iRandomTestAppIdStatus = EFalse; |
|
174 } |
|
175 |
|
176 CleanupStack::PopAndDestroy(iniFile); |
|
177 } |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CSettings::StoreL |
|
180 // Function to Store the User Emulator settings |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 void CSettings::StoreL() |
|
184 { |
|
185 CDictionaryStore* iniFile = iApp.OpenIniFileLC(CCoeEnv::Static()->FsSession()); |
|
186 RDictionaryWriteStream writeStream; |
|
187 writeStream.AssignLC(*iniFile, KUidUserEmulatorApp); |
|
188 |
|
189 writeStream.WriteInt32L(iScriptsPath.Length()); |
|
190 writeStream.WriteL(iScriptsPath); |
|
191 writeStream.WriteInt8L(iLogStatus); |
|
192 writeStream.WriteInt32L(iLogPath.Length()); |
|
193 writeStream.WriteL(iLogPath); |
|
194 writeStream.WriteInt8L(iRandomTestAppIdStatus); |
|
195 writeStream.WriteInt32L(iRandomTestAppID.Length()); |
|
196 writeStream.WriteL(iRandomTestAppID); |
|
197 |
|
198 writeStream.CommitL(); |
|
199 iniFile->CommitL(); |
|
200 |
|
201 CleanupStack::PopAndDestroy(2, iniFile); |
|
202 } |