Update Manager

Use the "ShiftOS.Updater" as your startup project for this to work
correctly.
This commit is contained in:
Michael 2017-04-07 18:33:36 -04:00
parent 0d198594c4
commit a8583c95d0
15 changed files with 927 additions and 52 deletions

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View file

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShiftOS.Updater.exe
{
class Program
{
static void Main(string[] args)
{
}
}
}

View 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("ShiftOS.Updater.exe")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShiftOS.Updater.exe")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[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("8031adf5-caf0-4210-bec0-964a9db130a9")]
// 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.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8031ADF5-CAF0-4210-BEC0-964A9DB130A9}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ShiftOS.Updater.exe</RootNamespace>
<AssemblyName>ShiftOS.Updater.exe</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

View file

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ShiftOS.Updater
{
class Program
{
static void Main(string[] args)
{
if (Directory.Exists("updater-work"))
{
//Give the engine time to shutdown before invoking this app.
Thread.Sleep(5000);
foreach (var f in Directory.GetFiles("updater-work"))
{
var bytes = File.ReadAllBytes(f);
var finf = new FileInfo(f);
File.WriteAllBytes(finf.Name, bytes);
}
Directory.Delete("updater-work", true);
}
//Restart the actual game.
System.Diagnostics.Process.Start("ShiftOS.WinForms.exe");
}
}
}

View 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("ShiftOS.Updater")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShiftOS.Updater")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[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("36bc512f-6fd4-4139-aed7-565fc8d5bcbc")]
// 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.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{36BC512F-6FD4-4139-AED7-565FC8D5BCBC}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ShiftOS.Updater</RootNamespace>
<AssemblyName>ShiftOS.Updater</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ShiftOS.WinForms\ShiftOS.WinForms.csproj">
<Project>{2295d2e2-3a00-4e02-b66f-b961ac329fe6}</Project>
<Name>ShiftOS.WinForms</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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>

View file

