2010-12-08 08:26:18 +01:00
# ifndef NANDDUMP_H
# define NANDDUMP_H
# include "nusdownloader.h"
# include "includes.h"
# include "sharedcontentmap.h"
# include "uidmap.h"
2010-12-10 14:10:53 +01:00
struct SaveGame //struct to hold save data
{
quint64 tid ; //tid this data belongs to
QStringList entries ; //paths of all the files & folders
QList < bool > isFile ; //type of each entry. false = folder, true = file
QList < QByteArray > data ; //data for each file. size of this list should equal the number of files in the above list
} ;
2010-12-10 04:50:08 +01:00
//class for handeling an extracted wii nand filesystem
//! nothing can be done unless basePath is set. do this either by setting it in the constructor, or by calling SetPath()
//! current reading and writing is limited to installing a title in the form of NusJob, reading/writing/deleting specific paths
//! for performance reasons, the uid and content map are cached and only written to the HDD when the destructor or Flush() is called
2010-12-10 14:10:53 +01:00
//! GetData() and SaveData() expect relative paths inside the nand.
//! to support creating a nand on different filesystems, characters in filenames may have to be changed
//! use SetReplaceString() to specify a character to replace and the string to replace it with. these characters
//! will be stored in "/sys/replace". only characters allowed on a FAT32 filesystem are allowed in replacement strings
//! to get a list of these replacement strings, use GetReplacementStrings()
//! This is ONLY DESIGNED FOR FIXING SAVEGAMES. All of the normal files on a nand can be stored on any modern filesystem
//! The only time these replacement characters are used is when dealing with save data. it is advised to only try to replace
//! characters that cannot be used on a modern PC filesystem. trying to replace any common string will probably result in
//! a broken nand FS
2010-12-08 08:26:18 +01:00
class NandDump
{
public :
NandDump ( const QString & path = QString ( ) ) ;
~ NandDump ( ) ;
2010-12-10 14:10:53 +01:00
//set a character to be replaced, and the string to replace it with
//giving an empty replacement string will remove that entry and all the actual character will be used in paths
//! this function will recurse the "/title" folder and apply any change to any existing files if finds
//! if that fails ( like you tried to tell it to use a ':' while writing to a FAT32 drive), it will try to recurse that folder again and undo the change
bool SetReplaceString ( const QString ch , const QString & replaceWith = QString ( ) ) ;
//get a list of the replacement strings used when writing save data
// they are returned as ( character as it would be on the wii nand, string as it is on this nand dump )
QMap < QString , QString > GetReplacementStrings ( ) ;
2010-12-08 08:26:18 +01:00
//sets the basepath for this nand
//if it doesnt exist, the function will try to create it
//also creates the normal folders in the nand
bool SetPath ( const QString & path ) ;
2010-12-09 06:45:12 +01:00
const QString GetPath ( ) { return basePath ; }
2010-12-08 08:26:18 +01:00
//installs a title to the nand dump from an already existing NusJob
//returns false if something went wrong
bool InstallNusItem ( NusJob job ) ;
//tries to delete a title from the nand dump
//deleteData gives the option to just delete the title and leave behind its data
bool DeleteTitle ( quint64 tid , bool deleteData = false ) ;
//check what version a given title is on this nand, returns 0 if it isnt installed
2010-12-10 04:50:08 +01:00
//quint16 GetTitleVersion( quint64 tid );
//get a list of all titles for which there is a ticket & tmd
// returns a map of < tid, version >
2010-12-10 14:10:53 +01:00
QMap < quint64 , quint16 > GetInstalledTitles ( ) ;
2010-12-08 08:26:18 +01:00
//write the current uid & content.map to the PC
//failure to make sure this is done can end up with a broken nand
bool Flush ( ) ;
2010-12-10 04:50:08 +01:00
//overloads GetFile() with "/title/00000001/00000002/data/setting.txt"
2010-12-08 08:26:18 +01:00
QByteArray GetSettingTxt ( ) ;
bool SetSettingTxt ( const QByteArray ba ) ;
2010-12-10 04:50:08 +01:00
//reads a file from the nand and returns it as a qbytearray
2010-12-08 08:26:18 +01:00
const QByteArray GetFile ( const QString & path ) ;
2010-12-10 04:50:08 +01:00
//tries to write the given bytearray to a file of the given path
2010-12-08 08:26:18 +01:00
bool SaveData ( const QByteArray ba , const QString & path ) ;
2010-12-10 04:50:08 +01:00
//expects a file, not directory
2010-12-08 08:26:18 +01:00
void DeleteData ( const QString & path ) ;
2010-12-10 14:10:53 +01:00
//extract save data for a given title
// if no save is found, it will return a SaveData object with an empty list of entries
SaveGame GetSaveData ( quint64 tid ) ;
//installs a save to the nand
bool InstallSave ( SaveGame save ) ;
//convert a name TO the format that will be writen to the nand
// it would be wise to only give these functions the name of the exact file you want to convert instead of the path
// as there might be replacements for the path delimiter ('/')
const QString ToNandName ( const QString & name ) ;
//convert a name FROM the format that will be writen to the nand
const QString FromNandName ( const QString & name ) ;
//like the above function, but splits a path at '/', converts the parts, and puts it back together into a path again
// the return string has '/' before EVERY entry
//! these are not exactly lightweight as they call the above 2 functions for every part
//! of a path. they are only meant to be used for converting paths for savedata
const QString ToNandPath ( const QString & path ) ;
const QString FromNandPath ( const QString & path ) ;
//sanity check a save object
static bool IsValidSave ( SaveGame save ) ;
2010-12-08 08:26:18 +01:00
private :
QString basePath ;
SharedContentMap cMap ;
UIDmap uidMap ;
2010-12-10 14:10:53 +01:00
QMap < QString , QString > replaceStrings ;
void ReadReplacementStrings ( ) ;
bool FlushReplacementStrings ( ) ;
2010-12-08 08:26:18 +01:00
//write the current uid.sys to disc
bool uidDirty ;
bool FlushUID ( ) ;
//write the content.map to disc
bool cmDirty ;
bool FlushContentMap ( ) ;
bool InstallTicket ( const QByteArray ba , quint64 tid ) ;
bool InstallTmd ( const QByteArray ba , quint64 tid ) ;
bool InstallSharedContent ( const QByteArray ba , const QByteArray hash = QByteArray ( ) ) ;
bool InstallPrivateContent ( const QByteArray ba , quint64 tid , const QString & cid ) ;
void AbortInstalling ( quint64 tid ) ;
//go through and delete all the stuff in a given folder and then delete the folder itself
//this function expects an absolute path, not a relitive one inside the nand dump
bool RecurseDeleteFolder ( const QString & path ) ;
2010-12-10 14:10:53 +01:00
//recursively replaces strings in filenames. this one expects an absolute path as well
bool RecurseRename ( const QString & path , const QString & from , const QString & to ) ;
2010-12-08 08:26:18 +01:00
} ;
# endif // NANDDUMP_H