Add old launcher project from 2012.
48
Giants.Launcher/Common.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
class ScreenResolution : IComparable
|
||||
{
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
|
||||
public ScreenResolution(int width, int height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
if (obj == null) return 1;
|
||||
|
||||
ScreenResolution other = obj as ScreenResolution;
|
||||
if (other == null)
|
||||
throw new ArgumentException();
|
||||
|
||||
if (this.Width > other.Width)
|
||||
return 1;
|
||||
else if (this.Width == other.Width && this.Height == other.Height)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}x{1}", Width, Height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum WindowType
|
||||
{
|
||||
Fullscreen = 0,
|
||||
Windowed = 1,
|
||||
Borderless = 2,
|
||||
}
|
||||
}
|
24
Giants.Launcher/Extensions.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
public static class RegistryExtensions
|
||||
{
|
||||
// Extension to Registry.GetValue() that returns the default value if the returned object does not
|
||||
// match the type specified.
|
||||
public static object GetValue(string keyName, string valueName, object defaultValue, Type type)
|
||||
{
|
||||
object retVal = Registry.GetValue(keyName, valueName, defaultValue);
|
||||
|
||||
if (retVal.GetType() != type)
|
||||
return defaultValue;
|
||||
else
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
122
Giants.Launcher/GameSettings.cs
Normal file
@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
static class GameSettings
|
||||
{
|
||||
// Constants
|
||||
private const string REGISTRY_KEY = @"HKEY_CURRENT_USER\Software\PlanetMoon\Giants";
|
||||
private const int OPTIONS_VERSION = 3;
|
||||
|
||||
private static Dictionary<string, object> _Settings = new Dictionary<string, object>();
|
||||
|
||||
// List of renderers compatible with the user's system.
|
||||
static public List<RendererInterop.Capabilities> CompatibleRenderers;
|
||||
|
||||
public static object Get(string settingName)
|
||||
{
|
||||
if (_Settings.ContainsKey(settingName))
|
||||
return _Settings[settingName];
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
public static void Modify(string settingName, object settingValue)
|
||||
{
|
||||
_Settings[settingName] = settingValue;
|
||||
}
|
||||
|
||||
public static void SetDefaults(string gamePath)
|
||||
{
|
||||
// Set default settings:
|
||||
_Settings["Renderer"] = "gg_dx7r.dll";
|
||||
_Settings["Antialiasing"] = 0;
|
||||
_Settings["AnisotropicFiltering"] = 0;
|
||||
_Settings["VideoWidth"] = 640;
|
||||
_Settings["VideoHeight"] = 480;
|
||||
_Settings["VideoDepth"] = 32;
|
||||
_Settings["Windowed"] = 0;
|
||||
_Settings["BorderlessWindow"] = 0;
|
||||
_Settings["VerticalSync"] = 1;
|
||||
_Settings["TripleBuffering"] = 1;
|
||||
_Settings["NoAutoUpdate"] = 0;
|
||||
|
||||
// Get a list of renderers compatible with the user's system
|
||||
if (CompatibleRenderers == null)
|
||||
{
|
||||
CompatibleRenderers = RendererInterop.GetCompatibleRenderers(gamePath);
|
||||
if (CompatibleRenderers.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Could not locate any renderers compatible with your system. The most compatible renderer has been selected, but you may experience difficulty running the game.",
|
||||
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// Select the highest priority renderer
|
||||
if (CompatibleRenderers.Count > 0)
|
||||
_Settings["Renderer"] = Path.GetFileName(CompatibleRenderers.Max().FilePath);
|
||||
|
||||
// Set the current desktop resolution, leaving bit depth at the default 32:
|
||||
_Settings["VideoWidth"] = Screen.PrimaryScreen.Bounds.Width;
|
||||
_Settings["VideoHeight"] = Screen.PrimaryScreen.Bounds.Height;
|
||||
}
|
||||
|
||||
public static void Load(string gamePath)
|
||||
{
|
||||
SetDefaults(gamePath);
|
||||
|
||||
if ((int)Registry.GetValue(REGISTRY_KEY, "GameOptionsVersion", 0) == OPTIONS_VERSION)
|
||||
{
|
||||
try
|
||||
{
|
||||
_Settings["Renderer"] = RegistryExtensions.GetValue(REGISTRY_KEY, "Renderer", _Settings["Renderer"], typeof(string));
|
||||
//System.Diagnostics.Debug.Assert(_Settings["Renderer"] is string);
|
||||
_Settings["Antialiasing"] = RegistryExtensions.GetValue(REGISTRY_KEY, "Antialiasing", _Settings["Antialiasing"], typeof(int));
|
||||
_Settings["AnisotropicFiltering"] = RegistryExtensions.GetValue(REGISTRY_KEY, "AnisotropicFiltering", _Settings["AnisotropicFiltering"], typeof(int));
|
||||
_Settings["VideoWidth"] = RegistryExtensions.GetValue(REGISTRY_KEY, "VideoWidth", _Settings["VideoWidth"], typeof(int));
|
||||
_Settings["VideoHeight"] = RegistryExtensions.GetValue(REGISTRY_KEY, "VideoHeight", _Settings["VideoHeight"], typeof(int));
|
||||
_Settings["VideoDepth"] = RegistryExtensions.GetValue(REGISTRY_KEY, "VideoDepth", _Settings["VideoDepth"], typeof(int));
|
||||
_Settings["Windowed"] = RegistryExtensions.GetValue(REGISTRY_KEY, "Windowed", _Settings["Windowed"], typeof(int));
|
||||
_Settings["BorderlessWindow"] = RegistryExtensions.GetValue(REGISTRY_KEY, "BorderlessWindow", _Settings["BorderlessWindow"], typeof(int));
|
||||
_Settings["VerticalSync"] = RegistryExtensions.GetValue(REGISTRY_KEY, "VerticalSync", _Settings["VerticalSync"], typeof(int));
|
||||
_Settings["TripleBuffering"] = RegistryExtensions.GetValue(REGISTRY_KEY, "TripleBuffering", _Settings["TripleBuffering"], typeof(int));
|
||||
_Settings["NoAutoUpdate"] = RegistryExtensions.GetValue(REGISTRY_KEY, "NoAutoUpdate", _Settings["NoAutoUpdate"], typeof(int));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(string.Format("Could not read game settings from registry!\n\nReason: {0}", ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
Registry.SetValue(REGISTRY_KEY, "GameOptionsVersion", 3, RegistryValueKind.DWord);
|
||||
Registry.SetValue(REGISTRY_KEY, "Renderer", _Settings["Renderer"], RegistryValueKind.String);
|
||||
Registry.SetValue(REGISTRY_KEY, "Antialiasing", _Settings["Antialiasing"], RegistryValueKind.DWord);
|
||||
Registry.SetValue(REGISTRY_KEY, "AnisotropicFiltering", _Settings["AnisotropicFiltering"], RegistryValueKind.DWord);
|
||||
Registry.SetValue(REGISTRY_KEY, "VideoWidth", _Settings["VideoWidth"], RegistryValueKind.DWord);
|
||||
Registry.SetValue(REGISTRY_KEY, "VideoHeight", _Settings["VideoHeight"], RegistryValueKind.DWord);
|
||||
Registry.SetValue(REGISTRY_KEY, "VideoDepth", _Settings["VideoDepth"], RegistryValueKind.DWord);
|
||||
Registry.SetValue(REGISTRY_KEY, "Windowed", _Settings["Windowed"], RegistryValueKind.DWord);
|
||||
Registry.SetValue(REGISTRY_KEY, "BorderlessWindow", _Settings["BorderlessWindow"], RegistryValueKind.DWord);
|
||||
Registry.SetValue(REGISTRY_KEY, "VerticalSync", _Settings["VerticalSync"], RegistryValueKind.DWord);
|
||||
Registry.SetValue(REGISTRY_KEY, "TripleBuffering", _Settings["TripleBuffering"], RegistryValueKind.DWord);
|
||||
Registry.SetValue(REGISTRY_KEY, "NoAutoUpdate", _Settings["NoAutoUpdate"], RegistryValueKind.DWord);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(string.Format("Could not save game settings to registry!\n\nReason: {0}", ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
199
Giants.Launcher/Giants.Launcher.csproj
Normal file
@ -0,0 +1,199 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{612FD606-F072-4A04-9054-65BC592E9D3E}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Giants.Launcher</RootNamespace>
|
||||
<AssemblyName>Giants</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ApplicationIcon>giants.ico</ApplicationIcon>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Common.cs" />
|
||||
<Compile Include="GameSettings.cs" />
|
||||
<Compile Include="ImageButton.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="LauncherForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
<CustomToolNamespace>Giants.Launcher</CustomToolNamespace>
|
||||
</Compile>
|
||||
<Compile Include="LauncherForm.Designer.cs">
|
||||
<DependentUpon>LauncherForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Native\NativeMethods.cs" />
|
||||
<Compile Include="Native\RendererInterop.cs" />
|
||||
<Compile Include="OptionsForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
<CustomToolNamespace>Giants.Launcher</CustomToolNamespace>
|
||||
</Compile>
|
||||
<Compile Include="OptionsForm.Designer.cs">
|
||||
<DependentUpon>OptionsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="LauncherForm.resx">
|
||||
<DependentUpon>LauncherForm.cs</DependentUpon>
|
||||
<CustomToolNamespace>Giants.Launcher</CustomToolNamespace>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="OptionsForm.resx">
|
||||
<DependentUpon>OptionsForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
<CustomToolNamespace>Giants.Launcher</CustomToolNamespace>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="Updater.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\LauncherStart.wav" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\backdrop.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\exit.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\options.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\play.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\playhover.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\playpush.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\exithover.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\exitpush.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\optionshover.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="Resources\optionspush.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="giants.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<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.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
231
Giants.Launcher/ImageButton.cs
Normal file
@ -0,0 +1,231 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
public class ImageButton : PictureBox, IButtonControl
|
||||
{
|
||||
|
||||
#region IButtonControl Members
|
||||
|
||||
private DialogResult m_DialogResult;
|
||||
public DialogResult DialogResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_DialogResult;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_DialogResult = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyDefault(bool value)
|
||||
{
|
||||
isDefault = value;
|
||||
}
|
||||
|
||||
public void PerformClick()
|
||||
{
|
||||
base.OnClick(EventArgs.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HoverImage
|
||||
private Image m_HoverImage;
|
||||
|
||||
[Category("Appearance")]
|
||||
[Description("Image to show when the button is hovered over.")]
|
||||
public Image HoverImage
|
||||
{
|
||||
get { return m_HoverImage; }
|
||||
set { m_HoverImage = value; if (hover) Image = value; }
|
||||
}
|
||||
#endregion
|
||||
#region DownImage
|
||||
private Image m_DownImage;
|
||||
|
||||
[Category("Appearance")]
|
||||
[Description("Image to show when the button is depressed.")]
|
||||
public Image DownImage
|
||||
{
|
||||
get { return m_DownImage; }
|
||||
set { m_DownImage = value; if (down) Image = value; }
|
||||
}
|
||||
#endregion
|
||||
#region NormalImage
|
||||
private Image m_NormalImage;
|
||||
|
||||
[Category("Appearance")]
|
||||
[Description("Image to show when the button is not in any other state.")]
|
||||
public Image NormalImage
|
||||
{
|
||||
get { return m_NormalImage; }
|
||||
set { m_NormalImage = value; if (!(hover || down)) Image = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
private const int WM_KEYDOWN = 0x0100;
|
||||
private const int WM_KEYUP = 0x0101;
|
||||
private bool hover = false;
|
||||
private bool down = false;
|
||||
private bool isDefault = false;
|
||||
|
||||
#region Overrides
|
||||
|
||||
[Browsable(true)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
||||
[Category("Appearance")]
|
||||
[Description("The text associated with the control.")]
|
||||
public override string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(true)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
||||
[Category("Appearance")]
|
||||
[Description("The font used to display text in the control.")]
|
||||
public override Font Font
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Font;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Font = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Description Changes
|
||||
[Description("Controls how the ImageButton will handle image placement and control sizing.")]
|
||||
public new PictureBoxSizeMode SizeMode { get { return base.SizeMode; } set { base.SizeMode = value; } }
|
||||
|
||||
[Description("Controls what type of border the ImageButton should have.")]
|
||||
public new BorderStyle BorderStyle { get { return base.BorderStyle; } set { base.BorderStyle = value; } }
|
||||
#endregion
|
||||
|
||||
#region Hiding
|
||||
|
||||
[Browsable(false)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public new Image Image { get { return base.Image; } set { base.Image = value; } }
|
||||
|
||||
[Browsable(false)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public new ImageLayout BackgroundImageLayout { get { return base.BackgroundImageLayout; } set { base.BackgroundImageLayout = value; } }
|
||||
|
||||
[Browsable(false)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public new Image BackgroundImage { get { return base.BackgroundImage; } set { base.BackgroundImage = value; } }
|
||||
|
||||
[Browsable(false)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public new String ImageLocation { get { return base.ImageLocation; } set { base.ImageLocation = value; } }
|
||||
|
||||
[Browsable(false)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public new Image ErrorImage { get { return base.ErrorImage; } set { base.ErrorImage = value; } }
|
||||
|
||||
[Browsable(false)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public new Image InitialImage { get { return base.InitialImage; } set { base.InitialImage = value; } }
|
||||
|
||||
[Browsable(false)]
|
||||
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public new bool WaitOnLoad { get { return base.WaitOnLoad; } set { base.WaitOnLoad = value; } }
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
hover = true;
|
||||
if (down)
|
||||
{
|
||||
if ((m_DownImage != null) && (Image != m_DownImage))
|
||||
Image = m_DownImage;
|
||||
}
|
||||
else
|
||||
if (m_HoverImage != null)
|
||||
Image = m_HoverImage;
|
||||
else
|
||||
Image = m_NormalImage;
|
||||
base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
hover = false;
|
||||
Image = m_NormalImage;
|
||||
base.OnMouseLeave(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.Focus();
|
||||
OnMouseUp(null);
|
||||
down = true;
|
||||
if (m_DownImage != null)
|
||||
Image = m_DownImage;
|
||||
base.OnMouseDown(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
down = false;
|
||||
if (hover)
|
||||
{
|
||||
if (m_HoverImage != null)
|
||||
Image = m_HoverImage;
|
||||
}
|
||||
else
|
||||
Image = m_NormalImage;
|
||||
base.OnMouseUp(e);
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
OnMouseUp(null);
|
||||
base.OnLostFocus(e);
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs pe)
|
||||
{
|
||||
base.OnPaint(pe);
|
||||
if ((!string.IsNullOrEmpty(Text)) && (pe != null) && (base.Font != null))
|
||||
{
|
||||
SolidBrush drawBrush = new SolidBrush(base.ForeColor);
|
||||
SizeF drawStringSize = pe.Graphics.MeasureString(base.Text, base.Font);
|
||||
PointF drawPoint;
|
||||
if (base.Image != null)
|
||||
drawPoint = new PointF(base.Image.Width / 2 - drawStringSize.Width / 2, base.Image.Height / 2 - drawStringSize.Height / 2);
|
||||
else
|
||||
drawPoint = new PointF(base.Width / 2 - drawStringSize.Width / 2, base.Height / 2 - drawStringSize.Height / 2);
|
||||
pe.Graphics.DrawString(base.Text, base.Font, drawBrush, drawPoint);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnTextChanged(EventArgs e)
|
||||
{
|
||||
Refresh();
|
||||
base.OnTextChanged(e);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
150
Giants.Launcher/LauncherForm.Designer.cs
generated
Normal file
@ -0,0 +1,150 @@
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
partial class LauncherForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LauncherForm));
|
||||
this.btnExit = new Launcher.ImageButton();
|
||||
this.btnOptions = new Launcher.ImageButton();
|
||||
this.btnPlay = new Launcher.ImageButton();
|
||||
this.updateProgressBar = new System.Windows.Forms.ProgressBar();
|
||||
this.txtProgress = new System.Windows.Forms.Label();
|
||||
((System.ComponentModel.ISupportInitialize)(this.btnExit)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.btnOptions)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.btnPlay)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnExit
|
||||
//
|
||||
this.btnExit.BackColor = System.Drawing.Color.Transparent;
|
||||
this.btnExit.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.btnExit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.btnExit.DownImage = Resources.exitpush;
|
||||
this.btnExit.HoverImage = Resources.exithover;
|
||||
this.btnExit.Location = new System.Drawing.Point(618, 451);
|
||||
this.btnExit.Name = "btnExit";
|
||||
this.btnExit.NormalImage = Resources.exit;
|
||||
this.btnExit.Size = new System.Drawing.Size(100, 50);
|
||||
this.btnExit.TabIndex = 8;
|
||||
this.btnExit.TabStop = false;
|
||||
this.btnExit.Visible = false;
|
||||
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
|
||||
//
|
||||
// btnOptions
|
||||
//
|
||||
this.btnOptions.BackColor = System.Drawing.Color.Transparent;
|
||||
this.btnOptions.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.btnOptions.DialogResult = System.Windows.Forms.DialogResult.None;
|
||||
this.btnOptions.DownImage = Resources.optionspush;
|
||||
this.btnOptions.HoverImage = Resources.optionshover;
|
||||
this.btnOptions.Location = new System.Drawing.Point(618, 395);
|
||||
this.btnOptions.Name = "btnOptions";
|
||||
this.btnOptions.NormalImage = Resources.options;
|
||||
this.btnOptions.Size = new System.Drawing.Size(118, 50);
|
||||
this.btnOptions.TabIndex = 7;
|
||||
this.btnOptions.TabStop = false;
|
||||
this.btnOptions.Visible = false;
|
||||
this.btnOptions.Click += new System.EventHandler(this.btnOptions_Click);
|
||||
//
|
||||
// btnPlay
|
||||
//
|
||||
this.btnPlay.BackColor = System.Drawing.Color.Transparent;
|
||||
this.btnPlay.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
this.btnPlay.DialogResult = System.Windows.Forms.DialogResult.None;
|
||||
this.btnPlay.DownImage = Resources.playpush;
|
||||
this.btnPlay.HoverImage = Resources.playhover;
|
||||
this.btnPlay.Location = new System.Drawing.Point(618, 339);
|
||||
this.btnPlay.Name = "btnPlay";
|
||||
this.btnPlay.NormalImage = ((System.Drawing.Image)(resources.GetObject("btnPlay.NormalImage")));
|
||||
this.btnPlay.Size = new System.Drawing.Size(100, 50);
|
||||
this.btnPlay.TabIndex = 6;
|
||||
this.btnPlay.TabStop = false;
|
||||
this.btnPlay.Visible = false;
|
||||
this.btnPlay.Click += new System.EventHandler(this.btnPlay_Click);
|
||||
//
|
||||
// updateProgressBar
|
||||
//
|
||||
this.updateProgressBar.Location = new System.Drawing.Point(64, 465);
|
||||
this.updateProgressBar.Name = "updateProgressBar";
|
||||
this.updateProgressBar.Size = new System.Drawing.Size(534, 23);
|
||||
this.updateProgressBar.TabIndex = 9;
|
||||
this.updateProgressBar.Visible = false;
|
||||
//
|
||||
// txtProgress
|
||||
//
|
||||
this.txtProgress.AutoSize = true;
|
||||
this.txtProgress.BackColor = System.Drawing.Color.Transparent;
|
||||
this.txtProgress.ForeColor = System.Drawing.SystemColors.HighlightText;
|
||||
this.txtProgress.Location = new System.Drawing.Point(65, 449);
|
||||
this.txtProgress.Name = "txtProgress";
|
||||
this.txtProgress.Size = new System.Drawing.Size(69, 13);
|
||||
this.txtProgress.TabIndex = 10;
|
||||
this.txtProgress.Text = "ProgressText";
|
||||
this.txtProgress.Visible = false;
|
||||
//
|
||||
// LauncherForm
|
||||
//
|
||||
this.AcceptButton = this.btnPlay;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
|
||||
this.CancelButton = this.btnExit;
|
||||
this.ClientSize = new System.Drawing.Size(800, 500);
|
||||
this.ControlBox = false;
|
||||
this.Controls.Add(this.txtProgress);
|
||||
this.Controls.Add(this.updateProgressBar);
|
||||
this.Controls.Add(this.btnExit);
|
||||
this.Controls.Add(this.btnOptions);
|
||||
this.Controls.Add(this.btnPlay);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Name = "LauncherForm";
|
||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Launcher";
|
||||
this.Load += new System.EventHandler(this.LauncherForm_Load);
|
||||
this.Shown += new System.EventHandler(this.LauncherForm_Shown);
|
||||
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LauncherForm_MouseDown);
|
||||
((System.ComponentModel.ISupportInitialize)(this.btnExit)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.btnOptions)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.btnPlay)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ImageButton btnPlay;
|
||||
private ImageButton btnOptions;
|
||||
private ImageButton btnExit;
|
||||
private System.Windows.Forms.ProgressBar updateProgressBar;
|
||||
private System.Windows.Forms.Label txtProgress;
|
||||
}
|
||||
}
|
||||
|
199
Giants.Launcher/LauncherForm.cs
Normal file
@ -0,0 +1,199 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Media;
|
||||
using System.Net;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
public partial class LauncherForm : Form
|
||||
{
|
||||
// Constant settings
|
||||
const string GAME_NAME = "Giants: Citizen Kabuto";
|
||||
const string GAME_PATH = "GiantsMain.exe";
|
||||
const string REGISTRY_KEY = @"HKEY_CURRENT_USER\Software\PlanetMoon\Giants";
|
||||
const string REGISTRY_VALUE = "DestDir";
|
||||
const string UPDATE_URL = @"https://google.com"; // update me
|
||||
|
||||
string _commandLine = String.Empty;
|
||||
string _gamePath = null;
|
||||
Updater _Updater;
|
||||
|
||||
public LauncherForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// Set window title
|
||||
this.Text = GAME_NAME;
|
||||
}
|
||||
|
||||
private void btnExit_Click(object sender, EventArgs e)
|
||||
{
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
private void btnPlay_Click(object sender, EventArgs e)
|
||||
{
|
||||
GameSettings.Save();
|
||||
|
||||
foreach (string c in Environment.GetCommandLineArgs())
|
||||
_commandLine = _commandLine + c + " ";
|
||||
|
||||
string commandLine = string.Format("{0} -launcher", _commandLine.Trim());
|
||||
|
||||
try
|
||||
{
|
||||
Process gameProcess = new Process();
|
||||
|
||||
gameProcess.StartInfo.Arguments = commandLine;
|
||||
gameProcess.StartInfo.FileName = _gamePath;
|
||||
gameProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(_gamePath);
|
||||
|
||||
gameProcess.Start();
|
||||
Application.Exit();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show(string.Format("Failed to launch game process at: {0}. {1}", _gamePath, ex.Message),
|
||||
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnOptions_Click(object sender, EventArgs e)
|
||||
{
|
||||
OptionsForm form = new OptionsForm(GAME_NAME + " Options", _gamePath);
|
||||
|
||||
//form.MdiParent = this;
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void LauncherForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
// Find the game executable, first looking for it relative to our current directory and then
|
||||
// using the registry path if that fails.
|
||||
_gamePath = Path.GetDirectoryName(Application.ExecutablePath) + "\\" + GAME_PATH;
|
||||
if (!File.Exists(_gamePath))
|
||||
{
|
||||
_gamePath = (string)Registry.GetValue(REGISTRY_KEY, REGISTRY_VALUE, null);
|
||||
if (_gamePath != null)
|
||||
_gamePath = Path.Combine(_gamePath, GAME_PATH);
|
||||
|
||||
if (_gamePath == null || !File.Exists(_gamePath))
|
||||
{
|
||||
string message = string.Format(Resources.AppNotFound, GAME_NAME);
|
||||
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Application.Exit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Version gameVersion = null;
|
||||
try
|
||||
{
|
||||
|
||||
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(_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(_gamePath);
|
||||
|
||||
if ((int)GameSettings.Get("NoAutoUpdate") == 0)
|
||||
{
|
||||
// Check for updates
|
||||
_Updater = new Updater(new Uri(UPDATE_URL), gameVersion);
|
||||
_Updater.DownloadUpdateInfo(LauncherForm_DownloadCompletedCallback, LauncherForm_DownloadProgressCallback);
|
||||
}
|
||||
}
|
||||
|
||||
private void LauncherForm_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
// Force window to be draggable even though we have no menu bar
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
NativeMethods.ReleaseCapture();
|
||||
NativeMethods.SendMessage(Handle, NativeMethods.WM_NCLBUTTONDOWN, NativeMethods.HT_CAPTION, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LauncherForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
btnOptions.Visible = true;
|
||||
btnPlay.Visible = true;
|
||||
btnExit.Visible = true;
|
||||
|
||||
// Play intro sound
|
||||
SoundPlayer player = new SoundPlayer(Resources.LauncherStart);
|
||||
player.Play();
|
||||
}
|
||||
|
||||
private void LauncherForm_DownloadCompletedCallback(object sender, AsyncCompletedEventArgs e)
|
||||
{
|
||||
if (e.Cancelled)
|
||||
return;
|
||||
|
||||
updateProgressBar.Value = 0;
|
||||
updateProgressBar.Visible = false;
|
||||
txtProgress.Visible = false;
|
||||
|
||||
if (e.Error != null)
|
||||
{
|
||||
string errorMsg = string.Format(Resources.UpdateDownloadFailedText, e.Error.Message);
|
||||
MessageBox.Show(errorMsg, Resources.UpdateDownloadFailedTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show "Download Complete" message, warn that we're closing
|
||||
MessageBox.Show(Resources.LauncherClosingText, Resources.LauncherClosingTitle);
|
||||
|
||||
UpdateInfo updateInfo = (UpdateInfo)e.UserState;
|
||||
|
||||
// Start the installer process
|
||||
Process updaterProcess = new Process();
|
||||
updaterProcess.StartInfo.FileName = Path.Combine(Path.GetTempPath(), updateInfo.FileName);
|
||||
updaterProcess.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
|
||||
|
||||
if (updateInfo.UpdateType == UpdateType.Game)
|
||||
{
|
||||
// Default installation directory to current directory
|
||||
updaterProcess.StartInfo.Arguments = string.Format("/D {0}", Path.GetDirectoryName(Application.ExecutablePath));
|
||||
}
|
||||
else if (updateInfo.UpdateType == UpdateType.Launcher)
|
||||
{
|
||||
// Default installation directory to current directory and launch a silent install
|
||||
updaterProcess.StartInfo.Arguments = string.Format("/S /D {0}", Path.GetDirectoryName(Application.ExecutablePath));
|
||||
}
|
||||
|
||||
updaterProcess.Start();
|
||||
|
||||
Application.Exit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void LauncherForm_DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)
|
||||
{
|
||||
updateProgressBar.Visible = true;
|
||||
updateProgressBar.Value = e.ProgressPercentage;
|
||||
|
||||
UpdateInfo info = (UpdateInfo)e.UserState;
|
||||
|
||||
txtProgress.Visible = true;
|
||||
txtProgress.Text = string.Format(Resources.DownloadProgress, e.ProgressPercentage, (info.FileSize / 1024) / 1024);
|
||||
}
|
||||
}
|
||||
}
|
14582
Giants.Launcher/LauncherForm.resx
Normal file
77
Giants.Launcher/Native/NativeMethods.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
static class NativeMethods
|
||||
{
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern IntPtr LoadLibrary(string dllToLoad);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern bool FreeLibrary(IntPtr hModule);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
public const int WM_NCLBUTTONDOWN = 0xA1;
|
||||
public const int HT_CAPTION = 0x2;
|
||||
|
||||
[DllImportAttribute("user32.dll")]
|
||||
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
|
||||
[DllImportAttribute("user32.dll")]
|
||||
public static extern bool ReleaseCapture();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool EnumDisplaySettings(
|
||||
string deviceName, int modeNum, ref DEVMODE devMode);
|
||||
const int ENUM_CURRENT_SETTINGS = -1;
|
||||
|
||||
const int ENUM_REGISTRY_SETTINGS = -2;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct DEVMODE
|
||||
{
|
||||
|
||||
private const int CCHDEVICENAME = 0x20;
|
||||
private const int CCHFORMNAME = 0x20;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
|
||||
public string dmDeviceName;
|
||||
public short dmSpecVersion;
|
||||
public short dmDriverVersion;
|
||||
public short dmSize;
|
||||
public short dmDriverExtra;
|
||||
public int dmFields;
|
||||
public int dmPositionX;
|
||||
public int dmPositionY;
|
||||
public ScreenOrientation dmDisplayOrientation;
|
||||
public int dmDisplayFixedOutput;
|
||||
public short dmColor;
|
||||
public short dmDuplex;
|
||||
public short dmYResolution;
|
||||
public short dmTTOption;
|
||||
public short dmCollate;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
|
||||
public string dmFormName;
|
||||
public short dmLogPixels;
|
||||
public int dmBitsPerPel;
|
||||
public int dmPelsWidth;
|
||||
public int dmPelsHeight;
|
||||
public int dmDisplayFlags;
|
||||
public int dmDisplayFrequency;
|
||||
public int dmICMMethod;
|
||||
public int dmICMIntent;
|
||||
public int dmMediaType;
|
||||
public int dmDitherType;
|
||||
public int dmReserved1;
|
||||
public int dmReserved2;
|
||||
public int dmPanningWidth;
|
||||
public int dmPanningHeight;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
139
Giants.Launcher/Native/RendererInterop.cs
Normal file
@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
class RendererInterop
|
||||
{
|
||||
#pragma warning disable 649
|
||||
public struct GFXCapabilityInfo
|
||||
{
|
||||
public int maxAnisotropy;
|
||||
public uint flags;
|
||||
public int priority;
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
||||
public string rendererName;
|
||||
};
|
||||
#pragma warning restore 649
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate bool GFXGetCapabilities(ref GFXCapabilityInfo outCapabilities);
|
||||
|
||||
/// <summary>
|
||||
/// Makes interop call to native renderer DLL to obtain capability information.
|
||||
/// </summary>
|
||||
/// <returns>True if the given renderer is supported by the system.</returns>
|
||||
public static bool GetRendererCapabilities(string dllPath, ref GFXCapabilityInfo capabilities)
|
||||
{
|
||||
bool rendererSupported = false;
|
||||
IntPtr pDll = NativeMethods.LoadLibrary(dllPath);
|
||||
if (pDll == IntPtr.Zero)
|
||||
throw new System.Exception(string.Format("LoadLibrary() for {0} failed", dllPath));
|
||||
|
||||
IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "GFXGetCapabilities");
|
||||
if (pAddressOfFunctionToCall == IntPtr.Zero)
|
||||
return false;
|
||||
|
||||
var prcGetCapabilities = (GFXGetCapabilities)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(GFXGetCapabilities));
|
||||
rendererSupported = prcGetCapabilities(ref capabilities);
|
||||
|
||||
NativeMethods.FreeLibrary(pDll);
|
||||
|
||||
return rendererSupported;
|
||||
}
|
||||
|
||||
|
||||
public static List<Capabilities> GetCompatibleRenderers(string gamePath)
|
||||
{
|
||||
DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(gamePath));
|
||||
|
||||
List<Capabilities> Capabilities = new List<Capabilities>();
|
||||
|
||||
// Search current directory for compatible renderers:
|
||||
foreach (FileInfo file in dir.GetFiles("gg_*.dll"))
|
||||
{
|
||||
try
|
||||
{
|
||||
// Make interop call to native renderer DLLs to get capability info
|
||||
RendererInterop.GFXCapabilityInfo interopCaps = new RendererInterop.GFXCapabilityInfo();
|
||||
string path = Path.Combine(file.DirectoryName, file.Name);
|
||||
if (RendererInterop.GetRendererCapabilities(path, ref interopCaps))
|
||||
{
|
||||
|
||||
Capabilities caps = new Capabilities(path, ref interopCaps);
|
||||
Capabilities.Add(caps);
|
||||
//cmbRenderer.Items.Add(caps);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
return Capabilities;
|
||||
|
||||
// Select highest priority renderer
|
||||
//cmbRenderer.SelectedItem = _RendererCaps.Max();
|
||||
}
|
||||
|
||||
public class Capabilities : IComparable
|
||||
{
|
||||
[Flags]
|
||||
public enum RendererFlag
|
||||
{
|
||||
LowBitDepthAllowed = 0x1,
|
||||
|
||||
// Multisampling support flags:
|
||||
MSAA2x = 0x2,
|
||||
MSAA4x = 0x4,
|
||||
MSAA8x = 0x8,
|
||||
MSAA16x = 0x10,
|
||||
|
||||
// Other options:
|
||||
VSync = 0x20,
|
||||
TripleBuffer = 0x40,
|
||||
|
||||
|
||||
};
|
||||
|
||||
public Capabilities(string filePath, ref RendererInterop.GFXCapabilityInfo gfxCaps)
|
||||
{
|
||||
FilePath = filePath;
|
||||
FileName = Path.GetFileName(filePath);
|
||||
MaxAnisotropy = gfxCaps.maxAnisotropy;
|
||||
Flags = (RendererFlag)gfxCaps.flags;
|
||||
Priority = gfxCaps.priority;
|
||||
Name = gfxCaps.rendererName;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0} ({1})", Name, Path.GetFileName(FilePath));
|
||||
}
|
||||
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
if (obj == null) return 1;
|
||||
|
||||
Capabilities other = obj as Capabilities;
|
||||
if (other != null)
|
||||
return this.Priority.CompareTo(other.Priority);
|
||||
else
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
public string FilePath { get; private set; }
|
||||
public string FileName { get; private set; }
|
||||
public int MaxAnisotropy { get; private set; }
|
||||
public RendererFlag Flags { get; private set; }
|
||||
public int Priority { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
294
Giants.Launcher/OptionsForm.Designer.cs
generated
Normal file
@ -0,0 +1,294 @@
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
partial class OptionsForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.cmbRenderer = new System.Windows.Forms.ComboBox();
|
||||
this.cmbResolution = new System.Windows.Forms.ComboBox();
|
||||
this.cmbAntialiasing = new System.Windows.Forms.ComboBox();
|
||||
this.cmbAnisotropy = new System.Windows.Forms.ComboBox();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.chkTripleBuffering = new System.Windows.Forms.CheckBox();
|
||||
this.chkVSync = new System.Windows.Forms.CheckBox();
|
||||
this.btnOK = new System.Windows.Forms.Button();
|
||||
this.btnCancel = new System.Windows.Forms.Button();
|
||||
this.btnResetDefaults = new System.Windows.Forms.Button();
|
||||
this.groupBox3 = new System.Windows.Forms.GroupBox();
|
||||
this.chkUpdates = new System.Windows.Forms.CheckBox();
|
||||
this.cmbMode = new System.Windows.Forms.ComboBox();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.groupBox3.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// cmbRenderer
|
||||
//
|
||||
this.cmbRenderer.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cmbRenderer.FormattingEnabled = true;
|
||||
this.cmbRenderer.Location = new System.Drawing.Point(124, 19);
|
||||
this.cmbRenderer.Name = "cmbRenderer";
|
||||
this.cmbRenderer.Size = new System.Drawing.Size(252, 21);
|
||||
this.cmbRenderer.TabIndex = 0;
|
||||
this.cmbRenderer.SelectedIndexChanged += new System.EventHandler(this.cmbRenderer_SelectedIndexChanged);
|
||||
//
|
||||
// cmbResolution
|
||||
//
|
||||
this.cmbResolution.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cmbResolution.FormattingEnabled = true;
|
||||
this.cmbResolution.Location = new System.Drawing.Point(124, 50);
|
||||
this.cmbResolution.Name = "cmbResolution";
|
||||
this.cmbResolution.Size = new System.Drawing.Size(252, 21);
|
||||
this.cmbResolution.TabIndex = 1;
|
||||
//
|
||||
// cmbAntialiasing
|
||||
//
|
||||
this.cmbAntialiasing.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cmbAntialiasing.FormattingEnabled = true;
|
||||
this.cmbAntialiasing.Location = new System.Drawing.Point(124, 81);
|
||||
this.cmbAntialiasing.Name = "cmbAntialiasing";
|
||||
this.cmbAntialiasing.Size = new System.Drawing.Size(252, 21);
|
||||
this.cmbAntialiasing.TabIndex = 2;
|
||||
//
|
||||
// cmbAnisotropy
|
||||
//
|
||||
this.cmbAnisotropy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cmbAnisotropy.FormattingEnabled = true;
|
||||
this.cmbAnisotropy.Location = new System.Drawing.Point(124, 112);
|
||||
this.cmbAnisotropy.Name = "cmbAnisotropy";
|
||||
this.cmbAnisotropy.Size = new System.Drawing.Size(252, 21);
|
||||
this.cmbAnisotropy.TabIndex = 3;
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.label4);
|
||||
this.groupBox1.Controls.Add(this.label3);
|
||||
this.groupBox1.Controls.Add(this.label2);
|
||||
this.groupBox1.Controls.Add(this.label1);
|
||||
this.groupBox1.Controls.Add(this.cmbAnisotropy);
|
||||
this.groupBox1.Controls.Add(this.cmbRenderer);
|
||||
this.groupBox1.Controls.Add(this.cmbResolution);
|
||||
this.groupBox1.Controls.Add(this.cmbAntialiasing);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(382, 150);
|
||||
this.groupBox1.TabIndex = 4;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Graphics Settings";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(17, 115);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(101, 13);
|
||||
this.label4.TabIndex = 7;
|
||||
this.label4.Text = "Anisotropic Filtering:";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(52, 84);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(66, 13);
|
||||
this.label3.TabIndex = 6;
|
||||
this.label3.Text = "Anti-aliasing:";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(58, 53);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(60, 13);
|
||||
this.label2.TabIndex = 5;
|
||||
this.label2.Text = "Resolution:";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(64, 22);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(54, 13);
|
||||
this.label1.TabIndex = 4;
|
||||
this.label1.Text = "Renderer:";
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.cmbMode);
|
||||
this.groupBox2.Controls.Add(this.chkTripleBuffering);
|
||||
this.groupBox2.Controls.Add(this.chkVSync);
|
||||
this.groupBox2.Location = new System.Drawing.Point(12, 168);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(118, 93);
|
||||
this.groupBox2.TabIndex = 5;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Mode";
|
||||
//
|
||||
// chkTripleBuffering
|
||||
//
|
||||
this.chkTripleBuffering.AutoSize = true;
|
||||
this.chkTripleBuffering.Location = new System.Drawing.Point(12, 64);
|
||||
this.chkTripleBuffering.Name = "chkTripleBuffering";
|
||||
this.chkTripleBuffering.Size = new System.Drawing.Size(97, 17);
|
||||
this.chkTripleBuffering.TabIndex = 2;
|
||||
this.chkTripleBuffering.Text = "Triple Buffering";
|
||||
this.chkTripleBuffering.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// chkVSync
|
||||
//
|
||||
this.chkVSync.AutoSize = true;
|
||||
this.chkVSync.Location = new System.Drawing.Point(12, 43);
|
||||
this.chkVSync.Name = "chkVSync";
|
||||
this.chkVSync.Size = new System.Drawing.Size(88, 17);
|
||||
this.chkVSync.TabIndex = 1;
|
||||
this.chkVSync.Text = "Vertical Sync";
|
||||
this.chkVSync.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// btnOK
|
||||
//
|
||||
this.btnOK.Location = new System.Drawing.Point(238, 238);
|
||||
this.btnOK.Name = "btnOK";
|
||||
this.btnOK.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnOK.TabIndex = 6;
|
||||
this.btnOK.Text = "OK";
|
||||
this.btnOK.UseVisualStyleBackColor = true;
|
||||
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
|
||||
//
|
||||
// btnCancel
|
||||
//
|
||||
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.btnCancel.Location = new System.Drawing.Point(319, 238);
|
||||
this.btnCancel.Name = "btnCancel";
|
||||
this.btnCancel.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnCancel.TabIndex = 7;
|
||||
this.btnCancel.Text = "Cancel";
|
||||
this.btnCancel.UseVisualStyleBackColor = true;
|
||||
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
|
||||
//
|
||||
// btnResetDefaults
|
||||
//
|
||||
this.btnResetDefaults.Location = new System.Drawing.Point(300, 168);
|
||||
this.btnResetDefaults.Name = "btnResetDefaults";
|
||||
this.btnResetDefaults.Size = new System.Drawing.Size(94, 23);
|
||||
this.btnResetDefaults.TabIndex = 8;
|
||||
this.btnResetDefaults.Text = "Reset Defaults";
|
||||
this.btnResetDefaults.UseVisualStyleBackColor = true;
|
||||
this.btnResetDefaults.Click += new System.EventHandler(this.btnResetDefaults_Click);
|
||||
//
|
||||
// groupBox3
|
||||
//
|
||||
this.groupBox3.Controls.Add(this.chkUpdates);
|
||||
this.groupBox3.Location = new System.Drawing.Point(136, 168);
|
||||
this.groupBox3.Name = "groupBox3";
|
||||
this.groupBox3.Size = new System.Drawing.Size(127, 49);
|
||||
this.groupBox3.TabIndex = 6;
|
||||
this.groupBox3.TabStop = false;
|
||||
this.groupBox3.Text = "Other";
|
||||
//
|
||||
// chkUpdates
|
||||
//
|
||||
this.chkUpdates.AutoSize = true;
|
||||
this.chkUpdates.Location = new System.Drawing.Point(8, 22);
|
||||
this.chkUpdates.Name = "chkUpdates";
|
||||
this.chkUpdates.Size = new System.Drawing.Size(115, 17);
|
||||
this.chkUpdates.TabIndex = 1;
|
||||
this.chkUpdates.Text = "Check for Updates";
|
||||
this.chkUpdates.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// cmbMode
|
||||
//
|
||||
this.cmbMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cmbMode.FormattingEnabled = true;
|
||||
this.cmbMode.Items.AddRange(new object[] {
|
||||
"Fullscreen",
|
||||
"Windowed",
|
||||
"Borderless"});
|
||||
this.cmbMode.Location = new System.Drawing.Point(12, 19);
|
||||
this.cmbMode.Name = "cmbMode";
|
||||
this.cmbMode.Size = new System.Drawing.Size(88, 21);
|
||||
this.cmbMode.TabIndex = 3;
|
||||
//
|
||||
// OptionsForm
|
||||
//
|
||||
this.AcceptButton = this.btnOK;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.btnCancel;
|
||||
this.ClientSize = new System.Drawing.Size(406, 273);
|
||||
this.ControlBox = false;
|
||||
this.Controls.Add(this.groupBox3);
|
||||
this.Controls.Add(this.btnResetDefaults);
|
||||
this.Controls.Add(this.btnCancel);
|
||||
this.Controls.Add(this.btnOK);
|
||||
this.Controls.Add(this.groupBox2);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||
this.Name = "OptionsForm";
|
||||
this.ShowIcon = false;
|
||||
this.ShowInTaskbar = false;
|
||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "OptionsForm";
|
||||
this.TopMost = true;
|
||||
this.Load += new System.EventHandler(this.OptionsForm_Load);
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.groupBox2.PerformLayout();
|
||||
this.groupBox3.ResumeLayout(false);
|
||||
this.groupBox3.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.ComboBox cmbRenderer;
|
||||
private System.Windows.Forms.ComboBox cmbResolution;
|
||||
private System.Windows.Forms.ComboBox cmbAntialiasing;
|
||||
private System.Windows.Forms.ComboBox cmbAnisotropy;
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.CheckBox chkVSync;
|
||||
private System.Windows.Forms.Button btnOK;
|
||||
private System.Windows.Forms.Button btnCancel;
|
||||
private System.Windows.Forms.Button btnResetDefaults;
|
||||
private System.Windows.Forms.CheckBox chkTripleBuffering;
|
||||
private System.Windows.Forms.GroupBox groupBox3;
|
||||
private System.Windows.Forms.CheckBox chkUpdates;
|
||||
private System.Windows.Forms.ComboBox cmbMode;
|
||||
}
|
||||
}
|
244
Giants.Launcher/OptionsForm.cs
Normal file
@ -0,0 +1,244 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
public partial class OptionsForm : Form
|
||||
{
|
||||
string _gamePath = null;
|
||||
|
||||
public OptionsForm(string title, string gamePath)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Text = title;
|
||||
_gamePath = gamePath;
|
||||
}
|
||||
|
||||
private void OptionsForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
PopulateResolution();
|
||||
SetOptions();
|
||||
}
|
||||
|
||||
private void SetOptions()
|
||||
{
|
||||
cmbRenderer.Items.Clear();
|
||||
cmbRenderer.Items.AddRange(GameSettings.CompatibleRenderers.ToArray());
|
||||
|
||||
RendererInterop.Capabilities renderer = GameSettings.CompatibleRenderers.Find(r => StringComparer.OrdinalIgnoreCase.Compare(Path.GetFileName(r.FilePath), GameSettings.Get("Renderer")) == 0);
|
||||
if (renderer != null)
|
||||
cmbRenderer.SelectedItem = renderer;
|
||||
else
|
||||
{
|
||||
renderer = GameSettings.CompatibleRenderers.Find(r => r.Name == "DirectX 7");
|
||||
cmbRenderer.SelectedItem = renderer;
|
||||
}
|
||||
|
||||
var Resolutions = (List<ScreenResolution>)cmbResolution.DataSource;
|
||||
cmbResolution.SelectedItem = Resolutions.Find(r => r.Width == (int)GameSettings.Get("VideoWidth") && r.Height == (int)GameSettings.Get("VideoHeight"));
|
||||
if (cmbResolution.SelectedItem == null)
|
||||
cmbResolution.SelectedIndex = 0;
|
||||
|
||||
var AntialiasingOptions = (List<KeyValuePair<string, int>>)cmbAntialiasing.DataSource;
|
||||
cmbAntialiasing.SelectedItem = AntialiasingOptions.Find(o => o.Value == (int)GameSettings.Get("Antialiasing"));
|
||||
if (cmbAntialiasing.SelectedItem == null)
|
||||
cmbAntialiasing.SelectedIndex = 0;
|
||||
|
||||
var AnisotropyOptions = (List<KeyValuePair<string, int>>)cmbAnisotropy.DataSource;
|
||||
cmbAnisotropy.SelectedItem = AnisotropyOptions.Find(o => o.Value == (int)GameSettings.Get("AnisotropicFiltering"));
|
||||
if (cmbAnisotropy.SelectedItem == null)
|
||||
cmbAnisotropy.SelectedIndex = 0;
|
||||
|
||||
chkUpdates.Checked = ((int)GameSettings.Get("NoAutoUpdate") == 1 ? false : true);
|
||||
}
|
||||
|
||||
private void PopulateAntialiasing()
|
||||
{
|
||||
List<KeyValuePair<string, int>> AntialiasingOptions = new List<KeyValuePair<string, int>>();
|
||||
|
||||
AntialiasingOptions.Add(new KeyValuePair<string, int>("None (Best performance)", 0));
|
||||
|
||||
var renderer = (RendererInterop.Capabilities)cmbRenderer.SelectedItem;
|
||||
if (renderer != null)
|
||||
{
|
||||
if ((renderer.Flags & RendererInterop.Capabilities.RendererFlag.MSAA2x) == RendererInterop.Capabilities.RendererFlag.MSAA2x)
|
||||
AntialiasingOptions.Add(new KeyValuePair<string, int>("2 Samples", 2));
|
||||
if ((renderer.Flags & RendererInterop.Capabilities.RendererFlag.MSAA4x) == RendererInterop.Capabilities.RendererFlag.MSAA4x)
|
||||
AntialiasingOptions.Add(new KeyValuePair<string, int>("4 Samples", 4));
|
||||
if ((renderer.Flags & RendererInterop.Capabilities.RendererFlag.MSAA8x) == RendererInterop.Capabilities.RendererFlag.MSAA8x)
|
||||
AntialiasingOptions.Add(new KeyValuePair<string, int>("8 Samples", 8));
|
||||
if ((renderer.Flags & RendererInterop.Capabilities.RendererFlag.MSAA16x) == RendererInterop.Capabilities.RendererFlag.MSAA16x)
|
||||
AntialiasingOptions.Add(new KeyValuePair<string, int>("16 Samples", 16));
|
||||
}
|
||||
|
||||
// Try to keep current selection when repopulating
|
||||
int? currentValue = null;
|
||||
if (cmbAntialiasing.SelectedValue != null)
|
||||
{
|
||||
currentValue = (int)cmbAntialiasing.SelectedValue;
|
||||
}
|
||||
|
||||
cmbAntialiasing.DataSource = AntialiasingOptions;
|
||||
cmbAntialiasing.DisplayMember = "Key";
|
||||
cmbAntialiasing.ValueMember = "Value";
|
||||
|
||||
if (currentValue != null)
|
||||
cmbAntialiasing.SelectedValue = currentValue;
|
||||
|
||||
if (cmbAntialiasing.SelectedValue == null)
|
||||
cmbAntialiasing.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
private bool IsPowerOfTwo(int x)
|
||||
{
|
||||
return (x != 0) && ((x & (x - 1)) == 0);
|
||||
}
|
||||
|
||||
private void PopulateAnisotropy()
|
||||
{
|
||||
List<KeyValuePair<string, int>> AnisotropyOptions = new List<KeyValuePair<string, int>>();
|
||||
|
||||
AnisotropyOptions.Add(new KeyValuePair<string, int>("None (Best performance)", 0));
|
||||
|
||||
var renderer = (RendererInterop.Capabilities)cmbRenderer.SelectedItem;
|
||||
if (renderer != null)
|
||||
{
|
||||
for (int i = 2; i <= renderer.MaxAnisotropy; i++)
|
||||
{
|
||||
if (!IsPowerOfTwo(i)) continue;
|
||||
|
||||
AnisotropyOptions.Add(new KeyValuePair<string,int>(String.Format("{0} Samples", i), i));
|
||||
}
|
||||
}
|
||||
|
||||
// Try to keep current selection when repopulating
|
||||
int? currentValue = null;
|
||||
if (cmbAnisotropy.SelectedValue != null)
|
||||
{
|
||||
currentValue = (int)cmbAnisotropy.SelectedValue;
|
||||
}
|
||||
|
||||
cmbAnisotropy.DataSource = AnisotropyOptions;
|
||||
cmbAnisotropy.DisplayMember = "Key";
|
||||
cmbAnisotropy.ValueMember = "Value";
|
||||
|
||||
if (currentValue != null)
|
||||
cmbAnisotropy.SelectedValue = currentValue;
|
||||
|
||||
if (cmbAnisotropy.SelectedValue == null)
|
||||
cmbAnisotropy.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
private void PopulateResolution()
|
||||
{
|
||||
List<ScreenResolution> resolutions = new List<ScreenResolution>();
|
||||
|
||||
NativeMethods.DEVMODE devMode = new NativeMethods.DEVMODE();
|
||||
int i = 0;
|
||||
while (NativeMethods.EnumDisplaySettings(null, i, ref devMode))
|
||||
{
|
||||
if (devMode.dmBitsPerPel == 32 && devMode.dmPelsWidth >= 640 && devMode.dmPelsHeight >= 480)
|
||||
{
|
||||
if (resolutions.Find(r => r.Width == devMode.dmPelsWidth && r.Height == devMode.dmPelsHeight) == null)
|
||||
resolutions.Add(new ScreenResolution(devMode.dmPelsWidth, devMode.dmPelsHeight));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
resolutions.Sort();
|
||||
cmbResolution.DataSource = resolutions;
|
||||
}
|
||||
|
||||
private void cmbRenderer_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
PopulateAntialiasing();
|
||||
PopulateAnisotropy();
|
||||
|
||||
bool windowed = ((int)GameSettings.Get("Windowed") == 1 ? true : false);
|
||||
if (windowed)
|
||||
{
|
||||
bool borderless = (int)GameSettings.Get("BorderlessWindow") == 1 ? true : false;
|
||||
if (borderless)
|
||||
cmbMode.SelectedIndex = 2;
|
||||
else
|
||||
cmbMode.SelectedIndex = 1;
|
||||
}
|
||||
else
|
||||
cmbMode.SelectedIndex = 0;
|
||||
|
||||
var renderer = (RendererInterop.Capabilities)cmbRenderer.SelectedItem;
|
||||
|
||||
if ((renderer.Flags & RendererInterop.Capabilities.RendererFlag.VSync) != RendererInterop.Capabilities.RendererFlag.VSync)
|
||||
{
|
||||
chkVSync.Checked = false;
|
||||
chkVSync.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
chkVSync.Checked = ((int)GameSettings.Get("VerticalSync") == 1 ? true : false);
|
||||
chkVSync.Enabled = true;
|
||||
}
|
||||
|
||||
if ((renderer.Flags & RendererInterop.Capabilities.RendererFlag.TripleBuffer) != RendererInterop.Capabilities.RendererFlag.TripleBuffer)
|
||||
{
|
||||
chkTripleBuffering.Checked = false;
|
||||
chkTripleBuffering.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
chkTripleBuffering.Checked = ((int)GameSettings.Get("TripleBuffering") == 1 ? true : false);
|
||||
chkTripleBuffering.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void btnOK_Click(object sender, EventArgs e)
|
||||
{
|
||||
var renderer = cmbRenderer.SelectedItem as RendererInterop.Capabilities;
|
||||
if (renderer != null)
|
||||
{
|
||||
GameSettings.Modify("Renderer", renderer.FileName);
|
||||
}
|
||||
|
||||
var resolution = (ScreenResolution)cmbResolution.SelectedItem;
|
||||
if (resolution != null)
|
||||
{
|
||||
GameSettings.Modify("VideoWidth", resolution.Width);
|
||||
GameSettings.Modify("VideoHeight", resolution.Height);
|
||||
}
|
||||
|
||||
GameSettings.Modify("Antialiasing", cmbAntialiasing.SelectedValue);
|
||||
GameSettings.Modify("AnisotropicFiltering", cmbAnisotropy.SelectedValue);
|
||||
bool windowed = ((WindowType)cmbMode.SelectedIndex == WindowType.Windowed || (WindowType)cmbMode.SelectedIndex == WindowType.Borderless);
|
||||
GameSettings.Modify("Windowed", (windowed == true ? 1 : 0));
|
||||
bool borderless = (WindowType)cmbMode.SelectedIndex == WindowType.Borderless;
|
||||
GameSettings.Modify("BorderlessWindow", borderless == true ? 1 : 0);
|
||||
GameSettings.Modify("VerticalSync", (chkVSync.Checked == true ? 1 : 0));
|
||||
GameSettings.Modify("TripleBuffering", (chkTripleBuffering.Checked == true ? 1 : 0));
|
||||
GameSettings.Modify("NoAutoUpdate", (chkUpdates.Checked == false ? 1 : 0));
|
||||
|
||||
GameSettings.Save();
|
||||
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void btnCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
GameSettings.Load(_gamePath);
|
||||
}
|
||||
|
||||
private void btnResetDefaults_Click(object sender, EventArgs e)
|
||||
{
|
||||
GameSettings.SetDefaults(_gamePath);
|
||||
SetOptions();
|
||||
}
|
||||
}
|
||||
}
|
123
Giants.Launcher/OptionsForm.resx
Normal file
@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
44
Giants.Launcher/Program.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
using (Mutex mutex = new Mutex(true, "GiantsLauncherMutex"))
|
||||
{
|
||||
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;
|
||||
Process[] processes = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(appName));
|
||||
|
||||
Process otherProcess = processes.FirstOrDefault(p => p.Id != Process.GetCurrentProcess().Id);
|
||||
if (otherProcess != null)
|
||||
{
|
||||
NativeMethods.SetForegroundWindow(otherProcess.MainWindowHandle);
|
||||
}
|
||||
|
||||
Application.Exit();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new LauncherForm());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
Giants.Launcher/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Launcher")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Launcher")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2012")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("6880ab7a-c446-4f4f-ac56-6e7a9bcecf23")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.3.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.3.0")]
|
253
Giants.Launcher/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,253 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Giants.Launcher {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Giants.Launcher.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Could not locate an installation of {0}. The launcher will now exit..
|
||||
/// </summary>
|
||||
internal static string AppNotFound {
|
||||
get {
|
||||
return ResourceManager.GetString("AppNotFound", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap backdrop {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("backdrop", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Downloading - {0}% of {1} MB.
|
||||
/// </summary>
|
||||
internal static string DownloadProgress {
|
||||
get {
|
||||
return ResourceManager.GetString("DownloadProgress", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap exit {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("exit", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap exithover {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("exithover", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap exitpush {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("exitpush", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Download complete. The launcher will now close to apply the update..
|
||||
/// </summary>
|
||||
internal static string LauncherClosingText {
|
||||
get {
|
||||
return ResourceManager.GetString("LauncherClosingText", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Download Complete.
|
||||
/// </summary>
|
||||
internal static string LauncherClosingTitle {
|
||||
get {
|
||||
return ResourceManager.GetString("LauncherClosingTitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.IO.UnmanagedMemoryStream similar to System.IO.MemoryStream.
|
||||
/// </summary>
|
||||
internal static System.IO.UnmanagedMemoryStream LauncherStart {
|
||||
get {
|
||||
return ResourceManager.GetStream("LauncherStart", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to An update for the launcher is available: version {0}. Download it?.
|
||||
/// </summary>
|
||||
internal static string LauncherUpdateAvailableText {
|
||||
get {
|
||||
return ResourceManager.GetString("LauncherUpdateAvailableText", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap options {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("options", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap optionshover {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("optionshover", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap optionspush {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("optionspush", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap play {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("play", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap playhover {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("playhover", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap playpush {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("playpush", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to An update is available: version {0}. Download it?.
|
||||
/// </summary>
|
||||
internal static string UpdateAvailableText {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateAvailableText", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Update Available.
|
||||
/// </summary>
|
||||
internal static string UpdateAvailableTitle {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateAvailableTitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Failed to download update. Please visit www.giantswd.org and download the update manually. The error was: {0}.
|
||||
/// </summary>
|
||||
internal static string UpdateDownloadFailedText {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateDownloadFailedText", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Update Failed.
|
||||
/// </summary>
|
||||
internal static string UpdateDownloadFailedTitle {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateDownloadFailedTitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
181
Giants.Launcher/Properties/Resources.resx
Normal file
@ -0,0 +1,181 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="backdrop" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\backdrop.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="exit" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\exit.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="exithover" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\exithover.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="exitpush" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\exitpush.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="LauncherStart" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\LauncherStart.wav;System.IO.MemoryStream, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="options" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\options.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="optionshover" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\optionshover.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="optionspush" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\optionspush.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="play" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\play.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="playhover" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\playhover.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="playpush" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\playpush.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="AppNotFound" xml:space="preserve">
|
||||
<value>Could not locate an installation of {0}. The launcher will now exit.</value>
|
||||
</data>
|
||||
<data name="UpdateAvailableText" xml:space="preserve">
|
||||
<value>An update is available: version {0}. Download it?</value>
|
||||
</data>
|
||||
<data name="UpdateAvailableTitle" xml:space="preserve">
|
||||
<value>Update Available</value>
|
||||
</data>
|
||||
<data name="UpdateDownloadFailedText" xml:space="preserve">
|
||||
<value>Failed to download update. Please visit www.giantswd.org and download the update manually. The error was: {0}</value>
|
||||
</data>
|
||||
<data name="UpdateDownloadFailedTitle" xml:space="preserve">
|
||||
<value>Update Failed</value>
|
||||
</data>
|
||||
<data name="LauncherClosingText" xml:space="preserve">
|
||||
<value>Download complete. The launcher will now close to apply the update.</value>
|
||||
</data>
|
||||
<data name="LauncherClosingTitle" xml:space="preserve">
|
||||
<value>Download Complete</value>
|
||||
</data>
|
||||
<data name="LauncherUpdateAvailableText" xml:space="preserve">
|
||||
<value>An update for the launcher is available: version {0}. Download it?</value>
|
||||
</data>
|
||||
<data name="DownloadProgress" xml:space="preserve">
|
||||
<value>Downloading - {0}% of {1} MB</value>
|
||||
</data>
|
||||
</root>
|
BIN
Giants.Launcher/Resources/LauncherStart.wav
Normal file
BIN
Giants.Launcher/Resources/backdrop.png
Normal file
After Width: | Height: | Size: 595 KiB |
BIN
Giants.Launcher/Resources/exit.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
Giants.Launcher/Resources/exithover.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
Giants.Launcher/Resources/exitpush.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
Giants.Launcher/Resources/giants.ico
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
Giants.Launcher/Resources/options.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
Giants.Launcher/Resources/optionshover.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
Giants.Launcher/Resources/optionspush.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
Giants.Launcher/Resources/play.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
Giants.Launcher/Resources/playhover.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
Giants.Launcher/Resources/playpush.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
205
Giants.Launcher/Updater.cs
Normal file
@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Giants.Launcher
|
||||
{
|
||||
public enum UpdateType
|
||||
{
|
||||
Launcher,
|
||||
Game,
|
||||
}
|
||||
|
||||
public class UpdateInfo
|
||||
{
|
||||
public Version VersionFrom { get; set; }
|
||||
public Version VersionTo { get; set; }
|
||||
public Uri DownloadUri
|
||||
{
|
||||
get
|
||||
{
|
||||
return _downloadUri;
|
||||
}
|
||||
set
|
||||
{
|
||||
_downloadUri = value;
|
||||
FileName = Path.GetFileName(value.AbsoluteUri);
|
||||
}
|
||||
}
|
||||
public int FileSize { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public UpdateType UpdateType { get; set; }
|
||||
|
||||
private Uri _downloadUri;
|
||||
}
|
||||
|
||||
public class Updater
|
||||
{
|
||||
Uri _updateUri;
|
||||
Version _appVersion;
|
||||
AsyncCompletedEventHandler _updateCompletedCallback;
|
||||
DownloadProgressChangedEventHandler _updateProgressCallback;
|
||||
|
||||
public Updater(Uri updateUri, Version appVersion)
|
||||
{
|
||||
_updateUri = updateUri;
|
||||
_appVersion = appVersion;
|
||||
}
|
||||
public void DownloadUpdateInfo(AsyncCompletedEventHandler downloadCompleteCallback, DownloadProgressChangedEventHandler downloadProgressCallback)
|
||||
{
|
||||
WebClient client = new WebClient();
|
||||
|
||||
// Keep track of our progress callbacks
|
||||
_updateCompletedCallback = downloadCompleteCallback;
|
||||
_updateProgressCallback = downloadProgressCallback;
|
||||
|
||||
// Download update info XML
|
||||
client.Proxy = null;
|
||||
client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(DownloadDataCallback);
|
||||
client.DownloadDataAsync(_updateUri);
|
||||
}
|
||||
|
||||
private int GetHttpFileSize(Uri uri)
|
||||
{
|
||||
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);
|
||||
req.Proxy = null;
|
||||
req.Method = "HEAD";
|
||||
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
|
||||
|
||||
if (resp.StatusCode == HttpStatusCode.OK && int.TryParse(resp.Headers.Get("Content-Length"), out int contentLength))
|
||||
{
|
||||
resp.Close();
|
||||
return contentLength;
|
||||
}
|
||||
|
||||
resp.Close();
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
private void StartGameUpdate(XElement root, Version currentVersion)
|
||||
{
|
||||
var updates = from update in root.Elements("Update")
|
||||
select new UpdateInfo()
|
||||
{
|
||||
VersionFrom = new Version(update.Attribute("FromVersion").Value),
|
||||
VersionTo = new Version(update.Attribute("ToVersion").Value),
|
||||
DownloadUri = new Uri(update.Attribute("Url").Value),
|
||||
UpdateType = UpdateType.Game
|
||||
};
|
||||
|
||||
// Grab the download path for the update to our current version, otherwise fall back to the full installer
|
||||
// (specially defined as FromVersion 0.0.0.0 in the XML)
|
||||
UpdateInfo info = updates.FirstOrDefault(update => update.VersionFrom == currentVersion);
|
||||
if (info == null)
|
||||
info = updates.Single(update => update.VersionFrom == new Version("0.0.0.0"));
|
||||
|
||||
// Display update prompt
|
||||
string updateMsg = string.Format(Resources.UpdateAvailableText, info.VersionTo.ToString());
|
||||
if (MessageBox.Show(updateMsg, Resources.UpdateAvailableTitle, MessageBoxButtons.YesNo) == DialogResult.No)
|
||||
return; // User declined update
|
||||
|
||||
string path = Path.Combine(Path.GetTempPath(), info.FileName);
|
||||
|
||||
// Delete the file locally if it already exists, just to be safe
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
|
||||
info.FileSize = GetHttpFileSize(info.DownloadUri);
|
||||
if (info.FileSize == -1)
|
||||
{
|
||||
string errorMsg = string.Format(Resources.UpdateDownloadFailedText, "File not found on server.");
|
||||
MessageBox.Show(errorMsg, Resources.UpdateDownloadFailedTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Download the update
|
||||
WebClient client = new WebClient()
|
||||
{
|
||||
Proxy = null
|
||||
};
|
||||
client.DownloadFileAsync(info.DownloadUri, path, info);
|
||||
client.DownloadFileCompleted += _updateCompletedCallback;
|
||||
client.DownloadProgressChanged += _updateProgressCallback;
|
||||
}
|
||||
|
||||
private void StartLauncherUpdate(XElement root)
|
||||
{
|
||||
var query = from update in root.Descendants("LauncherUpdate")
|
||||
select new UpdateInfo()
|
||||
{
|
||||
VersionTo = new Version(update.Attribute("ToVersion").Value),
|
||||
DownloadUri = new Uri(update.Attribute("Url").Value),
|
||||
UpdateType = UpdateType.Launcher
|
||||
};
|
||||
|
||||
UpdateInfo info = query.FirstOrDefault();
|
||||
|
||||
// Display update prompt
|
||||
string updateMsg = string.Format(Resources.LauncherUpdateAvailableText, info.VersionTo.ToString());
|
||||
if (MessageBox.Show(updateMsg, Resources.UpdateAvailableTitle, MessageBoxButtons.YesNo) == DialogResult.No)
|
||||
return; // User declined update
|
||||
|
||||
string path = Path.Combine(Path.GetTempPath(), info.FileName);
|
||||
|
||||
// Delete the file locally if it already exists, just to be safe
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
|
||||
info.FileSize = GetHttpFileSize(info.DownloadUri);
|
||||
if (info.FileSize == -1)
|
||||
{
|
||||
string errorMsg = string.Format(Resources.UpdateDownloadFailedText, "File not found on server.");
|
||||
MessageBox.Show(errorMsg, Resources.UpdateDownloadFailedTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Download the update
|
||||
WebClient client = new WebClient()
|
||||
{
|
||||
Proxy = null
|
||||
};
|
||||
client.DownloadFileAsync(info.DownloadUri, path, info);
|
||||
client.DownloadFileCompleted += _updateCompletedCallback;
|
||||
client.DownloadProgressChanged += _updateProgressCallback;
|
||||
}
|
||||
|
||||
private void DownloadDataCallback(Object sender, DownloadDataCompletedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!e.Cancelled && e.Error == null)
|
||||
{
|
||||
byte[] data = (byte[])e.Result;
|
||||
string textData = System.Text.Encoding.UTF8.GetString(data);
|
||||
|
||||
XElement root = XElement.Parse(textData);
|
||||
|
||||
Version launcherVersion = new Version(root.Attribute("CurrentLauncherVersion").Value);
|
||||
Version gameVersion = new Version(root.Attribute("CurrentGameVersion").Value);
|
||||
|
||||
Version ourVersion = new Version(Application.ProductVersion);
|
||||
if (launcherVersion > ourVersion)
|
||||
{
|
||||
StartLauncherUpdate(root);
|
||||
return;
|
||||
}
|
||||
else if (gameVersion > _appVersion)
|
||||
StartGameUpdate(root, _appVersion);
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if DEBUG
|
||||
MessageBox.Show(string.Format("Exception in DownloadDataCallback: {0}", ex.Message));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Giants.Launcher/app.config
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
|
BIN
Giants.Launcher/giants.ico
Normal file
After Width: | Height: | Size: 2.2 KiB |
@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Giants.DataContract", "Gian
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Giants.WebApi", "Giants.WebApi\Giants.WebApi.csproj", "{9A284C34-8F4B-4E20-B74B-1A0AF04EDBD1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Giants.Launcher", "Giants.Launcher\Giants.Launcher.csproj", "{612FD606-F072-4A04-9054-65BC592E9D3E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -27,6 +29,10 @@ Global
|
||||
{9A284C34-8F4B-4E20-B74B-1A0AF04EDBD1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9A284C34-8F4B-4E20-B74B-1A0AF04EDBD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9A284C34-8F4B-4E20-B74B-1A0AF04EDBD1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{612FD606-F072-4A04-9054-65BC592E9D3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{612FD606-F072-4A04-9054-65BC592E9D3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{612FD606-F072-4A04-9054-65BC592E9D3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{612FD606-F072-4A04-9054-65BC592E9D3E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|