Non-WinForms launcher with auto updater
This commit is contained in:
Generated
+89
-6
@@ -37,6 +37,12 @@
|
||||
this.contentPackageBox = new System.Windows.Forms.ComboBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.packageManagerButton = new System.Windows.Forms.Button();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.autoUpdateCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.progressBar = new System.Windows.Forms.ProgressBar();
|
||||
this.patchNoteBox = new System.Windows.Forms.TextBox();
|
||||
this.updateLabel = new System.Windows.Forms.Label();
|
||||
this.downloadButton = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@@ -70,7 +76,7 @@
|
||||
//
|
||||
this.resolutionBox.AllowDrop = true;
|
||||
this.resolutionBox.FormattingEnabled = true;
|
||||
this.resolutionBox.Location = new System.Drawing.Point(57, 207);
|
||||
this.resolutionBox.Location = new System.Drawing.Point(369, 236);
|
||||
this.resolutionBox.Name = "resolutionBox";
|
||||
this.resolutionBox.Size = new System.Drawing.Size(212, 21);
|
||||
this.resolutionBox.TabIndex = 2;
|
||||
@@ -80,7 +86,7 @@
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.BackColor = System.Drawing.Color.Transparent;
|
||||
this.label1.ForeColor = System.Drawing.SystemColors.Window;
|
||||
this.label1.Location = new System.Drawing.Point(54, 191);
|
||||
this.label1.Location = new System.Drawing.Point(366, 220);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(60, 13);
|
||||
this.label1.TabIndex = 3;
|
||||
@@ -91,7 +97,7 @@
|
||||
this.fullscreenBox.AutoSize = true;
|
||||
this.fullscreenBox.BackColor = System.Drawing.Color.Transparent;
|
||||
this.fullscreenBox.ForeColor = System.Drawing.SystemColors.Window;
|
||||
this.fullscreenBox.Location = new System.Drawing.Point(57, 252);
|
||||
this.fullscreenBox.Location = new System.Drawing.Point(369, 281);
|
||||
this.fullscreenBox.Name = "fullscreenBox";
|
||||
this.fullscreenBox.Size = new System.Drawing.Size(74, 17);
|
||||
this.fullscreenBox.TabIndex = 4;
|
||||
@@ -101,7 +107,7 @@
|
||||
// contentPackageBox
|
||||
//
|
||||
this.contentPackageBox.FormattingEnabled = true;
|
||||
this.contentPackageBox.Location = new System.Drawing.Point(368, 207);
|
||||
this.contentPackageBox.Location = new System.Drawing.Point(369, 138);
|
||||
this.contentPackageBox.Name = "contentPackageBox";
|
||||
this.contentPackageBox.Size = new System.Drawing.Size(212, 21);
|
||||
this.contentPackageBox.TabIndex = 5;
|
||||
@@ -112,7 +118,7 @@
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.BackColor = System.Drawing.Color.Transparent;
|
||||
this.label2.ForeColor = System.Drawing.SystemColors.Window;
|
||||
this.label2.Location = new System.Drawing.Point(365, 191);
|
||||
this.label2.Location = new System.Drawing.Point(366, 122);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(92, 13);
|
||||
this.label2.TabIndex = 6;
|
||||
@@ -123,7 +129,7 @@
|
||||
this.packageManagerButton.BackColor = System.Drawing.Color.OrangeRed;
|
||||
this.packageManagerButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.packageManagerButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.packageManagerButton.Location = new System.Drawing.Point(368, 234);
|
||||
this.packageManagerButton.Location = new System.Drawing.Point(369, 165);
|
||||
this.packageManagerButton.Name = "packageManagerButton";
|
||||
this.packageManagerButton.Size = new System.Drawing.Size(120, 35);
|
||||
this.packageManagerButton.TabIndex = 7;
|
||||
@@ -131,6 +137,71 @@
|
||||
this.packageManagerButton.UseVisualStyleBackColor = false;
|
||||
this.packageManagerButton.Click += new System.EventHandler(this.packageManagerButton_Click);
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.BackColor = System.Drawing.Color.Transparent;
|
||||
this.label3.ForeColor = System.Drawing.SystemColors.ControlLightLight;
|
||||
this.label3.Location = new System.Drawing.Point(266, 78);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(86, 13);
|
||||
this.label3.TabIndex = 8;
|
||||
this.label3.Text = "Installed version:";
|
||||
//
|
||||
// autoUpdateCheckBox
|
||||
//
|
||||
this.autoUpdateCheckBox.AutoSize = true;
|
||||
this.autoUpdateCheckBox.BackColor = System.Drawing.Color.Transparent;
|
||||
this.autoUpdateCheckBox.ForeColor = System.Drawing.SystemColors.Window;
|
||||
this.autoUpdateCheckBox.Location = new System.Drawing.Point(47, 122);
|
||||
this.autoUpdateCheckBox.Name = "autoUpdateCheckBox";
|
||||
this.autoUpdateCheckBox.Size = new System.Drawing.Size(177, 17);
|
||||
this.autoUpdateCheckBox.TabIndex = 9;
|
||||
this.autoUpdateCheckBox.Text = "Automatically check for updates";
|
||||
this.autoUpdateCheckBox.UseVisualStyleBackColor = false;
|
||||
//
|
||||
// progressBar
|
||||
//
|
||||
this.progressBar.Location = new System.Drawing.Point(129, 407);
|
||||
this.progressBar.Name = "progressBar";
|
||||
this.progressBar.Size = new System.Drawing.Size(207, 30);
|
||||
this.progressBar.TabIndex = 10;
|
||||
//
|
||||
// patchNoteBox
|
||||
//
|
||||
this.patchNoteBox.AcceptsReturn = true;
|
||||
this.patchNoteBox.Location = new System.Drawing.Point(47, 145);
|
||||
this.patchNoteBox.Multiline = true;
|
||||
this.patchNoteBox.Name = "patchNoteBox";
|
||||
this.patchNoteBox.ReadOnly = true;
|
||||
this.patchNoteBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.patchNoteBox.Size = new System.Drawing.Size(289, 226);
|
||||
this.patchNoteBox.TabIndex = 11;
|
||||
//
|
||||
// updateLabel
|
||||
//
|
||||
this.updateLabel.AutoSize = true;
|
||||
this.updateLabel.BackColor = System.Drawing.Color.Transparent;
|
||||
this.updateLabel.ForeColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||
this.updateLabel.Location = new System.Drawing.Point(44, 383);
|
||||
this.updateLabel.Name = "updateLabel";
|
||||
this.updateLabel.Size = new System.Drawing.Size(98, 13);
|
||||
this.updateLabel.TabIndex = 12;
|
||||
this.updateLabel.Text = "New update found!";
|
||||
//
|
||||
// downloadButton
|
||||
//
|
||||
this.downloadButton.BackColor = System.Drawing.Color.OrangeRed;
|
||||
this.downloadButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.downloadButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.downloadButton.Location = new System.Drawing.Point(47, 407);
|
||||
this.downloadButton.Name = "downloadButton";
|
||||
this.downloadButton.Size = new System.Drawing.Size(76, 30);
|
||||
this.downloadButton.TabIndex = 13;
|
||||
this.downloadButton.Text = "Download";
|
||||
this.downloadButton.UseVisualStyleBackColor = false;
|
||||
this.downloadButton.Click += new System.EventHandler(this.downloadButton_Click);
|
||||
//
|
||||
// LauncherMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@@ -139,6 +210,12 @@
|
||||
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
|
||||
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.ClientSize = new System.Drawing.Size(628, 453);
|
||||
this.Controls.Add(this.downloadButton);
|
||||
this.Controls.Add(this.updateLabel);
|
||||
this.Controls.Add(this.patchNoteBox);
|
||||
this.Controls.Add(this.progressBar);
|
||||
this.Controls.Add(this.autoUpdateCheckBox);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.packageManagerButton);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.contentPackageBox);
|
||||
@@ -166,6 +243,12 @@
|
||||
private System.Windows.Forms.ComboBox contentPackageBox;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Button packageManagerButton;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.CheckBox autoUpdateCheckBox;
|
||||
private System.Windows.Forms.ProgressBar progressBar;
|
||||
private System.Windows.Forms.TextBox patchNoteBox;
|
||||
private System.Windows.Forms.Label updateLabel;
|
||||
private System.Windows.Forms.Button downloadButton;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+192
-2
@@ -1,4 +1,5 @@
|
||||
using Subsurface;
|
||||
using RestSharp;
|
||||
using Subsurface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -7,6 +8,8 @@ using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -17,9 +20,13 @@ namespace Launcher
|
||||
{
|
||||
public partial class LauncherMain : Form
|
||||
{
|
||||
string version = AssemblyName.GetAssemblyName("subsurface.exe").Version.ToString();
|
||||
|
||||
private const string configPath = "config.xml";
|
||||
private Subsurface.GameSettings settings;
|
||||
|
||||
private string latestVersionFileList, latestVersionFolder;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool EnumDisplaySettings(
|
||||
string deviceName, int modeNum, ref DEVMODE devMode);
|
||||
@@ -35,6 +42,12 @@ namespace Launcher
|
||||
set { settings.FullScreenEnabled = value; }
|
||||
}
|
||||
|
||||
public bool AutoCheckUpdates
|
||||
{
|
||||
get { return settings.AutoCheckUpdates; }
|
||||
set { settings.AutoCheckUpdates = value; }
|
||||
}
|
||||
|
||||
//private GraphicsMode selectedMode;
|
||||
|
||||
public LauncherMain()
|
||||
@@ -80,6 +93,9 @@ namespace Launcher
|
||||
|
||||
fullscreenBox.DataBindings.Add("Checked", this, "FullscreenEnabled");
|
||||
|
||||
autoUpdateCheckBox.DataBindings.Add("Checked", this, "AutoCheckUpdates");
|
||||
|
||||
|
||||
if (settings.SelectedContentPackage == null)
|
||||
{
|
||||
if (contentPackageBox.Items.Count > 0) contentPackageBox.SelectedItem = contentPackageBox.Items[0];
|
||||
@@ -89,6 +105,15 @@ namespace Launcher
|
||||
contentPackageBox.SelectedItem = settings.SelectedContentPackage;
|
||||
}
|
||||
|
||||
progressBar.Visible = false;
|
||||
updateLabel.Visible = false;
|
||||
downloadButton.Visible = false;
|
||||
|
||||
if (settings.AutoCheckUpdates)
|
||||
{
|
||||
CheckForUpdates();
|
||||
}
|
||||
|
||||
//resolutionBox.SelectedItem = selectedMode;
|
||||
}
|
||||
|
||||
@@ -122,6 +147,172 @@ namespace Launcher
|
||||
|
||||
settings.SelectedContentPackage = comboBox.SelectedItem as ContentPackage;
|
||||
}
|
||||
|
||||
private bool CheckForUpdates()
|
||||
{
|
||||
patchNoteBox.Text = "Checking for updates...";
|
||||
|
||||
XDocument doc = null;
|
||||
|
||||
try
|
||||
{
|
||||
doc = FetchXML("versioninfo.xml");
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
patchNoteBox.Text = "Error while checking for updates: " + e.Message;
|
||||
return false;
|
||||
}
|
||||
|
||||
CheckUpdateXML(doc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private XDocument FetchXML(string fileName)
|
||||
{
|
||||
var client = new RestClient(settings.MasterServerUrl);
|
||||
|
||||
var request = new RestRequest(fileName, Method.GET);
|
||||
|
||||
IRestResponse response = client.Execute(request);
|
||||
|
||||
if (response.ResponseStatus!= ResponseStatus.Completed) return null;
|
||||
if (response.StatusCode != HttpStatusCode.OK) return null;
|
||||
|
||||
string xml = response.Content;
|
||||
|
||||
string _byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
|
||||
if (xml.StartsWith(_byteOrderMarkUtf8))
|
||||
{
|
||||
xml = xml.Remove(0, _byteOrderMarkUtf8.Length);
|
||||
}
|
||||
|
||||
return XDocument.Parse(xml);
|
||||
}
|
||||
|
||||
private bool CheckUpdateXML(XDocument doc)
|
||||
{
|
||||
if (doc.Root==null)
|
||||
{
|
||||
patchNoteBox.Text = "Error while checking for updates: could not parse update info";
|
||||
return false;
|
||||
}
|
||||
|
||||
progressBar.Visible = true;
|
||||
downloadButton.Visible = true;
|
||||
updateLabel.Visible = true;
|
||||
|
||||
string latestVersion = ToolBox.GetAttributeString(doc.Root, "latestversion", "");
|
||||
latestVersionFolder = ToolBox.GetAttributeString(doc.Root, "latestversionfolder", "");
|
||||
latestVersionFileList = ToolBox.GetAttributeString(doc.Root, "latestversionfilelist", "");
|
||||
|
||||
if (latestVersion == version)
|
||||
{
|
||||
patchNoteBox.Text = "Game is up to date!";
|
||||
return false;
|
||||
}
|
||||
|
||||
updateLabel.Text = "New update found! (" + latestVersion + ")";
|
||||
|
||||
XElement patchNotes = doc.Root.Element("patchnotes");
|
||||
|
||||
if (patchNotes!=null)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
foreach (XElement patchNote in patchNotes.Elements())
|
||||
{
|
||||
string patchNumber = ToolBox.GetAttributeString(patchNote, "version", "");
|
||||
|
||||
//read the patch notes until we reach the user's version
|
||||
if (patchNumber == version) break;
|
||||
|
||||
sb.AppendLine(ToolBox.ElementInnerText(patchNote));
|
||||
sb.AppendLine("*************************************\n");
|
||||
}
|
||||
|
||||
patchNoteBox.Text = sb.ToString();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void downloadButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(latestVersionFolder)) return;
|
||||
|
||||
Button senderButton = sender as Button;
|
||||
senderButton.Enabled = false;
|
||||
|
||||
XDocument doc = null;
|
||||
|
||||
try
|
||||
{
|
||||
doc = FetchXML("filelist.xml");
|
||||
}
|
||||
|
||||
catch (Exception exception)
|
||||
{
|
||||
patchNoteBox.Text = "Error while checking for updates: " + exception.Message;
|
||||
return;
|
||||
}
|
||||
|
||||
filesToDownload = UpdaterUtil.GetRequiredFiles(doc);
|
||||
|
||||
string dir = Directory.GetCurrentDirectory();
|
||||
|
||||
filesToDownloadCount = filesToDownload.Count;
|
||||
if (filesToDownloadCount>0)
|
||||
{
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
|
||||
//webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
|
||||
|
||||
webClient.DownloadFileAsync(new Uri(latestVersionFolder + filesToDownload[0]), dir);
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> filesToDownload;
|
||||
|
||||
private int filesDownloaded, filesToDownloadCount;
|
||||
|
||||
private void Completed(object sender, AsyncCompletedEventArgs e)
|
||||
{
|
||||
filesDownloaded++;
|
||||
progressBar.Value = (int)(((float)filesDownloaded / (float)filesToDownloadCount) * 100.0f);//e.ProgressPercentage;
|
||||
|
||||
filesToDownload.RemoveAt(0);
|
||||
|
||||
if (filesToDownload.Count==0)
|
||||
{
|
||||
progressBar.Visible = false;
|
||||
downloadButton.Visible = false;
|
||||
updateLabel.Visible = false;
|
||||
|
||||
MessageBox.Show("Download completed!");
|
||||
return;
|
||||
}
|
||||
|
||||
updateLabel.Text = "Downloading file "+ filesDownloaded + "/" + filesToDownloadCount + " ("+ filesToDownload[0] + ")";
|
||||
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
|
||||
//webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
|
||||
|
||||
string dir = Directory.GetCurrentDirectory();
|
||||
|
||||
string fileDir = Path.GetDirectoryName(filesToDownload[0]);
|
||||
if (!string.IsNullOrWhiteSpace(fileDir) && !Directory.Exists(fileDir))
|
||||
{
|
||||
Directory.CreateDirectory(fileDir);
|
||||
}
|
||||
|
||||
webClient.DownloadFileAsync(new Uri(latestVersionFolder + filesToDownload[0]), @dir + "\\" + filesToDownload[0]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class GraphicsMode
|
||||
@@ -182,7 +373,6 @@ namespace Launcher
|
||||
public int dmReserved2;
|
||||
public int dmPanningWidth;
|
||||
public int dmPanningHeight;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3552
-2766
File diff suppressed because it is too large
Load Diff
@@ -38,6 +38,10 @@
|
||||
<ApplicationIcon>Icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.DirectoryServices" />
|
||||
@@ -67,6 +71,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="PackageManager.resx">
|
||||
<DependentUpon>PackageManager.cs</DependentUpon>
|
||||
@@ -80,6 +85,7 @@
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="RestSharp" version="105.2.3" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user