#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2023 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library 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 IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_PLATFORM_PLATFORM_WINDOWSFILEAPI_H #define NUCLEX_PLATFORM_PLATFORM_WINDOWSFILEAPI_H #include "Nuclex/Platform/Config.h" #if defined(NUCLEX_PLATFORM_WINDOWS) #include "WindowsApi.h" #include // for std::uint64_t #include // for std::vector namespace Nuclex { namespace Platform { namespace Platform { // ------------------------------------------------------------------------------------------- // /// Wraps file access functions from the Windows file system API class WindowsFileApi { /// Opens the active screen buffer for the process console window /// /// Whether to throw an exception if no console screen buffer exists /// /// The handle of the process' active console screen buffer public: static HANDLE OpenActiveConsoleScreenBuffer( bool throwIfNoneExists = true ); /// /// Opens an existing file for read access while allowing other processes to access it /// /// Path to the file or volume to open for shared reading /// Permissions to request for the file handle /// The handle representing the opened file or volume /// /// An invalid handle (INVALID_HANDLE_VALUE) will be returned if /// the file cannot be found or the process lacks permissions. All other problems /// will result in exception being thrown. /// public: static HANDLE TryOpenExistingFileForSharedReading( const std::wstring &path, DWORD permissions = GENERIC_READ ); /// Closes the specified file /// Handle of the file that will be closed /// /// Whether to throw an exception if the file cannot be closed /// public: static void CloseFile(HANDLE fileHandle, bool throwOnError = true); /// /// Starts a volume enumeration and provides the name of the first volume /// /// Receives the name of the first volume /// /// The volume enumeration handle which needs to be closed again using /// the method /// public: static ::HANDLE FindFirstVolume(std::wstring &volumeName); /// Advances to the next volume in an active volume enumeration /// /// Handle returned by that will be advanced /// to the next storage volume on the system /// /// /// Receives the name of the next storage volume unless the enumeration ended /// /// /// True if the next volume name was written into the /// parameter, false if the enumeration had reached the last volume /// public: static bool FindNextVolume(::HANDLE findHandle, std::wstring &volumeName); /// Closes a storage volume numeration handle /// /// Volume enumeration handle originally obtained via /// the method. /// /// /// Whether to throw an exception if the handle could not be closed. /// Can be set to false if this method is used in RAII-like scopes. /// public: static void FindVolumeClose(::HANDLE findHandle, bool throwOnError = true); /// Retrieves the paths mapped to a volume /// /// Name of the volume, this must be a volume name in the form that is returend by /// . /// /// /// Receives the path names that are mapped to the volume /// /// /// True if the volume name was valid and could be checked (the number of paths /// returned may still be zero) /// public: static bool TryGetVolumePathNamesForVolumeName( const std::wstring &volumeName, std::vector &pathNames ); /// Retrieves informations about a storage volume /// /// Name of the volume for which informations will be queried /// /// Receives the serial number of the volume /// Label the user has given the volume /// The name of the file system used on the volume /// /// True if the information about the volume could be queried, /// false if there was a permission problem or the medium was missing (disc drives), /// all other errors lead to an exception being thrown. /// public: static bool TryGetVolumeInformation( const std::wstring &volumeName, DWORD &serialNumber, std::string &label, std::string &fileSystem ); /// Queries the amount of free and total disk space of a partition /// Path of a volume or directory with trailing slash /// Receives the number of free bytes on the partition /// Receives the capacity, in bytes, of the partition /// /// True if the information was obtained, false if one of the acceptable error cases /// happened and the system (or Wine) is unable to provide the information. /// public: static bool TryGetDiskFreeSpace( const std::wstring &path, std::uint64_t &freeByteCount, std::uint64_t &totalByteCount ); }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Platform::Platform #endif // defined(NUCLEX_PLATFORM_WINDOWS) #endif // NUCLEX_PLATFORM_PLATFORM_WINDOWSFILEAPI_H