History Viewer: Prevent history viewer window from overwriting .sav files
This commit is contained in:
parent
82c4dc8316
commit
6fc37e980f
10 changed files with 45 additions and 39 deletions
|
@ -26,7 +26,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
AsciiTurboFile(shared_ptr<Console> console) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort)
|
AsciiTurboFile(shared_ptr<Console> console) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort)
|
||||||
{
|
{
|
||||||
BatteryManager::LoadBattery(".tf", _data, AsciiTurboFile::FileSize);
|
_console->GetBatteryManager()->LoadBattery(".tf", _data, AsciiTurboFile::FileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
~AsciiTurboFile()
|
~AsciiTurboFile()
|
||||||
|
@ -36,7 +36,7 @@ public:
|
||||||
|
|
||||||
void SaveBattery() override
|
void SaveBattery() override
|
||||||
{
|
{
|
||||||
BatteryManager::SaveBattery(".tf", _data, AsciiTurboFile::FileSize);
|
_console->GetBatteryManager()->SaveBattery(".tf", _data, AsciiTurboFile::FileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ReadRAM(uint16_t addr) override
|
uint8_t ReadRAM(uint16_t addr) override
|
||||||
|
|
|
@ -353,22 +353,22 @@ bool BaseMapper::HasBattery()
|
||||||
void BaseMapper::LoadBattery()
|
void BaseMapper::LoadBattery()
|
||||||
{
|
{
|
||||||
if(HasBattery() && _saveRamSize > 0) {
|
if(HasBattery() && _saveRamSize > 0) {
|
||||||
BatteryManager::LoadBattery(".sav", _saveRam, _saveRamSize);
|
_console->GetBatteryManager()->LoadBattery(".sav", _saveRam, _saveRamSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_hasChrBattery && _chrRamSize > 0) {
|
if(_hasChrBattery && _chrRamSize > 0) {
|
||||||
BatteryManager::LoadBattery(".sav.chr", _chrRam, _chrRamSize);
|
_console->GetBatteryManager()->LoadBattery(".sav.chr", _chrRam, _chrRamSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseMapper::SaveBattery()
|
void BaseMapper::SaveBattery()
|
||||||
{
|
{
|
||||||
if(HasBattery() && _saveRamSize > 0) {
|
if(HasBattery() && _saveRamSize > 0) {
|
||||||
BatteryManager::SaveBattery(".sav", _saveRam, _saveRamSize);
|
_console->GetBatteryManager()->SaveBattery(".sav", _saveRam, _saveRamSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_hasChrBattery && _chrRamSize > 0) {
|
if(_hasChrBattery && _chrRamSize > 0) {
|
||||||
BatteryManager::SaveBattery(".sav.chr", _chrRam, _chrRamSize);
|
_console->GetBatteryManager()->SaveBattery(".sav.chr", _chrRam, _chrRamSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,10 @@
|
||||||
#include "VirtualFile.h"
|
#include "VirtualFile.h"
|
||||||
#include "../Utilities/FolderUtilities.h"
|
#include "../Utilities/FolderUtilities.h"
|
||||||
|
|
||||||
string BatteryManager::_romName;
|
|
||||||
bool BatteryManager::_saveEnabled = true;
|
|
||||||
std::weak_ptr<IBatteryRecorder> BatteryManager::_recorder;
|
|
||||||
std::weak_ptr<IBatteryProvider> BatteryManager::_provider;
|
|
||||||
|
|
||||||
void BatteryManager::Initialize(string romName)
|
void BatteryManager::Initialize(string romName)
|
||||||
{
|
{
|
||||||
_romName = romName;
|
_romName = romName;
|
||||||
|
_saveEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BatteryManager::GetBasePath()
|
string BatteryManager::GetBasePath()
|
||||||
|
|
|
@ -16,25 +16,23 @@ public:
|
||||||
class BatteryManager
|
class BatteryManager
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static string _romName;
|
string _romName;
|
||||||
static bool _saveEnabled;
|
bool _saveEnabled;
|
||||||
static string GetBasePath();
|
string GetBasePath();
|
||||||
|
|
||||||
static std::weak_ptr<IBatteryProvider> _provider;
|
std::weak_ptr<IBatteryProvider> _provider;
|
||||||
static std::weak_ptr<IBatteryRecorder> _recorder;
|
std::weak_ptr<IBatteryRecorder> _recorder;
|
||||||
|
|
||||||
BatteryManager() = delete;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void Initialize(string romName);
|
void Initialize(string romName);
|
||||||
|
|
||||||
static void SetSaveEnabled(bool enabled);
|
void SetSaveEnabled(bool enabled);
|
||||||
|
|
||||||
static void SetBatteryProvider(shared_ptr<IBatteryProvider> provider);
|
void SetBatteryProvider(shared_ptr<IBatteryProvider> provider);
|
||||||
static void SetBatteryRecorder(shared_ptr<IBatteryRecorder> recorder);
|
void SetBatteryRecorder(shared_ptr<IBatteryRecorder> recorder);
|
||||||
|
|
||||||
static void SaveBattery(string extension, uint8_t* data, uint32_t length);
|
void SaveBattery(string extension, uint8_t* data, uint32_t length);
|
||||||
|
|
||||||
static vector<uint8_t> LoadBattery(string extension);
|
vector<uint8_t> LoadBattery(string extension);
|
||||||
static void LoadBattery(string extension, uint8_t* data, uint32_t length);
|
void LoadBattery(string extension, uint8_t* data, uint32_t length);
|
||||||
};
|
};
|
|
@ -33,7 +33,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
BattleBox(shared_ptr<Console> console) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort)
|
BattleBox(shared_ptr<Console> console) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort)
|
||||||
{
|
{
|
||||||
BatteryManager::LoadBattery(".bb", (uint8_t*)_data, BattleBox::FileSize);
|
_console->GetBatteryManager()->LoadBattery(".bb", (uint8_t*)_data, BattleBox::FileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
~BattleBox()
|
~BattleBox()
|
||||||
|
@ -43,7 +43,7 @@ public:
|
||||||
|
|
||||||
void SaveBattery() override
|
void SaveBattery() override
|
||||||
{
|
{
|
||||||
BatteryManager::SaveBattery(".bb", (uint8_t*)_data, BattleBox::FileSize);
|
_console->GetBatteryManager()->SaveBattery(".bb", (uint8_t*)_data, BattleBox::FileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ReadRAM(uint16_t addr) override
|
uint8_t ReadRAM(uint16_t addr) override
|
||||||
|
|
|
@ -74,6 +74,7 @@ Console::~Console()
|
||||||
void Console::Init()
|
void Console::Init()
|
||||||
{
|
{
|
||||||
_notificationManager.reset(new NotificationManager());
|
_notificationManager.reset(new NotificationManager());
|
||||||
|
_batteryManager.reset(new BatteryManager());
|
||||||
|
|
||||||
_videoRenderer.reset(new VideoRenderer(shared_from_this()));
|
_videoRenderer.reset(new VideoRenderer(shared_from_this()));
|
||||||
_videoDecoder.reset(new VideoDecoder(shared_from_this()));
|
_videoDecoder.reset(new VideoDecoder(shared_from_this()));
|
||||||
|
@ -135,6 +136,11 @@ void Console::Release(bool forShutdown)
|
||||||
_controlManager.reset();
|
_controlManager.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_ptr<BatteryManager> Console::GetBatteryManager()
|
||||||
|
{
|
||||||
|
return _batteryManager;
|
||||||
|
}
|
||||||
|
|
||||||
shared_ptr<SaveStateManager> Console::GetSaveStateManager()
|
shared_ptr<SaveStateManager> Console::GetSaveStateManager()
|
||||||
{
|
{
|
||||||
return _saveStateManager;
|
return _saveStateManager;
|
||||||
|
@ -264,7 +270,7 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile)
|
||||||
vector<uint8_t> fileData;
|
vector<uint8_t> fileData;
|
||||||
romFile.ReadFile(fileData);
|
romFile.ReadFile(fileData);
|
||||||
|
|
||||||
BatteryManager::Initialize(FolderUtilities::GetFilename(romFile.GetFileName(), false));
|
_batteryManager->Initialize(FolderUtilities::GetFilename(romFile.GetFileName(), false));
|
||||||
shared_ptr<BaseMapper> mapper = MapperFactory::InitializeFromFile(shared_from_this(), romFile.GetFileName(), fileData);
|
shared_ptr<BaseMapper> mapper = MapperFactory::InitializeFromFile(shared_from_this(), romFile.GetFileName(), fileData);
|
||||||
if(mapper) {
|
if(mapper) {
|
||||||
_soundMixer->StopAudio(true);
|
_soundMixer->StopAudio(true);
|
||||||
|
@ -324,7 +330,7 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Temporarely disable battery saves to prevent battery files from being created for the wrong game (for Battle Box & Turbo File)
|
//Temporarely disable battery saves to prevent battery files from being created for the wrong game (for Battle Box & Turbo File)
|
||||||
BatteryManager::SetSaveEnabled(false);
|
_batteryManager->SetSaveEnabled(false);
|
||||||
|
|
||||||
uint32_t pollCounter = 0;
|
uint32_t pollCounter = 0;
|
||||||
if(_controlManager && !isDifferentGame) {
|
if(_controlManager && !isDifferentGame) {
|
||||||
|
@ -341,7 +347,7 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile)
|
||||||
_controlManager->UpdateControlDevices();
|
_controlManager->UpdateControlDevices();
|
||||||
|
|
||||||
//Re-enable battery saves
|
//Re-enable battery saves
|
||||||
BatteryManager::SetSaveEnabled(true);
|
_batteryManager->SetSaveEnabled(true);
|
||||||
|
|
||||||
if(_hdData && (!_hdData->Tiles.empty() || !_hdData->Backgrounds.empty())) {
|
if(_hdData && (!_hdData->Tiles.empty() || !_hdData->Backgrounds.empty())) {
|
||||||
_ppu.reset(new HdPpu(shared_from_this(), _hdData.get()));
|
_ppu.reset(new HdPpu(shared_from_this(), _hdData.get()));
|
||||||
|
@ -415,7 +421,7 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Reset battery source to current game if new game failed to load
|
//Reset battery source to current game if new game failed to load
|
||||||
BatteryManager::Initialize(FolderUtilities::GetFilename(GetRomInfo().RomName, false));
|
_batteryManager->Initialize(FolderUtilities::GetFilename(GetRomInfo().RomName, false));
|
||||||
if(_mapper) {
|
if(_mapper) {
|
||||||
_videoDecoder->StartThread();
|
_videoDecoder->StartThread();
|
||||||
}
|
}
|
||||||
|
@ -1275,6 +1281,8 @@ void Console::CopyRewindData(shared_ptr<Console> sourceConsole)
|
||||||
sourceConsole->Pause();
|
sourceConsole->Pause();
|
||||||
Pause();
|
Pause();
|
||||||
|
|
||||||
|
//Disable battery saving for this instance
|
||||||
|
_batteryManager->SetSaveEnabled(false);
|
||||||
_historyViewer.reset(new HistoryViewer(shared_from_this()));
|
_historyViewer.reset(new HistoryViewer(shared_from_this()));
|
||||||
sourceConsole->_rewindManager->CopyHistory(_historyViewer);
|
sourceConsole->_rewindManager->CopyHistory(_historyViewer);
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ class SoundMixer;
|
||||||
class NotificationManager;
|
class NotificationManager;
|
||||||
class Debugger;
|
class Debugger;
|
||||||
class EmulationSettings;
|
class EmulationSettings;
|
||||||
|
class BatteryManager;
|
||||||
|
|
||||||
struct HdPackData;
|
struct HdPackData;
|
||||||
struct HashInfo;
|
struct HashInfo;
|
||||||
|
@ -61,7 +62,8 @@ private:
|
||||||
//Used by VS-DualSystem
|
//Used by VS-DualSystem
|
||||||
shared_ptr<Console> _master;
|
shared_ptr<Console> _master;
|
||||||
shared_ptr<Console> _slave;
|
shared_ptr<Console> _slave;
|
||||||
|
|
||||||
|
shared_ptr<BatteryManager> _batteryManager;
|
||||||
shared_ptr<SystemActionManager> _systemActionManager;
|
shared_ptr<SystemActionManager> _systemActionManager;
|
||||||
|
|
||||||
shared_ptr<VideoDecoder> _videoDecoder;
|
shared_ptr<VideoDecoder> _videoDecoder;
|
||||||
|
@ -106,6 +108,7 @@ public:
|
||||||
void Init();
|
void Init();
|
||||||
void Release(bool forShutdown);
|
void Release(bool forShutdown);
|
||||||
|
|
||||||
|
shared_ptr<BatteryManager> GetBatteryManager();
|
||||||
shared_ptr<SaveStateManager> GetSaveStateManager();
|
shared_ptr<SaveStateManager> GetSaveStateManager();
|
||||||
shared_ptr<VideoDecoder> GetVideoDecoder();
|
shared_ptr<VideoDecoder> GetVideoDecoder();
|
||||||
shared_ptr<VideoRenderer> GetVideoRenderer();
|
shared_ptr<VideoRenderer> GetVideoRenderer();
|
||||||
|
|
|
@ -31,7 +31,7 @@ void FDS::InitMapper(RomData &romData)
|
||||||
_fdsRawData = romData.RawData;
|
_fdsRawData = romData.RawData;
|
||||||
|
|
||||||
//Apply save data (saved as an IPS file), if found
|
//Apply save data (saved as an IPS file), if found
|
||||||
vector<uint8_t> ipsData = BatteryManager::LoadBattery(".ips");
|
vector<uint8_t> ipsData = _console->GetBatteryManager()->LoadBattery(".ips");
|
||||||
LoadDiskData(ipsData);
|
LoadDiskData(ipsData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ vector<uint8_t> FDS::CreateIpsPatch()
|
||||||
void FDS::SaveBattery()
|
void FDS::SaveBattery()
|
||||||
{
|
{
|
||||||
vector<uint8_t> ipsData = CreateIpsPatch();
|
vector<uint8_t> ipsData = CreateIpsPatch();
|
||||||
BatteryManager::SaveBattery(".ips", ipsData.data(), (uint32_t)ipsData.size());
|
_console->GetBatteryManager()->SaveBattery(".ips", ipsData.data(), (uint32_t)ipsData.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FDS::Reset(bool softReset)
|
void FDS::Reset(bool softReset)
|
||||||
|
|
|
@ -112,7 +112,7 @@ bool MesenMovie::Play(VirtualFile &file)
|
||||||
|
|
||||||
_console->Pause();
|
_console->Pause();
|
||||||
|
|
||||||
BatteryManager::SetBatteryProvider(shared_from_this());
|
_console->GetBatteryManager()->SetBatteryProvider(shared_from_this());
|
||||||
_console->GetNotificationManager()->RegisterNotificationListener(shared_from_this());
|
_console->GetNotificationManager()->RegisterNotificationListener(shared_from_this());
|
||||||
ApplySettings();
|
ApplySettings();
|
||||||
|
|
||||||
|
|
|
@ -40,12 +40,12 @@ bool MovieRecorder::Record(RecordMovieOptions options)
|
||||||
_console->Pause();
|
_console->Pause();
|
||||||
|
|
||||||
if(options.RecordFrom == RecordMovieFrom::StartWithoutSaveData) {
|
if(options.RecordFrom == RecordMovieFrom::StartWithoutSaveData) {
|
||||||
BatteryManager::SetBatteryProvider(shared_from_this());
|
_console->GetBatteryManager()->SetBatteryProvider(shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save existing battery files
|
//Save existing battery files
|
||||||
if(options.RecordFrom == RecordMovieFrom::StartWithSaveData) {
|
if(options.RecordFrom == RecordMovieFrom::StartWithSaveData) {
|
||||||
BatteryManager::SetBatteryRecorder(shared_from_this());
|
_console->GetBatteryManager()->SetBatteryRecorder(shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
||||||
_console->GetNotificationManager()->RegisterNotificationListener(shared_from_this());
|
_console->GetNotificationManager()->RegisterNotificationListener(shared_from_this());
|
||||||
|
@ -56,7 +56,7 @@ bool MovieRecorder::Record(RecordMovieOptions options)
|
||||||
} else {
|
} else {
|
||||||
_console->PowerCycle();
|
_console->PowerCycle();
|
||||||
}
|
}
|
||||||
BatteryManager::SetBatteryRecorder(nullptr);
|
_console->GetBatteryManager()->SetBatteryRecorder(nullptr);
|
||||||
_console->Resume();
|
_console->Resume();
|
||||||
|
|
||||||
MessageManager::DisplayMessage("Movies", "MovieRecordingTo", FolderUtilities::GetFilename(_filename, true));
|
MessageManager::DisplayMessage("Movies", "MovieRecordingTo", FolderUtilities::GetFilename(_filename, true));
|
||||||
|
@ -238,7 +238,8 @@ bool MovieRecorder::CreateMovie(string movieFile, std::deque<RewindData> &data,
|
||||||
if(startPosition < data.size() && endPosition <= data.size() && _writer->Initialize(_filename)) {
|
if(startPosition < data.size() && endPosition <= data.size() && _writer->Initialize(_filename)) {
|
||||||
vector<shared_ptr<BaseControlDevice>> devices = _console->GetControlManager()->GetControlDevices();
|
vector<shared_ptr<BaseControlDevice>> devices = _console->GetControlManager()->GetControlDevices();
|
||||||
|
|
||||||
if(startPosition > 0) {
|
if(startPosition > 0 || _console->GetRomInfo().HasBattery) {
|
||||||
|
//Create a movie from a savestate if we don't start from the beginning (or if the game has save ram)
|
||||||
_hasSaveState = true;
|
_hasSaveState = true;
|
||||||
_saveStateData = stringstream();
|
_saveStateData = stringstream();
|
||||||
_console->GetSaveStateManager()->GetSaveStateHeader(_saveStateData);
|
_console->GetSaveStateManager()->GetSaveStateHeader(_saveStateData);
|
||||||
|
|
Loading…
Add table
Reference in a new issue