1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-21 13:45:37 +01:00

Add post build step for clients assembly. Show message box if launcher fails to start.

This commit is contained in:
Nick Blakely 2020-08-11 01:55:57 -07:00
parent 957848dad2
commit 006612a655
5 changed files with 63 additions and 32 deletions

View 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);
}
}

View File

@ -62,6 +62,7 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@ -75,6 +76,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationNames.cs" />
<Compile Include="Updater\ApplicationType.cs" />
<Compile Include="WindowType.cs" />
<Compile Include="GameSettings.cs" />
<Compile Include="ImageButton.cs">
@ -100,7 +103,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScreenResolution.cs" />
<Compile Include="Updater\UpdateInfo.cs" />
<Compile Include="Updater\UpdateType.cs" />
<EmbeddedResource Include="LauncherForm.resx">
<DependentUpon>LauncherForm.cs</DependentUpon>
<CustomToolNamespace>Giants.Launcher</CustomToolNamespace>
@ -199,7 +201,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /DY "$(TargetPath)" "$(GIANTS_PATH)\$(TargetFileName)"</PostBuildEvent>
<PostBuildEvent>xcopy /DY "$(TargetPath)" "$(GIANTS_PATH)\$(TargetFileName)*"</PostBuildEvent>
</PropertyGroup>
<!-- 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.

View File

@ -19,7 +19,6 @@ namespace Giants.Launcher
private const string GAME_PATH = "GiantsMain.exe";
private const string REGISTRY_KEY = @"HKEY_CURRENT_USER\Software\PlanetMoon\Giants";
private const string REGISTRY_VALUE = "DestDir";
private const string UPDATE_URL = @"https://google.com"; // update me
private readonly VersionClient httpClient;
private string commandLine = String.Empty;
@ -28,13 +27,13 @@ namespace Giants.Launcher
public LauncherForm()
{
this.InitializeComponent();
this.InitializeComponent();
// Set window title
this.Text = GAME_NAME;
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)
@ -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
GameSettings.Load(this.gamePath);
if ((int)GameSettings.Get("NoAutoUpdate") == 0)
{
// Check for updates
this.updater = new Updater(
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();
}
}
// Check for updates
this.updater = new Updater(
appVersion: gameVersion,
updateCompletedCallback: this.LauncherForm_DownloadCompletedCallback,
updateProgressCallback: this.LauncherForm_DownloadProgressCallback);
Task<VersionInfo> gameVersionInfo = this.GetVersionInfo("Giants");
Task<VersionInfo> launcherVersionInfo = this.GetVersionInfo("GiantsLauncher");
Task<VersionInfo> gameVersionInfo = this.GetVersionInfo(ApplicationNames.Giants);
Task<VersionInfo> launcherVersionInfo = this.GetVersionInfo(ApplicationNames.GiantsLauncher);
await Task.WhenAll(gameVersionInfo, launcherVersionInfo);

View File

@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
namespace Giants.Launcher
{
@ -21,7 +20,7 @@ namespace Giants.Launcher
if (!mutex.WaitOne(TimeSpan.Zero, true))
{
// 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 otherProcess = processes.FirstOrDefault(p => p.Id != Process.GetCurrentProcess().Id);
@ -37,7 +36,19 @@ namespace Giants.Launcher
Application.EnableVisualStyles();
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);
}
}
}
}

View File

@ -36,4 +36,8 @@
<RemoveDir Directories="$(OutDir)References" />
</Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy /DY &quot;$(TargetPath)&quot; &quot;$(GIANTS_PATH)\$(TargetFileName)*&quot;" />
</Target>
</Project>