This repository was archived by the owner on Sep 14, 2022. It is now read-only.
forked from nineto4/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileUtils.cs
More file actions
55 lines (46 loc) · 2.25 KB
/
FileUtils.cs
File metadata and controls
55 lines (46 loc) · 2.25 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
using PCLStorage;
using System;
using System.IO;
using System.Threading.Tasks;
namespace CodePush.ReactNative
{
internal class FileUtils
{
internal async static Task MergeFoldersAsync(IFolder source, IFolder target)
{
foreach (IFile sourceFile in await source.GetFilesAsync().ConfigureAwait(false))
{
await CopyFileAsync(sourceFile.Path, Path.Combine(target.Path, sourceFile.Name)).ConfigureAwait(false);
}
foreach (IFolder sourceDirectory in await source.GetFoldersAsync().ConfigureAwait(false))
{
var nextTargetSubDir = await target.CreateFolderAsync(sourceDirectory.Name, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
await MergeFoldersAsync(sourceDirectory, nextTargetSubDir).ConfigureAwait(false);
}
}
internal async static Task ClearReactDevBundleCacheAsync()
{
if (await FileSystem.Current.LocalStorage.CheckExistsAsync(CodePushConstants.ReactDevBundleCacheFileName).ConfigureAwait(false) != ExistenceCheckResult.FileExists)
return;
var devBundleCacheFile = await FileSystem.Current.LocalStorage.GetFileAsync(CodePushConstants.ReactDevBundleCacheFileName).ConfigureAwait(false);
await devBundleCacheFile.DeleteAsync().ConfigureAwait(false);
}
internal static Task<long> GetBinaryResourcesModifiedTimeAsync(string fileName)
{
var pathToAssembly = CodePushUtils.GetAppFolder();
var pathToAssemblyResource = Path.Combine(pathToAssembly, CodePushConstants.AssetsBundlePrefix, fileName);
var lastUpdateTime = File.GetCreationTime(pathToAssemblyResource);
return Task.FromResult(new DateTimeOffset(lastUpdateTime).ToUnixTimeMilliseconds());
}
internal async static Task CopyFileAsync(string sourcePath, string destinationPath)
{
using (var source = File.Open(sourcePath, FileMode.Open, System.IO.FileAccess.Read))
{
using (var destination = File.Create(destinationPath)) // Replace if exists
{
await source.CopyToAsync(destination);
}
}
}
}
}