2014-02-21 02:35:33 +01:00
|
|
|
#include "stdafx.h"
|
2014-06-02 19:27:24 +02:00
|
|
|
#include "Emu/ConLog.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
|
|
|
|
|
|
|
|
PKGLoader::PKGLoader(wxFile& f) : pkg_f(f)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
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-04-01 02:33:55 +02:00
|
|
|
dest = fmt::ToUTF8(wxGetCwd()) + dest;
|
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-04-01 02:33:55 +02:00
|
|
|
if (wxDirExists(fmt::FromUTF8(dest+titleID))) {
|
2014-02-21 14:21:08 +01:00
|
|
|
wxMessageDialog d_overwrite(NULL, "Another installation was found. Do you want to overwrite it?", "PKG Decrypter / Installer", wxYES_NO|wxCENTRE);
|
|
|
|
|
if (d_overwrite.ShowModal() != wxID_YES) {
|
2014-04-01 02:33:55 +02:00
|
|
|
ConLog.Error("PKG Loader: Another installation found in: %s", titleID.c_str());
|
2014-02-21 14:21:08 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// TODO: Remove the following two lines and remove the folder dest+titleID
|
2014-04-01 02:33:55 +02:00
|
|
|
ConLog.Error("PKG Loader: Another installation found in: %s", titleID.c_str());
|
2014-02-21 02:35:33 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2014-04-01 02:33:55 +02:00
|
|
|
if (!wxMkdir(fmt::FromUTF8(dest+titleID))) {
|
|
|
|
|
ConLog.Error("PKG Loader: Could not make 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-03-03 05:48:07 +01:00
|
|
|
ConLog.Error("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-04-01 02:33:55 +02:00
|
|
|
ConLog.Write("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();
|
|
|
|
|
}
|