Skip to content

Commit

Permalink
Fix static services accessor (temporary). Create AppVersionHelper for…
Browse files Browse the repository at this point in the history
… getting app version.
  • Loading branch information
bitbound committed May 2, 2023
1 parent db056a6 commit 4230ad7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Agent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ public static async Task Main(string[] args)

await host.StartAsync();

Services = host.Services;

await Init(host.Services);

await host.WaitForShutdownAsync();
}
catch (Exception ex)
{
var version = typeof(Program).Assembly.GetName().Version?.ToString() ?? "0.0.0";
var version = AppVersionHelper.GetAppVersion();
var logger = new FileLogger("Remotely_Agent", version, "Main");
logger.LogError(ex, "Error during agent startup.");
throw;
Expand Down
2 changes: 1 addition & 1 deletion Desktop.Linux/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using Immense.RemoteControl.Desktop.Shared.Startup;
using System.Linq;

var version = typeof(Program).Assembly.GetName().Version?.ToString() ?? "0.0.0";
var version = AppVersionHelper.GetAppVersion();
var logger = new FileLogger("Remotely_Desktop", version, "Program.cs");
var filePath = Environment.ProcessPath ?? Environment.GetCommandLineArgs().First();
var serverUrl = Debugger.IsAttached ? "http://localhost:5000" : string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion Desktop.Win/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using Immense.RemoteControl.Desktop.Shared.Startup;
using System.Linq;

var version = typeof(Program).Assembly.GetName().Version?.ToString() ?? "0.0.0";
var version = AppVersionHelper.GetAppVersion();
var logger = new FileLogger("Remotely_Desktop", version, "Program.cs");
var filePath = Environment.ProcessPath ?? Environment.GetCommandLineArgs().First();
var serverUrl = Debugger.IsAttached ? "https://localhost:5001" : string.Empty;
Expand Down
10 changes: 1 addition & 9 deletions Server/Pages/About.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,5 @@
Open-Source Licenses: <a href="/credits">Credits</a>
</p>
<p>
Version: @if (System.IO.File.Exists("Remotely_Server.dll"))
{
<span>@System.Diagnostics.FileVersionInfo.GetVersionInfo("Remotely_Server.dll").FileVersion</span>
}
else
{
<span>1.0.0.0</span>
}

Version: @(AppVersionHelper.GetAppVersion())
</p>
41 changes: 41 additions & 0 deletions Shared/Utilities/AppVersionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Remotely.Shared.Utilities
{
public static class AppVersionHelper
{
public static string GetAppVersion(string defaultVersion = "1.0.0")
{
try
{
if (File.Exists(Environment.ProcessPath))
{
var versionInfo = FileVersionInfo.GetVersionInfo(Environment.ProcessPath);
if (!string.IsNullOrEmpty(versionInfo.FileVersion))
{
return versionInfo.FileVersion;
}
}

var asmVersion = Assembly.GetEntryAssembly()?.GetName().Version;
if (asmVersion is not null && asmVersion > new Version(1, 0, 0))
{
return asmVersion.ToString();
}

return defaultVersion;
}
catch
{
return defaultVersion;
}
}
}
}

0 comments on commit 4230ad7

Please sign in to comment.