GitHub
4 年前
当前提交
b5843c49
共有 5 个文件被更改,包括 339 次插入 和 19 次删除
-
179engine/Build.bee.cs
-
19engine/README.md
-
59engine/src/render_api_d3d11.cc
-
99engine/src/TestLoadICU.cpp
-
2engine/src/TestLoadICU.h
|
|||
// Copyright 2019 Google LLC.
|
|||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|||
|
|||
#include "TestLoadICU.h"
|
|||
|
|||
//#if defined(_WIN32) && defined(SK_USING_THIRD_PARTY_ICU)
|
|||
|
|||
#ifndef WIN32_LEAN_AND_MEAN
|
|||
#define WIN32_LEAN_AND_MEAN
|
|||
#endif
|
|||
#include <windows.h>
|
|||
#include <io.h>
|
|||
|
|||
#include <cstdio>
|
|||
#include <cstring>
|
|||
#include <mutex>
|
|||
#include <string>
|
|||
|
|||
#include "unicode/udata.h"
|
|||
|
|||
static void* win_mmap(const char* dataFile) { |
|||
if (!dataFile) { |
|||
return nullptr; |
|||
} |
|||
struct FCloseWrapper { void operator()(FILE* f) { fclose(f); } }; |
|||
std::unique_ptr<FILE, FCloseWrapper> stream(fopen(dataFile, "rb")); |
|||
if (stream == NULL) { |
|||
fprintf(stderr, "SkIcuLoader: datafile missing.\n"); |
|||
return nullptr; |
|||
} |
|||
int fileno = _fileno(stream.get()); |
|||
if (fileno < 0) { |
|||
fprintf(stderr, "SkIcuLoader: datafile fileno error.\n"); |
|||
return nullptr; |
|||
} |
|||
HANDLE file = (HANDLE)_get_osfhandle(fileno); |
|||
if ((HANDLE)INVALID_HANDLE_VALUE == file) { |
|||
fprintf(stderr, "SkIcuLoader: datafile handle error.\n"); |
|||
return nullptr; |
|||
} |
|||
struct CloseHandleWrapper { void operator()(HANDLE h) { CloseHandle(h); } }; |
|||
std::unique_ptr<void, CloseHandleWrapper> mmapHandle( |
|||
CreateFileMapping(file, nullptr, PAGE_READONLY, 0, 0, nullptr)); |
|||
if (!mmapHandle) { |
|||
fprintf(stderr, "SkIcuLoader: datafile mmap error.\n"); |
|||
return nullptr; |
|||
} |
|||
void* addr = MapViewOfFile(mmapHandle.get(), FILE_MAP_READ, 0, 0, 0); |
|||
if (nullptr == addr) { |
|||
fprintf(stderr, "SkIcuLoader: datafile view error.\n"); |
|||
return nullptr; |
|||
} |
|||
return addr; |
|||
} |
|||
|
|||
static bool init_icu(void* addr) { |
|||
UErrorCode err = U_ZERO_ERROR; |
|||
udata_setCommonData(addr, &err); |
|||
if (err != U_ZERO_ERROR) { |
|||
fprintf(stderr, "udata_setCommonData() returned %d.\n", (int)err); |
|||
return false; |
|||
} |
|||
udata_setFileAccess(UDATA_ONLY_PACKAGES, &err); |
|||
if (err != U_ZERO_ERROR) { |
|||
fprintf(stderr, "udata_setFileAccess() returned %d.\n", (int)err); |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
static std::string executable_directory() { |
|||
HMODULE hModule = GetModuleHandleA(NULL); |
|||
char path[MAX_PATH]; |
|||
GetModuleFileNameA(hModule, path, MAX_PATH); |
|||
const char* end = strrchr(path, '\\'); |
|||
return end ? std::string(path, end - path) : std::string(); |
|||
} |
|||
|
|||
bool TestLoadICU() |
|||
{ |
|||
static bool good = false; |
|||
static std::once_flag flag; |
|||
std::call_once(flag, []() { |
|||
const char *env_p = std::getenv("UIWIDGETS_ICUDATA"); |
|||
if (env_p) |
|||
{ |
|||
if (void *addr = win_mmap(env_p)) |
|||
{ |
|||
if (init_icu(addr)) |
|||
{ |
|||
good = true; |
|||
} |
|||
} |
|||
} |
|||
}); |
|||
|
|||
return good; |
|||
} |
|||
|
|
|||
|
|||
bool TestLoadICU(); |
撰写
预览
正在加载...
取消
保存
Reference in new issue