aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.WinForms')
-rw-r--r--ShiftOS.WinForms/Applications/Shifter.cs679
-rw-r--r--ShiftOS.WinForms/Applications/Terminal.cs4
-rw-r--r--ShiftOS.WinForms/Servers/RemoteTerminalServer.cs161
-rw-r--r--ShiftOS.WinForms/ShiftOS.WinForms.csproj1
-rw-r--r--ShiftOS.WinForms/Tools/ControlManager.cs13
5 files changed, 524 insertions, 334 deletions
diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs
index acb64a5..1a59c80 100644
--- a/ShiftOS.WinForms/Applications/Shifter.cs
+++ b/ShiftOS.WinForms/Applications/Shifter.cs
@@ -31,6 +31,8 @@ using System.Reflection;
using System.Windows.Forms;
using ShiftOS.Engine;
using ShiftOS.WinForms.Tools;
+using System.Linq;
+using System.Threading;
namespace ShiftOS.WinForms.Applications
{
@@ -540,400 +542,425 @@ namespace ShiftOS.WinForms.Applications
{
flbody.Controls.Clear();
- List<ShifterSetting> cats = new List<ShifterSetting>();
+ IEnumerable<ShifterSetting> cats = this.settings.Where(x => x.SubCategory == subcat && x.Category == cat && x.Field.FlagFullfilled(LoadedSkin)).OrderBy(x=>x.Name);
- foreach (var c in this.settings)
+ new Thread(() =>
{
- if (c.SubCategory == subcat && c.Category == cat)
+ foreach (var c in cats)
{
- if (c.Field.FlagFullfilled(LoadedSkin))
+ Label lbl = null;
+ int labelHeight = 0;
+ Desktop.InvokeOnWorkerThread(() =>
{
- if (!cats.Contains(c))
- {
- cats.Add(c);
- }
- }
- }
- }
-
- foreach(var c in cats)
- {
- var lbl = new Label();
- int labelHeight = 0;
- lbl.AutoSize = true;
- lbl.Text = c.Name + ":";
- flbody.Controls.Add(lbl);
- lbl.TextAlign = ContentAlignment.MiddleLeft;
- lbl.Show();
- //Cool - label's in.
- if(c.Field.FieldType == typeof(Point))
- {
- var width = new TextBox();
- var height = new TextBox();
- labelHeight = width.Height; //irony?
- width.Width = 30;
- height.Width = width.Width;
- width.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString();
- height.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString();
- flbody.SetFlowBreak(height, true);
- ControlManager.SetupControl(width);
- ControlManager.SetupControl(height);
-
- flbody.Controls.Add(width);
- width.Show();
- flbody.Controls.Add(height);
- height.Show();
-
- EventHandler tc = (o, a) =>
+ lbl = new Label();
+ lbl.AutoSize = true;
+ lbl.Text = c.Name + ":";
+ flbody.Controls.Add(lbl);
+ lbl.TextAlign = ContentAlignment.MiddleLeft;
+ lbl.Show();
+ });
+ //Cool - label's in.
+ if (c.Field.FieldType == typeof(Point))
{
- try
+ TextBox width = null;
+ TextBox height = null;
+ Desktop.InvokeOnWorkerThread(() =>
{
- int x = Convert.ToInt32(width.Text);
- int y = Convert.ToInt32(height.Text);
+ width = new TextBox();
+ height = new TextBox();
+ labelHeight = width.Height; //irony?
+ width.Width = 30;
+ height.Width = width.Width;
+ width.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString();
+ height.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString();
+ flbody.SetFlowBreak(height, true);
+ ControlManager.SetupControl(width);
+ ControlManager.SetupControl(height);
- int oldx = ((Point)c.Field.GetValue(this.LoadedSkin)).X;
- int oldy = ((Point)c.Field.GetValue(this.LoadedSkin)).Y;
+ flbody.Controls.Add(width);
+ width.Show();
+ flbody.Controls.Add(height);
+ height.Show();
- if(x != oldx || y != oldy)
+ EventHandler tc = (o, a) =>
{
- c.Field.SetValue(LoadedSkin, new Point(x, y));
- CodepointValue += 200;
- }
- }
- catch
- {
- width.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString();
- height.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString();
- }
- InvokeSetup(cat);
- };
+ try
+ {
+ int x = Convert.ToInt32(width.Text);
+ int y = Convert.ToInt32(height.Text);
- width.TextChanged += tc;
- height.TextChanged += tc;
+ int oldx = ((Point)c.Field.GetValue(this.LoadedSkin)).X;
+ int oldy = ((Point)c.Field.GetValue(this.LoadedSkin)).Y;
- }
- else if(c.Field.FieldType == typeof(string))
- {
- var str = new TextBox();
- str.Width = 120;
- ControlManager.SetupControl(str);
- labelHeight = str.Height;
- str.Text = c.Field.GetValue(LoadedSkin).ToString();
- flbody.SetFlowBreak(str, true);
- str.TextChanged += (o, a) =>
- {
- c.Field.SetValue(LoadedSkin, str.Text); CodepointValue += 100;
+ if (x != oldx || y != oldy)
+ {
+ c.Field.SetValue(LoadedSkin, new Point(x, y));
+ CodepointValue += 200;
+ }
+ }
+ catch
+ {
+ width.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString();
+ height.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString();
+ }
+ InvokeSetup(cat);
+ };
- InvokeSetup(cat);
- };
- flbody.Controls.Add(str);
- str.Show();
- }
- else if(c.Field.FieldType == typeof(byte[]))
- {
- //We'll assume that this is an image file.
- var color = new Button();
- color.Width = 40;
- labelHeight = color.Height;
- //just so it's flat like the system.
- ControlManager.SetupControl(color);
- flbody.SetFlowBreak(color, true);
-
- color.BackgroundImage = SkinEngine.ImageFromBinary((byte[])c.Field.GetValue(this.LoadedSkin));
- color.Click += (o, a) =>
+ width.TextChanged += tc;
+ height.TextChanged += tc;
+ });
+ }
+ else if (c.Field.FieldType == typeof(string))
{
- AppearanceManager.SetupDialog(new GraphicPicker(color.BackgroundImage, c.Name, GetLayout(c.Field.GetImageName()), new Action<byte[], Image, ImageLayout>((col, gdiImg, layout) =>
+ Desktop.InvokeOnWorkerThread(() =>
{
- c.Field.SetValue(LoadedSkin, col);
- color.BackgroundImage = SkinEngine.ImageFromBinary(col);
- color.BackgroundImageLayout = layout;
- LoadedSkin.SkinImageLayouts[c.Field.GetImageName()] = layout;
- CodepointValue += 700;
- InvokeSetup(cat);
-
- })));
- };
- flbody.Controls.Add(color);
- color.Show();
- }
- else if (c.Field.FieldType == typeof(Size))
- {
- var width = new TextBox();
- var height = new TextBox();
- width.Width = 30;
- height.Width = width.Width;
- labelHeight = width.Height;
- flbody.SetFlowBreak(height, true);
-
- width.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Width.ToString();
- height.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Height.ToString();
- ControlManager.SetupControl(width);
- ControlManager.SetupControl(height);
-
- flbody.Controls.Add(width);
- width.Show();
- flbody.Controls.Add(height);
- height.Show();
-
- EventHandler tc = (o, a) =>
+ var str = new TextBox();
+ str.Width = 120;
+ ControlManager.SetupControl(str);
+ labelHeight = str.Height;
+ str.Text = c.Field.GetValue(LoadedSkin).ToString();
+ flbody.SetFlowBreak(str, true);
+ str.TextChanged += (o, a) =>
+ {
+ c.Field.SetValue(LoadedSkin, str.Text); CodepointValue += 100;
+
+ InvokeSetup(cat);
+ };
+ flbody.Controls.Add(str);
+ str.Show();
+ });
+ }
+ else if (c.Field.FieldType == typeof(byte[]))
{
- try
+ Desktop.InvokeOnWorkerThread(() =>
{
- int x = Convert.ToInt32(width.Text);
- int y = Convert.ToInt32(height.Text);
-
- int oldx = ((Size)c.Field.GetValue(this.LoadedSkin)).Width;
- int oldy = ((Size)c.Field.GetValue(this.LoadedSkin)).Height;
-
- if (x != oldx || y != oldy)
+ //We'll assume that this is an image file.
+ var color = new Button();
+ color.Width = 40;
+ labelHeight = color.Height;
+ //just so it's flat like the system.
+ ControlManager.SetupControl(color);
+ flbody.SetFlowBreak(color, true);
+
+ color.BackgroundImage = SkinEngine.ImageFromBinary((byte[])c.Field.GetValue(this.LoadedSkin));
+ color.Click += (o, a) =>
{
- c.Field.SetValue(LoadedSkin, new Size(x, y));
- CodepointValue += 200;
- }
- }
- catch
+ AppearanceManager.SetupDialog(new GraphicPicker(color.BackgroundImage, c.Name, GetLayout(c.Field.GetImageName()), new Action<byte[], Image, ImageLayout>((col, gdiImg, layout) =>
+ {
+ c.Field.SetValue(LoadedSkin, col);
+ color.BackgroundImage = SkinEngine.ImageFromBinary(col);
+ color.BackgroundImageLayout = layout;
+ LoadedSkin.SkinImageLayouts[c.Field.GetImageName()] = layout;
+ CodepointValue += 700;
+ InvokeSetup(cat);
+
+ })));
+ };
+ flbody.Controls.Add(color);
+ color.Show();
+ });
+ }
+ else if (c.Field.FieldType == typeof(Size))
+ {
+ Desktop.InvokeOnWorkerThread(() =>
{
+ var width = new TextBox();
+ var height = new TextBox();
+ width.Width = 30;
+ height.Width = width.Width;
+ labelHeight = width.Height;
+ flbody.SetFlowBreak(height, true);
+
width.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Width.ToString();
height.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Height.ToString();
- }
- InvokeSetup(cat);
+ ControlManager.SetupControl(width);
+ ControlManager.SetupControl(height);
- };
+ flbody.Controls.Add(width);
+ width.Show();
+ flbody.Controls.Add(height);
+ height.Show();
- width.TextChanged += tc;
- height.TextChanged += tc;
+ EventHandler tc = (o, a) =>
+ {
+ try
+ {
+ int x = Convert.ToInt32(width.Text);
+ int y = Convert.ToInt32(height.Text);
- }
- else if(c.Field.FieldType == typeof(bool))
- {
- var check = new CheckBox();
- check.Checked = ((bool)c.Field.GetValue(LoadedSkin));
- labelHeight = check.Height;
- check.CheckedChanged += (o, a) =>
- {
- c.Field.SetValue(LoadedSkin, check.Checked);
- CodepointValue += 50;
- InvokeSetup(cat);
+ int oldx = ((Size)c.Field.GetValue(this.LoadedSkin)).Width;
+ int oldy = ((Size)c.Field.GetValue(this.LoadedSkin)).Height;
- };
- flbody.SetFlowBreak(check, true);
+ if (x != oldx || y != oldy)
+ {
+ c.Field.SetValue(LoadedSkin, new Size(x, y));
+ CodepointValue += 200;
+ }
+ }
+ catch
+ {
+ width.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Width.ToString();
+ height.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Height.ToString();
+ }
+ InvokeSetup(cat);
- flbody.Controls.Add(check);
- check.Show();
- }
- else if(c.Field.FieldType == typeof(Font))
- {
- var name = new ComboBox();
- var size = new TextBox();
- var style = new ComboBox();
-
- name.Width = 120;
- labelHeight = name.Height;
- size.Width = 40;
- style.Width = 80;
- flbody.SetFlowBreak(style, true);
-
- ControlManager.SetupControl(name);
- ControlManager.SetupControl(size);
- ControlManager.SetupControl(style);
-
- //populate the font name box
- foreach(var font in FontFamily.Families)
- {
- name.Items.Add(font.Name);
+ };
+
+ width.TextChanged += tc;
+ height.TextChanged += tc;
+ });
}
- name.Text = ((Font)c.Field.GetValue(LoadedSkin)).Name;
+ else if (c.Field.FieldType == typeof(bool))
+ {
+ Desktop.InvokeOnWorkerThread(() =>
+ {
+ var check = new CheckBox();
+ check.Checked = ((bool)c.Field.GetValue(LoadedSkin));
+ labelHeight = check.Height;
+ check.CheckedChanged += (o, a) =>
+ {
+ c.Field.SetValue(LoadedSkin, check.Checked);
+ CodepointValue += 50;
+ InvokeSetup(cat);
- size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString();
+ };
+ flbody.SetFlowBreak(check, true);
- //populate the style box
- foreach(var s in (FontStyle[])Enum.GetValues(typeof(FontStyle)))
- {
- style.Items.Add(s.ToString());
+ flbody.Controls.Add(check);
+ check.Show();
+ });
}
- style.Text = ((Font)c.Field.GetValue(LoadedSkin)).Style.ToString();
-
- name.SelectedIndexChanged += (o, a) =>
+ else if (c.Field.FieldType == typeof(Font))
{
- var en = (FontStyle[])Enum.GetValues(typeof(FontStyle));
+ Desktop.InvokeOnWorkerThread(() =>
+ {
+ var name = new ComboBox();
+ var size = new TextBox();
+ var style = new ComboBox();
+
+ name.Width = 120;
+ labelHeight = name.Height;
+ size.Width = 40;
+ style.Width = 80;
+ flbody.SetFlowBreak(style, true);
+
+ ControlManager.SetupControl(name);
+ ControlManager.SetupControl(size);
+ ControlManager.SetupControl(style);
+
+ //populate the font name box
+ foreach (var font in FontFamily.Families)
+ {
+ name.Items.Add(font.Name);
+ }
+ name.Text = ((Font)c.Field.GetValue(LoadedSkin)).Name;
- var f = en[style.SelectedIndex];
+ size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString();
- c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f));
- CodepointValue += 100;
- InvokeSetup(cat);
+ //populate the style box
+ foreach (var s in (FontStyle[])Enum.GetValues(typeof(FontStyle)))
+ {
+ style.Items.Add(s.ToString());
+ }
+ style.Text = ((Font)c.Field.GetValue(LoadedSkin)).Style.ToString();
- };
+ name.SelectedIndexChanged += (o, a) =>
+ {
+ var en = (FontStyle[])Enum.GetValues(typeof(FontStyle));
- style.SelectedIndexChanged += (o, a) =>
- {
- var en = (FontStyle[])Enum.GetValues(typeof(FontStyle));
+ var f = en[style.SelectedIndex];
- var f = en[style.SelectedIndex];
+ c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f));
+ CodepointValue += 100;
+ InvokeSetup(cat);
- c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f));
- CodepointValue += 50;
- InvokeSetup(cat);
+ };
- };
+ style.SelectedIndexChanged += (o, a) =>
+ {
+ var en = (FontStyle[])Enum.GetValues(typeof(FontStyle));
- size.TextChanged += (o, a) =>
- {
- try
- {
- var en = (FontStyle[])Enum.GetValues(typeof(FontStyle));
+ var f = en[style.SelectedIndex];
- var f = en[style.SelectedIndex];
+ c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f));
+ CodepointValue += 50;
+ InvokeSetup(cat);
- c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f));
- }
- catch
- {
- size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString();
- }
- CodepointValue += 50;
- InvokeSetup(cat);
+ };
- };
+ size.TextChanged += (o, a) =>
+ {
+ try
+ {
+ var en = (FontStyle[])Enum.GetValues(typeof(FontStyle));
- flbody.Controls.Add(name);
- flbody.Controls.Add(size);
- flbody.Controls.Add(style);
+ var f = en[style.SelectedIndex];
- name.Show();
- size.Show();
- style.Show();
+ c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToDouble(size.Text), f));
+ }
+ catch
+ {
+ size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString();
+ }
+ CodepointValue += 50;
+ InvokeSetup(cat);
- }
- else if(c.Field.FieldType == typeof(Color))
- {
- var color = new Button();
- color.Width = 40;
- labelHeight = color.Height;
- //just so it's flat like the system.
- ControlManager.SetupControl(color);
-
- color.BackColor = ((Color)c.Field.GetValue(LoadedSkin));
- color.Click += (o, a) =>
- {
- AppearanceManager.SetupDialog(new ColorPicker((Color)c.Field.GetValue(LoadedSkin), c.Name, new Action<Color>((col) =>
- {
- color.BackColor = col;
- c.Field.SetValue(LoadedSkin, col);
- CodepointValue += 300;
- InvokeSetup(cat);
-
- })));
- };
- flbody.SetFlowBreak(color, true);
- color.Tag = "keepbg";
- flbody.Controls.Add(color);
- color.Show();
- }
- else if(c.Field.FieldType.IsEnum == true)
- {
- var cBox = new ComboBox();
- cBox.Width = 150;
- ControlManager.SetupControl(cBox);
+ };
+
+ flbody.Controls.Add(name);
+ flbody.Controls.Add(size);
+ flbody.Controls.Add(style);
- foreach(var itm in Enum.GetNames(c.Field.FieldType))
+ name.Show();
+ size.Show();
+ style.Show();
+ });
+ }
+ else if (c.Field.FieldType == typeof(Color))
{
- cBox.Items.Add(itm);
+ Desktop.InvokeOnWorkerThread(() =>
+ {
+ var color = new Button();
+ color.Width = 40;
+ labelHeight = color.Height;
+ //just so it's flat like the system.
+ ControlManager.SetupControl(color);
+
+ color.BackColor = ((Color)c.Field.GetValue(LoadedSkin));
+ color.Click += (o, a) =>
+ {
+ AppearanceManager.SetupDialog(new ColorPicker((Color)c.Field.GetValue(LoadedSkin), c.Name, new Action<Color>((col) =>
+ {
+ color.BackColor = col;
+ c.Field.SetValue(LoadedSkin, col);
+ CodepointValue += 300;
+ InvokeSetup(cat);
+
+ })));
+ };
+ flbody.SetFlowBreak(color, true);
+ color.Tag = "keepbg";
+ flbody.Controls.Add(color);
+ color.Show();
+ });
}
-
- cBox.Text = c.Field.GetValue(LoadedSkin).ToString();
-
- cBox.SelectedIndexChanged += (o, a) =>
+ else if (c.Field.FieldType.IsEnum == true)
{
- c.Field.SetValue(LoadedSkin, Enum.Parse(c.Field.FieldType, cBox.Text));
- InvokeSetup(cat);
+ Desktop.InvokeOnWorkerThread(() =>
+ {
+ var cBox = new ComboBox();
+ cBox.Width = 150;
+ ControlManager.SetupControl(cBox);
- };
+ foreach (var itm in Enum.GetNames(c.Field.FieldType))
+ {
+ cBox.Items.Add(itm);
+ }
- labelHeight = cBox.Height;
+ cBox.Text = c.Field.GetValue(LoadedSkin).ToString();
- flbody.Controls.Add(cBox);
- cBox.Show();
- flbody.SetFlowBreak(cBox, true);
- }
- else if(c.Field.FieldType == typeof(int))
- {
- if (c.Field.HasShifterEnumMask())
- {
- var name = new ComboBox();
- name.Width = 120;
- ControlManager.SetupControl(name);
- string[] items = c.Field.GetShifterEnumMask();
- foreach(var item in items)
- {
- name.Items.Add(item);
- }
- name.SelectedIndex = (int)c.Field.GetValue(LoadedSkin);
- name.SelectedIndexChanged += (o, a) =>
- {
- c.Field.SetValue(LoadedSkin, name.SelectedIndex);
- CodepointValue += 75;
- InvokeSetup(cat);
+ cBox.SelectedIndexChanged += (o, a) =>
+ {
+ c.Field.SetValue(LoadedSkin, Enum.Parse(c.Field.FieldType, cBox.Text));
+ InvokeSetup(cat);
+
+ };
- };
- labelHeight = name.Height;
- flbody.Controls.Add(name);
- name.Show();
- flbody.SetFlowBreak(name, true);
+ labelHeight = cBox.Height;
+ flbody.Controls.Add(cBox);
+ cBox.Show();
+ flbody.SetFlowBreak(cBox, true);
+ });
}
- else
+ else if (c.Field.FieldType == typeof(int))
{
- var width = new TextBox();
- width.Width = 30;
- width.Text = ((int)c.Field.GetValue(this.LoadedSkin)).ToString();
- ControlManager.SetupControl(width);
- labelHeight = width.Height;
- flbody.Controls.Add(width);
- width.Show();
-
- EventHandler tc = (o, a) =>
+ Desktop.InvokeOnWorkerThread(() =>
{
- try
+ if (c.Field.HasShifterEnumMask())
{
- int x = Convert.ToInt32(width.Text);
-
- int oldx = ((int)c.Field.GetValue(this.LoadedSkin));
-
- if (x != oldx)
+ var name = new ComboBox();
+ name.Width = 120;
+ ControlManager.SetupControl(name);
+ string[] items = c.Field.GetShifterEnumMask();
+ foreach (var item in items)
{
- c.Field.SetValue(LoadedSkin, x);
- CodepointValue += 75;
+ name.Items.Add(item);
}
+ name.SelectedIndex = (int)c.Field.GetValue(LoadedSkin);
+ name.SelectedIndexChanged += (o, a) =>
+ {
+ c.Field.SetValue(LoadedSkin, name.SelectedIndex);
+ CodepointValue += 75;
+ InvokeSetup(cat);
+
+ };
+ labelHeight = name.Height;
+ flbody.Controls.Add(name);
+ name.Show();
+ flbody.SetFlowBreak(name, true);
+
}
- catch
+ else
{
+ var width = new TextBox();
+ width.Width = 30;
width.Text = ((int)c.Field.GetValue(this.LoadedSkin)).ToString();
- }
- InvokeSetup(cat);
+ ControlManager.SetupControl(width);
+ labelHeight = width.Height;
+ flbody.Controls.Add(width);
+ width.Show();
+
+ EventHandler tc = (o, a) =>
+ {
+ try
+ {
+ int x = Convert.ToInt32(width.Text);
+
+ int oldx = ((int)c.Field.GetValue(this.LoadedSkin));
- };
+ if (x != oldx)
+ {
+ c.Field.SetValue(LoadedSkin, x);
+ CodepointValue += 75;
+ }
+ }
+ catch
+ {
+ width.Text = ((int)c.Field.GetValue(this.LoadedSkin)).ToString();
+ }
+ InvokeSetup(cat);
- width.TextChanged += tc;
- flbody.SetFlowBreak(width, true);
+ };
+ width.TextChanged += tc;
+ flbody.SetFlowBreak(width, true);
+
+ }
+ });
}
- }
- lbl.AutoSize = false;
- lbl.Width = (int)this.CreateGraphics().MeasureString(lbl.Text, SkinEngine.LoadedSkin.MainFont).Width + 15;
- lbl.Height = labelHeight;
- lbl.TextAlign = ContentAlignment.MiddleLeft;
+ Desktop.InvokeOnWorkerThread(() =>
+ {
+ lbl.AutoSize = false;
+ lbl.Width = (int)this.CreateGraphics().MeasureString(lbl.Text, SkinEngine.LoadedSkin.MainFont).Width + 15;
+ lbl.Height = labelHeight;
+ lbl.TextAlign = ContentAlignment.MiddleLeft;
+ });
- if (!string.IsNullOrWhiteSpace(c.Description))
- {
- var desc = new Label();
- flbody.SetFlowBreak(desc, true);
- desc.Text = c.Description;
- desc.AutoSize = true;
- flbody.Controls.Add(desc);
- desc.Show();
+ if (!string.IsNullOrWhiteSpace(c.Description))
+ {
+ Desktop.InvokeOnWorkerThread(() =>
+ {
+ var desc = new Label();
+ flbody.SetFlowBreak(desc, true);
+ desc.Text = c.Description;
+ desc.AutoSize = true;
+ flbody.Controls.Add(desc);
+ desc.Show();
+ });
+ }
}
- }
+ }).Start();
}
public ImageLayout GetLayout(string name)
diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs
index 664b657..ea24686 100644
--- a/ShiftOS.WinForms/Applications/Terminal.cs
+++ b/ShiftOS.WinForms/Applications/Terminal.cs
@@ -442,6 +442,10 @@ namespace ShiftOS.WinForms.Applications
}).Start();
}
+ public static string RemoteSystemName { get; set; }
+ public static string RemoteUser { get; set; }
+ public static string RemotePass { get; set; }
+
[Story("first_steps")]
public static void FirstSteps()
{
diff --git a/ShiftOS.WinForms/Servers/RemoteTerminalServer.cs b/ShiftOS.WinForms/Servers/RemoteTerminalServer.cs
new file mode 100644
index 0000000..d57e28f
--- /dev/null
+++ b/ShiftOS.WinForms/Servers/RemoteTerminalServer.cs
@@ -0,0 +1,161 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+using ShiftOS.Engine;
+using ShiftOS.Objects;
+
+namespace ShiftOS.WinForms.Servers
+{
+ [Namespace("rts")]
+ [Server("Remote Terminal Server", 21)]
+ //[RequiresUpgrade("story_hacker101_breakingthebonds")] //Uncomment when story is implemented.
+ public class RemoteTerminalServer : Server
+ {
+ public void MessageReceived(ServerMessage msg)
+ {
+ var rtsMessage = JsonConvert.DeserializeObject<RTSMessage>(msg.Contents);
+ if (msg.Name == "disconnected")
+ {
+ if (Applications.Terminal.IsInRemoteSystem == true)
+ {
+ if (Applications.Terminal.RemoteSystemName == rtsMessage.SenderSystemName)
+ {
+ if(Applications.Terminal.RemoteUser == rtsMessage.Username)
+ if(Applications.Terminal.RemotePass == rtsMessage.Password)
+ {
+ Applications.Terminal.IsInRemoteSystem = false;
+ Applications.Terminal.RemoteSystemName = "";
+ Applications.Terminal.RemoteUser = "";
+ Applications.Terminal.RemotePass = "";
+ TerminalBackend.PrefixEnabled = true;
+ TerminalBackend.PrintPrompt();
+ }
+ }
+ }
+ return;
+ }
+
+ string currentUserName = SaveSystem.CurrentUser.Username;
+
+ var user = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == rtsMessage.Username && x.Password == rtsMessage.Password);
+
+ if(user == null)
+ {
+ ServerManager.SendMessageToIngameServer(rtsMessage.SenderSystemName, 0, "Access denied.", "The username and password you have provided was denied.");
+ return;
+ }
+ else
+ {
+ SaveSystem.CurrentUser = user;
+
+ string cmd = rtsMessage.Namespace + "." + rtsMessage.Command + JsonConvert.SerializeObject(rtsMessage.Arguments);
+ TerminalBackend.InvokeCommand(cmd, true);
+ ServerManager.SendMessageToIngameServer(rtsMessage.SenderSystemName, 1, "writeline", TerminalBackend.LastCommandBuffer);
+ ServerManager.SendMessageToIngameServer(rtsMessage.SenderSystemName, 1, "write", $"{rtsMessage.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ");
+
+ SaveSystem.CurrentUser = SaveSystem.Users.FirstOrDefault(x => x.Username == currentUserName);
+ }
+ }
+
+ [Command("connect")]
+ [RequiresArgument("sysname")]
+ [RequiresArgument("username")]
+ [RequiresArgument("password")]
+ public static bool Connect(Dictionary<string, object> args)
+ {
+ string sysname = args["sysname"].ToString();
+ string username = args["username"].ToString();
+ string password = args["password"].ToString();
+
+ bool connectionFinished = false;
+
+
+ new Thread(() =>
+ {
+ Thread.Sleep(10000);
+ if (connectionFinished == false)
+ {
+ Applications.Terminal.IsInRemoteSystem = false;
+ Applications.Terminal.RemoteSystemName = "";
+ Applications.Terminal.RemoteUser = "";
+ Applications.Terminal.RemotePass = "";
+ TerminalBackend.PrefixEnabled = true;
+ Console.WriteLine("[rts] Connection failed, target system did not respond.");
+ TerminalBackend.PrintPrompt();
+
+ }
+ }).Start();
+
+ ServerMessageReceived smr = null;
+ smr = (msg) =>
+ {
+ if (msg.Name == "msgtosys")
+ {
+ var m = JsonConvert.DeserializeObject<ServerMessage>(msg.Contents);
+ if (m.GUID.Split('|')[2] != ServerManager.thisGuid.ToString())
+ {
+ connectionFinished = true;
+ ServerManager.MessageReceived -= smr;
+ }
+ }
+ };
+ ServerManager.MessageReceived += smr;
+ ServerManager.SendMessageToIngameServer(sysname, 21, "cmd", JsonConvert.SerializeObject(new RTSMessage
+ {
+ SenderSystemName = SaveSystem.CurrentSave.SystemName,
+ Username = username,
+ Password = password,
+ Namespace = "trm",
+ Command = "clear"
+ }));
+ Applications.Terminal.IsInRemoteSystem = true;
+ Applications.Terminal.RemoteSystemName = sysname;
+ Applications.Terminal.RemoteUser = username;
+ Applications.Terminal.RemotePass = password;
+ TerminalBackend.PrefixEnabled = false;
+ return true;
+ }
+ }
+
+ [Server("Generic port 0", 0)]
+ public class InfoboxServer : Server
+ {
+ public void MessageReceived(ServerMessage msg)
+ {
+ Infobox.Show(msg.Name, msg.Contents);
+ }
+ }
+
+ [Server("Generic port 1", 1)]
+ public class ConsoleServer : Server
+ {
+ public void MessageReceived(ServerMessage msg)
+ {
+ switch (msg.Name)
+ {
+ case "write":
+ Console.Write(msg.Contents);
+ break;
+ case "writeline":
+ Console.WriteLine(msg.Contents);
+ break;
+ }
+ }
+ }
+
+ public class RTSMessage
+ {
+ public string SenderSystemName { get; set; }
+
+ public string Namespace { get; set; }
+ public string Command { get; set; }
+ public Dictionary<string, object> Arguments { get; set; }
+
+ public string Username { get; set; }
+ public string Password { get; set; }
+ }
+}
diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj
index 9675744..da8eafc 100644
--- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj
+++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj
@@ -363,6 +363,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="ScriptingTestFunctions.cs" />
+ <Compile Include="Servers\RemoteTerminalServer.cs" />
<Compile Include="ShiftnetSites\AppscapeMain.cs">
<SubType>UserControl</SubType>
</Compile>
diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs
index fc9567d..1643b23 100644
--- a/ShiftOS.WinForms/Tools/ControlManager.cs
+++ b/ShiftOS.WinForms/Tools/ControlManager.cs
@@ -144,10 +144,7 @@ namespace ShiftOS.WinForms.Tools
public static void SetupControl(Control ctrl)
{
- Desktop.InvokeOnWorkerThread(new Action(() =>
- {
- ctrl.SuspendLayout();
- }));
+
if (!(ctrl is MenuStrip) && !(ctrl is ToolStrip) && !(ctrl is StatusStrip) && !(ctrl is ContextMenuStrip))
{
string tag = "";
@@ -306,7 +303,6 @@ namespace ShiftOS.WinForms.Tools
{
MakeDoubleBuffered(ctrl);
- ctrl.ResumeLayout();
});
ControlSetup?.Invoke(ctrl);
}
@@ -330,17 +326,18 @@ namespace ShiftOS.WinForms.Tools
public static void SetupControls(Control frm, bool runInThread = true)
{
- SetupControl(frm);
frm.Click += (o, a) =>
{
Desktop.HideAppLauncher();
};
ThreadStart ts = () =>
{
- for (int i = 0; i < frm.Controls.Count; i++)
+ var ctrls = frm.Controls.ToList();
+ for (int i = 0; i < ctrls.Count(); i++)
{
- SetupControls(frm.Controls[i], false);
+ SetupControls(ctrls[i]);
}
+ SetupControl(frm);
};