mirror of
https://github.com/ncblakely/GiantsTools
synced 2024-11-21 21:55:38 +01:00
Add post build step for clients assembly. Show message box if launcher fails to start.
This commit is contained in:
parent
957848dad2
commit
006612a655
15
Giants.Launcher/ApplicationNames.cs
Normal file
15
Giants.Launcher/ApplicationNames.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
namespace Giants.Launcher
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
public class ApplicationNames
|
||||||
|
{
|
||||||
|
public const string Giants = nameof(Giants);
|
||||||
|
|
||||||
|
public const string GiantsLauncher = nameof(GiantsLauncher);
|
||||||
|
}
|
||||||
|
}
|
@ -62,6 +62,7 @@
|
|||||||
<Reference Include="System.Core">
|
<Reference Include="System.Core">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Xml.Linq">
|
<Reference Include="System.Xml.Linq">
|
||||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
</Reference>
|
</Reference>
|
||||||
@ -75,6 +76,8 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="ApplicationNames.cs" />
|
||||||
|
<Compile Include="Updater\ApplicationType.cs" />
|
||||||
<Compile Include="WindowType.cs" />
|
<Compile Include="WindowType.cs" />
|
||||||
<Compile Include="GameSettings.cs" />
|
<Compile Include="GameSettings.cs" />
|
||||||
<Compile Include="ImageButton.cs">
|
<Compile Include="ImageButton.cs">
|
||||||
@ -100,7 +103,6 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ScreenResolution.cs" />
|
<Compile Include="ScreenResolution.cs" />
|
||||||
<Compile Include="Updater\UpdateInfo.cs" />
|
<Compile Include="Updater\UpdateInfo.cs" />
|
||||||
<Compile Include="Updater\UpdateType.cs" />
|
|
||||||
<EmbeddedResource Include="LauncherForm.resx">
|
<EmbeddedResource Include="LauncherForm.resx">
|
||||||
<DependentUpon>LauncherForm.cs</DependentUpon>
|
<DependentUpon>LauncherForm.cs</DependentUpon>
|
||||||
<CustomToolNamespace>Giants.Launcher</CustomToolNamespace>
|
<CustomToolNamespace>Giants.Launcher</CustomToolNamespace>
|
||||||
@ -199,7 +201,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>xcopy /DY "$(TargetPath)" "$(GIANTS_PATH)\$(TargetFileName)"</PostBuildEvent>
|
<PostBuildEvent>xcopy /DY "$(TargetPath)" "$(GIANTS_PATH)\$(TargetFileName)*"</PostBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
@ -19,7 +19,6 @@ namespace Giants.Launcher
|
|||||||
private const string GAME_PATH = "GiantsMain.exe";
|
private const string GAME_PATH = "GiantsMain.exe";
|
||||||
private const string REGISTRY_KEY = @"HKEY_CURRENT_USER\Software\PlanetMoon\Giants";
|
private const string REGISTRY_KEY = @"HKEY_CURRENT_USER\Software\PlanetMoon\Giants";
|
||||||
private const string REGISTRY_VALUE = "DestDir";
|
private const string REGISTRY_VALUE = "DestDir";
|
||||||
private const string UPDATE_URL = @"https://google.com"; // update me
|
|
||||||
private readonly VersionClient httpClient;
|
private readonly VersionClient httpClient;
|
||||||
|
|
||||||
private string commandLine = String.Empty;
|
private string commandLine = String.Empty;
|
||||||
@ -28,13 +27,13 @@ namespace Giants.Launcher
|
|||||||
|
|
||||||
public LauncherForm()
|
public LauncherForm()
|
||||||
{
|
{
|
||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
|
|
||||||
// Set window title
|
// Set window title
|
||||||
this.Text = GAME_NAME;
|
this.Text = GAME_NAME;
|
||||||
|
|
||||||
this.httpClient = new VersionClient(new HttpClient());
|
this.httpClient = new VersionClient(new HttpClient());
|
||||||
this.httpClient.BaseUrl = "https://giants.azurewebsites.net";
|
this.httpClient.BaseUrl = "https://giants.azurewebsites.net"; // TODO: Read from file
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnExit_Click(object sender, EventArgs e)
|
private void btnExit_Click(object sender, EventArgs e)
|
||||||
@ -98,36 +97,36 @@ namespace Giants.Launcher
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Version gameVersion = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(this.gamePath);
|
|
||||||
gameVersion = new Version(fvi.FileVersion.Replace(',', '.'));
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (gameVersion == null)
|
|
||||||
{
|
|
||||||
string message = string.Format(Resources.AppNotFound, GAME_NAME);
|
|
||||||
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
Application.Exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read game settings from registry
|
// Read game settings from registry
|
||||||
GameSettings.Load(this.gamePath);
|
GameSettings.Load(this.gamePath);
|
||||||
|
|
||||||
if ((int)GameSettings.Get("NoAutoUpdate") == 0)
|
if ((int)GameSettings.Get("NoAutoUpdate") == 0)
|
||||||
{
|
{
|
||||||
// Check for updates
|
Version gameVersion = null;
|
||||||
this.updater = new Updater(
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(this.gamePath);
|
||||||
|
gameVersion = new Version(fvi.FileVersion.Replace(',', '.'));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (gameVersion == null)
|
||||||
|
{
|
||||||
|
string message = string.Format(Resources.AppNotFound, GAME_NAME);
|
||||||
|
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
Application.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for updates
|
||||||
|
this.updater = new Updater(
|
||||||
appVersion: gameVersion,
|
appVersion: gameVersion,
|
||||||
updateCompletedCallback: this.LauncherForm_DownloadCompletedCallback,
|
updateCompletedCallback: this.LauncherForm_DownloadCompletedCallback,
|
||||||
updateProgressCallback: this.LauncherForm_DownloadProgressCallback);
|
updateProgressCallback: this.LauncherForm_DownloadProgressCallback);
|
||||||
|
|
||||||
Task<VersionInfo> gameVersionInfo = this.GetVersionInfo("Giants");
|
Task<VersionInfo> gameVersionInfo = this.GetVersionInfo(ApplicationNames.Giants);
|
||||||
Task<VersionInfo> launcherVersionInfo = this.GetVersionInfo("GiantsLauncher");
|
Task<VersionInfo> launcherVersionInfo = this.GetVersionInfo(ApplicationNames.GiantsLauncher);
|
||||||
|
|
||||||
await Task.WhenAll(gameVersionInfo, launcherVersionInfo);
|
await Task.WhenAll(gameVersionInfo, launcherVersionInfo);
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Giants.Launcher
|
namespace Giants.Launcher
|
||||||
{
|
{
|
||||||
@ -21,7 +20,7 @@ namespace Giants.Launcher
|
|||||||
if (!mutex.WaitOne(TimeSpan.Zero, true))
|
if (!mutex.WaitOne(TimeSpan.Zero, true))
|
||||||
{
|
{
|
||||||
// Another instance must be running, switch the first process we find with the same name to the foreground:
|
// Another instance must be running, switch the first process we find with the same name to the foreground:
|
||||||
string appName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
|
string appName = Process.GetCurrentProcess().MainModule.FileName;
|
||||||
Process[] processes = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(appName));
|
Process[] processes = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(appName));
|
||||||
|
|
||||||
Process otherProcess = processes.FirstOrDefault(p => p.Id != Process.GetCurrentProcess().Id);
|
Process otherProcess = processes.FirstOrDefault(p => p.Id != Process.GetCurrentProcess().Id);
|
||||||
@ -37,7 +36,19 @@ namespace Giants.Launcher
|
|||||||
|
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new LauncherForm());
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Application.Run(new LauncherForm());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
text: $"Unable to start launcher: {ex.Message}",
|
||||||
|
caption: "Fatal Error",
|
||||||
|
buttons: MessageBoxButtons.OK,
|
||||||
|
icon: MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,4 +36,8 @@
|
|||||||
<RemoveDir Directories="$(OutDir)References" />
|
<RemoveDir Directories="$(OutDir)References" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
<Exec Command="xcopy /DY "$(TargetPath)" "$(GIANTS_PATH)\$(TargetFileName)*"" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user