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"
|
2014-08-25 16:56:13 +02:00
|
|
|
#include "Utilities/rFile.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
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
PKGLoader::PKGLoader(rFile& f) : pkg_f(f)
|
2014-02-21 02:35:33 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-03 05:48:07 +01:00
|
|
|
bool PKGLoader::Install(std::string dest)
|
2014-02-21 02:35:33 +01:00
|
|
|
{
|
|
|
|
|
// Initial checks
|
2014-02-21 14:21:08 +01:00
|
|
|
if (!pkg_f.IsOpened())
|
2014-02-21 02:35:33 +01:00
|
|
|
return false;
|
|
|
|
|
|
2014-07-31 20:20:00 +02:00
|
|
|
// TODO: This shouldn't use current dir
|
|
|
|
|
dest.insert(0, 1, '.');
|
2014-02-21 02:35:33 +01:00
|
|
|
if (!dest.empty() && dest.back() != '/')
|
|
|
|
|
dest += '/';
|
|
|
|
|
|
2014-03-03 05:48:07 +01:00
|
|
|
// Fetch title ID from the header.
|
|
|
|
|
char title_id[48];
|
|
|
|
|
pkg_f.Seek(48);
|
|
|
|
|
pkg_f.Read(title_id, 48);
|
|
|
|
|
|
|
|
|
|
std::string titleID = std::string(title_id).substr(7, 9);
|
2014-02-21 02:35:33 +01:00
|
|
|
|
2014-08-23 09:30:26 +02:00
|
|
|
if (rExists(dest + titleID)) {
|
2015-01-04 17:44:54 +01:00
|
|
|
rMessageDialog d_overwrite(NULL, "Another installation found. Do you want to overwrite it?", "PKG Decrypter / Installer", rYES_NO|rCENTRE);
|
2014-05-02 08:30:32 +02:00
|
|
|
if (d_overwrite.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-01-04 17:44:54 +01:00
|
|
|
} else if (!rMkdir(dest + titleID)) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-03 05:48:07 +01:00
|
|
|
bool PKGLoader::Close()
|
2014-02-21 02:35:33 +01:00
|
|
|
{
|
2014-03-03 05:48:07 +01:00
|
|
|
return pkg_f.Close();
|
2014-07-31 20:20:00 +02:00
|
|
|
}
|