Skip to content

Commit

Permalink
Merge AppUpdater to Common; Add package icon
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Dec 6, 2020
1 parent 2f3e596 commit 45a6142
Show file tree
Hide file tree
Showing 18 changed files with 230 additions and 19 deletions.
10 changes: 10 additions & 0 deletions VpnHood.App.Launcher/VpnHood.App.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
<AssemblyName>run</AssemblyName>
<PackageId>VpnHood.App.Launcher</PackageId>
<Version>1.0.2</Version>
<PackageIcon>VpnHood.png</PackageIcon>
<Product>VpnHood.App.Launcher</Product>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
7 changes: 6 additions & 1 deletion VpnHood.Client.App.UI/VpnHood.Client.App.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
<AssemblyName>VpnHood.Client.App.UI</AssemblyName>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<Authors>VpnHood</Authors>
<Company>VpnHoodVpnHood</Company>
<Company>VpnHood</Company>
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageProjectUrl>https://github.com/vpnhood/vpnhood</PackageProjectUrl>
<PackageIcon>VpnHood.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Html\**" />
<EmbeddedResource Remove="Html\**" />
<None Remove="Html\**" />
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions VpnHood.Client.App.Win/VpnHood.Client.App.Win.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<Authors>VpnHood</Authors>
<Company>VpnHood</Company>
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageIcon>VpnHood.png</PackageIcon>
<LangVersion>default</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -37,6 +39,10 @@
<None Update="WinDivert64.sys">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions VpnHood.Client.App/VpnHood.Client.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Authors>VpnHood</Authors>
<Company>VpnHood</Company>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<Copyright>2020 VpnHood</Copyright>
<PackageProjectUrl>https://github.com/vpnhood/vpnhood</PackageProjectUrl>
<PackageIcon>VpnHood.png</PackageIcon>
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\VpnHood.Client\VpnHood.Client.csproj" />
<ProjectReference Include="..\VpnHood.Common\VpnHood.Common.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Authors>VpnHood</Authors>
<Company>VpnHood</Company>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<Copyright>2020 VpnHood</Copyright>
<PackageProjectUrl>https://github.com/vpnhood/vpnhood</PackageProjectUrl>
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageIcon>VpnHood.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
Expand All @@ -21,6 +28,10 @@
<None Update="WinDivert64.sys">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions VpnHood.Client/VpnHood.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Company>VpnHood</Company>
<PackageProjectUrl>https://github.com/vpnhood/vpnhood</PackageProjectUrl>
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageIcon>VpnHood.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
Expand All @@ -22,4 +23,11 @@
<ProjectReference Include="..\VpnHood.Tunneling\VpnHood.Tunneling.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
using System.Text.Json;
using System.Threading;

