Files
react-native-code-push/windows/CodePush.Shared/CodePushUtils.cs
Alexander Bodalevsky be96f07eda Added React Native Windows dotNet46 support (#684)
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);
2017-02-13 16:23:20 -08:00

75 lines
1.9 KiB
C#

using System;
using System.Diagnostics;
#if WINDOWS_UWP
using Windows.ApplicationModel;
using Windows.Storage;
#else
using System.IO;
#endif
namespace CodePush.ReactNative
{
internal partial class CodePushUtils
{
internal static void Log(string message)
{
Debug.WriteLine("[CodePush] " + message, CodePushConstants.ReactNativeLogCategory);
}
internal static void LogBundleUrl(string path)
{
Log("Loading JS bundle from \"" + path + "\"");
}
static string _deviceId = String.Empty;
internal static string GetDeviceId()
{
//It's quite long operation, cache it
if (!String.IsNullOrEmpty(_deviceId))
return _deviceId;
_deviceId = GetDeviceIdImpl();
return _deviceId;
}
internal static string GetAppVersion()
{
#if WINDOWS_UWP
return Package.Current.Id.Version.Major + "." + Package.Current.Id.Version.Minor + "." + Package.Current.Id.Version.Build;
#else
var version = FileVersionInfo.GetVersionInfo(Environment.GetCommandLineArgs()[0]);
return $"{version.FileMajorPart}.{version.FileMinorPart}.{version.FileBuildPart}";
#endif
}
internal static string GetAppFolder()
{
#if WINDOWS_UWP
return ApplicationData.Current.LocalFolder.Path;
#else
return AppDomain.CurrentDomain.BaseDirectory;
#endif
}
internal static string GetAssetsBundlePrefix()
{
#if WINDOWS_UWP
return CodePushConstants.AssetsBundlePrefix;
#else
return Path.Combine(GetAppFolder(), CodePushConstants.AssetsBundlePrefix);
#endif
}
internal static string GetFileBundlePrefix()
{
#if WINDOWS_UWP
return CodePushConstants.FileBundlePrefix;
#else
return GetAppFolder();
#endif
}
}
}