2020-09-09 00:54:16 -04:00
|
|
|
#pragma once
|
2020-11-21 12:52:38 -05:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @file FileUtil.h
|
|
|
|
* Utility functions for reading and writing files.
|
|
|
|
*/
|
|
|
|
|
2022-07-05 20:38:13 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define NOMINMAX
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "third-party/filesystem.hpp"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#undef FALSE
|
|
|
|
#endif
|
|
|
|
|
2022-04-03 19:17:03 -04:00
|
|
|
#include <optional>
|
2022-07-06 18:10:38 -04:00
|
|
|
#include <regex>
|
2022-06-22 23:37:46 -04:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-03-06 16:06:08 -05:00
|
|
|
#include "common/common_types.h"
|
2023-04-22 14:13:57 -04:00
|
|
|
#include "common/versions/versions.h"
|
2020-09-09 00:54:16 -04:00
|
|
|
|
2022-07-05 20:38:13 -04:00
|
|
|
namespace fs = ghc::filesystem;
|
2021-05-20 14:18:28 -04:00
|
|
|
|
2020-09-10 20:03:31 -04:00
|
|
|
namespace file_util {
|
2022-07-05 20:38:13 -04:00
|
|
|
fs::path get_user_home_dir();
|
|
|
|
fs::path get_user_config_dir();
|
2022-08-21 18:13:27 -04:00
|
|
|
fs::path get_user_settings_dir(GameVersion game_version);
|
|
|
|
fs::path get_user_memcard_dir(GameVersion game_version);
|
2022-11-19 23:28:20 -05:00
|
|
|
fs::path get_user_misc_dir(GameVersion game_version);
|
2022-07-05 20:38:13 -04:00
|
|
|
fs::path get_jak_project_dir();
|
2022-03-20 20:29:44 -04:00
|
|
|
|
2022-07-05 20:38:13 -04:00
|
|
|
bool create_dir_if_needed(const fs::path& path);
|
2022-03-20 20:29:44 -04:00
|
|
|
bool create_dir_if_needed_for_file(const std::string& path);
|
2022-07-05 20:38:13 -04:00
|
|
|
bool create_dir_if_needed_for_file(const fs::path& path);
|
2023-05-21 17:24:23 -04:00
|
|
|
std::optional<std::string> try_get_project_path_from_path(const std::string& path);
|
2022-07-05 20:38:13 -04:00
|
|
|
bool setup_project_path(std::optional<fs::path> project_path_override);
|
2022-04-03 19:17:03 -04:00
|
|
|
std::string get_file_path(const std::vector<std::string>& path);
|
2021-02-05 19:41:09 -05:00
|
|
|
void write_binary_file(const std::string& name, const void* data, size_t size);
|
2022-07-05 20:38:13 -04:00
|
|
|
void write_binary_file(const fs::path& name, const void* data, size_t size);
|
|
|
|
void write_rgba_png(const fs::path& name, void* data, int w, int h);
|
2020-09-10 20:03:31 -04:00
|
|
|
void write_text_file(const std::string& file_name, const std::string& text);
|
2022-07-05 20:38:13 -04:00
|
|
|
void write_text_file(const fs::path& file_name, const std::string& text);
|
2020-09-10 20:03:31 -04:00
|
|
|
std::vector<uint8_t> read_binary_file(const std::string& filename);
|
2022-07-05 20:38:13 -04:00
|
|
|
std::vector<uint8_t> read_binary_file(const fs::path& filename);
|
2020-09-10 20:03:31 -04:00
|
|
|
std::string read_text_file(const std::string& path);
|
2022-07-05 20:38:13 -04:00
|
|
|
std::string read_text_file(const fs::path& path);
|
2020-09-10 20:03:31 -04:00
|
|
|
bool is_printable_char(char c);
|
2020-10-25 02:26:35 -04:00
|
|
|
std::string combine_path(const std::string& parent, const std::string& child);
|
2022-02-12 17:48:50 -05:00
|
|
|
bool file_exists(const std::string& path);
|
2020-10-25 02:26:35 -04:00
|
|
|
std::string base_name(const std::string& filename);
|
2022-11-29 19:22:22 -05:00
|
|
|
std::string base_name_no_ext(const std::string& filename);
|
2023-01-28 20:15:58 -05:00
|
|
|
std::string split_path_at(const fs::path& path, const std::vector<std::string>& folders);
|
|
|
|
std::string convert_to_unix_path_separators(const std::string& path);
|
2020-11-21 15:58:51 -05:00
|
|
|
void MakeISOName(char* dst, const char* src);
|
|
|
|
void ISONameFromAnimationName(char* dst, const char* src);
|
2020-11-22 12:59:55 -05:00
|
|
|
void assert_file_exists(const char* path, const char* error_message);
|
2021-03-06 16:06:08 -05:00
|
|
|
bool dgo_header_is_compressed(const std::vector<u8>& data);
|
|
|
|
std::vector<u8> decompress_dgo(const std::vector<u8>& data_in);
|
2022-08-05 12:25:35 -04:00
|
|
|
FILE* open_file(const fs::path& path, const std::string& mode);
|
2023-08-08 20:49:01 -04:00
|
|
|
std::vector<fs::path> find_files_in_dir(const fs::path& dir, const std::regex& pattern);
|
2022-08-05 12:25:35 -04:00
|
|
|
std::vector<fs::path> find_files_recursively(const fs::path& base_dir, const std::regex& pattern);
|
2023-01-07 11:24:02 -05:00
|
|
|
std::vector<fs::path> find_directories_in_dir(const fs::path& base_dir);
|
2023-08-08 12:59:37 -04:00
|
|
|
std::vector<fs::path> sort_filepaths(const std::vector<fs::path>& paths, const bool aescending);
|
2023-03-01 17:52:33 -05:00
|
|
|
/// Will overwrite the destination if it exists
|
2023-02-26 17:56:25 -05:00
|
|
|
void copy_file(const fs::path& src, const fs::path& dst);
|
2023-06-04 15:34:37 -04:00
|
|
|
std::string make_screenshot_filepath(const GameVersion game_version, const std::string& name = "");
|
2020-09-10 20:03:31 -04:00
|
|
|
} // namespace file_util
|