2014-02-21 02:35:33 +01:00
|
|
|
#include "stdafx.h"
|
2014-06-17 17:44:03 +02:00
|
|
|
#include "Utilities/Log.h"
|
2014-08-22 16:21:55 +02:00
|
|
|
#include "Utilities/rMsgBox.h"
|
2015-04-24 23:38:11 +02:00
|
|
|
#include "Utilities/File.h"
|
2014-02-21 02:35:33 +01:00
|
|
|
#include "PKG.h"
|
2014-03-03 05:48:07 +01:00
|
|
|
#include "../Crypto/unpkg.h"
|
2014-02-21 02:35:33 +01:00
|
|
|
|
2015-04-24 23:38:11 +02:00
|
|
|
bool PKGLoader::Install(const fs::file& pkg_f, std::string dest)
|
2014-02-21 02:35:33 +01:00
|
|
|
{
|
|
|
|
|
// Initial checks
|
2015-04-19 15:19:24 +02:00
|
|
|
if (!pkg_f)
|
|
|
|
|
{
|
2014-02-21 02:35:33 +01:00
|
|
|
return false;
|
2015-04-19 15:19:24 +02:00
|
|
|
}
|
2014-02-21 02:35:33 +01:00
|
|
|
|
2014-03-03 05:48:07 +01:00
|
|
|
// Fetch title ID from the header.
|
|
|
|
|
char title_id[48];
|
2015-04-19 15:19:24 +02:00
|
|
|
pkg_f.seek(48);
|
|
|
|
|
pkg_f.read(title_id, 48);
|
2014-03-03 05:48:07 +01:00
|
|
|
|
|
|
|
|
std::string titleID = std::string(title_id).substr(7, 9);
|
2014-02-21 02:35:33 +01:00
|
|
|
|
2015-04-24 23:38:11 +02:00
|
|
|
if (fs::is_dir(dest + titleID))
|
2015-04-19 15:19:24 +02:00
|
|
|
{
|
|
|
|
|
if (rMessageDialog(NULL, "Another installation found. Do you want to overwrite it?", "PKG Decrypter / Installer", rYES_NO | rCENTRE).ShowModal() != rID_YES)
|
|
|
|
|
{
|
2014-06-27 15:26:46 +02:00
|
|
|
LOG_ERROR(LOADER, "PKG Loader: Another installation found in: %s", titleID.c_str());
|
2014-02-21 14:21:08 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-04-19 15:19:24 +02:00
|
|
|
}
|
2015-04-24 23:38:11 +02:00
|
|
|
else if (!fs::create_dir(dest + titleID))
|
2015-04-19 15:19:24 +02:00
|
|
|
{
|
2015-01-04 17:44:54 +01:00
|
|
|
LOG_ERROR(LOADER, "PKG Loader: Could not create the installation directory: %s", titleID.c_str());
|
2014-02-21 02:35:33 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-03 05:48:07 +01:00
|
|
|
// Decrypt and unpack the PKG file.
|
|
|
|
|
if (Unpack(pkg_f, titleID, dest) < 0)
|
2014-02-21 02:35:33 +01:00
|
|
|
{
|
2014-06-17 17:44:03 +02:00
|
|
|
LOG_ERROR(LOADER, "PKG Loader: Failed to install package!");
|
2014-02-21 02:35:33 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2014-03-03 05:48:07 +01:00
|
|
|
else
|
2014-02-21 02:35:33 +01:00
|
|
|
{
|
2014-06-27 15:26:46 +02:00
|
|
|
LOG_NOTICE(LOADER, "PKG Loader: Package successfully installed in: /dev_hdd0/game/%s", titleID.c_str());
|
2014-03-03 05:48:07 +01:00
|
|
|
return true;
|
2014-02-21 02:35:33 +01:00
|
|
|
}
|
|
|
|
|
}
|