Browse Source
QtCommon::FS, symlink abstractor
QtCommon::FS, symlink abstractor
Signed-off-by: crueter <crueter@eden-emu.dev>pull/2815/head
18 changed files with 149 additions and 70 deletions
-
3src/common/CMakeLists.txt
-
0src/common/fs/ryujinx_compat.cpp
-
0src/common/fs/ryujinx_compat.h
-
43src/common/fs/symlink.cpp
-
12src/common/fs/symlink.h
-
3src/qt_common/CMakeLists.txt
-
2src/qt_common/abstract/frontend.cpp
-
6src/qt_common/abstract/frontend.h
-
30src/qt_common/qt_common.cpp
-
2src/qt_common/qt_common.h
-
2src/qt_common/util/content.cpp
-
56src/qt_common/util/fs.cpp
-
14src/qt_common/util/fs.h
-
2src/qt_common/util/game.cpp
-
2src/qt_common/util/path.cpp
-
7src/yuzu/main.cpp
-
9src/yuzu/migration_worker.cpp
-
26src/yuzu/ryujinx_dialog.cpp
@ -0,0 +1,43 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|||
|
|||
#include "symlink.h"
|
|||
|
|||
#ifdef _WIN32
|
|||
#include <winbase.h>
|
|||
#endif
|
|||
|
|||
namespace fs = std::filesystem; |
|||
|
|||
// The sole purpose of this file is to treat symlinks like symlinks on POSIX,
|
|||
// or treat them as directory junctions on Windows.
|
|||
// This is because, for some inexplicable reason, Microsoft has locked symbolic
|
|||
// links behind a "security policy", whereas directory junctions--functionally identical
|
|||
// for directories, by the way--are not. Why? I don't know.
|
|||
|
|||
namespace Common::FS { |
|||
|
|||
bool CreateSymlink(const fs::path &from, const fs::path &to) |
|||
{ |
|||
// TODO: test this, + does it need symlink perms?
|
|||
#ifdef _WIN32
|
|||
return CreateSymbolicLinkW(to.wstring().c_str(), |
|||
from.wstring().c_str(), |
|||
SYMBOLIC_LINK_FLAG_DIRECTORY); |
|||
#else
|
|||
std::error_code ec; |
|||
fs::create_directory_symlink(from, to, ec); |
|||
return !ec; |
|||
#endif
|
|||
} |
|||
|
|||
bool IsSymlink(const fs::path &path) |
|||
{ |
|||
#ifdef _WIN32
|
|||
return fs::status(path).type() == fs::file_type::junction; |
|||
#else
|
|||
return fs::status(path).type() == fs::file_type::symlink; |
|||
#endif
|
|||
} |
|||
|
|||
} // namespace Common::FS
|
|||
@ -0,0 +1,12 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project |
|||
// SPDX-License-Identifier: GPL-3.0-or-later |
|||
|
|||
#pragma once |
|||
|
|||
#include <filesystem> |
|||
namespace Common::FS { |
|||
|
|||
bool CreateSymlink(const std::filesystem::path &from, const std::filesystem::path &to); |
|||
bool IsSymlink(const std::filesystem::path &path); |
|||
|
|||
} // namespace Common::FS |
|||
@ -1,7 +1,7 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|||
|
|||
#include "qt_frontend_util.h"
|
|||
#include "frontend.h"
|
|||
#include "qt_common/qt_common.h"
|
|||
|
|||
#ifdef YUZU_QT_WIDGETS
|
|||
@ -0,0 +1,56 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|||
|
|||
#include "fs.h"
|
|||
#include "common/fs/ryujinx_compat.h"
|
|||
#include "common/fs/symlink.h"
|
|||
#include "qt_common/abstract/frontend.h"
|
|||
#include "qt_common/qt_string_lookup.h"
|
|||
|
|||
namespace fs = std::filesystem; |
|||
|
|||
namespace QtCommon::FS { |
|||
|
|||
void LinkRyujinx(std::filesystem::path &from, std::filesystem::path &to) { |
|||
std::error_code ec; |
|||
|
|||
// "ignore" errors--if the dir fails to be deleted, error handling later will handle it
|
|||
fs::remove_all(to, ec); |
|||
|
|||
if (Common::FS::CreateSymlink(from, to)) { |
|||
QtCommon::Frontend::Information(tr("Linked Save Data"), tr("Save data has been linked.")); |
|||
} else { |
|||
QtCommon::Frontend::Critical(tr("Failed to link save data"), |
|||
tr("Could not link directory:\n\t%1\nTo:\n\t%2") |
|||
.arg(QString::fromStdString(from.string()), |
|||
QString::fromStdString(to.string()))); |
|||
} |
|||
} |
|||
|
|||
u64 GetRyujinxSaveID(const u64 &program_id) |
|||
{ |
|||
auto path = Common::FS::GetKvdbPath(); |
|||
std::vector<Common::FS::IMEN> imens; |
|||
Common::FS::IMENReadResult res = Common::FS::ReadKvdb(path, imens); |
|||
|
|||
if (res == Common::FS::IMENReadResult::Success) { |
|||
// TODO: this can probably be done with std::find_if but I'm lazy
|
|||
for (const Common::FS::IMEN &imen : imens) { |
|||
if (imen.title_id == program_id) |
|||
return imen.save_id; |
|||
} |
|||
|
|||
QtCommon::Frontend::Critical( |
|||
tr("Could not find Ryujinx save data"), |
|||
StringLookup::Lookup(StringLookup::RyujinxNoSaveId).arg(program_id, 0, 16)); |
|||
} else { |
|||
// TODO: make this long thing a function or something
|
|||
QString caption = StringLookup::Lookup( |
|||
static_cast<StringLookup::StringKey>((int) res + (int) StringLookup::KvdbNonexistent)); |
|||
QtCommon::Frontend::Critical(tr("Could not find Ryujinx save data"), caption); |
|||
} |
|||
|
|||
return -1; |
|||
} |
|||
|
|||
} // namespace QtCommon::FS
|
|||
@ -0,0 +1,14 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project |
|||
// SPDX-License-Identifier: GPL-3.0-or-later |
|||
|
|||
#include "common/common_types.h" |
|||
#include <filesystem> |
|||
|
|||
#pragma once |
|||
|
|||
namespace QtCommon::FS { |
|||
|
|||
void LinkRyujinx(std::filesystem::path &from, std::filesystem::path &to); |
|||
u64 GetRyujinxSaveID(const u64& program_id); |
|||
|
|||
} // namespace QtCommon::FS |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue