Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 6a1d1ff

Browse files
abodalevskysergey-akhalkov
authored andcommitted
WPF:WINDOWS Added ability to update application installed in Program Files folder (#813)
* Updated Windows Example * Organized usings * Fix for update application in write protected folder * Typo fixed * Examples updated to RNW 0.43.0 * Fixed Warning CS0108
1 parent 66cf73f commit 6a1d1ff

File tree

13 files changed

+96
-30
lines changed

13 files changed

+96
-30
lines changed

Examples/CodePushDemoApp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"react": "16.0.0-alpha.6",
1111
"react-native": "^0.43.2",
1212
"react-native-code-push": "file:../../",
13-
"react-native-windows": "0.40.0-rc.1"
13+
"react-native-windows": "^0.43.0-rc.0"
1414
},
1515
"devDependencies": {
1616
"babel-jest": "19.0.0",
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
55
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="System.Reactive.Core" publicKeyToken="94bc3704cddfc263" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
614
</configuration>

Examples/CodePushDemoApp/windows/CodePushDemoApp.Wpf/App.xaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
4-
using System.Data;
5-
using System.Linq;
6-
using System.Threading.Tasks;
72
using System.Windows;
83
using System.Windows.Controls;
94
using System.Windows.Navigation;

Examples/CodePushDemoApp/windows/CodePushDemoApp.Wpf/CodePushDemoApp.Wpf.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\Microsoft.ChakraCore.1.4.1-preview-00010-42060\build\netstandard1.0\Microsoft.ChakraCore.props" Condition="Exists('..\packages\Microsoft.ChakraCore.1.4.1-preview-00010-42060\build\netstandard1.0\Microsoft.ChakraCore.props')" />
3+
<Import Project="..\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props" Condition="Exists('..\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props')" />
44
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
55
<PropertyGroup>
66
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -102,7 +102,7 @@
102102
<ItemGroup>
103103
<Reference Include="Facebook.Yoga, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
104104
<SpecificVersion>False</SpecificVersion>
105-
<HintPath>..\packages\Facebook.Yoga.1.0.1-pre\lib\netstandard\Facebook.Yoga.dll</HintPath>
105+
<HintPath>..\packages\Facebook.Yoga.1.2.0-pre1\lib\net45\Facebook.Yoga.dll</HintPath>
106106
<Private>True</Private>
107107
</Reference>
108108
<Reference Include="System" />
@@ -170,10 +170,10 @@
170170
<PropertyGroup>
171171
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
172172
</PropertyGroup>
173-
<Error Condition="!Exists('..\packages\Microsoft.ChakraCore.1.4.1-preview-00010-42060\build\netstandard1.0\Microsoft.ChakraCore.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.ChakraCore.1.4.1-preview-00010-42060\build\netstandard1.0\Microsoft.ChakraCore.props'))" />
174-
<Error Condition="!Exists('..\packages\Facebook.Yoga.1.0.1-pre\build\netstandard\Facebook.Yoga.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Facebook.Yoga.1.0.1-pre\build\netstandard\Facebook.Yoga.targets'))" />
173+
<Error Condition="!Exists('..\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props'))" />
174+
<Error Condition="!Exists('..\packages\Facebook.Yoga.1.2.0-pre1\build\net45\Facebook.Yoga.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Facebook.Yoga.1.2.0-pre1\build\net45\Facebook.Yoga.targets'))" />
175175
</Target>
176-
<Import Project="..\packages\Facebook.Yoga.1.0.1-pre\build\netstandard\Facebook.Yoga.targets" Condition="Exists('..\packages\Facebook.Yoga.1.0.1-pre\build\netstandard\Facebook.Yoga.targets')" />
176+
<Import Project="..\packages\Facebook.Yoga.1.2.0-pre1\build\net45\Facebook.Yoga.targets" Condition="Exists('..\packages\Facebook.Yoga.1.2.0-pre1\build\net45\Facebook.Yoga.targets')" />
177177
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
178178
Other similar extension points exist, see Microsoft.Common.targets.
179179
<Target Name="BeforeBuild">
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Facebook.Yoga" version="1.0.1-pre" targetFramework="net46" />
4-
<package id="Microsoft.ChakraCore" version="1.4.1-preview-00010-42060" targetFramework="net46" developmentDependency="true" />
3+
<package id="Facebook.Yoga" version="1.2.0-pre1" targetFramework="net46" />
4+
<package id="Microsoft.ChakraCore" version="1.4.1" targetFramework="net46" developmentDependency="true" />
55
</packages>

Examples/CodePushDemoApp/windows/CodePushDemoApp/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"Facebook.Yoga": "1.0.1-pre",
3+
"Facebook.Yoga": "1.2.0-pre1",
44
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2"
55
},
66
"frameworks": {

windows/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public DictionaryWithDefault(TValue defaultValue) : base()
4242
}
4343
}
4444

45-
public bool Remove(TKey key)
45+
public new bool Remove(TKey key)
4646
{
4747
var found = base.Remove(key);
4848
if (found)

windows/CodePush.Net46/CodePushUtils.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,61 @@
11
using Newtonsoft.Json.Linq;
22
using PCLStorage;
33
using System;
4+
using System.Diagnostics;
5+
using System.IO;
46
using System.Management;
57
using System.Threading.Tasks;
68

79
namespace CodePush.ReactNative
810
{
911
internal partial class CodePushUtils
1012
{
13+
class ApplicationInfo
14+
{
15+
public ApplicationInfo()
16+
{
17+
var info = FileVersionInfo.GetVersionInfo(Environment.GetCommandLineArgs()[0]);
18+
Version = $"{info.FileMajorPart}.{info.FileMinorPart}.{info.FileBuildPart}";
19+
CompanyName = string.IsNullOrEmpty(info.CompanyName) ? info.ProductName : info.CompanyName;
20+
ProductName = info.ProductName;
21+
}
22+
23+
public string Version { private set; get; }
24+
public string CompanyName { private set; get; }
25+
public string ProductName { private set; get; }
26+
}
27+
28+
static ApplicationInfo applicationInfo = new ApplicationInfo();
29+
static string _bundlePath;
30+
31+
internal static string GetFileBundlePrefix()
32+
{
33+
// For Windows desktop application the prefix of a bundle is the full path to the folder where
34+
// bundle should be installed.
35+
//
36+
// Desktop application can be installed at any location, the most popular are:
37+
// - User local data folder, in this case the bundle can be stored in the same location and be
38+
// unique for the user.
39+
// - Program Files folder, in this case the application is unique for the system and will be shared
40+
// amoung all users of the system, the bundle should be unique for the system as well.
41+
// Commonly, user has no write access to Program Files folder or at least admin privileges have to been requested.
42+
// In this case the bundle will be stored in ProgramData folder as it is recommended by MS.
43+
44+
if (!string.IsNullOrEmpty(_bundlePath))
45+
{
46+
return _bundlePath;
47+
}
48+
49+
_bundlePath = GetAppFolder();
50+
51+
if (!HasWriteAccessToFolder(_bundlePath))
52+
{
53+
_bundlePath = $"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), applicationInfo.CompanyName, applicationInfo.ProductName, applicationInfo.Version)}\\";
54+
}
55+
56+
return _bundlePath;
57+
}
58+
1159
internal async static Task<JObject> GetJObjectFromFileAsync(IFile file)
1260
{
1361
string jsonString = await file.ReadAllTextAsync().ConfigureAwait(false);
@@ -93,5 +141,18 @@ static string GetMAC()
93141

94142
return mac;
95143
}
144+
145+
static bool HasWriteAccessToFolder(string path)
146+
{
147+
try
148+
{
149+
File.Open(Path.Combine(path, ".security-check"), FileMode.OpenOrCreate).Close();
150+
return true;
151+
}
152+
catch
153+
{
154+
return false;
155+
}
156+
}
96157
}
97158
}

windows/CodePush.Net46/UpdateUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal async static Task DownloadBundleAsync(string url, string fileName, IPro
6363

6464
internal static async Task<IFolder> GetCodePushFolderAsync()
6565
{
66-
var pathToCodePush = Path.Combine(CodePushUtils.GetAppFolder(), CodePushConstants.CodePushFolderPrefix);
66+
var pathToCodePush = Path.Combine(CodePushUtils.GetFileBundlePrefix(), CodePushConstants.CodePushFolderPrefix);
6767
return await FileSystem.Current.LocalStorage.CreateFolderAsync(pathToCodePush, CreationCollisionOption.OpenIfExists).ConfigureAwait(false);
6868
}
6969
}

windows/CodePush.Shared/CodePushConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal class CodePushConstants
2727
internal const string UnzippedFolderName = "unzipped";
2828
#if WINDOWS_UWP
2929
internal const string AssetsBundlePrefix = "ms-appx:///ReactAssets/";
30-
internal const string FileBundlePrefix = "ms-appdata:///local";
30+
internal const string FileBundlePrefix = "ms-appdata:///local/";
3131
#else
3232
internal const string AssetsBundlePrefix = "ReactAssets/";
3333
#endif

0 commit comments

Comments
 (0)