From 251521835b60024dec292a759d738e2b81bf1417 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 9 Mar 2017 16:46:34 -0500 Subject: Console colors! --- ShiftOS.WinForms/Applications/Terminal.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 7bab213..65a8f0f 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -134,7 +134,7 @@ namespace ShiftOS.WinForms.Applications rtbterm.Text = ""; TerminalBackend.PrefixEnabled = true; TerminalBackend.InStory = false; - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + TerminalBackend.PrintPrompt(); if (Shiftorium.UpgradeInstalled("wm_free_placement")) { this.ParentForm.Width = 640; @@ -276,7 +276,7 @@ namespace ShiftOS.WinForms.Applications } if (TerminalBackend.PrefixEnabled) { - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + TerminalBackend.PrintPrompt(); } } } -- cgit v1.2.3 From a9b08eb21676a6c59b0c8bb6046b40bd42e078d5 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 9 Mar 2017 18:15:29 -0500 Subject: FULLY COMPLETE TERMINAL COLORS --- ShiftOS.WinForms/Applications/Shifter.cs | 24 ++++++++++++++++++++++++ ShiftOS.WinForms/Applications/Shiftnet.cs | 7 +++++-- ShiftOS.WinForms/Applications/Terminal.cs | 12 ++++++------ ShiftOS_TheReturn/Skinning.cs | 4 ++-- ShiftOS_TheReturn/TerminalBackend.cs | 3 ++- 5 files changed, 39 insertions(+), 11 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 4d29cf8..1adc75a 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -446,6 +446,30 @@ namespace ShiftOS.WinForms.Applications flbody.Controls.Add(color); color.Show(); } + else if(c.Field.FieldType.IsEnum == true) + { + var cBox = new ComboBox(); + cBox.Width = 150; + ControlManager.SetupControl(cBox); + + foreach(var itm in Enum.GetNames(c.Field.FieldType)) + { + cBox.Items.Add(itm); + } + + cBox.Text = c.Field.GetValue(LoadedSkin).ToString(); + + cBox.SelectedIndexChanged += (o, a) => + { + c.Field.SetValue(LoadedSkin, Enum.Parse(c.Field.FieldType, cBox.Text)); + }; + + labelHeight = cBox.Height; + + flbody.Controls.Add(cBox); + cBox.Show(); + flbody.SetFlowBreak(cBox, true); + } else if(c.Field.FieldType == typeof(int)) { if (c.Field.HasShifterEnumMask()) diff --git a/ShiftOS.WinForms/Applications/Shiftnet.cs b/ShiftOS.WinForms/Applications/Shiftnet.cs index 9540794..45f37d4 100644 --- a/ShiftOS.WinForms/Applications/Shiftnet.cs +++ b/ShiftOS.WinForms/Applications/Shiftnet.cs @@ -34,6 +34,7 @@ using System.Windows.Forms; using ShiftOS.Engine; using Newtonsoft.Json; using static ShiftOS.Engine.SkinEngine; +using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { [Launcher("Shiftnet", false, null, "Networking")] @@ -62,6 +63,8 @@ namespace ShiftOS.WinForms.Applications { } public string ConstructHtml(string markdown) { + var TerminalForeColor = ControlManager.ConvertColor(SkinEngine.LoadedSkin.TerminalForeColorCC); + var TerminalBackColor = ControlManager.ConvertColor(SkinEngine.LoadedSkin.TerminalBackColorCC); string html = $@" diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 65a8f0f..06a6e8d 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -43,6 +43,7 @@ using System.Collections; using static ShiftOS.Engine.SkinEngine; using ShiftOS.Engine; using ShiftOS.Objects; +using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { @@ -350,8 +351,8 @@ namespace ShiftOS.WinForms.Applications txt.Focus(); txt.Font = LoadedSkin.TerminalFont; - txt.ForeColor = LoadedSkin.TerminalForeColor; - txt.BackColor = LoadedSkin.TerminalBackColor; + txt.ForeColor = ControlManager.ConvertColor(LoadedSkin.TerminalForeColorCC); + txt.BackColor = ControlManager.ConvertColor(LoadedSkin.TerminalBackColorCC); } @@ -391,8 +392,7 @@ namespace ShiftOS.WinForms.Applications rtbterm.Text = AppearanceManager.LastTerminalText; rtbterm.Select(rtbterm.TextLength, 0); } - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); - + TerminalBackend.PrintPrompt(); } @@ -403,8 +403,8 @@ namespace ShiftOS.WinForms.Applications try { rtbterm.Font = LoadedSkin.TerminalFont; - rtbterm.ForeColor = LoadedSkin.TerminalForeColor; - rtbterm.BackColor = LoadedSkin.TerminalBackColor; + rtbterm.ForeColor = ControlManager.ConvertColor(LoadedSkin.TerminalForeColorCC); + rtbterm.BackColor = ControlManager.ConvertColor(LoadedSkin.TerminalBackColorCC); } catch { diff --git a/ShiftOS_TheReturn/Skinning.cs b/ShiftOS_TheReturn/Skinning.cs index 43e0b5d..800b107 100644 --- a/ShiftOS_TheReturn/Skinning.cs +++ b/ShiftOS_TheReturn/Skinning.cs @@ -865,12 +865,12 @@ namespace ShiftOS.Engine { [ShifterMeta("System")] [ShifterCategory("General")] [ShifterName("Terminal text color")] - public Color TerminalForeColor = DefaultForeground; + public ConsoleColor TerminalForeColorCC = ConsoleColor.White; [ShifterMeta("System")] [ShifterCategory("General")] [ShifterName("Terminal background color")] - public Color TerminalBackColor = DesktopBG; + public ConsoleColor TerminalBackColorCC = ConsoleColor.Black; [ShifterMeta("Desktop")] [ShifterCategory("Desktop Panel")] diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 841fd6a..5c08cfe 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -286,6 +286,7 @@ namespace ShiftOS.Engine public static void PrintPrompt() { + ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC; ConsoleEx.Italic = false; ConsoleEx.Underline = false; @@ -311,7 +312,7 @@ namespace ShiftOS.Engine Console.Write("$"); ConsoleEx.Italic = false; ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = ConsoleColor.White; + ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; Console.Write(" "); } -- cgit v1.2.3 From 6460ccee378e15408768337dcdc1bc77da07da53 Mon Sep 17 00:00:00 2001 From: pfg Date: Sun, 12 Mar 2017 09:29:17 -0700 Subject: Custom Command Syntax --- .../Applications/FormatEditor.Designer.cs | 59 ++-- ShiftOS.WinForms/Applications/FormatEditor.cs | 222 ++----------- ShiftOS.WinForms/Applications/Shifter.cs | 9 +- ShiftOS.WinForms/Applications/Terminal.cs | 282 ++++++---------- ShiftOS_TheReturn/CommandParser.cs | 366 +++++++++++++++++++++ ShiftOS_TheReturn/Commands.cs | 1 + ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 + ShiftOS_TheReturn/TerminalBackend.cs | 213 ++++++------ 8 files changed, 634 insertions(+), 519 deletions(-) create mode 100644 ShiftOS_TheReturn/CommandParser.cs (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs b/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs index 2f628f1..536ea62 100644 --- a/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs +++ b/ShiftOS.WinForms/Applications/FormatEditor.Designer.cs @@ -61,8 +61,9 @@ namespace ShiftOS.WinForms.Applications this.btnAddColor = new System.Windows.Forms.Button(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.btnTest = new System.Windows.Forms.Button(); - this.button1 = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); + this.btnSave = new System.Windows.Forms.Button(); + this.btnLoad = new System.Windows.Forms.Button(); + this.btnApply = new System.Windows.Forms.Button(); this.SuspendLayout(); // // panelEditor @@ -109,9 +110,9 @@ namespace ShiftOS.WinForms.Applications // this.btnAddCommand.Location = new System.Drawing.Point(4, 85); this.btnAddCommand.Name = "btnAddCommand"; - this.btnAddCommand.Size = new System.Drawing.Size(75, 23); + this.btnAddCommand.Size = new System.Drawing.Size(85, 23); this.btnAddCommand.TabIndex = 5; - this.btnAddCommand.Text = "+ Command"; + this.btnAddCommand.Text = "+ Namespace"; this.btnAddCommand.UseVisualStyleBackColor = true; this.btnAddCommand.Click += new System.EventHandler(this.btnAddCommand_Click); // @@ -154,30 +155,43 @@ namespace ShiftOS.WinForms.Applications this.btnTest.UseVisualStyleBackColor = true; this.btnTest.Click += new System.EventHandler(this.btnTest_Click); // - // button1 + // btnSave // - this.button1.Location = new System.Drawing.Point(7, 161); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(47, 23); - this.button1.TabIndex = 12; - this.button1.Text = "Apply"; - this.button1.UseVisualStyleBackColor = true; + this.btnSave.Location = new System.Drawing.Point(7, 161); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(47, 23); + this.btnSave.TabIndex = 13; + this.btnSave.Text = "Save"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); // - // button2 + // btnLoad // - this.button2.Location = new System.Drawing.Point(60, 161); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(47, 23); - this.button2.TabIndex = 13; - this.button2.Text = "Save"; - this.button2.UseVisualStyleBackColor = true; + this.btnLoad.Location = new System.Drawing.Point(60, 161); + this.btnLoad.Name = "btnLoad"; + this.btnLoad.Size = new System.Drawing.Size(47, 23); + this.btnLoad.TabIndex = 14; + this.btnLoad.Text = "Load"; + this.btnLoad.UseVisualStyleBackColor = true; + this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click); + // + // btnApply + // + this.btnApply.Location = new System.Drawing.Point(113, 161); + this.btnApply.Name = "btnApply"; + this.btnApply.Size = new System.Drawing.Size(47, 23); + this.btnApply.TabIndex = 15; + this.btnApply.Text = "Apply"; + this.btnApply.UseVisualStyleBackColor = true; + this.btnApply.Click += new System.EventHandler(this.btnApply_Click); // // FormatEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.button2); - this.Controls.Add(this.button1); + this.Controls.Add(this.btnApply); + this.Controls.Add(this.btnLoad); + this.Controls.Add(this.btnSave); this.Controls.Add(this.btnTest); this.Controls.Add(this.richTextBox1); this.Controls.Add(this.btnAddColor); @@ -204,7 +218,8 @@ namespace ShiftOS.WinForms.Applications private System.Windows.Forms.Button btnAddColor; private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.Button btnTest; - private System.Windows.Forms.Button button1; - private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.Button btnLoad; + private System.Windows.Forms.Button btnApply; } } diff --git a/ShiftOS.WinForms/Applications/FormatEditor.cs b/ShiftOS.WinForms/Applications/FormatEditor.cs index ef44b47..bf5e78c 100644 --- a/ShiftOS.WinForms/Applications/FormatEditor.cs +++ b/ShiftOS.WinForms/Applications/FormatEditor.cs @@ -42,9 +42,10 @@ namespace ShiftOS.WinForms.Applications { public partial class FormatEditor : UserControl, IShiftOSWindow { IList parts = new List(); + CommandParser parser = new CommandParser(); IList editorBoxes = new List(); - string commandMode = "command"; + string commandMode = "namespace"; int avcount = 0; public FormatEditor() { @@ -66,10 +67,15 @@ namespace ShiftOS.WinForms.Applications { } private void addPart(CommandFormat part) { - parts.Add(part); + parser.AddPart(part); + + addPart(part.Draw()); + } + + private void addPart(Control part) { Panel container = new Panel(); - Control drawnPart = part.Draw(); + Control drawnPart = part; container.Size = drawnPart.Size; container.Controls.Add(drawnPart); @@ -103,6 +109,11 @@ namespace ShiftOS.WinForms.Applications { private void btnAddCommand_Click(object sender, EventArgs e) { switch (commandMode) { + case "namespace": + addPart(new CommandFormatNamespace()); + commandMode = "command"; + btnAddCommand.Text = "+ Command"; + break; case "command": addPart(new CommandFormatCommand()); commandMode = "argument"; @@ -129,215 +140,46 @@ namespace ShiftOS.WinForms.Applications { } private void richTextBox1_TextChanged(object sender, EventArgs e) { - string command = ""; - Dictionary arguments = new Dictionary(); - - string text = richTextBox1.Text; - int position = 0; - - int commandPos; - int firstValuePos = -1; - int lastValuePos = -1; - - for(int ii = 0; ii < parts.Count; ii++) { - CommandFormat part = parts[ii]; - if (part is CommandFormatMarker) { - if (part is CommandFormatCommand) { - commandPos = ii; - } else if (part is CommandFormatValue) { - if (firstValuePos > -1) - lastValuePos = ii; - else - firstValuePos = ii; - } - } - } - - int i = 0; - string currentArgument = ""; - int help = -1; - - while (position < text.Length) { - - if (i >= parts.Count) { - position = text.Length; - command = "+FALSE+"; - i = 0; - } - - CommandFormat part = parts[i]; - string res = part.CheckValidity(text.Substring(position)); - - // ok so: - - // example - // COMMAND text[ --] ARGUMENT VALUE text[ --] ARGUMENT VALUE - // COMMAND text[{] ARGUMENT text[=] VALUE text[, ] ARGUMENT text[=] VALUE text[}] - - if (part is CommandFormatMarker) { - if (part is CommandFormatCommand) { - command = res; - help = -1; - } else if (part is CommandFormatArgument) { - currentArgument = res; - help = -1; - } else if (part is CommandFormatValue) { - arguments[currentArgument] = res; - - if(i == firstValuePos) - help = lastValuePos; - if (i == lastValuePos) - help = firstValuePos; - } - } + var result = parser.ParseCommand(richTextBox1.Text); - if(res == "+FALSE+") { - if(help > -1) { - i = help; - if(i >= parts.Count) { - position = text.Length; - command = "+FALSE+"; - } - }else { - position = text.Length; - command = "+FALSE+"; - } - help = -1; - }else { - position += res.Length; - } - - i++; - } - - if (command == "+FALSE+") { + if (result.Equals(default(KeyValuePair, Dictionary>))) { lblExampleCommand.Text = "Syntax Error"; } else { string argvs = "{"; - foreach (KeyValuePair entry in arguments) { - argvs += entry.Key + "=" + entry.Value + ", "; + foreach (KeyValuePair entry in result.Value) { + argvs += entry.Key + "=\"" + entry.Value + "\", "; } argvs += "}"; - lblExampleCommand.Text = command + argvs; + lblExampleCommand.Text = result.Key + argvs; } } private void btnTest_Click(object sender, EventArgs e) { } - } - - interface CommandFormat { - string CheckValidity(string check); - Control Draw(); - } - class CommandFormatText : CommandFormat { - protected string str; - TextBox textBox; - - public CommandFormatText() { - } - - public virtual string CheckValidity(string check) { - return check.StartsWith(str) ? str : "+FALSE+"; - } - - public Control Draw() { - textBox = new TextBox(); - textBox.TextChanged += new EventHandler(TextChanged); - textBox.Location = new Point(0,0); - - return textBox; - } - - void TextChanged(object sender, EventArgs e) { - str = textBox.Text; - } - } - - class CommandFormatOptionalText : CommandFormatText { - public override string CheckValidity(string check) { - return check.StartsWith(str) ? str : ""; - } - } - - class CommandFormatMarker : CommandFormat { - protected string str; - Button button; - - public CommandFormatMarker() { - } - - public virtual string CheckValidity(string check) { - string res = string.Empty; - string alphanumeric = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890"; // not using regex for performance reasons - - foreach (char c in check) { - if (alphanumeric.IndexOf(c) > -1) { - res += c; - } else { - break; - } - } - - return res; - } - - public virtual Control Draw() { - button = new Button(); - button.Location = new Point(0, 0); - button.Text = "Marker"; - - return button; - } - } - class CommandFormatCommand : CommandFormatMarker { - public override Control Draw() { - Button draw = (Button)base.Draw(); - draw.Text = "Command"; - return draw; - } - } + private void btnSave_Click(object sender, EventArgs e) { + CurrentCommandParser.parser = parser; - class CommandFormatArgument : CommandFormatMarker { - public override Control Draw() { - Button draw = (Button)base.Draw(); - draw.Text = "Argument"; - return draw; + FileSkimmerBackend.GetFile(new string[] { ".cf" }, FileOpenerStyle.Save, new Action((result) => { + Objects.ShiftFS.Utils.WriteAllText(result, parser.Save()); + })); } - } - class CommandFormatValue : CommandFormatMarker { - public override string CheckValidity(string cd) { - string res = string.Empty; - var check = ""; - - if (cd.StartsWith("\"")) - check = cd.Substring(1); - bool done = false; - - foreach (char c in check) { - Console.WriteLine(check); - if (c != '"') { - res += c; - } else { - done = true; - res += "\""; - break; + private void btnLoad_Click(object sender, EventArgs e) { + FileSkimmerBackend.GetFile(new string[] { ".cf" }, FileOpenerStyle.Open, new Action((result) => { + parser = CommandParser.Load(Objects.ShiftFS.Utils.ReadAllText(result)); + foreach(CommandFormat part in parser.parts) { + addPart(part.Draw()); } - } - - return done ? "\""+res : "+FALSE+"; + })); } - public override Control Draw() { - Button draw = (Button)base.Draw(); - draw.Text = "\"Value\""; - return draw; + private void btnApply_Click(object sender, EventArgs e) { + CurrentCommandParser.parser = parser; } } } diff --git a/ShiftOS.WinForms/Applications/Shifter.cs b/ShiftOS.WinForms/Applications/Shifter.cs index 4d29cf8..9a9b4ad 100644 --- a/ShiftOS.WinForms/Applications/Shifter.cs +++ b/ShiftOS.WinForms/Applications/Shifter.cs @@ -26,20 +26,13 @@ using Newtonsoft.Json; using ShiftOS.Objects.ShiftFS; using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Engine; using ShiftOS.WinForms.Tools; -namespace ShiftOS.WinForms.Applications -{ +namespace ShiftOS.WinForms.Applications { [Launcher("Shifter", true, "al_shifter", "Customization")] [RequiresUpgrade("shifter")] [WinOpen("shifter")] diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 7bab213..9bd9f3c 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -44,13 +44,11 @@ using static ShiftOS.Engine.SkinEngine; using ShiftOS.Engine; using ShiftOS.Objects; -namespace ShiftOS.WinForms.Applications -{ +namespace ShiftOS.WinForms.Applications { [Launcher("Terminal", false, null, "Utilities")] [WinOpen("terminal")] [DefaultIcon("iconTerminal")] - public partial class Terminal : UserControl, IShiftOSWindow - { + public partial class Terminal : UserControl, IShiftOSWindow { public static Stack ConsoleStack = new Stack(); public static System.Windows.Forms.Timer ti = new System.Windows.Forms.Timer(); @@ -62,81 +60,63 @@ namespace ShiftOS.WinForms.Applications public static string RemoteGuid = ""; [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static bool PrefixEnabled - { - get - { + public static bool PrefixEnabled { + get { return TerminalBackend.PrefixEnabled; } - set - { + set { TerminalBackend.PrefixEnabled = value; } } [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static bool InStory - { - get - { + public static bool InStory { + get { return TerminalBackend.InStory; } - set - { + set { TerminalBackend.InStory = value; } } [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static string LastCommand - { - get - { + public static string LastCommand { + get { return TerminalBackend.LastCommand; } - set - { + set { TerminalBackend.LastCommand = value; } } - public int TutorialProgress - { - get - { + public int TutorialProgress { + get { throw new NotImplementedException(); } - set - { + set { throw new NotImplementedException(); } } [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static void InvokeCommand(string text) - { - + public static void InvokeCommand(string text) { + TerminalBackend.InvokeCommand(text); } - public Terminal() - { + public Terminal() { InitializeComponent(); - SaveSystem.GameReady += () => - { - try - { - this.Invoke(new Action(() => - { + SaveSystem.GameReady += () => { + try { + this.Invoke(new Action(() => { ResetAllKeywords(); rtbterm.Text = ""; TerminalBackend.PrefixEnabled = true; TerminalBackend.InStory = false; Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); - if (Shiftorium.UpgradeInstalled("wm_free_placement")) - { + if (Shiftorium.UpgradeInstalled("wm_free_placement")) { this.ParentForm.Width = 640; this.ParentForm.Height = 480; this.ParentForm.Left = (Screen.PrimaryScreen.Bounds.Width - 640) / 2; @@ -144,8 +124,7 @@ namespace ShiftOS.WinForms.Applications } })); - } - catch { } + } catch { } }; @@ -153,32 +132,21 @@ namespace ShiftOS.WinForms.Applications } - public void FocusOnTerminal() - { + public void FocusOnTerminal() { rtbterm.Focus(); } - public static string GetTime() - { + public static string GetTime() { var time = DateTime.Now; - if (ShiftoriumFrontend.UpgradeInstalled("full_precision_time")) - { + if (ShiftoriumFrontend.UpgradeInstalled("full_precision_time")) { return DateTime.Now.ToString("h:mm:ss tt"); - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock_am_and_pm")) - { + } else if (ShiftoriumFrontend.UpgradeInstalled("clock_am_and_pm")) { return time.TimeOfDay.TotalHours > 12 ? $"{time.Hour - 12} PM" : $"{time.Hour} AM"; - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock_hours")) - { + } else if (ShiftoriumFrontend.UpgradeInstalled("clock_hours")) { return ((int)time.TimeOfDay.TotalHours).ToString(); - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock_minutes")) - { + } else if (ShiftoriumFrontend.UpgradeInstalled("clock_minutes")) { return ((int)time.TimeOfDay.TotalMinutes).ToString(); - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock")) - { + } else if (ShiftoriumFrontend.UpgradeInstalled("clock")) { return ((int)time.TimeOfDay.TotalSeconds).ToString(); } @@ -188,8 +156,7 @@ namespace ShiftOS.WinForms.Applications public static event TextSentEventHandler TextSent; - public void ResetAllKeywords() - { + public void ResetAllKeywords() { string primary = SaveSystem.CurrentSave.Username + " "; string secondary = "shiftos "; @@ -198,27 +165,18 @@ namespace ShiftOS.WinForms.Applications var types = asm.GetTypes(); - foreach (var type in types) - { - foreach (var a in type.GetCustomAttributes(false)) - { - if (ShiftoriumFrontend.UpgradeAttributesUnlocked(type)) - { - if (a is Namespace) - { + foreach (var type in types) { + foreach (var a in type.GetCustomAttributes(false)) { + if (ShiftoriumFrontend.UpgradeAttributesUnlocked(type)) { + if (a is Namespace) { var ns = a as Namespace; - if (!primary.Contains(ns.name)) - { + if (!primary.Contains(ns.name)) { primary += ns.name + " "; } - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) - { - if (ShiftoriumFrontend.UpgradeAttributesUnlocked(method)) - { - foreach (var ma in method.GetCustomAttributes(false)) - { - if (ma is Command) - { + foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { + if (ShiftoriumFrontend.UpgradeAttributesUnlocked(method)) { + foreach (var ma in method.GetCustomAttributes(false)) { + if (ma is Command) { var cmd = ma as Command; if (!secondary.Contains(cmd.name)) secondary += cmd.name + " "; @@ -234,19 +192,14 @@ namespace ShiftOS.WinForms.Applications } - public static void MakeWidget(Controls.TerminalBox txt) - { + public static void MakeWidget(Controls.TerminalBox txt) { AppearanceManager.StartConsoleOut(); - txt.GotFocus += (o, a) => - { + txt.GotFocus += (o, a) => { AppearanceManager.ConsoleOut = txt; }; - txt.KeyDown += (o, a) => - { - if (a.KeyCode == Keys.Enter) - { - try - { + txt.KeyDown += (o, a) => { + if (a.KeyCode == Keys.Enter) { + try { a.SuppressKeyPress = true; Console.WriteLine(""); var text = txt.Lines.ToArray(); @@ -254,60 +207,55 @@ namespace ShiftOS.WinForms.Applications var text3 = ""; var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); - if (IsInRemoteSystem == true) - { - ServerManager.SendMessage("trm_invcmd", JsonConvert.SerializeObject(new - { + if (IsInRemoteSystem == true) { + ServerManager.SendMessage("trm_invcmd", JsonConvert.SerializeObject(new { guid = RemoteGuid, command = text4 })); - } - else - { - if (TerminalBackend.PrefixEnabled) - { + } else { + if (TerminalBackend.PrefixEnabled) { text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); } TerminalBackend.LastCommand = text3; TextSent?.Invoke(text4); - if (TerminalBackend.InStory == false) - { - TerminalBackend.InvokeCommand(text3); + if (TerminalBackend.InStory == false) { + if(text3 == "stop theme") { + CurrentCommandParser.parser = null; + }else { + if(CurrentCommandParser.parser == null) { + TerminalBackend.InvokeCommand(text3); + } else { + var result = CurrentCommandParser.parser.ParseCommand(text3); + + if (result.Equals(default(KeyValuePair, Dictionary>))) { + Console.WriteLine("Syntax Error: Syntax Error"); + } else { + TerminalBackend.InvokeCommand(result.Key.Key, result.Key.Value, result.Value); + } + } + } } - if (TerminalBackend.PrefixEnabled) - { + if (TerminalBackend.PrefixEnabled) { Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); } } + } catch { } - catch - { - } - } - else if (a.KeyCode == Keys.Back) - { - try - { + } else if (a.KeyCode == Keys.Back) { + try { var tostring3 = txt.Lines[txt.Lines.Length - 1]; var tostringlen = tostring3.Length + 1; var workaround = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; var derp = workaround.Length + 1; - if (tostringlen != derp) - { + if (tostringlen != derp) { AppearanceManager.CurrentPosition--; - } - else - { + } else { a.SuppressKeyPress = true; } - } - catch - { + } catch { Debug.WriteLine("Drunky alert in terminal."); } - } - else if (a.KeyCode == Keys.Left) - { + } else if (a.KeyCode == Keys.Left) { var getstring = txt.Lines[txt.Lines.Length - 1]; var stringlen = getstring.Length + 1; var header = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; @@ -316,28 +264,19 @@ namespace ShiftOS.WinForms.Applications var remstrlen = txt.TextLength - stringlen; var finalnum = selstart - remstrlen; - if (finalnum != headerlen) - { + if (finalnum != headerlen) { AppearanceManager.CurrentPosition--; - } - else - { + } else { a.SuppressKeyPress = true; } - } - //( ͡° ͜ʖ ͡° ) You found the lennyface without looking at the commit message. Message Michael in the #shiftos channel on Discord saying "ladouceur" somewhere in your message if you see this. - else if (a.KeyCode == Keys.Up) - { + } else if (a.KeyCode == Keys.Up) { var tostring3 = txt.Lines[txt.Lines.Length - 1]; if (tostring3 == $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ") Console.Write(TerminalBackend.LastCommand); a.SuppressKeyPress = true; - } - else - { - if (TerminalBackend.InStory) - { + } else { + if (TerminalBackend.InStory) { a.SuppressKeyPress = true; } AppearanceManager.CurrentPosition++; @@ -346,7 +285,7 @@ namespace ShiftOS.WinForms.Applications }; AppearanceManager.ConsoleOut = txt; - + txt.Focus(); txt.Font = LoadedSkin.TerminalFont; @@ -355,17 +294,12 @@ namespace ShiftOS.WinForms.Applications } - private void Terminal_Load(object sender, EventArgs e) - { - ServerManager.MessageReceived += (msg) => - { - if(msg.Name == "trm_handshake_guid") - { + private void Terminal_Load(object sender, EventArgs e) { + ServerManager.MessageReceived += (msg) => { + if (msg.Name == "trm_handshake_guid") { IsInRemoteSystem = true; RemoteGuid = msg.GUID; - } - else if(msg.Name == "trm_handshake_stop") - { + } else if (msg.Name == "trm_handshake_stop") { IsInRemoteSystem = false; RemoteGuid = ""; } @@ -373,21 +307,17 @@ namespace ShiftOS.WinForms.Applications } - private void Terminal_FormClosing(object sender, FormClosingEventArgs e) - { + private void Terminal_FormClosing(object sender, FormClosingEventArgs e) { ti.Stop(); IsInRemoteSystem = false; RemoteGuid = ""; } - public void OnLoad() - { + public void OnLoad() { MakeWidget(rtbterm); - if (SaveSystem.CurrentSave != null) - { - if (!ShiftoriumFrontend.UpgradeInstalled("window_manager")) - { + if (SaveSystem.CurrentSave != null) { + if (!ShiftoriumFrontend.UpgradeInstalled("window_manager")) { rtbterm.Text = AppearanceManager.LastTerminalText; rtbterm.Select(rtbterm.TextLength, 0); } @@ -398,42 +328,30 @@ namespace ShiftOS.WinForms.Applications } - public void OnSkinLoad() - { - try - { + public void OnSkinLoad() { + try { rtbterm.Font = LoadedSkin.TerminalFont; rtbterm.ForeColor = LoadedSkin.TerminalForeColor; rtbterm.BackColor = LoadedSkin.TerminalBackColor; - } - catch - { + } catch { } } - public bool OnUnload() - { - if (SaveSystem.ShuttingDown == false) - { - if (!ShiftoriumFrontend.UpgradeInstalled("desktop")) - { - if (AppearanceManager.OpenForms.Count <= 1) - { + public bool OnUnload() { + if (SaveSystem.ShuttingDown == false) { + if (!ShiftoriumFrontend.UpgradeInstalled("desktop")) { + if (AppearanceManager.OpenForms.Count <= 1) { Console.WriteLine(""); Console.WriteLine("{WIN_CANTCLOSETERMINAL}"); - try - { + try { Console.WriteLine(""); - if (TerminalBackend.PrefixEnabled) - { + if (TerminalBackend.PrefixEnabled) { Console.Write($"{SaveSystem.CurrentSave.Username}@shiftos:~$ "); } - } - catch (Exception ex) - { + } catch (Exception ex) { Console.WriteLine(ex); } return false; @@ -443,15 +361,13 @@ namespace ShiftOS.WinForms.Applications return true; } - public void OnUpgrade() - { + public void OnUpgrade() { } - private void rtbterm_TextChanged(object sender, EventArgs e) - { + private void rtbterm_TextChanged(object sender, EventArgs e) { } - + } } //lol you found this comment i made so i chould push a change to make a point. \ No newline at end of file diff --git a/ShiftOS_TheReturn/CommandParser.cs b/ShiftOS_TheReturn/CommandParser.cs new file mode 100644 index 0000000..182ff53 --- /dev/null +++ b/ShiftOS_TheReturn/CommandParser.cs @@ -0,0 +1,366 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShiftOS.Engine { + public static class CurrentCommandParser { + public static CommandParser parser; + } + + public class CommandParser { + public IList parts = new List(); + + public void AddPart(CommandFormat part) { + parts.Add(part); + } + + public void ImportPart(IList parts) { + this.parts = parts; + } + + public string Save() { + JArray data = new JArray(); + foreach(CommandFormat part in parts) { + CFValue val = new CFValue(part); + JObject obj = new JObject(); + obj["type"] = new JValue(val.type); + obj["text"] = new JValue(val.text); + data.Add(obj); + } + + return data.ToString(); + } + + public static CommandParser Load(string val) { + CommandParser parser = new CommandParser(); + JArray data = JArray.Parse(val); + + IList values = data.Select(obj => new CFValue ( + (string)obj["type"], + (string)obj["text"] + )).ToList(); + + foreach(CFValue value in values) { + parser.AddPart(value.GetCommandFormat()); + } + + return parser; + } + + public KeyValuePair, Dictionary> ParseCommand(string cdd) { + string command = ""; + string ns = ""; + Dictionary arguments = new Dictionary(); + + string text = cdd; + int position = 0; + + int commandPos; + int firstValuePos = -1; + int lastValuePos = -1; + + string syntaxError = ""; + + for (int ii = 0; ii < parts.Count; ii++) { + CommandFormat part = parts[ii]; + if (part is CommandFormatMarker) { + if (part is CommandFormatCommand) { + commandPos = ii; + } else if (part is CommandFormatValue) { + if (firstValuePos > -1) + lastValuePos = ii; + else + firstValuePos = ii; + } + } + } + + int i = 0; + string currentArgument = ""; + int help = -1; + + while (position < text.Length) { + + if (i >= parts.Count) { + position = text.Length; + command = "+FALSE+"; + i = 0; + } + + CommandFormat part = parts[i]; + string res = part.CheckValidity(text.Substring(position)); + + // ok so: + + // example + // COMMAND text[ --] ARGUMENT VALUE text[ --] ARGUMENT VALUE + // COMMAND text[{] ARGUMENT text[=] VALUE text[, ] ARGUMENT text[=] VALUE text[}] + + if (part is CommandFormatMarker) { + if (part is CommandFormatNamespace) { + ns = res; + help = -1; + }else if (part is CommandFormatCommand) { + command = res; + help = -1; + } else if (part is CommandFormatArgument) { + currentArgument = res; + help = -1; + } else if (part is CommandFormatValue) { + arguments[currentArgument] = string.Join("", res.Split('"')); + + if (i == firstValuePos) + help = lastValuePos; + if (i == lastValuePos) + help = firstValuePos; + } + } + + if (res == "+FALSE+") { + if (help > -1) { + i = help; + if (i >= parts.Count) { + position = text.Length; + command = "+FALSE+"; + } + } else { + position = text.Length; + syntaxError = "Syntax Error"; + command = "+FALSE+"; + } + help = -1; + } else { + position += res.Length; + } + + i++; + } + + if (command == "+FALSE+") { + //lblExampleCommand.Text = "Syntax Error"; + return new KeyValuePair, Dictionary>(); + } else { + /*string argvs = "{"; + + foreach (KeyValuePair entry in arguments) { + argvs += entry.Key + "=" + entry.Value + ", "; + } + + argvs += "}"; + + lblExampleCommand.Text = command + argvs;*/ + return new KeyValuePair, Dictionary> (new KeyValuePair(ns, command), arguments); + } + } + } + + public class CFValue { + public string type { get; set; } + public string text { get; set; } + + public CFValue(string type, string text) { + this.type = type; + this.text = text; + } + + public CFValue(CommandFormat format) { + type = ""; + text = ""; + if(format is CommandFormatText) { + text = ((CommandFormatText) format).str; + if(format is CommandFormatOptionalText) { + type = "optionalText"; + }else if (format is CommandFormatRegex) { + type = "regexText"; + }else { + type = "text"; + } + }else if (format is CommandFormatMarker) { + if (format is CommandFormatNamespace) { + type = "namespace"; + } else if (format is CommandFormatCommand) { + type = "command"; + } else if (format is CommandFormatArgument) { + type = "argument"; + } else if (format is CommandFormatValue) { + type = "value"; + } + } + } + + public CommandFormat GetCommandFormat() { // TODO update with better code + switch (type) { + case "text": + return new CommandFormatText(text); + case "optionalText": + return new CommandFormatOptionalText(text); + case "regexText": + return new CommandFormatRegex(text); + case "namespace": + return new CommandFormatNamespace(); + case "command": + return new CommandFormatCommand(); + case "argument": + return new CommandFormatArgument(); + case "value": + return new CommandFormatValue(); + case "color": + throw new NotImplementedException(); // fix this (make it not a notimplementedexception) + } + return new CommandFormatMarker(); + } + } + + + public interface CommandFormat { + string CheckValidity(string check); + Control Draw(); + } + public class CommandFormatText : CommandFormat { + public string str = ""; + TextBox textBox; + + public CommandFormatText() { + + } + + public CommandFormatText(string str) { + this.str = str; + } + + public virtual string CheckValidity(string check) { + return check.StartsWith(str) ? str : "+FALSE+"; + } + + public Control Draw() { + textBox = new TextBox(); + textBox.TextChanged += new EventHandler(TextChanged); + textBox.Location = new Point(0, 0); + textBox.Text = str; + + return textBox; + } + + void TextChanged(object sender, EventArgs e) { + str = textBox.Text; + } + } + + public class CommandFormatOptionalText : CommandFormatText { + public CommandFormatOptionalText() : base() { + } + public CommandFormatOptionalText(string str) : base(str) { + } + + public override string CheckValidity(string check) { + return check.StartsWith(str) ? str : ""; + } + } + + public class CommandFormatRegex : CommandFormatText { + public CommandFormatRegex() : base() { + } + public CommandFormatRegex(string str) : base(str) { + } + + public override string CheckValidity(string check) { + Match match = (new Regex("^" + str)).Match(check); + return match.Success ? match.Value : "+FALSE+"; + } + } + + public class CommandFormatMarker : CommandFormat { + protected string str; + Button button; + + public CommandFormatMarker() { + } + + public virtual string CheckValidity(string check) { + string res = string.Empty; + string alphanumeric = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; // not using regex for performance reasons + + foreach (char c in check) { + if (alphanumeric.IndexOf(c) > -1) { + res += c; + } else { + break; + } + } + + return res; + } + + public virtual Control Draw() { + button = new Button(); + button.Location = new Point(0, 0); + button.Text = "Marker"; + + return button; + } + } + + public class CommandFormatCommand : CommandFormatMarker { + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "Command"; + return draw; + } + } + + public class CommandFormatNamespace : CommandFormatMarker { + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "Namespace"; + return draw; + } + } + + public class CommandFormatArgument : CommandFormatMarker { + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "Argument"; + return draw; + } + } + + public class CommandFormatValue : CommandFormatMarker { + public override string CheckValidity(string cd) { + string res = string.Empty; + var check = ""; + bool done = false; + + if (cd.StartsWith("\"")) { + check = cd.Substring(1); + + foreach (char c in check) { + if (c != '"') { + res += c; + } else { + done = true; + res = "\"" + res + "\""; + break; + } + } + } else{ + res = base.CheckValidity(cd); + done = true; + } + return done ? res : "+FALSE+"; + } + + public override Control Draw() { + Button draw = (Button)base.Draw(); + draw.Text = "\"Value\""; + return draw; + } + } +} diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 0ea00e5..779c616 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -305,6 +305,7 @@ namespace ShiftOS.Engine [RequiresArgument("type")] public static bool MultArg(Dictionary args) { + Console.WriteLine("Success! "+args.ToString()); return true; } diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 20ca879..5521f49 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -97,6 +97,7 @@ + diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 8be54d0..fd2524f 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -32,26 +32,21 @@ using System.Threading.Tasks; using Newtonsoft.Json; using static ShiftOS.Engine.SaveSystem; -namespace ShiftOS.Engine -{ - public static class TerminalBackend - { +namespace ShiftOS.Engine { + public static class TerminalBackend { public static event Action CommandProcessed; public static bool Elevated { get; set; } - public static Dictionary GetArgs(ref string text) - { + public static Dictionary GetArgs(ref string text) { bool shouldParse = false; int argStart = 0; - if (text.Contains("{")) - { + if (text.Contains("{")) { shouldParse = true; argStart = text.IndexOf('{'); } - if (shouldParse == false) - { + if (shouldParse == false) { string replacement = Regex.Replace(text, @"\t|\n|\r", ""); text = replacement + "{}"; shouldParse = true; @@ -61,15 +56,47 @@ namespace ShiftOS.Engine string args = text.Substring(argStart, text.Length - argStart); text = text.Remove(argStart, text.Length - argStart).Replace(" ", ""); - return JsonConvert.DeserializeObject>(args); + return JsonConvert.DeserializeObject>(args); } public static string LastCommand = ""; - public static void InvokeCommand(string text, bool isRemote = false) - { - try - { + public static void InvokeCommand(string ns, string command, Dictionary arguments, bool isRemote = false) { + try { + if (string.IsNullOrWhiteSpace(ns)) + return; + + + bool commandWasClient = RunClient(ns, command, arguments, isRemote); + + if (!commandWasClient && !string.IsNullOrWhiteSpace(ns)) { + PrefixEnabled = false; + + ServerManager.SendMessage("script", $@"{{ + user: ""{ns}"", + script: ""{command}"", + args: ""{GetSentArgs(arguments)}"" +}}"); + } + + CommandProcessed?.Invoke(ns + "." + command, JsonConvert.SerializeObject(arguments)); + } catch (Exception ex) { + Console.WriteLine($"Command parse error: {ex.Message}"); // This shouldn't ever be called now + PrefixEnabled = true; + + } + } + + public static string GetSentArgs(Dictionary argss) { + Dictionary args = new Dictionary(); + foreach (KeyValuePair arg in argss) { + args[arg.Key] = arg.Value; + } + return JsonConvert.SerializeObject(args); + } + + public static void InvokeCommand(string text, bool isRemote = false) { + try { if (string.IsNullOrWhiteSpace(text)) return; @@ -77,19 +104,17 @@ namespace ShiftOS.Engine bool commandWasClient = RunClient(text, args, isRemote); - if (!commandWasClient && !string.IsNullOrWhiteSpace(text)) - { + if (!commandWasClient) { PrefixEnabled = false; + ServerManager.SendMessage("script", $@"{{ user: ""{text.Split('.')[0]}"", script: ""{text.Split('.')[1]}"", - args: ""{JsonConvert.SerializeObject(args)}"" + args: ""{GetSentArgs(args)}"" }}"); } - CommandProcessed?.Invoke(text, JsonConvert.SerializeObject(args)); - } - catch (Exception ex) - { + CommandProcessed?.Invoke(text, GetSentArgs(args)); + } catch (Exception ex) { Console.WriteLine($"Command parse error: {ex.Message}"); PrefixEnabled = true; @@ -104,18 +129,15 @@ namespace ShiftOS.Engine public static event EmptyEventHandler TerminalRequested; - internal static void OpenTerminal() - { + internal static void OpenTerminal() { TerminalRequested?.Invoke(); } - public static bool CanRunRemotely(MethodInfo mth, bool isRemote) - { + public static bool CanRunRemotely(MethodInfo mth, bool isRemote) { if (!isRemote) return true; - foreach(var attr in mth.GetCustomAttributes(false)) - { + foreach (var attr in mth.GetCustomAttributes(false)) { if (attr is RemoteLockAttribute) return false; } @@ -123,60 +145,45 @@ namespace ShiftOS.Engine return true; } - public static bool RunClient(string text, Dictionary args, bool isRemote = false) - { + public static bool RunClient(string ns, string cmd, Dictionary args, bool isRemote = false) { + return RunClient(ns + "." + cmd, args, isRemote); + } + + public static bool RunClient(string text, Dictionary args, bool isRemote = false) { latestCommmand = text; - foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - try - { + foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) { + try { var asm = Assembly.LoadFile(asmExec); var types = asm.GetTypes(); - foreach (var type in types) - { - if (Shiftorium.UpgradeAttributesUnlocked(type)) - { - if (KernelWatchdog.IsSafe(type)) - { - foreach (var a in type.GetCustomAttributes(false)) - { - if (a is Namespace) - { + foreach (var type in types) { + if (Shiftorium.UpgradeAttributesUnlocked(type)) { + if (KernelWatchdog.IsSafe(type)) { + foreach (var a in type.GetCustomAttributes(false)) { + if (a is Namespace) { var ns = a as Namespace; - if (text.Split('.')[0] == ns.name) - { - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) - { - if (Shiftorium.UpgradeAttributesUnlocked(method)) - { - if (KernelWatchdog.IsSafe(method)) - { - if (CanRunRemotely(method, isRemote)) - { - foreach (var ma in method.GetCustomAttributes(false)) - { - if (ma is Command) - { + if (text.Split('.')[0] == ns.name) { + foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { + if (Shiftorium.UpgradeAttributesUnlocked(method)) { + if (KernelWatchdog.IsSafe(method)) { + if (CanRunRemotely(method, isRemote)) { + foreach (var ma in method.GetCustomAttributes(false)) { + if (ma is Command) { var cmd = ma as Command; - if (text.Split('.')[1] == cmd.name) - { + if (text.Split('.')[1] == cmd.name) { var attr = method.GetCustomAttribute(); - if (attr != null) - { + if (attr != null) { string newcommand = attr.newcommand; - if (attr.warn) - { + if (attr.warn) { Console.WriteLine(Localization.Parse((newcommand == "" ? "{ERROR}" : "{WARN}") + attr.reason, new Dictionary() { {"%newcommand", newcommand} })); } - if (newcommand != "") - { + if (newcommand != "") { // redo the entire process running newcommand return RunClient(newcommand, args); @@ -188,13 +195,10 @@ namespace ShiftOS.Engine bool error = false; bool providedusage = false; - foreach (RequiresArgument argument in requiresArgs) - { - if (!args.ContainsKey(argument.argument)) - { + foreach (RequiresArgument argument in requiresArgs) { + if (!args.ContainsKey(argument.argument)) { - if (!providedusage) - { + if (!providedusage) { string usageparse = "{COMMAND_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_USAGE}"; if (usageparse == Localization.Parse(usageparse)) usageparse = ""; @@ -209,14 +213,11 @@ namespace ShiftOS.Engine providedusage = true; } - if (Shiftorium.UpgradeInstalled("help_usage")) - { + if (Shiftorium.UpgradeInstalled("help_usage")) { Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED}", new Dictionary() { {"%argument", argument.argument} })); - } - else - { + } else { Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED_NO_USAGE}")); } @@ -224,89 +225,69 @@ namespace ShiftOS.Engine } } - if (error) - { + if (error) { throw new Exception("{ERROR_COMMAND_WRONG}"); } - try - { + try { return (bool)method.Invoke(null, new[] { args }); - } - catch (TargetInvocationException e) - { + } catch (TargetInvocationException e) { Console.WriteLine(Localization.Parse("{ERROR_EXCEPTION_THROWN_IN_METHOD}")); Console.WriteLine(e.InnerException.Message); Console.WriteLine(e.InnerException.StackTrace); return true; - } - catch - { + } catch { return (bool)method.Invoke(null, new object[] { }); } } } } - } - else - { + } else { Console.WriteLine(text + " cannot be ran in a remote session"); return true; } } - + } } } } } } - + } } - } - catch { } + } catch { } } return false; } - - static TerminalBackend() - { - ServerMessageReceived onMessageReceived = (msg) => - { - if (msg.Name == "trm_invokecommand") - { + + static TerminalBackend() { + ServerMessageReceived onMessageReceived = (msg) => { + if (msg.Name == "trm_invokecommand") { string text3 = ""; string text4 = msg.Contents; - if (TerminalBackend.PrefixEnabled) - { + if (TerminalBackend.PrefixEnabled) { text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); } IsForwardingConsoleWrites = true; - if (TerminalBackend.InStory == false) - { + if (TerminalBackend.InStory == false) { TerminalBackend.InvokeCommand(text3, true); } - if (TerminalBackend.PrefixEnabled) - { + if (TerminalBackend.PrefixEnabled) { Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); } IsForwardingConsoleWrites = false; - } - else if (msg.Name == "pleasewrite") - { + } else if (msg.Name == "pleasewrite") { Console.Write(msg.Contents); - } - else if(msg.Name == "handshake_from") - { + } else if (msg.Name == "handshake_from") { var a = JsonConvert.DeserializeObject>(msg.Contents); string uName = a["username"] as string; string pass = a["password"] as string; string sys = a["sysname"] as string; string guid = msg.GUID; - if(SaveSystem.CurrentSave.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys) - { + if (SaveSystem.CurrentSave.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys) { ForwardGUID = guid; ServerManager.SendMessage("trm_handshake_accept", $@"{{ guid: ""{ServerManager.thisGuid}"", @@ -326,6 +307,6 @@ namespace ShiftOS.Engine public static bool IsForwardingConsoleWrites { get; internal set; } public static string ForwardGUID { get; internal set; } - + } } -- cgit v1.2.3 From a0fc2b5e701659d1ed17eba9c2888cae6d519c1e Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 16 Apr 2017 09:48:33 -0400 Subject: More documentation --- ShiftOS.WinForms/Applications/Pong.cs | 11 ++-- ShiftOS.WinForms/Applications/Terminal.cs | 1 - ShiftOS.WinForms/Resources/Shiftorium.txt | 7 --- ShiftOS.WinForms/WinformsWindowManager.cs | 6 -- ShiftOS_TheReturn/ConsoleEx.cs | 24 +++++++ ShiftOS_TheReturn/CrashHandler.cs | 1 - ShiftOS_TheReturn/Desktop.cs | 101 +++++++++++++++++++++++++++++- 7 files changed, 129 insertions(+), 22 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Pong.cs b/ShiftOS.WinForms/Applications/Pong.cs index 5d09ca0..0ef4da3 100644 --- a/ShiftOS.WinForms/Applications/Pong.cs +++ b/ShiftOS.WinForms/Applications/Pong.cs @@ -115,11 +115,12 @@ namespace ShiftOS.WinForms.Applications paddleHuman.BackColor = SkinEngine.LoadedSkin.ControlTextColor; //Check if paddle upgrade has been bought and change paddles accordingly - if (ShiftoriumFrontend.UpgradeInstalled("pong_increased_paddle_size")) - { - paddleHuman.Height = 150; - paddleComputer.Height = 150; - } + //if (ShiftoriumFrontend.UpgradeInstalled("pong_increased_paddle_size")) + //{ + // paddleHuman.Height = 150; + // paddleComputer.Height = 150; + //} + //I don't know the point of this but I'm fucking 86ing it. - Michael //Set the computer player to move according to the ball's position. if (aiShouldIsbeEnabled) diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index c0fdf01..8d29cba 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -321,7 +321,6 @@ namespace ShiftOS.WinForms.Applications { if (SaveSystem.CurrentSave != null) { if (!ShiftoriumFrontend.UpgradeInstalled("window_manager")) { - rtbterm.Text = AppearanceManager.LastTerminalText; rtbterm.Select(rtbterm.TextLength, 0); } TerminalBackend.PrintPrompt(); diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index 2260198..82ee613 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -259,13 +259,6 @@ Category: "Device Drivers", Description: "With the free placement upgrade, you can place windows of any size anywhere on the desktop, which means theoretically you could add kernel coherence between ShiftOS and another GUI-based operating system and run their applications inside ShiftOS. This upgrade unlocks that.", }, - { - Name: "Pong Increased Paddle Size", - Cost: 1000, - Dependencies: "pong_upgrade", - Category: "Enhancements", - Description: "Having trouble keeping that darn ball in front of you? Well, with this upgrade, your paddle increases in height.... slightly.", - }, { Name: "WM 4 Windows", Cost: 150, diff --git a/ShiftOS.WinForms/WinformsWindowManager.cs b/ShiftOS.WinForms/WinformsWindowManager.cs index 4fcd185..8bff387 100644 --- a/ShiftOS.WinForms/WinformsWindowManager.cs +++ b/ShiftOS.WinForms/WinformsWindowManager.cs @@ -125,12 +125,6 @@ namespace ShiftOS.WinForms public override void SetupWindow(IShiftOSWindow form) { - if (!AppearanceManager.CanOpenWindow(form)) - { - Infobox.Show("{MULTIPLAYER_ONLY}", "{MULTIPLAYER_ONLY_EXP}"); - return; - } - foreach(var attr in form.GetType().GetCustomAttributes(true)) { if(attr is MultiplayerOnlyAttribute) diff --git a/ShiftOS_TheReturn/ConsoleEx.cs b/ShiftOS_TheReturn/ConsoleEx.cs index 69f6a18..90f9cc0 100644 --- a/ShiftOS_TheReturn/ConsoleEx.cs +++ b/ShiftOS_TheReturn/ConsoleEx.cs @@ -6,8 +6,14 @@ using System.Threading.Tasks; namespace ShiftOS.Engine { + /// + /// Provides extra eye candy data that can be used by ShiftOS terminals. + /// public static class ConsoleEx { + /// + /// Initializes the class, performing core configuration. + /// static ConsoleEx() { ForegroundColor = ConsoleColor.White; @@ -18,11 +24,29 @@ namespace ShiftOS.Engine Underline = false; } + /// + /// Gets or sets the foreground color of text in the Terminal. + /// public static ConsoleColor ForegroundColor { get; set; } + + /// + /// Gets or sets the background color of text in the Terminal. + /// public static ConsoleColor BackgroundColor { get; set; } + /// + /// Gets or sets whether text in the Terminal is bold. + /// public static bool Bold { get; set; } + + /// + /// Gets or sets whether text in the Terminal is italic. + /// public static bool Italic { get; set; } + + /// + /// Gets or sets whether text in the Terminal is underlined. + /// public static bool Underline { get; set; } } } diff --git a/ShiftOS_TheReturn/CrashHandler.cs b/ShiftOS_TheReturn/CrashHandler.cs index 734f1a9..ed42ea5 100644 --- a/ShiftOS_TheReturn/CrashHandler.cs +++ b/ShiftOS_TheReturn/CrashHandler.cs @@ -97,7 +97,6 @@ namespace ShiftOS.Engine { if(SaveSystem.CurrentSave != null) TerminalBackend.InvokeCommand("sos.save"); - AudioManager.Kill(); ServerManager.Disconnect(); while (Application.OpenForms.Count > 0) diff --git a/ShiftOS_TheReturn/Desktop.cs b/ShiftOS_TheReturn/Desktop.cs index b72f0cc..bc17a8e 100644 --- a/ShiftOS_TheReturn/Desktop.cs +++ b/ShiftOS_TheReturn/Desktop.cs @@ -37,6 +37,10 @@ using static ShiftOS.Engine.SkinEngine; namespace ShiftOS.Engine { + /// + /// Denotes that this class is launchable from the App Launcher. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class LauncherAttribute : Attribute { /// @@ -54,10 +58,29 @@ namespace ShiftOS.Engine ID = upgradeID; } + /// + /// Gets or sets the name of the launcher item + /// public string Name { get; set; } + + /// + /// Gets or sets whether this entry requires a Shiftorium upgrade. + /// public bool RequiresUpgrade { get; set; } + + /// + /// Gets or sets the ID of the required upgrade. + /// public string ID { get; set; } + + /// + /// Gets or sets this item's category. + /// public string Category { get; private set; } + + /// + /// Gets whether or not the required upgrade is installed. + /// public bool UpgradeInstalled { get @@ -70,36 +93,110 @@ namespace ShiftOS.Engine } } - + /// + /// Provides core functionality for a typical ShiftOS desktop. + /// public interface IDesktop { + /// + /// Gets the name of the desktop. + /// string DesktopName { get; } + + /// + /// Performs most of the skinning and layout handling for the desktop. + /// void SetupDesktop(); + /// + /// Hides the currently-opened app launcher menu. + /// void HideAppLauncher(); + + /// + /// Populates the app launcher menu. + /// + /// All items to be placed in the menu. void PopulateAppLauncher(LauncherItem[] items); + + /// + /// Handles desktop-specific routines for showing ShiftOS windows. + /// + /// The calling window. void ShowWindow(IWindowBorder border); + + /// + /// Handles desktop-specific routines for closing ShiftOS windows. + /// + /// The calling window. void KillWindow(IWindowBorder border); + + /// + /// Populates the panel button list with all open windows. + /// void PopulatePanelButtons(); + + /// + /// Performs desktop-specific routines for minimizing a window. + /// + /// The calling window. void MinimizeWindow(IWindowBorder brdr); + + + /// + /// Performs desktop-specific routines for maximizing a window. + /// + /// The calling window. void MaximizeWindow(IWindowBorder brdr); + + + /// + /// Performs desktop-specific routines for restoring a window to its default state. + /// + /// The calling window. void RestoreWindow(IWindowBorder brdr); + + /// + /// Invokes an action on the UI thread. + /// + /// The action to invoke. void InvokeOnWorkerThread(Action act); + + /// + /// Calculates the screen size of the desktop. + /// + /// The desktop's screen size. Size GetSize(); + /// + /// Opens the app launcher at a specific point. + /// + /// Where the app launcher should be opened. void OpenAppLauncher(Point loc); + /// + /// Opens the desktop. + /// void Show(); + + /// + /// Closes the desktop. + /// void Close(); } public static class Desktop { + /// + /// The underlying desktop object. + /// private static IDesktop _desktop = null; - public static Size Size { get + public static Size Size + { + get { return _desktop.GetSize(); } -- cgit v1.2.3 From 32fc6ed13d8334a6af66b43cf84324a123670620 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 17 Apr 2017 15:10:34 -0400 Subject: Basically finish new OOBE --- ShiftOS.Server/SaveManager.cs | 4 +- ShiftOS.WinForms/Applications/Terminal.cs | 5 +- ShiftOS.WinForms/Oobe.Designer.cs | 4 +- ShiftOS.WinForms/Oobe.cs | 134 ++++---------- ShiftOS.WinForms/OobeStory.cs | 284 ++++++++++++++++++++++++++++++ ShiftOS.WinForms/Program.cs | 4 +- ShiftOS.WinForms/Resources/Shiftorium.txt | 7 - ShiftOS.WinForms/ShiftOS.WinForms.csproj | 1 + ShiftOS_TheReturn/SaveSystem.cs | 8 +- ShiftOS_TheReturn/Story.cs | 2 +- 10 files changed, 334 insertions(+), 119 deletions(-) create mode 100644 ShiftOS.WinForms/OobeStory.cs (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.Server/SaveManager.cs b/ShiftOS.Server/SaveManager.cs index a277b6d..56e8d50 100644 --- a/ShiftOS.Server/SaveManager.cs +++ b/ShiftOS.Server/SaveManager.cs @@ -121,7 +121,7 @@ namespace ShiftOS.Server public static void CheckUserExists(string guid, object contents) { var args = contents as Dictionary; - if (args["username"] != null && args["password"] != null) + if (args["username"] != null) { args["username"] = args["username"].ToString().ToLower(); foreach (var savefile in Directory.GetFiles("saves")) @@ -131,7 +131,7 @@ namespace ShiftOS.Server var save = JsonConvert.DeserializeObject(ReadEncFile(savefile)); - if (save.Username == args["username"].ToString() && save.Password == args["password"].ToString()) + if (save.Username == args["username"].ToString()) { server.DispatchTo(new Guid(guid), new NetObject("mud_savefile", new ServerMessage { diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 8d29cba..30dbd82 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -56,7 +56,6 @@ namespace ShiftOS.WinForms.Applications { public static string latestCommmand = ""; - public static bool IsInRemoteSystem = false; public static string RemoteGuid = ""; @@ -371,5 +370,9 @@ namespace ShiftOS.WinForms.Applications { } + internal void ClearText() + { + rtbterm.Text = ""; + } } } \ No newline at end of file diff --git a/ShiftOS.WinForms/Oobe.Designer.cs b/ShiftOS.WinForms/Oobe.Designer.cs index 587f50a..d3a0f38 100644 --- a/ShiftOS.WinForms/Oobe.Designer.cs +++ b/ShiftOS.WinForms/Oobe.Designer.cs @@ -82,14 +82,14 @@ namespace ShiftOS.WinForms // // lblhackwords // - this.lblhackwords.AutoSize = true; this.lblhackwords.Dock = System.Windows.Forms.DockStyle.Fill; this.lblhackwords.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblhackwords.ForeColor = System.Drawing.SystemColors.ButtonFace; this.lblhackwords.Location = new System.Drawing.Point(0, 0); this.lblhackwords.Name = "lblhackwords"; - this.lblhackwords.Size = new System.Drawing.Size(127, 18); + this.lblhackwords.Size = new System.Drawing.Size(653, 457); this.lblhackwords.TabIndex = 1; + this.lblhackwords.Tag = "header2"; this.lblhackwords.Text = "Hijack in progress"; // // hackeffecttimer diff --git a/ShiftOS.WinForms/Oobe.cs b/ShiftOS.WinForms/Oobe.cs index d6d3b92..5b767e0 100644 --- a/ShiftOS.WinForms/Oobe.cs +++ b/ShiftOS.WinForms/Oobe.cs @@ -36,6 +36,7 @@ using Newtonsoft.Json; using ShiftOS.Engine; using ShiftOS.Objects; using ShiftOS.Objects.ShiftFS; +using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms { @@ -47,7 +48,10 @@ namespace ShiftOS.WinForms this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; this.BackColor = Color.Black; - + this.Load += (o, a) => + { + ControlManager.SetupControls(this); + }; } @@ -62,6 +66,7 @@ namespace ShiftOS.WinForms public void TextType(string texttotype) { + textgeninput.TextAlign = ContentAlignment.MiddleCenter; while(typing == true) { //JESUS CHRIST PAST MICHAEL. @@ -116,114 +121,43 @@ namespace ShiftOS.WinForms { try { - textgeninput = this.lblHijack; - TextType("Your system is now being hijacked."); - rtext = ""; - Thread.Sleep(1000); textgeninput = this.lblhackwords; this.Invoke(new Action(() => { lblHijack.Hide(); })); - TextType("Hello, and welcome to ShiftOS."); - Thread.Sleep(500); - TextType("You have been cordially and involuntarily selected to participate in the development and testing of this operating system."); - Thread.Sleep(500); - TextType("My identity shall remain secret, but if you've been through this before, you'll know exactly who I am."); - Thread.Sleep(500); - TextType("But that doesn't matter."); - Thread.Sleep(500); - TextType("I will now begin to prepare your system for the installation of ShiftOS."); - Thread.Sleep(1000); - FakeSetupScreen fakeForm = null; - this.Invoke(new Action(() => - { - fakeForm = new FakeSetupScreen(this); - fakeForm.Show(); - MySave = save; - lblhackwords.GotFocus += (o, a) => - { - try - { - fakeForm.Invoke(new Action(() => - { - fakeForm.Focus(); - fakeForm.BringToFront(); - })); - } - catch { } - }; - fakeForm.TextSent += (txt) => - { - TextType(txt); - }; - })); - while (fakeForm?.Visible == true) - { - Thread.Sleep(10); - } - if (fakeForm.CreateNewSave == true) + + TextType(@"Throughout many years, man has tried to develop +a digital environment usable by anyone that never goes +offline, full of AIs and humans alike, thinking, interacting, +innovating. + +No one has ever come close to a digital society of such +properties yet, except for one sentient being. It does not +have a life, a gender, an age or a body, but simply one name. + +They call it ""DevX"". + +If anyone sees this message, my identity is anonymous, but I +need your help. I am trapped within ""DevX""'s digital society +with no way out, constantly under attack. + +You must join the digital society, rise up the ranks, and save us. + + - undisclosed_0x1DDFB5977."); + + Thread.Sleep(5000); + while(this.Opacity > 0f) { - TextType("That's all the information I need for now."); - Thread.Sleep(2000); - TextType("Beginning installation of ShiftOS on " + MySave.SystemName + "."); - Thread.Sleep(500); - TextType("Creating new user: " + MySave.Username); - TextType("...with 0 Codepoints, 0 installed upgrades, no legion, and no user shops..."); - MySave.Codepoints = 0; - MySave.CurrentLegions = new List(); - MySave.MyShop = ""; - TextType("User created successfully."); - Thread.Sleep(450); - TextType("You may be wondering what all that meant... You see, in ShiftOS, your user account holds everything I need to know about you."); - Thread.Sleep(640); - TextType("It holds the amount of Codepoints you have - Codepoints are a special currency you can get by doing various tasks in ShiftOS."); - Thread.Sleep(500); - TextType("It also holds all the upgrades you've installed onto ShiftOS - features, applications, enhancements, patches, all that stuff."); - Thread.Sleep(500); - TextType("As for the legions and the shop thing, I'll reveal that to you when it becomes necessary."); - Thread.Sleep(500); - TextType("Your user account is stored on a server of mine called the multi-user domain. It holds every single user account, every script, every application, every thing within ShiftOS."); - Thread.Sleep(600); - TextType("Every time you boot ShiftOS, if you are connected to the Internet, you will immediately connect to the multi-user domain and ShiftOS will attempt to authenticate using the last "); - TextType("successful username and password pair."); - Thread.Sleep(500); - TextType("When you are in the MUD, you are in the middle of a free-for-all. I don't want it to be this way, it just is. I've employed you to help me develop and test the MUD and ShiftOS, "); - TextType("but you have a secondary task if you choose to accept it."); - Thread.Sleep(500); - TextType("There have been a few rebelious groups in the MUD - who have cracked ShiftOS's security barriers - and they're using these exploits to steal others' Codepoints, upgrades, "); - TextType("and even spread damaging viruses."); - Thread.Sleep(500); - TextType("I want you to stop them."); - Thread.Sleep(500); - TextType("Whoever can stop these hackers will gain eternal control over the multi-user domain. They will be given the ability to do as they please, so long as it doesn't interfere with my experiments."); - Thread.Sleep(500); - TextType("I have been installing ShiftOS on your system in the background as I was talking with you. Before I can set you free, I need to give you a tutorial on how to use the system."); - Thread.Sleep(500); - TextType("I will reboot your system in Tutorial Mode now. Complete the tutorial, and you shall be on your way."); - - Thread.Sleep(3000); - SaveSystem.CurrentSave = MySave; - SaveSystem.CurrentSave.StoryPosition = 1; - Utils.WriteAllText(Paths.GetPath("user.dat"), JsonConvert.SerializeObject(new + this.Invoke(new Action(() => { - username = MySave.Username, - password = MySave.Password + this.Opacity -= 0.01f; })); - Shiftorium.Silent = true; - SaveSystem.SaveGame(); //Yknow, just incase it crashes. - } - else - { - TextType("Your login attempt was successful, " + SaveSystem.CurrentSave.Username + "."); - Thread.Sleep(500); - TextType($"According to my data on you, you have earned {SaveSystem.CurrentSave.Codepoints} Codepoints so far."); - Thread.Sleep(500); - TextType($"You have also acquired {SaveSystem.CurrentSave.CountUpgrades()} Shiftorium upgrades out of the {SaveSystem.CurrentSave.Upgrades.Count} available."); - Thread.Sleep(500); - TextType("I will now let you proceed to your system."); - Thread.Sleep(1000); + Thread.Sleep(25); } + + Story.Start("mud_fundamentals"); + this.Invoke(new Action(this.Close)); } catch (Exception e) diff --git a/ShiftOS.WinForms/OobeStory.cs b/ShiftOS.WinForms/OobeStory.cs new file mode 100644 index 0000000..68e2a7b --- /dev/null +++ b/ShiftOS.WinForms/OobeStory.cs @@ -0,0 +1,284 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using Newtonsoft.Json; +using ShiftOS.Engine; +using ShiftOS.Objects; + +namespace ShiftOS.WinForms +{ + public class OobeStory + { + [Story("mud_fundamentals")] + public static void DoStory() + { + Applications.Terminal term = null; + TerminalBackend.PrefixEnabled = false; + Desktop.InvokeOnWorkerThread(() => + { + term = new Applications.Terminal(); + AppearanceManager.SetupWindow(term); + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Welcome to ShiftOS."); + Console.WriteLine(); + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.White; + Console.WriteLine("Before we can bring you to your new system, we must perform some system tasks."); + Console.WriteLine(); + Console.WriteLine("Here's the installation outline."); + Console.WriteLine(); + Console.Write(" - "); + ConsoleEx.Bold = true; + Console.Write("Storage preparation"); + ConsoleEx.Bold = false; + Console.Write(" First, we have to prepare your computer's storage device for ShiftOS. This \r\nincludes formatting your drive with the ShiftFS file \r\nsystem, creating system directories, and generating system files."); + Console.WriteLine(); + Console.Write(" - "); + ConsoleEx.Bold = true; + Console.Write("User configuration"); + ConsoleEx.Bold = false; + Console.Write(" Next it's up to you to set up a system hostname, create a user account, and personalize it."); + Console.WriteLine(); + Console.Write(" - "); + ConsoleEx.Bold = true; + Console.Write("System tutorial"); + ConsoleEx.Bold = false; + Console.WriteLine("Finally, we'll teach you how to use ShiftOS."); + + Console.WriteLine(); + + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("Let's get started!"); + }); + int position = 0; + + Thread.Sleep(5000); + + ConsoleEx.Bold = true; + Console.WriteLine("System preparation"); + + + Console.WriteLine(); + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.White; + Console.WriteLine(@"We'll now begin formatting your drive. Please be patient."); + Console.WriteLine(); + var dinf = new DriveInfo("C:\\"); + decimal bytesFree = ((dinf.AvailableFreeSpace / 1024) / 1024) / 1024; + decimal totalBytes = ((dinf.TotalSize / 1024) / 1024) / 1024; + string type = dinf.DriveType.ToString(); + string name = dinf.Name; + ConsoleEx.Bold = true; + Console.Write("Drive name: "); + ConsoleEx.Bold = false; + Console.WriteLine(name); + ConsoleEx.Bold = true; + Console.Write("Drive type: "); + ConsoleEx.Bold = false; + Console.WriteLine(type); + ConsoleEx.Bold = true; + Console.Write("Total space: "); + ConsoleEx.Bold = false; + Console.WriteLine(totalBytes.ToString() + " GB"); + ConsoleEx.Bold = true; + Console.Write("Free space: "); + Console.WriteLine(bytesFree.ToString() + " GB"); + Console.WriteLine(); + + + ConsoleEx.Bold = false; + ConsoleEx.BackgroundColor = ConsoleColor.Black; + Console.Write("Formatting: ["); + int formatProgress = 0; + while (formatProgress <= 100) + { + if (formatProgress % 3 == 0) + { + ConsoleEx.BackgroundColor = ConsoleColor.White; + Console.Write(" "); + ConsoleEx.BackgroundColor = ConsoleColor.Black; + } + Engine.AudioManager.PlayStream(Properties.Resources.typesound); + formatProgress++; + Thread.Sleep(175); + } + Console.WriteLine("] ..done."); + Thread.Sleep(1000); + ConsoleEx.Bold = true; + Console.WriteLine("Creating directories..."); + ConsoleEx.Bold = false; + foreach (var dir in Paths.GetAllWithoutKey()) + { + if (!dir.Contains(".") && dir.StartsWith("0:/")) + { + Console.WriteLine("Creating: " + dir); + Thread.Sleep(125); + Engine.AudioManager.PlayStream(Properties.Resources.writesound); + } + } + Console.WriteLine(); + Console.WriteLine("Next, let's get user information."); + Console.WriteLine(); + Console.WriteLine("Please enter a system hostname."); + string allowed_chars = "abcdefghijklmnopqrstuvwxyz1234567890_"; + bool userExists = false; + Applications.Terminal.TextSent += (text) => + { + if(position == 0) + { + if(text.Length < 5) + { + Console.WriteLine("Your hostname must be at least 5 characters long."); + return; + } + + if(!isValid(text, allowed_chars)) + { + Console.WriteLine("Your hostname contains illegal characters. You can only use these characters: " + allowed_chars); + return; + } + SaveSystem.CurrentSave.SystemName = text; + position = 1; + } + else if(position == 1) + { + if (text.Length < 5) + { + Console.WriteLine("Your username must be at least 5 characters long."); + return; + } + if (!isValid(text, allowed_chars)) + { + Console.WriteLine("Your username contains illegal characters. You can only use these characters: " + allowed_chars); + return; + } + SaveSystem.CurrentSave.Username = text; + position = 2; + } + else if(position == 3) + { + if (!userExists) + { + if (text.Length < 5) + { + Console.WriteLine("Your password must be at least 5 characters long."); + return; + } + SaveSystem.CurrentSave.Password = text; + position = 4; + } + else + { + ServerManager.SendMessage("mud_login", JsonConvert.SerializeObject(new + { + username = SaveSystem.CurrentSave.Username, + password = text + })); + } + } + }; + + TerminalBackend.InStory = false; + + while (position == 0) + Thread.Sleep(10); + Console.WriteLine("Connecting to the multi-user domain as " + SaveSystem.CurrentSave.SystemName + "..."); + Engine.AudioManager.PlayStream(Properties.Resources.dial_up_modem_02); + Console.WriteLine("Connection successful, system spinning up..."); + Thread.Sleep(200); + Console.WriteLine("No users associated with this system. Please enter a username."); + Console.WriteLine(" - If the username is registered as a digital being, you will be prompted for your password. Else, you will be prompted to create a new account."); + while(position == 1) + { + Thread.Sleep(10); + } + int incorrectChances = 2; + Console.WriteLine("Checking sentience records..."); + ServerManager.MessageReceived += (msg) => + { + if (position == 2) + { + if (msg.Name == "mud_found") + { + Console.WriteLine("Your username has been taken by another sentient being within the digital society."); + Console.WriteLine("If you are that sentience, you have two chances to type the correct password."); + userExists = true; + } + else if (msg.Name == "mud_notfound") + { + Console.WriteLine("Please enter a password for this new user."); + userExists = false; + } + position = 3; + } + else if (position == 3) + { + if(userExists == true) + { + if(msg.Name == "mud_savefile") + { + Console.WriteLine("Your sentience profile has been assigned to your system successfully. We will bring you to your system shortly."); + SaveSystem.CurrentSave = JsonConvert.DeserializeObject(msg.Contents); + position = 4; + } + else if(msg.Name == "mud_login_denied") + { + if (incorrectChances > 0) + { + incorrectChances--; + Console.WriteLine("Access denied. Chances: " + incorrectChances); + } + else + { + Console.WriteLine("Access denied."); + position = 2; + } + } + } + } + }; + ServerManager.SendMessage("mud_checkuserexists", JsonConvert.SerializeObject(new { username = SaveSystem.CurrentSave.Username })); + while(position == 2) + { + Thread.Sleep(10); + } + while (position == 3) + { + Thread.Sleep(10); + } + Console.WriteLine("Sentience linkup successful."); + Console.WriteLine("We will bring you to your system in 5 seconds."); + Thread.Sleep(5000); + Desktop.InvokeOnWorkerThread(() => + { + var lst = new List
(); + foreach (Form frm in Application.OpenForms) + lst.Add(frm); + lst.ForEach((frm) => + { + if (!(frm is WinformsDesktop)) + frm.Close(); + }); + TerminalBackend.PrefixEnabled = true; + + AppearanceManager.SetupWindow(new Applications.Terminal()); + }); + } + private static bool isValid(string text, string chars) + { + foreach(var c in text) + { + if (!chars.Contains(c)) + return false; + } + return true; + } + } +} diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs index 348360f..36c9338 100644 --- a/ShiftOS.WinForms/Program.cs +++ b/ShiftOS.WinForms/Program.cs @@ -64,12 +64,12 @@ namespace ShiftOS.WinForms { AppearanceManager.SetupWindow(new Applications.Terminal()); }; - AppearanceManager.Initiate(new WinformsWindowManager()); - OutOfBoxExperience.Init(new Oobe()); Infobox.Init(new Dialog()); FileSkimmerBackend.Init(new WinformsFSFrontend()); var desk = new WinformsDesktop(); Desktop.Init(desk); + OutOfBoxExperience.Init(new Oobe()); + AppearanceManager.Initiate(new WinformsWindowManager()); Application.Run(desk); } } diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index c18f456..c70f849 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -98,13 +98,6 @@ Category: "Enhancements", Description: "Wanna start all over with a new equation? With this CE (Clear Everything) button, you get rid of not only the numbers in the number field, but also the equation!" }, - { - Name: "MUD Fundamentals", - Cost: 50, - Description: "Some basic commands for the terminal that'll help you out in the multi-user domain.", - Category: "Kernel & System", - Dependencies: null - }, { Name: "AL Notifications", Cost: 150, diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index a223f47..b9e6910 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -286,6 +286,7 @@ Oobe.cs + True True diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 9ff3111..998c60d 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -120,7 +120,7 @@ namespace ShiftOS.Engine //This haults the client until the connection is successful. while (ServerManager.thisGuid == new Guid()) { - + Thread.Sleep(10); } Console.WriteLine("GUID received - bootstrapping complete."); FinishBootstrap(); @@ -133,7 +133,7 @@ namespace ShiftOS.Engine ServerManager.StartLANServer(); while (ServerManager.thisGuid == new Guid()) { - + Thread.Sleep(10); } Console.WriteLine("GUID received - bootstrapping complete."); FinishBootstrap(); @@ -172,7 +172,7 @@ namespace ShiftOS.Engine while (CurrentSave == null) { - + Thread.Sleep(10); } Localization.SetupTHETRUEDefaultLocals(); @@ -181,7 +181,7 @@ namespace ShiftOS.Engine while (CurrentSave.StoryPosition < 1) { - + Thread.Sleep(10); } Thread.Sleep(75); diff --git a/ShiftOS_TheReturn/Story.cs b/ShiftOS_TheReturn/Story.cs index ecd04f4..8c726ed 100644 --- a/ShiftOS_TheReturn/Story.cs +++ b/ShiftOS_TheReturn/Story.cs @@ -68,7 +68,7 @@ namespace ShiftOS.Engine } } } - catch { } + catch (Exception ex) { throw ex; } } } #if DEBUG -- cgit v1.2.3 From ba0ae29bbb7eee83c5a4969316d97b43b5f18ba0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Apr 2017 08:06:00 -0400 Subject: Fix widget stacking --- ShiftOS.WinForms/Applications/Terminal.cs | 295 ++++++++++++++------- .../DesktopWidgets/CodepointsWidget.Designer.cs | 61 +++++ .../DesktopWidgets/CodepointsWidget.cs | 53 ++++ .../DesktopWidgets/CodepointsWidget.resx | 120 +++++++++ ShiftOS.WinForms/ShiftOS.WinForms.csproj | 9 + ShiftOS.WinForms/WinformsDesktop.cs | 2 +- 6 files changed, 446 insertions(+), 94 deletions(-) create mode 100644 ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.Designer.cs create mode 100644 ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.cs create mode 100644 ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.resx (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 30dbd82..cae0bda 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -45,11 +45,13 @@ using ShiftOS.Engine; using ShiftOS.Objects; using ShiftOS.WinForms.Tools; -namespace ShiftOS.WinForms.Applications { +namespace ShiftOS.WinForms.Applications +{ [Launcher("Terminal", false, null, "Utilities")] [WinOpen("terminal")] [DefaultIcon("iconTerminal")] - public partial class Terminal : UserControl, IShiftOSWindow { + public partial class Terminal : UserControl, IShiftOSWindow + { public static Stack ConsoleStack = new Stack(); public static System.Windows.Forms.Timer ti = new System.Windows.Forms.Timer(); @@ -60,72 +62,97 @@ namespace ShiftOS.WinForms.Applications { public static string RemoteGuid = ""; [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static bool PrefixEnabled { - get { + public static bool PrefixEnabled + { + get + { return TerminalBackend.PrefixEnabled; } - set { + set + { TerminalBackend.PrefixEnabled = value; } } [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static bool InStory { - get { + public static bool InStory + { + get + { return TerminalBackend.InStory; } - set { + set + { TerminalBackend.InStory = value; } } [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static string LastCommand { - get { + public static string LastCommand + { + get + { return TerminalBackend.LastCommand; } - set { + set + { TerminalBackend.LastCommand = value; } } - public int TutorialProgress { - get { + public int TutorialProgress + { + get + { throw new NotImplementedException(); } - set { + set + { throw new NotImplementedException(); } } [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static void InvokeCommand(string text) { + public static void InvokeCommand(string text) + { TerminalBackend.InvokeCommand(text); } - public Terminal() { + public Terminal() + { InitializeComponent(); - SaveSystem.GameReady += () => { - try { - this.Invoke(new Action(() => { + SaveSystem.GameReady += () => + { + try + { + this.Invoke(new Action(() => + { ResetAllKeywords(); rtbterm.Text = ""; - TerminalBackend.PrefixEnabled = true; - TerminalBackend.InStory = false; - TerminalBackend.PrintPrompt(); - if (Shiftorium.UpgradeInstalled("wm_free_placement")) + if (!Shiftorium.UpgradeInstalled("desktop")) { - this.ParentForm.Width = 640; - this.ParentForm.Height = 480; - this.ParentForm.Left = (Screen.PrimaryScreen.Bounds.Width - 640) / 2; - this.ParentForm.Top = (Screen.PrimaryScreen.Bounds.Height - 480) / 2; + TerminalBackend.PrefixEnabled = true; + TerminalBackend.InStory = false; + TerminalBackend.PrintPrompt(); + if (Shiftorium.UpgradeInstalled("wm_free_placement")) + { + this.ParentForm.Width = 640; + this.ParentForm.Height = 480; + this.ParentForm.Left = (Screen.PrimaryScreen.Bounds.Width - 640) / 2; + this.ParentForm.Top = (Screen.PrimaryScreen.Bounds.Height - 480) / 2; + } + } + else + { + AppearanceManager.Close(this); } })); - } catch { } + } + catch { } }; @@ -133,21 +160,32 @@ namespace ShiftOS.WinForms.Applications { } - public void FocusOnTerminal() { + public void FocusOnTerminal() + { rtbterm.Focus(); } - public static string GetTime() { + public static string GetTime() + { var time = DateTime.Now; - if (ShiftoriumFrontend.UpgradeInstalled("full_precision_time")) { + if (ShiftoriumFrontend.UpgradeInstalled("full_precision_time")) + { return DateTime.Now.ToString("h:mm:ss tt"); - } else if (ShiftoriumFrontend.UpgradeInstalled("clock_am_and_pm")) { + } + else if (ShiftoriumFrontend.UpgradeInstalled("clock_am_and_pm")) + { return time.TimeOfDay.TotalHours > 12 ? $"{time.Hour - 12} PM" : $"{time.Hour} AM"; - } else if (ShiftoriumFrontend.UpgradeInstalled("clock_hours")) { + } + else if (ShiftoriumFrontend.UpgradeInstalled("clock_hours")) + { return ((int)time.TimeOfDay.TotalHours).ToString(); - } else if (ShiftoriumFrontend.UpgradeInstalled("clock_minutes")) { + } + else if (ShiftoriumFrontend.UpgradeInstalled("clock_minutes")) + { return ((int)time.TimeOfDay.TotalMinutes).ToString(); - } else if (ShiftoriumFrontend.UpgradeInstalled("clock")) { + } + else if (ShiftoriumFrontend.UpgradeInstalled("clock")) + { return ((int)time.TimeOfDay.TotalSeconds).ToString(); } @@ -157,7 +195,8 @@ namespace ShiftOS.WinForms.Applications { public static event TextSentEventHandler TextSent; - public void ResetAllKeywords() { + public void ResetAllKeywords() + { string primary = SaveSystem.CurrentSave.Username + " "; string secondary = "shiftos "; @@ -166,18 +205,27 @@ namespace ShiftOS.WinForms.Applications { var types = asm.GetTypes(); - foreach (var type in types) { - foreach (var a in type.GetCustomAttributes(false)) { - if (ShiftoriumFrontend.UpgradeAttributesUnlocked(type)) { - if (a is Namespace) { + foreach (var type in types) + { + foreach (var a in type.GetCustomAttributes(false)) + { + if (ShiftoriumFrontend.UpgradeAttributesUnlocked(type)) + { + if (a is Namespace) + { var ns = a as Namespace; - if (!primary.Contains(ns.name)) { + if (!primary.Contains(ns.name)) + { primary += ns.name + " "; } - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { - if (ShiftoriumFrontend.UpgradeAttributesUnlocked(method)) { - foreach (var ma in method.GetCustomAttributes(false)) { - if (ma is Command) { + foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) + { + if (ShiftoriumFrontend.UpgradeAttributesUnlocked(method)) + { + foreach (var ma in method.GetCustomAttributes(false)) + { + if (ma is Command) + { var cmd = ma as Command; if (!secondary.Contains(cmd.name)) secondary += cmd.name + " "; @@ -193,14 +241,19 @@ namespace ShiftOS.WinForms.Applications { } - public static void MakeWidget(Controls.TerminalBox txt) { + public static void MakeWidget(Controls.TerminalBox txt) + { AppearanceManager.StartConsoleOut(); - txt.GotFocus += (o, a) => { + txt.GotFocus += (o, a) => + { AppearanceManager.ConsoleOut = txt; }; - txt.KeyDown += (o, a) => { - if (a.KeyCode == Keys.Enter) { - try { + txt.KeyDown += (o, a) => + { + if (a.KeyCode == Keys.Enter) + { + try + { a.SuppressKeyPress = true; Console.WriteLine(""); var text = txt.Lines.ToArray(); @@ -208,29 +261,44 @@ namespace ShiftOS.WinForms.Applications { var text3 = ""; var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); - if (IsInRemoteSystem == true) { - ServerManager.SendMessage("trm_invcmd", JsonConvert.SerializeObject(new { + if (IsInRemoteSystem == true) + { + ServerManager.SendMessage("trm_invcmd", JsonConvert.SerializeObject(new + { guid = RemoteGuid, command = text4 })); - } else { - if (TerminalBackend.PrefixEnabled) { + } + else + { + if (TerminalBackend.PrefixEnabled) + { text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); } TerminalBackend.LastCommand = text3; TextSent?.Invoke(text4); - if (TerminalBackend.InStory == false) { - if(text3 == "stop theme") { + if (TerminalBackend.InStory == false) + { + if (text3 == "stop theme") + { CurrentCommandParser.parser = null; - }else { - if(CurrentCommandParser.parser == null) { + } + else + { + if (CurrentCommandParser.parser == null) + { TerminalBackend.InvokeCommand(text3); - } else { + } + else + { var result = CurrentCommandParser.parser.ParseCommand(text3); - if (result.Equals(default(KeyValuePair, Dictionary>))) { + if (result.Equals(default(KeyValuePair, Dictionary>))) + { Console.WriteLine("Syntax Error: Syntax Error"); - } else { + } + else + { TerminalBackend.InvokeCommand(result.Key.Key, result.Key.Value, result.Value); } } @@ -241,23 +309,35 @@ namespace ShiftOS.WinForms.Applications { TerminalBackend.PrintPrompt(); } } - } catch { } - } else if (a.KeyCode == Keys.Back) { - try { + catch + { + } + } + else if (a.KeyCode == Keys.Back) + { + try + { var tostring3 = txt.Lines[txt.Lines.Length - 1]; var tostringlen = tostring3.Length + 1; var workaround = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; var derp = workaround.Length + 1; - if (tostringlen != derp) { + if (tostringlen != derp) + { AppearanceManager.CurrentPosition--; - } else { + } + else + { a.SuppressKeyPress = true; } - } catch { + } + catch + { Debug.WriteLine("Drunky alert in terminal."); } - } else if (a.KeyCode == Keys.Left) { + } + else if (a.KeyCode == Keys.Left) + { var getstring = txt.Lines[txt.Lines.Length - 1]; var stringlen = getstring.Length + 1; var header = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; @@ -266,19 +346,27 @@ namespace ShiftOS.WinForms.Applications { var remstrlen = txt.TextLength - stringlen; var finalnum = selstart - remstrlen; - if (finalnum != headerlen) { + if (finalnum != headerlen) + { AppearanceManager.CurrentPosition--; - } else { + } + else + { a.SuppressKeyPress = true; } - } else if (a.KeyCode == Keys.Up) { + } + else if (a.KeyCode == Keys.Up) + { var tostring3 = txt.Lines[txt.Lines.Length - 1]; if (tostring3 == $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ") Console.Write(TerminalBackend.LastCommand); a.SuppressKeyPress = true; - } else { - if (TerminalBackend.InStory) { + } + else + { + if (TerminalBackend.InStory) + { a.SuppressKeyPress = true; } AppearanceManager.CurrentPosition++; @@ -287,7 +375,7 @@ namespace ShiftOS.WinForms.Applications { }; AppearanceManager.ConsoleOut = txt; - + txt.Focus(); txt.Font = LoadedSkin.TerminalFont; @@ -296,12 +384,17 @@ namespace ShiftOS.WinForms.Applications { } - private void Terminal_Load(object sender, EventArgs e) { - ServerManager.MessageReceived += (msg) => { - if (msg.Name == "trm_handshake_guid") { + private void Terminal_Load(object sender, EventArgs e) + { + ServerManager.MessageReceived += (msg) => + { + if (msg.Name == "trm_handshake_guid") + { IsInRemoteSystem = true; RemoteGuid = msg.GUID; - } else if (msg.Name == "trm_handshake_stop") { + } + else if (msg.Name == "trm_handshake_stop") + { IsInRemoteSystem = false; RemoteGuid = ""; } @@ -309,17 +402,21 @@ namespace ShiftOS.WinForms.Applications { } - private void Terminal_FormClosing(object sender, FormClosingEventArgs e) { + private void Terminal_FormClosing(object sender, FormClosingEventArgs e) + { ti.Stop(); IsInRemoteSystem = false; RemoteGuid = ""; } - public void OnLoad() { + public void OnLoad() + { MakeWidget(rtbterm); - if (SaveSystem.CurrentSave != null) { - if (!ShiftoriumFrontend.UpgradeInstalled("window_manager")) { + if (SaveSystem.CurrentSave != null) + { + if (!ShiftoriumFrontend.UpgradeInstalled("window_manager")) + { rtbterm.Select(rtbterm.TextLength, 0); } TerminalBackend.PrintPrompt(); @@ -328,8 +425,10 @@ namespace ShiftOS.WinForms.Applications { } - public void OnSkinLoad() { - try { + public void OnSkinLoad() + { + try + { rtbterm.Font = LoadedSkin.TerminalFont; rtbterm.ForeColor = ControlManager.ConvertColor(LoadedSkin.TerminalForeColorCC); rtbterm.BackColor = ControlManager.ConvertColor(LoadedSkin.TerminalBackColorCC); @@ -341,19 +440,27 @@ namespace ShiftOS.WinForms.Applications { } - public bool OnUnload() { - if (SaveSystem.ShuttingDown == false) { - if (!ShiftoriumFrontend.UpgradeInstalled("desktop")) { - if (AppearanceManager.OpenForms.Count <= 1) { + public bool OnUnload() + { + if (SaveSystem.ShuttingDown == false) + { + if (!ShiftoriumFrontend.UpgradeInstalled("desktop")) + { + if (AppearanceManager.OpenForms.Count <= 1) + { Console.WriteLine(""); Console.WriteLine("{WIN_CANTCLOSETERMINAL}"); - try { + try + { Console.WriteLine(""); - if (TerminalBackend.PrefixEnabled) { + if (TerminalBackend.PrefixEnabled) + { Console.Write($"{SaveSystem.CurrentSave.Username}@shiftos:~$ "); } - } catch (Exception ex) { + } + catch (Exception ex) + { Console.WriteLine(ex); } return false; @@ -363,10 +470,12 @@ namespace ShiftOS.WinForms.Applications { return true; } - public void OnUpgrade() { + public void OnUpgrade() + { } - private void rtbterm_TextChanged(object sender, EventArgs e) { + private void rtbterm_TextChanged(object sender, EventArgs e) + { } diff --git a/ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.Designer.cs b/ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.Designer.cs new file mode 100644 index 0000000..9f3ccc7 --- /dev/null +++ b/ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.Designer.cs @@ -0,0 +1,61 @@ +namespace ShiftOS.WinForms.DesktopWidgets +{ + partial class CodepointsWidget + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lbcodepoints = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // lbcodepoints + // + this.lbcodepoints.Cursor = System.Windows.Forms.Cursors.Default; + this.lbcodepoints.Dock = System.Windows.Forms.DockStyle.Fill; + this.lbcodepoints.Location = new System.Drawing.Point(0, 0); + this.lbcodepoints.Name = "lbcodepoints"; + this.lbcodepoints.Size = new System.Drawing.Size(274, 57); + this.lbcodepoints.TabIndex = 0; + this.lbcodepoints.Tag = "header3"; + this.lbcodepoints.Text = "label1"; + this.lbcodepoints.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // CodepointsWidget + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.lbcodepoints); + this.Name = "CodepointsWidget"; + this.Size = new System.Drawing.Size(274, 57); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label lbcodepoints; + } +} diff --git a/ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.cs b/ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.cs new file mode 100644 index 0000000..fee8b1d --- /dev/null +++ b/ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.cs @@ -0,0 +1,53 @@ +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.WinForms.Tools; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms.DesktopWidgets +{ + [DesktopWidget("Codepoints Display", "Show how many Codepoints you have.")] + public partial class CodepointsWidget : UserControl, IDesktopWidget + { + public CodepointsWidget() + { + InitializeComponent(); + tmr.Tick += (o, a) => + { + try + { + lbcodepoints.Text = SaveSystem.CurrentSave.Codepoints.ToString() + " Codepoints"; + } + catch { } + }; + tmr.Interval = 350; + this.VisibleChanged += (o, a) => + { + if (this.Visible == false) + tmr.Stop(); + }; + } + + Timer tmr = new Timer(); + + public void OnSkinLoad() + { + ControlManager.SetupControls(this); + } + + public void OnUpgrade() + { + } + + public void Setup() + { + tmr.Start(); + } + } +} diff --git a/ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.resx b/ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/DesktopWidgets/CodepointsWidget.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 3f7c463..bd8fd65 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -270,6 +270,12 @@ Clock.cs + + UserControl + + + CodepointsWidget.cs + UserControl @@ -434,6 +440,9 @@ Clock.cs + + CodepointsWidget.cs + TerminalWidget.cs diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index c5e3efe..c98a255 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -475,7 +475,7 @@ namespace ShiftOS.WinForms if (widget.Location.X == -1 && widget.Location.Y == -1) { widget.Location = new Point(5, lastHeight); - lastHeight += (widget.Location.Y + widget.Size.Height) + 5; + lastHeight += widget.Size.Height + 5; } } else -- cgit v1.2.3 From 7c070a8213fc59f289385d82b60c3a49c02e03a9 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 24 Apr 2017 17:23:29 -0400 Subject: block ctrl and alt in terminal --- ShiftOS.WinForms/Applications/Terminal.cs | 6 ++++++ ShiftOS.WinForms/WindowBorder.cs | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index cae0bda..a4889e9 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -250,6 +250,12 @@ namespace ShiftOS.WinForms.Applications }; txt.KeyDown += (o, a) => { + if (a.Control == true || a.Alt == true) + { + a.SuppressKeyPress = true; + return; + } + if (a.KeyCode == Keys.Enter) { try diff --git a/ShiftOS.WinForms/WindowBorder.cs b/ShiftOS.WinForms/WindowBorder.cs index 2829a3e..0d351d2 100644 --- a/ShiftOS.WinForms/WindowBorder.cs +++ b/ShiftOS.WinForms/WindowBorder.cs @@ -134,14 +134,14 @@ namespace ShiftOS.WinForms } }; - - + + this.Width = (LoadedSkin.LeftBorderWidth*2) + _parentWindow.Width + LoadedSkin.RightBorderWidth; + this.Height = (LoadedSkin.TitlebarHeight*2) + _parentWindow.Height + LoadedSkin.BottomBorderWidth; + this.pnlcontents.Controls.Add(this._parentWindow); this._parentWindow.Dock = DockStyle.Fill; this._parentWindow.Show(); SetupControls(this); - this.Width = LoadedSkin.LeftBorderWidth + this.Width + LoadedSkin.RightBorderWidth; - this.Height = LoadedSkin.TitlebarHeight + this.Height + LoadedSkin.BottomBorderWidth; ControlManager.SetupControls(this._parentWindow); Shiftorium.Installed += () => -- cgit v1.2.3 From 9916fafefca35e11edffb91566a3eee3aa90cd95 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 29 Apr 2017 10:52:10 -0400 Subject: fix all beta 2.3 bugs --- ShiftOS.WinForms/Applications/Terminal.cs | 8 +++++--- ShiftOS.WinForms/ShiftOS.WinForms.csproj | 1 + ShiftOS.WinForms/TestCommandsForUpgrades.cs | 20 ++++++++++++++++++++ ShiftOS_TheReturn/Shiftorium.cs | 6 +++++- 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 ShiftOS.WinForms/TestCommandsForUpgrades.cs (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index a4889e9..3b1a020 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -405,7 +405,6 @@ namespace ShiftOS.WinForms.Applications RemoteGuid = ""; } }; - } private void Terminal_FormClosing(object sender, FormClosingEventArgs e) @@ -425,10 +424,13 @@ namespace ShiftOS.WinForms.Applications { rtbterm.Select(rtbterm.TextLength, 0); } - TerminalBackend.PrintPrompt(); } - + new Thread(() => + { + Thread.Sleep(1000); + TerminalBackend.PrintPrompt(); + }).Start(); } public void OnSkinLoad() diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 890bbe4..510afed 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -355,6 +355,7 @@ + diff --git a/ShiftOS.WinForms/TestCommandsForUpgrades.cs b/ShiftOS.WinForms/TestCommandsForUpgrades.cs new file mode 100644 index 0000000..491cc6a --- /dev/null +++ b/ShiftOS.WinForms/TestCommandsForUpgrades.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms +{ + [Namespace("test")] + public static class TestCommandsForUpgrades + { + [ShiftoriumUpgrade("Test Command", 50, "This is a simple test command", null, "Test")] + [Command("simpletest")] + public static bool Simple() + { + return true; + } + } +} diff --git a/ShiftOS_TheReturn/Shiftorium.cs b/ShiftOS_TheReturn/Shiftorium.cs index 2637f1b..ad60134 100644 --- a/ShiftOS_TheReturn/Shiftorium.cs +++ b/ShiftOS_TheReturn/Shiftorium.cs @@ -445,7 +445,11 @@ namespace ShiftOS.Engine { public ShiftoriumUpgradeAttribute(string name, long cost, string desc, string dependencies, string category) : base(name.ToLower().Replace(" ", "_")) { - + Name = name; + Description = desc; + Dependencies = dependencies; + Cost = cost; + Category = category; } public string Name { get; private set; } -- cgit v1.2.3 From a99711507970055e02dd678e613e9d8546e6742e Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Apr 2017 20:28:31 -0400 Subject: fix unite login and add multiuser support --- ShiftOS.Objects/ClientSave.cs | 9 +++ ShiftOS.Objects/Save.cs | 2 + ShiftOS.WinForms/Applications/Terminal.cs | 1 + ShiftOS.WinForms/UniteLoginDialog.Designer.cs | 4 +- ShiftOS_TheReturn/SaveSystem.cs | 99 +++++++++++++++++++---- ShiftOS_TheReturn/TerminalBackend.cs | 110 ++++++++++++++++++-------- 6 files changed, 176 insertions(+), 49 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.Objects/ClientSave.cs b/ShiftOS.Objects/ClientSave.cs index edbb7dc..fbe1044 100644 --- a/ShiftOS.Objects/ClientSave.cs +++ b/ShiftOS.Objects/ClientSave.cs @@ -34,5 +34,14 @@ namespace ShiftOS.Objects { public string Username { get; set; } public string Password { get; set; } + public UserPermissions Permissions { get; set; } + } + + public enum UserPermissions + { + Root, + Admin, + User, + Guest } } diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 7208de5..1adaf3b 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -93,6 +93,8 @@ namespace ShiftOS.Objects } return count; } + + public List Users = new List(); } public class SettingsObject : DynamicObject diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 3b1a020..d35f7e0 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -283,6 +283,7 @@ namespace ShiftOS.WinForms.Applications } TerminalBackend.LastCommand = text3; TextSent?.Invoke(text4); + TerminalBackend.SendText(text4); if (TerminalBackend.InStory == false) { if (text3 == "stop theme") diff --git a/ShiftOS.WinForms/UniteLoginDialog.Designer.cs b/ShiftOS.WinForms/UniteLoginDialog.Designer.cs index daf385b..f510393 100644 --- a/ShiftOS.WinForms/UniteLoginDialog.Designer.cs +++ b/ShiftOS.WinForms/UniteLoginDialog.Designer.cs @@ -51,9 +51,9 @@ this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(16, 82); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(58, 13); + this.label2.Size = new System.Drawing.Size(35, 13); this.label2.TabIndex = 1; - this.label2.Text = "Username:"; + this.label2.Text = "Email:"; // // label3 // diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index bd9a14f..2df914e 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -50,6 +50,9 @@ namespace ShiftOS.Engine { public static bool ShuttingDown = false; + public static ClientSave CurrentUser { get; set; } + + public static Save CurrentSave { get; set; } /// @@ -189,28 +192,96 @@ namespace ShiftOS.Engine Thread.Sleep(50); Console.WriteLine("{SYSTEM_INITIATED}"); + + + if(CurrentSave.Users.Count == 0) + { + CurrentSave.Users.Add(new ClientSave + { + Username = "root", + Password = "", + Permissions = UserPermissions.Root + }); + Console.WriteLine("No users found. Creating new user with username \"root\", with no password."); + } TerminalBackend.InStory = false; + + TerminalBackend.PrefixEnabled = false; + + Login: + string username = ""; + int progress = 0; + bool goback = false; + TextSentEventHandler ev = null; + ev = (text) => + { + if (progress == 0) + { + if (!string.IsNullOrWhiteSpace(text)) + { + if (CurrentSave.Users.FirstOrDefault(x => x.Username == text) == null) + { + Console.WriteLine("User not found."); + goback = true; + progress++; + TerminalBackend.TextSent -= ev; + return; + } + username = text; + progress++; + } + else + { + Console.WriteLine("Username not provided."); + TerminalBackend.TextSent -= ev; + goback = true; + progress++; + } + } + else if (progress == 1) + { + var user = CurrentSave.Users.FirstOrDefault(x => x.Username == username); + if (user.Password == text) + { + Console.WriteLine("Welcome to ShiftOS."); + CurrentUser = user; + Thread.Sleep(2000); + progress++; + } + else + { + Console.WriteLine("Access denied."); + goback = true; + progress++; + } + TerminalBackend.TextSent -= ev; + } + }; + TerminalBackend.TextSent += ev; + Console.WriteLine(CurrentSave.SystemName + " login:"); + while(progress == 0) + { + Thread.Sleep(10); + } + if (goback) + goto Login; + Console.WriteLine("password:"); + while (progress == 1) + Thread.Sleep(10); + if (goback) + goto Login; + + TerminalBackend.PrefixEnabled = true; Shiftorium.LogOrphanedUpgrades = true; Desktop.InvokeOnWorkerThread(new Action(() => { ShiftOS.Engine.Scripting.LuaInterpreter.RunSft(Paths.GetPath("kernel.sft")); })); - Desktop.InvokeOnWorkerThread(new Action(() => Desktop.PopulateAppLauncher())); - if (CurrentSave.StoryPosition == 1) - { - Desktop.InvokeOnWorkerThread(new Action(() => - { - TutorialManager.StartTutorial(); - })); - while (TutorialManager.IsInTutorial == true) { } - GameReady?.Invoke(); - } - else - { - GameReady?.Invoke(); - } + + Desktop.InvokeOnWorkerThread(new Action(() => Desktop.PopulateAppLauncher())); + GameReady?.Invoke(); } public delegate void EmptyEventHandler(); diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 318c818..3bfdeff 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -32,21 +32,26 @@ using System.Threading.Tasks; using Newtonsoft.Json; using static ShiftOS.Engine.SaveSystem; -namespace ShiftOS.Engine { - public static class TerminalBackend { +namespace ShiftOS.Engine +{ + public static class TerminalBackend + { public static event Action CommandProcessed; public static bool Elevated { get; set; } - public static Dictionary GetArgs(ref string text) { + public static Dictionary GetArgs(ref string text) + { bool shouldParse = false; int argStart = 0; - if (text.Contains("{")) { + if (text.Contains("{")) + { shouldParse = true; argStart = text.IndexOf('{'); } - if (shouldParse == false) { + if (shouldParse == false) + { string replacement = Regex.Replace(text, @"\t|\n|\r", ""); text = replacement + "{}"; shouldParse = true; @@ -61,15 +66,18 @@ namespace ShiftOS.Engine { public static string LastCommand = ""; - public static void InvokeCommand(string ns, string command, Dictionary arguments, bool isRemote = false) { - try { + public static void InvokeCommand(string ns, string command, Dictionary arguments, bool isRemote = false) + { + try + { if (string.IsNullOrWhiteSpace(ns)) return; bool commandWasClient = RunClient(ns, command, arguments, isRemote); - if (!commandWasClient && !string.IsNullOrWhiteSpace(ns)) { + if (!commandWasClient && !string.IsNullOrWhiteSpace(ns)) + { PrefixEnabled = false; ServerManager.SendMessage("script", $@"{{ @@ -80,23 +88,29 @@ namespace ShiftOS.Engine { } CommandProcessed?.Invoke(ns + "." + command, JsonConvert.SerializeObject(arguments)); - } catch (Exception ex) { + } + catch (Exception ex) + { Console.WriteLine($"Command parse error: {ex.Message}"); // This shouldn't ever be called now PrefixEnabled = true; } } - public static string GetSentArgs(Dictionary argss) { + public static string GetSentArgs(Dictionary argss) + { Dictionary args = new Dictionary(); - foreach (KeyValuePair arg in argss) { + foreach (KeyValuePair arg in argss) + { args[arg.Key] = arg.Value; } return JsonConvert.SerializeObject(args); } - public static void InvokeCommand(string text, bool isRemote = false) { - try { + public static void InvokeCommand(string text, bool isRemote = false) + { + try + { if (string.IsNullOrWhiteSpace(text)) return; @@ -104,7 +118,8 @@ namespace ShiftOS.Engine { bool commandWasClient = RunClient(text, args, isRemote); - if (!commandWasClient) { + if (!commandWasClient) + { PrefixEnabled = false; ServerManager.SendMessage("script", $@"{{ @@ -114,7 +129,9 @@ namespace ShiftOS.Engine { }}"); } CommandProcessed?.Invoke(text, GetSentArgs(args)); - } catch (Exception ex) { + } + catch (Exception ex) + { Console.WriteLine($"Command parse error: {ex.Message}"); PrefixEnabled = true; @@ -129,15 +146,18 @@ namespace ShiftOS.Engine { public static event EmptyEventHandler TerminalRequested; - internal static void OpenTerminal() { + internal static void OpenTerminal() + { TerminalRequested?.Invoke(); } - public static bool CanRunRemotely(MethodInfo mth, bool isRemote) { + public static bool CanRunRemotely(MethodInfo mth, bool isRemote) + { if (!isRemote) return true; - foreach (var attr in mth.GetCustomAttributes(false)) { + foreach (var attr in mth.GetCustomAttributes(false)) + { if (attr is RemoteLockAttribute) return false; } @@ -145,26 +165,32 @@ namespace ShiftOS.Engine { return true; } - public static bool RunClient(string ns, string cmd, Dictionary args, bool isRemote = false) { + public static bool RunClient(string ns, string cmd, Dictionary args, bool isRemote = false) + { return RunClient(ns + "." + cmd, args, isRemote); } - public static bool RunClient(string text, Dictionary argss, bool isRemote = false) { + public static bool RunClient(string text, Dictionary argss, bool isRemote = false) + { Dictionary args = new Dictionary(); - foreach (KeyValuePair arg in argss) { + foreach (KeyValuePair arg in argss) + { args[arg.Key] = arg.Value; } return RunClient(text, args, isRemote); } - public static bool RunClient(string text, Dictionary args, bool isRemote = false) { + public static bool RunClient(string text, Dictionary args, bool isRemote = false) + { latestCommmand = text; //Console.WriteLine(text + " " + "{" + string.Join(",", args.Select(kv => kv.Key + "=" + kv.Value).ToArray()) + "}" + " " + isRemote); - foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) { - try { + foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) + { + try + { var asm = Assembly.LoadFile(asmExec); var types = asm.GetTypes(); @@ -315,7 +341,9 @@ namespace ShiftOS.Engine { } } - } else { + } + else + { Console.WriteLine(text + " cannot be ran in a remote session"); return true; } @@ -360,7 +388,8 @@ namespace ShiftOS.Engine { } } } - } catch { } + } + catch { } } return false; } @@ -375,7 +404,7 @@ namespace ShiftOS.Engine { ConsoleEx.ForegroundColor = ConsoleColor.Magenta; ConsoleEx.Bold = true; - Console.Write(SaveSystem.CurrentSave.Username); + Console.Write(SaveSystem.CurrentUser.Username); ConsoleEx.Bold = false; ConsoleEx.ForegroundColor = ConsoleColor.Gray; Console.Write("@"); @@ -410,26 +439,34 @@ namespace ShiftOS.Engine { string text3 = ""; string text4 = msg.Contents; - if (TerminalBackend.PrefixEnabled) { + if (TerminalBackend.PrefixEnabled) + { text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); } IsForwardingConsoleWrites = true; - if (TerminalBackend.InStory == false) { + if (TerminalBackend.InStory == false) + { TerminalBackend.InvokeCommand(text3, true); } - if (TerminalBackend.PrefixEnabled) { + if (TerminalBackend.PrefixEnabled) + { Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); } IsForwardingConsoleWrites = false; - } else if (msg.Name == "pleasewrite") { + } + else if (msg.Name == "pleasewrite") + { Console.Write(msg.Contents); - } else if (msg.Name == "handshake_from") { + } + else if (msg.Name == "handshake_from") + { var a = JsonConvert.DeserializeObject>(msg.Contents); string uName = a["username"] as string; string pass = a["password"] as string; string sys = a["sysname"] as string; string guid = msg.GUID; - if (SaveSystem.CurrentSave.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys) { + if (SaveSystem.CurrentSave.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys) + { ForwardGUID = guid; ServerManager.SendMessage("trm_handshake_accept", $@"{{ guid: ""{ServerManager.thisGuid}"", @@ -450,5 +487,12 @@ namespace ShiftOS.Engine { public static bool IsForwardingConsoleWrites { get; internal set; } public static string ForwardGUID { get; internal set; } + public static event TextSentEventHandler TextSent; + + public static void SendText(string text) + { + TextSent?.Invoke(text); + } + } } -- cgit v1.2.3 From 7532df70757ecbcaf735a5fc50eee282f555741a Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 1 May 2017 15:23:46 -0400 Subject: Replace most instances of "CurrentSave.Username" --- ShiftOS.Objects/Save.cs | 4 + ShiftOS.Server/Program.cs | 7 +- ShiftOS.WinForms/Applications/Dialog.cs | 2 - ShiftOS.WinForms/Applications/Terminal.cs | 12 +- ShiftOS.WinForms/FakeSetupScreen.Designer.cs | 624 --------------------------- ShiftOS.WinForms/FakeSetupScreen.cs | 395 ----------------- ShiftOS.WinForms/FakeSetupScreen.resx | 120 ------ ShiftOS.WinForms/Oobe.cs | 34 +- ShiftOS.WinForms/ShiftOS.WinForms.csproj | 9 - ShiftOS.WinForms/WinformsDesktop.cs | 5 +- ShiftOS_TheReturn/CommandParser.cs | 3 - ShiftOS_TheReturn/Commands.cs | 2 +- 12 files changed, 14 insertions(+), 1203 deletions(-) delete mode 100644 ShiftOS.WinForms/FakeSetupScreen.Designer.cs delete mode 100644 ShiftOS.WinForms/FakeSetupScreen.cs delete mode 100644 ShiftOS.WinForms/FakeSetupScreen.resx (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 1adaf3b..4f91db7 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -34,7 +34,11 @@ namespace ShiftOS.Objects //Better to store this stuff server-side so we can do some neat stuff with hacking... public class Save { + + [Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")] public string Username { get; set; } + + public long Codepoints { get; set; } public Dictionary Upgrades { get; set; } public int StoryPosition { get; set; } diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs index 9e89e56..97c8a66 100644 --- a/ShiftOS.Server/Program.cs +++ b/ShiftOS.Server/Program.cs @@ -296,8 +296,6 @@ namespace ShiftOS.Server /// Message. public static void Interpret(ServerMessage msg) { - Dictionary args = null; - try { Console.WriteLine($@"[{DateTime.Now}] Message received from {msg.GUID}: {msg.Name}"); @@ -325,8 +323,7 @@ namespace ShiftOS.Server try { object contents = null; - bool throwOnNull = false; - + if (mAttrib.ExpectedType == typeof(int)) { @@ -354,7 +351,6 @@ namespace ShiftOS.Server } else if (mAttrib.ExpectedType == typeof(bool)) { - throwOnNull = true; if (msg.Contents.ToLower() == "true") { contents = true; @@ -371,7 +367,6 @@ namespace ShiftOS.Server } else if (mAttrib.ExpectedType == null) { - throwOnNull = false; } else if(mAttrib.ExpectedType == typeof(string)) { diff --git a/ShiftOS.WinForms/Applications/Dialog.cs b/ShiftOS.WinForms/Applications/Dialog.cs index 2abc705..f9d0b86 100644 --- a/ShiftOS.WinForms/Applications/Dialog.cs +++ b/ShiftOS.WinForms/Applications/Dialog.cs @@ -85,8 +85,6 @@ namespace ShiftOS.WinForms.Applications } - private Action OpenCallback = null; - public void Open(string title, string msg, Action c = null) { new Dialog().OpenInternal(title, msg, c); diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index d35f7e0..32c5363 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -197,7 +197,7 @@ namespace ShiftOS.WinForms.Applications public void ResetAllKeywords() { - string primary = SaveSystem.CurrentSave.Username + " "; + string primary = SaveSystem.CurrentUser.Username + " "; string secondary = "shiftos "; @@ -279,7 +279,7 @@ namespace ShiftOS.WinForms.Applications { if (TerminalBackend.PrefixEnabled) { - text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); + text3 = text4.Remove(0, $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); } TerminalBackend.LastCommand = text3; TextSent?.Invoke(text4); @@ -327,7 +327,7 @@ namespace ShiftOS.WinForms.Applications { var tostring3 = txt.Lines[txt.Lines.Length - 1]; var tostringlen = tostring3.Length + 1; - var workaround = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; + var workaround = $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; var derp = workaround.Length + 1; if (tostringlen != derp) { @@ -347,7 +347,7 @@ namespace ShiftOS.WinForms.Applications { var getstring = txt.Lines[txt.Lines.Length - 1]; var stringlen = getstring.Length + 1; - var header = $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; + var header = $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; var headerlen = header.Length + 1; var selstart = txt.SelectionStart; var remstrlen = txt.TextLength - stringlen; @@ -365,7 +365,7 @@ namespace ShiftOS.WinForms.Applications else if (a.KeyCode == Keys.Up) { var tostring3 = txt.Lines[txt.Lines.Length - 1]; - if (tostring3 == $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ") + if (tostring3 == $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ") Console.Write(TerminalBackend.LastCommand); a.SuppressKeyPress = true; @@ -465,7 +465,7 @@ namespace ShiftOS.WinForms.Applications if (TerminalBackend.PrefixEnabled) { - Console.Write($"{SaveSystem.CurrentSave.Username}@shiftos:~$ "); + Console.Write($"{SaveSystem.CurrentUser.Username}@shiftos:~$ "); } } catch (Exception ex) diff --git a/ShiftOS.WinForms/FakeSetupScreen.Designer.cs b/ShiftOS.WinForms/FakeSetupScreen.Designer.cs deleted file mode 100644 index b14367b..0000000 --- a/ShiftOS.WinForms/FakeSetupScreen.Designer.cs +++ /dev/null @@ -1,624 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -namespace ShiftOS.WinForms -{ - partial class FakeSetupScreen - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.pnlheader = new System.Windows.Forms.Panel(); - this.flbuttons = new System.Windows.Forms.FlowLayoutPanel(); - this.btnnext = new System.Windows.Forms.Button(); - this.btnback = new System.Windows.Forms.Button(); - this.page1 = new System.Windows.Forms.Panel(); - this.label2 = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); - this.page2 = new System.Windows.Forms.Panel(); - this.lbbyteszeroed = new System.Windows.Forms.Label(); - this.pgformatprogress = new System.Windows.Forms.ProgressBar(); - this.lbformattitle = new System.Windows.Forms.Label(); - this.page3 = new System.Windows.Forms.Panel(); - this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.label3 = new System.Windows.Forms.Label(); - this.txtnewusername = new System.Windows.Forms.TextBox(); - this.label5 = new System.Windows.Forms.Label(); - this.txtnewpassword = new System.Windows.Forms.TextBox(); - this.label6 = new System.Windows.Forms.Label(); - this.txtnewsysname = new System.Windows.Forms.TextBox(); - this.label4 = new System.Windows.Forms.Label(); - this.page4 = new System.Windows.Forms.Panel(); - this.txtlicenseagreement = new System.Windows.Forms.RichTextBox(); - this.label10 = new System.Windows.Forms.Label(); - this.pgrereg = new System.Windows.Forms.Panel(); - this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); - this.label7 = new System.Windows.Forms.Label(); - this.txtruname = new System.Windows.Forms.TextBox(); - this.label8 = new System.Windows.Forms.Label(); - this.txtrpass = new System.Windows.Forms.TextBox(); - this.label9 = new System.Windows.Forms.Label(); - this.txtrsys = new System.Windows.Forms.TextBox(); - this.label11 = new System.Windows.Forms.Label(); - this.pglogin = new System.Windows.Forms.Panel(); - this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); - this.label12 = new System.Windows.Forms.Label(); - this.txtluser = new System.Windows.Forms.TextBox(); - this.label13 = new System.Windows.Forms.Label(); - this.txtlpass = new System.Windows.Forms.TextBox(); - this.label15 = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); - this.btnnlogin = new System.Windows.Forms.Button(); - this.flbuttons.SuspendLayout(); - this.page1.SuspendLayout(); - this.page2.SuspendLayout(); - this.page3.SuspendLayout(); - this.tableLayoutPanel1.SuspendLayout(); - this.page4.SuspendLayout(); - this.pgrereg.SuspendLayout(); - this.tableLayoutPanel2.SuspendLayout(); - this.pglogin.SuspendLayout(); - this.tableLayoutPanel3.SuspendLayout(); - this.SuspendLayout(); - // - // pnlheader - // - this.pnlheader.BackColor = System.Drawing.SystemColors.ControlDark; - this.pnlheader.Dock = System.Windows.Forms.DockStyle.Left; - this.pnlheader.Location = new System.Drawing.Point(0, 0); - this.pnlheader.Name = "pnlheader"; - this.pnlheader.Size = new System.Drawing.Size(138, 300); - this.pnlheader.TabIndex = 0; - // - // flbuttons - // - this.flbuttons.AutoSize = true; - this.flbuttons.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.flbuttons.Controls.Add(this.btnnext); - this.flbuttons.Controls.Add(this.btnback); - this.flbuttons.Dock = System.Windows.Forms.DockStyle.Bottom; - this.flbuttons.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft; - this.flbuttons.Location = new System.Drawing.Point(0, 300); - this.flbuttons.Name = "flbuttons"; - this.flbuttons.Size = new System.Drawing.Size(490, 29); - this.flbuttons.TabIndex = 1; - // - // btnnext - // - this.btnnext.Location = new System.Drawing.Point(412, 3); - this.btnnext.Name = "btnnext"; - this.btnnext.Size = new System.Drawing.Size(75, 23); - this.btnnext.TabIndex = 0; - this.btnnext.Text = "Next"; - this.btnnext.UseVisualStyleBackColor = true; - this.btnnext.Click += new System.EventHandler(this.btnnext_Click); - // - // btnback - // - this.btnback.Location = new System.Drawing.Point(331, 3); - this.btnback.Name = "btnback"; - this.btnback.Size = new System.Drawing.Size(75, 23); - this.btnback.TabIndex = 1; - this.btnback.Text = "Back"; - this.btnback.UseVisualStyleBackColor = true; - this.btnback.Click += new System.EventHandler(this.btnback_Click); - // - // page1 - // - this.page1.Controls.Add(this.label2); - this.page1.Controls.Add(this.label1); - this.page1.Dock = System.Windows.Forms.DockStyle.Fill; - this.page1.Location = new System.Drawing.Point(138, 0); - this.page1.Name = "page1"; - this.page1.Size = new System.Drawing.Size(352, 300); - this.page1.TabIndex = 2; - // - // label2 - // - this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.label2.Location = new System.Drawing.Point(20, 87); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(320, 199); - this.label2.TabIndex = 1; - this.label2.Text = "This wizard will guide you through the installation and configuration of ShiftOS." + - "\r\n\r\nPress Next to continue."; - // - // label1 - // - this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F); - this.label1.Location = new System.Drawing.Point(19, 22); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(321, 44); - this.label1.TabIndex = 0; - this.label1.Text = "Welcome to the ShiftOS installation wizard."; - // - // page2 - // - this.page2.Controls.Add(this.lbbyteszeroed); - this.page2.Controls.Add(this.pgformatprogress); - this.page2.Controls.Add(this.lbformattitle); - this.page2.Dock = System.Windows.Forms.DockStyle.Fill; - this.page2.Location = new System.Drawing.Point(138, 0); - this.page2.Name = "page2"; - this.page2.Size = new System.Drawing.Size(352, 300); - this.page2.TabIndex = 2; - // - // lbbyteszeroed - // - this.lbbyteszeroed.AutoSize = true; - this.lbbyteszeroed.Location = new System.Drawing.Point(20, 91); - this.lbbyteszeroed.Name = "lbbyteszeroed"; - this.lbbyteszeroed.Size = new System.Drawing.Size(127, 13); - this.lbbyteszeroed.TabIndex = 5; - this.lbbyteszeroed.Text = "Bytes zeroed: 0/1000000"; - // - // pgformatprogress - // - this.pgformatprogress.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.pgformatprogress.Location = new System.Drawing.Point(23, 61); - this.pgformatprogress.Name = "pgformatprogress"; - this.pgformatprogress.Size = new System.Drawing.Size(317, 23); - this.pgformatprogress.Style = System.Windows.Forms.ProgressBarStyle.Continuous; - this.pgformatprogress.TabIndex = 4; - // - // lbformattitle - // - this.lbformattitle.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.lbformattitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F); - this.lbformattitle.Location = new System.Drawing.Point(16, 9); - this.lbformattitle.Name = "lbformattitle"; - this.lbformattitle.Size = new System.Drawing.Size(321, 26); - this.lbformattitle.TabIndex = 3; - this.lbformattitle.Text = "Formatting your drive..."; - // - // page3 - // - this.page3.Controls.Add(this.btnnlogin); - this.page3.Controls.Add(this.tableLayoutPanel1); - this.page3.Controls.Add(this.label4); - this.page3.Dock = System.Windows.Forms.DockStyle.Fill; - this.page3.Location = new System.Drawing.Point(138, 0); - this.page3.Name = "page3"; - this.page3.Size = new System.Drawing.Size(352, 300); - this.page3.TabIndex = 6; - // - // tableLayoutPanel1 - // - this.tableLayoutPanel1.AutoSize = true; - this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.tableLayoutPanel1.ColumnCount = 2; - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.Controls.Add(this.label3, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.txtnewusername, 1, 0); - this.tableLayoutPanel1.Controls.Add(this.label5, 0, 1); - this.tableLayoutPanel1.Controls.Add(this.txtnewpassword, 1, 1); - this.tableLayoutPanel1.Controls.Add(this.label6, 0, 2); - this.tableLayoutPanel1.Controls.Add(this.txtnewsysname, 1, 2); - this.tableLayoutPanel1.Location = new System.Drawing.Point(20, 61); - this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 3; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(212, 72); - this.tableLayoutPanel1.TabIndex = 4; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(3, 0); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(58, 13); - this.label3.TabIndex = 0; - this.label3.Text = "Username:"; - // - // txtnewusername - // - this.txtnewusername.Location = new System.Drawing.Point(109, 3); - this.txtnewusername.Name = "txtnewusername"; - this.txtnewusername.Size = new System.Drawing.Size(100, 20); - this.txtnewusername.TabIndex = 1; - // - // label5 - // - this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(3, 26); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(56, 13); - this.label5.TabIndex = 2; - this.label5.Text = "Password:"; - // - // txtnewpassword - // - this.txtnewpassword.Location = new System.Drawing.Point(109, 29); - this.txtnewpassword.Name = "txtnewpassword"; - this.txtnewpassword.PasswordChar = '*'; - this.txtnewpassword.Size = new System.Drawing.Size(100, 20); - this.txtnewpassword.TabIndex = 3; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(3, 52); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(75, 13); - this.label6.TabIndex = 4; - this.label6.Text = "System Name:"; - // - // txtnewsysname - // - this.txtnewsysname.Location = new System.Drawing.Point(109, 55); - this.txtnewsysname.Name = "txtnewsysname"; - this.txtnewsysname.Size = new System.Drawing.Size(100, 20); - this.txtnewsysname.TabIndex = 5; - // - // label4 - // - this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F); - this.label4.Location = new System.Drawing.Point(16, 9); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(321, 26); - this.label4.TabIndex = 3; - this.label4.Text = "User information"; - // - // page4 - // - this.page4.Controls.Add(this.txtlicenseagreement); - this.page4.Controls.Add(this.label10); - this.page4.Dock = System.Windows.Forms.DockStyle.Fill; - this.page4.Location = new System.Drawing.Point(138, 0); - this.page4.Name = "page4"; - this.page4.Size = new System.Drawing.Size(352, 300); - this.page4.TabIndex = 7; - // - // txtlicenseagreement - // - this.txtlicenseagreement.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.txtlicenseagreement.Location = new System.Drawing.Point(23, 58); - this.txtlicenseagreement.Name = "txtlicenseagreement"; - this.txtlicenseagreement.ReadOnly = true; - this.txtlicenseagreement.Size = new System.Drawing.Size(326, 228); - this.txtlicenseagreement.TabIndex = 4; - this.txtlicenseagreement.Text = ""; - // - // label10 - // - this.label10.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F); - this.label10.Location = new System.Drawing.Point(16, 9); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(321, 26); - this.label10.TabIndex = 3; - this.label10.Text = "License Agreement"; - // - // pgrereg - // - this.pgrereg.Controls.Add(this.tableLayoutPanel2); - this.pgrereg.Controls.Add(this.label11); - this.pgrereg.Dock = System.Windows.Forms.DockStyle.Fill; - this.pgrereg.Location = new System.Drawing.Point(138, 0); - this.pgrereg.Name = "pgrereg"; - this.pgrereg.Size = new System.Drawing.Size(352, 300); - this.pgrereg.TabIndex = 8; - // - // tableLayoutPanel2 - // - this.tableLayoutPanel2.AutoSize = true; - this.tableLayoutPanel2.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.tableLayoutPanel2.ColumnCount = 2; - this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel2.Controls.Add(this.label7, 0, 0); - this.tableLayoutPanel2.Controls.Add(this.txtruname, 1, 0); - this.tableLayoutPanel2.Controls.Add(this.label8, 0, 1); - this.tableLayoutPanel2.Controls.Add(this.txtrpass, 1, 1); - this.tableLayoutPanel2.Controls.Add(this.label9, 0, 2); - this.tableLayoutPanel2.Controls.Add(this.txtrsys, 1, 2); - this.tableLayoutPanel2.Location = new System.Drawing.Point(20, 61); - this.tableLayoutPanel2.Name = "tableLayoutPanel2"; - this.tableLayoutPanel2.RowCount = 3; - this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); - this.tableLayoutPanel2.Size = new System.Drawing.Size(212, 72); - this.tableLayoutPanel2.TabIndex = 4; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(3, 0); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(58, 13); - this.label7.TabIndex = 0; - this.label7.Text = "Username:"; - // - // txtruname - // - this.txtruname.Location = new System.Drawing.Point(109, 3); - this.txtruname.Name = "txtruname"; - this.txtruname.Size = new System.Drawing.Size(100, 20); - this.txtruname.TabIndex = 1; - // - // label8 - // - this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(3, 26); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(56, 13); - this.label8.TabIndex = 2; - this.label8.Text = "Password:"; - // - // txtrpass - // - this.txtrpass.Location = new System.Drawing.Point(109, 29); - this.txtrpass.Name = "txtrpass"; - this.txtrpass.PasswordChar = '*'; - this.txtrpass.Size = new System.Drawing.Size(100, 20); - this.txtrpass.TabIndex = 3; - // - // label9 - // - this.label9.AutoSize = true; - this.label9.Location = new System.Drawing.Point(3, 52); - this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(75, 13); - this.label9.TabIndex = 4; - this.label9.Text = "System Name:"; - // - // txtrsys - // - this.txtrsys.Location = new System.Drawing.Point(109, 55); - this.txtrsys.Name = "txtrsys"; - this.txtrsys.Size = new System.Drawing.Size(100, 20); - this.txtrsys.TabIndex = 5; - // - // label11 - // - this.label11.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.label11.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F); - this.label11.Location = new System.Drawing.Point(16, 9); - this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(321, 26); - this.label11.TabIndex = 3; - this.label11.Text = "User information"; - // - // pglogin - // - this.pglogin.Controls.Add(this.tableLayoutPanel3); - this.pglogin.Controls.Add(this.label15); - this.pglogin.Controls.Add(this.button1); - this.pglogin.Dock = System.Windows.Forms.DockStyle.Fill; - this.pglogin.Location = new System.Drawing.Point(138, 0); - this.pglogin.Name = "pglogin"; - this.pglogin.Size = new System.Drawing.Size(352, 300); - this.pglogin.TabIndex = 9; - // - // tableLayoutPanel3 - // - this.tableLayoutPanel3.AutoSize = true; - this.tableLayoutPanel3.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.tableLayoutPanel3.ColumnCount = 2; - this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel3.Controls.Add(this.label12, 0, 0); - this.tableLayoutPanel3.Controls.Add(this.txtluser, 1, 0); - this.tableLayoutPanel3.Controls.Add(this.label13, 0, 1); - this.tableLayoutPanel3.Controls.Add(this.txtlpass, 1, 1); - this.tableLayoutPanel3.Location = new System.Drawing.Point(20, 61); - this.tableLayoutPanel3.Name = "tableLayoutPanel3"; - this.tableLayoutPanel3.RowCount = 3; - this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); - this.tableLayoutPanel3.Size = new System.Drawing.Size(212, 72); - this.tableLayoutPanel3.TabIndex = 4; - // - // label12 - // - this.label12.AutoSize = true; - this.label12.Location = new System.Drawing.Point(3, 0); - this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(58, 13); - this.label12.TabIndex = 0; - this.label12.Text = "Username:"; - // - // txtluser - // - this.txtluser.Location = new System.Drawing.Point(109, 3); - this.txtluser.Name = "txtluser"; - this.txtluser.Size = new System.Drawing.Size(100, 20); - this.txtluser.TabIndex = 1; - // - // label13 - // - this.label13.AutoSize = true; - this.label13.Location = new System.Drawing.Point(3, 26); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(56, 13); - this.label13.TabIndex = 2; - this.label13.Text = "Password:"; - // - // txtlpass - // - this.txtlpass.Location = new System.Drawing.Point(109, 29); - this.txtlpass.Name = "txtlpass"; - this.txtlpass.PasswordChar = '*'; - this.txtlpass.Size = new System.Drawing.Size(100, 20); - this.txtlpass.TabIndex = 3; - // - // label15 - // - this.label15.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.label15.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F); - this.label15.Location = new System.Drawing.Point(16, 9); - this.label15.Name = "label15"; - this.label15.Size = new System.Drawing.Size(321, 26); - this.label15.TabIndex = 3; - this.label15.Text = "User information"; - // - // button1 - // - this.button1.Location = new System.Drawing.Point(129, 142); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 21); - this.button1.TabIndex = 4; - this.button1.Text = "Register"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); - // - // btnnlogin - // - this.btnnlogin.Location = new System.Drawing.Point(129, 156); - this.btnnlogin.Name = "btnnlogin"; - this.btnnlogin.Size = new System.Drawing.Size(75, 23); - this.btnnlogin.TabIndex = 5; - this.btnnlogin.Text = "Log in"; - this.btnnlogin.UseVisualStyleBackColor = true; - this.btnnlogin.Click += new System.EventHandler(this.btnnlogin_Click); - // - // FakeSetupScreen - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(490, 329); - this.Controls.Add(this.pglogin); - this.Controls.Add(this.page3); - this.Controls.Add(this.pgrereg); - this.Controls.Add(this.page4); - this.Controls.Add(this.page2); - this.Controls.Add(this.page1); - this.Controls.Add(this.pnlheader); - this.Controls.Add(this.flbuttons); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "FakeSetupScreen"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "ShiftOS"; - this.TopMost = true; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FakeSetupScreen_FormClosing); - this.flbuttons.ResumeLayout(false); - this.page1.ResumeLayout(false); - this.page2.ResumeLayout(false); - this.page2.PerformLayout(); - this.page3.ResumeLayout(false); - this.page3.PerformLayout(); - this.tableLayoutPanel1.ResumeLayout(false); - this.tableLayoutPanel1.PerformLayout(); - this.page4.ResumeLayout(false); - this.pgrereg.ResumeLayout(false); - this.pgrereg.PerformLayout(); - this.tableLayoutPanel2.ResumeLayout(false); - this.tableLayoutPanel2.PerformLayout(); - this.pglogin.ResumeLayout(false); - this.pglogin.PerformLayout(); - this.tableLayoutPanel3.ResumeLayout(false); - this.tableLayoutPanel3.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Panel pnlheader; - private System.Windows.Forms.FlowLayoutPanel flbuttons; - private System.Windows.Forms.Button btnnext; - private System.Windows.Forms.Button btnback; - private System.Windows.Forms.Panel page1; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Panel page2; - private System.Windows.Forms.Label lbformattitle; - private System.Windows.Forms.Label lbbyteszeroed; - private System.Windows.Forms.ProgressBar pgformatprogress; - private System.Windows.Forms.Panel page3; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.TextBox txtnewusername; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.TextBox txtnewpassword; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.TextBox txtnewsysname; - private System.Windows.Forms.Panel page4; - private System.Windows.Forms.RichTextBox txtlicenseagreement; - private System.Windows.Forms.Label label10; - private System.Windows.Forms.Panel pgrereg; - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.TextBox txtruname; - private System.Windows.Forms.Label label8; - private System.Windows.Forms.TextBox txtrpass; - private System.Windows.Forms.Label label9; - private System.Windows.Forms.TextBox txtrsys; - private System.Windows.Forms.Label label11; - private System.Windows.Forms.Panel pglogin; - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; - private System.Windows.Forms.Label label12; - private System.Windows.Forms.TextBox txtluser; - private System.Windows.Forms.Label label13; - private System.Windows.Forms.TextBox txtlpass; - private System.Windows.Forms.Label label15; - private System.Windows.Forms.Button button1; - private System.Windows.Forms.Button btnnlogin; - } -} \ No newline at end of file diff --git a/ShiftOS.WinForms/FakeSetupScreen.cs b/ShiftOS.WinForms/FakeSetupScreen.cs deleted file mode 100644 index f62c777..0000000 --- a/ShiftOS.WinForms/FakeSetupScreen.cs +++ /dev/null @@ -1,395 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Forms; -using Newtonsoft.Json; -using ShiftOS.Engine; - -namespace ShiftOS.WinForms -{ - public partial class FakeSetupScreen : Form - { - private Oobe oobe = null; - - public Action MUDUserFound = null; - - public FakeSetupScreen(Oobe _oobe, int page = 0) - { - oobe = _oobe; - InitializeComponent(); - currentPage = page; - SetupUI(); - ServerManager.MessageReceived += (msg) => - { - if (this.Visible == true) - { - if (msg.Name == "mud_notfound") - this.Invoke(new Action(() => { MUDUserFound?.Invoke(false); })); - else if (msg.Name == "mud_found") - this.Invoke(new Action(() => { MUDUserFound?.Invoke(true); })); - } - }; - } - - public event Action TextSent; - bool isTyping = false; - - private int currentPage = 0; - - public void SetupUI() - { - btnback.Show(); - pnlheader.Dock = DockStyle.Top; - pnlheader.Height = 50; - switch (currentPage) - { - case 0: - page1.BringToFront(); - pnlheader.Dock = DockStyle.Left; - pnlheader.Width = 100; - btnback.Hide(); - break; - case 1: - btnnext.Hide(); - btnback.Hide(); - page2.BringToFront(); - pgformatprogress.Value = 0; - var dinf = new System.IO.DriveInfo("C:"); - StartWipingInBackground(((dinf.TotalSize / 1024) / 1024) / 1024); - TextType($@"So I see you're progressing through. -I really hope you aren't one of those newbies who just next-next-next-finish their way through these things. -I see you've named your drive " + dinf.VolumeLabel + $@" -And it can contain up to {dinf.TotalSize} bytes of information. -And you've formatted this drive with a partition of type " + dinf.DriveFormat + $@". -Interesting... -Very interesting..."); - break; - case 2: - btnnext.Show(); - btnback.Hide(); - TextType(@"Now it's all gone. Now I need some user input so I can install ShiftOS. -Firstly, please enter a username, password, and system name. -Make the username and system name unique so I can identify exactly who you are. You're not the only one here. -Also, make sure the password is secure... There have been people known to breach users' accounts in ShiftOS and steal their stuff. -So make sure your password is secure enough that it can't be guessed, but easy for you to remember, and don't put any personal information in your account."); - page3.BringToFront(); - break; - case 3: - if (string.IsNullOrEmpty(txtnewusername.Text)) - { - TextType("You must specify a valid username!"); - currentPage--; - //SetupUI(); - break; - } - - if (string.IsNullOrEmpty(txtnewpassword.Text)) - { - TextType("A password would seriously be recommended."); - currentPage--; - //SetupUI(); - break; - } - - if (string.IsNullOrEmpty(txtnewsysname.Text)) - { - TextType("You must name your computer."); - currentPage--; - //SetupUI(); - break; - } - - - MUDUserFound = (val) => - { - if(val == true) - { - TextType("I have just verified that your username and password already exists on my end. Please choose another."); - currentPage--; - //SetupUI(); - - } - else - { - TextType("I am going to keep that info on my checklist for installing ShiftOS on your system. Now, onto some legal stuff. I highly suggest you read this."); - currentPage++; - oobe.MySave.Username = txtnewusername.Text; - oobe.MySave.Password = txtnewpassword.Text; - oobe.MySave.SystemName = txtnewsysname.Text; - SetupUI(); - } - }; - ServerManager.SendMessage("mud_checkuserexists", $@"{{ - username: ""{txtnewusername.Text}"", - password: ""{txtnewpassword.Text}"" -}}"); - break; - case 4: - page4.BringToFront(); - txtlicenseagreement.Rtf = Properties.Resources.ShiftOS; - break; - case 5: - CanClose = true; - this.Close(); - break; - case 7: - btnnext.Show(); - btnback.Hide(); - pgrereg.BringToFront(); - TextType("You have two choices - either you can migrate your local user file to this multi-user domain, or you can restart with 0 Codepoints, no upgrades, and still keep your files."); - break; - case 8: - btnnext.Hide(); - ServerMessageReceived rc = null; - - rc = (msg) => - { - if(msg.Name == "mud_found") - { - TextType("That username and password already exists in this multi-user domain. Please choose another."); - currentPage = 7; - } - else if(msg.Name == "mud_notfound") - { - currentPage = 9; - SetupUI(); - } - ServerManager.MessageReceived -= rc; - }; - - if (string.IsNullOrEmpty(txtruname.Text)) - { - TextType("You must provide a username."); - currentPage = 7; - } - - if (string.IsNullOrEmpty(txtrpass.Text)) - { - TextType("You must provide a password."); - currentPage = 7; - } - - if (string.IsNullOrEmpty(txtrsys.Text)) - { - TextType("You must provide a system hostname."); - currentPage = 7; - } - - if (currentPage == 7) - return; - - ServerManager.MessageReceived += rc; - ServerManager.SendMessage("mud_checkuserexists", $@"{{ - username: ""{txtruname.Text}"", - password: ""{txtrpass.Text}"" -}}"); - break; - case 9: - UserReregistered?.Invoke(txtruname.Text, txtrpass.Text, txtrsys.Text); - this.CanClose = true; - this.Close(); - break; - case 10: - btnnext.Show(); - btnback.Hide(); - pglogin.BringToFront(); - break; - case 11: - btnnext.Hide(); - ServerMessageReceived login = null; - - login = (msg) => - { - if (msg.Name == "mud_found") - { - this.Invoke(new Action(() => - { - currentPage = 12; - SetupUI(); - })); - - ServerManager.MessageReceived -= login; - } - else if (msg.Name == "mud_notfound") - { - this.Invoke(new Action(() => - { - currentPage = 10; - SetupUI(); - })); - - ServerManager.MessageReceived -= login; - } - }; - - ServerManager.MessageReceived += login; - if(!string.IsNullOrWhiteSpace(txtluser.Text) && !string.IsNullOrWhiteSpace(txtlpass.Text)) - { - ServerManager.SendMessage("mud_checkuserexists", JsonConvert.SerializeObject(new - { - username = txtluser.Text, - password = txtlpass.Text - })); - } - break; - case 12: - btnnext.Hide(); - ServerMessageReceived getsave = null; - - getsave = (msg) => - { - if (msg.Name == "mud_savefile") - { - this.Invoke(new Action(() => - { - SaveSystem.CurrentSave = JsonConvert.DeserializeObject(msg.Contents); - SaveSystem.SaveGame(); - CreateNewSave = false; - DoneLoggingIn?.Invoke(); - this.CanClose = true; - this.Close(); - - })); - } - else if (msg.Name == "mud_notfound") - { - this.Invoke(new Action(() => - { - currentPage = 10; - SetupUI(); - })); - } - ServerManager.MessageReceived -= getsave; - }; - - ServerManager.MessageReceived += getsave; - - ServerManager.SendMessage("mud_login", JsonConvert.SerializeObject(new - { - username = txtluser.Text, - password = txtlpass.Text - })); - - break; - } - } - - public event Action DoneLoggingIn; - - public bool CreateNewSave = true; - - public event Action UserReregistered; - - public void StartWipingInBackground(long arbitraryAmountOfBytes) - { - pgformatprogress.Maximum = (int)arbitraryAmountOfBytes; - var t = new Thread(() => - { - for(long i = 0; i <= arbitraryAmountOfBytes; i++) - { - Thread.Sleep(40); - this.Invoke(new Action(() => - { - pgformatprogress.Value = (int)i; - lbbyteszeroed.Text = $"Gigabytes zeroed: {i}/{arbitraryAmountOfBytes}"; - })); - } - this.Invoke(new Action(() => - { - currentPage++; - SetupUI(); - })); - }); - t.IsBackground = true; - t.Start(); - } - - - - private void TextType(string text) - { - new Thread(() => - { - while(isTyping == true) - { - - } - isTyping = true; - TextSent?.Invoke(text); - isTyping = false; - }).Start(); - } - - bool CanClose = false; - - private void FakeSetupScreen_FormClosing(object sender, FormClosingEventArgs e) - { - if (CanClose) - { - - } - else - { - e.Cancel = true; - TextType("Don't try to close the dialog. It's a futile attempt."); - } - } - - private void btnback_Click(object sender, EventArgs e) - { - currentPage--; - SetupUI(); - } - - private void btnnext_Click(object sender, EventArgs e) - { - currentPage++; - SetupUI(); - } - - private void button1_Click(object sender, EventArgs e) - { - ShiftOS.Objects.ShiftFS.Utils.Delete(Paths.GetPath("user.dat")); - System.IO.File.WriteAllText(Paths.SaveFile, ShiftOS.Objects.ShiftFS.Utils.ExportMount(0)); - SaveSystem.NewSave(); - this.CanClose = true; - this.Close(); - } - - private void btnnlogin_Click(object sender, EventArgs e) - { - currentPage = 10; - SetupUI(); - } - } -} diff --git a/ShiftOS.WinForms/FakeSetupScreen.resx b/ShiftOS.WinForms/FakeSetupScreen.resx deleted file mode 100644 index 1af7de1..0000000 --- a/ShiftOS.WinForms/FakeSetupScreen.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/ShiftOS.WinForms/Oobe.cs b/ShiftOS.WinForms/Oobe.cs index 54a022c..a4d63e0 100644 --- a/ShiftOS.WinForms/Oobe.cs +++ b/ShiftOS.WinForms/Oobe.cs @@ -185,39 +185,7 @@ You must join the digital society, rise up the ranks, and save us. public void ShowSaveTransfer(Save save) { - this.Show(); - var fSetup = new FakeSetupScreen(this, 7); - - var t = new Thread(() => - { - textgeninput = lblhackwords; - Clear(); - TextType("Welcome back to ShiftOS."); - Thread.Sleep(500); - TextType("Since your last time inside ShiftOS, the operating system has changed. Your user account is no longer stored on your local system."); - Thread.Sleep(500); - this.Invoke(new Action(() => - { - //UPS is drunky heaven over here... it's a liquor store, I think... - Drunk Michael - fSetup.UserReregistered += (u, p, s) => - { - save.Username = u; - save.Password = p; - save.SystemName = s; - SaveSystem.CurrentSave = save; - SaveSystem.CurrentSave.Upgrades = new Dictionary(); - Shiftorium.Init(); - - SaveSystem.SaveGame(); - if(Utils.FileExists(Paths.SaveFileInner)) - Utils.Delete(Paths.SaveFileInner); - this.Close(); - }; - fSetup.Show(); - })); - }); - t.IsBackground = true; - t.Start(); + //Stub. } public void PerformUniteLogin() diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 1d4e91a..9fc237f 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -316,12 +316,6 @@ DownloadControl.cs - - Form - - - FakeSetupScreen.cs - @@ -517,9 +511,6 @@ DownloadControl.cs - - FakeSetupScreen.cs - Oobe.cs diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index d7c5196..6825f34 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -52,7 +52,6 @@ namespace ShiftOS.WinForms public List Widgets = new List(); - private bool InScreensaver = false; private int millisecondsUntilScreensaver = 300000; /// @@ -231,13 +230,11 @@ namespace ShiftOS.WinForms if(millisecondsUntilScreensaver <= 0) { ShowScreensaver(); - InScreensaver = true; } millisecondsUntilScreensaver--; Thread.Sleep(1); } millisecondsUntilScreensaver = 300000; - InScreensaver = false; HideScreensaver(); } }); @@ -990,7 +987,7 @@ namespace ShiftOS.WinForms { if (Shiftorium.UpgradeInstalled("advanced_app_launcher")) { - lbalstatus.Text = $@"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName} + lbalstatus.Text = $@"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName} {SaveSystem.CurrentSave.Codepoints} Codepoints {Shiftorium.GetAvailable().Length} available, {SaveSystem.CurrentSave.CountUpgrades()} installed."; diff --git a/ShiftOS_TheReturn/CommandParser.cs b/ShiftOS_TheReturn/CommandParser.cs index 7a190df..868d27a 100644 --- a/ShiftOS_TheReturn/CommandParser.cs +++ b/ShiftOS_TheReturn/CommandParser.cs @@ -98,8 +98,6 @@ namespace ShiftOS.Engine int firstValuePos = -1; int lastValuePos = -1; - string syntaxError = ""; - for (int ii = 0; ii < parts.Count; ii++) { CommandFormat part = parts[ii]; @@ -184,7 +182,6 @@ namespace ShiftOS.Engine else { position = text.Length; - syntaxError = "Syntax Error"; command = "+FALSE+"; } help = -1; diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 7980635..87aacd6 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -73,7 +73,7 @@ namespace ShiftOS.Engine TerminalBackend.IsForwardingConsoleWrites = forwarding; TerminalBackend.ForwardGUID = (forwarding == true) ? fGuid : null; string resultFriendly = (result == true) ? "yes" : "no"; - Console.WriteLine($"{SaveSystem.CurrentSave.Username} says {resultFriendly}."); + Console.WriteLine($"{SaveSystem.CurrentUser.Username} says {resultFriendly}."); TerminalBackend.IsForwardingConsoleWrites = false; }; Desktop.InvokeOnWorkerThread(new Action(() => -- cgit v1.2.3 From 94e1603b8574b45b809d3c66b6b90e7734a99d1e Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 12 May 2017 21:22:08 -0400 Subject: Post-intro tutorial --- ShiftOS.WinForms/Applications/Terminal.cs | 130 +++++++++++++++++++++++++++--- ShiftOS.WinForms/Controls/TerminalBox.cs | 4 + ShiftOS_TheReturn/TerminalBackend.cs | 61 +++++++------- 3 files changed, 156 insertions(+), 39 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 32c5363..a14cc58 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -132,23 +132,31 @@ namespace ShiftOS.WinForms.Applications { ResetAllKeywords(); rtbterm.Text = ""; - if (!Shiftorium.UpgradeInstalled("desktop")) + if (Shiftorium.UpgradeInstalled("first_steps")) { - TerminalBackend.PrefixEnabled = true; - TerminalBackend.InStory = false; - TerminalBackend.PrintPrompt(); - if (Shiftorium.UpgradeInstalled("wm_free_placement")) + if (!Shiftorium.UpgradeInstalled("desktop")) { - this.ParentForm.Width = 640; - this.ParentForm.Height = 480; - this.ParentForm.Left = (Screen.PrimaryScreen.Bounds.Width - 640) / 2; - this.ParentForm.Top = (Screen.PrimaryScreen.Bounds.Height - 480) / 2; + TerminalBackend.PrefixEnabled = true; + TerminalBackend.InStory = false; + TerminalBackend.PrintPrompt(); + if (Shiftorium.UpgradeInstalled("wm_free_placement")) + { + this.ParentForm.Width = 640; + this.ParentForm.Height = 480; + this.ParentForm.Left = (Screen.PrimaryScreen.Bounds.Width - 640) / 2; + this.ParentForm.Top = (Screen.PrimaryScreen.Bounds.Height - 480) / 2; + } + } + else + { + AppearanceManager.Close(this); } } else { - AppearanceManager.Close(this); + Story.Start("first_steps"); + } })); } @@ -434,6 +442,108 @@ namespace ShiftOS.WinForms.Applications }).Start(); } + [Story("first_steps")] + public static void FirstSteps() + { + new Thread(() => + { + TerminalBackend.InStory = true; + Console.WriteLine("Hey there, and welcome to ShiftOS."); + Thread.Sleep(2000); + Console.WriteLine("My name is DevX. I am the developer of this operating system."); + Thread.Sleep(2000); + Console.WriteLine("Right now, I am using the Terminal application as a means of talking to you."); + Thread.Sleep(2000); + Console.WriteLine("ShiftOS is a very early operating system, but I have big plans for it."); + Thread.Sleep(2000); + Console.WriteLine("I can't reveal all my plans to you at this moment, but you play a big role."); + Thread.Sleep(2000); + Console.WriteLine("Your role in all of this is to help me develop ShiftOS more."); + Thread.Sleep(2000); + Console.WriteLine("You may not know how to program, but that's perfectly fine. You don't need to."); + Thread.Sleep(2000); + Console.WriteLine("What you do need to do, is simply use the operating system - like you would a regular computer."); + Thread.Sleep(2000); + Console.WriteLine("As you use ShiftOS, you will earn a special currency called Codepoints."); + Thread.Sleep(2000); + Console.WriteLine("The more things you do, the more Codepoints you get! Simple, right?"); + Thread.Sleep(2000); + Console.WriteLine("Once you rack up enough Codepoints, you can use them inside the Shiftorium to buy new features for ShiftOS."); + Thread.Sleep(2000); + Console.WriteLine("These features include new programs, system enhancements, Terminal commands, and so much more!"); + Thread.Sleep(2000); + Console.WriteLine("Ahh, that reminds me. I suppose you don't know how to use the Terminal yet, do you..."); + Thread.Sleep(2000); + Console.WriteLine("Well, the ShiftOS terminal is similar to a regular Linux terminal, however things are a bit... how you say.... primitive."); + Thread.Sleep(2000); + Console.WriteLine("Let's just say.... I've been focusing more on function than form with this one.... Anyways, here's how the terminal works."); + Thread.Sleep(2000); + Console.WriteLine("Each command is categorized into a \"Namespace\". All a namespace is, is a nice way of distinguishing between commands."); + Thread.Sleep(2000); + Console.WriteLine("...For example you may have a bunch of commands for managing files, and others for opening/closing programs."); + Thread.Sleep(2000); + Console.WriteLine("The three main namespaces you'll be using for the next while are the \"sos\", \"shiftorium\", and \"win\" namespaces."); + Thread.Sleep(2000); + Console.WriteLine("To run a command, simply type its namespace, followed by a period/full-stop, followed by the command name."); + Thread.Sleep(2000); + Console.WriteLine("Give it a try! Type \"sos.help\" in the following prompt to view a list of all ShiftOS commands."); + Thread.Sleep(2000); + TerminalBackend.InStory = false; + TerminalBackend.PrintPrompt(); + bool help_entered = false; + TerminalBackend.TextSent += (text) => + { + if (text == "sos.help" && help_entered == false) + help_entered = true; + }; + while (help_entered == false) + Thread.Sleep(10); + TerminalBackend.InStory = true; + Thread.Sleep(2000); + Console.WriteLine("Good job! Next, we will look at how to pass data to a command, such as win.open."); + Thread.Sleep(2000); + Console.WriteLine("In ShiftOS, passing data to a command is quite simple! After the command name, place an opening and closing curly brace, like so: \"win.open{}\"."); + Thread.Sleep(2000); + Console.WriteLine("Everything between those two curly braces is treated as command data."); + Thread.Sleep(2000); + Console.WriteLine("However, you can't just spam a bunch of 1s and 0s and call it a day, nonono!"); + Thread.Sleep(2000); + Console.WriteLine("Command data is split into a list of keys and values."); + Thread.Sleep(2000); + Console.WriteLine("The key tells the command the name of the data, and the value is what the command will see when it looks at the key."); + Thread.Sleep(2000); + Console.WriteLine("There are three main types of values. Booleans, which can be either \"true\" or \"false\", Numbers, which can be any integer number, positive or negative, and Strings - any piece of text as long as it is surrounded by double-quotes."); + Thread.Sleep(2000); + Console.WriteLine("For example, we could write every programmer's first program - by typing \"trm.echo{msg:\"Hello, world!\"}\". Running this will cause the Terminal to print, well, \"Hello, world!\""); + Thread.Sleep(2000); + Console.WriteLine("To open an application in ShiftOS, you can use this principle with the \"win.open\" command."); + Thread.Sleep(2000); + Console.WriteLine("First, type \"win.open\" with no data to see a list of all installed programs."); + Thread.Sleep(2000); + TerminalBackend.InStory = false; + bool winopenEntered = false; + TerminalBackend.PrintPrompt(); + TerminalBackend.TextSent += (text) => + { + if (help_entered == true) + if (text == "win.open" && winopenEntered == false) + winopenEntered = true; + }; + while (winopenEntered == false) + Thread.Sleep(10); + TerminalBackend.InStory = true; + Thread.Sleep(2000); + Console.WriteLine("Pretty cool, it gave you a nice list of other win.open commands that will let you open each program."); + Thread.Sleep(2000); + Console.WriteLine("I'll leave you to it, you've got the hang of it! One last thing, if ever you find yourself in another program, and want to exit, simply press CTRL+T to return to the Terminal."); + Thread.Sleep(2000); + + TerminalBackend.InStory = false; + TerminalBackend.PrintPrompt(); + SaveSystem.SaveGame(); + }).Start(); + } + public void OnSkinLoad() { try diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index ea7808c..e95d038 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -63,12 +63,14 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { + this.SuspendLayout(); this.HideSelection = true; this.SelectionFont = ConstructFont(); this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text)); this.HideSelection = false; + this.ResumeLayout(); } private Font ConstructFont() @@ -86,6 +88,7 @@ namespace ShiftOS.WinForms.Controls public void WriteLine(string text) { + this.SuspendLayout(); Engine.AudioManager.PlayStream(Properties.Resources.writesound); this.HideSelection = true; this.Select(this.TextLength, 0); @@ -94,6 +97,7 @@ namespace ShiftOS.WinForms.Controls this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text) + Environment.NewLine); this.HideSelection = false; + this.ResumeLayout(); } bool quickCopying = false; diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 086ff40..87bd24a 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -424,35 +424,38 @@ namespace ShiftOS.Engine { if (SaveSystem.CurrentSave != null && CurrentUser != null) { - ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC; - ConsoleEx.Italic = false; - ConsoleEx.Underline = false; - - ConsoleEx.ForegroundColor = ConsoleColor.Magenta; - ConsoleEx.Bold = true; - - Console.Write(SaveSystem.CurrentUser.Username); - ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = ConsoleColor.Gray; - Console.Write("@"); - ConsoleEx.Italic = true; - ConsoleEx.Bold = true; - ConsoleEx.ForegroundColor = ConsoleColor.Yellow; - Console.Write(SaveSystem.CurrentSave.SystemName); - ConsoleEx.Italic = false; - ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = ConsoleColor.Gray; - Console.Write(":~"); - Console.ForegroundColor = ConsoleColor.White; - ConsoleEx.Italic = true; - if (KernelWatchdog.InKernelMode == true) - Console.Write("#"); - else - Console.Write("$"); - ConsoleEx.Italic = false; - ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; - Console.Write(" "); + Desktop.InvokeOnWorkerThread(() => + { + ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC; + ConsoleEx.Italic = false; + ConsoleEx.Underline = false; + + ConsoleEx.ForegroundColor = ConsoleColor.Magenta; + ConsoleEx.Bold = true; + + Console.Write(SaveSystem.CurrentUser.Username); + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + Console.Write("@"); + ConsoleEx.Italic = true; + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.Yellow; + Console.Write(SaveSystem.CurrentSave.SystemName); + ConsoleEx.Italic = false; + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + Console.Write(":~"); + Console.ForegroundColor = ConsoleColor.White; + ConsoleEx.Italic = true; + if (KernelWatchdog.InKernelMode == true) + Console.Write("#"); + else + Console.Write("$"); + ConsoleEx.Italic = false; + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; + Console.Write(" "); + }); } } -- cgit v1.2.3 From c0f0e99f9d2a092209e710107c1f061fc8a2eaca Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 13 May 2017 10:22:51 -0400 Subject: Dithering, audio volume, and fix shutdown bug --- ShiftOS.Objects/Save.cs | 3 + ShiftOS.WinForms/Applications/Terminal.cs | 8 +- ShiftOS.WinForms/AudioManager.cs | 27 +++-- ShiftOS.WinForms/Program.cs | 6 +- ShiftOS.WinForms/Tools/DitheringEngine.cs | 160 ++++++++++++++++++++---------- ShiftOS_TheReturn/AppearanceManager.cs | 1 + ShiftOS_TheReturn/AudioManager.cs | 8 +- ShiftOS_TheReturn/Commands.cs | 34 +++++++ 8 files changed, 175 insertions(+), 72 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 2a02bbc..cc19c79 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -35,6 +35,9 @@ namespace ShiftOS.Objects public class Save { + public int MusicVolume { get; set; } + public int SfxVolume { get; set; } + [Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")] public string Username { get; set; } diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index a14cc58..02c4cc0 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -491,9 +491,9 @@ namespace ShiftOS.WinForms.Applications TerminalBackend.InStory = false; TerminalBackend.PrintPrompt(); bool help_entered = false; - TerminalBackend.TextSent += (text) => + TerminalBackend.CommandProcessed += (text, args) => { - if (text == "sos.help" && help_entered == false) + if (text.EndsWith("sos.help") && help_entered == false) help_entered = true; }; while (help_entered == false) @@ -523,10 +523,10 @@ namespace ShiftOS.WinForms.Applications TerminalBackend.InStory = false; bool winopenEntered = false; TerminalBackend.PrintPrompt(); - TerminalBackend.TextSent += (text) => + TerminalBackend.CommandProcessed += (text, args) => { if (help_entered == true) - if (text == "win.open" && winopenEntered == false) + if (text.EndsWith("win.open") && winopenEntered == false) winopenEntered = true; }; while (winopenEntered == false) diff --git a/ShiftOS.WinForms/AudioManager.cs b/ShiftOS.WinForms/AudioManager.cs index eb0e798..ec12614 100644 --- a/ShiftOS.WinForms/AudioManager.cs +++ b/ShiftOS.WinForms/AudioManager.cs @@ -74,7 +74,19 @@ namespace ShiftOS.WinForms MemoryStream str = null; NAudio.Wave.Mp3FileReader mp3 = null; NAudio.Wave.WaveOut o = null; - while (!Engine.SaveSystem.ShuttingDown) + bool shuttingDown = false; + + Engine.AppearanceManager.OnExit += () => + { + shuttingDown = true; + o?.Stop(); + o?.Dispose(); + mp3?.Close(); + mp3?.Dispose(); + str?.Close(); + str?.Dispose(); + }; + while (shuttingDown == false) { str = new MemoryStream(GetRandomSong()); mp3 = new NAudio.Wave.Mp3FileReader(str); @@ -87,14 +99,15 @@ namespace ShiftOS.WinForms c = true; }; while (!c) + { + try + { + o.Volume = (float)Engine.SaveSystem.CurrentSave.MusicVolume / 100; + } + catch { } Thread.Sleep(10); - str.Dispose(); - o.Dispose(); - mp3.Dispose(); + } } - str?.Dispose(); - o?.Dispose(); - mp3?.Dispose(); }); athread.IsBackground = true; athread.Start(); diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs index 73215d4..8f65265 100644 --- a/ShiftOS.WinForms/Program.cs +++ b/ShiftOS.WinForms/Program.cs @@ -68,11 +68,7 @@ namespace ShiftOS.WinForms SkinEngine.SetIconProber(new ShiftOSIconProvider()); ShiftOS.Engine.AudioManager.Init(new ShiftOSAudioProvider()); Localization.RegisterProvider(new WFLanguageProvider()); - AppearanceManager.OnExit += () => - { - Environment.Exit(0); - }; - + TutorialManager.RegisterTutorial(new Oobe()); TerminalBackend.TerminalRequested += () => diff --git a/ShiftOS.WinForms/Tools/DitheringEngine.cs b/ShiftOS.WinForms/Tools/DitheringEngine.cs index f96a45a..d042a40 100644 --- a/ShiftOS.WinForms/Tools/DitheringEngine.cs +++ b/ShiftOS.WinForms/Tools/DitheringEngine.cs @@ -226,6 +226,53 @@ namespace ShiftOS.WinForms.Tools } #endif + public static int GetClosestColor(int gray, bool eightBits, bool sixBits, bool fourBits, bool twoBits) + { + int newgray = gray; + if (!eightBits) + { + if (sixBits) + { + newgray = gray >> 2; + } + else + { + if (fourBits) + { + newgray = (int)linear(gray, 0, 255, 0, 15) * 4; + } + else + { + if (twoBits) + { + if (gray > 127 + 63) + { + newgray = 255; + } + else if (gray > 127) + newgray = 127 + 63; + else if (gray > 63) + { + newgray = 127; + } + else if (gray > 0) + newgray = 63; + else + newgray = 0; + } + else + { + if (gray > 127) + newgray = 255; + else + newgray = 0; + } + } + } + } + return newgray; + } + #if FLOYDSTEINBERG public static Image DitherImage(Image source) { @@ -260,75 +307,78 @@ namespace ShiftOS.WinForms.Tools bool eightBits = Shiftorium.UpgradeInstalled("color_depth_8_bits"); bool color_depth_floydsteinberg = Shiftorium.UpgradeInstalled("color_depth_floyd-steinberg_dithering"); bool dithering = Shiftorium.UpgradeInstalled("color_depth_dithering"); - - if (!sixteenBits) + bool twentyfourbits = Shiftorium.UpgradeInstalled("color_depth_24_bits"); + if (twentyfourbits) + { + sourceArr.CopyTo(destArr, 0); + } + else { - if (dithering == true) + + if (!sixteenBits) { - if (false == true) + if (dithering == true) { + if (false == true) + { + + } + else + { + int error = 0; + for (int i = 0; i < destArr.Length; i += 3) + { + byte r = sourceArr[i]; + byte g = sourceArr[i + 1]; + byte b = sourceArr[i + 2]; + + if (SkinEngine.LoadedSkin.SystemKey == Color.FromArgb(r, g, b)) + { + destArr[i] = r; + destArr[i + 1] = g; + destArr[i + 2] = b; + continue; + } + + int gray = (((r + g + b) / 3) + error); + int newgray = gray; + newgray = GetClosestColor(gray, eightBits, sixBits, fourBits, twoBits); + if (newgray > 255) + newgray = 255; + if (newgray < 0) + newgray = 0; + error = gray - newgray; + destArr[i] = (byte)newgray; + destArr[i + 1] = (byte)newgray; + destArr[i + 2] = (byte)newgray; + + } + } } + else { - int error = 0; - for (int i = 0; i < destArr.Length; i += 3) + for (int i = 0; i < sourceArr.Length; i += 3) { byte r = sourceArr[i]; byte g = sourceArr[i + 1]; byte b = sourceArr[i + 2]; - - int gray = (((r + g + b) / 3) + error); - int newgray = gray; - if (!eightBits) + if (SkinEngine.LoadedSkin.SystemKey == Color.FromArgb(r, g, b)) { - if (sixBits) - { - newgray = gray >> 2; - } - else - { - if (fourBits) - { - newgray = (int)linear(gray, 0, 255, 0, 63) * 4; - } - else - { - if (twoBits) - { - if (gray > 127 + 63) - { - newgray = 255; - } - else if (gray > 127) - newgray = 127 + 63; - else if (gray > 63) - { - newgray = 127; - } - else if (gray > 0) - newgray = 63; - else - newgray = 0; - } - else - { - if (gray > 127) - newgray = 255; - else - newgray = 0; - } - } - } + destArr[i] = r; + destArr[i + 1] = g; + destArr[i + 2] = b; + continue; } - if (newgray > 255) - newgray = 255; - if (newgray < 0) - newgray = 0; - error = gray - newgray; + + int gray = (r + g + b) / 3; + int newgray = GetClosestColor(gray, eightBits, sixBits, fourBits, twoBits); destArr[i] = (byte)newgray; - destArr[i+1] = (byte)newgray; - destArr[i+2] = (byte)newgray; + destArr[i + 1] = (byte)newgray; + destArr[i + 2] = (byte)newgray; + + } } diff --git a/ShiftOS_TheReturn/AppearanceManager.cs b/ShiftOS_TheReturn/AppearanceManager.cs index 42642f8..d8004bc 100644 --- a/ShiftOS_TheReturn/AppearanceManager.cs +++ b/ShiftOS_TheReturn/AppearanceManager.cs @@ -223,6 +223,7 @@ namespace ShiftOS.Engine /// internal static void Exit() { + OnExit?.Invoke(); //disconnect from MUD ServerManager.Disconnect(); Environment.Exit(0); diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index c50bd24..fff3369 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -88,7 +88,13 @@ namespace ShiftOS.Engine _reader = new AudioFileReader(file); _out = new WaveOut(); _out.Init(_reader); - _out.Volume = _provider.Volume; + try + { + _out.Volume = (float)SaveSystem.CurrentSave.SfxVolume / 100; + } + catch + { + } _out.Play(); _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); }; } diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 5b7674a..6e59311 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -378,6 +378,40 @@ namespace ShiftOS.Engine [Namespace("sos")] public static class ShiftOSCommands { + [Command("setsfxvolume", description = "Set the volume of various sound effects to a value between 1 and 100.")] + [RequiresArgument("value")] + public static bool SetSfxVolume(Dictionary args) + { + int value = int.Parse(args["value"].ToString()); + if (value >= 0 && value <= 100) + { + SaveSystem.CurrentSave.SfxVolume = value; + SaveSystem.SaveGame(); + } + else + { + Console.WriteLine("Volume must be between 0 and 100!"); + } + return true; + } + + [Command("setmusicvolume", description ="Set the music volume to a value between 1 and 100.")] + [RequiresArgument("value")] + public static bool SetMusicVolume(Dictionary args) + { + int value = int.Parse(args["value"].ToString()); + if(value >= 0 && value <= 100) + { + SaveSystem.CurrentSave.MusicVolume = value; + SaveSystem.SaveGame(); + } + else + { + Console.WriteLine("Volume must be between 0 and 100!"); + } + return true; + } + [RemoteLock] [Command("shutdown")] public static bool Shutdown() -- cgit v1.2.3 From 46a92866f8ac757bd236746be7ed11a1a0c39f86 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 18 May 2017 18:56:58 -0400 Subject: fix beta 2.5 first_steps --- ShiftOS.WinForms/Applications/Terminal.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 02c4cc0..8fa785a 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -445,6 +445,7 @@ namespace ShiftOS.WinForms.Applications [Story("first_steps")] public static void FirstSteps() { + TerminalBackend.PrefixEnabled = false; new Thread(() => { TerminalBackend.InStory = true; @@ -489,6 +490,7 @@ namespace ShiftOS.WinForms.Applications Console.WriteLine("Give it a try! Type \"sos.help\" in the following prompt to view a list of all ShiftOS commands."); Thread.Sleep(2000); TerminalBackend.InStory = false; + TerminalBackend.PrefixEnabled = true; TerminalBackend.PrintPrompt(); bool help_entered = false; TerminalBackend.CommandProcessed += (text, args) => @@ -499,6 +501,7 @@ namespace ShiftOS.WinForms.Applications while (help_entered == false) Thread.Sleep(10); TerminalBackend.InStory = true; + TerminalBackend.PrefixEnabled = false; Thread.Sleep(2000); Console.WriteLine("Good job! Next, we will look at how to pass data to a command, such as win.open."); Thread.Sleep(2000); @@ -522,6 +525,7 @@ namespace ShiftOS.WinForms.Applications Thread.Sleep(2000); TerminalBackend.InStory = false; bool winopenEntered = false; + TerminalBackend.PrefixEnabled = true; TerminalBackend.PrintPrompt(); TerminalBackend.CommandProcessed += (text, args) => { @@ -532,15 +536,18 @@ namespace ShiftOS.WinForms.Applications while (winopenEntered == false) Thread.Sleep(10); TerminalBackend.InStory = true; + TerminalBackend.PrefixEnabled = false; + Thread.Sleep(2000); Console.WriteLine("Pretty cool, it gave you a nice list of other win.open commands that will let you open each program."); Thread.Sleep(2000); Console.WriteLine("I'll leave you to it, you've got the hang of it! One last thing, if ever you find yourself in another program, and want to exit, simply press CTRL+T to return to the Terminal."); Thread.Sleep(2000); - + TerminalBackend.PrefixEnabled = true; TerminalBackend.InStory = false; - TerminalBackend.PrintPrompt(); SaveSystem.SaveGame(); + Thread.Sleep(1000); + TerminalBackend.PrintPrompt(); }).Start(); } -- cgit v1.2.3 From 4178d71cb9acfed6c171923e02e58e1273e14208 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 20 May 2017 15:37:37 -0400 Subject: some more story stuff --- ShiftOS.WinForms/Applications/Terminal.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 8fa785a..664b657 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -541,6 +541,16 @@ namespace ShiftOS.WinForms.Applications Thread.Sleep(2000); Console.WriteLine("Pretty cool, it gave you a nice list of other win.open commands that will let you open each program."); Thread.Sleep(2000); + Console.WriteLine("You've got the just of using ShiftOS. Now, for your goal."); + Thread.Sleep(2000); + Console.WriteLine("As you know, ShiftOS doesn't have very many features."); + Thread.Sleep(2000); + Console.WriteLine("Using the applications you have, I need you to earn 50,000 Codepoints."); + Thread.Sleep(2000); + Console.WriteLine("You can use the Codepoints you earn to buy new applications and features in the Shiftorium, to help earn Codepoints."); + Thread.Sleep(2000); + Console.WriteLine("Start small, try to earn 500. Once you do, I'll contact you with more details."); + Thread.Sleep(2000); Console.WriteLine("I'll leave you to it, you've got the hang of it! One last thing, if ever you find yourself in another program, and want to exit, simply press CTRL+T to return to the Terminal."); Thread.Sleep(2000); TerminalBackend.PrefixEnabled = true; -- cgit v1.2.3 From 97e22b35ada5898fdcb2556628f764d927cff913 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 26 May 2017 17:06:38 -0400 Subject: SLIGHT optimizations? --- ShiftOS.WinForms/Applications/Shifter.cs | 679 ++++++++++++----------- ShiftOS.WinForms/Applications/Terminal.cs | 4 + ShiftOS.WinForms/Servers/RemoteTerminalServer.cs | 161 ++++++ ShiftOS.WinForms/ShiftOS.WinForms.csproj | 1 + ShiftOS.WinForms/Tools/ControlManager.cs | 13 +- ShiftOS_TheReturn/Localization.cs | 4 - ShiftOS_TheReturn/Server.cs | 40 ++ ShiftOS_TheReturn/ServerManager.cs | 62 +++ ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 + ShiftOS_TheReturn/TerminalBackend.cs | 9 +- 10 files changed, 635 insertions(+), 339 deletions(-) create mode 100644 ShiftOS.WinForms/Servers/RemoteTerminalServer.cs create mode 100644 ShiftOS_TheReturn/Server.cs (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') 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 cats = new List(); + IEnumerable 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((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((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((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((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(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 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(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 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 @@ Resources.resx + UserControl 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); }; diff --git a/ShiftOS_TheReturn/Localization.cs b/ShiftOS_TheReturn/Localization.cs index 2c701c9..5d848b0 100644 --- a/ShiftOS_TheReturn/Localization.cs +++ b/ShiftOS_TheReturn/Localization.cs @@ -117,10 +117,6 @@ namespace ShiftOS.Engine } List orphaned = new List(); - if (Utils.FileExists("0:/dev_orphaned_lang.txt")) - { - orphaned = JsonConvert.DeserializeObject>(Utils.ReadAllText("0:/dev_orphaned_lang.txt")); // if this file exists read from it and put in list orphaned - } int start_index = 0; diff --git a/ShiftOS_TheReturn/Server.cs b/ShiftOS_TheReturn/Server.cs new file mode 100644 index 0000000..ddbd15b --- /dev/null +++ b/ShiftOS_TheReturn/Server.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Objects; + +namespace ShiftOS.Engine +{ + public interface Server + { + /// + /// Occurs when someone sends a message to the server. + /// + /// The message from the client. + void MessageReceived(ServerMessage msg); + } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)] + public class ServerAttribute : Attribute + { + public ServerAttribute(string name, int port) + { + Name = name; + Port = port; + } + + + /// + /// Gets the name of the server. + /// + public string Name { get; } + + /// + /// Gets the port of the server. + /// + public int Port { get; } + + } +} diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 95e86e9..217b9ee 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -36,6 +36,8 @@ using static ShiftOS.Engine.SaveSystem; using Newtonsoft.Json; using System.Net.Sockets; using System.Diagnostics; +using System.IO; +using System.Reflection; namespace ShiftOS.Engine { @@ -104,6 +106,43 @@ Ping: {ServerManager.DigitalSocietyPing} ms /// public static event Action GUIDReceived; + private static void delegateToServer(ServerMessage msg) + { + string[] split = msg.GUID.Split('|'); + bool finished = false; + foreach (var exec in Directory.GetFiles(Environment.CurrentDirectory)) + { + if(exec.ToLower().EndsWith(".exe") || exec.ToLower().EndsWith(".dll")) + { + try + { + var asm = Assembly.LoadFile(exec); + foreach(var type in asm.GetTypes().Where(x => x.GetInterfaces().Contains(typeof(Server)))) + { + var attrib = type.GetCustomAttributes().FirstOrDefault(x => x is ServerAttribute) as ServerAttribute; + if(attrib != null) + { + if(split[0] == SaveSystem.CurrentSave.SystemName && split[1] == attrib.Port.ToString()) + { + if (Shiftorium.UpgradeAttributesUnlocked(type)) + { + type.GetMethods(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(x => x.Name == "MessageReceived")?.Invoke(Activator.CreateInstance(type), null); + finished = true; + } + } + } + } + } + catch { } + } + } + if (finished == false) + { + Forward(split[2], "Error", $"{split[0]}:{split[1]}: connection refused"); + } + } + + private static void ServerManager_MessageReceived(ServerMessage msg) { switch(msg.Name) @@ -119,12 +158,35 @@ Ping: {ServerManager.DigitalSocietyPing} ms })); } break; + case "msgtosys": + try + { + var m = JsonConvert.DeserializeObject(msg.Contents); + if(m.GUID.Split('|')[2] != thisGuid.ToString()) + { + delegateToServer(m); + } + } + catch { } + break; case "getguid_reply": GUIDReceived?.Invoke(msg.Contents); break; } } + public static void SendMessageToIngameServer(string sysname, int port, string title, string contents) + { + var smsg = new ServerMessage + { + Name = title, + GUID = $"{sysname}|{port}|{thisGuid.ToString()}", + Contents = contents + }; + Forward("all", "msgtosys", JsonConvert.SerializeObject(smsg)); + + } + public static void Detach_ServerManager_MessageReceived() { MessageReceived -= new ServerMessageReceived(ServerManager_MessageReceived); diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 8b48023..9d7d696 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -124,6 +124,7 @@ + diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index c8619b5..b18e27c 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -84,6 +84,11 @@ namespace ShiftOS.Engine ///
public static string LastCommand = ""; + /// + /// Gets the output of the last command. + /// + public static string LastCommandBuffer { get; private set; } + /// /// Invokes a ShiftOS terminal command. /// @@ -395,8 +400,10 @@ namespace ShiftOS.Engine } string buffer = tw.ToString(); + LastCommandBuffer = buffer; Console.SetOut(new TerminalTextWriter()); - Console.Write(buffer); + if(!isRemote) + Console.Write(buffer); } -- cgit v1.2.3 From dc0b8c66885593f7412e24bf7132bc08f6c40a9c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 28 May 2017 06:44:58 -0400 Subject: Fix a bug with command-line login. --- ShiftOS.WinForms/Applications/Terminal.cs | 7 +++++++ ShiftOS_TheReturn/SaveSystem.cs | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index ea24686..4cd4806 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -269,6 +269,13 @@ namespace ShiftOS.WinForms.Applications try { a.SuppressKeyPress = true; + if (!TerminalBackend.PrefixEnabled) + { + string textraw = txt.Lines[txt.Lines.Length - 1]; + TextSent?.Invoke(textraw); + TerminalBackend.SendText(textraw); + return; + } Console.WriteLine(""); var text = txt.Lines.ToArray(); var text2 = text[text.Length - 2]; diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index d74006a..f3d95be 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -349,6 +349,7 @@ namespace ShiftOS.Engine { if (CurrentSave.Users.FirstOrDefault(x => x.Username == getuser) == null) { + Console.WriteLine(); Console.WriteLine("User not found."); goback = true; progress++; @@ -360,6 +361,7 @@ namespace ShiftOS.Engine } else { + Console.WriteLine(); Console.WriteLine("Username not provided."); TerminalBackend.TextSent -= ev; goback = true; @@ -373,13 +375,14 @@ namespace ShiftOS.Engine var user = CurrentSave.Users.FirstOrDefault(x => x.Username == username); if (user.Password == getpass) { + Console.WriteLine(); Console.WriteLine("Welcome to ShiftOS."); CurrentUser = user; - Thread.Sleep(2000); progress++; } else { + Console.WriteLine(); Console.WriteLine("Access denied."); goback = true; progress++; @@ -388,7 +391,7 @@ namespace ShiftOS.Engine } }; TerminalBackend.TextSent += ev; - + Console.WriteLine(); Console.Write(CurrentSave.SystemName + " login: "); while (progress == 0) { @@ -396,6 +399,7 @@ namespace ShiftOS.Engine } if (goback) goto Login; + Console.WriteLine(); Console.Write("password: "); while (progress == 1) Thread.Sleep(10); -- cgit v1.2.3 From 8e3bdf71e71096711f11a0d51b2b384e117391ee Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 28 May 2017 07:21:16 -0400 Subject: strip things down but make things better --- ShiftOS.WinForms/Applications/Terminal.cs | 6 ++--- ShiftOS.WinForms/Controls/TerminalBox.cs | 6 ----- ShiftOS_TheReturn/ConsoleEx.cs | 7 +++++ ShiftOS_TheReturn/SaveSystem.cs | 2 ++ ShiftOS_TheReturn/TerminalBackend.cs | 11 +++----- ShiftOS_TheReturn/TerminalTextWriter.cs | 45 ++++++++++++++++++------------- 6 files changed, 42 insertions(+), 35 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 4cd4806..6039456 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -268,7 +268,8 @@ namespace ShiftOS.WinForms.Applications { try { - a.SuppressKeyPress = true; + if (!TerminalBackend.InStory) + a.SuppressKeyPress = false; if (!TerminalBackend.PrefixEnabled) { string textraw = txt.Lines[txt.Lines.Length - 1]; @@ -276,9 +277,8 @@ namespace ShiftOS.WinForms.Applications TerminalBackend.SendText(textraw); return; } - Console.WriteLine(""); var text = txt.Lines.ToArray(); - var text2 = text[text.Length - 2]; + var text2 = text[text.Length - 1]; var text3 = ""; var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index 7658c8c..25f7144 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -64,9 +64,6 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { this.HideSelection = true; - this.SelectionFont = ConstructFont(); - this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); - this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text)); this.HideSelection = false; } @@ -89,9 +86,6 @@ namespace ShiftOS.WinForms.Controls Engine.AudioManager.PlayStream(Properties.Resources.writesound); this.HideSelection = true; this.Select(this.TextLength, 0); - this.SelectionFont = ConstructFont(); - this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); - this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text) + Environment.NewLine); this.HideSelection = false; } diff --git a/ShiftOS_TheReturn/ConsoleEx.cs b/ShiftOS_TheReturn/ConsoleEx.cs index 90f9cc0..74483dc 100644 --- a/ShiftOS_TheReturn/ConsoleEx.cs +++ b/ShiftOS_TheReturn/ConsoleEx.cs @@ -48,5 +48,12 @@ namespace ShiftOS.Engine /// Gets or sets whether text in the Terminal is underlined. /// public static bool Underline { get; set; } + + internal static void Flush() + { + OnFlush?.Invoke(); + } + + public static Action OnFlush; } } diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index f3d95be..24a491d 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -393,6 +393,7 @@ namespace ShiftOS.Engine TerminalBackend.TextSent += ev; Console.WriteLine(); Console.Write(CurrentSave.SystemName + " login: "); + ConsoleEx.Flush(); while (progress == 0) { Thread.Sleep(10); @@ -401,6 +402,7 @@ namespace ShiftOS.Engine goto Login; Console.WriteLine(); Console.Write("password: "); + ConsoleEx.Flush(); while (progress == 1) Thread.Sleep(10); if (goback) diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index b18e27c..1c024eb 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -361,14 +361,12 @@ namespace ShiftOS.Engine /// Whether the command should be sent through Remote Terminal Session (RTS). public static void InvokeCommand(string text, bool isRemote = false) { + if (string.IsNullOrWhiteSpace(text)) + return; var tw = new MemoryTextWriter(); Console.SetOut(tw); try { - - if (string.IsNullOrWhiteSpace(text)) - return; - var args = GetArgs(ref text); Stopwatch debugger = new Stopwatch(); @@ -533,10 +531,9 @@ namespace ShiftOS.Engine /// public static void PrintPrompt() { + Console.WriteLine(); if (SaveSystem.CurrentSave != null && CurrentUser != null) { - Desktop.InvokeOnWorkerThread(() => - { ConsoleEx.BackgroundColor = SkinEngine.LoadedSkin.TerminalBackColorCC; ConsoleEx.Italic = false; ConsoleEx.Underline = false; @@ -566,7 +563,7 @@ namespace ShiftOS.Engine ConsoleEx.Bold = false; ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; Console.Write(" "); - }); + ConsoleEx.Flush(); } } diff --git a/ShiftOS_TheReturn/TerminalTextWriter.cs b/ShiftOS_TheReturn/TerminalTextWriter.cs index 010e02c..4c0c3a0 100644 --- a/ShiftOS_TheReturn/TerminalTextWriter.cs +++ b/ShiftOS_TheReturn/TerminalTextWriter.cs @@ -37,14 +37,19 @@ namespace ShiftOS.Engine /// public class TerminalTextWriter : TextWriter { - /// - /// Win32 API call to lock the window from being updated. - /// - /// The Win32 window handle - /// ...I....have no idea. - [System.Runtime.InteropServices.DllImport("user32.dll")] - public static extern bool LockWindowUpdate(IntPtr hWndLock); + public TerminalTextWriter() + { + ConsoleEx.OnFlush = () => + { + Desktop.InvokeOnWorkerThread(() => + { + UnderlyingControl?.Write(buffer); + buffer = ""; + }); + }; + } + /// /// Gets the encoding format for this . God bless the Unicode Consortiem. /// @@ -94,11 +99,17 @@ namespace ShiftOS.Engine } else { - Desktop.InvokeOnWorkerThread(new Action(() => - { - UnderlyingControl?.Write(value.ToString()); - select(); - })); + buffer += value; + } + } + + private string buffer = ""; + + public string Buffer + { + get + { + return buffer; } } @@ -118,11 +129,8 @@ namespace ShiftOS.Engine else { - Desktop.InvokeOnWorkerThread(new Action(() => - { - UnderlyingControl?.WriteLine(value); - select(); - })); + buffer += value + Environment.NewLine; + ConsoleEx.Flush(); } } @@ -149,8 +157,7 @@ namespace ShiftOS.Engine Desktop.InvokeOnWorkerThread(new Action(() => { - UnderlyingControl?.Write(value.ToString()); - select(); + buffer += value; })); } } -- cgit v1.2.3 From 4036e97f3f3ecb6541cc623165e960e8c172f242 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 28 May 2017 10:26:11 -0400 Subject: Don't clear the terminal when in fullscreen --- ShiftOS.WinForms/Applications/Terminal.cs | 54 +------------------------------ 1 file changed, 1 insertion(+), 53 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 6039456..bfc4425 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -130,8 +130,6 @@ namespace ShiftOS.WinForms.Applications { this.Invoke(new Action(() => { - ResetAllKeywords(); - rtbterm.Text = ""; if (Shiftorium.UpgradeInstalled("first_steps")) { if (!Shiftorium.UpgradeInstalled("desktop")) @@ -203,52 +201,6 @@ namespace ShiftOS.WinForms.Applications public static event TextSentEventHandler TextSent; - public void ResetAllKeywords() - { - string primary = SaveSystem.CurrentUser.Username + " "; - string secondary = "shiftos "; - - - var asm = Assembly.GetExecutingAssembly(); - - var types = asm.GetTypes(); - - foreach (var type in types) - { - foreach (var a in type.GetCustomAttributes(false)) - { - if (ShiftoriumFrontend.UpgradeAttributesUnlocked(type)) - { - if (a is Namespace) - { - var ns = a as Namespace; - if (!primary.Contains(ns.name)) - { - primary += ns.name + " "; - } - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) - { - if (ShiftoriumFrontend.UpgradeAttributesUnlocked(method)) - { - foreach (var ma in method.GetCustomAttributes(false)) - { - if (ma is Command) - { - var cmd = ma as Command; - if (!secondary.Contains(cmd.name)) - secondary += cmd.name + " "; - } - } - } - } - } - } - } - } - - - } - public static void MakeWidget(Controls.TerminalBox txt) { AppearanceManager.StartConsoleOut(); @@ -436,17 +388,13 @@ namespace ShiftOS.WinForms.Applications if (SaveSystem.CurrentSave != null) { + TerminalBackend.PrintPrompt(); if (!ShiftoriumFrontend.UpgradeInstalled("window_manager")) { rtbterm.Select(rtbterm.TextLength, 0); } } - new Thread(() => - { - Thread.Sleep(1000); - TerminalBackend.PrintPrompt(); - }).Start(); } public static string RemoteSystemName { get; set; } -- cgit v1.2.3 From 03ebdf42d9f12b678d48f954736664f6f3eb1f84 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 28 May 2017 12:40:06 -0400 Subject: Funny, disabling localization makes things easier... --- ShiftOS.WinForms/Applications/Chat.cs | 1 + ShiftOS.WinForms/Applications/Terminal.cs | 6 +- ShiftOS.WinForms/Resources/Shiftorium.txt | 5 +- ShiftOS.WinForms/Tools/ControlManager.cs | 139 +++++++++++------------------- ShiftOS.WinForms/WinformsDesktop.cs | 10 ++- ShiftOS_TheReturn/Localization.cs | 45 +--------- ShiftOS_TheReturn/TerminalTextWriter.cs | 1 + 7 files changed, 72 insertions(+), 135 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Chat.cs b/ShiftOS.WinForms/Applications/Chat.cs index f9e601f..7a2de81 100644 --- a/ShiftOS.WinForms/Applications/Chat.cs +++ b/ShiftOS.WinForms/Applications/Chat.cs @@ -41,6 +41,7 @@ namespace ShiftOS.WinForms.Applications [WinOpen("simplesrc")] [Launcher("SimpleSRC Client", false, null, "Networking")] [DefaultTitle("SimpleSRC Client")] + [AppscapeEntry("SimpleSRC", "A simple ShiftOS Relay Chat client that allows you to talk with other ShiftOS users from all over the world.", 300, 145, "file_skimmer", "Networking")] public partial class Chat : UserControl, IShiftOSWindow { public Chat() diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index bfc4425..3d17d35 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -504,11 +504,11 @@ namespace ShiftOS.WinForms.Applications Thread.Sleep(2000); Console.WriteLine("As you know, ShiftOS doesn't have very many features."); Thread.Sleep(2000); - Console.WriteLine("Using the applications you have, I need you to earn 50,000 Codepoints."); + Console.WriteLine("Using the applications you have, I need you to earn as many Codepoints as you can."); Thread.Sleep(2000); - Console.WriteLine("You can use the Codepoints you earn to buy new applications and features in the Shiftorium, to help earn Codepoints."); + Console.WriteLine("You can use the Codepoints you earn to buy new applications and features in the Shiftorium, to help earn even more Codepoints."); Thread.Sleep(2000); - Console.WriteLine("Start small, try to earn 500. Once you do, I'll contact you with more details."); + Console.WriteLine("Once you earn 1,000 Codepoints, I will check back with you and see how well you've done."); Thread.Sleep(2000); Console.WriteLine("I'll leave you to it, you've got the hang of it! One last thing, if ever you find yourself in another program, and want to exit, simply press CTRL+T to return to the Terminal."); Thread.Sleep(2000); diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index 41b50a7..0eac58e 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -283,7 +283,7 @@ Name: "AL Widget Manager", Cost: 125, Description: "Desktop Widgets are a huge advancement in ShiftOS technology, allowing access to system information, and quick control of your system, without even opening a window. However, we still need to be able to modify each widget. This upgrade adds an App Launcher entry for the Desktop Widget Manager.", - Description: "app_launcher;desktop_widgets", + Dependencies: "app_launcher;desktop_widgets", Category: "GUI" }, { @@ -704,7 +704,8 @@ Name: "Artpad", Cost: 7500, Category: "Applications", - Description: "ArtPad is a very extensible tool that allows you to draw images within ShiftOS. Buy this upgrade to gain access to it through win.open{}!" + Description: "ArtPad is a very extensible tool that allows you to draw images within ShiftOS. Buy this upgrade to gain access to it through win.open{}!", + Dependencies: "color_depth_8_bits" }, { Name: "AL Artpad", diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs index 1643b23..83ab7fe 100644 --- a/ShiftOS.WinForms/Tools/ControlManager.cs +++ b/ShiftOS.WinForms/Tools/ControlManager.cs @@ -1,3 +1,5 @@ +#define SLOW_LOCALIZATION + /* * MIT License * @@ -144,77 +146,66 @@ namespace ShiftOS.WinForms.Tools public static void SetupControl(Control ctrl) { - - if (!(ctrl is MenuStrip) && !(ctrl is ToolStrip) && !(ctrl is StatusStrip) && !(ctrl is ContextMenuStrip)) + Desktop.InvokeOnWorkerThread(() => { - string tag = ""; - - try + if (!(ctrl is MenuStrip) && !(ctrl is ToolStrip) && !(ctrl is StatusStrip) && !(ctrl is ContextMenuStrip)) { - if(ctrl.Tag != null) - tag = ctrl.Tag.ToString(); - } - catch { } + string tag = ""; - if (!tag.Contains("keepbg")) - { - if (ctrl.BackColor != Control.DefaultBackColor) + try { - Desktop.InvokeOnWorkerThread(() => + if (ctrl.Tag != null) + tag = ctrl.Tag.ToString(); + } + catch { } + + if (!tag.Contains("keepbg")) + { + if (ctrl.BackColor != Control.DefaultBackColor) { ctrl.BackColor = SkinEngine.LoadedSkin.ControlColor; - }); + } } - } - if (!tag.Contains("keepfont")) - { - Desktop.InvokeOnWorkerThread(() => + if (!tag.Contains("keepfont")) { ctrl.ForeColor = SkinEngine.LoadedSkin.ControlTextColor; ctrl.Font = SkinEngine.LoadedSkin.MainFont; - }); - if (tag.Contains("header1")) - { - Desktop.InvokeOnWorkerThread(() => + if (tag.Contains("header1")) { - ctrl.Font = SkinEngine.LoadedSkin.HeaderFont; - }); - } + Desktop.InvokeOnWorkerThread(() => + { + ctrl.Font = SkinEngine.LoadedSkin.HeaderFont; + }); + } - if (tag.Contains("header2")) - { - Desktop.InvokeOnWorkerThread(() => + if (tag.Contains("header2")) { ctrl.Font = SkinEngine.LoadedSkin.Header2Font; - }); - } + } - if (tag.Contains("header3")) - { - Desktop.InvokeOnWorkerThread(() => + if (tag.Contains("header3")) { ctrl.Font = SkinEngine.LoadedSkin.Header3Font; - }); + } } - } - try - { - string ctrlText = Localization.Parse(ctrl.Text); - Desktop.InvokeOnWorkerThread(() => + try + { +#if !SLOW_LOCALIZATION + if (!string.IsNullOrWhiteSpace(ctrl.Text)) + { + string ctrlText = Localization.Parse(ctrl.Text); + ctrl.Text = ctrlText; + } +#endif + } + catch { - ctrl.Text = ctrlText; - }); - } - catch - { - } + } - if(ctrl is Button) - { - Desktop.InvokeOnWorkerThread(() => + if (ctrl is Button) { Button b = ctrl as Button; if (!b.Tag.ToString().ToLower().Contains("keepbg")) @@ -229,7 +220,7 @@ namespace ShiftOS.WinForms.Tools b.FlatAppearance.BorderColor = SkinEngine.LoadedSkin.ButtonForegroundColor; b.ForeColor = SkinEngine.LoadedSkin.ButtonForegroundColor; } - if(!b.Tag.ToString().ToLower().Contains("keepfont")) + if (!b.Tag.ToString().ToLower().Contains("keepfont")) b.Font = SkinEngine.LoadedSkin.ButtonTextFont; Color orig_bg = b.BackColor; @@ -260,15 +251,12 @@ namespace ShiftOS.WinForms.Tools b.BackgroundImageLayout = SkinEngine.GetImageLayout("buttonpressed"); }; - }); + } } - if(ctrl is TextBox) + if (ctrl is TextBox) { - Desktop.InvokeOnWorkerThread(() => - { - (ctrl as TextBox).BorderStyle = BorderStyle.FixedSingle; - }); + (ctrl as TextBox).BorderStyle = BorderStyle.FixedSingle; } ctrl.KeyDown += (o, a) => @@ -286,27 +274,19 @@ namespace ShiftOS.WinForms.Tools }; if (ctrl is Button) { - Desktop.InvokeOnWorkerThread(() => - { - (ctrl as Button).FlatStyle = FlatStyle.Flat; - }); + (ctrl as Button).FlatStyle = FlatStyle.Flat; } else if (ctrl is WindowBorder) { - Desktop.InvokeOnWorkerThread(() => - { - (ctrl as WindowBorder).Setup(); - }); + (ctrl as WindowBorder).Setup(); } - } - Desktop.InvokeOnWorkerThread(() => - { - MakeDoubleBuffered(ctrl); + ControlSetup?.Invoke(ctrl); }); - ControlSetup?.Invoke(ctrl); } + + public static event Action ControlSetup; public static void MakeDoubleBuffered(Control c) @@ -330,27 +310,12 @@ namespace ShiftOS.WinForms.Tools { Desktop.HideAppLauncher(); }; - ThreadStart ts = () => - { - var ctrls = frm.Controls.ToList(); - for (int i = 0; i < ctrls.Count(); i++) - { - SetupControls(ctrls[i]); - } - SetupControl(frm); - - }; - - if (runInThread == true) - { - var t = new Thread(ts); - t.IsBackground = true; - t.Start(); - } - else + var ctrls = frm.Controls.ToList(); + for (int i = 0; i < ctrls.Count(); i++) { - ts?.Invoke(); + SetupControls(ctrls[i]); } + SetupControl(frm); } } diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index 6ce8cc9..85eab55 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -202,13 +202,21 @@ namespace ShiftOS.WinForms { if (SaveSystem.CurrentSave.Codepoints != lastcp) lastcp = SaveSystem.CurrentSave.Codepoints; - if (lastcp >= 10000) + if (lastcp >= 2500) { if (!Shiftorium.UpgradeInstalled("victortran_shiftnet")) { Story.Start("victortran_shiftnet"); } } + if(lastcp >= 5000) + { + if(Shiftorium.UpgradeInstalled("triwrite") && Shiftorium.UpgradeInstalled("simplesrc") && Shiftorium.UpgradeInstalled("victortran_shiftnet") && Shiftorium.UpgradeInstalled("story_hacker101_breakingthebonds")) + { + if (!Shiftorium.UpgradeInstalled("story_thefennfamily")) + Story.Start("story_thefennfamily"); + } + } } } while (!SaveSystem.ShuttingDown); }); diff --git a/ShiftOS_TheReturn/Localization.cs b/ShiftOS_TheReturn/Localization.cs index 5d848b0..c542c2a 100644 --- a/ShiftOS_TheReturn/Localization.cs +++ b/ShiftOS_TheReturn/Localization.cs @@ -111,50 +111,11 @@ namespace ShiftOS.Engine localizationStrings = JsonConvert.DeserializeObject>(Utils.ReadAllText(Paths.GetPath("english.local"))); //if no provider fall back to english } - foreach (var kv in localizationStrings) + foreach (var kv in localizationStrings.Where(x=>original.Contains(x.Key))) { original = original.Replace(kv.Key, kv.Value); // goes through and replaces all the localization blocks } - List orphaned = new List(); - - - int start_index = 0; - int length = 0; - bool indexing = false; - - foreach (var c in original) - { - // start paying attenion when you see a "{" - if (c == '{') - { - start_index = original.IndexOf(c); - indexing = true; - } - - if (indexing == true) - { - // stop paying attention when you see a "}" after seeing a "{" - length++; - if (c == '}') - { - indexing = false; - string o = original.Substring(start_index, length); - if (!orphaned.Contains(o)) - { - orphaned.Add(o); - } - start_index = 0; - length = 0; - } - } - } - - if (orphaned.Count > 0) - { - Utils.WriteAllText("0:/dev_orphaned_lang.txt", JsonConvert.SerializeObject(orphaned, Formatting.Indented)); //format if from this txt file - } - //string original2 = Parse(original); string usernameReplace = ""; @@ -203,13 +164,13 @@ namespace ShiftOS.Engine }; // actually do the replacement - foreach (KeyValuePair replacement in replace) + foreach (KeyValuePair replacement in replace.Where(x => original.Contains(x.Key))) { original = original.Replace(replacement.Key, Parse(replacement.Value)); } // do the replacement but default - foreach (KeyValuePair replacement in defaultReplace) + foreach (KeyValuePair replacement in defaultReplace.Where(x => original.Contains(x.Key))) { original = original.Replace(replacement.Key, replacement.Value); } diff --git a/ShiftOS_TheReturn/TerminalTextWriter.cs b/ShiftOS_TheReturn/TerminalTextWriter.cs index 4c0c3a0..63e88eb 100644 --- a/ShiftOS_TheReturn/TerminalTextWriter.cs +++ b/ShiftOS_TheReturn/TerminalTextWriter.cs @@ -42,6 +42,7 @@ namespace ShiftOS.Engine { ConsoleEx.OnFlush = () => { + System.Diagnostics.Debug.WriteLine("[terminal] " + buffer); Desktop.InvokeOnWorkerThread(() => { UnderlyingControl?.Write(buffer); -- cgit v1.2.3 From 9914c18456a0c08019e778479ce727ac937b1e57 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 28 May 2017 14:40:42 -0400 Subject: Fuck --- ShiftOS.WinForms/Applications/Terminal.cs | 1 + ShiftOS.WinForms/Controls/TerminalBox.cs | 6 +++ ShiftOS.WinForms/Tools/ControlManager.cs | 6 +-- ShiftOS_TheReturn/SaveSystem.cs | 64 +++++++++++++++---------------- ShiftOS_TheReturn/ServerManager.cs | 17 -------- ShiftOS_TheReturn/ShiftOS.Engine.csproj | 4 -- 6 files changed, 42 insertions(+), 56 deletions(-) (limited to 'ShiftOS.WinForms/Applications/Terminal.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 3d17d35..de4888b 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -232,6 +232,7 @@ namespace ShiftOS.WinForms.Applications var text = txt.Lines.ToArray(); var text2 = text[text.Length - 1]; var text3 = ""; + Console.WriteLine(); var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); if (IsInRemoteSystem == true) diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index 25f7144..c188321 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -64,6 +64,9 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { this.HideSelection = true; + this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); + this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); + this.SelectionFont = ConstructFont(); this.AppendText(Localization.Parse(text)); this.HideSelection = false; } @@ -85,6 +88,9 @@ namespace ShiftOS.WinForms.Controls { Engine.AudioManager.PlayStream(Properties.Resources.writesound); this.HideSelection = true; + this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); + this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); + this.SelectionFont = ConstructFont(); this.Select(this.TextLength, 0); this.AppendText(Localization.Parse(text) + Environment.NewLine); this.HideSelection = false; diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs index fe77884..92482fa 100644 --- a/ShiftOS.WinForms/Tools/ControlManager.cs +++ b/ShiftOS.WinForms/Tools/ControlManager.cs @@ -207,19 +207,19 @@ namespace ShiftOS.WinForms.Tools if (ctrl is Button) { Button b = ctrl as Button; - if (!b.Tag.ToString().ToLower().Contains("keepbg")) + if (!tag.Contains("keepbg")) { b.BackColor = SkinEngine.LoadedSkin.ButtonBackgroundColor; b.BackgroundImage = SkinEngine.GetImage("buttonidle"); b.BackgroundImageLayout = SkinEngine.GetImageLayout("buttonidle"); } b.FlatAppearance.BorderSize = SkinEngine.LoadedSkin.ButtonBorderWidth; - if (!b.Tag.ToString().ToLower().Contains("keepfg")) + if (!tag.Contains("keepfg")) { b.FlatAppearance.BorderColor = SkinEngine.LoadedSkin.ButtonForegroundColor; b.ForeColor = SkinEngine.LoadedSkin.ButtonForegroundColor; } - if (!b.Tag.ToString().ToLower().Contains("keepfont")) + if (!tag.Contains("keepfont")) b.Font = SkinEngine.LoadedSkin.ButtonTextFont; Color orig_bg = b.BackColor; diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 489b718..55f5cd5 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -153,50 +153,50 @@ namespace ShiftOS.Engine } } - if (defaultConf.ConnectToMud == true) + + + bool guidReceived = false; + ServerManager.GUIDReceived += (str) => { - bool guidReceived = false; - ServerManager.GUIDReceived += (str) => - { //Connection successful! Stop waiting! guidReceived = true; - Console.WriteLine("[inetd] Connection successful."); - }; + Console.WriteLine("[inetd] Connection successful."); + }; - try - { - - ServerManager.Initiate(UserConfig.Get().DigitalSocietyAddress, UserConfig.Get().DigitalSocietyPort); - //This haults the client until the connection is successful. - while (ServerManager.thisGuid == new Guid()) - { - Thread.Sleep(10); - } - Console.WriteLine("[inetd] DHCP GUID recieved, finished setup"); - FinishBootstrap(); - } - catch (Exception ex) + try + { + + ServerManager.Initiate(UserConfig.Get().DigitalSocietyAddress, UserConfig.Get().DigitalSocietyPort); + //This haults the client until the connection is successful. + while (ServerManager.thisGuid == new Guid()) { - //No errors, this never gets called. - Console.WriteLine("[inetd] SEVERE: " + ex.Message); - Thread.Sleep(3000); - ServerManager.StartLANServer(); - while (ServerManager.thisGuid == new Guid()) - { - Thread.Sleep(10); - } - Console.WriteLine("[inetd] DHCP GUID recieved, finished setup"); - FinishBootstrap(); + Thread.Sleep(10); } + Console.WriteLine("[inetd] DHCP GUID recieved, finished setup"); + FinishBootstrap(); } - else + catch (Exception ex) { - ServerManager.StartLANServer(); + //No errors, this never gets called. + Console.WriteLine("[inetd] SEVERE: " + ex.Message); + Thread.Sleep(3000); + Console.WriteLine("[sys] SEVERE: Cannot connect to server. Shutting down in 5..."); + Thread.Sleep(1000); + Console.WriteLine("[sys] 4..."); + Thread.Sleep(1000); + Console.WriteLine("[sys] 3..."); + Thread.Sleep(1000); + Console.WriteLine("[sys] 2..."); + Thread.Sleep(1000); + Console.WriteLine("[sys] 1..."); + Thread.Sleep(1000); + Console.WriteLine("[sys] Bye bye."); + System.Diagnostics.Process.GetCurrentProcess().Kill(); } //Nothing happens past this point - but the client IS connected! It shouldn't be stuck in that while loop above. - + })); thread.IsBackground = true; thread.Start(); diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 217b9ee..f0acaa2 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -316,23 +316,6 @@ Ping: {ServerManager.DigitalSocietyPing} ms private static bool singleplayer = false; public static bool IsSingleplayer { get { return singleplayer; } } - public static void StartLANServer() - { - singleplayer = true; - ShiftOS.Server.Program.ServerStarted += (address) => - { - Console.WriteLine($"Connecting to {address}..."); - Initiate(address, 13370); - }; - Disconnected += () => - { - ShiftOS.Server.Program.Stop(); - }; - ShiftOS.Server.Program.Main(new[] { "" }); - - - } - /// /// Occurs when the server sends a message to this client. /// diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 9d7d696..4cbce72 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -162,10 +162,6 @@ {A069089A-8962-4607-B2B2-4CF4A371066E} ShiftOS.Objects - - {226C63B4-E60D-4949-B4E7-7A2DDBB96776} - ShiftOS.Server - -- cgit v1.2.3