mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-06-05 15:47:12 +02:00
[desktop, fs] main_window separation; fix Ryujinx save data link issues (#2929)
Some genius decided to put the entire MainWindow class into main.h and main.cpp, which is not only horrific practice but also completely destroys clangd beyond repair. Please, just don't do this. (this will probably merge conflict to hell and back) Also, fixes a bunch of issues with Ryujinx save data link: - Paths with spaces would cause mklink to fail - Add support for portable directories - Symlink detection was incorrect sometimes(????) - Some other stuff I'm forgetting Furthermore, when selecting "From Eden" and attempting to save in Ryujinx, Ryujinx would destroy the link for... some reason? So to get around this we just copy the Eden data to Ryujinx then treat it like a "From Ryujinx" op Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2929 Reviewed-by: Lizzie <lizzie@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
This commit is contained in:
parent
e13c7ef3f8
commit
08f3639c80
51 changed files with 5386 additions and 5283 deletions
|
|
@ -4,10 +4,12 @@
|
|||
#include "symlink.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <fmt/format.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
// The sole purpose of this file is to treat symlinks like symlinks on POSIX,
|
||||
|
|
@ -15,29 +17,40 @@ namespace fs = std::filesystem;
|
|||
// 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.
|
||||
// And no, they do NOT provide a standard API for this (at least to my knowledge).
|
||||
// CreateSymbolicLink, even when EXPLICITLY TOLD to create a junction, still fails
|
||||
// because of their security policy.
|
||||
// I don't know what kind of drugs the Windows developers have been on since NT started.
|
||||
|
||||
// Microsoft still has not implemented any of this in their std::filesystem implemenation,
|
||||
// which ALSO means that it DOES NOT FOLLOW ANY DIRECTORY JUNCTIONS... AT ALL.
|
||||
// Nor does any of their command line utilities or APIs. So you're quite literally
|
||||
// on your own.
|
||||
|
||||
namespace Common::FS {
|
||||
|
||||
bool CreateSymlink(const fs::path &from, const fs::path &to)
|
||||
bool CreateSymlink(fs::path from, fs::path to)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const std::string command = fmt::format("mklink /J {} {}", to.string(), from.string());
|
||||
return system(command.c_str()) == 0;
|
||||
#else
|
||||
from.make_preferred();
|
||||
to.make_preferred();
|
||||
|
||||
std::error_code ec;
|
||||
fs::create_directory_symlink(from, to, ec);
|
||||
return !ec;
|
||||
#ifdef _WIN32
|
||||
if (ec) {
|
||||
const std::string command = fmt::format("mklink /J \"{}\" \"{}\"",
|
||||
to.string(),
|
||||
from.string());
|
||||
return system(command.c_str()) == 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return !ec;
|
||||
}
|
||||
|
||||
bool IsSymlink(const fs::path &path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
auto attributes = GetFileAttributesW(path.wstring().c_str());
|
||||
return attributes & FILE_ATTRIBUTE_REPARSE_POINT;
|
||||
#else
|
||||
return fs::is_symlink(path);
|
||||
#endif
|
||||
return boost::filesystem::is_symlink(boost::filesystem::path{path});
|
||||
}
|
||||
|
||||
} // namespace Common::FS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue