86 lines
2.9 KiBLFS
C++
86 lines
2.9 KiBLFS
C++
/**
|
|
* @file
|
|
*
|
|
* @author Max Lammers <max@senseglove.com>
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @section LICENSE
|
|
*
|
|
* Copyright (c) 2020 - 2023 SenseGlove
|
|
*
|
|
* @section DESCRIPTION
|
|
*
|
|
* File Input/output handling
|
|
*/
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "Platform.hpp"
|
|
|
|
namespace SGCore
|
|
{
|
|
namespace Util
|
|
{
|
|
class SGCORE_API FileIO;
|
|
}// namespace Util
|
|
}// namespace SGCore
|
|
|
|
class SGCORE_API SGCore::Util::FileIO
|
|
{
|
|
public:
|
|
/// <summary> 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.</summary>
|
|
/// <param name="filePath"></param>
|
|
/// <param name="out_lines"></param>
|
|
/// <returns></returns>
|
|
static bool ReadTextFile(const std::string& filePath, std::vector<std::string>& out_lines);
|
|
|
|
/// <summary> Attempt to save a string[] to a filename within a desired directory. Returns true if successful. </summary>
|
|
/// <remarks> Directory is added as a separate variable so we can more easily check for its existence. </remarks>
|
|
/// <param name="directory"></param>
|
|
/// <param name="fileName"></param>
|
|
/// <param name="contents"></param>
|
|
/// <param name="append"></param>
|
|
/// <returns></returns>
|
|
static bool SaveTextFile(const std::string& directory, const std::string& fileName,
|
|
const std::vector<std::string>& contents, bool bAppend = false);
|
|
|
|
/// <summary> Creates a new directory. Returns false if it already existed. </summary>
|
|
/// <param name="directory"></param>
|
|
/// <returns></returns>
|
|
static bool CreateFullDirectory(const std::string& directoryPath);
|
|
|
|
/// <summary> Returns true if the directory exists </summary>
|
|
/// <param name="dir"></param>
|
|
/// <returns></returns>
|
|
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
|
|
[[nodiscard]]
|
|
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
|
|
static bool DirectoryExists(const std::string& directoryPath);
|
|
|
|
/// <summary> Returns true if this file exists </summary>
|
|
/// <param name="filePath"></param>
|
|
/// <returns></returns>
|
|
static bool FileExists(const std::string& filePath);
|
|
|
|
/// <summary> STUB - Gets the working directory of the current process. </summary>
|
|
/// <returns></returns>
|
|
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
|
|
[[nodiscard]]
|
|
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
|
|
static std::string GetWorkingDirectory();
|
|
|
|
/// <summary> Get the Path to MyDocuments, but without '\\' at the nnd </summary>
|
|
/// <returns></returns>
|
|
#if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN )
|
|
[[nodiscard]]
|
|
#endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */
|
|
static std::string GetMyDocumentsPath();
|
|
|
|
public:
|
|
FileIO() = delete;
|
|
virtual ~FileIO() = delete;
|
|
}; |