From: <man...@us...> - 2015-05-25 09:12:40
|
Revision: 5163 http://sourceforge.net/p/modplug/code/5163 Author: manxorist Date: 2015-05-25 09:12:34 +0000 (Mon, 25 May 2015) Log Message: ----------- [Ref] mptIO: Implement SetFilesystemCompression helper function for tracker builds. Works on mpt::PathString, HANDLE, fd, FILE*. Requires read and write permissions for already opened files. [Ref] Convert crash writer to SetFilesystemCompression. Modified Paths: -------------- trunk/OpenMPT/common/mptFileIO.cpp trunk/OpenMPT/common/mptFileIO.h trunk/OpenMPT/mptrack/ExceptionHandler.cpp Modified: trunk/OpenMPT/common/mptFileIO.cpp =================================================================== --- trunk/OpenMPT/common/mptFileIO.cpp 2015-05-25 00:55:20 UTC (rev 5162) +++ trunk/OpenMPT/common/mptFileIO.cpp 2015-05-25 09:12:34 UTC (rev 5163) @@ -11,14 +11,91 @@ #include "stdafx.h" #include "mptFileIO.h" +#ifdef MODPLUG_TRACKER +#if MPT_OS_WINDOWS +#include <WinIoCtl.h> +#include <io.h> +#endif // MPT_OS_WINDOWS +#endif // MODPLUG_TRACKER + OPENMPT_NAMESPACE_BEGIN #if defined(MPT_WITH_FILEIO) + + #ifdef MODPLUG_TRACKER +#if MPT_OS_WINDOWS +bool SetFilesystemCompression(HANDLE hFile) +{ + if(hFile == INVALID_HANDLE_VALUE) + { + return false; + } + USHORT format = COMPRESSION_FORMAT_DEFAULT; + DWORD dummy = 0; + BOOL result = DeviceIoControl(hFile, FSCTL_SET_COMPRESSION, (LPVOID)&format, sizeof(format), NULL, 0, &dummy /*required*/ , NULL); + return result ? true : false; +} +bool SetFilesystemCompression(int fd) +{ + if(fd < 0) + { + return false; + } + uintptr_t fhandle = _get_osfhandle(fd); + HANDLE hFile = (HANDLE)fhandle; + if(hFile == INVALID_HANDLE_VALUE) + { + return false; + } + return SetFilesystemCompression(hFile); +} +#if defined(MPT_WITH_FILEIO_STDIO) +bool SetFilesystemCompression(FILE *file) +{ + if(!file) + { + return false; + } + int fd = _fileno(file); + if(fd == -1) + { + return false; + } + return SetFilesystemCompression(fd); +} +#endif // MPT_WITH_FILEIO_STDIO +bool SetFilesystemCompression(const mpt::PathString &filename) +{ + DWORD attributes = GetFileAttributesW(filename.AsNative().c_str()); + if(attributes == INVALID_FILE_ATTRIBUTES) + { + return false; + } + if(attributes & FILE_ATTRIBUTE_COMPRESSED) + { + return true; + } + HANDLE hFile = CreateFileW(filename.AsNative().c_str(), GENERIC_ALL, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if(hFile == INVALID_HANDLE_VALUE) + { + return false; + } + bool result = SetFilesystemCompression(hFile); + CloseHandle(hFile); + hFile = INVALID_HANDLE_VALUE; + return result; +} +#endif // MPT_OS_WINDOWS +#endif // MODPLUG_TRACKER + + +#ifdef MODPLUG_TRACKER + CMappedFile::~CMappedFile() //------------------------- { Modified: trunk/OpenMPT/common/mptFileIO.h =================================================================== --- trunk/OpenMPT/common/mptFileIO.h 2015-05-25 00:55:20 UTC (rev 5162) +++ trunk/OpenMPT/common/mptFileIO.h 2015-05-25 09:12:34 UTC (rev 5163) @@ -45,6 +45,22 @@ #endif // MPT_WITH_FILEIO_STDIO +// Sets the NTFS compression attribute on the file or directory. +// Requires read and write permissions for already opened files. +// Returns true if the attribute has been set. +// In almost all cases, the return value should be ignored because most filesystems other than NTFS do not support compression. +#ifdef MODPLUG_TRACKER +#if MPT_OS_WINDOWS +bool SetFilesystemCompression(HANDLE hFile); +bool SetFilesystemCompression(int fd); +#if defined(MPT_WITH_FILEIO_STDIO) +bool SetFilesystemCompression(FILE *file); +#endif // MPT_WITH_FILEIO_STDIO +bool SetFilesystemCompression(const mpt::PathString &filename); +#endif // MPT_OS_WINDOWS +#endif // MODPLUG_TRACKER + + namespace mpt { Modified: trunk/OpenMPT/mptrack/ExceptionHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2015-05-25 00:55:20 UTC (rev 5162) +++ trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2015-05-25 09:12:34 UTC (rev 5163) @@ -18,9 +18,7 @@ #include "../common/version.h" #include "../common/mptFileIO.h" -#include <WinIoCtl.h> - OPENMPT_NAMESPACE_BEGIN @@ -52,23 +50,12 @@ { CreateDirectoryW(path.AsNative().c_str(), nullptr); } - DWORD attributes = GetFileAttributesW(path.AsNative().c_str()); - if(attributes != INVALID_FILE_ATTRIBUTES && !(attributes & FILE_ATTRIBUTE_COMPRESSED)) - { - // Set compressed attribute in order to save disk space. - // Debugging information should clutter the users computer as little as possible. - // Performance is not important here. - // Ignore any errors. - HANDLE hDir = CreateFileW(path.AsNative().c_str(), GENERIC_ALL, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); - if(hDir != INVALID_HANDLE_VALUE) - { - USHORT format = COMPRESSION_FORMAT_DEFAULT; - DWORD dummy = 0; - /* BOOL result = */ DeviceIoControl(hDir, FSCTL_SET_COMPRESSION, (LPVOID)&format, sizeof(format), NULL, 0, &dummy /*required*/ , NULL); - CloseHandle(hDir); - } - // Compression will be inherited by children directories and files automatically. - } + // Set compressed attribute in order to save disk space. + // Debugging information should clutter the users computer as little as possible. + // Performance is not important here. + // Ignore any errors. + SetFilesystemCompression(path); + // Compression will be inherited by children directories and files automatically. path += timestampDir; if(!path.IsDirectory()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |