///////////////////////////////////////////////////////////////////////////////
//
// File      : Asura_PS3_MultipleStorage.h
// Author    : Philip Hall
// Created   : 11/12/2007
//
// Copyright (C) 2007 Rebellion. All Rights Reserved
//
///////////////////////////////////////////////////////////////////////////////

#if !defined __ASURA_PS3_MULTIPLESTORAGE_H__
#define __ASURA_PS3_MULTIPLESTORAGE_H__

// Asura PS3 headers
#include "core/Asura_PS3_Semaphore.h"
#include "fileaccess/Asura_PS3_FileSystem.h"
#include "utility/Asura_PS3_SingleStorage.h"

// platform specific headers
#include <sys/ppu_thread.h>
#include <sysutil/sysutil_savedata.h>

#if !defined ASURA_PS3_MAX_MULTIPLE_SAVES
	#define ASURA_PS3_MAX_MULTIPLE_SAVES  16
#endif

#if !defined ASURA_PS3_MAX_SAVE_SLOTS
	#define ASURA_PS3_MAX_SAVE_SLOTS      4
#endif

////PGH////////////////////////////////////////////////////////////////////////
// How to use 'Asura_PS3_MultipleStorage'
//
// This storage class works almost identically to the Asura_PS3_SingleStorage
// class. However this class will display a list of saves if you're not using
// autosave/autoload.
//
// To use your own save lists, use autosave/autoload to read or write a single
// file containing ann Asura_PS3_SaveIndex structure. Then use the names
// in the slots to identify list-saves with the same slot index.
//
///////////////////////////////////////////////////////////////////////////////


////PGH/////////////////////////////////////////
// Save index entry                            
////////////////////////////////////////////////
struct Asura_PS3_SaveIndexEntry
{
	enum { NAME_LENGTH = 32 };
	char m_szName[NAME_LENGTH];
	Asura_PS3_SaveIndexEntry() { strncpy(m_szName, "Empty", NAME_LENGTH); }
};


////PGH/////////////////////////////////////////
// Save index structure (saved to file)        
////////////////////////////////////////////////
struct Asura_PS3_SaveIndex
{
	enum { ASURA_PS3_INDEX_VERSION = 1 };
	int   m_iVersion;
	int   m_iSlots;
	Asura_PS3_SaveIndexEntry m_axSaveSlots[ASURA_PS3_MAX_SAVE_SLOTS];
	Asura_PS3_SaveIndex() { m_iVersion = ASURA_PS3_INDEX_VERSION; m_iSlots = ASURA_PS3_MAX_SAVE_SLOTS; };
};


////PGH/////////////////////////////////////////
// Multiple directory data storage (list-based)
////////////////////////////////////////////////
class Asura_PS3_MultipleStorage : public Asura_PS3_SingleStorage
{
protected:

public:
	Asura_PS3_MultipleStorage(const char* szProductCode, Asura_PS3_StorageCallback pfnCompletion=NULL, void* pUserData=NULL);
	
	bool Load(const char* szPrefix, bool bAutoLoad, int iIndex=-1);
	bool Save(const char* szPrefix, bool bAutoSave, int iIndex=-1);
	bool Delete(bool bAll=true);

protected:
	void ThreadStorage();  // Overrides base (via thread proxy)
	static void ThreadDelete(uint64_t uParam);

	static void SaveListCallback(CellSaveDataCBResult* pResult, CellSaveDataListGet* pGet, CellSaveDataListSet* pSet );
	static void LoadListCallback(CellSaveDataCBResult* pResult, CellSaveDataListGet* pGet, CellSaveDataListSet* pSet );
	
protected:	
	bool   m_bDeleteAll; 
	CellSaveDataListNewData m_xNewData;
	char   m_szMultiDirectory[CELL_SAVEDATA_DIRNAME_SIZE];
};





#endif


