rpcs3/rpcs3/Loader/PKG.cpp
Sacha e8525a6f14 More rFile cleanups and fixes.
Was using fileExists/dirExists before when really should have just been exists. File or Dir doesn't matter and would only create false negatives.
Current working directory shouldn't really be used at all. This is just the folder the application is run from (not even where the .exe resides).
Some of the infos required by vfsLocalDir such as executable may not be portable. Not sure of their intended function as they are never used.
2014-08-01 04:20:00 +10:00

59 lines
1.5 KiB
C++

#include "stdafx.h"
#include "Utilities/Log.h"
#include "PKG.h"
#include "../Crypto/unpkg.h"
PKGLoader::PKGLoader(rFile& f) : pkg_f(f)
{
}
bool PKGLoader::Install(std::string dest)
{
// Initial checks
if (!pkg_f.IsOpened())
return false;
// TODO: This shouldn't use current dir
dest.insert(0, 1, '.');
if (!dest.empty() && dest.back() != '/')
dest += '/';
// 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);
if (rExists(dest+titleID)) {
rMessageDialog d_overwrite(NULL, "Another installation was found. Do you want to overwrite it?", "PKG Decrypter / Installer", rYES_NO|rCENTRE);
if (d_overwrite.ShowModal() != rID_YES) {
LOG_ERROR(LOADER, "PKG Loader: Another installation found in: %s", titleID.c_str());
return false;
}
// TODO: Remove the following two lines and remove the folder dest+titleID
LOG_ERROR(LOADER, "PKG Loader: Another installation found in: %s", titleID.c_str());
return false;
}
if (!rMkdir(dest+titleID)) {
LOG_ERROR(LOADER, "PKG Loader: Could not make the installation directory: %s", titleID.c_str());
return false;
}
// Decrypt and unpack the PKG file.
if (Unpack(pkg_f, titleID, dest) < 0)
{
LOG_ERROR(LOADER, "PKG Loader: Failed to install package!");
return false;
}
else
{
LOG_NOTICE(LOADER, "PKG Loader: Package successfully installed in: /dev_hdd0/game/%s", titleID.c_str());
return true;
}
}
bool PKGLoader::Close()
{
return pkg_f.Close();
}