From 17957f9bb8b3c7fd06cf39a01cd172343cd98a9a Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 7 Mar 2017 10:06:20 -0500 Subject: Fix bootstrapper bug. --- ShiftOS.WinForms/Controls/TerminalBox.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index ffc3f86..200c1d7 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -52,12 +52,12 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { - this.Text += Localization.Parse(text); + this.AppendText(Localization.Parse(text)); } public void WriteLine(string text) { - this.Text += Localization.Parse(text) + Environment.NewLine; + this.AppendText(Localization.Parse(text) + Environment.NewLine); } } } -- cgit v1.2.3 From 2a747334bd926d79537b9e8d4f38c79a815752e5 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 7 Mar 2017 14:56:48 -0500 Subject: WHOA HACKING --- .../Applications/TutorialBox.Designer.cs | 57 +++ ShiftOS.WinForms/Applications/TutorialBox.cs | 73 ++++ ShiftOS.WinForms/Applications/TutorialBox.resx | 120 +++++ ShiftOS.WinForms/Controls/TerminalBox.cs | 2 + ShiftOS.WinForms/HackerCommands.cs | 484 ++++++++++++++++++++- ShiftOS.WinForms/ShiftOS.WinForms.csproj | 9 + ShiftOS_TheReturn/Command.cs | 6 + ShiftOS_TheReturn/Commands.cs | 28 ++ ShiftOS_TheReturn/KernelWatchdog.cs | 70 +++ ShiftOS_TheReturn/SaveSystem.cs | 4 +- ShiftOS_TheReturn/ServerManager.cs | 7 + ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 + ShiftOS_TheReturn/Shiftorium.cs | 7 +- ShiftOS_TheReturn/TerminalBackend.cs | 156 +++---- 14 files changed, 939 insertions(+), 85 deletions(-) create mode 100644 ShiftOS.WinForms/Applications/TutorialBox.Designer.cs create mode 100644 ShiftOS.WinForms/Applications/TutorialBox.cs create mode 100644 ShiftOS.WinForms/Applications/TutorialBox.resx create mode 100644 ShiftOS_TheReturn/KernelWatchdog.cs (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Applications/TutorialBox.Designer.cs b/ShiftOS.WinForms/Applications/TutorialBox.Designer.cs new file mode 100644 index 0000000..6e74023 --- /dev/null +++ b/ShiftOS.WinForms/Applications/TutorialBox.Designer.cs @@ -0,0 +1,57 @@ +namespace ShiftOS.WinForms.Applications +{ + partial class TutorialBox + { + /// + /// 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.lbltuttext = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // lbltuttext + // + this.lbltuttext.Dock = System.Windows.Forms.DockStyle.Fill; + this.lbltuttext.Location = new System.Drawing.Point(0, 0); + this.lbltuttext.Name = "lbltuttext"; + this.lbltuttext.Size = new System.Drawing.Size(401, 134); + this.lbltuttext.TabIndex = 0; + // + // TutorialBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.lbltuttext); + this.Name = "TutorialBox"; + this.Size = new System.Drawing.Size(401, 134); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label lbltuttext; + } +} diff --git a/ShiftOS.WinForms/Applications/TutorialBox.cs b/ShiftOS.WinForms/Applications/TutorialBox.cs new file mode 100644 index 0000000..25921e1 --- /dev/null +++ b/ShiftOS.WinForms/Applications/TutorialBox.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; +using System.Threading; + +namespace ShiftOS.WinForms.Applications +{ + + [DefaultTitle("Tutorial objective")] + public partial class TutorialBox : UserControl, IShiftOSWindow + { + public TutorialBox() + { + InitializeComponent(); + IsComplete = false; + lbltuttext.Text = ""; + } + + bool stillTyping = false; + + public void SetObjective(string text) + { + while (stillTyping == true) + { + + } + + new Thread(() => + { + stillTyping = true; + this.Invoke(new Action(() => + { + lbltuttext.Text = ""; + })); + foreach(var c in text.ToCharArray()) + { + this.Invoke(new Action(() => + { + lbltuttext.Text += c; + })); + Thread.Sleep(75); + } + stillTyping = false; + }).Start(); + } + + public void OnLoad() + { + } + + public void OnSkinLoad() + { + } + + public bool IsComplete { get; set; } + + public bool OnUnload() + { + return IsComplete; + } + + public void OnUpgrade() + { + } + } +} diff --git a/ShiftOS.WinForms/Applications/TutorialBox.resx b/ShiftOS.WinForms/Applications/TutorialBox.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/Applications/TutorialBox.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/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index 200c1d7..4fcb429 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -52,7 +52,9 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { + this.HideSelection = true; this.AppendText(Localization.Parse(text)); + this.HideSelection = false; } public void WriteLine(string text) diff --git a/ShiftOS.WinForms/HackerCommands.cs b/ShiftOS.WinForms/HackerCommands.cs index ebe25a2..7938fd0 100644 --- a/ShiftOS.WinForms/HackerCommands.cs +++ b/ShiftOS.WinForms/HackerCommands.cs @@ -1,27 +1,67 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using Newtonsoft.Json; using ShiftOS.Engine; +using ShiftOS.Objects; using ShiftOS.WinForms.Applications; +using static ShiftOS.Objects.ShiftFS.Utils; namespace ShiftOS.WinForms { - [Namespace("l337")] + [Namespace("puppy")] + [RequiresUpgrade("hacker101_deadaccts")] + [KernelMode] + public static class KernelPuppyCommands + { + [Command("clear", true)] + public static bool ClearLogs() + { + WriteAllText("0:/system/data/kernel.log", ""); + Console.WriteLine(" logs cleared successfully."); + return true; + } + } + + [Namespace("krnl")] + public static class KernelCommands + { + [Command("control", true)] + [RequiresArgument("pass")] + public static bool Control(Dictionary args) + { + if(args["pass"].ToString() == ServerManager.thisGuid.ToString()) + { + KernelWatchdog.Log("warn", "User has breached the kernel."); + KernelWatchdog.EnterKernelMode(); + } + return true; + } + + [Command("lock_session")] + [KernelMode] + public static bool LeaveControl() + { + KernelWatchdog.Log("inf", "User has left the kernel-mode session."); + KernelWatchdog.LeaveKernelMode(); + KernelWatchdog.MudConnected = true; + return true; + } + } + + [Namespace("hacker101")] [RequiresUpgrade("hacker101_deadaccts")] public static class HackerCommands { private static void writeSlow(string text) { Console.Write("[hacker101@undisclosed]: "); - foreach(var c in text.ToCharArray()) - { - Console.Write(c); - Thread.Sleep(125); - } - Console.WriteLine(); + Thread.Sleep(200); + Console.WriteLine(text); Thread.Sleep(1000); } @@ -88,9 +128,217 @@ namespace ShiftOS.WinForms internal static void StartHackerTutorial() { - //nyi + Desktop.InvokeOnWorkerThread(() => + { + var tut = new TutorialBox(); + AppearanceManager.SetupWindow(tut); + + new Thread(() => + { + + + int tutPos = 0; + Action ondec = () => + { + if (tutPos == 2) + tutPos++; + }; + TerminalBackend.CommandProcessed += (o, a) => + { + switch (tutPos) + { + + case 0: + case 10: + if (o.ToLower().StartsWith("mud.disconnect")) + { + tutPos++; + } + break; + case 11: + if (o.ToLower().StartsWith("krnl.lock_session")) + tutPos++; + break; + case 1: + if (o.ToLower().StartsWith("hacker101.brute_decrypt")) + { + if (a.Contains("0:/system/data/kernel.log")) + { + tutPos++; + } + } + break; + case 3: + if (o.ToLower().StartsWith("krnl.control")) + { + tutPos++; + } + break; + case 4: + if (o.ToLower().StartsWith("puppy.clear")) + tutPos++; + break; + case 5: + if (o.ToLower().StartsWith("mud.reconnect")) + tutPos++; + break; + case 6: + if (o.ToLower().StartsWith("mud.sendmsg")) + { + var msg = JsonConvert.DeserializeObject(a); + try + { + if (msg.header == "getusers" && msg.body == "dead") + tutPos++; + } + catch + { + + } + } + break; + case 7: + if (o.ToLower().StartsWith("hacker101.breach_user_password")) + tutPos++; + break; + case 8: + if (o.ToLower().StartsWith("hacker101.print_user_info")) + tutPos++; + break; + case 9: + if (o.ToLower().StartsWith("hacker101.steal_codepoints")) + tutPos++; + break; + } + }; + tut.SetObjective("Welcome to the dead account exploitation tutorial. In this tutorial you will learn the basics of hacking within the multi-user domain."); + Thread.Sleep(1000); + tut.SetObjective("We will start with a simple system exploit - gaining kernel-level access to ShiftOS. This can help you perform actions not ever possible in the user level."); + Thread.Sleep(1000); + tut.SetObjective("To gain root access, you will first need to breach the system watchdog to keep it from dialing home to DevX."); + Thread.Sleep(1000); + tut.SetObjective("The watchdog can only function when it has a successful connection to the multi-user domain. You will need to use the MUD Control Centre to disconnect yourself from the MUD. This will lock you out of most features. To disconnect from the multi-user domain, simply run the 'mud.disconnect' command."); + while(tutPos == 0) + { + + } + tut.SetObjective("As you can see, the kernel watchdog has shut down temporarily, however before the disconnect it was able to tell DevX that it has gone offline."); + Thread.Sleep(1000); + tut.SetObjective("You'll also notice that commands like the shiftorium, MUD control centre and various applications that utilize these system components no longer function."); + Thread.Sleep(1000); + tut.SetObjective("The watchdog, however, is still watching. DevX was smart and programmed the kernel to log all events to a local file in 0:/system/data/kernel.log."); + Thread.Sleep(1000); + tut.SetObjective("You will need to empty out this file before you can connect to the multi-user domain, as the watchdog will send the contents of this file straight to DevX."); + Thread.Sleep(1000); + tut.SetObjective("Or, you can do what we're about to do and attempt to decrypt the log and sniff out the kernel-mode access password."); + Thread.Sleep(1000); + tut.SetObjective("This will allow us to gain kernel-level access to our system using the krnl.control{pass:} command."); + Thread.Sleep(1000); + tut.SetObjective("Let's start decrypting the log file using the hacker101.brute_decrypt{file:} script. The file: argument is a string and should point to a .log file. When the script succeeds, you will see a TextPad open with the decrypted contents."); + while(tutPos == 1) + { + + } + onCompleteDecrypt += ondec; + tut.SetObjective("This script isn't the most agile script ever, but it'll get the job done."); + while(tutPos == 2) + { + + } + onCompleteDecrypt -= ondec; + tut.SetObjective("Alright - it's done. Here's how it's laid out. In each log entry, you have the timestamp, then the event name, then the event description."); + Thread.Sleep(1000); + tut.SetObjective("Look for the most recent 'mudhandshake' event. This contains the kernel access code."); + Thread.Sleep(1000); + tut.SetObjective("Once you have it, run 'krnl.control{pass:\"the-kernel-code-here\"}. This will allow you to gain access to the kernel."); + while(tutPos == 3) + { + + } + tut.SetObjective("You are now in kernel mode. Every command you enter will run on the kernel. Now, let's clear the watchdog's logfile and reconnect to the multi-user domain."); + Thread.Sleep(1000); + tut.SetObjective("To clear the log, simply run 'puppy.clear'."); + while(tutPos == 4) + { + + } + tut.SetObjective("Who's a good dog... You are, ShiftOS. Now, we can connect back to the MUD using 'mud.reconnect'."); + Thread.Sleep(1000); + while(tutPos == 5) + { + + } + tut.SetObjective("We have now snuck by the watchdog and DevX has no idea. With kernel-level access, everything you do is not logged, however if you perform too much in one shot, you'll get kicked off and locked out of the multi-user domain temporarily."); + Thread.Sleep(1000); + tut.SetObjective("So, let's focus on the job. You want to get into one of those fancy dead accounts, don't ya? Well, first, we need to talk with the MUD to get a list of these accounts."); + Thread.Sleep(1000); + tut.SetObjective("Simply run the `mud.sendmsg` command, specifying a 'header' of \"getusers\", and a body of \"dead\"."); + while(tutPos == 6) + { + + } + tut.SetObjective("Great. We now have the usernames and sysnames of all dead accounts on the MUD. Now let's use the hacker101.breach_user_password{user:,sys:} command to breach one of these accounts' passwords."); + while(tutPos == 7) + { + + } + tut.SetObjective("There - you now have access to that account. Use its password, username and sysname and run the hacker101.print_user_info{user:,pass:,sys:} command to print the entirety of this user's information."); + while(tutPos == 8) + { + + } + tut.SetObjective("Now you can see a list of the user's Codepoints among other things. Now you can steal their codepoints by using the hacker101.steal_codepoints{user:,pass:,sys;,amount:} command. Be careful. This may alert DevX."); + while(tutPos == 9) + { + + } + if(devx_alerted == true) + { + tut.SetObjective("Alright... enough fun and games. DevX just found out we were doing this."); + Thread.Sleep(500); + tut.SetObjective("Quick! Disconnect from the MUD!!"); + while(tutPos == 10) + { + + } + tut.SetObjective("Now, get out of kernel mode! To do that, run krnl.lock_session."); + while(tutPos == 11) + { + + } + + } + else + { + tut.SetObjective("OK, that was risky, but we pulled it off. Treat yourself! But first, let's get you out of kernel mode."); + Thread.Sleep(500); + tut.SetObjective("First we need to get you off the MUD. Simply run mud.disconnect again."); + while (tutPos == 10) + { + + } + tut.SetObjective("Now, let's run krnl.lock_session. This will lock you back into the user mode, and reconnect you to the MUD."); + while (tutPos == 11) + { + + } + tut.SetObjective("If, for some reason, DevX DOES find out, you have to be QUICK to get off of kernel mode. You don't want to make him mad."); + } + + Thread.Sleep(1000); + tut.SetObjective("So that's all for now. Whenever you're in kernel mode again, and you have access to a user account, try breaching their filesystem next time. You can use sos.help{ns:} to show commands from a specific namespace to help you find more commands easily."); + Thread.Sleep(1000); + tut.SetObjective("You can now close this window."); + tut.IsComplete = true; + + }).Start(); + }); } + private static bool devx_alerted = false; + + private static event Action onCompleteDecrypt; + private static bool terminalIsOpen() { foreach(var win in AppearanceManager.OpenForms) @@ -100,6 +348,226 @@ namespace ShiftOS.WinForms } return false; } + + const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-_"; + + [Command("breach_user_password")] + [KernelMode] + [RequiresArgument("user")] + [RequiresArgument("sys")] + [RequiresUpgrade("hacker101_deadaccts")] + public static bool BreachUserPassword(Dictionary args) + { + string usr = args["user"].ToString(); + string sys = args["sys"].ToString(); + + ServerMessageReceived msgReceived = null; + + Console.WriteLine("--hooking system thread..."); + + msgReceived = (msg) => + { + if(msg.Name == "user_data") + { + var sve = JsonConvert.DeserializeObject(msg.Contents); + var rnd = new Random(); + var sw = new Stopwatch(); + sw.Start(); + string pass = ""; + for(int i = 0; i < sve.Password.Length; i++) + { + char c = '\0'; + while (c != sve.Password[i]) + c = chars[rnd.Next(0, chars.Length)]; + pass += c; + Thread.Sleep(rnd.Next(25,75)); + } + sw.Stop(); + Console.WriteLine(pass); + Console.WriteLine(); + Console.WriteLine("--password breached. Operation took " + sw.ElapsedMilliseconds + " milliseconds."); + } + else if(msg.Name == "user_data_not_found") + { + Console.WriteLine("--access denied."); + } + ServerManager.MessageReceived -= msgReceived; + }; + + Console.WriteLine("--beginning brute-force attack on " + usr + "@" + sys + "..."); + Thread.Sleep(500); + ServerManager.MessageReceived += msgReceived; + + ServerManager.SendMessage("get_user_data", JsonConvert.SerializeObject(new + { + user = usr, + sysname = sys + })); + return true; + } + + [Command("print_user_info")] + [KernelMode] + [RequiresArgument("pass")] + [RequiresArgument("user")] + [RequiresArgument("sys")] + [RequiresUpgrade("hacker101_deadaccts")] + public static bool PrintUserInfo(Dictionary args) + { + string usr = args["user"].ToString(); + string sys = args["sys"].ToString(); + string pass = args["pass"].ToString(); + + ServerMessageReceived msgReceived = null; + + Console.WriteLine("--hooking multi-user domain response call..."); + + msgReceived = (msg) => + { + if (msg.Name == "user_data") + { + var sve = JsonConvert.DeserializeObject(msg.Contents); + if(sve.Password == pass) + { + Console.WriteLine("Username: " + sve.Username); + Console.WriteLine("Password: " + sve.Password); + Console.WriteLine("System name: " + sve.SystemName); + Console.WriteLine(); + Console.WriteLine("Codepoints: " + sve.Codepoints.ToString()); + + } + else + { + Console.WriteLine("--access denied."); + } + + } + else if (msg.Name == "user_data_not_found") + { + Console.WriteLine("--access denied."); + } + ServerManager.MessageReceived -= msgReceived; + }; + + Console.WriteLine("--contacting multi-user domain..."); + Thread.Sleep(500); + ServerManager.MessageReceived += msgReceived; + + ServerManager.SendMessage("get_user_data", JsonConvert.SerializeObject(new + { + user = usr, + sysname = sys + })); + return true; + } + + [Command("steal_codepoints")] + [KernelMode] + [RequiresArgument("amount")] + [RequiresArgument("pass")] + [RequiresArgument("user")] + [RequiresArgument("sys")] + [RequiresUpgrade("hacker101_deadaccts")] + public static bool StealCodepoints(Dictionary args) + { + string usr = args["user"].ToString(); + string sys = args["sys"].ToString(); + string pass = args["pass"].ToString(); + long amount = (long)args["amount"]; + + if(amount < 0) + { + Console.WriteLine("--invalid codepoint amount - halting..."); + return true; + } + + ServerMessageReceived msgReceived = null; + + Console.WriteLine("--hooking multi-user domain response call..."); + + msgReceived = (msg) => + { + if (msg.Name == "user_data") + { + var sve = JsonConvert.DeserializeObject(msg.Contents); + if (sve.Password == pass) + { + if(amount > sve.Codepoints) + { + Console.WriteLine("--can't steal this many codepoints from user."); + return; + } + + sve.Codepoints -= amount; + SaveSystem.TransferCodepointsFrom(sve.Username, amount); + ServerManager.SendMessage("mud_save_allow_dead", JsonConvert.SerializeObject(sve)); + SaveSystem.SaveGame(); + } + else + { + Console.WriteLine("--access denied."); + } + + } + else if (msg.Name == "user_data_not_found") + { + Console.WriteLine("--access denied."); + } + ServerManager.MessageReceived -= msgReceived; + }; + + Console.WriteLine("--contacting multi-user domain..."); + Thread.Sleep(500); + ServerManager.MessageReceived += msgReceived; + + ServerManager.SendMessage("get_user_data", JsonConvert.SerializeObject(new + { + user = usr, + sysname = sys + })); + return true; + } + + + + [Command("brute_decrypt", true)] + [RequiresArgument("file")] + public static bool BruteDecrypt(Dictionary args) + { + if (FileExists(args["file"].ToString())) + { + string pass = new Random().Next(1000, 10000).ToString(); + string fake = ""; + Console.WriteLine("Beginning brute-force attack on password."); + var s = new Stopwatch(); + s.Start(); + for(int i = 0; i < pass.Length; i++) + { + for(int num = 0; num < 10; num++) + { + if(pass[i].ToString() == num.ToString()) + { + fake += num.ToString(); + Console.Write(num); + } + } + } + s.Stop(); + + Console.WriteLine("...password cracked - operation took " + s.ElapsedMilliseconds + " milliseconds."); + var tp = new TextPad(); + AppearanceManager.SetupWindow(tp); + WriteAllText("0:/temp.txt", ReadAllText(args["file"].ToString())); + tp.LoadFile("0:/temp.txt"); + Delete("0:/temp.txt"); + onCompleteDecrypt?.Invoke(); + } + else + { + Console.WriteLine("brute_decrypt: file not found"); + } + return true; + } } [Namespace("storydev")] diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 4bc79a0..7f728d5 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -208,6 +208,12 @@ Terminal.cs + + UserControl + + + TutorialBox.cs + @@ -350,6 +356,9 @@ Terminal.cs + + TutorialBox.cs + DownloadControl.cs diff --git a/ShiftOS_TheReturn/Command.cs b/ShiftOS_TheReturn/Command.cs index 85da6ca..a5924ed 100644 --- a/ShiftOS_TheReturn/Command.cs +++ b/ShiftOS_TheReturn/Command.cs @@ -30,6 +30,12 @@ using System.Threading.Tasks; namespace ShiftOS.Engine { + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)] + public class KernelModeAttribute : Attribute + { + + } + public class Command : Attribute { public string name; diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 76aa42f..0ea00e5 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -164,7 +164,35 @@ namespace ShiftOS.Engine } } + [Command("reconnect")] + [RequiresUpgrade("hacker101_deadaccts")] + public static bool Reconnect() + { + Console.WriteLine("--reconnecting to multi-user domain..."); + KernelWatchdog.MudConnected = true; + Console.WriteLine("--done."); + return true; + } + + [Command("disconnect")] + [RequiresUpgrade("hacker101_deadaccts")] + public static bool Disconnect() + { + Console.WriteLine("--connection to multi-user domain severed..."); + KernelWatchdog.MudConnected = false; + return true; + } + [Command("sendmsg")] + [KernelMode] + [RequiresUpgrade("hacker101_deadaccts")] + [RequiresArgument("header")] + [RequiresArgument("body")] + public static bool SendMessage(Dictionary args) + { + ServerManager.SendMessage(args["header"].ToString(), args["body"].ToString()); + return true; + } } [RequiresUpgrade("mud_fundamentals")] diff --git a/ShiftOS_TheReturn/KernelWatchdog.cs b/ShiftOS_TheReturn/KernelWatchdog.cs new file mode 100644 index 0000000..1b59b25 --- /dev/null +++ b/ShiftOS_TheReturn/KernelWatchdog.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using static ShiftOS.Objects.ShiftFS.Utils; + +namespace ShiftOS.Engine +{ + public static class KernelWatchdog + { + public static void Log(string e, string desc) + { + string line = $"[{DateTime.Now}] <{e}> {desc}"; + if (FileExists("0:/system/data/kernel.log")) + { + string contents = ReadAllText("0:/system/data/kernel.log"); + contents += Environment.NewLine + line; + WriteAllText("0:/system/data/kernel.log", contents); + } + else + { + WriteAllText("0:/system/data/kernel.log", line); + } + } + + public static bool InKernelMode { get; private set; } + public static bool MudConnected { get; set; } + + public static bool IsSafe(Type type) + { + if (InKernelMode == true) + return true; + + foreach (var attrib in type.GetCustomAttributes(false)) + { + if (attrib is KernelModeAttribute) + return false; + } + return true; + } + + public static bool IsSafe(MethodInfo type) + { + if (InKernelMode == true) + return true; + + foreach (var attrib in type.GetCustomAttributes(false)) + { + if (attrib is KernelModeAttribute) + return false; + } + return true; + } + + + public static void EnterKernelMode() + { + InKernelMode = true; + Console.WriteLine(" Watchdog deactivated, system-level access granted."); + } + + public static void LeaveKernelMode() + { + InKernelMode = false; + Console.WriteLine(" Kernel mode disabled."); + } + } +} diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index b9633e5..df4c6d6 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -155,6 +155,8 @@ namespace ShiftOS.Engine public static void FinishBootstrap() { + KernelWatchdog.Log("mud_handshake", "handshake successful: kernel watchdog access code is \"" + ServerManager.thisGuid.ToString() + "\""); + ServerManager.MessageReceived += (msg) => { if (msg.Name == "mud_savefile") @@ -313,7 +315,7 @@ namespace ShiftOS.Engine System.IO.File.WriteAllText(Paths.SaveFile, Utils.ExportMount(0)); } - public static void TransferCodepointsFrom(string who, int amount) + public static void TransferCodepointsFrom(string who, long amount) { NotificationDaemon.AddNotification(NotificationType.CodepointsReceived, amount); CurrentSave.Codepoints += amount; diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 3059391..a121ab6 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -126,6 +126,13 @@ namespace ShiftOS.Engine thisGuid = new Guid(msg.Contents); GUIDReceived?.Invoke(msg.Contents); } + else if(msg.Name == "allusers") + { + foreach(var acc in JsonConvert.DeserializeObject(msg.Contents)) + { + Console.WriteLine(acc); + } + } else if(msg.Name == "update_your_cp") { var args = JsonConvert.DeserializeObject>(msg.Contents); diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 3702b18..20ca879 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -107,6 +107,7 @@ + diff --git a/ShiftOS_TheReturn/Shiftorium.cs b/ShiftOS_TheReturn/Shiftorium.cs index 198dcc7..0bdd9f4 100644 --- a/ShiftOS_TheReturn/Shiftorium.cs +++ b/ShiftOS_TheReturn/Shiftorium.cs @@ -210,9 +210,12 @@ namespace ShiftOS.Engine if (SaveSystem.CurrentSave.StoriesExperienced == null) SaveSystem.CurrentSave.StoriesExperienced = new List(); - if (!SaveSystem.CurrentSave.StoriesExperienced.Contains(id)) - return SaveSystem.CurrentSave.Upgrades[id]; + bool upgInstalled = false; + if(SaveSystem.CurrentSave.Upgrades.ContainsKey(id)) + upgInstalled = SaveSystem.CurrentSave.Upgrades[id]; + if(upgInstalled == false) + return SaveSystem.CurrentSave.StoriesExperienced.Contains(id); return true; } catch diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 3c8e62a..8be54d0 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -139,121 +139,129 @@ namespace ShiftOS.Engine { if (Shiftorium.UpgradeAttributesUnlocked(type)) { - foreach (var a in type.GetCustomAttributes(false)) + if (KernelWatchdog.IsSafe(type)) { - if (a is Namespace) + foreach (var a in type.GetCustomAttributes(false)) { - var ns = a as Namespace; - if (text.Split('.')[0] == ns.name) + if (a is Namespace) { - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) + var ns = a as Namespace; + if (text.Split('.')[0] == ns.name) { - if (Shiftorium.UpgradeAttributesUnlocked(method)) + foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { - if (CanRunRemotely(method, isRemote)) + if (Shiftorium.UpgradeAttributesUnlocked(method)) { - foreach (var ma in method.GetCustomAttributes(false)) + if (KernelWatchdog.IsSafe(method)) { - if (ma is Command) + if (CanRunRemotely(method, isRemote)) { - var cmd = ma as Command; - if (text.Split('.')[1] == cmd.name) + foreach (var ma in method.GetCustomAttributes(false)) { - - var attr = method.GetCustomAttribute(); - - if (attr != null) + if (ma is Command) { - string newcommand = attr.newcommand; - if (attr.warn) + var cmd = ma as Command; + if (text.Split('.')[1] == cmd.name) { - Console.WriteLine(Localization.Parse((newcommand == "" ? "{ERROR}" : "{WARN}") + attr.reason, new Dictionary() { + + var attr = method.GetCustomAttribute(); + + if (attr != null) + { + string newcommand = attr.newcommand; + if (attr.warn) + { + Console.WriteLine(Localization.Parse((newcommand == "" ? "{ERROR}" : "{WARN}") + attr.reason, new Dictionary() { {"%newcommand", newcommand} })); - } - if (newcommand != "") - { - // redo the entire process running newcommand - - return RunClient(newcommand, args); - } - } + } + if (newcommand != "") + { + // redo the entire process running newcommand - var requiresArgs = method.GetCustomAttributes(); + return RunClient(newcommand, args); + } + } - bool error = false; - bool providedusage = false; + var requiresArgs = method.GetCustomAttributes(); - foreach (RequiresArgument argument in requiresArgs) - { - if (!args.ContainsKey(argument.argument)) - { + bool error = false; + bool providedusage = false; - if (!providedusage) + foreach (RequiresArgument argument in requiresArgs) { - string usageparse = "{COMMAND_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_USAGE}"; - if (usageparse == Localization.Parse(usageparse)) - usageparse = ""; - else - usageparse = Shiftorium.UpgradeInstalled("help_usage") ? Localization.Parse("{ERROR}{USAGE}" + usageparse, new Dictionary() { + if (!args.ContainsKey(argument.argument)) + { + + if (!providedusage) + { + string usageparse = "{COMMAND_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_USAGE}"; + if (usageparse == Localization.Parse(usageparse)) + usageparse = ""; + else + usageparse = Shiftorium.UpgradeInstalled("help_usage") ? Localization.Parse("{ERROR}{USAGE}" + usageparse, new Dictionary() { {"%ns", ns.name}, {"%cmd", cmd.name} }) : ""; - Console.WriteLine(usageparse); + Console.WriteLine(usageparse); - providedusage = true; - } + providedusage = true; + } - if (Shiftorium.UpgradeInstalled("help_usage")) - { - Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED}", new Dictionary() { + if (Shiftorium.UpgradeInstalled("help_usage")) + { + Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED}", new Dictionary() { {"%argument", argument.argument} })); + } + else + { + Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED_NO_USAGE}")); + } + + error = true; + } } - else + + if (error) { - Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED_NO_USAGE}")); + throw new Exception("{ERROR_COMMAND_WRONG}"); } - error = true; + try + { + return (bool)method.Invoke(null, new[] { args }); + } + 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 + { + return (bool)method.Invoke(null, new object[] { }); + } } } - - if (error) - { - throw new Exception("{ERROR_COMMAND_WRONG}"); - } - - try - { - return (bool)method.Invoke(null, new[] { args }); - } - 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 - { - return (bool)method.Invoke(null, new object[] { }); - } } } + else + { + Console.WriteLine(text + " cannot be ran in a remote session"); + return true; + } } - } - else - { - Console.WriteLine(text + " cannot be ran in a remote session"); - return true; + } } } } } } + } } } -- cgit v1.2.3 From 5f0cfb100cc0698ede828857393b7fd3f44af73d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 8 Mar 2017 19:08:35 -0500 Subject: selecting content in terminal copies to clipboard --- ShiftOS.WinForms/Controls/TerminalBox.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index 4fcb429..b75d077 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -61,5 +61,29 @@ namespace ShiftOS.WinForms.Controls { this.AppendText(Localization.Parse(text) + Environment.NewLine); } + + bool quickCopying = false; + + protected override void OnMouseDown(MouseEventArgs e) + { + //if right-clicking, then we initiate a quick-copy. + if (e.Button == MouseButtons.Right) + quickCopying = true; + + //Override the mouse event so that it's a left-click at all times. + base.OnMouseDown(new MouseEventArgs(MouseButtons.Left, e.Clicks, e.X, e.Y, e.Delta)); + } + + protected override void OnMouseUp(MouseEventArgs mevent) + { + if(quickCopying == true) + { + if (!string.IsNullOrWhiteSpace(this.SelectedText)) + { + this.Copy(); + } + } + base.OnMouseUp(mevent); + } } } -- cgit v1.2.3 From 3f08cb807c1490af423450e3eb03a46aa11caf2f Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 9 Mar 2017 16:14:35 -0500 Subject: Colored terminal text --- ShiftOS.WinForms/Controls/TerminalBox.cs | 10 ++++++++ ShiftOS.WinForms/Tools/ControlManager.cs | 42 ++++++++++++++++++++++++++++++++ ShiftOS_TheReturn/ConsoleEx.cs | 28 +++++++++++++++++++++ ShiftOS_TheReturn/ServerManager.cs | 2 ++ ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 + 5 files changed, 83 insertions(+) create mode 100644 ShiftOS_TheReturn/ConsoleEx.cs (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index b75d077..7c0da57 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -26,9 +26,11 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Engine; +using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Controls { @@ -53,13 +55,21 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { this.HideSelection = true; + this.Select(this.TextLength, 0); + this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); + this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text)); this.HideSelection = false; } public void WriteLine(string text) { + this.HideSelection = true; + this.Select(this.TextLength, 0); + this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); + this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text) + Environment.NewLine); + this.HideSelection = false; } bool quickCopying = false; diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs index 5cc4813..52663d7 100644 --- a/ShiftOS.WinForms/Tools/ControlManager.cs +++ b/ShiftOS.WinForms/Tools/ControlManager.cs @@ -152,6 +152,48 @@ namespace ShiftOS.WinForms.Tools } } + internal static Color ConvertColor(ConsoleColor cCol) + { + switch (cCol) + { + case ConsoleColor.Black: + return Color.Black; + case ConsoleColor.Gray: + return Color.Gray; + case ConsoleColor.DarkGray: + return Color.DarkGray; + case ConsoleColor.Blue: + return Color.Blue; + case ConsoleColor.Cyan: + return Color.Cyan; + case ConsoleColor.DarkBlue: + return Color.DarkBlue; + case ConsoleColor.DarkCyan: + return Color.DarkCyan; + case ConsoleColor.DarkGreen: + return Color.DarkGreen; + case ConsoleColor.DarkMagenta: + return Color.DarkMagenta; + case ConsoleColor.DarkRed: + return Color.DarkRed; + case ConsoleColor.DarkYellow: + return Color.YellowGreen; + case ConsoleColor.Yellow: + return Color.Yellow; + case ConsoleColor.Green: + return Color.Green; + case ConsoleColor.Magenta: + return Color.Magenta; + case ConsoleColor.Red: + return Color.Red; + case ConsoleColor.White: + return Color.White; + default: + return Color.Black; + } + + } + public static void SetCursor(Control ctrl) { #if STUPID diff --git a/ShiftOS_TheReturn/ConsoleEx.cs b/ShiftOS_TheReturn/ConsoleEx.cs new file mode 100644 index 0000000..69f6a18 --- /dev/null +++ b/ShiftOS_TheReturn/ConsoleEx.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Engine +{ + public static class ConsoleEx + { + static ConsoleEx() + { + ForegroundColor = ConsoleColor.White; + BackgroundColor = ConsoleColor.Black; + + Bold = false; + Italic = false; + Underline = false; + } + + public static ConsoleColor ForegroundColor { get; set; } + public static ConsoleColor BackgroundColor { get; set; } + + public static bool Bold { get; set; } + public static bool Italic { get; set; } + public static bool Underline { get; set; } + } +} diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index a121ab6..7da09f1 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -154,7 +154,9 @@ namespace ShiftOS.Engine { var ex = JsonConvert.DeserializeObject(msg.Contents); TerminalBackend.PrefixEnabled = true; + ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine($@"{{MUD_ERROR}}: {ex.Message}"); + ConsoleEx.ForegroundColor = ConsoleColor.White; TerminalBackend.PrefixEnabled = true; Console.Write($"{SaveSystem.CurrentSave.Username}@{CurrentSave.SystemName}:~$ "); } diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 20ca879..00d828f 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -99,6 +99,7 @@ + CrashHandler.cs -- cgit v1.2.3 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 ++-- ShiftOS.WinForms/Controls/TerminalBox.cs | 16 +++++++++++++++ ShiftOS_TheReturn/ServerManager.cs | 11 +++++++--- ShiftOS_TheReturn/TerminalBackend.cs | 34 ++++++++++++++++++++++++++++++- 4 files changed, 59 insertions(+), 6 deletions(-) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.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(); } } } diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index 7c0da57..9e4c61c 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -24,6 +24,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading; @@ -56,16 +57,31 @@ namespace ShiftOS.WinForms.Controls { 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)); this.HideSelection = false; } + private Font ConstructFont() + { + FontStyle fs = FontStyle.Regular; + if (ConsoleEx.Bold) + fs = fs | FontStyle.Bold; + if (ConsoleEx.Italic) + fs = fs | FontStyle.Italic; + if (ConsoleEx.Underline) + fs = fs | FontStyle.Underline; + + return new Font(this.Font, fs); + } + public void WriteLine(string text) { 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); diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 7da09f1..4d599cd 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -132,6 +132,7 @@ namespace ShiftOS.Engine { Console.WriteLine(acc); } + TerminalBackend.PrintPrompt(); } else if(msg.Name == "update_your_cp") { @@ -154,11 +155,15 @@ namespace ShiftOS.Engine { var ex = JsonConvert.DeserializeObject(msg.Contents); TerminalBackend.PrefixEnabled = true; + ConsoleEx.ForegroundColor = ConsoleColor.Red; + ConsoleEx.Bold = true; + Console.Write($@"{{MUD_ERROR}}: "); + ConsoleEx.Bold = false; + ConsoleEx.Italic = true; ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine($@"{{MUD_ERROR}}: {ex.Message}"); - ConsoleEx.ForegroundColor = ConsoleColor.White; + Console.WriteLine(ex.Message); TerminalBackend.PrefixEnabled = true; - Console.Write($"{SaveSystem.CurrentSave.Username}@{CurrentSave.SystemName}:~$ "); + TerminalBackend.PrintPrompt(); } else { diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index f78d7a5..841fd6a 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -283,7 +283,39 @@ namespace ShiftOS.Engine } return false; } - + + public static void PrintPrompt() + { + ConsoleEx.Italic = false; + ConsoleEx.Underline = false; + + ConsoleEx.ForegroundColor = ConsoleColor.Magenta; + ConsoleEx.Bold = true; + Console.Write(SaveSystem.CurrentSave.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 = ConsoleColor.White; + Console.Write(" "); + } + + static TerminalBackend() { ServerMessageReceived onMessageReceived = (msg) => -- cgit v1.2.3 From f89cd092830a8e88bd9aaf8048c18b0dda7dea25 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 2 Apr 2017 14:26:25 -0400 Subject: Various bugfixes. --- ShiftOS.WinForms/Controls/TerminalBox.cs | 8 +++ ShiftOS.WinForms/Oobe.cs | 22 +++---- ShiftOS.WinForms/WinformsDesktop.cs | 5 +- ShiftOS.WinForms/WinformsWindowManager.cs | 104 +++++++++++++++++++++++++++++- ShiftOS_TheReturn/AudioManager.cs | 2 +- ShiftOS_TheReturn/TerminalTextWriter.cs | 8 +-- 6 files changed, 129 insertions(+), 20 deletions(-) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index 9e4c61c..bc2bcc0 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -47,6 +47,14 @@ namespace ShiftOS.WinForms.Controls catch { } } + protected override void Dispose(bool disposing) + { + if (disposing == true) + if(AppearanceManager.ConsoleOut == this) + AppearanceManager.ConsoleOut = null; + base.Dispose(disposing); + } + protected override void OnClick(EventArgs e) { base.OnClick(e); diff --git a/ShiftOS.WinForms/Oobe.cs b/ShiftOS.WinForms/Oobe.cs index 7370396..898f60b 100644 --- a/ShiftOS.WinForms/Oobe.cs +++ b/ShiftOS.WinForms/Oobe.cs @@ -419,7 +419,7 @@ namespace ShiftOS.WinForms Clear(); textgeninput = lblhackwords; Clear(); - + this.Invoke(new Action(() => { textgeninput.Font = SkinEngine.LoadedSkin.TerminalFont; @@ -450,7 +450,7 @@ namespace ShiftOS.WinForms TextType("In ShiftOS, the Terminal is your main control centre for the operating system. You can see system status, check Codepoints, open other programs, buy upgrades, and more."); Thread.Sleep(500); TextType("Go ahead and type 'sos.help' to see a list of commands."); - while(TutorialProgress == 0) + while (TutorialProgress == 0) { } @@ -459,7 +459,7 @@ namespace ShiftOS.WinForms TextType("You can run any command, by typing in their Namespace, followed by a period (.), followed by their Command Name."); Thread.Sleep(500); TextType("Go ahead and run the 'status' command within the 'sos' namespace to see what the command does."); - while(TutorialProgress == 1) + while (TutorialProgress == 1) { } @@ -476,7 +476,7 @@ namespace ShiftOS.WinForms TextType("You can easily get upgrades using the Shiftorium - a repository of approved ShiftOS upgrades."); Thread.Sleep(500); TextType("To start using the Shiftorium, simply type 'shiftorium.list' to see available upgrades."); - while(TutorialProgress == 2) + while (TutorialProgress == 2) { } @@ -500,17 +500,17 @@ namespace ShiftOS.WinForms TextType("If you want to escape a backslash inside a string, simply type two backslashes instead of one - for example key:\"Back\\\\slash.\""); Thread.Sleep(500); TextType("shiftorium.info requires an upgrade argument, which is a string type. Go ahead and give shiftorium.info's upgrade argument the 'mud_fundamentals' upgrade's ID."); - while(TutorialProgress == 3) + while (TutorialProgress == 3) { - } + } TextType("As you can see, mud_fundamentals is very useful. In fact, a lot of useful upgrades depend on it. You should buy it!"); Thread.Sleep(500); TextType("shiftorium.info already gave you a command that will let you buy the upgrade - go ahead and run that command!"); while (!Shiftorium.UpgradeInstalled("mud_fundamentals")) { - } + } TextType("Hooray! You now have the MUD Fundamentals upgrade."); Thread.Sleep(500); TextType("You can also earn more Codepoints by playing Pong. To open Pong, you can use the win.open command."); @@ -518,20 +518,20 @@ namespace ShiftOS.WinForms TextType("If you run win.open without arguments, you can see a list of applications that you can open."); Thread.Sleep(500); TextType("Just run win.open without arguments, and this tutorial will be completed!"); - while(TutorialProgress == 4) + while (TutorialProgress == 4) { } TextType("This concludes the ShiftOS beginners' guide brought to you by the multi-user domain. Stay safe in a connected world."); Thread.Sleep(2000); - this.Invoke(new Action(() => + Desktop.InvokeOnWorkerThread(() => { OnComplete?.Invoke(this, EventArgs.Empty); - this.Close(); SaveSystem.CurrentSave.StoryPosition = 2; SaveSystem.SaveGame(); AppearanceManager.SetupWindow(new Applications.Terminal()); - })); + }); + }); t.IsBackground = true; t.Start(); diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index d30adb4..06f103e 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -664,7 +664,10 @@ namespace ShiftOS.WinForms /// Act. public void InvokeOnWorkerThread(Action act) { - this.Invoke(act); + this.Invoke(new Action(()=> + { + act?.Invoke(); + })); } public void OpenAppLauncher(Point loc) diff --git a/ShiftOS.WinForms/WinformsWindowManager.cs b/ShiftOS.WinForms/WinformsWindowManager.cs index eeaa6c9..40177be 100644 --- a/ShiftOS.WinForms/WinformsWindowManager.cs +++ b/ShiftOS.WinForms/WinformsWindowManager.cs @@ -36,6 +36,24 @@ namespace ShiftOS.WinForms { internal class WinformsWindowManager : WindowManager { + public int DesktopHeight + { + get + { + return Desktop.Size.Height - ((Shiftorium.UpgradeInstalled("desktop_panel") == true) ? SkinEngine.LoadedSkin.DesktopPanelHeight : 0); + } + } + + public int TopLocation + { + get + { + if (!Shiftorium.UpgradeInstalled("desktop_panel")) + return 0; + return ((SkinEngine.LoadedSkin.DesktopPanelPosition == 0) ? SkinEngine.LoadedSkin.DesktopPanelHeight : 0); + } + } + public override void Close(IShiftOSWindow win) { (win as UserControl).Close(); @@ -160,9 +178,11 @@ namespace ShiftOS.WinForms { List formstoclose = new List(); - foreach (WindowBorder frm in AppearanceManager.OpenForms) + for (int i = 0; i < maxWindows && i < AppearanceManager.OpenForms.Count; i++) { - formstoclose.Add(frm); + var frm = AppearanceManager.OpenForms[i] as WindowBorder; + if(!frm.IsDialog) + formstoclose.Add(frm); } @@ -177,7 +197,85 @@ namespace ShiftOS.WinForms var wb = new WindowBorder(form as UserControl); - ControlManager.SetupWindows(); + SetupWindows(); + } + + public void SetupWindows() + { + var windows = new List(); + foreach(var win in AppearanceManager.OpenForms) + { + if (win is WindowBorder) + if ((win as WindowBorder).IsDialog == false) + windows.Add(win as WindowBorder); + } + + if (Shiftorium.UpgradeInstalled("wm_free_placement")) + return; + + else if (windows.Count == 4) + { + var w1 = windows[0]; + var w2 = windows[1]; + var w3 = windows[2]; + var w4 = windows[3]; + w1.Location = new Point(0, TopLocation); + w1.Width = Desktop.Size.Width / 2; + w1.Height = DesktopHeight / 2; + w2.Left = w1.Width; + w2.Width = w1.Width; + w2.Height = w1.Height; + w2.Top = w1.Top; + w3.Top = w2.Height; + w3.Height = w1.Height; + w3.Left = 0; + w3.Width = w1.Width; + w4.Width = w3.Width; + w4.Top = w3.Top; + w4.Left = w3.Width; + w4.Height = w3.Height; + } + else if(windows.Count == 3) + { + var w1 = windows[0]; + var w2 = windows[1]; + var w3 = windows[2]; + w1.Location = new Point(0, TopLocation); + w1.Width = Desktop.Size.Width / 2; + w1.Height = DesktopHeight / 2; + w2.Left = w1.Width; + w2.Width = w1.Width; + w2.Height = w1.Height; + w2.Top = w1.Top; + w3.Top = w2.Height; + w3.Height = w1.Height; + w3.Left = 0; + w3.Width = w1.Width + w2.Width; + } + else if (windows.Count == 2) + { + var w1 = windows[0]; + var w2 = windows[1]; + + w1.Location = new Point(0, TopLocation); + w1.Width = Desktop.Size.Width / 2; + w1.Height = DesktopHeight; + w2.Left = w1.Width; + w2.Width = w1.Width; + w2.Height = w1.Height; + w2.Top = w1.Top; + + } + else if(windows.Count == 1) + { + var win = windows.FirstOrDefault(); + if(win != null) + { + win.Size = new Size(Desktop.Size.Width, DesktopHeight); + win.Location = new Point(0, this.TopLocation); + } + } + } } } diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index 7f6f5e9..7466eeb 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -22,7 +22,7 @@ * SOFTWARE. */ -//#define NOSOUND +#define NOSOUND using System; using System.Collections.Generic; diff --git a/ShiftOS_TheReturn/TerminalTextWriter.cs b/ShiftOS_TheReturn/TerminalTextWriter.cs index bc242a9..55e27cf 100644 --- a/ShiftOS_TheReturn/TerminalTextWriter.cs +++ b/ShiftOS_TheReturn/TerminalTextWriter.cs @@ -58,7 +58,7 @@ namespace ShiftOS.Engine { Desktop.InvokeOnWorkerThread(new Action(() => { - UnderlyingControl.SelectBottom(); + UnderlyingControl?.SelectBottom(); })); } @@ -76,7 +76,7 @@ namespace ShiftOS.Engine { Desktop.InvokeOnWorkerThread(new Action(() => { - UnderlyingControl.Write(value.ToString()); + UnderlyingControl?.Write(value.ToString()); select(); })); } @@ -96,7 +96,7 @@ namespace ShiftOS.Engine Desktop.InvokeOnWorkerThread(new Action(() => { - UnderlyingControl.WriteLine(value); + UnderlyingControl?.WriteLine(value); select(); })); } @@ -120,7 +120,7 @@ namespace ShiftOS.Engine Desktop.InvokeOnWorkerThread(new Action(() => { - UnderlyingControl.Write(value.ToString()); + UnderlyingControl?.Write(value.ToString()); select(); })); } -- cgit v1.2.3 From 2ac1033c2dcd0e70114ab9ee5c7bd129bff6c1fa Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 9 Apr 2017 15:56:14 -0400 Subject: Legion story work (SPOILERS!) --- ShiftOS.Objects/Reputation.cs | 21 ++- .../Applications/Installer.Designer.cs | 104 +++++++++++++ ShiftOS.WinForms/Applications/Installer.cs | 150 ++++++++++++++++++ ShiftOS.WinForms/Applications/Installer.resx | 120 +++++++++++++++ .../Applications/MUDControlCentre.Designer.cs | 88 +++++++++++ ShiftOS.WinForms/Applications/MUDControlCentre.cs | 54 ++++++- ShiftOS.WinForms/Controls/TerminalBox.cs | 1 - ShiftOS.WinForms/ShiftOS.WinForms.csproj | 10 ++ ShiftOS.WinForms/Stories/LegionStory.cs | 169 +++++++++++++++++++++ 9 files changed, 707 insertions(+), 10 deletions(-) create mode 100644 ShiftOS.WinForms/Applications/Installer.Designer.cs create mode 100644 ShiftOS.WinForms/Applications/Installer.cs create mode 100644 ShiftOS.WinForms/Applications/Installer.resx create mode 100644 ShiftOS.WinForms/Stories/LegionStory.cs (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.Objects/Reputation.cs b/ShiftOS.Objects/Reputation.cs index 32bb911..0ddea0a 100644 --- a/ShiftOS.Objects/Reputation.cs +++ b/ShiftOS.Objects/Reputation.cs @@ -23,38 +23,43 @@ namespace ShiftOS.Objects public enum UserClass { + /// + /// The user has no class. + /// + None = 0, + /// /// Skinners, otherwise known as "Shifters" due to their excessive use of the Shifter application, like to customize ShiftOS to look like other operating systems or even have an entirely different UI. They gain heaps of codepoints from it, and like to sell their skins for even more Codepoints. /// - Skinner, + Skinner = 1, /// /// Hackers are notorious for taking down large groups and individuals of which have many useful documents and Codepoints on their system. Hackers enjoy the rush of typing malicious commands into their terminals and seeing how they affect their target. /// - Hacker, + Hacker = 2, /// /// Much like hackers, investigators are skilled with a terminal and breaching systems, but they don't do it directly for monetary gain. They will search a target's system for any files and clues that may lead to them being guilty of a crime within the digital society. Unlike Hackers, Investigators mostly have higher reputations in society, and go after those with lower reputations. /// - Investigator, + Investigator = 3, /// /// Explorers like to venture the vast regions of the multi-user domain and Shiftnet looking for secrets, hidden tools and software, and finding the hidden truths behind their screen. Explorers don't always know how to hack, but if it involves finding a secret about ShiftOS, they will do it. They typically do not have malicious intent. /// - Explorer, + Explorer = 4, /// /// Safety Activists are skilled with exploitation and hacking, but they only go after the worst there is in the multi-user domain. Crime rings, large hacker groups, you name it. Their primary goal is keeping the multi-user domain safe. /// - SafetyActivist, + SafetyActivist = 5, /// /// Penetration testers go hand-in-hand with Safety Activists. They go after the good guys, but rather than attacking them, they alert them that an exploit was found in their service and that this exploit should be fixed. They are a gray subject though - you never know if you are dealing with a genuine pen-tester or a hacker skilled with social engineering. Be careful. /// - PenetrationTester, + PenetrationTester = 6, /// /// Collectors go well with Explorers - however, Collectors are the ones who open shops. They like to find rare objects and sell them for Codepoints. /// - Collector, + Collector = 7, /// /// Programmers are the ones who write applications and services for ShiftOS and the multi-user domain. Depending on the code that they write, they can be seen as either morally wrong sentiences or morally correct sentiences, it's up to their decisions. /// - Programmer + Programmer = 8 } } diff --git a/ShiftOS.WinForms/Applications/Installer.Designer.cs b/ShiftOS.WinForms/Applications/Installer.Designer.cs new file mode 100644 index 0000000..8b4ae81 --- /dev/null +++ b/ShiftOS.WinForms/Applications/Installer.Designer.cs @@ -0,0 +1,104 @@ +namespace ShiftOS.WinForms.Applications +{ + partial class Installer + { + /// + /// 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.lbtitle = new System.Windows.Forms.Label(); + this.pnlselectfile = new System.Windows.Forms.Panel(); + this.pginstall = new ShiftOS.WinForms.Controls.ShiftedProgressBar(); + this.lbprogress = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // lbtitle + // + this.lbtitle.AutoSize = true; + this.lbtitle.Location = new System.Drawing.Point(14, 13); + this.lbtitle.Name = "lbtitle"; + this.lbtitle.Size = new System.Drawing.Size(155, 13); + this.lbtitle.TabIndex = 0; + this.lbtitle.Tag = "header2"; + this.lbtitle.Text = "Installing MUD Control Centre..."; + // + // pnlselectfile + // + this.pnlselectfile.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.pnlselectfile.Location = new System.Drawing.Point(17, 48); + this.pnlselectfile.Name = "pnlselectfile"; + this.pnlselectfile.Size = new System.Drawing.Size(414, 85); + this.pnlselectfile.TabIndex = 1; + this.pnlselectfile.VisibleChanged += new System.EventHandler(this.pnlselectfile_VisibleChanged); + // + // pginstall + // + this.pginstall.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.pginstall.BlockSize = 5; + this.pginstall.Location = new System.Drawing.Point(17, 161); + this.pginstall.Maximum = 100; + this.pginstall.Name = "pginstall"; + this.pginstall.Size = new System.Drawing.Size(414, 23); + this.pginstall.Style = System.Windows.Forms.ProgressBarStyle.Continuous; + this.pginstall.TabIndex = 2; + this.pginstall.Text = "shiftedProgressBar1"; + this.pginstall.Value = 0; + // + // lbprogress + // + this.lbprogress.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.lbprogress.AutoSize = true; + this.lbprogress.Location = new System.Drawing.Point(17, 140); + this.lbprogress.Name = "lbprogress"; + this.lbprogress.Size = new System.Drawing.Size(35, 13); + this.lbprogress.TabIndex = 3; + this.lbprogress.Text = "label1"; + // + // Installer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.lbprogress); + this.Controls.Add(this.pginstall); + this.Controls.Add(this.pnlselectfile); + this.Controls.Add(this.lbtitle); + this.Name = "Installer"; + this.Size = new System.Drawing.Size(447, 203); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label lbtitle; + private System.Windows.Forms.Panel pnlselectfile; + private Controls.ShiftedProgressBar pginstall; + private System.Windows.Forms.Label lbprogress; + } +} diff --git a/ShiftOS.WinForms/Applications/Installer.cs b/ShiftOS.WinForms/Applications/Installer.cs new file mode 100644 index 0000000..1b5521e --- /dev/null +++ b/ShiftOS.WinForms/Applications/Installer.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms.Applications +{ + public partial class Installer : UserControl, IShiftOSWindow + { + public Installer() + { + InitializeComponent(); + lbtitle.Text = "Select file"; + } + + public void InitiateInstall(Installation install) + { + pnlselectfile.Hide(); + install.ProgressReported += (p) => + { + this.Invoke(new Action(() => + { + pginstall.Value = p; + })); + }; + install.StatusReported += (s) => + { + this.Invoke(new Action(() => + { + lbprogress.Text = s; + })); + }; + install.InstallCompleted += () => + { + this.Invoke(new Action(() => + { + lbtitle.Text = "Select file"; + pnlselectfile.Show(); + })); + isInstalling = false; + InstallCompleted?.Invoke(); + }; + isInstalling = true; + install.Install(); + } + + public void OnLoad() + { + } + + private bool isInstalling = false; + + public void OnSkinLoad() + { + } + + public bool OnUnload() + { + return !isInstalling; //Don't close if an install is running. + } + + public void OnUpgrade() + { + + } + + private void pnlselectfile_VisibleChanged(object sender, EventArgs e) + { + if(this.ParentForm != null) + { + this.ParentForm.Height = (pnlselectfile.Visible == true) ? this.ParentForm.Height + pnlselectfile.Height : this.ParentForm.Height - pnlselectfile.Height; + } + } + public event Action InstallCompleted; + } + + public abstract class Installation + { + /// + /// The display name of the installation. + /// + public string Name { get; set; } + + /// + /// Occurs when the installation updates its status. + /// + public event Action StatusReported; + /// + /// Occurs when the installation updates its progress percentage. + /// + public event Action ProgressReported; + /// + /// Occurs when the installation completes. + /// + public event Action InstallCompleted; + + /// + /// Start the installation. + /// + public void Install() + { + var t = new System.Threading.Thread(() => + { + ProgressReported?.Invoke(0); + StatusReported?.Invoke(""); + Run(); + ProgressReported?.Invoke(100); + StatusReported?.Invoke("Installation completed."); + InstallCompleted?.Invoke(); + }); + t.IsBackground = true; + t.Start(); + } + + /// + /// Sets the install progress percentage. + /// + /// The installation percentage. + protected void SetProgress(int value) + { + if (value < 0 || value > 100) + throw new ArgumentOutOfRangeException("value", "A percentage is typically between 0 and 100.... derp..."); + ProgressReported?.Invoke(value); + } + + /// + /// Sets the install status text. + /// + /// Text to display as status. + protected void SetStatus(string status) + { + StatusReported?.Invoke(status); + } + + /// + /// User-defined code to run during install. Once this code is ran, the installation is complete. + /// + protected abstract void Run(); + } + + + + +} diff --git a/ShiftOS.WinForms/Applications/Installer.resx b/ShiftOS.WinForms/Applications/Installer.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/Applications/Installer.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/Applications/MUDControlCentre.Designer.cs b/ShiftOS.WinForms/Applications/MUDControlCentre.Designer.cs index ba4c4f1..e2c0af3 100644 --- a/ShiftOS.WinForms/Applications/MUDControlCentre.Designer.cs +++ b/ShiftOS.WinForms/Applications/MUDControlCentre.Designer.cs @@ -144,6 +144,12 @@ namespace ShiftOS.WinForms.Applications this.you_memos = new System.Windows.Forms.Panel(); this.flmemos = new System.Windows.Forms.FlowLayoutPanel(); this.label3 = new System.Windows.Forms.Label(); + this.pnlclasses = new System.Windows.Forms.Panel(); + this.lbclasstitle = new System.Windows.Forms.Label(); + this.lbclassdesc = new System.Windows.Forms.Label(); + this.lbclasses = new System.Windows.Forms.ListBox(); + this.flowLayoutPanel6 = new System.Windows.Forms.FlowLayoutPanel(); + this.btnchooseclass = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); this.toolStripContainer1.ContentPanel.SuspendLayout(); this.toolStripContainer1.TopToolStripPanel.SuspendLayout(); @@ -172,6 +178,8 @@ namespace ShiftOS.WinForms.Applications this.panel3.SuspendLayout(); this.flowLayoutPanel2.SuspendLayout(); this.you_memos.SuspendLayout(); + this.pnlclasses.SuspendLayout(); + this.flowLayoutPanel6.SuspendLayout(); this.SuspendLayout(); // // menuStrip1 @@ -301,6 +309,7 @@ namespace ShiftOS.WinForms.Applications // // toolStripContainer1.ContentPanel // + this.toolStripContainer1.ContentPanel.Controls.Add(this.pnlclasses); this.toolStripContainer1.ContentPanel.Controls.Add(this.you_systemstatus); this.toolStripContainer1.ContentPanel.Controls.Add(this.shop_all); this.toolStripContainer1.ContentPanel.Controls.Add(this.shop_view); @@ -1182,6 +1191,75 @@ namespace ShiftOS.WinForms.Applications this.label3.Tag = "header1"; this.label3.Text = "Memos"; // + // pnlclasses + // + this.pnlclasses.Controls.Add(this.flowLayoutPanel6); + this.pnlclasses.Controls.Add(this.lbclasses); + this.pnlclasses.Controls.Add(this.lbclassdesc); + this.pnlclasses.Controls.Add(this.lbclasstitle); + this.pnlclasses.Dock = System.Windows.Forms.DockStyle.Fill; + this.pnlclasses.Location = new System.Drawing.Point(0, 0); + this.pnlclasses.Name = "pnlclasses"; + this.pnlclasses.Size = new System.Drawing.Size(756, 464); + this.pnlclasses.TabIndex = 3; + // + // lbclasstitle + // + this.lbclasstitle.AutoSize = true; + this.lbclasstitle.Dock = System.Windows.Forms.DockStyle.Top; + this.lbclasstitle.Location = new System.Drawing.Point(0, 0); + this.lbclasstitle.Name = "lbclasstitle"; + this.lbclasstitle.Padding = new System.Windows.Forms.Padding(10); + this.lbclasstitle.Size = new System.Drawing.Size(82, 33); + this.lbclasstitle.TabIndex = 0; + this.lbclasstitle.Tag = "header1"; + this.lbclasstitle.Text = "Join a class"; + // + // lbclassdesc + // + this.lbclassdesc.AutoSize = true; + this.lbclassdesc.Dock = System.Windows.Forms.DockStyle.Top; + this.lbclassdesc.Location = new System.Drawing.Point(0, 33); + this.lbclassdesc.Name = "lbclassdesc"; + this.lbclassdesc.Padding = new System.Windows.Forms.Padding(10); + this.lbclassdesc.Size = new System.Drawing.Size(727, 33); + this.lbclassdesc.TabIndex = 1; + this.lbclassdesc.Text = "A class is a way for the multi-user domain to better understand you. It defines w" + + "ho you are as a sentient being, what you do, what you like, and so on."; + // + // lbclasses + // + this.lbclasses.Dock = System.Windows.Forms.DockStyle.Fill; + this.lbclasses.FormattingEnabled = true; + this.lbclasses.Location = new System.Drawing.Point(0, 66); + this.lbclasses.Name = "lbclasses"; + this.lbclasses.Size = new System.Drawing.Size(756, 398); + this.lbclasses.TabIndex = 2; + // + // flowLayoutPanel6 + // + this.flowLayoutPanel6.AutoSize = true; + this.flowLayoutPanel6.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flowLayoutPanel6.Controls.Add(this.btnchooseclass); + this.flowLayoutPanel6.Dock = System.Windows.Forms.DockStyle.Bottom; + this.flowLayoutPanel6.Location = new System.Drawing.Point(0, 415); + this.flowLayoutPanel6.Name = "flowLayoutPanel6"; + this.flowLayoutPanel6.Padding = new System.Windows.Forms.Padding(10); + this.flowLayoutPanel6.Size = new System.Drawing.Size(756, 49); + this.flowLayoutPanel6.TabIndex = 3; + // + // btnchooseclass + // + this.btnchooseclass.AutoSize = true; + this.btnchooseclass.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnchooseclass.Location = new System.Drawing.Point(13, 13); + this.btnchooseclass.Name = "btnchooseclass"; + this.btnchooseclass.Size = new System.Drawing.Size(53, 23); + this.btnchooseclass.TabIndex = 0; + this.btnchooseclass.Text = "Choose"; + this.btnchooseclass.UseVisualStyleBackColor = true; + this.btnchooseclass.Click += new System.EventHandler(this.btnchooseclass_Click); + // // MUDControlCentre // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1242,6 +1320,10 @@ namespace ShiftOS.WinForms.Applications this.flowLayoutPanel2.PerformLayout(); this.you_memos.ResumeLayout(false); this.you_memos.PerformLayout(); + this.pnlclasses.ResumeLayout(false); + this.pnlclasses.PerformLayout(); + this.flowLayoutPanel6.ResumeLayout(false); + this.flowLayoutPanel6.PerformLayout(); this.ResumeLayout(false); } @@ -1339,5 +1421,11 @@ namespace ShiftOS.WinForms.Applications private System.Windows.Forms.ToolStripMenuItem chatToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem joinAChatToolStripMenuItem; private System.Windows.Forms.Button btndeletesave; + private System.Windows.Forms.Panel pnlclasses; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel6; + private System.Windows.Forms.Button btnchooseclass; + private System.Windows.Forms.ListBox lbclasses; + private System.Windows.Forms.Label lbclassdesc; + private System.Windows.Forms.Label lbclasstitle; } } diff --git a/ShiftOS.WinForms/Applications/MUDControlCentre.cs b/ShiftOS.WinForms/Applications/MUDControlCentre.cs index e2668bd..5a51f48 100644 --- a/ShiftOS.WinForms/Applications/MUDControlCentre.cs +++ b/ShiftOS.WinForms/Applications/MUDControlCentre.cs @@ -39,7 +39,7 @@ using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { [MultiplayerOnly] - [RequiresUpgrade("mud_fundamentals")] + [RequiresUpgrade("mud_control_centre")] [Launcher("MUD Control Centre", true, "al_mud_control_centre", "Networking")] [WinOpen("mud_control_centre")] [DefaultIcon("iconSysinfo")] @@ -177,6 +177,42 @@ namespace ShiftOS.WinForms.Applications }; } + + + internal void ShowClasses() + { + var descriptions = new Dictionary { + + { UserClass.Skinner, "Skinners, otherwise known as \"Shifters\" due to their excessive use of the Shifter application, like to customize ShiftOS to look like other operating systems or even have an entirely different UI. They gain heaps of codepoints from it, and like to sell their skins for even more Codepoints." }, + { UserClass.Hacker, "Hackers are notorious for taking down large groups and individuals of which have many useful documents and Codepoints on their system. Hackers enjoy the rush of typing malicious commands into their terminals and seeing how they affect their target." }, + { UserClass.Investigator, "Much like hackers, investigators are skilled with a terminal and breaching systems, but they don't do it directly for monetary gain. They will search a target's system for any files and clues that may lead to them being guilty of a crime within the digital society. Unlike Hackers, Investigators mostly have higher reputations in society, and go after those with lower reputations."}, + { UserClass.Explorer, "Explorers like to venture the vast regions of the multi-user domain and Shiftnet looking for secrets, hidden tools and software, and finding the hidden truths behind their screen. Explorers don't always know how to hack, but if it involves finding a secret about ShiftOS, they will do it. They typically do not have malicious intent."}, + { UserClass.SafetyActivist, "Safety Activists are skilled with exploitation and hacking, but they only go after the worst there is in the multi-user domain. Crime rings, large hacker groups, you name it. Their primary goal is keeping the multi-user domain safe." }, + { UserClass.PenetrationTester, "Penetration testers go hand-in-hand with Safety Activists. They go after the good guys, but rather than attacking them, they alert them that an exploit was found in their service and that this exploit should be fixed. They are a gray subject though - you never know if you are dealing with a genuine pen-tester or a hacker skilled with social engineering. Be careful." }, + { UserClass.Collector, "Collectors go well with Explorers - however, Collectors are the ones who open shops. They like to find rare objects and sell them for Codepoints." }, + {UserClass.Programmer, "Programmers are the ones who write applications and services for ShiftOS and the multi-user domain. Depending on the code that they write, they can be seen as either morally wrong sentiences or morally correct sentiences, it's up to their decisions." }, + + }; + + lbclasses.Items.Clear(); + lbclasses.SelectedIndexChanged += (o, a) => + { + newClass = (UserClass)Enum.Parse(typeof(UserClass), lbclasses.SelectedItem.ToString()); + lbclassdesc.Text = descriptions[newClass]; + lbclasstitle.Text = newClass.ToString(); + }; + foreach (var kv in descriptions) + { + lbclasses.Items.Add(kv.Key.ToString()); + + } + menuStrip1.Hide(); + pnlclasses.Show(); + pnlclasses.BringToFront(); + } + + UserClass newClass = UserClass.None; + public void ListAllChats(Channel[] channels) { shop_all.BringToFront(); @@ -890,5 +926,21 @@ Current legions: {legionname}"; } }); } + + public event Action ClassChanged; + + private void btnchooseclass_Click(object sender, EventArgs e) + { + if(newClass != UserClass.None) + { + SaveSystem.CurrentSave.Class = newClass; + SaveSystem.SaveGame(); + ClassChanged?.Invoke(); + menuStrip1.Show(); + pnlclasses.SendToBack(); + this.SetupSystemStatus(); + return; + } + } } } diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index bc2bcc0..df820f7 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -64,7 +64,6 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { this.HideSelection = true; - this.Select(this.TextLength, 0); this.SelectionFont = ConstructFont(); this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index ca0001e..95612ef 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -131,6 +131,12 @@ GraphicPicker.cs + + UserControl + + + Installer.cs + UserControl @@ -279,6 +285,7 @@ + @@ -336,6 +343,9 @@ GraphicPicker.cs + + Installer.cs + ShiftLetters.cs diff --git a/ShiftOS.WinForms/Stories/LegionStory.cs b/ShiftOS.WinForms/Stories/LegionStory.cs new file mode 100644 index 0000000..424c54b --- /dev/null +++ b/ShiftOS.WinForms/Stories/LegionStory.cs @@ -0,0 +1,169 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using ShiftOS.Engine; + +namespace ShiftOS.WinForms.Stories +{ + public static class LegionStory + { + private static void WriteLine(string text, bool showCharacterName=true) + { + Console.WriteLine(); + if (showCharacterName == true) + { + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.DarkMagenta; + Console.Write("DevX"); + Console.ForegroundColor = ConsoleColor.White; + Console.Write("@"); + ConsoleEx.ForegroundColor = ConsoleColor.Yellow; + Console.Write("mud: "); + } + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + ConsoleEx.Bold = false; + + foreach (var c in text) + { + Desktop.InvokeOnWorkerThread(() => + { + Console.Write(c); + }); + Thread.Sleep(75); + } + Thread.Sleep(1000); + } + + public static bool terminalOpen() + { + foreach(var win in AppearanceManager.OpenForms) + { + if (win.ParentWindow is Applications.Terminal) + return true; + } + return false; + } + + [Story("mud_control_centre")] + public static void MCC_Placeholder() + { + //What a way to create unbuyable, engine-managed Shiftorium Upgrades... :P + } + + [Story("devx_legions")] + public static void DevXLegionStory() + { + bool waiting = false; + //Used for DevX dialogue. + //Used for legion selection. + var mud = new Applications.MUDControlCentre(); + //For installing the MCC + var installer = new Applications.Installer(); + installer.InstallCompleted += () => + { + Desktop.InvokeOnWorkerThread(() => + { + AppearanceManager.Close(installer); + }); + waiting = false; + }; + + if (!terminalOpen()) + { + var term = new Applications.Terminal(); + AppearanceManager.SetupWindow(term); + } + + var t = new Thread(() => + { + WriteLine("DevX@mud - user connecting to your system.", false); + Thread.Sleep(2000); + WriteLine($"Hello, {SaveSystem.CurrentSave.Username}. It's been a while."); + WriteLine("My intelligence suggests you've installed all GUI-based Shiftorium upgrades."); + WriteLine("Bet you're liking ShiftOS now that the terminal isn't the only way you can control it."); + WriteLine("Well, now it's time to introduce your next task."); + WriteLine("In the multi-user domain, each user has a reputation value associated with them."); + WriteLine("Right now, you have a reputation of 0, Neutral."); + WriteLine("This means that nobody has an opinion on you, yet."); + WriteLine("What a good time to make your presence known?"); + WriteLine("I have an application for you to try, that will help you out in the multi-user domain, and help you make yourself famous."); + WriteLine("In the digital society, you can't survive long as a lone sentience. You must kongregate with a group, and these groups are called \"legions\"."); + WriteLine("This application will assist you in finding one. A legion is a group of sentiences who carry out actions together. They're like... a pack of wolves, or a family, if you will."); + WriteLine("They share Codepoints, documents, applications, and other things with each other."); + WriteLine("And they all have their own goals."); + WriteLine("Up until now, you've been blindly following my directions, with the goal of upgrading ShiftOS. Now, it's time for you to join a legion, and fulfill their goals, to become known within the digital society."); + + WriteLine("You'll do all of this through the MUD Control Centre."); + WriteLine("I'll set it up on your system now."); + //Set up an Installer. + waiting = true; + Desktop.InvokeOnWorkerThread(() => + { + AppearanceManager.SetupWindow(installer); + installer.InitiateInstall(new MCCInstallation()); + }); + while (waiting == true) + Thread.Sleep(25); + + WriteLine("There, it's all installed, so let's get you set up with a legion, shall we?"); + Desktop.InvokeOnWorkerThread(() => + { + AppearanceManager.SetupWindow(mud); + mud.ShowClasses(); + mud.ClassChanged += () => + { + waiting = false; + }; + }); + WriteLine("First, select a class. A class will help define your personality within the multi-user domain. It'll determine the best legions for you."); + waiting = true; + while (waiting == true) + Thread.Sleep(25); + TerminalBackend.PrefixEnabled = true; + TerminalBackend.PrintPrompt(); + }); + t.IsBackground = true; + t.Start(); + + TerminalBackend.PrefixEnabled = false; + } + + public class MCCInstallation : Applications.Installation + { + protected override void Run() + { + SetStatus("Beginning installation..."); + Thread.Sleep(1270); + SetProgress(10); + SetStatus("Installing base application..."); + for(int i = 0; i < 45; i++) + { + Thread.Sleep(25); + SetProgress(10 + i); + } + SetStatus("Configuring system..."); + //First, we initialize the user's legion value. + SaveSystem.CurrentSave.CurrentLegions = new List(); + Thread.Sleep(250); + SetProgress(65); + //Now we initialize their shop value. + SaveSystem.CurrentSave.MyShop = null; + Thread.Sleep(200); + SetProgress(75); + //Now for their reputation... + SaveSystem.CurrentSave.RawReputation = 0.000; + Thread.Sleep(250); + SetProgress(90); + //Now their class. + SaveSystem.CurrentSave.Class = Objects.UserClass.None; + Thread.Sleep(200); + Story.Start("mud_control_centre"); + SaveSystem.SaveGame(); + SetProgress(100); + } + } + } +} -- cgit v1.2.3 From fb481614fc2cd64357d60c4459adb5b65072bbce Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 14 Apr 2017 10:50:05 -0400 Subject: Dramatic speed-up of window loading. --- ShiftOS.WinForms/Applications/Artpad.cs | 371 +++---------------------------- ShiftOS.WinForms/Controls/TerminalBox.cs | 5 + ShiftOS.WinForms/Tools/ControlManager.cs | 106 ++++++--- ShiftOS.WinForms/WindowBorder.cs | 6 +- 4 files changed, 114 insertions(+), 374 deletions(-) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Applications/Artpad.cs b/ShiftOS.WinForms/Applications/Artpad.cs index 71f7afb..7ef66aa 100644 --- a/ShiftOS.WinForms/Applications/Artpad.cs +++ b/ShiftOS.WinForms/Applications/Artpad.cs @@ -38,6 +38,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.WinForms.Tools; using ShiftOS.Engine; +using System.Diagnostics; namespace ShiftOS.WinForms.Applications { @@ -55,8 +56,11 @@ namespace ShiftOS.WinForms.Applications { try { + Stopwatch sw = new Stopwatch(); + sw.Start(); InitializeComponent(); - + sw.Stop(); + Console.WriteLine("ArtPad construction timespan:" + sw.Elapsed.ToString()); } catch (Exception ex) { @@ -141,17 +145,7 @@ namespace ShiftOS.WinForms.Applications private void Template_Load(object sender, EventArgs e) { - justopened = true; - this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2; - this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2; - - setuppreview(); - settoolcolours(); - loadcolors(); - AddFonts(); - setuptoolbox(); - determinevisiblepalettes(); - tmrsetupui.Start(); + //Moved to the engine "OnLoad" method. } @@ -171,55 +165,24 @@ namespace ShiftOS.WinForms.Applications needtosave = false; } + //PHILCODE: I just reduced this function's amount of Windows Forms calls by 66%. public void setuptoolbox() { - btnpixelplacer.Hide(); - btnpencil.Hide(); - btnfloodfill.Hide(); - btnoval.Hide(); - btnsquare.Hide(); - btnlinetool.Hide(); - btnpaintbrush.Hide(); - btntexttool.Hide(); - btneracer.Hide(); - btnnew.Hide(); - btnopen.Hide(); - btnsave.Hide(); - btnundo.Hide(); - btnredo.Hide(); - btnpixelplacermovementmode.Hide(); - - if (ShiftoriumFrontend.UpgradeInstalled("artpad_pixel_placer") == true) - btnpixelplacer.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_pencil") == true) - btnpencil.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_fill_tool") == true) - btnfloodfill.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_oval_tool") == true) - btnoval.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_rectangle_tool") == true) - btnsquare.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_line_tool") == true) - btnlinetool.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_paintbrush") == true) - btnpaintbrush.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_text_tool") == true) - btntexttool.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_eraser") == true) - btneracer.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_new") == true) - btnnew.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_load") == true) - btnopen.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_save") == true) - btnsave.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_undo") == true) - btnundo.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_redo") == true) - btnredo.Show(); - if (ShiftoriumFrontend.UpgradeInstalled("artpad_pp_movement_mode") == true) - btnpixelplacermovementmode.Show(); - + btnpixelplacer.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_pixel_placer") == true); + btnpencil.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_pencil") == true); + btnfloodfill.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_fill_tool") == true); + btnoval.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_oval_tool") == true); + btnsquare.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_rectangle_tool") == true); + btnlinetool.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_line_tool") == true); + btnpaintbrush.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_paintbrush") == true); + btntexttool.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_text_tool") == true); + btneracer.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_eraser") == true); + btnnew.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_new") == true); + btnopen.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_load") == true); + btnsave.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_save") == true); + btnundo.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_undo") == true); + btnredo.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_redo") == true); + btnpixelplacermovementmode.Visible = (ShiftoriumFrontend.UpgradeInstalled("artpad_pp_movement_mode") == true); } private void AddFonts() @@ -688,290 +651,6 @@ namespace ShiftOS.WinForms.Applications } } - // - public void loadcolors() - { - /*bool allwhite = true; - for (int i = 0; i <= 127; i++) - { - if (ShiftOSDesktop.artpad_colour_palettes(i) == null) - { - } - else { - allwhite = false; - } - } - if (allwhite == true) - { - for (i = 0; i <= 127; i++) - { - ShiftOSDesktop.artpad_colour_palettes(i) = Color.Black; - } - } - colourpalette1.BackColor = ShiftOSDesktop.artpad_colour_palettes(0); - colourpalette2.BackColor = ShiftOSDesktop.artpad_colour_palettes(1); - colourpalette3.BackColor = ShiftOSDesktop.artpad_colour_palettes(2); - colourpalette4.BackColor = ShiftOSDesktop.artpad_colour_palettes(3); - colourpalette5.BackColor = ShiftOSDesktop.artpad_colour_palettes(4); - colourpalette6.BackColor = ShiftOSDesktop.artpad_colour_palettes(5); - colourpalette7.BackColor = ShiftOSDesktop.artpad_colour_palettes(6); - colourpalette8.BackColor = ShiftOSDesktop.artpad_colour_palettes(7); - colourpalette9.BackColor = ShiftOSDesktop.artpad_colour_palettes(8); - colourpalette10.BackColor = ShiftOSDesktop.artpad_colour_palettes(9); - colourpalette11.BackColor = ShiftOSDesktop.artpad_colour_palettes(10); - colourpalette12.BackColor = ShiftOSDesktop.artpad_colour_palettes(11); - colourpalette13.BackColor = ShiftOSDesktop.artpad_colour_palettes(12); - colourpalette14.BackColor = ShiftOSDesktop.artpad_colour_palettes(13); - colourpalette15.BackColor = ShiftOSDesktop.artpad_colour_palettes(14); - colourpalette16.BackColor = ShiftOSDesktop.artpad_colour_palettes(15); - colourpalette17.BackColor = ShiftOSDesktop.artpad_colour_palettes(16); - colourpalette18.BackColor = ShiftOSDesktop.artpad_colour_palettes(17); - colourpalette19.BackColor = ShiftOSDesktop.artpad_colour_palettes(18); - colourpalette20.BackColor = ShiftOSDesktop.artpad_colour_palettes(19); - colourpalette21.BackColor = ShiftOSDesktop.artpad_colour_palettes(20); - colourpalette22.BackColor = ShiftOSDesktop.artpad_colour_palettes(21); - colourpalette23.BackColor = ShiftOSDesktop.artpad_colour_palettes(22); - colourpalette24.BackColor = ShiftOSDesktop.artpad_colour_palettes(23); - colourpalette25.BackColor = ShiftOSDesktop.artpad_colour_palettes(24); - colourpalette26.BackColor = ShiftOSDesktop.artpad_colour_palettes(25); - colourpalette27.BackColor = ShiftOSDesktop.artpad_colour_palettes(26); - colourpalette28.BackColor = ShiftOSDesktop.artpad_colour_palettes(27); - colourpalette29.BackColor = ShiftOSDesktop.artpad_colour_palettes(28); - colourpalette30.BackColor = ShiftOSDesktop.artpad_colour_palettes(29); - colourpalette31.BackColor = ShiftOSDesktop.artpad_colour_palettes(30); - colourpalette32.BackColor = ShiftOSDesktop.artpad_colour_palettes(31); - colourpalette33.BackColor = ShiftOSDesktop.artpad_colour_palettes(32); - colourpalette34.BackColor = ShiftOSDesktop.artpad_colour_palettes(33); - colourpalette35.BackColor = ShiftOSDesktop.artpad_colour_palettes(34); - colourpalette36.BackColor = ShiftOSDesktop.artpad_colour_palettes(35); - colourpalette37.BackColor = ShiftOSDesktop.artpad_colour_palettes(36); - colourpalette38.BackColor = ShiftOSDesktop.artpad_colour_palettes(37); - colourpalette39.BackColor = ShiftOSDesktop.artpad_colour_palettes(38); - colourpalette40.BackColor = ShiftOSDesktop.artpad_colour_palettes(39); - colourpalette41.BackColor = ShiftOSDesktop.artpad_colour_palettes(40); - colourpalette42.BackColor = ShiftOSDesktop.artpad_colour_palettes(41); - colourpalette43.BackColor = ShiftOSDesktop.artpad_colour_palettes(42); - colourpalette44.BackColor = ShiftOSDesktop.artpad_colour_palettes(43); - colourpalette45.BackColor = ShiftOSDesktop.artpad_colour_palettes(44); - colourpalette46.BackColor = ShiftOSDesktop.artpad_colour_palettes(45); - colourpalette47.BackColor = ShiftOSDesktop.artpad_colour_palettes(46); - colourpalette48.BackColor = ShiftOSDesktop.artpad_colour_palettes(47); - colourpalette49.BackColor = ShiftOSDesktop.artpad_colour_palettes(48); - colourpalette50.BackColor = ShiftOSDesktop.artpad_colour_palettes(49); - colourpalette51.BackColor = ShiftOSDesktop.artpad_colour_palettes(50); - colourpalette52.BackColor = ShiftOSDesktop.artpad_colour_palettes(51); - colourpalette53.BackColor = ShiftOSDesktop.artpad_colour_palettes(52); - colourpalette54.BackColor = ShiftOSDesktop.artpad_colour_palettes(53); - colourpalette55.BackColor = ShiftOSDesktop.artpad_colour_palettes(54); - colourpalette56.BackColor = ShiftOSDesktop.artpad_colour_palettes(55); - colourpalette57.BackColor = ShiftOSDesktop.artpad_colour_palettes(56); - colourpalette58.BackColor = ShiftOSDesktop.artpad_colour_palettes(57); - colourpalette59.BackColor = ShiftOSDesktop.artpad_colour_palettes(58); - colourpalette60.BackColor = ShiftOSDesktop.artpad_colour_palettes(59); - colourpalette61.BackColor = ShiftOSDesktop.artpad_colour_palettes(60); - colourpalette62.BackColor = ShiftOSDesktop.artpad_colour_palettes(61); - colourpalette63.BackColor = ShiftOSDesktop.artpad_colour_palettes(62); - colourpalette64.BackColor = ShiftOSDesktop.artpad_colour_palettes(63); - colourpalette65.BackColor = ShiftOSDesktop.artpad_colour_palettes(64); - colourpalette66.BackColor = ShiftOSDesktop.artpad_colour_palettes(65); - colourpalette67.BackColor = ShiftOSDesktop.artpad_colour_palettes(66); - colourpalette68.BackColor = ShiftOSDesktop.artpad_colour_palettes(67); - colourpalette69.BackColor = ShiftOSDesktop.artpad_colour_palettes(68); - colourpalette70.BackColor = ShiftOSDesktop.artpad_colour_palettes(69); - colourpalette71.BackColor = ShiftOSDesktop.artpad_colour_palettes(70); - colourpalette72.BackColor = ShiftOSDesktop.artpad_colour_palettes(71); - colourpalette73.BackColor = ShiftOSDesktop.artpad_colour_palettes(72); - colourpalette74.BackColor = ShiftOSDesktop.artpad_colour_palettes(73); - colourpalette75.BackColor = ShiftOSDesktop.artpad_colour_palettes(74); - colourpalette76.BackColor = ShiftOSDesktop.artpad_colour_palettes(75); - colourpalette77.BackColor = ShiftOSDesktop.artpad_colour_palettes(76); - colourpalette78.BackColor = ShiftOSDesktop.artpad_colour_palettes(77); - colourpalette79.BackColor = ShiftOSDesktop.artpad_colour_palettes(78); - colourpalette80.BackColor = ShiftOSDesktop.artpad_colour_palettes(79); - colourpalette81.BackColor = ShiftOSDesktop.artpad_colour_palettes(80); - colourpalette82.BackColor = ShiftOSDesktop.artpad_colour_palettes(81); - colourpalette83.BackColor = ShiftOSDesktop.artpad_colour_palettes(82); - colourpalette84.BackColor = ShiftOSDesktop.artpad_colour_palettes(83); - colourpalette85.BackColor = ShiftOSDesktop.artpad_colour_palettes(84); - colourpalette86.BackColor = ShiftOSDesktop.artpad_colour_palettes(85); - colourpalette87.BackColor = ShiftOSDesktop.artpad_colour_palettes(86); - colourpalette88.BackColor = ShiftOSDesktop.artpad_colour_palettes(87); - colourpalette89.BackColor = ShiftOSDesktop.artpad_colour_palettes(88); - colourpalette90.BackColor = ShiftOSDesktop.artpad_colour_palettes(89); - colourpalette91.BackColor = ShiftOSDesktop.artpad_colour_palettes(90); - colourpalette92.BackColor = ShiftOSDesktop.artpad_colour_palettes(91); - colourpalette93.BackColor = ShiftOSDesktop.artpad_colour_palettes(92); - colourpalette94.BackColor = ShiftOSDesktop.artpad_colour_palettes(93); - colourpalette95.BackColor = ShiftOSDesktop.artpad_colour_palettes(94); - colourpalette96.BackColor = ShiftOSDesktop.artpad_colour_palettes(95); - colourpalette97.BackColor = ShiftOSDesktop.artpad_colour_palettes(96); - colourpalette98.BackColor = ShiftOSDesktop.artpad_colour_palettes(97); - colourpalette99.BackColor = ShiftOSDesktop.artpad_colour_palettes(98); - colourpalette100.BackColor = ShiftOSDesktop.artpad_colour_palettes(99); - colourpalette101.BackColor = ShiftOSDesktop.artpad_colour_palettes(100); - colourpalette102.BackColor = ShiftOSDesktop.artpad_colour_palettes(101); - colourpalette103.BackColor = ShiftOSDesktop.artpad_colour_palettes(102); - colourpalette104.BackColor = ShiftOSDesktop.artpad_colour_palettes(103); - colourpalette105.BackColor = ShiftOSDesktop.artpad_colour_palettes(104); - colourpalette106.BackColor = ShiftOSDesktop.artpad_colour_palettes(105); - colourpalette107.BackColor = ShiftOSDesktop.artpad_colour_palettes(106); - colourpalette108.BackColor = ShiftOSDesktop.artpad_colour_palettes(107); - colourpalette109.BackColor = ShiftOSDesktop.artpad_colour_palettes(108); - colourpalette110.BackColor = ShiftOSDesktop.artpad_colour_palettes(109); - colourpalette111.BackColor = ShiftOSDesktop.artpad_colour_palettes(110); - colourpalette112.BackColor = ShiftOSDesktop.artpad_colour_palettes(111); - colourpalette113.BackColor = ShiftOSDesktop.artpad_colour_palettes(112); - colourpalette114.BackColor = ShiftOSDesktop.artpad_colour_palettes(113); - colourpalette115.BackColor = ShiftOSDesktop.artpad_colour_palettes(114); - colourpalette116.BackColor = ShiftOSDesktop.artpad_colour_palettes(115); - colourpalette117.BackColor = ShiftOSDesktop.artpad_colour_palettes(116); - colourpalette118.BackColor = ShiftOSDesktop.artpad_colour_palettes(117); - colourpalette119.BackColor = ShiftOSDesktop.artpad_colour_palettes(118); - colourpalette120.BackColor = ShiftOSDesktop.artpad_colour_palettes(119); - colourpalette121.BackColor = ShiftOSDesktop.artpad_colour_palettes(120); - colourpalette122.BackColor = ShiftOSDesktop.artpad_colour_palettes(121); - colourpalette123.BackColor = ShiftOSDesktop.artpad_colour_palettes(122); - colourpalette124.BackColor = ShiftOSDesktop.artpad_colour_palettes(123); - colourpalette125.BackColor = ShiftOSDesktop.artpad_colour_palettes(124); - colourpalette126.BackColor = ShiftOSDesktop.artpad_colour_palettes(125); - colourpalette127.BackColor = ShiftOSDesktop.artpad_colour_palettes(126); - colourpalette128.BackColor = ShiftOSDesktop.artpad_colour_palettes(127); - */ - } - - public void savecolors() - {/* - ShiftOSDesktop.artpad_colour_palettes(0) = colourpalette1.BackColor; - ShiftOSDesktop.artpad_colour_palettes(1) = colourpalette2.BackColor; - ShiftOSDesktop.artpad_colour_palettes(2) = colourpalette3.BackColor; - ShiftOSDesktop.artpad_colour_palettes(3) = colourpalette4.BackColor; - ShiftOSDesktop.artpad_colour_palettes(4) = colourpalette5.BackColor; - ShiftOSDesktop.artpad_colour_palettes(5) = colourpalette6.BackColor; - ShiftOSDesktop.artpad_colour_palettes(6) = colourpalette7.BackColor; - ShiftOSDesktop.artpad_colour_palettes(7) = colourpalette8.BackColor; - ShiftOSDesktop.artpad_colour_palettes(8) = colourpalette9.BackColor; - ShiftOSDesktop.artpad_colour_palettes(9) = colourpalette10.BackColor; - ShiftOSDesktop.artpad_colour_palettes(10) = colourpalette11.BackColor; - ShiftOSDesktop.artpad_colour_palettes(11) = colourpalette12.BackColor; - ShiftOSDesktop.artpad_colour_palettes(12) = colourpalette13.BackColor; - ShiftOSDesktop.artpad_colour_palettes(13) = colourpalette14.BackColor; - ShiftOSDesktop.artpad_colour_palettes(14) = colourpalette15.BackColor; - ShiftOSDesktop.artpad_colour_palettes(15) = colourpalette16.BackColor; - ShiftOSDesktop.artpad_colour_palettes(16) = colourpalette17.BackColor; - ShiftOSDesktop.artpad_colour_palettes(17) = colourpalette18.BackColor; - ShiftOSDesktop.artpad_colour_palettes(18) = colourpalette19.BackColor; - ShiftOSDesktop.artpad_colour_palettes(19) = colourpalette20.BackColor; - ShiftOSDesktop.artpad_colour_palettes(20) = colourpalette21.BackColor; - ShiftOSDesktop.artpad_colour_palettes(21) = colourpalette22.BackColor; - ShiftOSDesktop.artpad_colour_palettes(22) = colourpalette23.BackColor; - ShiftOSDesktop.artpad_colour_palettes(23) = colourpalette24.BackColor; - ShiftOSDesktop.artpad_colour_palettes(24) = colourpalette25.BackColor; - ShiftOSDesktop.artpad_colour_palettes(25) = colourpalette26.BackColor; - ShiftOSDesktop.artpad_colour_palettes(26) = colourpalette27.BackColor; - ShiftOSDesktop.artpad_colour_palettes(27) = colourpalette28.BackColor; - ShiftOSDesktop.artpad_colour_palettes(28) = colourpalette29.BackColor; - ShiftOSDesktop.artpad_colour_palettes(29) = colourpalette30.BackColor; - ShiftOSDesktop.artpad_colour_palettes(30) = colourpalette31.BackColor; - ShiftOSDesktop.artpad_colour_palettes(31) = colourpalette32.BackColor; - ShiftOSDesktop.artpad_colour_palettes(32) = colourpalette33.BackColor; - ShiftOSDesktop.artpad_colour_palettes(33) = colourpalette34.BackColor; - ShiftOSDesktop.artpad_colour_palettes(34) = colourpalette35.BackColor; - ShiftOSDesktop.artpad_colour_palettes(35) = colourpalette36.BackColor; - ShiftOSDesktop.artpad_colour_palettes(36) = colourpalette37.BackColor; - ShiftOSDesktop.artpad_colour_palettes(37) = colourpalette38.BackColor; - ShiftOSDesktop.artpad_colour_palettes(38) = colourpalette39.BackColor; - ShiftOSDesktop.artpad_colour_palettes(39) = colourpalette40.BackColor; - ShiftOSDesktop.artpad_colour_palettes(40) = colourpalette41.BackColor; - ShiftOSDesktop.artpad_colour_palettes(41) = colourpalette42.BackColor; - ShiftOSDesktop.artpad_colour_palettes(42) = colourpalette43.BackColor; - ShiftOSDesktop.artpad_colour_palettes(43) = colourpalette44.BackColor; - ShiftOSDesktop.artpad_colour_palettes(44) = colourpalette45.BackColor; - ShiftOSDesktop.artpad_colour_palettes(45) = colourpalette46.BackColor; - ShiftOSDesktop.artpad_colour_palettes(46) = colourpalette47.BackColor; - ShiftOSDesktop.artpad_colour_palettes(47) = colourpalette48.BackColor; - ShiftOSDesktop.artpad_colour_palettes(48) = colourpalette49.BackColor; - ShiftOSDesktop.artpad_colour_palettes(49) = colourpalette50.BackColor; - ShiftOSDesktop.artpad_colour_palettes(50) = colourpalette51.BackColor; - ShiftOSDesktop.artpad_colour_palettes(51) = colourpalette52.BackColor; - ShiftOSDesktop.artpad_colour_palettes(52) = colourpalette53.BackColor; - ShiftOSDesktop.artpad_colour_palettes(53) = colourpalette54.BackColor; - ShiftOSDesktop.artpad_colour_palettes(54) = colourpalette55.BackColor; - ShiftOSDesktop.artpad_colour_palettes(55) = colourpalette56.BackColor; - ShiftOSDesktop.artpad_colour_palettes(56) = colourpalette57.BackColor; - ShiftOSDesktop.artpad_colour_palettes(57) = colourpalette58.BackColor; - ShiftOSDesktop.artpad_colour_palettes(58) = colourpalette59.BackColor; - ShiftOSDesktop.artpad_colour_palettes(59) = colourpalette60.BackColor; - ShiftOSDesktop.artpad_colour_palettes(60) = colourpalette61.BackColor; - ShiftOSDesktop.artpad_colour_palettes(61) = colourpalette62.BackColor; - ShiftOSDesktop.artpad_colour_palettes(62) = colourpalette63.BackColor; - ShiftOSDesktop.artpad_colour_palettes(63) = colourpalette64.BackColor; - ShiftOSDesktop.artpad_colour_palettes(64) = colourpalette65.BackColor; - ShiftOSDesktop.artpad_colour_palettes(65) = colourpalette66.BackColor; - ShiftOSDesktop.artpad_colour_palettes(66) = colourpalette67.BackColor; - ShiftOSDesktop.artpad_colour_palettes(67) = colourpalette68.BackColor; - ShiftOSDesktop.artpad_colour_palettes(68) = colourpalette69.BackColor; - ShiftOSDesktop.artpad_colour_palettes(69) = colourpalette70.BackColor; - ShiftOSDesktop.artpad_colour_palettes(70) = colourpalette71.BackColor; - ShiftOSDesktop.artpad_colour_palettes(71) = colourpalette72.BackColor; - ShiftOSDesktop.artpad_colour_palettes(72) = colourpalette73.BackColor; - ShiftOSDesktop.artpad_colour_palettes(73) = colourpalette74.BackColor; - ShiftOSDesktop.artpad_colour_palettes(74) = colourpalette75.BackColor; - ShiftOSDesktop.artpad_colour_palettes(75) = colourpalette76.BackColor; - ShiftOSDesktop.artpad_colour_palettes(76) = colourpalette77.BackColor; - ShiftOSDesktop.artpad_colour_palettes(77) = colourpalette78.BackColor; - ShiftOSDesktop.artpad_colour_palettes(78) = colourpalette79.BackColor; - ShiftOSDesktop.artpad_colour_palettes(79) = colourpalette80.BackColor; - ShiftOSDesktop.artpad_colour_palettes(80) = colourpalette81.BackColor; - ShiftOSDesktop.artpad_colour_palettes(81) = colourpalette82.BackColor; - ShiftOSDesktop.artpad_colour_palettes(82) = colourpalette83.BackColor; - ShiftOSDesktop.artpad_colour_palettes(83) = colourpalette84.BackColor; - ShiftOSDesktop.artpad_colour_palettes(84) = colourpalette85.BackColor; - ShiftOSDesktop.artpad_colour_palettes(85) = colourpalette86.BackColor; - ShiftOSDesktop.artpad_colour_palettes(86) = colourpalette87.BackColor; - ShiftOSDesktop.artpad_colour_palettes(87) = colourpalette88.BackColor; - ShiftOSDesktop.artpad_colour_palettes(88) = colourpalette89.BackColor; - ShiftOSDesktop.artpad_colour_palettes(89) = colourpalette90.BackColor; - ShiftOSDesktop.artpad_colour_palettes(90) = colourpalette91.BackColor; - ShiftOSDesktop.artpad_colour_palettes(91) = colourpalette92.BackColor; - ShiftOSDesktop.artpad_colour_palettes(92) = colourpalette93.BackColor; - ShiftOSDesktop.artpad_colour_palettes(93) = colourpalette94.BackColor; - ShiftOSDesktop.artpad_colour_palettes(94) = colourpalette95.BackColor; - ShiftOSDesktop.artpad_colour_palettes(95) = colourpalette96.BackColor; - ShiftOSDesktop.artpad_colour_palettes(96) = colourpalette97.BackColor; - ShiftOSDesktop.artpad_colour_palettes(97) = colourpalette98.BackColor; - ShiftOSDesktop.artpad_colour_palettes(98) = colourpalette99.BackColor; - ShiftOSDesktop.artpad_colour_palettes(99) = colourpalette100.BackColor; - ShiftOSDesktop.artpad_colour_palettes(100) = colourpalette101.BackColor; - ShiftOSDesktop.artpad_colour_palettes(101) = colourpalette102.BackColor; - ShiftOSDesktop.artpad_colour_palettes(102) = colourpalette103.BackColor; - ShiftOSDesktop.artpad_colour_palettes(103) = colourpalette104.BackColor; - ShiftOSDesktop.artpad_colour_palettes(104) = colourpalette105.BackColor; - ShiftOSDesktop.artpad_colour_palettes(105) = colourpalette106.BackColor; - ShiftOSDesktop.artpad_colour_palettes(106) = colourpalette107.BackColor; - ShiftOSDesktop.artpad_colour_palettes(107) = colourpalette108.BackColor; - ShiftOSDesktop.artpad_colour_palettes(108) = colourpalette109.BackColor; - ShiftOSDesktop.artpad_colour_palettes(109) = colourpalette110.BackColor; - ShiftOSDesktop.artpad_colour_palettes(110) = colourpalette111.BackColor; - ShiftOSDesktop.artpad_colour_palettes(111) = colourpalette112.BackColor; - ShiftOSDesktop.artpad_colour_palettes(112) = colourpalette113.BackColor; - ShiftOSDesktop.artpad_colour_palettes(113) = colourpalette114.BackColor; - ShiftOSDesktop.artpad_colour_palettes(114) = colourpalette115.BackColor; - ShiftOSDesktop.artpad_colour_palettes(115) = colourpalette116.BackColor; - ShiftOSDesktop.artpad_colour_palettes(116) = colourpalette117.BackColor; - ShiftOSDesktop.artpad_colour_palettes(117) = colourpalette118.BackColor; - ShiftOSDesktop.artpad_colour_palettes(118) = colourpalette119.BackColor; - ShiftOSDesktop.artpad_colour_palettes(119) = colourpalette120.BackColor; - ShiftOSDesktop.artpad_colour_palettes(120) = colourpalette121.BackColor; - ShiftOSDesktop.artpad_colour_palettes(121) = colourpalette122.BackColor; - ShiftOSDesktop.artpad_colour_palettes(122) = colourpalette123.BackColor; - ShiftOSDesktop.artpad_colour_palettes(123) = colourpalette124.BackColor; - ShiftOSDesktop.artpad_colour_palettes(124) = colourpalette125.BackColor; - ShiftOSDesktop.artpad_colour_palettes(125) = colourpalette126.BackColor; - ShiftOSDesktop.artpad_colour_palettes(126) = colourpalette127.BackColor; - ShiftOSDesktop.artpad_colour_palettes(127) = colourpalette128.BackColor; - */ - } - // public void settoolcolours() { @@ -1859,6 +1538,12 @@ namespace ShiftOS.WinForms.Applications ctrl.Tag = "keepbg"; ctrl.BackColor = Color.Black; } + setuppreview(); + settoolcolours(); + AddFonts(); + setuptoolbox(); + determinevisiblepalettes(); + } public void OnSkinLoad() diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index df820f7..cdb0965 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -118,5 +118,10 @@ namespace ShiftOS.WinForms.Controls } base.OnMouseUp(mevent); } + + public TerminalBox() : base() + { + this.Tag = "keepbg keepfg keepfont"; + } } } diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs index a2a76b7..781e045 100644 --- a/ShiftOS.WinForms/Tools/ControlManager.cs +++ b/ShiftOS.WinForms/Tools/ControlManager.cs @@ -28,6 +28,7 @@ using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Engine; @@ -143,9 +144,11 @@ namespace ShiftOS.WinForms.Tools public static void SetupControl(Control ctrl) { - SuspendDrawing(ctrl); - ctrl.SuspendLayout(); - SetCursor(ctrl); + Desktop.InvokeOnWorkerThread(new Action(() => + { + SuspendDrawing(ctrl); + ctrl.SuspendLayout(); + })); if (!(ctrl is MenuStrip) && !(ctrl is ToolStrip) && !(ctrl is StatusStrip) && !(ctrl is ContextMenuStrip)) { string tag = ""; @@ -160,32 +163,52 @@ namespace ShiftOS.WinForms.Tools { if (ctrl.BackColor != Control.DefaultBackColor) { - ctrl.BackColor = SkinEngine.LoadedSkin.ControlColor; + Desktop.InvokeOnWorkerThread(() => + { + ctrl.BackColor = SkinEngine.LoadedSkin.ControlColor; + }); } } - ctrl.ForeColor = SkinEngine.LoadedSkin.ControlTextColor; - - ctrl.Font = SkinEngine.LoadedSkin.MainFont; - - if (tag.Contains("header1")) + if (!tag.Contains("keepfont")) { - ctrl.Font = SkinEngine.LoadedSkin.HeaderFont; - } + Desktop.InvokeOnWorkerThread(() => + { + ctrl.ForeColor = SkinEngine.LoadedSkin.ControlTextColor; + ctrl.Font = SkinEngine.LoadedSkin.MainFont; + }); + if (tag.Contains("header1")) + { + Desktop.InvokeOnWorkerThread(() => + { + ctrl.Font = SkinEngine.LoadedSkin.HeaderFont; + }); + } - if (tag.Contains("header2")) - { - ctrl.Font = SkinEngine.LoadedSkin.Header2Font; - } + if (tag.Contains("header2")) + { + Desktop.InvokeOnWorkerThread(() => + { + ctrl.Font = SkinEngine.LoadedSkin.Header2Font; + }); + } - if (tag.Contains("header3")) - { - ctrl.Font = SkinEngine.LoadedSkin.Header3Font; - } + if (tag.Contains("header3")) + { + Desktop.InvokeOnWorkerThread(() => + { + ctrl.Font = SkinEngine.LoadedSkin.Header3Font; + }); + } + } try { - ctrl.Text = Localization.Parse(ctrl.Text); + string ctrlText = Localization.Parse(ctrl.Text); + Desktop.InvokeOnWorkerThread(() => + { + ctrl.Text = ctrlText; + }); } catch { @@ -206,19 +229,31 @@ namespace ShiftOS.WinForms.Tools }; if (ctrl is Button) { - (ctrl as Button).FlatStyle = FlatStyle.Flat; + Desktop.InvokeOnWorkerThread(() => + { + (ctrl as Button).FlatStyle = FlatStyle.Flat; + }); } else if (ctrl is WindowBorder) { - (ctrl as WindowBorder).Setup(); + Desktop.InvokeOnWorkerThread(() => + { + (ctrl as WindowBorder).Setup(); + }); } } + Desktop.InvokeOnWorkerThread(() => + { - MakeDoubleBuffered(ctrl); - ctrl.ResumeLayout(); - ResumeDrawing(ctrl); + MakeDoubleBuffered(ctrl); + ctrl.ResumeLayout(); + ResumeDrawing(ctrl); + }); + ControlSetup?.Invoke(ctrl); } + public static event Action ControlSetup; + public static void MakeDoubleBuffered(Control c) { if (System.Windows.Forms.SystemInformation.TerminalServerSession) @@ -234,13 +269,28 @@ namespace ShiftOS.WinForms.Tools } - public static void SetupControls(Control frm) + public static void SetupControls(Control frm, bool runInThread = true) { SetupControl(frm); - for (int i = 0; i < frm.Controls.Count; i++) + ThreadStart ts = () => + { + for (int i = 0; i < frm.Controls.Count; i++) + { + SetupControls(frm.Controls[i], false); + } + + }; + + if (runInThread == true) + { + var t = new Thread(ts); + t.IsBackground = true; + t.Start(); + } + else { - SetupControls(frm.Controls[i]); + ts?.Invoke(); } } diff --git a/ShiftOS.WinForms/WindowBorder.cs b/ShiftOS.WinForms/WindowBorder.cs index 4babbbd..e716803 100644 --- a/ShiftOS.WinForms/WindowBorder.cs +++ b/ShiftOS.WinForms/WindowBorder.cs @@ -146,8 +146,6 @@ namespace ShiftOS.WinForms }; - this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2; - this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2; if (!this.IsDialog) { @@ -171,7 +169,6 @@ namespace ShiftOS.WinForms })); }; - ParentWindow.OnLoad(); } /// @@ -208,6 +205,9 @@ namespace ShiftOS.WinForms public void WindowBorder_Load(object sender, EventArgs e) { this.DoubleBuffered = true; + this.Left = (Screen.PrimaryScreen.Bounds.Width - this.Width) / 2; + this.Top = (Screen.PrimaryScreen.Bounds.Height - this.Height) / 2; + ParentWindow.OnLoad(); this._parentWindow.Show(); } -- cgit v1.2.3 From 57277a01d685b0e29a79e5d74a1465a2ceb23ef9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 6 May 2017 09:44:47 -0400 Subject: Most of TriWrite is implemented. --- .../Applications/ShiftoriumFrontend.cs | 108 +++++++---- ShiftOS.WinForms/Applications/Skin Loader.cs | 9 +- ShiftOS.WinForms/Applications/TriWrite.Designer.cs | 197 ++++++++++++++++++--- ShiftOS.WinForms/Applications/TriWrite.cs | 120 ++++++++++++- ShiftOS.WinForms/Applications/TriWrite.resx | 108 ++++++++++- ShiftOS.WinForms/Controls/TerminalBox.cs | 130 ++++++++++++++ ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs | 4 +- ShiftOS_TheReturn/Commands.cs | 17 +- ShiftOS_TheReturn/ServerManager.cs | 4 +- 9 files changed, 617 insertions(+), 80 deletions(-) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs index 66b0448..06266c3 100644 --- a/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs +++ b/ShiftOS.WinForms/Applications/ShiftoriumFrontend.cs @@ -30,6 +30,7 @@ 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; @@ -90,46 +91,68 @@ namespace ShiftOS.WinForms.Applications public void PopulateShiftorium() { - try + var t = new Thread(() => { - lbnoupgrades.Hide(); - lbupgrades.Items.Clear(); - upgrades.Clear(); - Timer(); - - foreach (var upg in backend.GetAvailable().Where(x => x.Category == backend.GetCategories()[CategoryId])) + try { - String name = Localization.Parse(upg.Name) + " - " + upg.Cost.ToString() + "CP"; - upgrades.Add(name, upg); - lbupgrades.Items.Add(name); + Desktop.InvokeOnWorkerThread(() => + { + lbnoupgrades.Hide(); + lbupgrades.Items.Clear(); + upgrades.Clear(); + Timer(); + }); + + foreach (var upg in backend.GetAvailable().Where(x => x.Category == backend.GetCategories()[CategoryId])) + { + string name = Localization.Parse(upg.Name) + " - " + upg.Cost.ToString() + "CP"; + upgrades.Add(name, upg); + Desktop.InvokeOnWorkerThread(() => + { + lbupgrades.Items.Add(name); + }); + } + + if (lbupgrades.Items.Count == 0) + { + Desktop.InvokeOnWorkerThread(() => + { + lbnoupgrades.Show(); + lbnoupgrades.Location = new Point( + (lbupgrades.Width - lbnoupgrades.Width) / 2, + lbupgrades.Top + (lbupgrades.Height - lbnoupgrades.Height) / 2 + ); + }); + } + else + { + Desktop.InvokeOnWorkerThread(() => + { + lbnoupgrades.Hide(); + }); + } + + Desktop.InvokeOnWorkerThread(() => + { + lblcategorytext.Text = Shiftorium.GetCategories()[CategoryId]; + btncat_back.Visible = (CategoryId > 0); + btncat_forward.Visible = (CategoryId < backend.GetCategories().Length - 1); + }); } - - if (lbupgrades.Items.Count == 0) + catch { - lbnoupgrades.Show(); - lbnoupgrades.Location = new Point( - (lbupgrades.Width - lbnoupgrades.Width) / 2, - (lbupgrades.Height - lbnoupgrades.Height) / 2 - ); - + Desktop.InvokeOnWorkerThread(() => + { + lbnoupgrades.Show(); + lbnoupgrades.Location = new Point( + (lbupgrades.Width - lbnoupgrades.Width) / 2, + lbupgrades.Top + (lbupgrades.Height - lbnoupgrades.Height) / 2 + ); + }); } - else - { - lbnoupgrades.Hide(); - } - lblcategorytext.Text = Shiftorium.GetCategories()[CategoryId]; - btncat_back.Visible = (CategoryId > 0); - btncat_forward.Visible = (CategoryId < backend.GetCategories().Length - 1); - } - catch - { - lbnoupgrades.Show(); - lbnoupgrades.Location = new Point( - (lbupgrades.Width - lbnoupgrades.Width) / 2, - (lbupgrades.Height - lbnoupgrades.Height) / 2 - ); - - } + }); + t.IsBackground = true; + t.Start(); } public static bool UpgradeInstalled(string upg) @@ -200,7 +223,17 @@ namespace ShiftOS.WinForms.Applications { foreach(var upg in UpgradesToBuy) { - backend.Buy(upg.Key, upg.Value); + SaveSystem.CurrentSave.Codepoints -= upg.Value; + if (SaveSystem.CurrentSave.Upgrades.ContainsKey(upg.Key)) + { + SaveSystem.CurrentSave.Upgrades[upg.Key] = true; + } + else + { + SaveSystem.CurrentSave.Upgrades.Add(upg.Key, true); + } + SaveSystem.SaveGame(); + backend.InvokeUpgradeInstalled(); } } @@ -224,7 +257,7 @@ namespace ShiftOS.WinForms.Applications } - Timer cp_update = new System.Windows.Forms.Timer(); + System.Windows.Forms.Timer cp_update = new System.Windows.Forms.Timer(); public bool OnUnload() { @@ -248,6 +281,7 @@ namespace ShiftOS.WinForms.Applications { timer100 = new System.Timers.Timer(); timer100.Interval = 2000; + //CLARIFICATION: What is this supposed to do? - Michael //timer100.Elapsed += ???; timer100.AutoReset = true; timer100.Enabled = true; diff --git a/ShiftOS.WinForms/Applications/Skin Loader.cs b/ShiftOS.WinForms/Applications/Skin Loader.cs index f9857b7..90b05a1 100644 --- a/ShiftOS.WinForms/Applications/Skin Loader.cs +++ b/ShiftOS.WinForms/Applications/Skin Loader.cs @@ -65,8 +65,11 @@ namespace ShiftOS.WinForms.Applications public void SetupUI() { - SetupDesktop(); - Setup(); + if (LoadedSkin != null) + { + SetupDesktop(); + Setup(); + } } public void SetupDesktop() @@ -78,7 +81,7 @@ namespace ShiftOS.WinForms.Applications //upgrades - if (SaveSystem.CurrentSave != null) + if (SaveSystem.CurrentSave != null && LoadedSkin != null) { desktoppanel.Visible = ShiftoriumFrontend.UpgradeInstalled("desktop"); lbtime.Visible = ShiftoriumFrontend.UpgradeInstalled("desktop_clock_widget"); diff --git a/ShiftOS.WinForms/Applications/TriWrite.Designer.cs b/ShiftOS.WinForms/Applications/TriWrite.Designer.cs index e420fd5..a1432d8 100644 --- a/ShiftOS.WinForms/Applications/TriWrite.Designer.cs +++ b/ShiftOS.WinForms/Applications/TriWrite.Designer.cs @@ -36,15 +36,27 @@ this.panel1 = new System.Windows.Forms.Panel(); this.txtbody = new System.Windows.Forms.Label(); this.lbtitle = new System.Windows.Forms.Label(); - this.txtcontents = new System.Windows.Forms.TextBox(); this.menuStrip2 = new System.Windows.Forms.MenuStrip(); this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.menuStrip3 = new System.Windows.Forms.MenuStrip(); + this.txtcontents = new System.Windows.Forms.RichTextBox(); + this.toolStrip1 = new System.Windows.Forms.ToolStrip(); + this.bold = new System.Windows.Forms.ToolStripButton(); + this.italic = new System.Windows.Forms.ToolStripButton(); + this.underline = new System.Windows.Forms.ToolStripButton(); + this.strikethrough = new System.Windows.Forms.ToolStripButton(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.fonts = new System.Windows.Forms.ToolStripComboBox(); + this.size = new System.Windows.Forms.ToolStripTextBox(); + this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.left = new System.Windows.Forms.ToolStripButton(); + this.center = new System.Windows.Forms.ToolStripButton(); + this.right = new System.Windows.Forms.ToolStripButton(); this.menuStrip1.SuspendLayout(); this.panel1.SuspendLayout(); this.menuStrip2.SuspendLayout(); + this.toolStrip1.SuspendLayout(); this.SuspendLayout(); // // menuStrip1 @@ -61,16 +73,17 @@ // addContactToolStripMenuItem // this.addContactToolStripMenuItem.Name = "addContactToolStripMenuItem"; - this.addContactToolStripMenuItem.Size = new System.Drawing.Size(32, 19); + this.addContactToolStripMenuItem.Size = new System.Drawing.Size(12, 20); // // removeToolStripMenuItem // this.removeToolStripMenuItem.Name = "removeToolStripMenuItem"; - this.removeToolStripMenuItem.Size = new System.Drawing.Size(32, 19); + this.removeToolStripMenuItem.Size = new System.Drawing.Size(12, 20); // // tvcontacts // this.tvcontacts.Dock = System.Windows.Forms.DockStyle.Left; + this.tvcontacts.LineColor = System.Drawing.Color.Empty; this.tvcontacts.Location = new System.Drawing.Point(0, 24); this.tvcontacts.Name = "tvcontacts"; this.tvcontacts.Size = new System.Drawing.Size(224, 551); @@ -107,16 +120,6 @@ this.lbtitle.Tag = "header1"; this.lbtitle.Text = "TriWrite"; // - // txtcontents - // - this.txtcontents.Dock = System.Windows.Forms.DockStyle.Fill; - this.txtcontents.Location = new System.Drawing.Point(0, 53); - this.txtcontents.Multiline = true; - this.txtcontents.Name = "txtcontents"; - this.txtcontents.Size = new System.Drawing.Size(527, 460); - this.txtcontents.TabIndex = 1; - this.txtcontents.TabStop = false; - // // menuStrip2 // this.menuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -125,7 +128,7 @@ this.saveToolStripMenuItem}); this.menuStrip2.Location = new System.Drawing.Point(0, 0); this.menuStrip2.Name = "menuStrip2"; - this.menuStrip2.Size = new System.Drawing.Size(527, 24); + this.menuStrip2.Size = new System.Drawing.Size(652, 24); this.menuStrip2.TabIndex = 2; this.menuStrip2.Text = "menuStrip2"; // @@ -134,40 +137,173 @@ this.newToolStripMenuItem.Name = "newToolStripMenuItem"; this.newToolStripMenuItem.Size = new System.Drawing.Size(43, 20); this.newToolStripMenuItem.Text = "New"; + this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click); // // openToolStripMenuItem // this.openToolStripMenuItem.Name = "openToolStripMenuItem"; this.openToolStripMenuItem.Size = new System.Drawing.Size(48, 20); this.openToolStripMenuItem.Text = "Open"; + this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); // // saveToolStripMenuItem // this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; this.saveToolStripMenuItem.Size = new System.Drawing.Size(43, 20); this.saveToolStripMenuItem.Text = "Save"; + this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); + // + // txtcontents + // + this.txtcontents.Dock = System.Windows.Forms.DockStyle.Fill; + this.txtcontents.Location = new System.Drawing.Point(0, 49); + this.txtcontents.Name = "txtcontents"; + this.txtcontents.Size = new System.Drawing.Size(652, 365); + this.txtcontents.TabIndex = 4; + this.txtcontents.Text = ""; + this.txtcontents.SelectionChanged += new System.EventHandler(this.txtcontents_SelectionChanged); + // + // toolStrip1 + // + this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.bold, + this.italic, + this.underline, + this.strikethrough, + this.toolStripSeparator1, + this.fonts, + this.size, + this.toolStripSeparator2, + this.left, + this.center, + this.right}); + this.toolStrip1.Location = new System.Drawing.Point(0, 24); + this.toolStrip1.Name = "toolStrip1"; + this.toolStrip1.Size = new System.Drawing.Size(652, 25); + this.toolStrip1.TabIndex = 5; + this.toolStrip1.Text = "toolStrip1"; + // + // bold + // + this.bold.CheckOnClick = true; + this.bold.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.bold.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold); + this.bold.Image = ((System.Drawing.Image)(resources.GetObject("bold.Image"))); + this.bold.ImageTransparentColor = System.Drawing.Color.Magenta; + this.bold.Name = "bold"; + this.bold.Size = new System.Drawing.Size(23, 22); + this.bold.Text = "B"; + this.bold.CheckedChanged += new System.EventHandler(this.bold_CheckedChanged); + // + // italic + // + this.italic.CheckOnClick = true; + this.italic.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.italic.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Italic); + this.italic.Image = ((System.Drawing.Image)(resources.GetObject("italic.Image"))); + this.italic.ImageTransparentColor = System.Drawing.Color.Magenta; + this.italic.Name = "italic"; + this.italic.Size = new System.Drawing.Size(23, 22); + this.italic.Text = "I"; + this.italic.CheckedChanged += new System.EventHandler(this.bold_CheckedChanged); + // + // underline + // + this.underline.CheckOnClick = true; + this.underline.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.underline.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Underline); + this.underline.Image = ((System.Drawing.Image)(resources.GetObject("underline.Image"))); + this.underline.ImageTransparentColor = System.Drawing.Color.Magenta; + this.underline.Name = "underline"; + this.underline.Size = new System.Drawing.Size(23, 22); + this.underline.Text = "U"; + this.underline.CheckedChanged += new System.EventHandler(this.bold_CheckedChanged); + // + // strikethrough + // + this.strikethrough.CheckOnClick = true; + this.strikethrough.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.strikethrough.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Strikeout, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.strikethrough.Image = ((System.Drawing.Image)(resources.GetObject("strikethrough.Image"))); + this.strikethrough.ImageTransparentColor = System.Drawing.Color.Magenta; + this.strikethrough.Name = "strikethrough"; + this.strikethrough.Size = new System.Drawing.Size(23, 22); + this.strikethrough.Text = "S"; + this.strikethrough.CheckedChanged += new System.EventHandler(this.bold_CheckedChanged); + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25); + // + // fonts + // + this.fonts.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.fonts.Name = "fonts"; + this.fonts.Size = new System.Drawing.Size(121, 25); + this.fonts.SelectedIndexChanged += new System.EventHandler(this.fonts_SelectedIndexChanged); + // + // size + // + this.size.AutoSize = false; + this.size.MaxLength = 3; + this.size.Name = "size"; + this.size.Size = new System.Drawing.Size(40, 25); + this.size.TextChanged += new System.EventHandler(this.size_Click); + // + // toolStripSeparator2 + // + this.toolStripSeparator2.Name = "toolStripSeparator2"; + this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25); + // + // left + // + this.left.CheckOnClick = true; + this.left.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.left.Image = ((System.Drawing.Image)(resources.GetObject("left.Image"))); + this.left.ImageTransparentColor = System.Drawing.Color.Magenta; + this.left.Name = "left"; + this.left.Size = new System.Drawing.Size(31, 22); + this.left.Text = "Left"; + this.left.Click += new System.EventHandler(this.left_Click); + // + // center + // + this.center.CheckOnClick = true; + this.center.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.center.Image = ((System.Drawing.Image)(resources.GetObject("center.Image"))); + this.center.ImageTransparentColor = System.Drawing.Color.Magenta; + this.center.Name = "center"; + this.center.Size = new System.Drawing.Size(46, 22); + this.center.Text = "Center"; + this.center.Click += new System.EventHandler(this.center_Click); // - // menuStrip3 + // right // - this.menuStrip3.Location = new System.Drawing.Point(0, 30); - this.menuStrip3.Name = "menuStrip3"; - this.menuStrip3.Size = new System.Drawing.Size(527, 24); - this.menuStrip3.TabIndex = 3; - this.menuStrip3.Text = "menuStrip3"; + this.right.CheckOnClick = true; + this.right.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.right.Image = ((System.Drawing.Image)(resources.GetObject("right.Image"))); + this.right.ImageTransparentColor = System.Drawing.Color.Magenta; + this.right.Name = "right"; + this.right.Size = new System.Drawing.Size(39, 22); + this.right.Text = "Right"; + this.right.Click += new System.EventHandler(this.right_Click); // // TriWrite // this.Controls.Add(this.txtcontents); - this.Controls.Add(this.menuStrip3); + this.Controls.Add(this.toolStrip1); this.Controls.Add(this.menuStrip2); this.Name = "TriWrite"; - this.Size = new System.Drawing.Size(527, 513); + this.Size = new System.Drawing.Size(652, 414); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.menuStrip2.ResumeLayout(false); this.menuStrip2.PerformLayout(); + this.toolStrip1.ResumeLayout(false); + this.toolStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -182,11 +318,22 @@ private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label txtbody; private System.Windows.Forms.Label lbtitle; - private System.Windows.Forms.TextBox txtcontents; private System.Windows.Forms.MenuStrip menuStrip2; private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem; - private System.Windows.Forms.MenuStrip menuStrip3; + private System.Windows.Forms.RichTextBox txtcontents; + private System.Windows.Forms.ToolStrip toolStrip1; + private System.Windows.Forms.ToolStripButton bold; + private System.Windows.Forms.ToolStripButton italic; + private System.Windows.Forms.ToolStripButton underline; + private System.Windows.Forms.ToolStripButton strikethrough; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripComboBox fonts; + private System.Windows.Forms.ToolStripTextBox size; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolStripButton left; + private System.Windows.Forms.ToolStripButton center; + private System.Windows.Forms.ToolStripButton right; } } diff --git a/ShiftOS.WinForms/Applications/TriWrite.cs b/ShiftOS.WinForms/Applications/TriWrite.cs index 6fb814f..b5845ba 100644 --- a/ShiftOS.WinForms/Applications/TriWrite.cs +++ b/ShiftOS.WinForms/Applications/TriWrite.cs @@ -13,7 +13,7 @@ using ShiftOS.Engine; namespace ShiftOS.WinForms.Applications { [WinOpen("triwrite")] - [AppscapeEntry("TriWrite", "Part of the trilogy of office applications for enhancement of your system. TriWrite is easliy the best text editor out there for ShiftOS.", 1024, 750, null, "Office")] + [AppscapeEntry("TriWrite", "Part of the trilogy of office applications for enhancement of your system. TriWrite is easliy the best text editor out there for ShiftOS.", 1024, 750, "file_skimmer;textpad", "Office")] [DefaultTitle("TriWrite")] [Launcher("TriWrite", false, null, "Office")] public partial class TriWrite : UserControl, IShiftOSWindow @@ -32,35 +32,54 @@ namespace ShiftOS.WinForms.Applications private void openToolStripMenuItem_Click(object sender, EventArgs e) { var txt = new List(); - txt.Add(".txt"); + txt.Add(".rtf"); - AppearanceManager.SetupDialog(new FileDialog(txt.ToArray(), FileOpenerStyle.Open, new Action((file) => this.LoadFile(file)))); + FileSkimmerBackend.GetFile(txt.ToArray(), FileOpenerStyle.Open, (path) => LoadFile(path)); } public void LoadFile(string file) { - txtcontents.Text = Utils.ReadAllText(file); + txtcontents.Rtf = Utils.ReadAllText(file); } public void SaveFile(string file) { - Utils.WriteAllText(file, txtcontents.Text); + if (file.ToLower().EndsWith(".rtf")) + { + Utils.WriteAllText(file, txtcontents.Rtf); + } + else + { + Utils.WriteAllText(file, txtcontents.Text); + } } private void saveToolStripMenuItem_Click(object sender, EventArgs e) { var txt = new List(); + txt.Add(".rtf"); txt.Add(".txt"); - - AppearanceManager.SetupDialog(new FileDialog(txt.ToArray(), FileOpenerStyle.Save, new Action((file) => this.SaveFile(file)))); + FileSkimmerBackend.GetFile(txt.ToArray(), FileOpenerStyle.Save, (path) => SaveFile(path)); } public void OnLoad() { + UpdateUI(); } public void OnSkinLoad() { + ResetFonts(); + } + + public void ResetFonts() + { + fonts.Items.Clear(); + foreach(var font in FontFamily.Families) + { + fonts.Items.Add(font.Name); + } + UpdateUI(); } public bool OnUnload() @@ -72,5 +91,92 @@ namespace ShiftOS.WinForms.Applications { } + public void UpdateUI() + { + bold.Checked = txtcontents.SelectionFont.Bold; + italic.Checked = txtcontents.SelectionFont.Italic; + underline.Checked = txtcontents.SelectionFont.Underline; + strikethrough.Checked = txtcontents.SelectionFont.Strikeout; + fonts.Text = txtcontents.SelectionFont.Name; + size.Text = txtcontents.SelectionFont.Size.ToString(); + left.Checked = txtcontents.SelectionAlignment == HorizontalAlignment.Left; + center.Checked = txtcontents.SelectionAlignment == HorizontalAlignment.Center; + right.Checked = txtcontents.SelectionAlignment == HorizontalAlignment.Right; + + } + + private void txtcontents_SelectionChanged(object sender, EventArgs e) + { + UpdateUI(); + } + + public void SetFontStyle(bool bold, bool italic, bool underline, bool strikethrough) + { + FontStyle fs = FontStyle.Regular; + if (bold) + fs |= FontStyle.Bold; + if (italic) + fs |= FontStyle.Italic; + if (underline) + fs |= FontStyle.Underline; + if (strikethrough) + fs |= FontStyle.Strikeout; + txtcontents.SelectionFont = new Font(txtcontents.SelectionFont, fs); + UpdateUI(); + } + + private void bold_CheckedChanged(object sender, EventArgs e) + { + SetFontStyle(bold.Checked, italic.Checked, underline.Checked, strikethrough.Checked); + } + + public void SetFontFamily(string family, float emSize) + { + var style = txtcontents.SelectionFont.Style; + var size = emSize; + txtcontents.SelectionFont = new Font(family, size, style); + UpdateUI(); + } + + private void fonts_SelectedIndexChanged(object sender, EventArgs e) + { + SetFontFamily(fonts.Text, Convert.ToSingle(size.Text)); + } + + private void left_Click(object sender, EventArgs e) + { + txtcontents.SelectionAlignment = HorizontalAlignment.Left; + UpdateUI(); + } + + private void center_Click(object sender, EventArgs e) + { + txtcontents.SelectionAlignment = HorizontalAlignment.Center; + UpdateUI(); + + } + + private void right_Click(object sender, EventArgs e) + { + txtcontents.SelectionAlignment = HorizontalAlignment.Right; + UpdateUI(); + + } + + private void size_Click(object sender, EventArgs e) + { + try + { + float s = Convert.ToSingle(size.Text); + if(s != txtcontents.SelectionFont.Size) + { + SetFontFamily(fonts.Text, s); + } + } + catch + { + UpdateUI(); + } + } } } \ No newline at end of file diff --git a/ShiftOS.WinForms/Applications/TriWrite.resx b/ShiftOS.WinForms/Applications/TriWrite.resx index 525a23c..a06716c 100644 --- a/ShiftOS.WinForms/Applications/TriWrite.resx +++ b/ShiftOS.WinForms/Applications/TriWrite.resx @@ -130,7 +130,113 @@ To add a contact, simply click "Add Contact", and to remove one, click "Remove". 132, 17 - + 247, 17 + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + \ No newline at end of file diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index cdb0965..f85daa6 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -86,6 +86,7 @@ namespace ShiftOS.WinForms.Controls public void WriteLine(string text) { + Engine.AudioManager.PlayStream(Properties.Resources.writesound); this.HideSelection = true; this.Select(this.TextLength, 0); this.SelectionFont = ConstructFont(); @@ -119,6 +120,135 @@ namespace ShiftOS.WinForms.Controls base.OnMouseUp(mevent); } + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + if (!TerminalBackend.InStory) + { + switch (e.KeyCode) { + case Keys.Add: + case Keys.Alt: + case Keys.Apps: + case Keys.Attn: + case Keys.BrowserBack: + case Keys.BrowserFavorites: + case Keys.BrowserForward: + case Keys.BrowserHome: + case Keys.BrowserRefresh: + case Keys.BrowserSearch: + case Keys.BrowserStop: + case Keys.Cancel: + case Keys.Capital: + case Keys.Clear: + case Keys.Control: + case Keys.ControlKey: + case Keys.Crsel: + case Keys.Decimal: + case Keys.Divide: + case Keys.Down: + case Keys.End: + case Keys.Enter: + case Keys.EraseEof: + case Keys.Escape: + case Keys.Execute: + case Keys.Exsel: + case Keys.F1: + case Keys.F10: + case Keys.F11: + case Keys.F12: + case Keys.F13: + case Keys.F14: + case Keys.F15: + case Keys.F16: + case Keys.F17: + case Keys.F18: + case Keys.F19: + case Keys.F2: + case Keys.F20: + case Keys.F21: + case Keys.F22: + case Keys.F23: + case Keys.F24: + case Keys.F3: + case Keys.F4: + case Keys.F5: + case Keys.F6: + case Keys.F7: + case Keys.F8: + case Keys.F9: + case Keys.FinalMode: + case Keys.HanguelMode: + case Keys.HanjaMode: + case Keys.Help: + case Keys.Home: + case Keys.IMEAccept: + case Keys.IMEConvert: + case Keys.IMEModeChange: + case Keys.IMENonconvert: + case Keys.Insert: + case Keys.JunjaMode: + case Keys.KeyCode: + case Keys.LaunchApplication1: + case Keys.LaunchApplication2: + case Keys.LaunchMail: + case Keys.LButton: + case Keys.LControlKey: + case Keys.Left: + case Keys.LineFeed: + case Keys.LMenu: + case Keys.LShiftKey: + case Keys.LWin: + case Keys.MButton: + case Keys.MediaNextTrack: + case Keys.MediaPlayPause: + case Keys.MediaPreviousTrack: + case Keys.MediaStop: + case Keys.Menu: + case Keys.Modifiers: + case Keys.Multiply: + case Keys.Next: + case Keys.NoName: + case Keys.None: + case Keys.NumLock: + case Keys.Pa1: + case Keys.Packet: + case Keys.PageUp: + case Keys.Pause: + case Keys.Play: + case Keys.Print: + case Keys.PrintScreen: + case Keys.ProcessKey: + case Keys.RButton: + case Keys.RControlKey: + case Keys.Right: + case Keys.RMenu: + case Keys.RShiftKey: + case Keys.RWin: + case Keys.Scroll: + case Keys.Select: + case Keys.SelectMedia: + case Keys.Separator: + case Keys.Shift: + case Keys.ShiftKey: + case Keys.Sleep: + case Keys.Subtract: + case Keys.Tab: + case Keys.Up: + case Keys.VolumeDown: + case Keys.VolumeMute: + case Keys.VolumeUp: + case Keys.XButton1: + case Keys.XButton2: + case Keys.Zoom: + + break; + default: + Engine.AudioManager.PlayStream(Properties.Resources.typesound); + break; + } + } + } + public TerminalBox() : base() { this.Tag = "keepbg keepfg keepfont"; diff --git a/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs index d38cdc3..b0dc552 100644 --- a/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs +++ b/ShiftOS.WinForms/DesktopWidgets/HeartbeatWidget.cs @@ -24,13 +24,13 @@ namespace ShiftOS.WinForms.DesktopWidgets if(ts != ServerManager.DigitalSocietyPing) { ts = ServerManager.DigitalSocietyPing; - lbheartbeat.Text = "Server ping: " + ts.ToString(); + lbheartbeat.Text = "Server ping: " + ts.ToString() + " MS"; } }; } //Fun fact. I misspelled this as "TimeSpam." - TimeSpan ts; + long ts = 0; public void OnSkinLoad() { diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index 57d1d34..dc0b3a2 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -276,6 +276,17 @@ namespace ShiftOS.Engine return true; } + [Command("restart")] + public static bool Restart() + { + SaveSystem.CurrentSave.Upgrades = new Dictionary(); + SaveSystem.CurrentSave.Codepoints = 0; + SaveSystem.CurrentSave.StoriesExperienced.Clear(); + SaveSystem.CurrentSave.StoriesExperienced.Add("mud_fundamentals"); + SaveSystem.SaveGame(); + Shiftorium.InvokeUpgradeInstalled(); + return true; + } [Command("freecp")] public static bool FreeCodepoints(Dictionary args) @@ -283,8 +294,8 @@ namespace ShiftOS.Engine if (args.ContainsKey("amount")) try { - Int64 codepointsToAdd = Convert.ToInt64(args["amount"].ToString()); - SaveSystem.TransferCodepointsFrom("dev", codepointsToAdd); + long codepointsToAdd = Convert.ToInt64(args["amount"].ToString()); + SaveSystem.CurrentSave.Codepoints += codepointsToAdd; return true; } catch (Exception ex) @@ -293,7 +304,7 @@ namespace ShiftOS.Engine return true; } - SaveSystem.TransferCodepointsFrom("dev", 1000); + SaveSystem.CurrentSave.Codepoints += 1000; return true; } diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 792b38d..825064b 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -55,7 +55,7 @@ namespace ShiftOS.Engine private static NetObjectClient client { get; set; } private static bool UserDisconnect = false; - public static TimeSpan DigitalSocietyPing + public static long DigitalSocietyPing { get; private set; @@ -148,7 +148,7 @@ namespace ShiftOS.Engine { if (PingTimer.IsRunning) { - DigitalSocietyPing = PingTimer.Elapsed; + DigitalSocietyPing = PingTimer.ElapsedMilliseconds; PingTimer.Reset(); } var msg = a.Data.Object as ServerMessage; -- cgit v1.2.3 From 7d24f19716f6c09bbe82c470b83924950ab92daf Mon Sep 17 00:00:00 2001 From: william341 Date: Sat, 6 May 2017 14:56:45 -0700 Subject: oh god --- ShiftOS.WinForms/Controls/TerminalBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index f85daa6..ea7808c 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -243,7 +243,7 @@ namespace ShiftOS.WinForms.Controls break; default: - Engine.AudioManager.PlayStream(Properties.Resources.typesound); + //Engine.AudioManager.PlayStream(Properties.Resources.typesound); // infernal beeping noise only enable for the trailers break; } } -- 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/Controls/TerminalBox.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 8e345174ee0796084c542681208c57fa8f962f61 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 24 May 2017 16:41:49 -0400 Subject: Dramatically increase terminal performance. --- ShiftOS.WinForms/Controls/TerminalBox.cs | 2 + ShiftOS_TheReturn/Commands.cs | 133 ++------- ShiftOS_TheReturn/KernelWatchdog.cs | 34 +-- ShiftOS_TheReturn/SaveSystem.cs | 3 +- ShiftOS_TheReturn/Shiftorium.cs | 2 + ShiftOS_TheReturn/TerminalBackend.cs | 496 ++++++++++++++++--------------- 6 files changed, 302 insertions(+), 368 deletions(-) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index e95d038..a6dd610 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -63,6 +63,7 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { + Thread.Sleep(5); this.SuspendLayout(); this.HideSelection = true; this.SelectionFont = ConstructFont(); @@ -88,6 +89,7 @@ namespace ShiftOS.WinForms.Controls public void WriteLine(string text) { + Thread.Sleep(5); this.SuspendLayout(); Engine.AudioManager.PlayStream(Properties.Resources.writesound); this.HideSelection = true; diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index c2005f2..96e5af5 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -330,8 +330,13 @@ namespace ShiftOS.Engine { foreach (var upg in Shiftorium.GetDefaults()) { - Shiftorium.Buy(upg.ID, 0); + if (!SaveSystem.CurrentSave.Upgrades.ContainsKey(upg.ID)) + SaveSystem.CurrentSave.Upgrades.Add(upg.ID, true); + else + SaveSystem.CurrentSave.Upgrades[upg.ID] = true; } + Shiftorium.InvokeUpgradeInstalled(); + SkinEngine.LoadSkin(); return true; } @@ -453,122 +458,40 @@ namespace ShiftOS.Engine [Command("help", "{COMMAND_HELP_USAGE", "{COMMAND_HELP_DESCRIPTION}")] public static bool Help(Dictionary args) { - Console.WriteLine("Retrieving help data..."); + var sb = new StringBuilder(); + sb.AppendLine("Retrieving help data."); + if (args.ContainsKey("ns")) { - if (args["ns"] is string) + string ns = args["ns"].ToString(); + //First let's check for a command that has this namespace. + var cmdtest = TerminalBackend.Commands.FirstOrDefault(x => x.NamespaceInfo.name == ns); + if (cmdtest == null) //Namespace not found. + sb.AppendLine("Error retrieving help for namespace \"" + ns + "\". Namespace not found."); + else { - string ns = args["ns"].ToString(); - bool foundNS = false; - foreach (var exec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) + //Now do the actual scan. + sb.AppendLine("Namespace: " + ns); + foreach(var cmd in TerminalBackend.Commands.Where(x => x.NamespaceInfo.name == ns)) { - if (exec.EndsWith(".exe") || exec.EndsWith(".dll")) - { - try - { - var asm = Assembly.LoadFile(exec); - - var types = asm.GetTypes(); - - foreach (var type in types) - { - if (Shiftorium.UpgradeAttributesUnlocked(type)) - { - var nsa = (Namespace)type.GetCustomAttributes(false).FirstOrDefault(x => x is Namespace && (x as Namespace).name == ns); - - if (nsa != null) - { - - if (!nsa.hide) - { - foundNS = true; - string descp = "{NAMESPACE_" + nsa.name.ToUpper() + "_DESCRIPTION}"; - if (descp == Localization.Parse(descp)) - descp = ""; - else - descp = Shiftorium.UpgradeInstalled("help_description") ? Localization.Parse("{SEPERATOR}" + descp) : ""; - - Console.WriteLine($"{{NAMESPACE}}{nsa.name}" + descp); - - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) - { - if (Shiftorium.UpgradeAttributesUnlocked(method)) - { - foreach (var ma in method.GetCustomAttributes(false)) - { - if (ma is Command) - { - var cmd = ma as Command; - - if (!cmd.hide) - { - string descriptionparse = "{COMMAND_" + nsa.name.ToUpper() + "_" + cmd.name.ToUpper() + "_DESCRIPTION}"; - string usageparse = "{COMMAND_" + nsa.name.ToUpper() + "_" + cmd.name.ToUpper() + "_USAGE}"; - if (descriptionparse == Localization.Parse(descriptionparse)) - descriptionparse = ""; - else - descriptionparse = Shiftorium.UpgradeInstalled("help_description") ? Localization.Parse("{SEPERATOR}" + descriptionparse) : ""; - - if (usageparse == Localization.Parse(usageparse)) - usageparse = ""; - else - usageparse = Shiftorium.UpgradeInstalled("help_usage") ? Localization.Parse("{SEPERATOR}" + usageparse, new Dictionary() { - {"%ns", nsa.name}, - {"%cmd", cmd.name} - }) : ""; - - Console.WriteLine($"{{COMMAND}}{nsa.name}.{cmd.name}" + usageparse + descriptionparse); - } - } - } - } - - } - } - } - } - } - - } - - - - - catch { } - } + string str = cmd.ToString(); + str = str.Replace(str.Substring(str.LastIndexOf("|")), ""); + sb.AppendLine(str); } - if (foundNS == false) - { - Console.WriteLine("Error: Namespace not found! Couldn't retrieve help info."); - } - } - return true; } - - foreach(var exec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) + else { - if(exec.ToLower().EndsWith(".exe") || exec.ToLower().EndsWith(".dll")) + + //print all unique namespaces. + foreach(var n in TerminalBackend.Commands.Select(x => x.NamespaceInfo.name).Distinct()) { - try - { - var asm = Assembly.LoadFile(exec); - foreach(var type in asm.GetTypes()) - { - Namespace ns = type.GetCustomAttributes(false).FirstOrDefault(x => x is Namespace) as Namespace; - if(ns != null) - { - if(!ns.hide) - { - Console.WriteLine("sos.help{ns:\"" + ns.name + "\"}"); - } - } - } - } - catch { } + sb.AppendLine("sos.help{ns:\"" + n + "\"}"); } } + Console.WriteLine(sb.ToString()); + return true; } diff --git a/ShiftOS_TheReturn/KernelWatchdog.cs b/ShiftOS_TheReturn/KernelWatchdog.cs index 66ec1f7..0608c46 100644 --- a/ShiftOS_TheReturn/KernelWatchdog.cs +++ b/ShiftOS_TheReturn/KernelWatchdog.cs @@ -66,41 +66,19 @@ namespace ShiftOS.Engine } } - //determines if user is root - public static bool IsSafe(Type type) + public static bool IsSafe(TerminalBackend.TerminalCommand cmd) { - if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Root) + if (!cmd.RequiresElevation) return true; - - foreach (var attrib in type.GetCustomAttributes(false)) + else { - if (attrib is KernelModeAttribute) - { - if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Root) - return true; + if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Root) + return true; + else return false; - } } - return true; } - //also determines if user is root, only for a method instead - public static bool IsSafe(MethodInfo type) - { - if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Root) - return true; - - foreach (var attrib in type.GetCustomAttributes(false)) - { - if (attrib is KernelModeAttribute) - { - if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Root) - return true; - return false; - } - } - return true; - } static string regularUsername = ""; //put regular username in here later diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs index 9c812c7..d74006a 100644 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ b/ShiftOS_TheReturn/SaveSystem.cs @@ -137,7 +137,8 @@ namespace ShiftOS.Engine Thread.Sleep(100); Console.WriteLine("[sfs] 4096 blocks read."); Console.WriteLine("[simpl-conf] Reading configuration files (global-3.conf)"); - + Console.WriteLine("[termdb] Building command database from filesystem..."); + TerminalBackend.PopulateTerminalCommands(); Console.WriteLine("[inetd] Connecting to network..."); Ready = false; diff --git a/ShiftOS_TheReturn/Shiftorium.cs b/ShiftOS_TheReturn/Shiftorium.cs index fe436d4..0ac784e 100644 --- a/ShiftOS_TheReturn/Shiftorium.cs +++ b/ShiftOS_TheReturn/Shiftorium.cs @@ -312,6 +312,8 @@ namespace ShiftOS.Engine /// Whether the upgrade is installed. public static bool UpgradeInstalled(string id) { + if (string.IsNullOrWhiteSpace(id)) + return true; if (SaveSystem.CurrentSave != null) { if (!IsInitiated) diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 79c6349..6a15d3e 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -24,6 +24,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Reflection; using System.Text; @@ -136,6 +137,218 @@ namespace ShiftOS.Engine return JsonConvert.SerializeObject(args); } + public class TerminalCommand + { + public override int GetHashCode() + { + int hash = 0; + foreach (char c in ToString()) + { + hash += (int)c; + } + return hash; + } + + public Namespace NamespaceInfo { get; set; } + public Command CommandInfo { get; set; } + + public List RequiredArguments { get; set; } + public string Dependencies { get; set; } + + public MethodInfo CommandHandler; + + public Type CommandType; + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append(this.NamespaceInfo.name); + sb.Append("."); + sb.Append(this.CommandInfo.name); + if (this.RequiredArguments.Count > 0) + { + sb.Append("{"); + foreach (var arg in RequiredArguments) + { + sb.Append(arg); + sb.Append(":"); + if (RequiredArguments.IndexOf(arg) < RequiredArguments.Count - 1) + sb.Append(','); + } + sb.Append("}"); + } + sb.Append("|"); + sb.Append(CommandHandler.Name + "()"); + return sb.ToString(); + } + + public bool RequiresElevation { get; set; } + + public void Invoke(Dictionary args) + { + List errors = new List(); + bool requiresAuth = false; + if (!KernelWatchdog.IsSafe(this)) + { + if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Admin) + requiresAuth = true; + else + errors.Add("You can't run this command - you do not have permission."); + } + if (errors.Count > 0) + { + foreach (var error in errors) + { + Console.WriteLine("Command error: " + error); + } + return; + } + if (requiresAuth) + { + Infobox.PromptText("Enter your password.", "This command requires you to have elevated permissions. Please enter your password to confirm this action.", (pass) => + { + if (pass == SaveSystem.CurrentUser.Password) + { + var uname = SaveSystem.CurrentUser.Username; + SaveSystem.CurrentUser = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == "root"); + try + { + var h = CommandHandler; + h.Invoke(null, new[] { args }); + } + catch + { + var h = CommandHandler; + h.Invoke(null, null); + } + SaveSystem.CurrentUser = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == uname); + } + else + { + Infobox.Show("Access denied.", "Incorrect password provided. The command will not run."); + } + }, true); + } + + try + { + CommandHandler.Invoke(null, new[] { args }); + } + catch + { + CommandHandler.Invoke(null, null); + } + } + } + + public class MemoryTextWriter : System.IO.TextWriter + { + public override Encoding Encoding + { + get + { + return Encoding.Unicode; + } + } + + private StringBuilder sb = null; + + public MemoryTextWriter() + { + sb = new StringBuilder(); + } + + public override string ToString() + { + return sb.ToString(); + } + + public override void Write(char value) + { + sb.Append(value); + } + + public override void WriteLine() + { + sb.AppendLine(); + } + + public override void Write(string value) + { + sb.Append(value); + } + + public override void Close() + { + sb.Clear(); + sb = null; + base.Close(); + } + + public override void WriteLine(string value) + { + sb.AppendLine(value); + } + } + + public static List Commands { get; private set; } + + public static void PopulateTerminalCommands() + { + Commands = new List(); + foreach(var exec in System.IO.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()) + { + var ns = type.GetCustomAttributes(false).FirstOrDefault(x => x is Namespace) as Namespace; + if(ns != null) + { + foreach(var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) + { + var cmd = mth.GetCustomAttributes(false).FirstOrDefault(x => x is Command); + if(cmd != null) + { + var tc = new TerminalCommand(); + tc.RequiresElevation = !(type.GetCustomAttributes(false).FirstOrDefault(x => x is KernelModeAttribute) == null); + + tc.NamespaceInfo = ns; + + tc.CommandInfo = cmd as Command; + tc.RequiresElevation = tc.RequiresElevation || !(mth.GetCustomAttributes(false).FirstOrDefault(x => x is KernelModeAttribute) == null); + tc.RequiredArguments = new List(); + foreach (var arg in mth.GetCustomAttributes(false).Where(x=>x is RequiresArgument)) + { + var rarg = arg as RequiresArgument; + tc.RequiredArguments.Add(rarg.argument); + } + var rupg = mth.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresUpgradeAttribute) as RequiresUpgradeAttribute; + if (rupg != null) + tc.Dependencies = rupg.Upgrade; + else + tc.Dependencies = ""; + tc.CommandType = type; + tc.CommandHandler = mth; + if (!Commands.Contains(tc)) + Commands.Add(tc); + } + } + } + } + } + catch(Exception e) + { + Console.WriteLine("[termdb] Error: " + e.ToString()); + } + } + } + Console.WriteLine("[termdb] " + Commands.Count + " commands found."); + } + /// /// Invokes a ShiftOS terminal command. /// @@ -150,19 +363,27 @@ namespace ShiftOS.Engine var args = GetArgs(ref text); + Stopwatch debugger = new Stopwatch(); + debugger.Start(); bool commandWasClient = RunClient(text, args, isRemote); if (!commandWasClient) { - PrefixEnabled = false; - - ServerManager.SendMessage("script", $@"{{ - user: ""{text.Split('.')[0]}"", - script: ""{text.Split('.')[1]}"", - args: ""{GetSentArgs(args)}"" -}}"); + Console.WriteLine("Command not found."); + debugger.Stop(); + return; } CommandProcessed?.Invoke(text, GetSentArgs(args)); + debugger.Stop(); + ConsoleEx.ForegroundColor = ConsoleColor.White; + Console.Write("<"); + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.Blue; + Console.Write("debugger"); + ConsoleEx.ForegroundColor = ConsoleColor.White; + ConsoleEx.Bold = false; + Console.Write("> "); + Console.WriteLine("Command " + text + " took " + debugger.Elapsed.ToString() + " to execute."); } catch (Exception ex) { @@ -263,237 +484,44 @@ namespace ShiftOS.Engine //Console.WriteLine(text + " " + "{" + string.Join(",", args.Select(kv => kv.Key + "=" + kv.Value).ToArray()) + "}" + " " + isRemote); - foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) + var tw = new MemoryTextWriter(); + Console.SetOut(tw); + + string[] split = text.Split('.'); + var cmd = Commands.FirstOrDefault(x => x.NamespaceInfo.name == split[0] && x.CommandInfo.name == split[1]); + if (cmd == null) + return false; + if (!Shiftorium.UpgradeInstalled(cmd.Dependencies)) + return false; + if(cmd.RequiredArguments.Count != args.Count) { - try + Console.WriteLine("Command error: Argument count mismatch! You supplied " + args.Count + " arguments to a command that expects " + cmd.RequiredArguments.Count + "."); + return true; + } + bool res = false; + foreach (var arg in cmd.RequiredArguments) + { + if (!args.ContainsKey(arg)) { - var asm = Assembly.LoadFile(asmExec); - - var types = asm.GetTypes(); - foreach (var type in types) - { - if (Shiftorium.UpgradeAttributesUnlocked(type)) - { - foreach (var a in type.GetCustomAttributes(false)) - { - if (a is Namespace) - { - var ns = a as Namespace; - if (text.Split('.')[0] == ns.name) - { - if (KernelWatchdog.IsSafe(type)) - { - if (KernelWatchdog.CanRunOffline(type)) - { - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) - { - if (Shiftorium.UpgradeAttributesUnlocked(method)) - { - foreach (var ma in method.GetCustomAttributes(false)) - { - if (ma is Command) - { - var cmd = ma as Command; - if (text.Split('.')[1] == cmd.name) - { - if (KernelWatchdog.IsSafe(method)) - { - if (KernelWatchdog.CanRunOffline(method)) - { - var attr = method.GetCustomAttribute(); - - if (attr != null) - { - string newcommand = attr.newcommand; - if (attr.warn) - { - Console.WriteLine(Localization.Parse((newcommand == "" ? "{ERROR}" : "{WARN}") + attr.reason, new Dictionary() { - {"%newcommand", newcommand} - })); - } - if (newcommand != "") - { - // redo the entire process running newcommand - - return RunClient(newcommand, args); - } - } - - var requiresArgs = method.GetCustomAttributes(); - bool error = false; - bool providedusage = false; - - foreach (RequiresArgument argument in requiresArgs) - { - if (!args.ContainsKey(argument.argument)) - { - - if (!providedusage) - { - string usageparse = "{COMMAND_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_USAGE}"; - if (usageparse == Localization.Parse(usageparse)) - usageparse = ""; - else - usageparse = Shiftorium.UpgradeInstalled("help_usage") ? Localization.Parse("{ERROR}{USAGE}" + usageparse, new Dictionary() { - {"%ns", ns.name}, - {"%cmd", cmd.name} - }) : ""; - - Console.WriteLine(usageparse); - - providedusage = true; - } - if (Shiftorium.UpgradeInstalled("help_usage")) - { - Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED}", new Dictionary() { - {"%argument", argument.argument} - })); - } - else - { - Console.WriteLine(Localization.Parse("{ERROR_ARGUMENT_REQUIRED_NO_USAGE}")); - } - - error = true; - } - } - - if (error) - { - throw new Exception("{ERROR_COMMAND_WRONG}"); - } - - try - { - return (bool)method.Invoke(null, new[] { args }); - } - 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 - { - return (bool)method.Invoke(null, new object[] { }); - } - } - else - { - Console.Write("<"); - ConsoleEx.Bold = true; - ConsoleEx.ForegroundColor = ConsoleColor.DarkRed; - Console.Write("session_mgr"); - ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; - ConsoleEx.Bold = false; - Console.Write(">"); - ConsoleEx.Italic = true; - ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine(" You cannot run this command while disconnected from the multi-user domain.."); - return true; - - } - } - else - { - if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Admin) - { - Infobox.PromptText("Elevate to root mode", "This command cannot be run as a regular user. To run this command, please enter your password to elevate to root mode temporarily.", (pass) => - { - if (pass == SaveSystem.CurrentUser.Password) - { - KernelWatchdog.EnterKernelMode(); - RunClient(text, args, isRemote); - KernelWatchdog.LeaveKernelMode(); - } - else - { - Infobox.Show("Access denied.", "You did not type in the correct password."); - } - }, true); - return true; - } - Console.Write("<"); - ConsoleEx.Bold = true; - ConsoleEx.ForegroundColor = ConsoleColor.DarkRed; - Console.Write("watchdog"); - ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; - ConsoleEx.Bold = false; - Console.Write(">"); - ConsoleEx.Italic = true; - ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine(" You cannot run this command. You do not have permission. Incident reported."); - KernelWatchdog.Log("potential_sys_breach", "user attempted to run kernel mode command " + text + " - watchdog has prevented this, good sir."); - return true; - } - } - } - - - } - } - - else - { - Console.Write("<"); - ConsoleEx.Bold = true; - ConsoleEx.ForegroundColor = ConsoleColor.DarkRed; - Console.Write("session_mgr"); - ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; - ConsoleEx.Bold = false; - Console.Write(">"); - ConsoleEx.Italic = true; - ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine(" You cannot run this command while disconnected from the multi-user domain.."); - return true; - - } - - } - } - else - { - if (SaveSystem.CurrentUser.Permissions == Objects.UserPermissions.Admin) - { - Infobox.PromptText("Elevate to root mode", "This command cannot be run as a regular user. To run this command, please enter your password to elevate to root mode temporarily.", (pass) => - { - if (pass == SaveSystem.CurrentUser.Password) - { - KernelWatchdog.EnterKernelMode(); - RunClient(text, args, isRemote); - KernelWatchdog.LeaveKernelMode(); - } - else - { - Infobox.Show("Access denied.", "You did not type in the correct password."); - } - }, true); - return true; - } - Console.Write("<"); - ConsoleEx.Bold = true; - ConsoleEx.ForegroundColor = ConsoleColor.DarkRed; - Console.Write("watchdog"); - ConsoleEx.ForegroundColor = SkinEngine.LoadedSkin.TerminalForeColorCC; - ConsoleEx.Bold = false; - Console.Write(">"); - ConsoleEx.Italic = true; - ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine(" You cannot run this command. You do not have permission. Incident reported."); - KernelWatchdog.Log("potential_sys_breach", "user attempted to run kernel mode command " + text + " - watchdog has prevented this, good sir."); - return true; - } - } - } - } - } - } - } + res = true; + Console.WriteLine("You are missing an argument with the key \"" + arg + "\"."); } - catch { } } - return false; + if (res == true) + return true; + try + { + cmd.Invoke(args); + } + catch(Exception ex) + { + Console.WriteLine("Command error: " + ex.Message); + } + + string buffer = tw.ToString(); + Console.SetOut(new TerminalTextWriter()); + Console.Write(buffer); + return true; } /// -- cgit v1.2.3 From e841b168e13e0bd699c0e0d19857167aa725f1ca Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 27 May 2017 16:59:54 -0400 Subject: stuff --- ShiftOS.WinForms/Applications/Chat.cs | 1 + ShiftOS.WinForms/Controls/TerminalBox.cs | 11 ++++--- ShiftOS.WinForms/Stories/LegionStory.cs | 9 +----- ShiftOS.WinForms/WinformsDesktop.cs | 49 ++++++++++++++++++-------------- ShiftOS_TheReturn/AppearanceManager.cs | 2 +- 5 files changed, 35 insertions(+), 37 deletions(-) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Applications/Chat.cs b/ShiftOS.WinForms/Applications/Chat.cs index e150b1a..f9e601f 100644 --- a/ShiftOS.WinForms/Applications/Chat.cs +++ b/ShiftOS.WinForms/Applications/Chat.cs @@ -186,6 +186,7 @@ namespace ShiftOS.WinForms.Applications SendMessage(ch, ch, "A little birdie tells me you know about the RTS exploits going around... Try using that on Aiden's server. You can find his systemname on Appscape under \"Contact Us.\" He has a mailserver on Appscape - and also has RTS on the same server."); Thread.Sleep(2500); SendMessage(ch, ch, "Good luck... My life depends on you!"); + complete = true; }); t.IsBackground = true; t.Start(); diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index a6dd610..7658c8c 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -63,15 +63,12 @@ namespace ShiftOS.WinForms.Controls public void Write(string text) { - Thread.Sleep(5); - 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() @@ -89,8 +86,6 @@ namespace ShiftOS.WinForms.Controls public void WriteLine(string text) { - Thread.Sleep(5); - this.SuspendLayout(); Engine.AudioManager.PlayStream(Properties.Resources.writesound); this.HideSelection = true; this.Select(this.TextLength, 0); @@ -99,11 +94,12 @@ 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; + bool busy = false; + protected override void OnMouseDown(MouseEventArgs e) { //if right-clicking, then we initiate a quick-copy. @@ -255,8 +251,11 @@ namespace ShiftOS.WinForms.Controls } } + public string ThreadId = ""; + public TerminalBox() : base() { + ThreadId = Thread.CurrentThread.ManagedThreadId.ToString(); this.Tag = "keepbg keepfg keepfont"; } } diff --git a/ShiftOS.WinForms/Stories/LegionStory.cs b/ShiftOS.WinForms/Stories/LegionStory.cs index 9b4966f..53d55fb 100644 --- a/ShiftOS.WinForms/Stories/LegionStory.cs +++ b/ShiftOS.WinForms/Stories/LegionStory.cs @@ -92,14 +92,7 @@ namespace ShiftOS.WinForms.Stories ConsoleEx.ForegroundColor = ConsoleColor.Gray; ConsoleEx.Bold = false; - foreach (var c in text) - { - Desktop.InvokeOnWorkerThread(() => - { - Console.Write(c); - }); - Thread.Sleep(75); - } + Console.WriteLine(text); Thread.Sleep(1000); } diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index 15ecb7a..6ce8cc9 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -188,14 +188,40 @@ namespace ShiftOS.WinForms widget.OnSkinLoad(); } + SetupDesktop(); }; + + long lastcp = 0; + + var storythread = new Thread(() => + { + do + { + if (SaveSystem.CurrentSave != null) + { + if (SaveSystem.CurrentSave.Codepoints != lastcp) + lastcp = SaveSystem.CurrentSave.Codepoints; + if (lastcp >= 10000) + { + if (!Shiftorium.UpgradeInstalled("victortran_shiftnet")) + { + Story.Start("victortran_shiftnet"); + } + } + } + } while (!SaveSystem.ShuttingDown); + }); + storythread.IsBackground = true; + storythread.Start(); + time.Tick += (o, a) => { if (Shiftorium.IsInitiated == true) { - if (SaveSystem.CurrentSave != null && TutorialManager.IsInTutorial == false) + if (SaveSystem.CurrentSave != null) { + lbtime.Text = Applications.Terminal.GetTime(); lbtime.Left = pnlnotifications.Width - lbtime.Width - LoadedSkin.DesktopPanelClockFromRight.X; lbtime.Top = LoadedSkin.DesktopPanelClockFromRight.Y; @@ -230,27 +256,6 @@ namespace ShiftOS.WinForms }; time.Start(); - var ssThread = new Thread(() => - { - while(this.Visible == true) - { - var mousePos = Cursor.Position; - while(Cursor.Position == mousePos) - { - if(millisecondsUntilScreensaver <= 0) - { - ShowScreensaver(); - } - millisecondsUntilScreensaver--; - Thread.Sleep(1); - } - millisecondsUntilScreensaver = 300000; - HideScreensaver(); - } - }); - ssThread.IsBackground = true; - ssThread.Start(); - this.DoubleBuffered = true; } diff --git a/ShiftOS_TheReturn/AppearanceManager.cs b/ShiftOS_TheReturn/AppearanceManager.cs index 81858d3..7cf06c9 100644 --- a/ShiftOS_TheReturn/AppearanceManager.cs +++ b/ShiftOS_TheReturn/AppearanceManager.cs @@ -190,7 +190,7 @@ namespace ShiftOS.Engine ServerManager.Disconnect(); Desktop.InvokeOnWorkerThread(() => { - Environment.Exit(0); //bye bye + Process.GetCurrentProcess().Kill(); //bye bye }); } -- 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/Controls/TerminalBox.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 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/Controls/TerminalBox.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