1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-22 06:05:38 +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"> <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.

View File

@ -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;
@ -34,7 +33,7 @@ namespace Giants.Launcher
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,6 +97,11 @@ namespace Giants.Launcher
} }
} }
// Read game settings from registry
GameSettings.Load(this.gamePath);
if ((int)GameSettings.Get("NoAutoUpdate") == 0)
{
Version gameVersion = null; Version gameVersion = null;
try try
{ {
@ -115,19 +119,14 @@ namespace Giants.Launcher
} }
} }
// Read game settings from registry
GameSettings.Load(this.gamePath);
if ((int)GameSettings.Get("NoAutoUpdate") == 0)
{
// Check for updates // Check for updates
this.updater = new Updater( 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);

View File

@ -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,8 +36,20 @@ namespace Giants.Launcher
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
try
{
Application.Run(new LauncherForm()); 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" /> <RemoveDir Directories="$(OutDir)References" />
</Target> </Target>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy /DY &quot;$(TargetPath)&quot; &quot;$(GIANTS_PATH)\$(TargetFileName)*&quot;" />
</Target>
</Project> </Project>