From f5fe75a73b60d035ad3a6e421bc089c720332f7a Mon Sep 17 00:00:00 2001 From: Kingcom Date: Fri, 15 Aug 2014 22:48:12 +0200 Subject: [PATCH] Allow to share writing to the ISO through an ini option --- pcsx2/AsyncFileReader.h | 4 ++- pcsx2/CDVD/InputIsoFile.cpp | 5 +++- pcsx2/Config.h | 1 + pcsx2/Linux/LnxFlatFileReader.cpp | 2 +- pcsx2/Pcsx2Config.cpp | 1 + pcsx2/windows/FlatFileReaderWindows.cpp | 38 ++++++++++++++----------- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/pcsx2/AsyncFileReader.h b/pcsx2/AsyncFileReader.h index 73f5a5e572..af167682cc 100644 --- a/pcsx2/AsyncFileReader.h +++ b/pcsx2/AsyncFileReader.h @@ -75,8 +75,10 @@ class FlatFileReader : public AsyncFileReader io_context_t m_aio_context; #endif + bool shareWrite; + public: - FlatFileReader(void); + FlatFileReader(bool shareWrite = false); virtual ~FlatFileReader(void); virtual bool Open(const wxString& fileName); diff --git a/pcsx2/CDVD/InputIsoFile.cpp b/pcsx2/CDVD/InputIsoFile.cpp index 7eb8d50ff5..feab6b7ecd 100644 --- a/pcsx2/CDVD/InputIsoFile.cpp +++ b/pcsx2/CDVD/InputIsoFile.cpp @@ -201,7 +201,10 @@ bool InputIsoFile::Open( const wxString& srcfile, bool testOnly ) Close(); m_filename = srcfile; - m_reader = new FlatFileReader(); + // Allow write sharing of the iso based on the ini settings. + // Mostly useful for romhacking, where the disc is frequently + // changed and the emulator would block modifications + m_reader = new FlatFileReader(EmuConfig.CdvdShareWrite); m_reader->Open(m_filename); bool isBlockdump, isCompressed = false; diff --git a/pcsx2/Config.h b/pcsx2/Config.h index 4e662db88f..812ac03f28 100644 --- a/pcsx2/Config.h +++ b/pcsx2/Config.h @@ -433,6 +433,7 @@ struct Pcsx2Config bool CdvdVerboseReads :1, // enables cdvd read activity verbosely dumped to the console CdvdDumpBlocks :1, // enables cdvd block dumping + CdvdShareWrite :1, // allows the iso to be modified while it's loaded EnablePatches :1, // enables patch detection and application EnableCheats :1, // enables cheat detection and application EnableWideScreenPatches :1, diff --git a/pcsx2/Linux/LnxFlatFileReader.cpp b/pcsx2/Linux/LnxFlatFileReader.cpp index b19fd25863..3c8ba3c7f7 100644 --- a/pcsx2/Linux/LnxFlatFileReader.cpp +++ b/pcsx2/Linux/LnxFlatFileReader.cpp @@ -16,7 +16,7 @@ #include "PrecompiledHeader.h" #include "AsyncFileReader.h" -FlatFileReader::FlatFileReader(void) +FlatFileReader::FlatFileReader(bool shareWrite) : shareWrite(shareWrite) { m_blocksize = 2048; m_fd = 0; diff --git a/pcsx2/Pcsx2Config.cpp b/pcsx2/Pcsx2Config.cpp index 283255a2c6..7156256ef8 100644 --- a/pcsx2/Pcsx2Config.cpp +++ b/pcsx2/Pcsx2Config.cpp @@ -410,6 +410,7 @@ void Pcsx2Config::LoadSave( IniInterface& ini ) IniBitBool( CdvdVerboseReads ); IniBitBool( CdvdDumpBlocks ); + IniBitBool( CdvdShareWrite ); IniBitBool( EnablePatches ); IniBitBool( EnableCheats ); IniBitBool( EnableWideScreenPatches ); diff --git a/pcsx2/windows/FlatFileReaderWindows.cpp b/pcsx2/windows/FlatFileReaderWindows.cpp index 64709f5af5..f08cea6d4c 100644 --- a/pcsx2/windows/FlatFileReaderWindows.cpp +++ b/pcsx2/windows/FlatFileReaderWindows.cpp @@ -1,22 +1,22 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2014 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2014 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with PCSX2. + * If not, see . + */ + #include "PrecompiledHeader.h" #include "AsyncFileReader.h" -FlatFileReader::FlatFileReader(void) +FlatFileReader::FlatFileReader(bool shareWrite) : shareWrite(shareWrite) { m_blocksize = 2048; hOverlappedFile = INVALID_HANDLE_VALUE; @@ -35,10 +35,14 @@ bool FlatFileReader::Open(const wxString& fileName) hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + DWORD shareMode = FILE_SHARE_READ; + if (shareWrite) + shareMode |= FILE_SHARE_WRITE; + hOverlappedFile = CreateFile( fileName, GENERIC_READ, - FILE_SHARE_READ, + shareMode, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED,