#include "xentax.h"
#include "x_file.h"
#include "x_findfile.h"
#include "x_stream.h"
#include "x_dds.h"
#include "x_amc.h"
#include "x_gui.h"
#include "template3.h"
using namespace std;

#define X_SYSTEM PS3
#define X_GAME   GAMETITLEHERE

//
// FUNCTIONS
//

namespace X_SYSTEM { namespace X_GAME {

bool add_title(void)
{
 // title
 STDSTRING p1;
 p1 += TEXT("[PS3] Game Title Here");

 // instructions
 STDSTRING p2;
 p2 += TEXT("1. Extract game into its own folder.\n");
 p2 += TEXT("2. Run ripper.\n");
 p2 += TEXT("3. Select game and click Browse.\n");
 p2 += TEXT("4. Select folder where LINKDATA files are.\n");
 p2 += TEXT("5. Click OK.\n");
 p2 += TEXT("6. Answer questions.\n");
 p2 += TEXT("7. Watch console for a few hours.\n");
 p2 += TEXT("8. Open smcimport.py script in Blender 2.49.\n");
 p2 += TEXT("9. Run script on SMC files for models.");

 // notes
 STDSTRING p3;
 p3 += TEXT("1. You must run this program 'As Administrator.'\n");
 p3 += TEXT("2. You need ~12 GB free space.\n");
 p3 += TEXT("3. 4 GB for game + 8 GB extraction.\n");
 p3 += TEXT("4. For DLC, EDATs must be decrypted to DATs.");

 // insert title
 AddGameTitle(p1.c_str(), p2.c_str(), p3.c_str(), extract);
 return true;
}

bool extract(void)
{
 LPCTSTR pathname = GetModulePathname().get();
 return extract(pathname);
}

bool extract(LPCTSTR pname)
{
 // set pathname
 STDSTRING pathname(pname);
 if(!pathname.length()) pathname = GetModulePathname().get();

 // booleans
 bool doLDA = true;
 bool doLDB = true;
 bool doLDC = true;
 bool doLDD = true;
 bool doDLC = true;
 bool doARC = true;
 bool doG1T = true;
 bool doG1M = true;

 // questions
 if(doLDA) doLDA = YesNoBox("Process LINKDATA.A file?\nSay 'No' if you have already done this before.");
 if(doLDB) doLDB = YesNoBox("Process LINKDATA.B file?\nSay 'No' if you have already done this before.");
 if(doLDC) doLDC = YesNoBox("Process LINKDATA.C file?\nSay 'No' if you have already done this before.");
 if(doLDD) doLDD = YesNoBox("Process LINKDATA.D file?\nSay 'No' if you have already done this before.");
 if(doDLC) doDLC = YesNoBox("Process PS3 DLC (BIN) files?");
 if(doARC) doARC = YesNoBox("Process extracted (IDXZRC and IDXOUT) files?");
 if(doG1T) doG1T = YesNoBox("Process texture (G1T) files?");
 if(doG1M) doG1M = YesNoBox("Process model (G1M) files?");

 // record start time
 uint64 t0 = 0;
 QueryPerformanceCounter((LARGE_INTEGER*)&t0);

 // // unpack archives
 // if(doLDA) {
 //    STDSTRING file = pathname;
 //    file += TEXT("LINKDATA.A");
 //    PS3::DYNASTY_WARRIORS::UnpackABC(file.c_str());
 //   }
 // if(doLDB) {
 //    STDSTRING file = pathname;
 //    file += TEXT("LINKDATA.B");
 //    PS3::DYNASTY_WARRIORS::UnpackABC(file.c_str());
 //   }
 // if(doLDC) {
 //    STDSTRING file = pathname;
 //    file += TEXT("LINKDATA.C");
 //    PS3::DYNASTY_WARRIORS::UnpackABC(file.c_str());
 //   }
 // if(doLDD) {
 //    STDSTRING file = pathname;
 //    file += TEXT("LINKDATA.D");
 //    PS3::DYNASTY_WARRIORS::UnpackABC(file.c_str());
 //   }
 // 
 // // unpack DLC files
 // if(doDLC)
 //    PS3::DYNASTY_WARRIORS::UnpackDLC(pathname.c_str());
 // 
 // // recursively rename and unpack files
 // if(doARC) {
 //    PS3::DYNASTY_WARRIORS::UnpackIDXZRC(pathname.c_str());
 //    PS3::DYNASTY_WARRIORS::UnpackIDXOUT(pathname.c_str());
 //    PS3::DYNASTY_WARRIORS::IDXArchiveUnpackLoop(pathname.c_str());
 //   }
 // 
 // // texture extraction
 // if(doG1T)
 //    PS3::DYNASTY_WARRIORS::UnpackTextures(pathname.c_str());
 // 
 // // model extraction
 // if(doG1M)
 //    PS3::DYNASTY_WARRIORS::UnpackModels(pathname.c_str());

 // record end time
 uint64 t1 = 0;
 QueryPerformanceCounter((LARGE_INTEGER*)&t1);

 // determine time
 uint64 hz;
 QueryPerformanceFrequency((LARGE_INTEGER*)&hz);
 uint64 dt = (t1 - t0);
 real64 dt_sec = (real64)(t1 - t0)/(real64)hz;
 real64 dt_min = dt_sec/60.0;
 real64 dt_hrs = dt_min/60.0;
 cout << "Elapsed time = " << dt_min << " minutes." << endl;

 return true;
}

}};