mirror of https://github.com/PCSX2/pcsx2.git
System: Purge WinCompressNTFS.cpp
This is the most overengineered, stupid rubbish I've ever seen.
This commit is contained in:
parent
850deed6c1
commit
864651ce8d
|
@ -1183,6 +1183,38 @@ bool FileSystem::SetWorkingDirectory(const char* path)
|
|||
return (SetCurrentDirectoryW(wpath.c_str()) == TRUE);
|
||||
}
|
||||
|
||||
bool FileSystem::SetPathCompression(const char* path, bool enable)
|
||||
{
|
||||
const std::wstring wpath(StringUtil::UTF8StringToWideString(path));
|
||||
const DWORD attrs = GetFileAttributesW(wpath.c_str());
|
||||
if (attrs == INVALID_FILE_ATTRIBUTES)
|
||||
return false;
|
||||
|
||||
const bool isFile = !(attrs & FILE_ATTRIBUTE_DIRECTORY);
|
||||
const DWORD flags = isFile ? FILE_ATTRIBUTE_NORMAL : (FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_DIRECTORY);
|
||||
|
||||
const HANDLE handle = CreateFileW(wpath.c_str(),
|
||||
FILE_GENERIC_WRITE | FILE_GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_DELETE,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
flags,
|
||||
nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
DWORD bytesReturned = 0;
|
||||
DWORD compressMode = enable ? COMPRESSION_FORMAT_DEFAULT : COMPRESSION_FORMAT_NONE;
|
||||
|
||||
bool result = DeviceIoControl(
|
||||
handle, FSCTL_SET_COMPRESSION,
|
||||
&compressMode, 2, nullptr, 0,
|
||||
&bytesReturned, nullptr);
|
||||
|
||||
CloseHandle(handle);
|
||||
return result;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, const char* Path, const char* Pattern,
|
||||
|
@ -1650,4 +1682,9 @@ bool FileSystem::SetWorkingDirectory(const char* path)
|
|||
return (chdir(path) == 0);
|
||||
}
|
||||
|
||||
bool FileSystem::SetPathCompression(const char* path, bool enable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -175,4 +175,9 @@ namespace FileSystem
|
|||
/// Sets the current working directory. Returns true if successful.
|
||||
bool SetWorkingDirectory(const char* path);
|
||||
|
||||
/// Enables/disables NTFS compression on a file or directory.
|
||||
/// Does not apply the compression flag recursively if called for a directory.
|
||||
/// Does nothing and returns false on non-Windows platforms.
|
||||
bool SetPathCompression(const char* path, bool enable);
|
||||
|
||||
}; // namespace FileSystem
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "PrecompiledHeader.h"
|
||||
|
||||
#include "common/FileSystem.h"
|
||||
#include "common/StringUtil.h"
|
||||
|
||||
#include <QtWidgets/QMessageBox>
|
||||
|
@ -127,7 +128,7 @@ void CreateMemoryCardDialog::createCard()
|
|||
if (m_ui.ntfsCompression->isChecked() && m_type == MemoryCardType::File)
|
||||
{
|
||||
const std::string fullPath(Path::CombineStdString(EmuFolders::MemoryCards, nameStr));
|
||||
NTFS_CompressFile(StringUtil::UTF8StringToWxString(fullPath), true);
|
||||
FileSystem::SetPathCompression(fullPath.c_str(), true);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1394,7 +1394,6 @@ set(pcsx2WindowsSources
|
|||
windows/FlatFileReaderWindows.cpp
|
||||
windows/Optimus.cpp
|
||||
windows/VCprojects/IopSif.cpp
|
||||
windows/WinCompressNTFS.cpp
|
||||
windows/WinConsolePipe.cpp
|
||||
windows/WinKeyCodes.cpp
|
||||
windows/WinPowerProfile.cpp
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
void NTFS_CompressFile( const wxString& file, bool compressStatus ) {}
|
||||
|
||||
// Returns a WXK_* keycode, given some kinda GDK input mess!
|
||||
int TranslateGDKtoWXK( u32 keysym )
|
||||
{
|
||||
|
|
|
@ -328,8 +328,8 @@ void FileMemoryCard::Open()
|
|||
// [TODO] : Add memcard size detection and report it to the console log.
|
||||
// (8MB, 256Mb, formatted, unformatted, etc ...)
|
||||
|
||||
#ifdef __WXMSW__
|
||||
NTFS_CompressFile(str, EmuConfig.McdCompressNTFS);
|
||||
#ifdef _WIN32
|
||||
FileSystem::SetPathCompression(StringUtil::wxStringToUTF8String(str).c_str(), EmuConfig.McdCompressNTFS);
|
||||
#endif
|
||||
|
||||
if (str.EndsWith(".bin"))
|
||||
|
|
|
@ -163,7 +163,6 @@ extern void SysOutOfMemory_EmergencyResponse(uptr blocksize);
|
|||
|
||||
extern u8 *SysMmapEx(uptr base, u32 size, uptr bounds, const char *caller="Unnamed");
|
||||
extern void vSyncDebugStuff( uint frame );
|
||||
extern void NTFS_CompressFile( const wxString& file, bool compressStatus=true );
|
||||
|
||||
extern std::string SysGetBiosDiscID();
|
||||
extern std::string SysGetDiscID();
|
||||
|
|
|
@ -613,8 +613,8 @@ void AppApplySettings( const AppConfig* oldconf )
|
|||
// Update the compression attribute on the Memcards folder.
|
||||
// Memcards generally compress very well via NTFS compression.
|
||||
|
||||
#ifdef __WXMSW__
|
||||
NTFS_CompressFile( g_Conf->Folders.MemoryCards.ToString(), g_Conf->EmuOptions.McdCompressNTFS );
|
||||
#ifdef _WIN32
|
||||
FileSystem::SetPathCompression( g_Conf->Folders.MemoryCards.ToUTF8(), g_Conf->EmuOptions.McdCompressNTFS );
|
||||
#endif
|
||||
sApp.DispatchEvent( AppStatus_SettingsApplied );
|
||||
|
||||
|
|
|
@ -713,7 +713,6 @@
|
|||
<ClCompile Include="gui\Panels\PathsPanel.cpp" />
|
||||
<ClCompile Include="gui\Panels\SpeedhacksPanel.cpp" />
|
||||
<ClCompile Include="gui\Panels\VideoPanel.cpp" />
|
||||
<ClCompile Include="windows\WinCompressNTFS.cpp" />
|
||||
<ClCompile Include="windows\WinConsolePipe.cpp" />
|
||||
<ClCompile Include="windows\WinPowerProfile.cpp" />
|
||||
<ClCompile Include="Linux\LnxKeyCodes.cpp">
|
||||
|
|
|
@ -896,9 +896,6 @@
|
|||
<ClCompile Include="gui\Panels\VideoPanel.cpp">
|
||||
<Filter>AppHost\Panels</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="windows\WinCompressNTFS.cpp">
|
||||
<Filter>AppHost\Win32</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="windows\WinConsolePipe.cpp">
|
||||
<Filter>AppHost\Win32</Filter>
|
||||
</ClCompile>
|
||||
|
@ -3101,4 +3098,4 @@
|
|||
<Filter>AppHost\Resources</Filter>
|
||||
</Manifest>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -311,7 +311,6 @@
|
|||
<ClCompile Include="Dump.cpp" />
|
||||
<ClCompile Include="VMManager.cpp" />
|
||||
<ClCompile Include="windows\Optimus.cpp" />
|
||||
<ClCompile Include="windows\WinCompressNTFS.cpp" />
|
||||
<ClCompile Include="x86\iMisc.cpp" />
|
||||
<ClCompile Include="Pcsx2Config.cpp" />
|
||||
<ClCompile Include="windows\FlatFileReaderWindows.cpp" />
|
||||
|
|
|
@ -1241,9 +1241,6 @@
|
|||
<ClCompile Include="windows\Optimus.cpp">
|
||||
<Filter>Host</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="windows\WinCompressNTFS.cpp">
|
||||
<Filter>Host</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GS\Renderers\HW\GSTextureReplacements.cpp">
|
||||
<Filter>System\Ps2\GS\Renderers\Hardware</Filter>
|
||||
</ClCompile>
|
||||
|
@ -2097,4 +2094,4 @@
|
|||
<Filter>System\Ps2\Debug\rdebug</Filter>
|
||||
</CustomBuildStep>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
/* PCSX2 - PS2 Emulator for PCs
|
||||
* Copyright (C) 2002-2010 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Win32.h"
|
||||
#include <winioctl.h>
|
||||
|
||||
// Throws an exception based on the value returned from GetLastError.
|
||||
// Performs an option return value success/fail check on hresult.
|
||||
void StreamException_ThrowLastError( const wxString& streamname, HANDLE result )
|
||||
{
|
||||
if( result != INVALID_HANDLE_VALUE ) return;
|
||||
|
||||
int error = GetLastError();
|
||||
|
||||
switch( error )
|
||||
{
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
throw Exception::FileNotFound( streamname );
|
||||
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
throw Exception::FileNotFound( streamname );
|
||||
|
||||
case ERROR_TOO_MANY_OPEN_FILES:
|
||||
throw Exception::CannotCreateStream( streamname ).SetDiagMsg(L"Too many open files");
|
||||
|
||||
case ERROR_ACCESS_DENIED:
|
||||
throw Exception::AccessDenied( streamname );
|
||||
|
||||
case ERROR_INVALID_HANDLE:
|
||||
throw Exception::BadStream( streamname ).SetDiagMsg(L"Stream object or handle is invalid");
|
||||
|
||||
case ERROR_SHARING_VIOLATION:
|
||||
throw Exception::AccessDenied( streamname ).SetDiagMsg(L"Sharing violation");
|
||||
|
||||
default:
|
||||
{
|
||||
throw Exception::BadStream( streamname ).SetDiagMsg(pxsFmt( L"General Win32 File/stream error [GetLastError: %d]", error ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// returns TRUE if an error occurred.
|
||||
bool StreamException_LogLastError( const wxString& streamname, const wxChar* action, HANDLE result )
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamException_ThrowLastError( streamname, result );
|
||||
}
|
||||
catch( Exception::BadStream& ex )
|
||||
{
|
||||
Console.WriteLn( Color_Yellow, L"%s: %s", action, ex.FormatDiagnosticMessage().c_str() );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sets the NTFS compression flag for a directory or file. This function does not operate
|
||||
// recursively. Set compressStatus to false to decompress compressed files (and do nothing
|
||||
// to already decompressed files).
|
||||
//
|
||||
// Exceptions thrown: None.
|
||||
// (Errors are logged to console. Failures are considered non-critical)
|
||||
//
|
||||
void NTFS_CompressFile( const wxString& file, bool compressStatus )
|
||||
{
|
||||
bool isFile = !wxDirExists( file );
|
||||
|
||||
if( isFile && !wxFileExists( file ) ) return;
|
||||
if( GetFileAttributes(file) & FILE_ATTRIBUTE_COMPRESSED ) return;
|
||||
if( !wxIsWritable( file ) ) return;
|
||||
|
||||
const DWORD flags = isFile ? FILE_ATTRIBUTE_NORMAL : (FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_DIRECTORY);
|
||||
|
||||
HANDLE bloated_crap = CreateFile( file,
|
||||
FILE_GENERIC_WRITE | FILE_GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_DELETE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
flags,
|
||||
NULL
|
||||
);
|
||||
|
||||
// Fail silently -- non-compression of files and folders is not an errorable offense.
|
||||
|
||||
if( !StreamException_LogLastError( file, L"NTFS Compress Notice", bloated_crap ) )
|
||||
{
|
||||
DWORD bytesReturned = 0;
|
||||
DWORD compressMode = compressStatus ? COMPRESSION_FORMAT_DEFAULT : COMPRESSION_FORMAT_NONE;
|
||||
|
||||
/*BOOL result = */DeviceIoControl(
|
||||
bloated_crap, FSCTL_SET_COMPRESSION,
|
||||
&compressMode, 2, NULL, 0,
|
||||
&bytesReturned, NULL
|
||||
);
|
||||
|
||||
// No need to see this every time on my exFAT drive (rama)
|
||||
//if( !result )
|
||||
// StreamException_LogLastError( file, L"NTFS Compress Notice" );
|
||||
|
||||
CloseHandle( bloated_crap );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue