mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-05-19 19:39:54 +08:00
Added support react-native-windows dotNet Added example for react-native-windows UWP based Added example for react-native-windows dotNet based Project structure: CodePush.Shared - shared code between UWP and dotNet CodePush - UWP specific code CodePush.Net46 - dotNet specific code For UWP solution it needs to be added the following projects: CodePush.Shared CodePush For dotNet solution it needs to be added the following projects: CodePush.Shared CodePush.Net46 Examples: Examples\CodePushDemoApp\windows\CodePushDemoApp.sln the solution contains both examples (UWP and dotNet). Notes Example for ARM configuration has not been tested. Since there is no changes in UWP part of implementation, there is low risk of failure. In this implementation we tried to reuse UWP library as much as possible. The following issues are relevant for both platforms: ZipFile.ExtractToDirectory is not reliable and throws exception if: folder exists already path is too long (> 250 chars) Un-zipping is quite long operation. Does it make sense for async? await UpdateUtils.UnzipBundleAsync(downloadFile.Path, unzippedFolder.Path);
56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|