namespace VpnHood
namespace VpnHood.Common
{
public class AppUpdater : IDisposable
{
private class PublishInfo
{
public string Version { get; set; }
public string LaunchPath { get; set; }
}

private const string PUBLISH_INFO = "publish.json";
private readonly FileSystemWatcher _fileSystemWatcher = new FileSystemWatcher();
private readonly ILogger _logger;
Expand Down
8 changes: 0 additions & 8 deletions VpnHood.Common.AppUpdater/PublishInfo.cs

This file was deleted.

8 changes: 8 additions & 0 deletions VpnHood.Common.AppUpdater/VpnHood.Common.AppUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@
<LangVersion>9.0</LangVersion>
<RootNamespace>VpnHood</RootNamespace>
<PackageId>VpnHood.Common.AppUpdater</PackageId>
<PackageIcon>VpnHood.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
117 changes: 117 additions & 0 deletions VpnHood.Common/AppUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text.Json;
using System.Threading;

namespace VpnHood.Common
{
public class AppUpdater : IDisposable
{
private class PublishInfo
{
public string Version { get; set; }
public string LaunchPath { get; set; }
}

private const string PUBLISH_INFO = "publish.json";
private readonly FileSystemWatcher _fileSystemWatcher = new FileSystemWatcher();
private readonly ILogger _logger;

public string PublishInfoPath { get; }
public string NewAppPath { get; private set; }
public event EventHandler NewVersionFound;

public AppUpdater(ILogger logger)
{
var publishFolder = Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
PublishInfoPath = Path.Combine(publishFolder, PUBLISH_INFO);
_logger = logger;

_fileSystemWatcher.Path = publishFolder;
_fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
_fileSystemWatcher.Filter = PUBLISH_INFO;
_fileSystemWatcher.Changed += FileSystemWatcher_Changed;
_fileSystemWatcher.Created += FileSystemWatcher_Changed;
_fileSystemWatcher.Renamed += FileSystemWatcher_Changed;
_fileSystemWatcher.EnableRaisingEvents = true;
_fileSystemWatcher.IncludeSubdirectories = false;
}

private void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
CheckNewerVersion();
if (NewAppPath != null)
NewVersionFound?.Invoke(this, EventArgs.Empty);
}

public bool CheckNewerVersion()
{
if (!File.Exists(PublishInfoPath))
return false;

Directory.SetCurrentDirectory(Path.GetDirectoryName(PublishInfoPath));

// read json
var json = ReadAllTextAndWait(PublishInfoPath);
var publishInfo = JsonSerializer.Deserialize<PublishInfo>(json);
var version = Version.Parse(publishInfo.Version);
if (version.CompareTo(Assembly.GetEntryAssembly().GetName().Version) != 0)
NewAppPath = publishInfo.LaunchPath;
return NewAppPath != null;
}

private string ReadAllTextAndWait(string fileName, long retry = 5)
{
Exception exception = null;
for (var i = 0; i < retry; i++)
{
try
{
return File.ReadAllText(fileName);
}
catch (IOException ex)
{
exception = ex;
Thread.Sleep(500);
}
}

throw exception;
}

public void Dispose()
{
_fileSystemWatcher?.Dispose();
}

public bool LaunchNewVersion(string[] args = null)
{
if (NewAppPath == null)
CheckNewerVersion();

if (NewAppPath != null)
{
_logger.LogInformation($"\nLaunching the new version!\n{NewAppPath}");
GC.Collect();
Thread.Sleep(2000); // wait to release

// create processStartInfo
ProcessStartInfo processStartInfo = new() { FileName = "dotnet" };
processStartInfo.ArgumentList.Add(NewAppPath);
if (args != null)
{
foreach (var arg in args)
processStartInfo.ArgumentList.Add(arg);
}

Process.Start(processStartInfo);
return true;
}

return false;
}
}
}
13 changes: 11 additions & 2 deletions VpnHood.Common/VpnHood.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/vpnhood/vpnhood</PackageProjectUrl>
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<Product>VpnHood.Common.Generic</Product>
<PackageId>VpnHood.Common.Generic</PackageId>
<Product>VpnHood.Common</Product>
<PackageId>VpnHood.Common</PackageId>
<Version>1.0.0</Version>
<PackageIcon>VpnHood.png</PackageIcon>
<LangVersion>latestMajor</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions VpnHood.Server.Access/VpnHood.Server.Access.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<Version>1.1.0</Version>
<PackageId>VpnHood.Server.Access</PackageId>
<PackageIcon>VpnHood.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
Expand All @@ -21,4 +22,11 @@
<ProjectReference Include="..\VpnHood.Common\VpnHood.Common.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
7 changes: 6 additions & 1 deletion VpnHood.Server.App.NetCore/VpnHood.Server.App.NetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@
<PackageProjectUrl>https://github.com/vpnhood/vpnhood</PackageProjectUrl>
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<PackageIcon>VpnHood.png</PackageIcon>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<None Remove="appsettings.json" />
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
Expand All @@ -31,7 +37,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\VpnHood.Common.AppUpdater\VpnHood.Common.AppUpdater.csproj" />
<ProjectReference Include="..\VpnHood.Tunneling\VpnHood.Tunneling.csproj" />
<ProjectReference Include="..\VpnHood.Server\VpnHood.Server.csproj" />
</ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions VpnHood.Server/VpnHood.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageProjectUrl>https://github.com/vpnhood/vpnhood</PackageProjectUrl>
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageTags>VPN VpnServer Proxy</PackageTags>
<PackageIcon>VpnHood.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
Expand All @@ -24,4 +25,11 @@
<ProjectReference Include="..\VpnHood.Server.Access\VpnHood.Server.Access.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\VpnHood.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
Loading

0 comments on commit 45a6142

Please sign in to comment.