/** * @file * * @author Max Lammers * @author Mamadou Babaei * * @section LICENSE * * Copyright (c) 2020 - 2026 SenseGlove * * @section DESCRIPTION * * File Input/output handling. */ #pragma once #include #include #include namespace SGCommon { class SGCOMMON_API FileIO; }// namespace SGCommon class SGCOMMON_API SGCommon::FileIO { public: SG_FORCEINLINE static const std::string& GetDirectorySeparator() { static const std::string separator{ #if ! SG_PLATFORM_WINDOWS "/" #else /* ! SG_PLATFORM_WINDOWS */ "\\" #endif /* ! SG_PLATFORM_WINDOWS */ }; return separator; } SG_FORCEINLINE static char GetDirectorySeparatorChar() { return GetDirectorySeparator().c_str()[0]; } /// Attempt to read all lines from a file and place them in the string[]. Returns true if successful. /// If unable to open the file, the string[] will be empty. /// /// /// static bool ReadTextFile(const std::string& filePath, std::vector& out_lines); /// Attempt to save a string[] to a filename within a desired directory. Returns true if successful. /// /// Directory is added as a separate variable so we can more easily check for its existence. /// /// /// /// /// static bool SaveTextFile(const std::string& directory, const std::string& fileName, const std::vector& contents, bool bAppend = false); /// Creates a new directory. Returns false if it already existed. /// /// static bool CreateFullDirectory(const std::string& directoryPath); /// Returns true if the directory exists /// /// [[nodiscard]] static bool DirectoryExists(const std::string& directoryPath); /// Returns true if this file exists /// /// static bool FileExists(const std::string& filePath); /// STUB - Gets the working directory of the current process. /// [[nodiscard]] static std::string GetWorkingDirectory(); /// Get the Path to MyDocuments, but without '\\' at the end. /// [[nodiscard]] static std::string GetMyDocumentsPath(); /// Get the Path to XDG_CONFIG_HOME on non-Windows platforms. /// [[nodiscard]] static std::string GetXdgConfigHomePath(); /// An easy way to get the SenseGlove home directory in a platform-agnostic manner, /// without the separator char at the end, unless the user specifies one through the env vars /// on non-Windows platforms. This should be fine on Linux, Android as well even if we end up /// having multiple consecutive slashes. /// [[nodiscard]] static std::string GetSenseGloveHomePath(); #if SG_PLATFORM_ANDROID static std::string& GetAndroidStoragePath(); static void SetAndroidStoragePath(const std::string& path); #endif /* SG_PLATFORM_ANDROID */ private: struct Impl; public: FileIO() = delete; virtual ~FileIO() = delete; };