Allows the creation of a file (0:/md.txt) for testing ShiftOS Markdown in the shiftnet
This commit is contained in:
parent
4723e0a604
commit
f16e5da5ae
3 changed files with 188 additions and 108 deletions
|
@ -35,36 +35,33 @@ using ShiftOS.Engine;
|
|||
using Newtonsoft.Json;
|
||||
using static ShiftOS.Engine.SkinEngine;
|
||||
|
||||
namespace ShiftOS.WinForms.Applications
|
||||
{
|
||||
namespace ShiftOS.WinForms.Applications {
|
||||
[Launcher("Shiftnet", false, null, "Networking")]
|
||||
[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")
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
wbcanvas.DocumentText = ConstructHtml(msg.Contents);
|
||||
}));
|
||||
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 {
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
wbcanvas.DocumentText = ConstructHtml(msg.Contents);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
} catch {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public string ConstructHtml(string markdown)
|
||||
{
|
||||
public string ConstructHtml(string markdown) {
|
||||
string html = $@"<html>
|
||||
<head>
|
||||
<style>
|
||||
|
@ -104,8 +101,7 @@ 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,15 +111,12 @@ 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/", ""));
|
||||
}
|
||||
|
||||
|
@ -131,23 +124,16 @@ 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.
|
||||
|
@ -156,10 +142,8 @@ namespace ShiftOS.WinForms.Applications
|
|||
SaveSystem.CurrentSave.LastMonthPaid = DateTime.Now.Month;
|
||||
//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.");
|
||||
}
|
||||
|
@ -174,51 +158,39 @@ 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;
|
||||
|
@ -229,79 +201,60 @@ 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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
9
ShiftOS.WinForms/Window.Designer.cs
generated
9
ShiftOS.WinForms/Window.Designer.cs
generated
|
@ -52,8 +52,15 @@ namespace ShiftOS.WinForms
|
|||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// Window
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Name = "Window";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
120
ShiftOS.WinForms/Window.resx
Normal file
120
ShiftOS.WinForms/Window.resx
Normal 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>
|
Reference in a new issue