2014-02-21 02:35:33 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
|
|
dest = wxGetCwd() + dest;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
if (wxDirExists(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) {
|
|
|
|
|
ConLog.Error("PKG Loader: Another installation found in: %s", wxString(titleID).wx_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// TODO: Remove the following two lines and remove the folder dest+titleID
|
2014-02-21 02:35:33 +01:00
|
|
|
ConLog.Error("PKG Loader: Another installation found in: %s", wxString(titleID).wx_str());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!wxMkdir(dest+titleID)) {
|
|
|
|
|
ConLog.Error("PKG Loader: Could not make the installation directory: %s", wxString(titleID).wx_str());
|
|
|
|
|
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-03-03 05:48:07 +01:00
|
|
|
ConLog.Write("PKG Loader: Package successfully installed in: /dev_hdd0/game/%s", wxString(titleID.c_str()).wx_str());
|
|
|
|
|
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();
|
|
|
|
|
}
|