Skip to content

Commit

Permalink
Fix opening assets on Windows
Browse files Browse the repository at this point in the history
Two bugs:

To open a directory with CreateFile, FILE_FLAG_BACKUP_SEMANTICS needs to
be specified.

GetFinalPathNameByHandle returns a UNC path, so forward slashes need to
be converted to backslashes.
  • Loading branch information
ds84182 committed Apr 15, 2018
1 parent e0c3c29 commit 3459964
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fml/platform/win/file_win.cc
Expand Up @@ -6,6 +6,7 @@

#include <Shlwapi.h>

#include <algorithm>
#include <sstream>

#include "flutter/fml/platform/win/wstring_conversion.h"
Expand Down Expand Up @@ -36,13 +37,19 @@ fml::UniqueFD OpenFile(const std::wstring& path,
break;
}

DWORD flags = FILE_ATTRIBUTE_NORMAL;

if (is_directory) {
flags |= FILE_FLAG_BACKUP_SEMANTICS;
}

return fml::UniqueFD{::CreateFile(
path.c_str(), // lpFileName
desired_access, // dwDesiredAccess
FILE_SHARE_READ, // dwShareMode
0, // lpSecurityAttributes
OPEN_EXISTING, // dwCreationDisposition
FILE_ATTRIBUTE_NORMAL, // dwFlagsAndAttributes
flags, // dwFlagsAndAttributes
0 // hTemplateFile
)};
}
Expand Down Expand Up @@ -83,7 +90,10 @@ fml::UniqueFD OpenFile(const fml::UniqueFD& base_directory,

std::wstringstream stream;
stream << GetFullHandlePath(base_directory) << "\\" << path;
return OpenFile(stream.str(), permission, is_directory);
std::wstring native_path = stream.str();
// native_path is a UNC path, so transform any forward slashes into back slashes
std::replace(native_path.begin(), native_path.end(), '/', '\\');
return OpenFile(native_path, permission, is_directory);
}

fml::UniqueFD Duplicate(fml::UniqueFD::element_type descriptor) {
Expand Down

0 comments on commit 3459964

Please sign in to comment.