@ -36,34 +36,53 @@ using Newtonsoft.Json;
using static ShiftOS.Engine.SkinEngine;
using ShiftOS.WinForms.Tools;
namespace ShiftOS.WinForms.Applications {
namespace ShiftOS.WinForms.Applications
{
//OH MY GOD. I HAD TO CORRECT HEAPS OF BADLY PLACED CURLY BRACES.
//
//I DO NOT CARE WHAT THE BLUE SMILEY FACE SAYS. CURLY BRACES BELONG ON THEIR OWN LINE.
//
//READ THE DAMN SHIFTOS CODING GUIDELINES.
[Launcher("Shiftnet", false, null, "Networking")]
[MultiplayerOnly]
[DefaultIcon("iconShiftnet")]
public partial class Shiftnet : UserControl, IShiftOSWindow {
public Shiftnet() {
public partial class Shiftnet : UserControl, IShiftOSWindow
{
public Shiftnet()
{
InitializeComponent();
ServerManager.MessageReceived += (msg) => {
try {
if (msg.Name == "shiftnet_file") {
if (Objects.ShiftFS.Utils.FileExists("0:/md.txt")) {
this.Invoke(new Action(() => {
ServerManager.MessageReceived += (msg) =>
{
try
{
if (msg.Name == "shiftnet_file")
{
if (Objects.ShiftFS.Utils.FileExists("0:/md.txt"))
{
this.Invoke(new Action(() =>
{
wbcanvas.DocumentText = ConstructHtml(Objects.ShiftFS.Utils.ReadAllText("0:/md.txt"));
}));
} else {
}
else
{
this.Invoke(new Action(() =>
{
wbcanvas.DocumentText = ConstructHtml(msg.Contents);
}));
}
}
} catch {
}
catch
{
}
};
}
public string ConstructHtml(string markdown) {
public string ConstructHtml(string markdown)
{
var TerminalForeColor = ControlManager.ConvertColor(SkinEngine.LoadedSkin.TerminalForeColorCC);
var TerminalBackColor = ControlManager.ConvertColor(SkinEngine.LoadedSkin.TerminalBackColorCC);
string html = $@"<html>
@ -105,7 +124,8 @@ namespace ShiftOS.WinForms.Applications {
</html>";
string body = CommonMark.CommonMarkConverter.Convert(markdown);
for (int i = 0; i <= Encoding.UTF8.GetBytes(body).Length; i += DownloadManager.GetDownloadSpeed()) {
for (int i = 0; i <= Encoding.UTF8.GetBytes(body).Length; i += DownloadManager.GetDownloadSpeed())
{
//halt the page load until 'download' finishes.
}
html = html.Replace("<markdown/>", body);
@ -115,12 +135,15 @@ namespace ShiftOS.WinForms.Applications {
public string CurrentUrl { get; set; }
private void wbcanvas_Navigating(object sender, WebBrowserNavigatingEventArgs e) {
private void wbcanvas_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
string Url = e.Url.ToString().Replace("http://", "");
if (CurrentUrl != Url.ToString() && !Url.ToString().StartsWith("about:")) {
if (CurrentUrl != Url.ToString() && !Url.ToString().StartsWith("about:"))
{
e.Cancel = true;
Future.Clear();
if (Url.StartsWith("runsyscmd/")) {
if (Url.StartsWith("runsyscmd/"))
{
ProcessShiftnetCmd(Url.Replace("runsyscmd/", ""));
}
@ -128,16 +151,23 @@ namespace ShiftOS.WinForms.Applications {
}
}
public void ProcessShiftnetCmd(string cmd) {
public void ProcessShiftnetCmd(string cmd)
{
var args = cmd.Split('/');
switch (args[0]) {
switch (args[0])
{
case "setsnsub":
for (int i = 0; i < DownloadManager.GetAllSubscriptions().Length; i++) {
if (DownloadManager.GetAllSubscriptions()[i].Name == args[1]) {
for (int i = 0; i < DownloadManager.GetAllSubscriptions().Length; i++)
{
if (DownloadManager.GetAllSubscriptions()[i].Name == args[1])
{
var sub = DownloadManager.GetAllSubscriptions()[i];
Infobox.PromptYesNo("Shiftnet", $"Are you sure you want to switch your system's Shiftnet subscription to {sub.Name} by {sub.Company}?{Environment.NewLine}{Environment.NewLine}Cost per month: {sub.CostPerMonth} CP{Environment.NewLine}Download speed: {sub.DownloadSpeed} bytes per second", new Action<bool>((answer) => {
if (answer == true) {
if (SaveSystem.CurrentSave.Codepoints >= sub.CostPerMonth) {
Infobox.PromptYesNo("Shiftnet", $"Are you sure you want to switch your system's Shiftnet subscription to {sub.Name} by {sub.Company}?{Environment.NewLine}{Environment.NewLine}Cost per month: {sub.CostPerMonth} CP{Environment.NewLine}Download speed: {sub.DownloadSpeed} bytes per second", new Action<bool>((answer) =>
{
if (answer == true)
{
if (SaveSystem.CurrentSave.Codepoints >= sub.CostPerMonth)
{
//Initial fee gets deducted.
SaveSystem.CurrentSave.Codepoints -= sub.CostPerMonth;
//Then we set the subscription.
@ -147,7 +177,9 @@ namespace ShiftOS.WinForms.Applications {
//Then we send our save to the MUD.
SaveSystem.SaveGame();
} else {
}
else
{
//User can't afford this subscription.
Infobox.Show("Shiftnet - Not enough Codepoints", $"You cannot afford to pay for this subscription at this time. You need {sub.CostPerMonth - SaveSystem.CurrentSave.Codepoints} more Codepoints.");
}
@ -162,39 +194,51 @@ namespace ShiftOS.WinForms.Applications {
public Stack<string> History = new Stack<string>();
public Stack<string> Future = new Stack<string>();
public void ShiftnetNavigate(string Url, bool pushHistory = true) {
if (Url.EndsWith(".rnp") || !Url.Contains(".")) {
public void ShiftnetNavigate(string Url, bool pushHistory = true)
{
if (Url.EndsWith(".rnp") || !Url.Contains("."))
{
if (!string.IsNullOrEmpty(CurrentUrl) && pushHistory)
History.Push(CurrentUrl);
CurrentUrl = Url;
ServerManager.SendMessage("shiftnet_get", JsonConvert.SerializeObject(new {
ServerManager.SendMessage("shiftnet_get", JsonConvert.SerializeObject(new
{
url = Url
}));
txturl.Text = Url;
} else {
}
else
{
ServerMessageReceived smr = null;
smr = (msg) => {
if (msg.Name == "download_meta") {
smr = (msg) =>
{
if (msg.Name == "download_meta")
{
var bytes = JsonConvert.DeserializeObject<byte[]>(msg.Contents);
string destPath = null;
string ext = Url.Split('.')[Url.Split('.').Length - 1];
this.Invoke(new Action(() => {
FileSkimmerBackend.GetFile(new[] { ext }, FileOpenerStyle.Save, new Action<string>((file) => {
this.Invoke(new Action(() =>
{
FileSkimmerBackend.GetFile(new[] { ext }, FileOpenerStyle.Save, new Action<string>((file) =>
{
destPath = file;
}));
}));
while (string.IsNullOrEmpty(destPath)) {
while (string.IsNullOrEmpty(destPath))
{
}
var d = new Download {
var d = new Download
{
ShiftnetUrl = Url,
Destination = destPath,
Bytes = bytes,
Progress = 0,
};
DownloadManager.StartDownload(d);
this.Invoke(new Action(() => {
this.Invoke(new Action(() =>
{
AppearanceManager.SetupWindow(new Downloader());
}));
ServerManager.MessageReceived -= smr;
@ -205,60 +249,79 @@ namespace ShiftOS.WinForms.Applications {
}
}
public void OnLoad() {
public void OnLoad()
{
ShiftnetNavigate("shiftnet/main");
}
public void OnSkinLoad() {
public void OnSkinLoad()
{
ShiftnetNavigate(CurrentUrl);
}
public bool OnUnload() {
public bool OnUnload()
{
return true;
}
public void OnUpgrade() {
public void OnUpgrade()
{
}
private void btnback_Click(object sender, EventArgs e) {
try {
private void btnback_Click(object sender, EventArgs e)
{
try
{
string hist = History.Pop();
if (!string.IsNullOrEmpty(hist)) {
if (!string.IsNullOrEmpty(hist))
{
Future.Push(hist);
ShiftnetNavigate(hist, false);
}
} catch {
}
catch
{
}
}
private void btnforward_Click(object sender, EventArgs e) {
try {
private void btnforward_Click(object sender, EventArgs e)
{
try
{
string fut = Future.Pop();
if (!string.IsNullOrEmpty(fut)) {
if (!string.IsNullOrEmpty(fut))
{
ShiftnetNavigate(fut);
}
} catch {
}
catch
{
}
}
private void btngo_Click(object sender, EventArgs e) {
if (!string.IsNullOrWhiteSpace(txturl.Text)) {
private void btngo_Click(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(txturl.Text))
{
Future.Clear();
ShiftnetNavigate(txturl.Text);
}
}
private void txturl_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Enter) {
private void txturl_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btngo_Click(sender, EventArgs.Empty);
e.SuppressKeyPress = true;
}
}
private void wbcanvas_Navigated(object sender, WebBrowserNavigatedEventArgs e) {
private void wbcanvas_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
}
}
}

View file

@ -0,0 +1,130 @@
namespace ShiftOS.WinForms.Applications
{
partial class UpdateManager
{
/// <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 Component 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.lbupdatetitle = new System.Windows.Forms.Label();
this.pnlupdatebar = new System.Windows.Forms.Panel();
this.btnclose = new System.Windows.Forms.Button();
this.btnaction = new System.Windows.Forms.Button();
this.pgdownload = new ShiftOS.WinForms.Controls.ShiftedProgressBar();
this.wbstatus = new System.Windows.Forms.WebBrowser();
this.pnlupdatebar.SuspendLayout();
this.SuspendLayout();
//
// lbupdatetitle
//
this.lbupdatetitle.AutoSize = true;
this.lbupdatetitle.Dock = System.Windows.Forms.DockStyle.Top;
this.lbupdatetitle.Location = new System.Drawing.Point(0, 0);
this.lbupdatetitle.Margin = new System.Windows.Forms.Padding(10);
this.lbupdatetitle.Name = "lbupdatetitle";
this.lbupdatetitle.Size = new System.Drawing.Size(117, 13);
this.lbupdatetitle.TabIndex = 0;
this.lbupdatetitle.Tag = "header1";
this.lbupdatetitle.Text = "Checking for updates...";
//
// pnlupdatebar
//
this.pnlupdatebar.Controls.Add(this.pgdownload);
this.pnlupdatebar.Controls.Add(this.btnaction);
this.pnlupdatebar.Controls.Add(this.btnclose);
this.pnlupdatebar.Dock = System.Windows.Forms.DockStyle.Bottom;
this.pnlupdatebar.Location = new System.Drawing.Point(0, 426);
this.pnlupdatebar.Name = "pnlupdatebar";
this.pnlupdatebar.Size = new System.Drawing.Size(597, 33);
this.pnlupdatebar.TabIndex = 1;
//
// btnclose
//
this.btnclose.Location = new System.Drawing.Point(4, 4);
this.btnclose.Name = "btnclose";
this.btnclose.Size = new System.Drawing.Size(75, 23);
this.btnclose.TabIndex = 0;
this.btnclose.Text = "{CLOSE}";
this.btnclose.UseVisualStyleBackColor = true;
this.btnclose.Click += new System.EventHandler(this.btnclose_Click);
//
// btnaction
//
this.btnaction.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnaction.Location = new System.Drawing.Point(519, 4);
this.btnaction.Name = "btnaction";
this.btnaction.Size = new System.Drawing.Size(75, 23);
this.btnaction.TabIndex = 1;
this.btnaction.Text = "Update";
this.btnaction.UseVisualStyleBackColor = true;
//
// pgdownload
//
this.pgdownload.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pgdownload.BlockSize = 5;
this.pgdownload.Location = new System.Drawing.Point(86, 4);
this.pgdownload.Maximum = 100;
this.pgdownload.Name = "pgdownload";
this.pgdownload.Size = new System.Drawing.Size(427, 23);
this.pgdownload.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
this.pgdownload.TabIndex = 2;
this.pgdownload.Text = "Updating...";
this.pgdownload.Value = 0;
//
// wbstatus
//
this.wbstatus.Dock = System.Windows.Forms.DockStyle.Fill;
this.wbstatus.Location = new System.Drawing.Point(0, 13);
this.wbstatus.MinimumSize = new System.Drawing.Size(20, 20);
this.wbstatus.Name = "wbstatus";
this.wbstatus.Size = new System.Drawing.Size(597, 413);
this.wbstatus.TabIndex = 2;
//
// UpdateManager
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.wbstatus);
this.Controls.Add(this.pnlupdatebar);
this.Controls.Add(this.lbupdatetitle);
this.Name = "UpdateManager";
this.Size = new System.Drawing.Size(597, 459);
this.pnlupdatebar.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lbupdatetitle;
private System.Windows.Forms.Panel pnlupdatebar;
private Controls.ShiftedProgressBar pgdownload;
private System.Windows.Forms.Button btnaction;
private System.Windows.Forms.Button btnclose;
private System.Windows.Forms.WebBrowser wbstatus;
}
}

View file

@ -0,0 +1,279 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ShiftOS.Engine;
using ShiftOS.WinForms.Tools;
using static ShiftOS.Engine.SkinEngine;
using System.Net;
using Newtonsoft.Json;
using System.Reflection;
using System.IO;
using System.IO.Compression;
namespace ShiftOS.WinForms.Applications
{
[Launcher("Update Manager", true, "al_update_manager", "Networking")]
[DefaultTitle("Update Manager")]
[WinOpen("update_manager")]
public partial class UpdateManager : UserControl, IShiftOSWindow
{
public UpdateManager()
{
InitializeComponent();
btnaction.Click += (o, a) => OnActionButtonClick?.Invoke();
}
public void OnLoad()
{
CheckForUpdate();
}
public void CheckForUpdate()
{
ConstructHtml(@"ShiftOS is grabbing information on the latest version. Please be patient.");
pgdownload.Show();
btnaction.Show();
lbupdatetitle.Text = "Checking for updates...";
pgdownload.Value = 0;
pgdownload.Maximum = 100;
var wc = new WebClient();
wc.DownloadProgressChanged += (o, a) =>
{
this.Invoke(new Action(() =>
{
pgdownload.Text = "Grabbing update data from multi-user-domain...";
pgdownload.Value = a.ProgressPercentage;
}));
};
wc.DownloadStringCompleted += (o, a) =>
{
var releases = JsonConvert.DeserializeObject<ShiftOS.Objects.Unite.Download[]>(a.Result);
var download = releases.OrderByDescending(x => x.PostDate).First();
var thisBuildDate = Assembly.GetExecutingAssembly().GetBuildDate(TimeZoneInfo.Utc);
if(download.PostDate > thisBuildDate)
{
this.Invoke(new Action(() =>
{
//This build is more recent than the currently running ShiftOS client.
SetupBuildUpdate(download);
}));
}
else
{
if (thisBuildDate > download.PostDate)
{
this.Invoke(new Action(() => ConstructHtml($@"### Unreleased build.
You are currently running an unreleased build of ShiftOS, compiled on {thisBuildDate}, after the latest released version, {download.Name}, compiled on {download.PostDate}.")));
}
else
{
this.Invoke(new Action(() => ConstructHtml($@"### Up to date.
You are currently running {download.Name}, compiled on {download.PostDate}.")));
}
this.Invoke(new Action(() =>
{
lbupdatetitle.Text = "No update available";
pgdownload.Hide();
btnaction.Hide();
}));
}
};
wc.DownloadStringAsync(new Uri("http://getshiftos.ml/API/Releases?showUnstable=true&showObsolete=false"));
}
public void OnSkinLoad()
{
ConstructHtml(CurrentMD);
}
public bool OnUnload()
{
return true;
}
public void OnUpgrade()
{
ConstructHtml(CurrentMD);
}
public void SetupBuildUpdate(ShiftOS.Objects.Unite.Download download)
{
string devUpdate = "";
if (!string.IsNullOrEmpty(download.DevUpdateId))
{
devUpdate = $@"## Development update
<iframe src=""http://youtube.com/embed/{download.DevUpdateId}"" allowfullscreen width=""720"" height=""480""></iframe>
";
}
string screenshot = "";
if(!string.IsNullOrEmpty(download.ScreenshotUrl))
{
screenshot = $"<img src=\"http://getshiftos.ml{download.ScreenshotUrl}\" style=\"max-width:720px;width:auto;height:auto;\"/>";
}
lbupdatetitle.Text = download.Name;
string markdown = $@"**Built on {download.PostDate}**
{devUpdate}
{screenshot}
## Changelog
{download.Changelog}";
ConstructHtml(markdown);
pgdownload.Value = 0;
pgdownload.Text = "Waiting.";
btnaction.Text = "Update";
btnaction.Show();
OnActionButtonClick = () =>
{
pgdownload.Show();
var wc = new WebClient();
wc.DownloadProgressChanged += (o, a) =>
{
this.Invoke(new Action(() =>
{
pgdownload.Text = "Downloading " + download.Name + "...";
pgdownload.Value = a.ProgressPercentage;
}));
};
wc.DownloadDataCompleted += (o, a) =>
{
if (Directory.Exists("updater-work"))
Directory.Delete("updater-work", true);
Directory.CreateDirectory("updater-work");
string temp_guid = Guid.NewGuid().ToString();
File.WriteAllBytes($"{temp_guid}.zip", a.Result);
ZipFile.ExtractToDirectory($"{temp_guid}.zip", "updater-work");
File.Delete($"{temp_guid}.zip");
//Start the updater helper.
System.Diagnostics.Process.Start("ShiftOS.Updater.exe");
//Now we stop the engine.
TerminalBackend.InvokeCommand("sos.shutdown");
};
wc.DownloadDataAsync(new Uri($"http://getshiftos.ml{download.DownloadUrl}"));
};
}
public Action OnActionButtonClick = () => { };
public void ConstructHtml(string markdown)
{
CurrentMD = markdown;
var TerminalForeColor = ControlManager.ConvertColor(SkinEngine.LoadedSkin.TerminalForeColorCC);
var TerminalBackColor = ControlManager.ConvertColor(SkinEngine.LoadedSkin.TerminalBackColorCC);
string html = $@"<html>
<head>
<style>
body {{
background-color: rgb({LoadedSkin.ControlColor.R}, {LoadedSkin.ControlColor.G}, {LoadedSkin.ControlColor.B});
color: rgb({LoadedSkin.ControlTextColor.R}, {LoadedSkin.ControlTextColor.G}, {LoadedSkin.ControlTextColor.B});
font-family: ""{LoadedSkin.MainFont.Name}"";
font-size: {LoadedSkin.MainFont.SizeInPoints}pt;
}}
h1 {{
font-family: ""{LoadedSkin.HeaderFont.Name}"";
font-size: {LoadedSkin.HeaderFont.SizeInPoints}pt;
}}
h2 {{
font-family: ""{LoadedSkin.Header2Font.Name}"";
font-size: {LoadedSkin.Header2Font.SizeInPoints}pt;
}}
h3 {{
font-family: ""{LoadedSkin.Header3Font.Name}"";
font-size: {LoadedSkin.Header3Font.SizeInPoints}pt;
}}
pre, code {{
font-family: ""{LoadedSkin.TerminalFont.Name}"";
font-size: {LoadedSkin.TerminalFont.SizeInPoints}pt;
color: rgb({TerminalForeColor.R}, {TerminalForeColor.G}, {TerminalForeColor.B});
background-color: rgb({TerminalBackColor.R}, {TerminalBackColor.G}, {TerminalBackColor.B});
}}
</style>
</head>
<body>
<markdown/>
</body>
</html>";
string body = CommonMark.CommonMarkConverter.Convert(markdown);
html = html.Replace("<markdown/>", body);
wbstatus.DocumentText = html;
}
public string CurrentMD = "";
private void btnclose_Click(object sender, EventArgs e)
{
AppearanceManager.Close(this);
}
}
public static class UpdateHelpers
{
/// <summary>
/// Grabs the build date from the assembly's PE header.
/// </summary>
/// <param name="assembly">The assembly to probe.</param>
/// <param name="target">The target timezone.</param>
/// <returns>The assembly's build date.</returns>
public static DateTime GetBuildDate(this Assembly assembly, TimeZoneInfo target = null)
{
var filePath = assembly.Location;
const int c_PeHeaderOffset = 60;
const int c_LinkerTimestampOffset = 8;
var buffer = new byte[2048];
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
stream.Read(buffer, 0, 2048);
var offset = BitConverter.ToInt32(buffer, c_PeHeaderOffset);
var secondsSince1970 = BitConverter.ToInt32(buffer, offset + c_LinkerTimestampOffset);
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var linkTimeUtc = epoch.AddSeconds(secondsSince1970);
var tz = target ?? TimeZoneInfo.Local;
var localTime = TimeZoneInfo.ConvertTimeFromUtc(linkTimeUtc, tz);
return localTime;
}
}
}

View file

@ -0,0 +1,120 @@
<?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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -945,6 +945,16 @@
Description: "In the shiftorium GUI but dont know what you can spend because you can't see how many code points are on hand? Well shop easy, because with this upgrade that is now possible! You have to restart the shiftorium for it to work."
},
//UPDATE MANAGER
{
Name: "AL Update Manager",
Cost: 150,
Description: "Want to get the latest features of ShiftOS, right from your App Launcher? This upgrade is for you!",
Dependencies: "app_launcher",
Category: "GUI"
},
// SHIFTSWEEPER
{

View file

@ -43,6 +43,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -226,6 +227,12 @@
<Compile Include="Applications\TutorialBox.Designer.cs">
<DependentUpon>TutorialBox.cs</DependentUpon>
</Compile>
<Compile Include="Applications\UpdateManager.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Applications\UpdateManager.Designer.cs">
<DependentUpon>UpdateManager.cs</DependentUpon>
</Compile>
<Compile Include="AudioManager.cs" />
<Compile Include="Commands.cs" />
<Compile Include="Controls\ColorControl.cs">
@ -377,6 +384,9 @@
<EmbeddedResource Include="Applications\TutorialBox.resx">
<DependentUpon>TutorialBox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Applications\UpdateManager.resx">
<DependentUpon>UpdateManager.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="DownloadControl.resx">
<DependentUpon>DownloadControl.cs</DependentUpon>
</EmbeddedResource>

View file

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShiftOS.Engine", "ShiftOS_TheReturn\ShiftOS.Engine.csproj", "{7C979B07-0585-4033-A110-E5555B9D6651}"
EndProject
@ -19,6 +19,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ShiftOS.Modding.VB.LegacySk
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModLauncher", "ModLauncher\ModLauncher.csproj", "{AEACB7B5-E8FC-4569-BBD3-5053A694D6EC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShiftOS.Updater", "ShiftOS.Updater\ShiftOS.Updater.csproj", "{36BC512F-6FD4-4139-AED7-565FC8D5BCBC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -57,6 +59,10 @@ Global
{AEACB7B5-E8FC-4569-BBD3-5053A694D6EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEACB7B5-E8FC-4569-BBD3-5053A694D6EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEACB7B5-E8FC-4569-BBD3-5053A694D6EC}.Release|Any CPU.Build.0 = Release|Any CPU
{36BC512F-6FD4-4139-AED7-565FC8D5BCBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{36BC512F-6FD4-4139-AED7-565FC8D5BCBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36BC512F-6FD4-4139-AED7-565FC8D5BCBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36BC512F-6FD4-4139-AED7-565FC8D5BCBC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE