Compare commits

...

7 Commits

Author SHA1 Message Date
chaoticgd
0c21023bb2 Path: Prevent Path::RealPath from returning '.' and '..' components 2024-12-14 13:41:01 -05:00
chaoticgd
68e6ede47e Path: Add tests for Path::RealPath 2024-12-14 13:41:01 -05:00
chaoticgd
1ed3001358 FileSystem: Add CreateSymLink function 2024-12-14 13:41:01 -05:00
chaoticgd
b8ff171127 FileSystem: Improve directory deletion test slightly 2024-12-14 13:41:01 -05:00
lightningterror
7d16a915ed GS/HW: Adjust how we handle dithering on blend mix.
Allow dither adjust regardless of alpha. usually it is clamed to 1 anyway so we can expand it if alpha max is higher than 128.

Expand dither adjust to work in rev subtract conditions.
2024-12-13 08:27:00 +01:00
lightningterror
ecc24ce2e9 GS/TC: Use proper alpha min max for palettes.
If it's an old source made from target make sure it isn't a palette, alphas need to be used from the palette then.
2024-12-13 08:27:00 +01:00
TheLastRar
65748351c7 ChdFileReader: Correct extension check 2024-12-12 08:39:28 -05:00
7 changed files with 167 additions and 17 deletions

View File

