forked from microsoft/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodePushUpdateUtils.cpp
More file actions
86 lines (77 loc) · 2.98 KB
/
CodePushUpdateUtils.cpp
File metadata and controls
86 lines (77 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "winrt/Windows.ApplicationModel.h"
#include "winrt/Windows.Foundation.h"
#include "winrt/Windows.Foundation.Collections.h"
#include "winrt/Windows.Security.Cryptography.h"
#include "winrt/Windows.Security.Cryptography.Core.h"
#include "winrt/Windows.Storage.h"
#include "winrt/Windows.Storage.FileProperties.h"
#include "winrt/Windows.Storage.Streams.h"
#include <algorithm>
#include <string_view>
#include <vector>
#include "CodePushUpdateUtils.h"
#include "CodePushUtils.h"
#include "CodePushNativeModule.h"
namespace Microsoft::CodePush::ReactNative
{
using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Storage;
using namespace Windows::Security::Cryptography;
using namespace Windows::Security::Cryptography::Core;
/*static*/ IAsyncOperation<bool> CodePushUpdateUtils::CopyEntriesInFolderAsync(StorageFolder& sourceFolder, StorageFolder& destFolder)
{
auto entries{ co_await sourceFolder.GetItemsAsync() };
for (const auto& entry : entries)
{
if (entry.IsOfType(StorageItemTypes::File))
{
auto file{ entry.try_as<StorageFile>() };
co_await file.CopyAsync(destFolder, file.Name(), NameCollisionOption::ReplaceExisting);
}
else if (entry.IsOfType(StorageItemTypes::Folder))
{
auto folder{ entry.try_as<StorageFolder>() };
auto folderCopy{ co_await destFolder.CreateFolderAsync(folder.Name(), CreationCollisionOption::ReplaceExisting) };
auto result{ co_await CopyEntriesInFolderAsync(folder, folderCopy) };
if (!result)
{
co_return false;
}
}
}
co_return true;
}
/*static*/ IAsyncOperation<StorageFile> CodePushUpdateUtils::GetSignatureFileAsync(const StorageFolder& rootFolder)
{
auto manifestFolder{ (co_await rootFolder.TryGetItemAsync(ManifestFolderPrefix)).try_as<StorageFolder>() };
if (manifestFolder != nullptr)
{
auto bundleJWTFile{ (co_await rootFolder.TryGetItemAsync(BundleJWTFile)).try_as<StorageFile>() };
if (bundleJWTFile != nullptr)
{
co_return bundleJWTFile;
}
}
co_return nullptr;
}
/*static*/ IAsyncOperation<hstring> CodePushUpdateUtils::ModifiedDateStringOfFileAsync(const StorageFile& file)
{
if (file != nullptr)
{
auto basicProperties{ co_await file.GetBasicPropertiesAsync() };
auto modifiedDate{ basicProperties.DateModified() };
auto mtime{ clock::to_time_t(modifiedDate) };
auto modifiedDateString{ to_hstring(mtime) };
co_return modifiedDateString;
}
else
{
co_return L"";
}
}
}