2023-12-22 11:57:49 +00:00
|
|
|
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0+
|
2009-07-23 23:30:19 +00:00
|
|
|
|
2009-10-29 13:51:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-05-18 13:27:23 +00:00
|
|
|
#include "common/Pcsx2Defs.h"
|
|
|
|
|
2022-05-19 14:46:33 +00:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2022-05-19 14:46:33 +00:00
|
|
|
namespace Path
|
|
|
|
{
|
|
|
|
/// Converts any forward slashes to backslashes on Win32.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string ToNativePath(const std::string_view path);
|
2022-05-19 14:46:33 +00:00
|
|
|
void ToNativePath(std::string* path);
|
2021-12-24 22:48:52 +00:00
|
|
|
|
2022-05-19 14:46:33 +00:00
|
|
|
/// Builds a path relative to the specified file
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string BuildRelativePath(const std::string_view filename, const std::string_view new_filename);
|
2021-12-24 22:48:52 +00:00
|
|
|
|
2022-05-19 14:46:33 +00:00
|
|
|
/// Joins path components together, producing a new path.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string Combine(const std::string_view base, const std::string_view next);
|
2009-02-22 12:08:05 +00:00
|
|
|
|
2022-05-19 14:46:33 +00:00
|
|
|
/// Removes all .. and . components from a path.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string Canonicalize(const std::string_view path);
|
2022-05-19 14:46:33 +00:00
|
|
|
void Canonicalize(std::string* path);
|
|
|
|
|
|
|
|
/// Sanitizes a filename for use in a filesystem.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string SanitizeFileName(const std::string_view str, bool strip_slashes = true);
|
2022-09-17 07:44:38 +00:00
|
|
|
void SanitizeFileName(std::string* str, bool strip_slashes = true);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
2023-07-04 10:56:13 +00:00
|
|
|
/// Returns true if the specified filename is valid on this operating system.
|
2024-05-14 23:42:40 +00:00
|
|
|
bool IsValidFileName(const std::string_view str, bool allow_slashes = false);
|
2023-07-04 10:56:13 +00:00
|
|
|
|
2022-05-19 14:46:33 +00:00
|
|
|
/// Returns true if the specified path is an absolute path (C:\Path on Windows or /path on Unix).
|
2024-05-14 23:42:40 +00:00
|
|
|
bool IsAbsolute(const std::string_view path);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
2023-12-10 15:47:14 +00:00
|
|
|
/// Resolves any symbolic links in the specified path.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string RealPath(const std::string_view path);
|
2023-12-10 15:47:14 +00:00
|
|
|
|
2022-05-19 14:46:33 +00:00
|
|
|
/// Makes the specified path relative to another (e.g. /a/b/c, /a/b -> ../c).
|
|
|
|
/// Both paths must be relative, otherwise this function will just return the input path.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string MakeRelative(const std::string_view path, const std::string_view relative_to);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
|
|
|
/// Returns a view of the extension of a filename.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string_view GetExtension(const std::string_view path);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
|
|
|
/// Removes the extension of a filename.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string_view StripExtension(const std::string_view path);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
|
|
|
/// Replaces the extension of a filename with another.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string ReplaceExtension(const std::string_view path, const std::string_view new_extension);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
|
|
|
/// Returns the directory component of a filename.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string_view GetDirectory(const std::string_view path);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
|
|
|
/// Returns the filename component of a filename.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string_view GetFileName(const std::string_view path);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
|
|
|
/// Returns the file title (less the extension and path) from a filename.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string_view GetFileTitle(const std::string_view path);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
|
|
|
/// Changes the filename in a path.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string ChangeFileName(const std::string_view path, const std::string_view new_filename);
|
|
|
|
void ChangeFileName(std::string* path, const std::string_view new_filename);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
|
|
|
/// Appends a directory to a path.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::string AppendDirectory(const std::string_view path, const std::string_view new_dir);
|
|
|
|
void AppendDirectory(std::string* path, const std::string_view new_dir);
|
2022-05-19 14:46:33 +00:00
|
|
|
|
|
|
|
/// Splits a path into its components, handling both Windows and Unix separators.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::vector<std::string_view> SplitWindowsPath(const std::string_view path);
|
2022-05-19 14:46:33 +00:00
|
|
|
std::string JoinWindowsPath(const std::vector<std::string_view>& components);
|
|
|
|
|
|
|
|
/// Splits a path into its components, only handling native separators.
|
2024-05-14 23:42:40 +00:00
|
|
|
std::vector<std::string_view> SplitNativePath(const std::string_view path);
|
2022-05-19 14:46:33 +00:00
|
|
|
std::string JoinNativePath(const std::vector<std::string_view>& components);
|
2024-03-13 09:51:44 +00:00
|
|
|
|
|
|
|
/// URL encodes the specified string.
|
|
|
|
std::string URLEncode(std::string_view str);
|
|
|
|
|
|
|
|
/// Decodes the specified escaped string.
|
|
|
|
std::string URLDecode(std::string_view str);
|
|
|
|
|
|
|
|
/// Returns a URL for a given path. The path should be absolute.
|
|
|
|
std::string CreateFileURL(std::string_view path);
|
2021-09-06 18:28:26 +00:00
|
|
|
} // namespace Path
|