1#include <cache_manager.h>
5QUrl cache_manager::get_cached_app_path(
const QString &gameId) {
7 QDir(APPS_DIR.filePath(gameId +
"/client"));
8 if (!cur_app_dir.exists()) {
11 QFile qml_file(cur_app_dir.filePath(
"app.qml"));
12 if (!qml_file.exists()) {
13 qDebug() <<
"Can not find app.qml in directory " << cur_app_dir <<
'\n';
16 return QUrl::fromUserInput(qml_file.fileName());
19QUrl cache_manager::save_zip_to_cache(
const QFile *archive_file,
20 const QString &gameId) {
21 QFileInfo archiveFileInfo(archive_file->fileName());
22 QDir app_dir(APPS_DIR.filePath(gameId));
24 if (app_dir.exists()) {
25 app_dir.removeRecursively();
28 unzip_to_folder(*archive_file, app_dir);
30 return QUrl::fromUserInput(app_dir.filePath(
"app.qml"));
33void cache_manager::unzip_to_folder(
const QFile &archive_file,
34 const QDir &dest_dir) {
35 if (!archive_file.exists()) {
36 qDebug() <<
"Can not unpack the archive: " << archive_file.fileName()
37 <<
" does not exist\n";
42 KZip archive(archive_file.fileName());
43 if (!archive.open(QIODevice::ReadOnly)) {
44 qDebug() <<
"Cannot open " << archive_file.fileName()
45 <<
" Is it a valid zip file?\n";
49 const KArchiveDirectory *archive_root = archive.directory();
50 archive_root->copyTo(dest_dir.path(),
true);
52 qDebug() <<
"Unpacked " << archive_file.fileName() <<
" to "
53 << dest_dir.path() <<
'\n';