#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 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_STORAGE_FILESYSTEM_WINRTFILEAPI_H #define NUCLEX_STORAGE_FILESYSTEM_WINRTFILEAPI_H #include "Nuclex/Storage/Config.h" #if defined(NUCLEX_STORAGE_WINRT) #include "../../Helpers/WindowsWithoutDefines.h" #include #include namespace Nuclex { namespace Storage { namespace FileSystem { // ------------------------------------------------------------------------------------------- // /// Wraps the WinRT file system API /// /// /// This is just a small helper class that reduces the amount of boilerplate code /// required when calling the file system API functions from WinRT, such as /// checking result codes and transforming paths from UTF-8 to UCS-2/UTF-16. /// /// /// It is not intended to hide operating system details or make this API platform /// neutral (the File and Container classes do that), so depending on the amount /// of noise required by the file system APIs of other operating systems there might /// exist similar classes. /// /// class WinRTFileApi { /// Creates the specified directory chain /// Path that will be created public: static void CreateDirectory(const std::string &path); /// Creates all directories down to the specified path /// Directory that will be created recursively public: static void CreateDirectoryRecursively(const std::string &directory); /// Deletes a directory and everything in it /// Path of the directory that will be deleted public: static void DeleteDirectory(const std::string &path); /// Deletes a file /// Path of the file that will be deleted public: static void DeleteFile(const std::string &path); /// Retrieves the attributes of the file in the specified path /// Path of the file whose attributes will be retrieved /// The attributes of the specified public: static DWORD GetFileAttributes(const std::string &path); /// /// Retrieves the extended attributes of the file in the specified path /// /// Path of the file whose attributes will be retrieved /// Receives the attributes of the file /// /// True if the attributes were retrieved, false if the file doesn't exist /// public: static bool GetFileAttributesEx( const std::string &path, WIN32_FILE_ATTRIBUTE_DATA &fileAttributeData ); /// Opens the specified file for shared reading /// Path of the file that will be opened /// The handle of the opened file public: static HANDLE OpenFileForReading(const std::string &path); /// Creates or opens the specified file for exclusive writing /// Path of the file that will be opened /// The handle of the opened file public: static HANDLE OpenFileForWriting(const std::string &path); /// Moves the file cursor for the specified file /// File whose file cursor will be moved /// Location the file cursor will be moved to public: static std::uint64_t SetFilePointer(HANDLE fileHandle, std::uint64_t location); /// Determines the length of the specified file /// Handle of the file whose length will be determined /// The length of the specified file in bytes public: static std::uint64_t GetFileSize(HANDLE fileHandle); /// Reads data from the specified file /// Handle of the file from which data will be read /// Buffer into which the data will be put /// Number of bytes that will be read from the file /// The number of bytes that were actually read public: static std::size_t Read(HANDLE fileHandle, void *buffer, std::size_t count); /// Writes data into the specified file /// Handle of the file into which data will be written /// Buffer containing the data that will be written /// Number of bytes that will be written into the file /// The number of bytes that were actually written public: static std::size_t Write(HANDLE fileHandle, const void *buffer, std::size_t count); /// Ensures changes to the specified file have been written to disk /// Handle of the file that will be flushed public: static void FlushFileBuffers(HANDLE fileHandle); /// 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); /// Finds the first file matching the specified search mask /// Search mask controlling which files will be found /// Receives the first found file or directory /// The handle of the file search or INVALID_HANDLE_VALUE if none found public: static HANDLE FindFirstFile( const std::string &searchMask, WIN32_FIND_DATAW &findData ); /// Advances to the next file in a file search /// Search handle returned by FindFirstFile() /// Receives the next found file or directory /// True if there was a next file, otherwise false public: static bool FindNextFile(HANDLE searchHandle, WIN32_FIND_DATAW &findData); /// Closes the specified search handle /// Handle of the search that will be closed /// /// Whether to throw an exception if the search handle cannot be closed /// public: static void CloseSearch(HANDLE searchHandle, bool throwOnError = true); /// Creates all directories down to the specified path /// Directory that will be created recursively /// /// The provided directory must not be terminated with a path separator. /// private: static void createDirectoryRecursively(const std::wstring &directory); /// Recursively deletes the specified directory and all its contents /// Absolute path of the directory that will be deleted /// /// The path must not be terminated with a path separator. /// private: static void recursiveDeleteDirectory(const std::wstring &path); /// Retrieves the attributes of the specified file /// Path of the file whose attribute will be retrieved /// The file's attributes or INVALID_FILE_ATTRIBUTES if not found private: static bool getFileAttributesEx( const std::wstring &path, WIN32_FILE_ATTRIBUTE_DATA &fileAttributeData ); }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Storage::FileSystem #endif // defined(NUCLEX_STORAGE_WINRT) #endif // NUCLEX_STORAGE_FILESYSTEM_WINRTFILEAPI_H