@@ -453,6 +453,11 @@ std::string Path::RealPath(const std::string_view path)
}
}
}
// If any relative symlinks were resolved, there may be '.' and '..'
// components in the resultant path, which must be removed.
realpath = Path::Canonicalize(realpath);
#endif
return realpath;
@@ -1961,6 +1966,26 @@ bool FileSystem::SetPathCompression(const char* path, bool enable)
return result;
}
bool FileSystem::CreateSymLink(const char* link, const char* target)
{
// convert to wide string
const std::wstring wlink = GetWin32Path(link);
if (wlink.empty())
return false;
const std::wstring wtarget = GetWin32Path(target);
if (wtarget.empty())
return false;
// check if it's a directory
DWORD flags = 0;
if (DirectoryExists(target))
flags |= SYMBOLIC_LINK_FLAG_DIRECTORY;
// create the symbolic link
return CreateSymbolicLinkW(wlink.c_str(), wtarget.c_str(), flags) != 0;
}
bool FileSystem::IsSymbolicLink(const char* path)
{
// convert to wide string
@@ -2541,6 +2566,11 @@ bool FileSystem::SetPathCompression(const char* path, bool enable)
return false;
}
bool FileSystem::CreateSymLink(const char* link, const char* target)
{
return symlink(target, link) == 0;
}
bool FileSystem::IsSymbolicLink(const char* path)
{
struct stat sysStatData;

View File

@@ -178,6 +178,10 @@ namespace FileSystem
/// Does nothing and returns false on non-Windows platforms.
bool SetPathCompression(const char* path, bool enable);
// Creates a symbolic link. Note that on Windows this requires elevated
// privileges so this is mostly useful for testing purposes.
bool CreateSymLink(const char* link, const char* target);
/// Checks if a file or directory is a symbolic link.
bool IsSymbolicLink(const char* path);

View File

@@ -105,7 +105,7 @@ static chd_file* OpenCHD(const std::string& filename, FileSystem::ManagedCFilePt
parent_dir.c_str(), "*.*", FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_HIDDEN_FILES | FILESYSTEM_FIND_KEEP_ARRAY, &parent_files);
for (FILESYSTEM_FIND_DATA& fd : parent_files)
{
if (StringUtil::EndsWithNoCase(Path::GetExtension(fd.FileName), ".chd"))
if (!StringUtil::EndsWithNoCase(Path::GetExtension(fd.FileName), "chd"))
continue;
// Re-check the header, it might have changed since we last opened.

View File

@@ -4553,7 +4553,8 @@ void GSRendererHW::EmulateBlending(int rt_alpha_min, int rt_alpha_max, const boo
// Disable dithering on blend mix if needed.
if (m_conf.ps.dither)
{
const bool can_dither = (m_conf.ps.blend_a == 0 && m_conf.ps.blend_b == 1 && alpha_eq_less_one);
// TODO: Either exclude BMIX1_ALPHA_HIGH_ONE case or allow alpha > 1.0 on dither adjust, case is currently disabled.
const bool can_dither = (m_conf.ps.blend_a == 0 && m_conf.ps.blend_b == 1) || (m_conf.ps.blend_a == 1 && m_conf.ps.blend_b == 0);
m_conf.ps.dither = can_dither;
m_conf.ps.dither_adjust = can_dither;
}

View File

@@ -1742,9 +1742,12 @@ GSTextureCache::Source* GSTextureCache::LookupSource(const bool is_color, const
TEX0.TBP0, psm_s.pal > 0 ? TEX0.CBP : 0,
psm_str(TEX0.PSM));
// If it's from a target, we need to make sure the alpha information is up to date, especially in 16/24 bit formats where it can change draw to draw.
// If it's an old source made from target make sure it isn't a palette,
// alphas need to be used from the palette then.
// If it's from a target, we need to make sure the alpha information is up to date,
// especially in 16/24 bit formats where it can change draw to draw.
// Guard against merged targets which don't actually link.
if (src->m_target && src->m_from_target)
if (!src->m_palette && src->m_target && src->m_from_target)
{
src->m_valid_alpha_minmax = true;
if (src->m_target_direct)

View File

@@ -7,8 +7,6 @@
#ifdef __linux__
#include <unistd.h>
static std::optional<std::string> create_test_directory()
{
for (u16 i = 0; i < UINT16_MAX; i++)
@@ -42,13 +40,13 @@ TEST(FileSystem, RecursiveDeleteDirectoryDontFollowSymbolicLinks)
std::string dir_to_delete = Path::Combine(*test_dir, "dir_to_delete");
ASSERT_TRUE(FileSystem::CreateDirectoryPath(dir_to_delete.c_str(), false));
std::string symlink_path = Path::Combine(dir_to_delete, "link");
ASSERT_EQ(symlink(target_dir.c_str(), symlink_path.c_str()), 0);
ASSERT_TRUE(FileSystem::CreateSymLink(symlink_path.c_str(), target_dir.c_str()));
// Delete the directory containing the symlink.
ASSERT_TRUE(dir_to_delete.starts_with("/tmp/"));
ASSERT_TRUE(dir_to_delete.starts_with("/tmp/pcsx2_filesystem_test_"));
ASSERT_TRUE(FileSystem::RecursiveDeleteDirectory(dir_to_delete.c_str()));
// Make sure the target file didn't get deleted.
// Make sure the file in the target directory didn't get deleted.
ASSERT_TRUE(FileSystem::FileExists(file_path.c_str()));
// Clean up.

View File

@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: GPL-3.0+
#include "common/FileSystem.h"
#include "common/Pcsx2Defs.h"
#include "common/Path.h"
#include <gtest/gtest.h>
@@ -238,16 +239,129 @@ TEST(Path, CreateFileURL)
#endif
}
#if 0
#if __linux__
// Relies on presence of files.
TEST(Path, RealPath)
static std::optional<std::string> create_test_directory()
{
#ifdef _WIN32
ASSERT_EQ(Path::RealPath("C:\\Users\\Me\\Desktop\\foo\\baz"), "C:\\Users\\Me\\Desktop\\foo\\bar\\baz");
#else
ASSERT_EQ(Path::RealPath("/lib/foo/bar"), "/usr/lib/foo/bar");
#endif
for (u16 i = 0; i < UINT16_MAX; i++)
{
std::string path = std::string("/tmp/pcsx2_path_test_") + std::to_string(i);
if (!FileSystem::DirectoryExists(path.c_str()))
{
if (!FileSystem::CreateDirectoryPath(path.c_str(), false))
break;
return path;
}
}
return std::nullopt;
}
TEST(Path, RealPathAbsoluteSymbolicLink)
{
std::optional<std::string> test_dir = create_test_directory();
ASSERT_TRUE(test_dir.has_value());
// Create a file to point at.
std::string file_path = Path::Combine(*test_dir, "file");
ASSERT_TRUE(FileSystem::WriteStringToFile(file_path.c_str(), "Hello, world!"));
// Create a symbolic link that points to said file.
std::string link_path = Path::Combine(*test_dir, "link");
ASSERT_TRUE(FileSystem::CreateSymLink(link_path.c_str(), file_path.c_str()));
// Make sure the symbolic link is resolved correctly.
ASSERT_EQ(Path::RealPath(link_path), file_path);
// Clean up.
ASSERT_TRUE(FileSystem::DeleteSymbolicLink(link_path.c_str()));
ASSERT_TRUE(FileSystem::DeleteFilePath(file_path.c_str()));
ASSERT_TRUE(FileSystem::DeleteDirectory(test_dir->c_str()));
}
TEST(Path, RealPathRelativeSymbolicLink)
{
std::optional<std::string> test_dir = create_test_directory();
ASSERT_TRUE(test_dir.has_value());
// Create a file to point at.
std::string file_path = Path::Combine(*test_dir, "file");
ASSERT_TRUE(FileSystem::WriteStringToFile(file_path.c_str(), "Hello, world!"));
// Create a symbolic link that points to said file.
std::string link_path = Path::Combine(*test_dir, "link");
ASSERT_TRUE(FileSystem::CreateSymLink(link_path.c_str(), "file"));
// Make sure the symbolic link is resolved correctly.
ASSERT_EQ(Path::RealPath(link_path), file_path);
// Clean up.
ASSERT_TRUE(FileSystem::DeleteSymbolicLink(link_path.c_str()));
ASSERT_TRUE(FileSystem::DeleteFilePath(file_path.c_str()));
ASSERT_TRUE(FileSystem::DeleteDirectory(test_dir->c_str()));
}
TEST(Path, RealPathDotDotSymbolicLink)
{
std::optional<std::string> test_dir = create_test_directory();
ASSERT_TRUE(test_dir.has_value());
// Create a file to point at.
std::string file_path = Path::Combine(*test_dir, "file");
ASSERT_TRUE(FileSystem::WriteStringToFile(file_path.c_str(), "Hello, world!"));
// Create a directory to put the link in.
std::string link_dir = Path::Combine(*test_dir, "dir");
ASSERT_TRUE(FileSystem::CreateDirectoryPath(link_dir.c_str(), false));
// Create a symbolic link that points to said file.
std::string link_path = Path::Combine(link_dir, "link");
ASSERT_TRUE(FileSystem::CreateSymLink(link_path.c_str(), "../file"));
// Make sure the symbolic link is resolved correctly.
ASSERT_EQ(Path::RealPath(link_path), file_path);
// Clean up.
ASSERT_TRUE(FileSystem::DeleteSymbolicLink(link_path.c_str()));
ASSERT_TRUE(FileSystem::DeleteDirectory(link_dir.c_str()));
ASSERT_TRUE(FileSystem::DeleteFilePath(file_path.c_str()));
ASSERT_TRUE(FileSystem::DeleteDirectory(test_dir->c_str()));
}
TEST(Path, RealPathCircularSymbolicLink)
{
std::optional<std::string> test_dir = create_test_directory();
ASSERT_TRUE(test_dir.has_value());
// Create a circular symbolic link.
std::string link_path = Path::Combine(*test_dir, "link");
ASSERT_TRUE(FileSystem::CreateSymLink(link_path.c_str(), "."));
// Make sure the link gets resolved correctly.
ASSERT_EQ(Path::RealPath(link_path), *test_dir);
ASSERT_EQ(Path::RealPath(Path::Combine(link_path, "link")), *test_dir);
// Clean up.
ASSERT_TRUE(FileSystem::DeleteSymbolicLink(link_path.c_str()));
ASSERT_TRUE(FileSystem::DeleteDirectory(test_dir->c_str()));
}
TEST(Path, RealPathLoopingSymbolicLink)
{
std::optional<std::string> test_dir = create_test_directory();
ASSERT_TRUE(test_dir.has_value());
// Create a symbolic link that points to itself.
std::string link_path = Path::Combine(*test_dir, "link");
ASSERT_TRUE(FileSystem::CreateSymLink(link_path.c_str(), "link"));
// Make sure this doesn't cause problems.
ASSERT_EQ(Path::RealPath(link_path), link_path);
// Clean up.
ASSERT_TRUE(FileSystem::DeleteSymbolicLink(link_path.c_str()));
ASSERT_TRUE(FileSystem::DeleteDirectory(test_dir->c_str()));
}
#endif