5#include "flutter/fml/file.h"
20#include "flutter/fml/build_config.h"
21#include "flutter/fml/mapping.h"
22#include "flutter/fml/platform/win/errors_win.h"
23#include "flutter/fml/platform/win/wstring_conversion.h"
38 if (
path ==
nullptr || strlen(
path) == 0) {
47 return ::PathIsRelative(wpath.c_str()) ==
FALSE;
60 std::replace(
path.begin(),
path.end(),
'/',
'\\');
66 auto result_size = ::GetTempPath(
MAX_PATH, wchar_path);
67 if (result_size > 0) {
68 return {wchar_path, result_size};
80 return GENERIC_READ | GENERIC_WRITE;
88 return FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
94 return FILE_SHARE_READ;
110 if (temp_dir_container.empty()) {
111 FML_DLOG(
ERROR) <<
"Could not get system temporary directory.";
117 RPC_STATUS status = UuidCreateSequential(&uuid);
118 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) {
119 FML_DLOG(
ERROR) <<
"Could not create UUID for temporary directory.";
123 RPC_WSTR uuid_string;
124 status = UuidToString(&uuid, &uuid_string);
125 if (status != RPC_S_OK) {
126 FML_DLOG(
ERROR) <<
"Could not map UUID to string for temporary directory.";
130 std::wstring uuid_str(
reinterpret_cast<wchar_t*
>(uuid_string));
131 RpcStringFree(&uuid_string);
135 std::wstringstream
stream;
136 stream << temp_dir_container <<
"\\" << uuid_str;
137 auto temp_dir =
stream.str();
141 if (!dir_fd.is_valid()) {
142 FML_DLOG(
ERROR) <<
"Could not get temporary directory file descriptor. "
152 bool create_if_necessary,
155 create_if_necessary, permission);
159 bool create_if_necessary,
161 if (
path ==
nullptr || strlen(
path) == 0) {
167 if (file_name.empty()) {
171 const DWORD creation_disposition =
172 create_if_necessary ? OPEN_ALWAYS : OPEN_EXISTING;
181 creation_disposition,
195 bool create_if_necessary,
198 create_if_necessary, permission);
202 bool create_if_necessary,
204 if (
path ==
nullptr || strlen(
path) == 0) {
210 if (file_name.empty()) {
214 if (create_if_necessary) {
224 const DWORD creation_disposition = OPEN_EXISTING;
226 const DWORD flags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS;
233 creation_disposition,
252 if (!::DuplicateHandle(
259 DUPLICATE_SAME_ACCESS)
268 BY_HANDLE_FILE_INFORMATION
info;
269 if (!::GetFileInformationByHandle(directory.
get(), &
info)) {
272 return info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
277 FILE_ATTRIBUTE_DIRECTORY;
282 if (attributes == INVALID_FILE_ATTRIBUTES) {
285 return !(attributes &
286 (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT));
328 LARGE_INTEGER large_size;
329 large_size.QuadPart =
size;
330 large_size.LowPart = SetFilePointer(
file.get(), large_size.LowPart,
331 &large_size.HighPart, FILE_BEGIN);
332 if (large_size.LowPart == INVALID_SET_FILE_POINTER &&
338 if (!::SetEndOfFile(
file.get())) {
348 INVALID_FILE_ATTRIBUTES;
354 const char* file_name,
355 const Mapping& mapping) {
356 if (file_name ==
nullptr) {
364 if (!temp_file.is_valid()) {
365 FML_DLOG(
ERROR) <<
"Could not create file: " << file_path.c_str() <<
" "
371 FML_DLOG(
ERROR) <<
"Could not truncate the file to the correct size. "
379 if (temp_file_mapping.GetSize() != mapping.GetSize()) {
380 FML_DLOG(
ERROR) <<
"Temporary file mapping size was incorrect. Is "
381 << temp_file_mapping.GetSize() <<
". Should be "
382 << mapping.GetSize() <<
".";
386 if (temp_file_mapping.GetMutableMapping() ==
nullptr) {
387 FML_DLOG(
ERROR) <<
"Temporary file does not have a mutable mapping.";
391 ::memcpy(temp_file_mapping.GetMutableMapping(), mapping.GetMapping(),
394 if (!::FlushViewOfFile(temp_file_mapping.GetMutableMapping(),
395 mapping.GetSize())) {
400 if (!::FlushFileBuffers(temp_file.get())) {
416 WIN32_FIND_DATA find_file_data;
428 if (filename !=
"." && filename !=
"..") {
429 if (!visitor(directory, filename)) {
430 ::FindClose(find_handle);
435 ::FindClose(find_handle);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
FlutterSemanticsFlag flags
#define FML_DLOG(severity)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
bool VisitFiles(const fml::UniqueFD &directory, const FileVisitor &visitor)
std::wstring Utf8ToWideString(const std::string_view str)
static std::string GetAbsolutePath(const fml::UniqueFD &base_directory, const char *subpath)
constexpr std::size_t size(T(&array)[N])
static bool IsAbsolutePath(const char *path)
static std::string GetFullHandlePath(const fml::UniqueFD &handle)
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
fml::UniqueFD Duplicate(fml::UniqueFD::element_type descriptor)
std::string GetLastErrorMessage()
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
bool IsFile(const std::string &path)
std::string CreateTemporaryDirectory()
bool UnlinkDirectory(const char *path)
static DWORD GetFileAttributesForUtf8Path(const char *absolute_path)
static std::wstring GetTemporaryDirectoryPath()
static DWORD GetDesiredAccessFlags(FilePermission permission)
bool TruncateFile(const fml::UniqueFD &file, size_t size)
static fml::UniqueFD CreateDirectory(const fml::UniqueFD &base_directory, const std::vector< std::string > &components, FilePermission permission, size_t index)
bool FileExists(const fml::UniqueFD &base_directory, const char *path)
std::string WideStringToUtf8(const std::wstring_view str)
bool UnlinkFile(const char *path)
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
static DWORD GetShareFlags(FilePermission permission)
std::function< bool(const fml::UniqueFD &directory, const std::string &filename)> FileVisitor
bool IsDirectory(const fml::UniqueFD &directory)
def subpath(path, base_dir)
#define GetFileAttributes
#define INVALID_HANDLE_VALUE
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)