Skip to content

Commit 65ed77e

Browse files
remutroLukeUsher
authored andcommitted
Fix symlinks to files for rom loading
1 parent bdf4dc9 commit 65ed77e

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

cmake/windows/compilerconfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ else()
3737
endif()
3838
endif()
3939

40-
add_compile_definitions(_WIN32_WINNT=0x0601) #global
40+
add_compile_definitions(_WIN32_WINNT=0x0A00) #global
4141

4242
option(
4343
ARES_MINGW_USE_DWARF_SYMBOLS

desktop-ui/emulator/emulator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ auto Emulator::load(std::shared_ptr<mia::Pak> pak, string& path) -> string {
160160
filters.trimRight(":", 1L);
161161
filters.prepend(pak->name(), "|");
162162
dialog.setFilters({filters, "All|*"});
163-
location = program.openFile(dialog);
163+
location = directory::resolveSymLink(program.openFile(dialog));
164164
}
165165

166166
if(location) {

nall/nall/arguments.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ inline auto Arguments::construct() -> void {
6161

6262
//normalize path and file arguments
6363
for(auto& argument : arguments) {
64+
argument = directory::resolveSymLink(argument);
6465
if(directory::exists(argument)) {
6566
argument.transform("\\", "/").trimRight("/").append("/");
6667
argument = Path::real(argument);

nall/nall/directory.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,30 @@ NALL_HEADER_INLINE auto directory::ufiles(const string& pathname, const string&
8787

8888
#endif
8989

90+
NALL_HEADER_INLINE auto directory::resolveSymLink(const string& pathname) -> string {
91+
string result = pathname;
92+
#if defined (PLATFORM_WINDOWS)
93+
HANDLE hFile = CreateFile(utf16_t(result.data()), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
94+
if (hFile != INVALID_HANDLE_VALUE)
95+
{
96+
wchar_t buffer [MAX_PATH];
97+
memset(buffer, 0, MAX_PATH * sizeof(wchar_t));
98+
if (GetFinalPathNameByHandle(hFile, buffer, MAX_PATH, 0) < MAX_PATH) {
99+
result = slice((const char*)utf8_t(buffer), 4, wcslen(buffer) - 4); //remove "\\?\" prefix
100+
}
101+
CloseHandle(hFile);
102+
}
103+
#else
104+
struct stat sb = {};
105+
if (lstat(result.data(), &sb) != -1 && S_ISLNK(sb.st_mode)) {
106+
char buffer[PATH_MAX];
107+
memset(buffer, 0, PATH_MAX);
108+
if(readlink(result.data(), buffer, PATH_MAX) < PATH_MAX) {
109+
result = string{buffer};
110+
}
111+
}
112+
#endif
113+
return result;
114+
}
115+
90116
}

nall/nall/directory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include <nall/file.hpp>
4-
#include <functional>
54
#include <nall/inode.hpp>
65
#include <nall/intrinsics.hpp>
76
#include <nall/string.hpp>
@@ -26,6 +25,7 @@ struct directory : inode {
2625
static auto create(const string& pathname, u32 permissions = 0755) -> bool; //recursive
2726
static auto remove(const string& pathname) -> bool; //recursive
2827
static auto exists(const string& pathname) -> bool;
28+
static auto resolveSymLink(const string& pathname) -> string;
2929

3030
static auto folders(const string& pathname, const string& pattern = "*") -> std::vector<string> {
3131
auto folders = directory::ufolders(pathname, pattern);

0 commit comments

Comments
 (0)