Skip to content
Snippets Groups Projects
Commit dec97ca2 authored by akiraohgaki's avatar akiraohgaki
Browse files

object for path

parent 3df3410a
No related branches found
No related tags found
No related merge requests found
...@@ -164,21 +164,20 @@ void XdgUrlHandler::saveDownloadedFile(qtlib::NetworkResource *resource) ...@@ -164,21 +164,20 @@ void XdgUrlHandler::saveDownloadedFile(qtlib::NetworkResource *resource)
QJsonObject result; QJsonObject result;
QString type = metadata_["type"].toString(); QString type = metadata_["type"].toString();
QString destination = destinations_[type].toString(); qtlib::Dir destDir(destinations_[type].toString());
QString path = destination + "/" + metadata_["filename"].toString(); destDir.make();
qtlib::File destFile(destDir.path() + "/" + metadata_["filename"].toString());
qtlib::Dir(destination).make(); if (!resource->saveData(destFile.path())) {
if (!resource->saveData(path)) {
result["status"] = QString("error_save"); result["status"] = QString("error_save");
result["message"] = QString("Failed to save data as " + path); result["message"] = QString("Failed to save data as " + destFile.path());
emit finishedWithError(result); emit finishedWithError(result);
resource->deleteLater(); resource->deleteLater();
return; return;
} }
result["status"] = QString("success_download"); result["status"] = QString("success_download");
result["message"] = QString("The file has been stored into " + destination); result["message"] = QString("The file has been stored into " + destDir.path());
emit finishedWithSuccess(result); emit finishedWithSuccess(result);
resource->deleteLater(); resource->deleteLater();
...@@ -188,28 +187,25 @@ void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource) ...@@ -188,28 +187,25 @@ void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
{ {
QJsonObject result; QJsonObject result;
QString tempPath = qtlib::Dir::tempPath() + "/" + metadata_["filename"].toString(); qtlib::File tempFile(qtlib::Dir::tempPath() + "/" + metadata_["filename"].toString());
if (!resource->saveData(tempPath)) { if (!resource->saveData(tempFile.path())) {
result["status"] = QString("error_save"); result["status"] = QString("error_save");
result["message"] = QString("Failed to save data as " + tempPath); result["message"] = QString("Failed to save data as " + tempFile.path());
emit finishedWithError(result); emit finishedWithError(result);
resource->deleteLater(); resource->deleteLater();
return; return;
} }
qtlib::File tempFile(tempPath); qtlib::Package package(tempFile.path());
qtlib::Package package(tempPath);
QString type = metadata_["type"].toString(); QString type = metadata_["type"].toString();
QString destination = destinations_[type].toString(); qtlib::Dir destDir(destinations_[type].toString());
QString path = destination + "/" + metadata_["filename"].toString(); destDir.make();
qtlib::File destFile(destDir.path() + "/" + metadata_["filename"].toString());
qtlib::Dir(destination).make();
if (type == "bin" if (type == "bin"
&& package.installAsProgram(path)) { && package.installAsProgram(destFile.path())) {
result["message"] = QString("The file has been installed into " + destination); result["message"] = QString("The file has been installed into " + destDir.path());
} }
else if ((type == "plasma_plasmoids" || type == "plasma4_plasmoids" || type == "plasma5_plasmoids") else if ((type == "plasma_plasmoids" || type == "plasma4_plasmoids" || type == "plasma5_plasmoids")
&& package.installAsPlasmapkg("plasmoid")) { && package.installAsPlasmapkg("plasmoid")) {
...@@ -235,11 +231,11 @@ void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource) ...@@ -235,11 +231,11 @@ void XdgUrlHandler::installDownloadedFile(qtlib::NetworkResource *resource)
&& package.installAsPlasmapkg("windowswitcher")) { && package.installAsPlasmapkg("windowswitcher")) {
result["message"] = QString("The KWin window switcher has been installed"); result["message"] = QString("The KWin window switcher has been installed");
} }
else if (package.installAsArchive(destination)) { else if (package.installAsArchive(destDir.path())) {
result["message"] = QString("The archive file has been extracted into " + destination); result["message"] = QString("The archive file has been extracted into " + destDir.path());
} }
else if (package.installAsFile(path)) { else if (package.installAsFile(destFile.path())) {
result["message"] = QString("The file has been installed into " + destination); result["message"] = QString("The file has been installed into " + destDir.path());
} }
else { else {
result["status"] = QString("error_install"); result["status"] = QString("error_install");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment