#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 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 // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_STORAGE_SOURCE 1 #include "Nuclex/Storage/FileSystem/FileManager.h" #include "FileManagerBackend.h" #if defined(NUCLEX_STORAGE_WIN32) #include "Windows/WindowsDirectoryContainer.h" #include "Windows/WindowsFileApi.h" #else #include "Linux/LinuxDirectoryContainer.h" #include "Linux/LinuxFileApi.h" #include "Linux/XdgDirectoryResolver.h" #endif #include namespace { // ------------------------------------------------------------------------------------------- // /// Determines the directory holding the executable /// The directory the executable is stored in std::string getExecutableDirectory() { #if defined(NUCLEX_STORAGE_WIN32) std::string executablePath = ( Nuclex::Storage::FileSystem::Windows::WindowsFileApi::GetModuleFileName() ); // Cut off the executable name so only its directory remains. // I don't think GetModuleFileName() would ever return a path with forward slashes, // but both variants are valid, so we deal with both as we do everywhere else. std::string::size_type lastSlashIndex = executablePath.rfind('/'); std::string::size_type lastBackslashIndex = executablePath.rfind('\\'); if(lastSlashIndex == std::string::npos) { if(lastBackslashIndex == std::string::npos) { return std::string(u8"C:\\Windows\\Temp\\InvalidPath"); } else { return executablePath.substr(0, lastBackslashIndex); } } else { if(lastBackslashIndex == std::string::npos) { return executablePath.substr(0, lastSlashIndex); } else { return executablePath.substr(0, std::max(lastSlashIndex, lastBackslashIndex)); } } #else std::string executablePath = Nuclex::Storage::FileSystem::Linux::LinuxFileApi::ReadLink( u8"/proc/self/exe" ); // Cut off the executable name so only its directory remains std::string::size_type lastSlashIndex = executablePath.rfind('/'); if(lastSlashIndex == std::string::npos) { return std::string(u8"/tmp/invalid-path"); } else { return executablePath.substr(0, lastSlashIndex); } #endif } // ------------------------------------------------------------------------------------------- // /// Determines the directory to use for user-specific files /// Name of the application-specific directory /// The absolute path to the directory for user-specific files std::string getPersonalDirectory(const std::string &applicationName) { #if defined(NUCLEX_STORAGE_WIN32) //Windows::WindowsFileApi::GetKnownFolder() #else //Linux::XdgDirectoryResolver:: #endif return u8""; } // ------------------------------------------------------------------------------------------- // } // anonymous namespace namespace Nuclex { namespace Storage { namespace FileSystem { // ------------------------------------------------------------------------------------------- // #if defined(NUCLEX_STORAGE_WIN32) FileManager::FileManager(const std::string &applicationName) : staticDataContainer(new Windows::WindowsDirectoryContainer(getExecutableDirectory())), playerSettingsContainer( new Windows::WindowsDirectoryContainer(getPersonalDirectory(applicationName)) ), playerDataContainer(), savedGameContainer(), temporaryContainer() {} #else FileManager::FileManager(const std::string &applicationName) : staticDataContainer(new Linux::LinuxDirectoryContainer(getExecutableDirectory())), playerSettingsContainer( new Linux::LinuxDirectoryContainer(getPersonalDirectory(applicationName)) ), playerDataContainer(), savedGameContainer(), temporaryContainer() {} #endif /* // Register the built-in codecs. These archives can be read by the file manager // without any additional configuration. //RegisterContainerFileCodec(std::make_shared()); //RegisterContainerFileCodec(std::make_shared()); } */ // ------------------------------------------------------------------------------------------- // FileManager::~FileManager() {} // ------------------------------------------------------------------------------------------- // #if 0 std::shared_ptr FileManager::CreateSystemDefault( const std::string &applicationName ) { #if defined(NUCLEX_STORAGE_WIN32) return std::make_shared(applicationName); #elif defined(NUCLEX_STORAGE_WINRT) return std::make_shared(applicationName); #else return std::make_shared(applicationName); #endif } #endif // ------------------------------------------------------------------------------------------- // #if 0 void FileManager::RegisterContainerFileCodec( const std::shared_ptr &codec ) { this->Codecs->AddCodec(codec); } #endif // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Storage::FileSystem