Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"comment": "use win32 file api to avoid runtime broker slowing us down",
"type": "prerelease",
"packageName": "react-native-windows",
"email": "stecrain@microsoft.com",
"commit": "6a9d6e7e6112f6b963b9a5c0079defbad4272f06",
"date": "2019-07-26T02:36:19.282Z"
}
12 changes: 6 additions & 6 deletions vnext/ReactUWP/Utils/UwpPreparedScriptStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <winrt/Windows.Storage.FileProperties.h>
#include <winrt/Windows.Storage.Streams.h>
#include "Utils/UwpPreparedScriptStore.h"
#include "Utils/UwpScriptStore.h"
#include "jsi/jsi.h"
#include "unicode.h"

Expand Down Expand Up @@ -93,9 +94,9 @@ winrt::StorageFile UwpPreparedScriptStore::TryGetByteCodeFileSync(
try {
if (m_byteCodeFileAsync != nullptr) {
auto file = m_byteCodeFileAsync.get();
auto fileprops = file.GetBasicPropertiesAsync().get();
facebook::jsi::ScriptVersion_t byteCodeVersion =
fileprops.DateModified().time_since_epoch().count();
auto byteCodeVersion =
UwpScriptStore::GetFileVersion(file.Path().c_str());

if (byteCodeVersion >= scriptSignature.version) {
return file;
}
Expand All @@ -113,9 +114,8 @@ winrt::StorageFile UwpPreparedScriptStore::TryGetByteCodeFileSync(
.LocalCacheFolder()
.GetFileAsync(fileName)
.get();
auto fileprops = file.GetBasicPropertiesAsync().get();
facebook::jsi::ScriptVersion_t byteCodeVersion =
fileprops.DateModified().time_since_epoch().count();

auto byteCodeVersion = UwpScriptStore::GetFileVersion(file.Path().c_str());

return byteCodeVersion > scriptSignature.version ? file : nullptr;
}
Expand Down
49 changes: 30 additions & 19 deletions vnext/ReactUWP/Utils/UwpScriptStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ namespace uwp {

UwpScriptStore::UwpScriptStore() {}

/* static */ facebook::jsi::ScriptVersion_t UwpScriptStore::GetFileVersion(
const std::wstring &filePath) {
// append prefix to allow long file paths.
auto longFilePath = L"\\\\?\\" + filePath;
WIN32_FILE_ATTRIBUTE_DATA fileData;
if (GetFileAttributesEx(
longFilePath.c_str(), GetFileExInfoStandard, &fileData)) {
return ((facebook::jsi::ScriptVersion_t)
fileData.ftLastWriteTime.dwHighDateTime
<< 32) |
fileData.ftLastWriteTime.dwLowDateTime;
}

return 0;
}

facebook::jsi::VersionedBuffer UwpScriptStore::getVersionedScript(
const std::string &url) noexcept {
facebook::jsi::VersionedBuffer versionedBuffer_;
Expand All @@ -29,27 +45,22 @@ facebook::jsi::VersionedBuffer UwpScriptStore::getVersionedScript(
// Script version = timestamp of bundle file last created
facebook::jsi::ScriptVersion_t UwpScriptStore::getScriptVersion(
const std::string &url) noexcept {
const std::string bundleUrl = "ms-appx:///Bundle/" + url + ".bundle";
const winrt::DateTime bundleModifiedTime =
getBundleModifiedDate(bundleUrl).get();
const std::uint64_t timestamp = bundleModifiedTime.time_since_epoch().count();
return timestamp;
auto version = getScriptVersionAsync(url).get();

return version;
}

std::future<winrt::DateTime> UwpScriptStore::getBundleModifiedDate(
const std::string &bundleUri) {
winrt::hstring str(facebook::react::unicode::utf8ToUtf16(bundleUri));
winrt::Windows::Foundation::Uri uri(str);

try {
auto file =
co_await winrt::StorageFile::GetFileFromApplicationUriAsync(uri);
auto props = file.GetBasicPropertiesAsync().get();
return props.DateModified();
} catch (winrt::hresult_error const &ex) {
winrt::DateTime date;
return date;
}
std::future<facebook::jsi::ScriptVersion_t>
UwpScriptStore::getScriptVersionAsync(const std::string &bundleUri) {
co_await winrt::resume_background();

const winrt::hstring fileUrl(facebook::react::unicode::utf8ToUtf16(
"ms-appx:///Bundle/" + bundleUri + ".bundle"));

auto file = co_await winrt::StorageFile::GetFileFromApplicationUriAsync(
winrt::Windows::Foundation::Uri{fileUrl});

co_return GetFileVersion(file.Path().c_str());
}

} // namespace uwp
Expand Down
8 changes: 6 additions & 2 deletions vnext/ReactUWP/Utils/UwpScriptStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ class UwpScriptStore : public facebook::jsi::ScriptStore {
UwpScriptStore(const UwpScriptStore &) = delete;
void operator=(const UwpScriptStore &) = delete;

public:
static facebook::jsi::ScriptVersion_t GetFileVersion(
const std::wstring &filePath);

private:
std::future<winrt::Windows::Foundation::DateTime> getBundleModifiedDate(
const std::string &bundlePath);
std::future<facebook::jsi::ScriptVersion_t> getScriptVersionAsync(
const std::string &bundleUri);
};

} // namespace uwp
Expand Down