-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemhelper.cpp
310 lines (255 loc) · 8.02 KB
/
systemhelper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#include "systemhelper.h"
SystemHelper::SystemHelper()
{
}
void SystemHelper::AppInstall(QString AppPath, QString InstallPath, bool Overwrite)
{
QStringList NameFilters;
QDir AppDir(AppPath);
QFileInfoList SisFilesList;
SwiUI::RSWInstLauncher Installer;
SwiUI::TInstallOptions Options;
SwiUI::TInstallOptionsPckg OptionsPckg;
QString FileName;
int Error = 0;
NameFilters << "*.sis";
NameFilters << "*.sisx";
NameFilters << "*.jar";
SisFilesList = AppDir.entryInfoList(NameFilters,QDir::Files);
if (SisFilesList.length() > 0)
{
FileName = SisFilesList.at(0).absoluteFilePath().replace("/", "\\");
}
else
{
emit done(true);
return;
}
if (Overwrite)
{
Options.iUpgrade = SwiUI::EPolicyAllowed;
Options.iOverwrite = SwiUI::EPolicyAllowed;
Options.iUpgradeData = SwiUI::EPolicyAllowed;
}
else
{
Options.iUpgrade = SwiUI::EPolicyNotAllowed;
Options.iOverwrite = SwiUI::EPolicyNotAllowed;
Options.iUpgradeData = SwiUI::EPolicyNotAllowed;
}
Options.iOCSP = SwiUI::EPolicyAllowed;
Options.iIgnoreOCSPWarnings = SwiUI::EPolicyAllowed;
Options.iOptionalItems = SwiUI::EPolicyAllowed;
Options.iDrive = InstallPath.at(0).toAscii();
Options.iUntrusted = SwiUI::EPolicyAllowed;
Options.iCapabilities = SwiUI::EPolicyAllowed;
Options.iPackageInfo = SwiUI::EPolicyAllowed;
Options.iKillApp = SwiUI::EPolicyAllowed;
Options.iDownload = SwiUI::EPolicyAllowed;
OptionsPckg = Options;
TPtrC16 BufFileName(reinterpret_cast<const TUint16*>(FileName.utf16()));
Installer.Connect();
if (ParamsHelper::IsAutoInstall)
{
Error = Installer.SilentInstall(BufFileName, OptionsPckg);
}
else
{
Error = Installer.Install(BufFileName, OptionsPckg);
}
Installer.Close();
if (Error == 0)
{
emit done(false);
}
else
{
emit done(true);
}
}
void SystemHelper::AppUninstall(uint AppUid)
{
SwiUI::RSWInstLauncher Uninstaller;
SwiUI::TUninstallOptions Options;
SwiUI::TUninstallOptionsPckg OptionsPckg;
int Error = 0;
Options.iKillApp = SwiUI::EPolicyAllowed;
OptionsPckg = Options;
Uninstaller.Connect();
if (ParamsHelper::IsAutoInstall)
{
Error = Uninstaller.SilentUninstall(TUid::Uid(AppUid), OptionsPckg, SwiUI::KSisxMimeType());
}
else
{
Error = Uninstaller.Uninstall(TUid::Uid(AppUid), SwiUI::KSisxMimeType());
if (Error != 0)
{
Error = Uninstaller.Uninstall(TUid::Uid(AppUid), SwiUI::KSisMimeType());
if (Error != 0)
{
Error = Uninstaller.Uninstall(TUid::Uid(AppUid), SwiUI::KJarxMIMEType);
}
}
}
Uninstaller.Close();
if (Error == 0)
{
emit done(false);
}
else
{
emit done(true);
}
}
ulong SystemHelper::GetStorageSpace(QString Path)
{
if (!Path.isEmpty() && !Path.isNull())
{
TChar DriveChar = Path.at(0).toAscii();
TInt Drive = 0;
RFs FileSystem;
TVolumeInfo VolumeInfo;
ulong DriveFreeSpace = 0;
int Error;
Error = FileSystem.Connect();
//CleanupClosePushL(FileSystem);
if (Error == 0)
{
FileSystem.CharToDrive(DriveChar, Drive);
FileSystem.Volume(VolumeInfo, Drive);
DriveFreeSpace = (ulong)VolumeInfo.iFree;
return DriveFreeSpace;
}
else
{
return 0;
}
//CleanupStack::PopAndDestroy(&FileSystem);
}
else
{
return 0;
}
}
QList<QString> SystemHelper::GetAllStorages()
{
QFileInfoList Drives = QDir::drives();
QList<QString> DrivesNames = QList<QString>();
foreach(QFileInfo drive, Drives)
{
QString DriveName = drive.path();
DrivesNames.append(DriveName);
}
return DrivesNames;
}
void SystemHelper::GetSystemInfo()
{
QString CurrentPath = "/";
QFile *SysInfoFile = new QFile(CurrentPath + QDir::separator() + "AppManager.log");
SysInfoFile->open(QFile::WriteOnly);
QTextStream SysInfo(SysInfoFile);
const QRect ScreenRect = QApplication::desktop()->screenGeometry();
const QRect AvailableRect = QApplication::desktop()->availableGeometry();
SysInfo << "ScreenGeometry: " << ScreenRect.width() << "x" << ScreenRect.height() << endl;
SysInfo << "AvailableGeometry: " << AvailableRect.width() << "x" << AvailableRect.height() << endl;
SysInfo << "InstallPath: " << ParamsHelper::InstallPath << endl;
SysInfo << "SymbianVersion: ";
switch (ParamsHelper::OSVersion)
{
case QSysInfo::SV_9_2:
SysInfo << "SV_9_2" << endl;
break;
case QSysInfo::SV_9_3:
SysInfo << "SV_9_3" << endl;
break;
case QSysInfo::SV_9_4:
SysInfo << "SV_9_4" << endl;
break;
case QSysInfo::SV_SF_2:
SysInfo << "SV_SF_2" << endl;
break;
case QSysInfo::SV_SF_3:
SysInfo << "SV_SF_3" << endl;
break;
case QSysInfo::SV_SF_4:
SysInfo << "SV_SF_4" << endl;
break;
case QSysInfo::SV_Unknown:
SysInfo << "SV_Unknown" << endl;
break;
default:
SysInfo << "SV_None" << endl;
}
SysInfoFile->close();
}
QRect* SystemHelper::GetScreenRect()
{
const QRect ScreenRect = QApplication::desktop()->screenGeometry();
const QRect AvailableRect = QApplication::desktop()->availableGeometry();
if (ScreenRect.height() == AvailableRect.height() && ScreenRect.width() == AvailableRect.width())
{
return new QRect(0, 0, ScreenRect.width(), (int)(ScreenRect.height()*0.92));
}
else
{
return new QRect(0, 0, AvailableRect.width(), AvailableRect.height());
}
}
QMap<QString, uint> SystemHelper::GetInstalledApps()
{
RApaLsSession AppListSession;
QMap<QString, uint> InstalledMap;
TApaAppInfo AppInfo;
int Error = 0;
Error = AppListSession.Connect();
if (Error == 0)
{
AppListSession.GetAllApps();
while (AppListSession.GetNextApp(AppInfo) == 0)
{
TApaAppCapabilityBuf CapabilityBuf;
TApaAppCapability Capability;
QString AppName = QString::fromUtf16(AppInfo.iCaption.Ptr(), AppInfo.iCaption.Length());
AppListSession.GetAppCapability(CapabilityBuf, AppInfo.iUid);
Capability = CapabilityBuf();
AppName = AppName.trimmed();
if (AppName.length() > 0 && !Capability.iAppIsHidden)
{
InstalledMap.insert(AppName, (uint)AppInfo.iUid.iUid);
}
}
}
return InstalledMap;
}
void SystemHelper::UpdateInstall(QString UpdatePath)
{
QProcess *Install = new QProcess(this);
UpdatePath = UpdatePath.replace("/", "\\");
Install->startDetached("\"" + UpdatePath + "\"");
//QDesktopServices::openUrl(QUrl("file:///" + UpdatePath));
}
void SystemHelper::WriteLog(QString LogString)
{
RFs fs;
User::LeaveIfError(fs.Connect());
CleanupClosePushL(fs);
_LIT(KLogFile, "c:\\log.txt");
RFile file;
file.Replace(fs, KLogFile, EFileWrite);
CleanupClosePushL(file);
CLogger *logger = CLogger::NewL(file, CLogger::ELevelAll & ~CLogger::ELevelDebug); // Prints all messages except Debug
CleanupStack::PushL(logger);
LoggerStatic::SetLogger(logger); // Set default logger
// You may use either 16 or 8-bit descriptors
LOG(_L16("Simple message in 16bit descriptor (uncategorized)"));
// or
LOG(_L8("Simple message in 8bit descriptor (uncategorized)"));
DEBUG(_L("This is debug message")); // This kind of message currently disabled in logger settings
INFO(_L("This is info message"));
WARNING(_L("This is warning message"));
_LIT(KErrTxt, "Not Found");
ERROR(_L("This is formatted error message with code: %d (%S)"), 404, &KErrTxt);
CleanupStack::PopAndDestroy(3, &fs); // logger + file + fs
LOG(_L("Logger already has been destroyed and this message won`t be included to the log file :("));
}