From 76b54853ba726179f9fddb30c6f838991b7aa71a Mon Sep 17 00:00:00 2001 From: Michael VanOverbeek Date: Sun, 21 May 2017 12:29:53 +0000 Subject: [PATCH] Merge a fuckton of shit. --- ShiftOS.WinForms/Applications/Terminal.cs | 496 ------ .../Applications/UpdateManager.Designer.cs | 130 -- .../Applications/VideoPlayer.Designer.cs | 168 -- .../Controls/ShiftedProgressBar.cs | 147 -- ShiftOS.WinForms/Controls/TerminalBox.cs | 257 --- ShiftOS.WinForms/DownloadControl.Designer.cs | 116 -- ShiftOS.WinForms/Oobe.cs | 600 ------- ShiftOS.WinForms/Program.cs | 269 ---- .../Properties/Resources.Designer.cs | 1394 ----------------- ShiftOS.WinForms/Tools/ControlManager.cs | 300 ---- ShiftOS.WinForms/Tools/DitheringEngine.cs | 402 ----- ShiftOS.WinForms/WinformsDesktop.Designer.cs | 312 ---- ShiftOS.WinForms/WinformsDesktop.cs | 1066 ------------- ShiftOS_TheReturn/AppearanceManager.cs | 379 ----- ShiftOS_TheReturn/AudioManager.cs | 134 -- ShiftOS_TheReturn/Commands.cs | 837 ---------- ShiftOS_TheReturn/CrashHandler.cs | 217 --- ShiftOS_TheReturn/Desktop.cs | 271 ---- ShiftOS_TheReturn/KernelWatchdog.cs | 145 -- ShiftOS_TheReturn/Localization.cs | 219 --- ShiftOS_TheReturn/NotificationDaemon.cs | 134 -- ShiftOS_TheReturn/Paths.cs | 237 --- ShiftOS_TheReturn/SaveSystem.cs | 487 ------ ShiftOS_TheReturn/Scripting.cs | 499 ------ ShiftOS_TheReturn/ServerManager.cs | 284 ---- ShiftOS_TheReturn/Shiftorium.cs | 479 ------ ShiftOS_TheReturn/Skinning.cs | 1336 ---------------- ShiftOS_TheReturn/Story.cs | 328 ---- ShiftOS_TheReturn/TerminalBackend.cs | 534 ------- ShiftOS_TheReturn/TerminalTextWriter.cs | 131 -- ShiftOS_TheReturn/UniteClient.cs | 135 -- ShiftOS_TheReturn/UserManagementCommands.cs | 201 --- 32 files changed, 12644 deletions(-) delete mode 100644 ShiftOS.WinForms/Applications/Terminal.cs delete mode 100644 ShiftOS.WinForms/Applications/UpdateManager.Designer.cs delete mode 100644 ShiftOS.WinForms/Applications/VideoPlayer.Designer.cs delete mode 100644 ShiftOS.WinForms/Controls/ShiftedProgressBar.cs delete mode 100644 ShiftOS.WinForms/Controls/TerminalBox.cs delete mode 100644 ShiftOS.WinForms/DownloadControl.Designer.cs delete mode 100644 ShiftOS.WinForms/Oobe.cs delete mode 100644 ShiftOS.WinForms/Program.cs delete mode 100644 ShiftOS.WinForms/Properties/Resources.Designer.cs delete mode 100644 ShiftOS.WinForms/Tools/ControlManager.cs delete mode 100644 ShiftOS.WinForms/Tools/DitheringEngine.cs delete mode 100644 ShiftOS.WinForms/WinformsDesktop.Designer.cs delete mode 100644 ShiftOS.WinForms/WinformsDesktop.cs delete mode 100644 ShiftOS_TheReturn/AppearanceManager.cs delete mode 100644 ShiftOS_TheReturn/AudioManager.cs delete mode 100644 ShiftOS_TheReturn/Commands.cs delete mode 100644 ShiftOS_TheReturn/CrashHandler.cs delete mode 100644 ShiftOS_TheReturn/Desktop.cs delete mode 100644 ShiftOS_TheReturn/KernelWatchdog.cs delete mode 100644 ShiftOS_TheReturn/Localization.cs delete mode 100644 ShiftOS_TheReturn/NotificationDaemon.cs delete mode 100644 ShiftOS_TheReturn/Paths.cs delete mode 100644 ShiftOS_TheReturn/SaveSystem.cs delete mode 100644 ShiftOS_TheReturn/Scripting.cs delete mode 100644 ShiftOS_TheReturn/ServerManager.cs delete mode 100644 ShiftOS_TheReturn/Shiftorium.cs delete mode 100644 ShiftOS_TheReturn/Skinning.cs delete mode 100644 ShiftOS_TheReturn/Story.cs delete mode 100644 ShiftOS_TheReturn/TerminalBackend.cs delete mode 100644 ShiftOS_TheReturn/TerminalTextWriter.cs delete mode 100644 ShiftOS_TheReturn/UniteClient.cs delete mode 100644 ShiftOS_TheReturn/UserManagementCommands.cs diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs deleted file mode 100644 index 32c5363..0000000 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ /dev/null @@ -1,496 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -//#define TRAILER -//#define CRASHONSTART -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Diagnostics; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.Text.RegularExpressions; -using System.Collections; -using static ShiftOS.Engine.SkinEngine; -using ShiftOS.Engine; -using ShiftOS.Objects; -using ShiftOS.WinForms.Tools; - -namespace ShiftOS.WinForms.Applications -{ - [Launcher("Terminal", false, null, "Utilities")] - [WinOpen("terminal")] - [DefaultIcon("iconTerminal")] - public partial class Terminal : UserControl, IShiftOSWindow - { - public static Stack ConsoleStack = new Stack(); - - public static System.Windows.Forms.Timer ti = new System.Windows.Forms.Timer(); - - public static string latestCommmand = ""; - - public static bool IsInRemoteSystem = false; - public static string RemoteGuid = ""; - - [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static bool PrefixEnabled - { - get - { - return TerminalBackend.PrefixEnabled; - } - set - { - TerminalBackend.PrefixEnabled = value; - } - } - - [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static bool InStory - { - get - { - return TerminalBackend.InStory; - } - set - { - TerminalBackend.InStory = value; - } - } - - [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static string LastCommand - { - get - { - return TerminalBackend.LastCommand; - } - set - { - TerminalBackend.LastCommand = value; - } - } - - public int TutorialProgress - { - get - { - throw new NotImplementedException(); - } - - set - { - throw new NotImplementedException(); - } - } - - [Obsolete("This is used for compatibility with old parts of the backend. Please use TerminalBackend instead.")] - public static void InvokeCommand(string text) - { - - TerminalBackend.InvokeCommand(text); - } - - public Terminal() - { - - InitializeComponent(); - SaveSystem.GameReady += () => - { - try - { - this.Invoke(new Action(() => - { - ResetAllKeywords(); - rtbterm.Text = ""; - if (!Shiftorium.UpgradeInstalled("desktop")) - { - TerminalBackend.PrefixEnabled = true; - TerminalBackend.InStory = false; - TerminalBackend.PrintPrompt(); - if (Shiftorium.UpgradeInstalled("wm_free_placement")) - { - this.ParentForm.Width = 640; - this.ParentForm.Height = 480; - this.ParentForm.Left = (Screen.PrimaryScreen.Bounds.Width - 640) / 2; - this.ParentForm.Top = (Screen.PrimaryScreen.Bounds.Height - 480) / 2; - - } - } - else - { - AppearanceManager.Close(this); - } - })); - } - catch { } - }; - - - this.DoubleBuffered = true; - - } - - public void FocusOnTerminal() - { - rtbterm.Focus(); - } - - public static string GetTime() - { - var time = DateTime.Now; - if (ShiftoriumFrontend.UpgradeInstalled("full_precision_time")) - { - return DateTime.Now.ToString("h:mm:ss tt"); - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock_am_and_pm")) - { - return time.TimeOfDay.TotalHours > 12 ? $"{time.Hour - 12} PM" : $"{time.Hour} AM"; - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock_hours")) - { - return ((int)time.TimeOfDay.TotalHours).ToString(); - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock_minutes")) - { - return ((int)time.TimeOfDay.TotalMinutes).ToString(); - } - else if (ShiftoriumFrontend.UpgradeInstalled("clock")) - { - return ((int)time.TimeOfDay.TotalSeconds).ToString(); - } - - return ""; - } - - - public static event TextSentEventHandler TextSent; - - public void ResetAllKeywords() - { - string primary = SaveSystem.CurrentUser.Username + " "; - string secondary = "shiftos "; - - - var asm = Assembly.GetExecutingAssembly(); - - var types = asm.GetTypes(); - - foreach (var type in types) - { - foreach (var a in type.GetCustomAttributes(false)) - { - if (ShiftoriumFrontend.UpgradeAttributesUnlocked(type)) - { - if (a is Namespace) - { - var ns = a as Namespace; - if (!primary.Contains(ns.name)) - { - primary += ns.name + " "; - } - foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) - { - if (ShiftoriumFrontend.UpgradeAttributesUnlocked(method)) - { - foreach (var ma in method.GetCustomAttributes(false)) - { - if (ma is Command) - { - var cmd = ma as Command; - if (!secondary.Contains(cmd.name)) - secondary += cmd.name + " "; - } - } - } - } - } - } - } - } - - - } - - public static void MakeWidget(Controls.TerminalBox txt) - { - AppearanceManager.StartConsoleOut(); - txt.GotFocus += (o, a) => - { - AppearanceManager.ConsoleOut = txt; - }; - txt.KeyDown += (o, a) => - { - if (a.Control == true || a.Alt == true) - { - a.SuppressKeyPress = true; - return; - } - - if (a.KeyCode == Keys.Enter) - { - try - { - a.SuppressKeyPress = true; - Console.WriteLine(""); - var text = txt.Lines.ToArray(); - var text2 = text[text.Length - 2]; - var text3 = ""; - var text4 = Regex.Replace(text2, @"\t|\n|\r", ""); - - if (IsInRemoteSystem == true) - { - ServerManager.SendMessage("trm_invcmd", JsonConvert.SerializeObject(new - { - guid = RemoteGuid, - command = text4 - })); - } - else - { - if (TerminalBackend.PrefixEnabled) - { - text3 = text4.Remove(0, $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); - } - TerminalBackend.LastCommand = text3; - TextSent?.Invoke(text4); - TerminalBackend.SendText(text4); - if (TerminalBackend.InStory == false) - { - if (text3 == "stop theme") - { - CurrentCommandParser.parser = null; - } - else - { - if (CurrentCommandParser.parser == null) - { - TerminalBackend.InvokeCommand(text3); - } - else - { - var result = CurrentCommandParser.parser.ParseCommand(text3); - - if (result.Equals(default(KeyValuePair, Dictionary>))) - { - Console.WriteLine("Syntax Error: Syntax Error"); - } - else - { - TerminalBackend.InvokeCommand(result.Key.Key, result.Key.Value, result.Value); - } - } - } - } - if (TerminalBackend.PrefixEnabled) - { - TerminalBackend.PrintPrompt(); - } - } - } - catch - { - } - } - else if (a.KeyCode == Keys.Back) - { - try - { - var tostring3 = txt.Lines[txt.Lines.Length - 1]; - var tostringlen = tostring3.Length + 1; - var workaround = $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; - var derp = workaround.Length + 1; - if (tostringlen != derp) - { - AppearanceManager.CurrentPosition--; - } - else - { - a.SuppressKeyPress = true; - } - } - catch - { - Debug.WriteLine("Drunky alert in terminal."); - } - } - else if (a.KeyCode == Keys.Left) - { - var getstring = txt.Lines[txt.Lines.Length - 1]; - var stringlen = getstring.Length + 1; - var header = $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "; - var headerlen = header.Length + 1; - var selstart = txt.SelectionStart; - var remstrlen = txt.TextLength - stringlen; - var finalnum = selstart - remstrlen; - - if (finalnum != headerlen) - { - AppearanceManager.CurrentPosition--; - } - else - { - a.SuppressKeyPress = true; - } - } - else if (a.KeyCode == Keys.Up) - { - var tostring3 = txt.Lines[txt.Lines.Length - 1]; - if (tostring3 == $"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ") - Console.Write(TerminalBackend.LastCommand); - a.SuppressKeyPress = true; - - } - else - { - if (TerminalBackend.InStory) - { - a.SuppressKeyPress = true; - } - AppearanceManager.CurrentPosition++; - } - - }; - - AppearanceManager.ConsoleOut = txt; - - txt.Focus(); - - txt.Font = LoadedSkin.TerminalFont; - txt.ForeColor = ControlManager.ConvertColor(LoadedSkin.TerminalForeColorCC); - txt.BackColor = ControlManager.ConvertColor(LoadedSkin.TerminalBackColorCC); - - } - - private void Terminal_Load(object sender, EventArgs e) - { - ServerManager.MessageReceived += (msg) => - { - if (msg.Name == "trm_handshake_guid") - { - IsInRemoteSystem = true; - RemoteGuid = msg.GUID; - } - else if (msg.Name == "trm_handshake_stop") - { - IsInRemoteSystem = false; - RemoteGuid = ""; - } - }; - } - - private void Terminal_FormClosing(object sender, FormClosingEventArgs e) - { - ti.Stop(); - IsInRemoteSystem = false; - RemoteGuid = ""; - } - - public void OnLoad() - { - MakeWidget(rtbterm); - - if (SaveSystem.CurrentSave != null) - { - if (!ShiftoriumFrontend.UpgradeInstalled("window_manager")) - { - rtbterm.Select(rtbterm.TextLength, 0); - } - } - - new Thread(() => - { - Thread.Sleep(1000); - TerminalBackend.PrintPrompt(); - }).Start(); - } - - public void OnSkinLoad() - { - try - { - rtbterm.Font = LoadedSkin.TerminalFont; - rtbterm.ForeColor = ControlManager.ConvertColor(LoadedSkin.TerminalForeColorCC); - rtbterm.BackColor = ControlManager.ConvertColor(LoadedSkin.TerminalBackColorCC); - } - catch - { - - } - - } - - public bool OnUnload() - { - if (SaveSystem.ShuttingDown == false) - { - if (!ShiftoriumFrontend.UpgradeInstalled("desktop")) - { - if (AppearanceManager.OpenForms.Count <= 1) - { - Console.WriteLine(""); - Console.WriteLine("{WIN_CANTCLOSETERMINAL}"); - try - { - Console.WriteLine(""); - - if (TerminalBackend.PrefixEnabled) - { - Console.Write($"{SaveSystem.CurrentUser.Username}@shiftos:~$ "); - } - } - catch (Exception ex) - { - Console.WriteLine(ex); - } - return false; - } - } - } - return true; - } - - public void OnUpgrade() - { - } - - private void rtbterm_TextChanged(object sender, EventArgs e) - { - - } - - internal void ClearText() - { - rtbterm.Text = ""; - } - } -} \ No newline at end of file diff --git a/ShiftOS.WinForms/Applications/UpdateManager.Designer.cs b/ShiftOS.WinForms/Applications/UpdateManager.Designer.cs deleted file mode 100644 index 0b23b8e..0000000 --- a/ShiftOS.WinForms/Applications/UpdateManager.Designer.cs +++ /dev/null @@ -1,130 +0,0 @@ -namespace ShiftOS.WinForms.Applications -{ - partial class UpdateManager - { - /// - /// 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.lbupdatetitle = new System.Windows.Forms.Label(); - this.pnlupdatebar = new System.Windows.Forms.Panel(); - this.pgdownload = new ShiftOS.WinForms.Controls.ShiftedProgressBar(); - this.btnaction = new System.Windows.Forms.Button(); - this.btnclose = new System.Windows.Forms.Button(); - this.wbstatus = new System.Windows.Forms.WebBrowser(); - this.pnlupdatebar.SuspendLayout(); - this.SuspendLayout(); - // - // lbupdatetitle - // - this.lbupdatetitle.AutoSize = true; - this.lbupdatetitle.Dock = System.Windows.Forms.DockStyle.Top; - this.lbupdatetitle.Location = new System.Drawing.Point(0, 0); - this.lbupdatetitle.Margin = new System.Windows.Forms.Padding(10); - this.lbupdatetitle.Name = "lbupdatetitle"; - this.lbupdatetitle.Size = new System.Drawing.Size(117, 13); - this.lbupdatetitle.TabIndex = 0; - this.lbupdatetitle.Tag = "header1"; - this.lbupdatetitle.Text = "Checking for updates..."; - // - // pnlupdatebar - // - this.pnlupdatebar.Controls.Add(this.pgdownload); - this.pnlupdatebar.Controls.Add(this.btnaction); - this.pnlupdatebar.Controls.Add(this.btnclose); - this.pnlupdatebar.Dock = System.Windows.Forms.DockStyle.Bottom; - this.pnlupdatebar.Location = new System.Drawing.Point(0, 426); - this.pnlupdatebar.Name = "pnlupdatebar"; - this.pnlupdatebar.Size = new System.Drawing.Size(597, 33); - this.pnlupdatebar.TabIndex = 1; - // - // pgdownload - // - this.pgdownload.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.pgdownload.BlockSize = 5; - this.pgdownload.Location = new System.Drawing.Point(86, 4); - this.pgdownload.Maximum = 100; - this.pgdownload.Name = "pgdownload"; - this.pgdownload.Size = new System.Drawing.Size(427, 23); - this.pgdownload.Style = System.Windows.Forms.ProgressBarStyle.Continuous; - this.pgdownload.TabIndex = 2; - this.pgdownload.Text = "Updating..."; - this.pgdownload.Value = 0; - // - // btnaction - // - this.btnaction.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnaction.Location = new System.Drawing.Point(519, 4); - this.btnaction.Name = "btnaction"; - this.btnaction.Size = new System.Drawing.Size(75, 23); - this.btnaction.TabIndex = 1; - this.btnaction.Text = "Update"; - this.btnaction.UseVisualStyleBackColor = true; - // - // btnclose - // - this.btnclose.Location = new System.Drawing.Point(4, 4); - this.btnclose.Name = "btnclose"; - this.btnclose.Size = new System.Drawing.Size(75, 23); - this.btnclose.TabIndex = 0; - this.btnclose.Text = "{CLOSE}"; - this.btnclose.UseVisualStyleBackColor = true; - this.btnclose.Click += new System.EventHandler(this.btnclose_Click); - // - // wbstatus - // - this.wbstatus.Dock = System.Windows.Forms.DockStyle.Fill; - this.wbstatus.Location = new System.Drawing.Point(0, 13); - this.wbstatus.MinimumSize = new System.Drawing.Size(20, 20); - this.wbstatus.Name = "wbstatus"; - this.wbstatus.Size = new System.Drawing.Size(597, 413); - this.wbstatus.TabIndex = 2; - // - // UpdateManager - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.wbstatus); - this.Controls.Add(this.pnlupdatebar); - this.Controls.Add(this.lbupdatetitle); - this.Name = "UpdateManager"; - this.Size = new System.Drawing.Size(597, 459); - this.pnlupdatebar.ResumeLayout(false); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.Label lbupdatetitle; - private System.Windows.Forms.Panel pnlupdatebar; - private Controls.ShiftedProgressBar pgdownload; - private System.Windows.Forms.Button btnaction; - private System.Windows.Forms.Button btnclose; - private System.Windows.Forms.WebBrowser wbstatus; - } -} diff --git a/ShiftOS.WinForms/Applications/VideoPlayer.Designer.cs b/ShiftOS.WinForms/Applications/VideoPlayer.Designer.cs deleted file mode 100644 index d915c31..0000000 --- a/ShiftOS.WinForms/Applications/VideoPlayer.Designer.cs +++ /dev/null @@ -1,168 +0,0 @@ -namespace ShiftOS.WinForms.Applications -{ - partial class VideoPlayer - { - /// - /// 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() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(VideoPlayer)); - this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer(); - this.flcontrols = new System.Windows.Forms.FlowLayoutPanel(); - this.btnplay = new System.Windows.Forms.Button(); - this.pgplaytime = new ShiftOS.WinForms.Controls.ShiftedProgressBar(); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.addSongToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.wpaudio = new AxWMPLib.AxWindowsMediaPlayer(); - this.toolStripContainer1.ContentPanel.SuspendLayout(); - this.toolStripContainer1.TopToolStripPanel.SuspendLayout(); - this.toolStripContainer1.SuspendLayout(); - this.flcontrols.SuspendLayout(); - this.menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.wpaudio)).BeginInit(); - this.SuspendLayout(); - // - // toolStripContainer1 - // - // - // toolStripContainer1.ContentPanel - // - this.toolStripContainer1.ContentPanel.Controls.Add(this.wpaudio); - this.toolStripContainer1.ContentPanel.Controls.Add(this.flcontrols); - this.toolStripContainer1.ContentPanel.Size = new System.Drawing.Size(805, 402); - this.toolStripContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.toolStripContainer1.LeftToolStripPanelVisible = false; - this.toolStripContainer1.Location = new System.Drawing.Point(0, 0); - this.toolStripContainer1.Name = "toolStripContainer1"; - this.toolStripContainer1.RightToolStripPanelVisible = false; - this.toolStripContainer1.Size = new System.Drawing.Size(805, 426); - this.toolStripContainer1.TabIndex = 3; - this.toolStripContainer1.Text = "toolStripContainer1"; - // - // toolStripContainer1.TopToolStripPanel - // - this.toolStripContainer1.TopToolStripPanel.Controls.Add(this.menuStrip1); - // - // flcontrols - // - this.flcontrols.AutoSize = true; - this.flcontrols.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.flcontrols.Controls.Add(this.btnplay); - this.flcontrols.Controls.Add(this.pgplaytime); - this.flcontrols.Dock = System.Windows.Forms.DockStyle.Bottom; - this.flcontrols.Location = new System.Drawing.Point(0, 373); - this.flcontrols.Name = "flcontrols"; - this.flcontrols.Size = new System.Drawing.Size(805, 29); - this.flcontrols.TabIndex = 0; - // - // btnplay - // - this.btnplay.AutoSize = true; - this.btnplay.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.btnplay.Location = new System.Drawing.Point(3, 3); - this.btnplay.Name = "btnplay"; - this.btnplay.Size = new System.Drawing.Size(37, 23); - this.btnplay.TabIndex = 0; - this.btnplay.Text = "Play"; - this.btnplay.UseVisualStyleBackColor = true; - this.btnplay.Click += new System.EventHandler(this.btnplay_Click); - // - // pgplaytime - // - this.pgplaytime.BlockSize = 5; - this.pgplaytime.Location = new System.Drawing.Point(46, 3); - this.pgplaytime.Maximum = 100; - this.pgplaytime.Name = "pgplaytime"; - this.pgplaytime.Size = new System.Drawing.Size(749, 23); - this.pgplaytime.Style = System.Windows.Forms.ProgressBarStyle.Continuous; - this.pgplaytime.TabIndex = 1; - this.pgplaytime.Tag = "keepbg"; - this.pgplaytime.Text = "shiftedProgressBar1"; - this.pgplaytime.Value = 0; - this.pgplaytime.MouseDown += new System.Windows.Forms.MouseEventHandler(this.startScrub); - this.pgplaytime.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pgplaytime_MouseMove); - this.pgplaytime.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pgplaytime_MouseUp); - // - // menuStrip1 - // - this.menuStrip1.Dock = System.Windows.Forms.DockStyle.None; - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.addSongToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(805, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; - // - // addSongToolStripMenuItem - // - this.addSongToolStripMenuItem.Name = "addSongToolStripMenuItem"; - this.addSongToolStripMenuItem.Size = new System.Drawing.Size(81, 20); - this.addSongToolStripMenuItem.Text = "Open Video"; - this.addSongToolStripMenuItem.Click += new System.EventHandler(this.addSongToolStripMenuItem_Click); - // - // wpaudio - // - this.wpaudio.Dock = System.Windows.Forms.DockStyle.Fill; - this.wpaudio.Enabled = true; - this.wpaudio.Location = new System.Drawing.Point(0, 0); - this.wpaudio.Name = "wpaudio"; - this.wpaudio.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("wpaudio.OcxState"))); - this.wpaudio.Size = new System.Drawing.Size(805, 373); - this.wpaudio.TabIndex = 2; - this.wpaudio.Visible = false; - // - // VideoPlayer - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.toolStripContainer1); - this.Name = "VideoPlayer"; - this.Size = new System.Drawing.Size(805, 426); - this.toolStripContainer1.ContentPanel.ResumeLayout(false); - this.toolStripContainer1.ContentPanel.PerformLayout(); - this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false); - this.toolStripContainer1.TopToolStripPanel.PerformLayout(); - this.toolStripContainer1.ResumeLayout(false); - this.toolStripContainer1.PerformLayout(); - this.flcontrols.ResumeLayout(false); - this.flcontrols.PerformLayout(); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.wpaudio)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - private System.Windows.Forms.ToolStripContainer toolStripContainer1; - private System.Windows.Forms.FlowLayoutPanel flcontrols; - private System.Windows.Forms.Button btnplay; - private Controls.ShiftedProgressBar pgplaytime; - private System.Windows.Forms.MenuStrip menuStrip1; - private System.Windows.Forms.ToolStripMenuItem addSongToolStripMenuItem; - private AxWMPLib.AxWindowsMediaPlayer wpaudio; - } -} diff --git a/ShiftOS.WinForms/Controls/ShiftedProgressBar.cs b/ShiftOS.WinForms/Controls/ShiftedProgressBar.cs deleted file mode 100644 index e5a2c33..0000000 --- a/ShiftOS.WinForms/Controls/ShiftedProgressBar.cs +++ /dev/null @@ -1,147 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace ShiftOS.WinForms.Controls -{ - public partial class ShiftedProgressBar : Control - { - public ShiftedProgressBar() - { - this.SizeChanged += (o, a) => - { - this.Refresh(); - }; - var t = new Timer(); - t.Interval = 100; - t.Tick += (o, a) => - { - if(this._style == ProgressBarStyle.Marquee) - { - if(_marqueePos >= this.Width) - { - _marqueePos = 0 - (this.Width / 4); - } - else - { - _marqueePos++; - } - this.Refresh(); - } - }; - t.Start(); - } - - private int _value = 0; - private int _max = 100; - public int Value - { - get - { - return _value; - } - set - { - _value = value; - this.Refresh(); - } - } - public int Maximum - { - get - { - return _max; - } - set - { - _max = value; - this.Refresh(); - } - } - - public ProgressBarStyle _style = ProgressBarStyle.Continuous; - - public ProgressBarStyle Style - { - get { return _style; } - set { _style = value; this.Refresh(); } - } - - private int _blocksize = 5; - - public int BlockSize - { - get { return _blocksize; } - set - { - _blocksize = value; - this.Refresh(); - } - } - - protected override void OnPaint(PaintEventArgs pe) - { - pe.Graphics.Clear(Color.Black); - switch (_style) - { - case ProgressBarStyle.Continuous: - double width = linear(this.Value, 0, this.Maximum, 0, this.Width); - pe.Graphics.FillRectangle(new SolidBrush(Color.Green), new RectangleF(0, 0, (float)width, this.Height)); - break; - case ProgressBarStyle.Blocks: - int block_count = this.Width / (this._blocksize + 2); - int blocks = (int)linear(this.Value, 0, this.Maximum, 0, block_count); - for(int i = 0; i < blocks - 1; i++) - { - int position = i * (_blocksize + 2); - pe.Graphics.FillRectangle(new SolidBrush(Color.Green), new Rectangle(position, 0, _blocksize, this.Height)); - } - break; - case ProgressBarStyle.Marquee: - pe.Graphics.FillRectangle(new SolidBrush(Color.Green), new Rectangle(_marqueePos, 0, this.Width / 4, this.Height)); - break; - } - } - - private int _marqueePos = 0; - - static private double linear(double x, double x0, double x1, double y0, double y1) - { - if ((x1 - x0) == 0) - { - return (y0 + y1) / 2; - } - return y0 + (x - x0) * (y1 - y0) / (x1 - x0); - } - } -} diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs deleted file mode 100644 index ea7808c..0000000 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ /dev/null @@ -1,257 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Drawing; -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 -{ - public class TerminalBox : RichTextBox, ITerminalWidget - { - public void SelectBottom() - { - try - { - this.Select(this.Text.Length, 0); - this.ScrollToCaret(); - } - 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); - this.Select(this.TextLength, 0); - } - - 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; - } - - 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) - { - 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; - } - - 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); - } - - 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); // infernal beeping noise only enable for the trailers - break; - } - } - } - - public TerminalBox() : base() - { - this.Tag = "keepbg keepfg keepfont"; - } - } -} diff --git a/ShiftOS.WinForms/DownloadControl.Designer.cs b/ShiftOS.WinForms/DownloadControl.Designer.cs deleted file mode 100644 index 2587b93..0000000 --- a/ShiftOS.WinForms/DownloadControl.Designer.cs +++ /dev/null @@ -1,116 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -namespace ShiftOS.WinForms -{ - partial class DownloadControl - { - /// - /// 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.pcicon = new System.Windows.Forms.PictureBox(); - this.lbshiftneturl = new System.Windows.Forms.Label(); - this.pgprogress = new ShiftOS.WinForms.Controls.ShiftedProgressBar(); - ((System.ComponentModel.ISupportInitialize)(this.pcicon)).BeginInit(); - this.SuspendLayout(); - // - // pcicon - // - this.pcicon.BackColor = System.Drawing.Color.Black; - this.pcicon.Location = new System.Drawing.Point(4, 4); - this.pcicon.Name = "pcicon"; - this.pcicon.Size = new System.Drawing.Size(42, 42); - this.pcicon.TabIndex = 1; - this.pcicon.TabStop = false; - // - // lbshiftneturl - // - this.lbshiftneturl.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.lbshiftneturl.Location = new System.Drawing.Point(52, 4); - this.lbshiftneturl.Name = "lbshiftneturl"; - this.lbshiftneturl.Size = new System.Drawing.Size(323, 42); - this.lbshiftneturl.TabIndex = 2; - this.lbshiftneturl.Text = "label1"; - this.lbshiftneturl.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // - // pgprogress - // - this.pgprogress.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.pgprogress.BlockSize = 5; - this.pgprogress.Location = new System.Drawing.Point(4, 52); - this.pgprogress.Maximum = 100; - this.pgprogress.Name = "pgprogress"; - this.pgprogress.Size = new System.Drawing.Size(371, 23); - this.pgprogress.Style = System.Windows.Forms.ProgressBarStyle.Continuous; - this.pgprogress.TabIndex = 0; - this.pgprogress.Text = "shiftedProgressBar1"; - this.pgprogress.Value = 0; - // - // DownloadControl - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.lbshiftneturl); - this.Controls.Add(this.pcicon); - this.Controls.Add(this.pgprogress); - this.Name = "DownloadControl"; - this.Size = new System.Drawing.Size(382, 82); - ((System.ComponentModel.ISupportInitialize)(this.pcicon)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private Controls.ShiftedProgressBar pgprogress; - private System.Windows.Forms.PictureBox pcicon; - private System.Windows.Forms.Label lbshiftneturl; - } -} diff --git a/ShiftOS.WinForms/Oobe.cs b/ShiftOS.WinForms/Oobe.cs deleted file mode 100644 index d5f28f8..0000000 --- a/ShiftOS.WinForms/Oobe.cs +++ /dev/null @@ -1,600 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Forms; -using Newtonsoft.Json; -using ShiftOS.Engine; -using ShiftOS.Objects; -using ShiftOS.Objects.ShiftFS; -using ShiftOS.Unite; -using ShiftOS.WinForms.Tools; - -namespace ShiftOS.WinForms -{ - public partial class Oobe : Form, IOobe, ITutorial - { - public Oobe() - { - InitializeComponent(); - this.FormBorderStyle = FormBorderStyle.None; - this.WindowState = FormWindowState.Maximized; - this.BackColor = Color.Black; - this.Load += (o, a) => - { - ControlManager.SetupControls(this); - }; - } - - - string rtext; - string gtexttotype; - int charcount; - int slashcount; - Label textgeninput; - public bool upgraded = false; - - private bool typing = false; - - public void TextType(string texttotype) - { - textgeninput.TextAlign = ContentAlignment.MiddleCenter; - while(typing == true) - { - //JESUS CHRIST PAST MICHAEL. - - //We should PROBABLY block the thread... You know... not everyone has a 10-core processor. - Thread.Sleep(100); - } - - charcount = texttotype.Length; - gtexttotype = texttotype; - slashcount = 1; - foreach (var c in gtexttotype) - { - typing = true; - rtext += c; - - this.Invoke(new Action(() => - { - textgeninput.Text = rtext + "|"; - })); - slashcount++; - if (slashcount == 5) - slashcount = 1; - Thread.Sleep(50); - } - rtext += Environment.NewLine; - typing = false; - } - - public Save MySave = null; - - public event EventHandler OnComplete; - - private int tutPrg = 0; - - public int TutorialProgress - { - get - { - return tutPrg; - } - - set - { - tutPrg = value; - } - } - - public void StartShowing(Save save) - { - var t = new Thread(new ThreadStart(() => - { - try - { - textgeninput = this.lblhackwords; - this.Invoke(new Action(() => - { - lblHijack.Hide(); - })); - - TextType(@"Throughout many years, man has tried to develop -a digital environment usable by anyone that never goes -offline, full of AIs and humans alike, thinking, interacting, -innovating. - -No one has ever come close to a digital society of such -properties yet, except for one sentient being. It does not -have a life, a gender, an age or a body, but simply one name. - -They call it ""DevX"". - -If anyone sees this message, my identity is anonymous, but I -need your help. I am trapped within ""DevX""'s digital society -with no way out, constantly under attack. - -You must join the digital society, rise up the ranks, and save us. - - - undisclosed_0x1DDFB5977."); - - Thread.Sleep(5000); - while(this.Opacity > 0f) - { - this.Invoke(new Action(() => - { - this.Opacity -= 0.01f; - })); - Thread.Sleep(25); - } - - Story.Start("mud_fundamentals"); - - this.Invoke(new Action(this.Close)); - } - catch (Exception e) - { - TextType("I have experienced an error."); - TextType(e.ToString()); - } - })); - this.Show(); - this.BringToFront(); - this.TopMost = true; - t.IsBackground = true; - t.Start(); - } - - public void Clear() - { - this.Invoke(new Action(() => - { - rtext = ""; - textgeninput.Text = ""; - })); - } - - public void ShowSaveTransfer(Save save) - { - //Stub. - } - - public void PerformUniteLogin() - { - - } - - public void PromptForLogin() - { - Infobox.Show("Login", "Since the last time you've played ShiftOS, some changes have been made to the login system. You must now login using your website credentials.", () => - { - Infobox.PromptYesNo("Website account", "Do you have an account at http://getshiftos.ml?", (hasAccount) => - { - if(hasAccount == true) - { - var loginDialog = new UniteLoginDialog((success)=> - { - string token = success; - var uClient = new UniteClient("http://getshiftos.ml", token); - Infobox.Show("Welcome to ShiftOS.", $"Hello, {uClient.GetDisplayName()}! We've signed you into your account. We'll now try to link your ShiftOS account with your save file.", () => - { - ServerMessageReceived smr = null; - smr = (msg) => - { - ServerManager.MessageReceived -= smr; - if (msg.Name == "mud_savefile") - { - SaveSystem.CurrentSave = JsonConvert.DeserializeObject(msg.Contents); - SaveSystem.SaveGame(); - } - else if(msg.Name=="mud_login_denied") - { - LinkSaveFile(token); - } - }; - ServerManager.MessageReceived += smr; - ServerManager.SendMessage("mud_token_login", token); - }); - }); - AppearanceManager.SetupDialog(loginDialog); - } - else - { - var signupDialog = new UniteSignupDialog((token) => - { - ServerMessageReceived smr = null; - smr = (msg) => - { - ServerManager.MessageReceived -= smr; - if (msg.Name == "mud_savefile") - { - SaveSystem.CurrentSave = JsonConvert.DeserializeObject(msg.Contents); - SaveSystem.SaveGame(); - } - else if (msg.Name == "mud_login_denied") - { - LinkSaveFile(token); - } - }; - ServerManager.MessageReceived += smr; - ServerManager.SendMessage("mud_token_login", token); - - }); - AppearanceManager.SetupDialog(signupDialog); - } - }); - }); - } - - public void LinkSaveFile(string token) - { - if (Utils.FileExists(Paths.GetPath("user.dat"))) - { - try - { - var details = JsonConvert.DeserializeObject(Utils.ReadAllText(Paths.GetPath("user.dat"))); - ServerMessageReceived smr = null; - bool msgreceived = false; - bool found = false; - smr = (msg) => - { - if (msg.Name == "mud_savefile") - { - var save = JsonConvert.DeserializeObject(msg.Contents); - save.UniteAuthToken = token; - Infobox.Show("Migration complete.", "We have migrated your old save file to the new system successfully. You can still log in using the old system on old builds of ShiftOS.", () => - { - SaveSystem.CurrentSave = save; - SaveSystem.SaveGame(); - found = true; - msgreceived = true; - }); - } - else if (msg.Name == "mud_login_denied") - { - found = false; - msgreceived = true; - } - ServerManager.MessageReceived -= smr; - }; - ServerManager.MessageReceived += smr; - ServerManager.SendMessage("mud_login", JsonConvert.SerializeObject(new - { - username = details.Username, - password = details.Password - })); - while (msgreceived == false) - Thread.Sleep(10); - if (found == true) - return; - } - catch - { - - } - } - - var client = new UniteClient("http://getshiftos.ml", token); - var sve = new Save(); - sve.Username = client.GetEmail(); - sve.Password = Guid.NewGuid().ToString(); - sve.SystemName = client.GetSysName(); - sve.UniteAuthToken = token; - sve.Codepoints = 0; - sve.Upgrades = new Dictionary(); - sve.ID = Guid.NewGuid(); - sve.StoriesExperienced = new List(); - sve.StoriesExperienced.Add("mud_fundamentals"); - Infobox.Show("Welcome to ShiftOS.", "Welcome to ShiftOS, " + client.GetDisplayName() + ". We have created a save file for you. Now, go on and Shift It Your Way.", () => - { - sve.StoryPosition = 8675309; - SaveSystem.CurrentSave = sve; - Shiftorium.Silent = true; - SaveSystem.SaveGame(); - Shiftorium.Silent = false; - - }); - } - - public void ForceReboot() - { - string json = Utils.ExportMount(0); - System.IO.File.WriteAllText(Paths.SaveFile, json); - System.Diagnostics.Process.Start(Application.ExecutablePath); - Environment.Exit(0); - } - - public void StartTrailer() - { - while(AppearanceManager.OpenForms.Count > 0) - { - AppearanceManager.OpenForms[0].Close(); - } - - this.Show(); - this.TopMost = true; - this.TransparencyKey = Color.Magenta; - this.BackColor = this.TransparencyKey; - textgeninput = lblHijack; - textgeninput.BackColor = Color.Black; - textgeninput.Font = new Font("Lucida Console", 13F, FontStyle.Bold); - textgeninput.AutoSize = true; - textgeninput.TextAlign = ContentAlignment.MiddleCenter; - textgeninput.TextChanged += (o, a) => - { - textgeninput.Location = new Point( - (this.Width - textgeninput.Width) / 2, - (this.Height - textgeninput.Height) / 2 - ); - }; - var t = new Thread(() => - { - Clear(); - Thread.Sleep(5000); - TextType("Michael VanOverbeek"); - TextType("presents..."); - Thread.Sleep(2000); - Clear(); - Thread.Sleep(1000); - TextType("A community-developed game"); - Thread.Sleep(3000); - Clear(); - Thread.Sleep(1000); - this.Invoke(new Action(() => - { - textgeninput.Font = new Font("Lucida Console", 14F, FontStyle.Bold); - this.BackColor = Color.Black; - })); - TextType("Welcome to ShiftOS."); - Thread.Sleep(4000); - Clear(); - textgeninput = lblhackwords; - TextType("Hello."); - Thread.Sleep(500); - TextType("You have been cordially and involuntarily selected to participate in the development and testing of an experimental operating system called ShiftOS."); - Thread.Sleep(500); - TextType("I want ShiftOS to be the most advanced operating system in the world."); - Thread.Sleep(500); - TextType("In ShiftOS, you start out with nothing."); - Thread.Sleep(500); - TextType("And your goal is to upgrade the operating system from a barebones command line to a fully graphical operating system."); - Thread.Sleep(500); - TextType("Along the way, you'll meet many people - hackers, rebels, programmers, administrators and many more."); - Thread.Sleep(500); - TextType("You'll meet new friends and foes."); - Thread.Sleep(500); - TextType("Your goal: Take it over. Upgrade the operating system, and take over its multi-user domain."); - Thread.Sleep(500); - TextType("I won't reveal quite what you have to do, but if you can handle it, head over to http://getshiftos.ml/ and download the operating system now."); - Thread.Sleep(5000); - Clear(); - textgeninput = lblHijack; - TextType("Think you can handle it?"); - }); - t.IsBackground = false; - t.Start(); - } - - public void Start() - { - Shiftorium.Silent = false; - foreach(var frm in AppearanceManager.OpenForms) - { - (frm as Form).Invoke(new Action(() => { - frm.Close(); - })); - } - - TerminalBackend.CommandProcessed += (cmd, args) => - { - if(cmd == "sos.help") - { - if (TutorialProgress == 0) - TutorialProgress = 1; - } - else if(cmd == "sos.status") - { - if (TutorialProgress == 1) - TutorialProgress = 2; - - } - else if(cmd == "shiftorium.list") - { - if (TutorialProgress == 2) - { - TutorialProgress = 3; - SaveSystem.TransferCodepointsFrom("sys", 50); - } - } - else if(cmd == "shiftorium.info" && args == "{\"upgrade\":\"mud_fundamentals\"}") - { - if (TutorialProgress == 3) - TutorialProgress = 4; - } - else if(cmd == "win.open") - { - if (TutorialProgress == 4) - TutorialProgress = 5; - } - }; - if(this.Visible == false) - this.Show(); - var t = new Thread(() => - { - textgeninput = lblHijack; - Clear(); - textgeninput = lblhackwords; - Clear(); - - this.Invoke(new Action(() => - { - textgeninput.Font = SkinEngine.LoadedSkin.TerminalFont; - })); - TextType("ShiftOS has been installed successfully."); - Thread.Sleep(500); - TextType("Before you can continue to the operating system, here's a little tutorial on how to use it."); - Thread.Sleep(500); - TextType("Starting a Terminal..."); - Applications.Terminal term = null; - this.Invoke(new Action(() => - { - term = new Applications.Terminal(); - this.Controls.Add(term); - term.Location = new Point( - (this.Width - term.Width) / 2, - (this.Height - term.Height) / 2 - ); - term.Show(); - term.OnLoad(); - term.OnSkinLoad(); - term.OnUpgrade(); - })); - TextType("This little text box is called a Terminal."); - Thread.Sleep(500); - TextType("Normally, it would appear in full-screen, but this window is hosting it as a control so you can see this text as well."); - Thread.Sleep(500); - 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) - { - //JESUS CHRIST PAST MICHAEL. - - //We should PROBABLY block the thread... You know... not everyone has a 10-core processor. - Thread.Sleep(100); - - } - TextType("As you can see, sos.help gives you a list of all commands in the system."); - Thread.Sleep(500); - 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) - { - //JESUS CHRIST PAST MICHAEL. - - //We should PROBABLY block the thread... You know... not everyone has a 10-core processor. - Thread.Sleep(100); - - } - TextType("Brilliant. The sos.status command will tell you how many Codepoints you have, as well as how many upgrades you have installed and how many are available."); - Thread.Sleep(500); - TextType("Codepoints, as you know, are a special currency within ShiftOS. They are used to buy things within the multi-user domain, such as upgrades, scripts, and applications."); - Thread.Sleep(500); - TextType("You can earn Codepoints by doing things in ShiftOS - such as completing jobs for other users, making things like skins, scripts, documents, etc, and playing games like Pong."); - Thread.Sleep(500); - TextType("At times, you'll be given Codepoints to help complete a task. You will receive Codepoints from 'sys' - the multi-user domain itself."); - //SaveSystem.TransferCodepointsFrom("sys", 50); - TextType("Right now, you don't have any upgrades. Upgrades can give ShiftOS additional features and capabilities - like new core applications, supported file types, and new Terminal commands."); - Thread.Sleep(500); - 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) - { - //JESUS CHRIST PAST MICHAEL. - - //We should PROBABLY block the thread... You know... not everyone has a 10-core processor. - Thread.Sleep(100); - - } - Clear(); - TextType("Right now, you have enough Codepoints to buy the 'mud_fundamentals' upgrade. You can use shiftorium.info to see information about this upgrade."); - Thread.Sleep(500); - TextType("Some commands, like shiftorium.info, require you to pass information to them in the form of arguments."); - Thread.Sleep(500); - TextType("Argument pairs sit at the end of the command, and are enclosed in curly braces."); - Thread.Sleep(500); - TextType("Inside these curly braces, you can input an argument key, followed by a colon, followed by the value. Then, if you need multiple arguments, you can put a comma after the value, and then insert another argument pair."); - Thread.Sleep(500); - TextType("There are different value types - numeric values, which can be any positive or negative 32-bit integer"); - Thread.Sleep(500); - TextType("Then there are boolean values which can be either 'true' or 'false'"); - Thread.Sleep(500); - TextType("Then there are string values, which are enclosed in double-quotes."); - Thread.Sleep(500); - TextType(" If for some reason you need to use a double-quote inside a string, you must escape it using a single backslash followed by the quote, like this: key:\"My \\\"awesome\\\" value.\""); - Thread.Sleep(500); - 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) - { - //JESUS CHRIST PAST MICHAEL. - - //We should PROBABLY block the thread... You know... not everyone has a 10-core processor. - Thread.Sleep(100); - - } - 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")) - { //JESUS CHRIST PAST MICHAEL. - - //We should PROBABLY block the thread... You know... not everyone has a 10-core processor. - Thread.Sleep(100); - - - } - 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."); - Thread.Sleep(500); - 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) - { - //JESUS CHRIST PAST MICHAEL. - - //We should PROBABLY block the thread... You know... not everyone has a 10-core processor. - Thread.Sleep(100); - - } - TextType("This concludes the ShiftOS beginners' guide brought to you by the multi-user domain. Stay safe in a connected world."); - Thread.Sleep(2000); - Desktop.InvokeOnWorkerThread(() => - { - OnComplete?.Invoke(this, EventArgs.Empty); - SaveSystem.CurrentSave.StoryPosition = 2; - this.Close(); - SaveSystem.SaveGame(); - AppearanceManager.SetupWindow(new Applications.Terminal()); - }); - - }); - t.IsBackground = true; - t.Start(); - } - } -} diff --git a/ShiftOS.WinForms/Program.cs b/ShiftOS.WinForms/Program.cs deleted file mode 100644 index ad8fc83..0000000 --- a/ShiftOS.WinForms/Program.cs +++ /dev/null @@ -1,269 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; -using ShiftOS.Engine; -using Newtonsoft.Json; -using static ShiftOS.Objects.ShiftFS.Utils; -using ShiftOS.WinForms.Applications; -using ShiftOS.WinForms.Tools; -using System.Reflection; -using System.IO; - -namespace ShiftOS.WinForms -{ - public static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - public static void Main() - { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - //if ANYONE puts code before those two winforms config lines they will be declared a drunky. - Michael - LoginManager.Init(new GUILoginFrontend()); - CrashHandler.SetGameMetadata(Assembly.GetExecutingAssembly()); - SkinEngine.SetIconProber(new ShiftOSIconProvider()); - ShiftOS.Engine.AudioManager.Init(new ShiftOSAudioProvider()); - Localization.RegisterProvider(new WFLanguageProvider()); - AppearanceManager.OnExit += () => - { - Environment.Exit(0); - }; - - TutorialManager.RegisterTutorial(new Oobe()); - - TerminalBackend.TerminalRequested += () => - { - AppearanceManager.SetupWindow(new Applications.Terminal()); - }; - Infobox.Init(new Dialog()); - FileSkimmerBackend.Init(new WinformsFSFrontend()); - var desk = new WinformsDesktop(); - Desktop.Init(desk); - OutOfBoxExperience.Init(new Oobe()); - AppearanceManager.Initiate(new WinformsWindowManager()); - Application.Run(desk); - } - } - - internal class ShiftOSIconProvider : IIconProber - { - public Image GetIcon(DefaultIconAttribute attr) - { - - var res = typeof(Properties.Resources); - foreach(var prop in res.GetProperties(BindingFlags.NonPublic | BindingFlags.Static)) - { - if(prop.PropertyType.BaseType == typeof(Image)) - { - if(prop.Name == attr.ID) - { - return prop.GetValue(null) as Image; - } - } - } - return new Bitmap(16, 16); - } - } - - [ShiftoriumProvider] - internal class WinformsShiftoriumProvider : IShiftoriumProvider - { - public List GetDefaults() - { - var defaultList = JsonConvert.DeserializeObject>(Properties.Resources.Shiftorium); - - foreach(var exe in Directory.GetFiles(Environment.CurrentDirectory)) - { - if (exe.EndsWith(".exe") || exe.EndsWith(".dll")) - { - try - { - var asm = Assembly.LoadFile(exe); - foreach (var type in asm.GetTypes()) - { - var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is AppscapeEntryAttribute) as AppscapeEntryAttribute; - if (attrib != null) - { - var upgrade = new ShiftoriumUpgrade - { - Id = attrib.Name.ToLower().Replace(" ", "_"), - Name = attrib.Name, - Description = attrib.Description, - Cost = attrib.Cost, - Category = attrib.Category, - Dependencies = (string.IsNullOrWhiteSpace(attrib.DependencyString)) ? "appscape_handled_nodisplay" : "appscape_handled_nodisplay;" + attrib.DependencyString - }; - defaultList.Add(upgrade); - } - - var sattrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is StpContents) as StpContents; - if (sattrib != null) - { - var upgrade = new ShiftoriumUpgrade - { - Id = sattrib.Upgrade, - Name = sattrib.Name, - Description = "This is a hidden dummy upgrade for the .stp file installation attribute \"" + sattrib.Name + "\".", - Cost = 0, - Category = "If this is shown, there's a bug in the Shiftorium Provider or the user is a supreme Shifter.", - Dependencies = "dummy_nodisplay" - }; - defaultList.Add(upgrade); - } - - } - - - - - } - catch { } - } - } - return defaultList; - } - } - - public class WinformsFSFrontend : IFileSkimmer - { - - - public void OpenDirectory(string path) - { - var fs = new Applications.FileSkimmer(); - AppearanceManager.SetupWindow(fs); - fs.ChangeDirectory(path); - } - - public void GetPath(string[] filetypes, FileOpenerStyle style, Action callback) - { - AppearanceManager.SetupDialog(new Applications.FileDialog(filetypes, style, callback)); - } - - public void OpenFile(string path) - { - try - { - switch (FileSkimmerBackend.GetFileType(path)) - { - case FileType.TextFile: - if (!Shiftorium.UpgradeInstalled("textpad")) - throw new Exception(); - - var txt = new TextPad(); - AppearanceManager.SetupWindow(txt); - txt.LoadFile(path); - break; - case FileType.Executable: - //NYI - throw new Exception(); - case FileType.Lua: - try - { - var runner = new Engine.Scripting.LuaInterpreter(); - runner.ExecuteFile(path); - } - catch (Exception ex) - { - Infobox.Show("{LUA_ERROR}", ex.Message); - } - break; - case FileType.JSON: - //NYI - throw new Exception(); - case FileType.Filesystem: - MountPersistent(path); - //If this doesn't fail... - FileSkimmerBackend.OpenDirectory((Mounts.Count - 1).ToString() + ":"); - break; - case FileType.Skin: - if (!Shiftorium.UpgradeInstalled("skinning")) - throw new Exception(); - - var sl = new Skin_Loader(); - AppearanceManager.SetupWindow(sl); - sl.LoadedSkin = JsonConvert.DeserializeObject(ReadAllText(path)); - sl.SetupUI(); - break; - case FileType.Image: - if (!Shiftorium.UpgradeInstalled("artpad_open")) - throw new Exception(); - - var ap = new Artpad(); - AppearanceManager.SetupWindow(ap); - ap.LoadPicture(path); - break; - default: - throw new Exception(); - - } - } - catch - { - Infobox.Show("{NO_APP_TO_OPEN}", "{NO_APP_TO_OPEN_EXP}"); - } - - } - - public Image GetImage(string path) - { - return Applications.FileSkimmer.GetImage(FileSkimmerBackend.GetFileType(path)); - } - - public string GetFileExtension(FileType fileType) - { - switch (fileType) - { - case FileType.Executable: - return ".saa"; - case FileType.Filesystem: - return ".mfs"; - case FileType.Image: - return ".pic"; - case FileType.JSON: - return ".json"; - case FileType.Lua: - return ".lua"; - case FileType.Python: - return ".py"; - case FileType.Skin: - return ".skn"; - case FileType.TextFile: - return ".txt"; - default: - return ".bin"; - - } - } - } -} diff --git a/ShiftOS.WinForms/Properties/Resources.Designer.cs b/ShiftOS.WinForms/Properties/Resources.Designer.cs deleted file mode 100644 index caaf503..0000000 --- a/ShiftOS.WinForms/Properties/Resources.Designer.cs +++ /dev/null @@ -1,1394 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace ShiftOS.WinForms.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShiftOS.WinForms.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized resource of type System.IO.UnmanagedMemoryStream similar to System.IO.MemoryStream. - /// - internal static System.IO.UnmanagedMemoryStream _3beepvirus { - get { - return ResourceManager.GetStream("_3beepvirus", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadcirclerubber { - get { - object obj = ResourceManager.GetObject("ArtPadcirclerubber", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadcirclerubberselected { - get { - object obj = ResourceManager.GetObject("ArtPadcirclerubberselected", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPaderacer { - get { - object obj = ResourceManager.GetObject("ArtPaderacer", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadfloodfill { - get { - object obj = ResourceManager.GetObject("ArtPadfloodfill", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadlinetool { - get { - object obj = ResourceManager.GetObject("ArtPadlinetool", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadmagnify { - get { - object obj = ResourceManager.GetObject("ArtPadmagnify", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadnew { - get { - object obj = ResourceManager.GetObject("ArtPadnew", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadopen { - get { - object obj = ResourceManager.GetObject("ArtPadopen", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadOval { - get { - object obj = ResourceManager.GetObject("ArtPadOval", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadpaintbrush { - get { - object obj = ResourceManager.GetObject("ArtPadpaintbrush", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadpencil { - get { - object obj = ResourceManager.GetObject("ArtPadpencil", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadpixelplacer { - get { - object obj = ResourceManager.GetObject("ArtPadpixelplacer", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadRectangle { - get { - object obj = ResourceManager.GetObject("ArtPadRectangle", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadredo { - get { - object obj = ResourceManager.GetObject("ArtPadredo", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadsave { - get { - object obj = ResourceManager.GetObject("ArtPadsave", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadsquarerubber { - get { - object obj = ResourceManager.GetObject("ArtPadsquarerubber", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadsquarerubberselected { - get { - object obj = ResourceManager.GetObject("ArtPadsquarerubberselected", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadtexttool { - get { - object obj = ResourceManager.GetObject("ArtPadtexttool", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap ArtPadundo { - get { - object obj = ResourceManager.GetObject("ArtPadundo", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap DefaultMouse { - get { - object obj = ResourceManager.GetObject("DefaultMouse", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.IO.UnmanagedMemoryStream similar to System.IO.MemoryStream. - /// - internal static System.IO.UnmanagedMemoryStream dial_up_modem_02 { - get { - return ResourceManager.GetStream("dial_up_modem_02", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon0 { - get { - object obj = ResourceManager.GetObject("fileicon0", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon1 { - get { - object obj = ResourceManager.GetObject("fileicon1", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon10 { - get { - object obj = ResourceManager.GetObject("fileicon10", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon11 { - get { - object obj = ResourceManager.GetObject("fileicon11", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon12 { - get { - object obj = ResourceManager.GetObject("fileicon12", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon13 { - get { - object obj = ResourceManager.GetObject("fileicon13", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon14 { - get { - object obj = ResourceManager.GetObject("fileicon14", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon15 { - get { - object obj = ResourceManager.GetObject("fileicon15", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon16 { - get { - object obj = ResourceManager.GetObject("fileicon16", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon17 { - get { - object obj = ResourceManager.GetObject("fileicon17", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon18 { - get { - object obj = ResourceManager.GetObject("fileicon18", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon19 { - get { - object obj = ResourceManager.GetObject("fileicon19", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon2 { - get { - object obj = ResourceManager.GetObject("fileicon2", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon3 { - get { - object obj = ResourceManager.GetObject("fileicon3", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon4 { - get { - object obj = ResourceManager.GetObject("fileicon4", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon5 { - get { - object obj = ResourceManager.GetObject("fileicon5", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon6 { - get { - object obj = ResourceManager.GetObject("fileicon6", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon7 { - get { - object obj = ResourceManager.GetObject("fileicon7", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon8 { - get { - object obj = ResourceManager.GetObject("fileicon8", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileicon9 { - get { - object obj = ResourceManager.GetObject("fileicon9", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileiconcf { - get { - object obj = ResourceManager.GetObject("fileiconcf", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap fileiconsaa { - get { - object obj = ResourceManager.GetObject("fileiconsaa", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap FloppyDriveIcon { - get { - object obj = ResourceManager.GetObject("FloppyDriveIcon", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized string similar to . - /// - internal static string hello { - get { - return ResourceManager.GetString("hello", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconArtpad { - get { - object obj = ResourceManager.GetObject("iconArtpad", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconAudioPlayer { - get { - object obj = ResourceManager.GetObject("iconAudioPlayer", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconBitnoteDigger { - get { - object obj = ResourceManager.GetObject("iconBitnoteDigger", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconBitnoteWallet { - get { - object obj = ResourceManager.GetObject("iconBitnoteWallet", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconCalculator { - get { - object obj = ResourceManager.GetObject("iconCalculator", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconClock { - get { - object obj = ResourceManager.GetObject("iconClock", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconColourPicker_fw { - get { - object obj = ResourceManager.GetObject("iconColourPicker_fw", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconDodge { - get { - object obj = ResourceManager.GetObject("iconDodge", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconDownloader { - get { - object obj = ResourceManager.GetObject("iconDownloader", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconFileOpener_fw { - get { - object obj = ResourceManager.GetObject("iconFileOpener_fw", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconFileSaver_fw { - get { - object obj = ResourceManager.GetObject("iconFileSaver_fw", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconFileSkimmer { - get { - object obj = ResourceManager.GetObject("iconFileSkimmer", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconfloodgate { - get { - object obj = ResourceManager.GetObject("iconfloodgate", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconFormatEditor { - get { - object obj = ResourceManager.GetObject("iconFormatEditor", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap icongraphicpicker { - get { - object obj = ResourceManager.GetObject("icongraphicpicker", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconIconManager { - get { - object obj = ResourceManager.GetObject("iconIconManager", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconInfoBox_fw { - get { - object obj = ResourceManager.GetObject("iconInfoBox_fw", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconKnowledgeInput { - get { - object obj = ResourceManager.GetObject("iconKnowledgeInput", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconmaze { - get { - object obj = ResourceManager.GetObject("iconmaze", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconNameChanger { - get { - object obj = ResourceManager.GetObject("iconNameChanger", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconoctocat { - get { - object obj = ResourceManager.GetObject("iconoctocat", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconorcwrite { - get { - object obj = ResourceManager.GetObject("iconorcwrite", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconPong { - get { - object obj = ResourceManager.GetObject("iconPong", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconShifter { - get { - object obj = ResourceManager.GetObject("iconShifter", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconShiftLetters { - get { - object obj = ResourceManager.GetObject("iconShiftLetters", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconShiftLotto { - get { - object obj = ResourceManager.GetObject("iconShiftLotto", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconShiftnet { - get { - object obj = ResourceManager.GetObject("iconShiftnet", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconShiftorium { - get { - object obj = ResourceManager.GetObject("iconShiftorium", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconShiftSweeper { - get { - object obj = ResourceManager.GetObject("iconShiftSweeper", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconshutdown { - get { - object obj = ResourceManager.GetObject("iconshutdown", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconshutdown1 { - get { - object obj = ResourceManager.GetObject("iconshutdown1", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconSkinLoader { - get { - object obj = ResourceManager.GetObject("iconSkinLoader", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconSkinShifter { - get { - object obj = ResourceManager.GetObject("iconSkinShifter", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconSnakey { - get { - object obj = ResourceManager.GetObject("iconSnakey", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconSysinfo { - get { - object obj = ResourceManager.GetObject("iconSysinfo", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconTerminal { - get { - object obj = ResourceManager.GetObject("iconTerminal", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconTextPad { - get { - object obj = ResourceManager.GetObject("iconTextPad", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconunitytoggle { - get { - object obj = ResourceManager.GetObject("iconunitytoggle", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconVideoPlayer { - get { - object obj = ResourceManager.GetObject("iconVideoPlayer", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconvirusscanner { - get { - object obj = ResourceManager.GetObject("iconvirusscanner", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap iconWebBrowser { - get { - object obj = ResourceManager.GetObject("iconWebBrowser", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.IO.UnmanagedMemoryStream similar to System.IO.MemoryStream. - /// - internal static System.IO.UnmanagedMemoryStream infobox { - get { - return ResourceManager.GetStream("infobox", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap justthes { - get { - object obj = ResourceManager.GetObject("justthes", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized string similar to [ - /// "english" - /// "deutsch" - ///]. - /// - internal static string languages { - get { - return ResourceManager.GetString("languages", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap RegularDesktopGlyph { - get { - object obj = ResourceManager.GetObject("RegularDesktopGlyph", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized string similar to [ - /// { - /// Name: "Freebie Solutions", - /// DownloadSpeed: 256, - /// CostPerMonth: 0, - /// Description: "The Shiftnet is a wonderful place full of apps, games, websites and skins for ShiftOS. - /// - ///With Freebie Solutions from ShiftSoft, you'll be able to traverse the Shiftnet without any worry about monthly fees.", - /// Company: "ShiftSoft" - /// }, - /// { - /// Company: "Shiftcast", - /// Name: "NetXtreme Hyper Edition", - /// CostPerMonth: 1500, - /// DownloadSpeed: 524288, //512 kb/s - /// Description: "It's time to supercharge your Shif [rest of string was truncated]";. - /// - internal static string ShiftnetServices { - get { - return ResourceManager.GetString("ShiftnetServices", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to [ - /// //TEMPORARY - /// { - /// Name: "Desktop Widgets", - /// Cost: 0, - /// Description: "Temporary upgrade. Will be replaced by either a Shiftnet app or a story element.", - /// Dependencies: "advanced_app_launcher;wm_free_placement", - /// Category: "Work-in-progress" - /// }, - /// - /// - /// - ///// SCREENSAVER - /// { - /// Name: "Screensavers", - /// Cost: 750, - /// Description: "Like to leave your PC idle for long periods of time? Save some energy and keep your screen from being tired by hiding the desktop behind a black screen with an image on it." [rest of string was truncated]";. - /// - internal static string Shiftorium { - get { - return ResourceManager.GetString("Shiftorium", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to {\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} - ///{\f37\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\f38\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0302020204030204}Calibri Light;}{\fl [rest of string was truncated]";. - /// - internal static string ShiftOS { - get { - return ResourceManager.GetString("ShiftOS", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyBG { - get { - object obj = ResourceManager.GetObject("SnakeyBG", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyBody { - get { - object obj = ResourceManager.GetObject("SnakeyBody", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyFruit { - get { - object obj = ResourceManager.GetObject("SnakeyFruit", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyHeadD { - get { - object obj = ResourceManager.GetObject("SnakeyHeadD", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyHeadL { - get { - object obj = ResourceManager.GetObject("SnakeyHeadL", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyHeadR { - get { - object obj = ResourceManager.GetObject("SnakeyHeadR", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyHeadU { - get { - object obj = ResourceManager.GetObject("SnakeyHeadU", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyTailD { - get { - object obj = ResourceManager.GetObject("SnakeyTailD", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyTailL { - get { - object obj = ResourceManager.GetObject("SnakeyTailL", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyTailR { - get { - object obj = ResourceManager.GetObject("SnakeyTailR", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SnakeyTailU { - get { - object obj = ResourceManager.GetObject("SnakeyTailU", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized string similar to [ - /// "http://downloads.michaeltheshifter.me/music/blockride.mp3", - /// "http://downloads.michaeltheshifter.me/music/nightcoding.mp3" - ///]. - /// - internal static string Songs { - get { - return ResourceManager.GetString("Songs", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to { - /// "{SUBMIT}":"Bestätigen", - /// - ///"{TERMINAL_TUTORIAL_1}":"Wilkommen zum ShiftOS Terminal. Hier wirst du die meiste Zeit in ShiftOS verbringen. - /// - ///Eine kurze Erklärung wie du das Terminal benutzt lautet wiefolgt. Du kannst das command 'sos.help' benutzen um eine Liste aller commands aufzurufen. Schreib es - ///einfach in das Terminal und drücke <enter> um alle commands anzuzeigen. - /// - ///Commands können mit argumenten versehen werden, indem du ein key-value Paar in einem {} Block hinter dem command angibst. Zum Be [rest of string was truncated]";. - /// - internal static string strings_de { - get { - return ResourceManager.GetString("strings_de", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to { - /// "{SUBMIT}":"Submit", - /// - ///"{TERMINAL_TUTORIAL_1}":"Welcome to the ShiftOS terminal. This is where you will spend the bulk of your time within ShiftOS. - /// - ///A brief rundown of how to use the terminal is as follows. You can use the 'sos.help' command to show a list of all commands. Simply type it in and strike <enter> to view all commands. - /// - ///Commands can be sent arguments by specifying a key-value pair inside a {} block at the end of the command. For example: - /// - ///some.command{print:\"hello\"} - ///math.add{op1 [rest of string was truncated]";. - /// - internal static string strings_en { - get { - return ResourceManager.GetString("strings_en", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SuperDesk_screenshot { - get { - object obj = ResourceManager.GetObject("SuperDesk screenshot", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperClickFace { - get { - object obj = ResourceManager.GetObject("SweeperClickFace", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperLoseFace { - get { - object obj = ResourceManager.GetObject("SweeperLoseFace", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperNormalFace { - get { - object obj = ResourceManager.GetObject("SweeperNormalFace", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTile0 { - get { - object obj = ResourceManager.GetObject("SweeperTile0", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTile1 { - get { - object obj = ResourceManager.GetObject("SweeperTile1", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTile2 { - get { - object obj = ResourceManager.GetObject("SweeperTile2", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTile3 { - get { - object obj = ResourceManager.GetObject("SweeperTile3", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTile4 { - get { - object obj = ResourceManager.GetObject("SweeperTile4", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTile5 { - get { - object obj = ResourceManager.GetObject("SweeperTile5", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTile6 { - get { - object obj = ResourceManager.GetObject("SweeperTile6", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTile7 { - get { - object obj = ResourceManager.GetObject("SweeperTile7", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTile8 { - get { - object obj = ResourceManager.GetObject("SweeperTile8", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTileBlock { - get { - object obj = ResourceManager.GetObject("SweeperTileBlock", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTileBomb { - get { - object obj = ResourceManager.GetObject("SweeperTileBomb", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperTileFlag { - get { - object obj = ResourceManager.GetObject("SweeperTileFlag", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap SweeperWinFace { - get { - object obj = ResourceManager.GetObject("SweeperWinFace", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized string similar to { - /// Character: "sys", - /// Lines:[ - /// "Hello there, %user.", - /// "Welcome to ShiftOS.", - /// "This is an automated message to all new sentiences within the ShiftOS multi-user domain.", - /// "Before you can begin with ShiftOS, you'll need to know a few things about it.", - /// "One: Terminal command syntax.", - /// "Inside ShiftOS, the bulk of your time is going to be spent within the Terminal.", - /// "The Terminal is an application that starts up when you turn on your computer. It allows you to execute system commands, ope [rest of string was truncated]";. - /// - internal static string sys_shiftoriumstory { - get { - return ResourceManager.GetString("sys_shiftoriumstory", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.IO.UnmanagedMemoryStream similar to System.IO.MemoryStream. - /// - internal static System.IO.UnmanagedMemoryStream typesound { - get { - return ResourceManager.GetStream("typesound", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.IO.UnmanagedMemoryStream similar to System.IO.MemoryStream. - /// - internal static System.IO.UnmanagedMemoryStream writesound { - get { - return ResourceManager.GetStream("writesound", resourceCulture); - } - } - } -} diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs deleted file mode 100644 index 3d66b2b..0000000 --- a/ShiftOS.WinForms/Tools/ControlManager.cs +++ /dev/null @@ -1,300 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.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; -using static ShiftOS.Engine.AppearanceManager; - - -namespace ShiftOS.WinForms.Tools -{ - public static class ControlManager - { - [DllImport("user32.dll")] - public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam); - - private const int WM_SETREDRAW = 11; - - public static void SuspendDrawing(Control parent) - { - SendMessage(parent.Handle, WM_SETREDRAW, false, 0); - } - - public static void ResumeDrawing(Control parent) - { - SendMessage(parent.Handle, WM_SETREDRAW, true, 0); - parent.Refresh(); - } - - public static void Close(this UserControl ctrl) - { - for (int i = 0; i < AppearanceManager.OpenForms.Count; i++) - { - if (OpenForms[i].ParentWindow == ctrl) - { - (OpenForms[i] as Form).Close(); - return; - } - } - } - - - 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 - if (!(ctrl is WebBrowser)) - { - var mouse = SkinEngine.GetImage("mouse"); - if (mouse == null) - mouse = Properties.Resources.DefaultMouse; - - var mBmp = new Bitmap(mouse); - mBmp.MakeTransparent(Color.FromArgb(1, 0, 1)); - var gfx = Graphics.FromImage(mBmp); - var handle = mBmp.GetHicon(); - - var cursor = new Cursor(handle); - ctrl.Cursor = cursor; - } -#endif - } - - /// - /// Centers the control along its parent. - /// - /// The control to center (this is an extension method - you can call it on a control as though it was a method in that control) - public static void CenterParent(this Control ctrl) - { - ctrl.Location = new Point( - (ctrl.Parent.Width - ctrl.Width) / 2, - (ctrl.Parent.Height - ctrl.Height) / 2 - ); - } - - public static void SetupControl(Control ctrl) - { - Desktop.InvokeOnWorkerThread(new Action(() => - { - ctrl.SuspendLayout(); - })); - if (!(ctrl is MenuStrip) && !(ctrl is ToolStrip) && !(ctrl is StatusStrip) && !(ctrl is ContextMenuStrip)) - { - string tag = ""; - - try - { - if(ctrl.Tag != null) - tag = ctrl.Tag.ToString(); - } - catch { } - - if (!tag.Contains("keepbg")) - { - if (ctrl.BackColor != Control.DefaultBackColor) - { - Desktop.InvokeOnWorkerThread(() => - { - ctrl.BackColor = SkinEngine.LoadedSkin.ControlColor; - }); - } - } - - if (!tag.Contains("keepfont")) - { - 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")) - { - Desktop.InvokeOnWorkerThread(() => - { - ctrl.Font = SkinEngine.LoadedSkin.Header2Font; - }); - } - - if (tag.Contains("header3")) - { - Desktop.InvokeOnWorkerThread(() => - { - - ctrl.Font = SkinEngine.LoadedSkin.Header3Font; - }); - } - } - try - { - string ctrlText = Localization.Parse(ctrl.Text); - Desktop.InvokeOnWorkerThread(() => - { - ctrl.Text = ctrlText; - }); - } - catch - { - - } - ctrl.KeyDown += (o, a) => - { - if (a.Control && a.KeyCode == Keys.T) - { - a.SuppressKeyPress = true; - - - Engine.AppearanceManager.SetupWindow(new Applications.Terminal()); - } - - ShiftOS.Engine.Scripting.LuaInterpreter.RaiseEvent("on_key_down", a); - //a.Handled = true; - }; - if (ctrl is Button) - { - Desktop.InvokeOnWorkerThread(() => - { - (ctrl as Button).FlatStyle = FlatStyle.Flat; - }); - } - else if (ctrl is WindowBorder) - { - Desktop.InvokeOnWorkerThread(() => - { - (ctrl as WindowBorder).Setup(); - }); - } - } - Desktop.InvokeOnWorkerThread(() => - { - - MakeDoubleBuffered(ctrl); - ctrl.ResumeLayout(); - }); - ControlSetup?.Invoke(ctrl); - } - - public static event Action ControlSetup; - - public static void MakeDoubleBuffered(Control c) - { - if (System.Windows.Forms.SystemInformation.TerminalServerSession) - return; - - System.Reflection.PropertyInfo aProp = - typeof(System.Windows.Forms.Control).GetProperty( - "DoubleBuffered", - System.Reflection.BindingFlags.NonPublic | - System.Reflection.BindingFlags.Instance); - - aProp.SetValue(c, true, null); - - } - - public static void SetupControls(Control frm, bool runInThread = true) - { - SetupControl(frm); - frm.Click += (o, a) => - { - Desktop.HideAppLauncher(); - }; - ThreadStart ts = () => - { - for (int i = 0; i < frm.Controls.Count; i++) - { - SetupControls(frm.Controls[i], false); - } - - }; - - if (runInThread == true) - { - var t = new Thread(ts); - t.IsBackground = true; - t.Start(); - } - else - { - ts?.Invoke(); - } - } - - } -} diff --git a/ShiftOS.WinForms/Tools/DitheringEngine.cs b/ShiftOS.WinForms/Tools/DitheringEngine.cs deleted file mode 100644 index 8509a0b..0000000 --- a/ShiftOS.WinForms/Tools/DitheringEngine.cs +++ /dev/null @@ -1,402 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define FLOYDSTEINBERG - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Drawing; -using System.Threading; -using ShiftOS.Engine; -using System.Runtime.InteropServices; - -namespace ShiftOS.WinForms.Tools -{ - public static class DitheringEngine - { - public static Color GetColor(Color source) - { - if (Shiftorium.UpgradeInstalled("color_depth_24_bits")) - { - return Color.FromArgb(source.R, source.G, source.B); //get rid of the alpha channel. - } - else - { - if (Shiftorium.UpgradeInstalled("color_depth_16_bits")) - { - byte r = (byte)linear(source.R, 0, 0xFF, 0, 0x1F); - byte g = (byte)linear(source.G, 0, 0xFF, 0, 0x3F); - byte b = (byte)linear(source.B, 0, 0xFF, 0, 0x1F); - - return Color.FromArgb(r, g, b); - } - else - { - int gray = (source.R + source.G + source.B) / 3; - - if (Shiftorium.UpgradeInstalled("color_depth_8_bits")) - return Color.FromArgb(gray, gray, gray); - else - { - if (Shiftorium.UpgradeInstalled("color_depth_6_bits")) - { - int gray6 = (int)linear(gray, 0, 0xFF, 0, 0x3F) * 3; - - - - return Color.FromArgb(gray6, gray6, gray6); - } - else - { - if (Shiftorium.UpgradeInstalled("color_depth_4_bits")) - { - int gray4 = (int)linear(linear(gray, 0, 0xFF, 0, 0xF), 0, 0xF, 0, 0xFF) * 0xF; - return Color.FromArgb(gray4, gray4, gray4); - } - else - { - if (Shiftorium.UpgradeInstalled("color_depth_2_bits")) - { - int gray2 = (int)linear(linear(gray, 0, 0xFF, 0, 0x3), 0, 0x3, 0, 0xFF) * 63; - return Color.FromArgb(gray2, gray2, gray2); - } - else { - if (gray >= 127) - { - return Color.Black; - } - else - { - return Color.White; - } - } - } - } - } - } - } - } - - public static void DitherColor(Color source, int width, int height, Action result) - { - var bmp = new Bitmap(width + 1, height + 1); - var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); - byte[] rgb = new byte[Math.Abs(data.Stride) * data.Height]; - Marshal.Copy(data.Scan0, rgb, 0, rgb.Length); - for (int i = 0; i < rgb.Length - 3; i += 3) - { - rgb[i] = source.R; - rgb[i + 1] = source.G; - rgb[i + 2] = source.B; - } - Marshal.Copy(rgb, 0, data.Scan0, rgb.Length); - bmp.UnlockBits(data); - DitherImage(bmp, result); - - } - - static private double linear(double x, double x0, double x1, double y0, double y1) - { - if ((x1 - x0) == 0) - { - return (y0 + y1) / 2; - } - return y0 + (x - x0) * (y1 - y0) / (x1 - x0); - } - -#if NODITHER - public static void DitherImage(Image source, Action result) - { - Desktop.InvokeOnWorkerThread(new Action(() => - { - result?.Invoke(source); - })); - } -#endif - -#if BINARIZE - public static void DitherImage(Image source, Action result) - { - if (source == null) - { - result?.Invoke(source); - return; - } - - - var t = new Thread(new ThreadStart(() => - { - var bmp = new Bitmap(source.Width, source.Height); - var sourceBmp = (Bitmap)source; - int error = 0; - for (int y = 0; y < bmp.Height; y++) - { - for (int x = 0; x < bmp.Width; x++) - { - - Color c = sourceBmp.GetPixel(x, y); - int gray = ((c.R + c.G + c.B) / 3); - if (gray >= 127) - { - error = gray - 255; - bmp.SetPixel(x, y, Color.White); - } - else - { - error = gray; - bmp.SetPixel(x, y, Color.Black); - } - - - } - } - Desktop.InvokeOnWorkerThread(new Action(() => { result?.Invoke(bmp); })); - })); - t.IsBackground = true; - t.Start(); - - } -#endif - -#if DITHER1D - public static void DitherImage(Image source, Action result) - { - if (source == null) - { - result?.Invoke(source); - return; - } - - - var t = new Thread(new ThreadStart(() => - { - var bmp = new Bitmap(source.Width, source.Height); - var sourceBmp = (Bitmap)source; - int error = 0; - for (int y = 0; y < bmp.Height; y++) - { - for (int x = 0; x < bmp.Width; x++) - { - - Color c = sourceBmp.GetPixel(x, y); - int gray = ((c.R + c.G + c.B) / 3) + error; - if (gray >= 127) - { - error = gray - 255; - bmp.SetPixel(x, y, Color.White); - } - else - { - error = gray; - bmp.SetPixel(x, y, Color.Black); - } - - - } - } - Desktop.InvokeOnWorkerThread(new Action(() => { result?.Invoke(bmp); })); - })); - t.IsBackground = true; - t.Start(); - } -#endif - -#if FLOYDSTEINBERG - public static void DitherImage(Image source, Action result) - { - if (source == null) - { - result?.Invoke(source); - return; - } - - - var bmp = new Bitmap(source.Width, source.Height); - var sourceBmp = (Bitmap)source; - var sourceLck = sourceBmp.LockBits(new Rectangle(0, 0, sourceBmp.Width, sourceBmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); - var destLck = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); - int error_r = 0; - - - int sourceBytes = Math.Abs(sourceLck.Stride) * sourceLck.Height; - int destBytes = Math.Abs(destLck.Stride) * destLck.Height; - - IntPtr sourcePtr = sourceLck.Scan0; - IntPtr destPtr = destLck.Scan0; - - byte[] destArr = new byte[destBytes]; - byte[] sourceArr = new byte[sourceBytes]; - - byte[] grays = new byte[destBytes]; - - Marshal.Copy(sourcePtr, sourceArr, 0, sourceBytes); - Marshal.Copy(destPtr, destArr, 0, destBytes); - - int width = Math.Abs(destLck.Stride); - int height = destLck.Height; - - bool sixteenBits = Shiftorium.UpgradeInstalled("color_depth_16_bits"); - bool twoBits = Shiftorium.UpgradeInstalled("color_depth_2_bits"); - bool sixBits = Shiftorium.UpgradeInstalled("color_depth_6_bits"); - bool fourBits = Shiftorium.UpgradeInstalled("color_depth_4_bits"); - bool eightBits = Shiftorium.UpgradeInstalled("color_depth_8_bits"); - bool color_depth_floydsteinberg = Shiftorium.UpgradeInstalled("color_depth_floyd-steinberg_dithering"); - bool dithering = Shiftorium.UpgradeInstalled("color_depth_dithering"); - - for (int y = 0; y < (destLck.Height); y++) - { - for (int x = 0; x < (Math.Abs(destLck.Stride)); x += 3) - { - int i = getIndexFromXY(x, y, width); - byte red = sourceArr[i]; - byte green = sourceArr[i + 1]; - byte blue = sourceArr[i + 2]; - - Color oldc = Color.FromArgb(red, green, blue); - Color newc; - - if (sixteenBits) - { - newc = GetColor(oldc); - } - else - { - int gray = ((oldc.R + oldc.G + oldc.B) / 3); - - byte newgray = 0; - - if (dithering && !color_depth_floydsteinberg) - gray += error_r; - - - - if (eightBits) - { - newgray = (byte)gray; - error_r = 0; - } - else if(sixBits) - { - newgray = (byte)(linear(gray, 0, 0xFF, 0, 0x3F) * 3); - error_r = newgray - gray; - } - else if (fourBits) - { - newgray = (byte)(linear(gray, 0, 0xFF, 0, 0xF) * 0xF); - error_r = newgray - gray; - } - else if (twoBits) - { - if (gray >= 191) - newgray = 0xFF; - else if (gray >= 127) - newgray = Color.LightGray.R; - else if (gray >= 64) - newgray = Color.DarkGray.R; - else - newgray = 0x00; - error_r = newgray - gray; - } - else - { - if (gray >= 127) - newgray = 0xFF; - else - newgray = 0x00; - error_r = newgray - gray; - } - newc = Color.FromArgb(newgray, newgray, newgray); - } - - int nextIndex = getIndexFromXY(x + 3, y, width); - int nextRow = getIndexFromXY(x, y + 1, width); - int nextIndexOnNextRow = getIndexFromXY(x + 3, y + 1, width); - int prevIndexOnNextRow = getIndexFromXY(x - 3, y + 1, width); - - grays[i] = newc.R; - grays[i + 1] = newc.G; - grays[i + 2] = newc.B; - - if (dithering) - { - if (color_depth_floydsteinberg) - { - if (x + 3 < width) - { - sourceArr[nextIndex] += (byte)((error_r * 7) / 16); - sourceArr[nextIndex + 1] += (byte)((error_r * 7) / 16); - sourceArr[nextIndex + 2] += (byte)((error_r * 7) / 16); - } - if (y + 1 < height) - { - sourceArr[nextRow] += (byte)((error_r) / 16); - sourceArr[nextRow + 1] += (byte)((error_r) / 16); - sourceArr[nextRow + 2] += (byte)((error_r) / 16); - } - if (x + 3 < width && y + 1 < height) - { - sourceArr[nextIndexOnNextRow] += (byte)((error_r * 3) / 16); - sourceArr[nextIndexOnNextRow + 1] += (byte)((error_r * 3) / 16); - sourceArr[nextIndexOnNextRow + 2] += (byte)((error_r * 3) / 16); - - } - if (x - 3 > 0 && y + 1 < height) - { - sourceArr[prevIndexOnNextRow] += (byte)((error_r * 5) / 16); - sourceArr[prevIndexOnNextRow + 1] += (byte)((error_r * 5) / 16); - sourceArr[prevIndexOnNextRow + 2] += (byte)((error_r * 5) / 16); - - } - } - } - } - } - - for (int i = 0; i < destArr.Length - 3; i++) - { - destArr[i] = grays[i]; - - } - - Marshal.Copy(destArr, 0, destPtr, destBytes); - - - bmp.UnlockBits(destLck); - - - - Desktop.InvokeOnWorkerThread(new Action(() => { result?.Invoke(bmp); })); - - } -#endif - - private static int getIndexFromXY(int x, int y, int width) - { - return (width * y) + x; - } - } -} diff --git a/ShiftOS.WinForms/WinformsDesktop.Designer.cs b/ShiftOS.WinForms/WinformsDesktop.Designer.cs deleted file mode 100644 index 71ef161..0000000 --- a/ShiftOS.WinForms/WinformsDesktop.Designer.cs +++ /dev/null @@ -1,312 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -namespace ShiftOS.WinForms -{ - partial class WinformsDesktop - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.desktoppanel = new System.Windows.Forms.Panel(); - this.btnnotifications = new System.Windows.Forms.Button(); - this.lbtime = new System.Windows.Forms.Label(); - this.panelbuttonholder = new System.Windows.Forms.FlowLayoutPanel(); - this.sysmenuholder = new System.Windows.Forms.Panel(); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.apps = new System.Windows.Forms.ToolStripMenuItem(); - this.pnlscreensaver = new System.Windows.Forms.Panel(); - this.pnlwidgetlayer = new System.Windows.Forms.Panel(); - this.pnlssicon = new System.Windows.Forms.Panel(); - this.pnladvancedal = new System.Windows.Forms.Panel(); - this.flapps = new System.Windows.Forms.FlowLayoutPanel(); - this.flcategories = new System.Windows.Forms.FlowLayoutPanel(); - this.pnlalsystemactions = new System.Windows.Forms.Panel(); - this.btnshutdown = new System.Windows.Forms.Button(); - this.pnlstatus = new System.Windows.Forms.Panel(); - this.lbalstatus = new System.Windows.Forms.Label(); - this.desktoppanel.SuspendLayout(); - this.sysmenuholder.SuspendLayout(); - this.menuStrip1.SuspendLayout(); - this.pnlscreensaver.SuspendLayout(); - this.pnladvancedal.SuspendLayout(); - this.pnlalsystemactions.SuspendLayout(); - this.pnlstatus.SuspendLayout(); - this.SuspendLayout(); - // - // desktoppanel - // - this.desktoppanel.BackColor = System.Drawing.Color.Green; - this.desktoppanel.Controls.Add(this.btnnotifications); - this.desktoppanel.Controls.Add(this.lbtime); - this.desktoppanel.Controls.Add(this.panelbuttonholder); - this.desktoppanel.Controls.Add(this.sysmenuholder); - this.desktoppanel.Dock = System.Windows.Forms.DockStyle.Top; - this.desktoppanel.Location = new System.Drawing.Point(0, 0); - this.desktoppanel.Name = "desktoppanel"; - this.desktoppanel.Size = new System.Drawing.Size(1296, 24); - this.desktoppanel.TabIndex = 0; - this.desktoppanel.Paint += new System.Windows.Forms.PaintEventHandler(this.desktoppanel_Paint); - // - // btnnotifications - // - this.btnnotifications.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnnotifications.AutoSize = true; - this.btnnotifications.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.btnnotifications.BackColor = System.Drawing.Color.Transparent; - this.btnnotifications.FlatAppearance.BorderSize = 0; - this.btnnotifications.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnnotifications.Location = new System.Drawing.Point(1066, -2); - this.btnnotifications.Name = "btnnotifications"; - this.btnnotifications.Size = new System.Drawing.Size(136, 24); - this.btnnotifications.TabIndex = 3; - this.btnnotifications.Text = "Notifications (0)"; - this.btnnotifications.UseVisualStyleBackColor = false; - this.btnnotifications.Click += new System.EventHandler(this.btnnotifications_Click); - // - // lbtime - // - this.lbtime.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Right))); - this.lbtime.AutoSize = true; - this.lbtime.Location = new System.Drawing.Point(3, 0); - this.lbtime.Name = "lbtime"; - this.lbtime.Size = new System.Drawing.Size(49, 14); - this.lbtime.TabIndex = 0; - this.lbtime.Text = "label1"; - this.lbtime.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - this.lbtime.Click += new System.EventHandler(this.lbtime_Click); - // - // panelbuttonholder - // - this.panelbuttonholder.AutoSize = true; - this.panelbuttonholder.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.panelbuttonholder.Location = new System.Drawing.Point(107, -77); - this.panelbuttonholder.Name = "panelbuttonholder"; - this.panelbuttonholder.Size = new System.Drawing.Size(0, 0); - this.panelbuttonholder.TabIndex = 2; - // - // sysmenuholder - // - this.sysmenuholder.Controls.Add(this.menuStrip1); - this.sysmenuholder.Location = new System.Drawing.Point(12, 5); - this.sysmenuholder.Name = "sysmenuholder"; - this.sysmenuholder.Size = new System.Drawing.Size(68, 24); - this.sysmenuholder.TabIndex = 1; - // - // menuStrip1 - // - this.menuStrip1.Dock = System.Windows.Forms.DockStyle.Fill; - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.apps}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Padding = new System.Windows.Forms.Padding(0); - this.menuStrip1.Size = new System.Drawing.Size(68, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; - // - // apps - // - this.apps.AutoSize = false; - this.apps.Name = "apps"; - this.apps.Padding = new System.Windows.Forms.Padding(0); - this.apps.Size = new System.Drawing.Size(58, 20); - this.apps.Tag = "applauncherbutton"; - this.apps.Text = "ShiftOS"; - this.apps.Click += new System.EventHandler(this.apps_Click); - // - // pnlscreensaver - // - this.pnlscreensaver.Controls.Add(this.pnlssicon); - this.pnlscreensaver.Dock = System.Windows.Forms.DockStyle.Fill; - this.pnlscreensaver.Location = new System.Drawing.Point(0, 24); - this.pnlscreensaver.Name = "pnlscreensaver"; - this.pnlscreensaver.Size = new System.Drawing.Size(1296, 714); - this.pnlscreensaver.TabIndex = 1; - this.pnlscreensaver.Visible = false; - // - // pnlwidgetlayer - // - this.pnlwidgetlayer.BackColor = System.Drawing.Color.Transparent; - this.pnlwidgetlayer.Dock = System.Windows.Forms.DockStyle.Fill; - this.pnlwidgetlayer.Location = new System.Drawing.Point(0, 24); - this.pnlwidgetlayer.Name = "pnlwidgetlayer"; - this.pnlwidgetlayer.Size = new System.Drawing.Size(1296, 714); - this.pnlwidgetlayer.TabIndex = 1; - // - // pnlssicon - // - this.pnlssicon.Location = new System.Drawing.Point(303, 495); - this.pnlssicon.Name = "pnlssicon"; - this.pnlssicon.Size = new System.Drawing.Size(200, 100); - this.pnlssicon.TabIndex = 0; - // - // pnladvancedal - // - this.pnladvancedal.Controls.Add(this.flapps); - this.pnladvancedal.Controls.Add(this.flcategories); - this.pnladvancedal.Controls.Add(this.pnlalsystemactions); - this.pnladvancedal.Controls.Add(this.pnlstatus); - this.pnladvancedal.Location = new System.Drawing.Point(0, 24); - this.pnladvancedal.Name = "pnladvancedal"; - this.pnladvancedal.Size = new System.Drawing.Size(433, 417); - this.pnladvancedal.TabIndex = 1; - this.pnladvancedal.Visible = false; - // - // flapps - // - this.flapps.Dock = System.Windows.Forms.DockStyle.Fill; - this.flapps.Location = new System.Drawing.Point(221, 58); - this.flapps.Name = "flapps"; - this.flapps.Size = new System.Drawing.Size(212, 328); - this.flapps.TabIndex = 3; - // - // flcategories - // - this.flcategories.Dock = System.Windows.Forms.DockStyle.Left; - this.flcategories.Location = new System.Drawing.Point(0, 58); - this.flcategories.Name = "flcategories"; - this.flcategories.Size = new System.Drawing.Size(221, 328); - this.flcategories.TabIndex = 2; - // - // pnlalsystemactions - // - this.pnlalsystemactions.Controls.Add(this.btnshutdown); - this.pnlalsystemactions.Dock = System.Windows.Forms.DockStyle.Bottom; - this.pnlalsystemactions.Location = new System.Drawing.Point(0, 386); - this.pnlalsystemactions.Name = "pnlalsystemactions"; - this.pnlalsystemactions.Size = new System.Drawing.Size(433, 31); - this.pnlalsystemactions.TabIndex = 1; - // - // btnshutdown - // - this.btnshutdown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnshutdown.AutoSize = true; - this.btnshutdown.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.btnshutdown.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnshutdown.Location = new System.Drawing.Point(355, 3); - this.btnshutdown.Name = "btnshutdown"; - this.btnshutdown.Size = new System.Drawing.Size(75, 26); - this.btnshutdown.TabIndex = 0; - this.btnshutdown.Text = "Shutdown"; - this.btnshutdown.UseVisualStyleBackColor = true; - this.btnshutdown.Click += new System.EventHandler(this.btnshutdown_Click); - // - // pnlstatus - // - this.pnlstatus.Controls.Add(this.lbalstatus); - this.pnlstatus.Dock = System.Windows.Forms.DockStyle.Top; - this.pnlstatus.Location = new System.Drawing.Point(0, 0); - this.pnlstatus.Name = "pnlstatus"; - this.pnlstatus.Size = new System.Drawing.Size(433, 58); - this.pnlstatus.TabIndex = 0; - // - // lbalstatus - // - this.lbalstatus.Dock = System.Windows.Forms.DockStyle.Fill; - this.lbalstatus.Location = new System.Drawing.Point(0, 0); - this.lbalstatus.Name = "lbalstatus"; - this.lbalstatus.Size = new System.Drawing.Size(433, 58); - this.lbalstatus.TabIndex = 0; - this.lbalstatus.Text = "michael@system\r\n0 Codepoints\r\n0 installed, 0 available"; - this.lbalstatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // WinformsDesktop - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BackColor = System.Drawing.Color.Black; - this.ClientSize = new System.Drawing.Size(1296, 738); - this.Controls.Add(this.pnlwidgetlayer); - this.Controls.Add(this.pnladvancedal); - this.Controls.Add(this.pnlscreensaver); - this.Controls.Add(this.desktoppanel); - this.Font = new System.Drawing.Font("Consolas", 9F); - this.ForeColor = System.Drawing.Color.LightGreen; - this.MainMenuStrip = this.menuStrip1; - this.Name = "WinformsDesktop"; - this.Text = "Desktop"; - this.Load += new System.EventHandler(this.Desktop_Load); - this.desktoppanel.ResumeLayout(false); - this.desktoppanel.PerformLayout(); - this.sysmenuholder.ResumeLayout(false); - this.sysmenuholder.PerformLayout(); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - this.pnlscreensaver.ResumeLayout(false); - this.pnladvancedal.ResumeLayout(false); - this.pnlalsystemactions.ResumeLayout(false); - this.pnlalsystemactions.PerformLayout(); - this.pnlstatus.ResumeLayout(false); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.Panel desktoppanel; - private System.Windows.Forms.Label lbtime; - private System.Windows.Forms.Panel sysmenuholder; - private System.Windows.Forms.MenuStrip menuStrip1; - private System.Windows.Forms.ToolStripMenuItem apps; - private System.Windows.Forms.FlowLayoutPanel panelbuttonholder; - private System.Windows.Forms.Button btnnotifications; - private System.Windows.Forms.Panel pnlscreensaver; - private System.Windows.Forms.Panel pnlssicon; - private System.Windows.Forms.Panel pnladvancedal; - private System.Windows.Forms.Panel pnlalsystemactions; - private System.Windows.Forms.Button btnshutdown; - private System.Windows.Forms.Panel pnlstatus; - private System.Windows.Forms.Label lbalstatus; - private System.Windows.Forms.FlowLayoutPanel flapps; - private System.Windows.Forms.FlowLayoutPanel flcategories; - private System.Windows.Forms.Panel pnlwidgetlayer; - } - -} - diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs deleted file mode 100644 index 6825f34..0000000 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ /dev/null @@ -1,1066 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using ShiftOS.Engine; -using static ShiftOS.Engine.SkinEngine; -using ShiftOS.WinForms.Tools; -using ShiftOS.WinForms.Applications; -using Newtonsoft.Json; -using ShiftOS.Engine.Scripting; -using System.Threading; - -/// -/// Winforms desktop. -/// -namespace ShiftOS.WinForms -{ - /// - /// Winforms desktop. - /// - public partial class WinformsDesktop : Form, IDesktop - { - public List Widgets = new List(); - - - private int millisecondsUntilScreensaver = 300000; - - /// - /// Initializes a new instance of the class. - /// - public WinformsDesktop() - { - InitializeComponent(); - pnlwidgetlayer.Click += (o, a) => - { - HideAppLauncher(); - }; - ControlManager.MakeDoubleBuffered(pnlwidgetlayer); - this.Click += (o, a) => - { - HideAppLauncher(); - }; - SetupControl(desktoppanel); - Shiftorium.Installed += () => - { - foreach(var widget in Widgets) - { - widget.OnUpgrade(); - } - - //Only if the DevX Legions story hasn't been experienced yet. - if (!Shiftorium.UpgradeInstalled("devx_legions")) - { - //Check for shiftnet story experience - if (Shiftorium.UpgradeInstalled("shiftnet")) - { - //Check for saturation of the "GUI" upgrade set - if (Shiftorium.IsCategoryEmptied("GUI")) - { - //Start the MUD Control Centre story. - Story.Start("devx_legions"); - } - } - } - - if (!Shiftorium.UpgradeInstalled("victortran_shiftnet")) - { - if (SaveSystem.CurrentSave.Codepoints >= 50000) - { - if (Shiftorium.IsCategoryEmptied("Applications")) - { - Story.Start("victortran_shiftnet"); - } - } - } - }; - this.TopMost = false; - - NotificationDaemon.NotificationMade += (note) => - { - //Soon this will pop a balloon note. - this.Invoke(new Action(() => - { - btnnotifications.Text = Localization.Parse("{NOTIFICATIONS} (" + NotificationDaemon.GetUnreadCount().ToString() + ")"); - })); - }; - - NotificationDaemon.NotificationRead += () => - { - //Soon this will pop a balloon note. - this.Invoke(new Action(() => - { - btnnotifications.Text = Localization.Parse("{NOTIFICATIONS} (" + NotificationDaemon.GetUnreadCount().ToString() + ")"); - })); - }; - - this.LocationChanged += (o, a) => - { - if (this.Left != 0) - this.Left = 0; - if (this.Top != 0) - this.Top = 0; - }; - - this.SizeChanged += (o, a) => - { - if (this.ClientRectangle != Screen.PrimaryScreen.Bounds) - { - this.WindowState = FormWindowState.Maximized; - } - }; - - SaveSystem.GameReady += () => - { - if (this.Visible == true) - this.Invoke(new Action(() => SetupDesktop())); - this.Invoke(new Action(() => - { - btnnotifications.Text = Localization.Parse("{NOTIFICATIONS} (" + NotificationDaemon.GetUnreadCount().ToString() + ")"); - })); - }; - Shiftorium.Installed += () => - { - if (this.Visible == true) - this.Invoke(new Action(() => SetupDesktop())); - }; - var time = new System.Windows.Forms.Timer(); - time.Interval = 100; - this.KeyDown += (o, a) => - { - if (a.Control && a.KeyCode == Keys.T) - { - Engine.AppearanceManager.SetupWindow(new Applications.Terminal()); - } - /*if (a.Control && a.KeyCode == Keys.Tab) - { - // CtrlTabMenu - CtrlTabMenu.Show(); - if (a.Shift) CtrlTabMenu.CycleBack(); - else CtrlTabMenu.CycleForwards(); - }*/ //nyi - - ShiftOS.Engine.Scripting.LuaInterpreter.RaiseEvent("on_key_down", a); - }; - SkinEngine.SkinLoaded += () => - { - foreach (var widget in Widgets) - { - widget.OnSkinLoad(); - } - - SetupDesktop(); - }; - time.Tick += (o, a) => - { - if (Shiftorium.IsInitiated == true) - { - if (SaveSystem.CurrentSave != null && TutorialManager.IsInTutorial == false) - { - lbtime.Text = Applications.Terminal.GetTime(); - lbtime.Left = desktoppanel.Width - lbtime.Width - LoadedSkin.DesktopPanelClockFromRight.X; - lbtime.Top = LoadedSkin.DesktopPanelClockFromRight.Y; - } - } - - try - { - if (SaveSystem.CurrentSave != null) - { - if (SaveSystem.CurrentSave.LastMonthPaid != DateTime.Now.Month) - { - if (SaveSystem.CurrentSave.Codepoints >= DownloadManager.GetAllSubscriptions()[SaveSystem.CurrentSave.ShiftnetSubscription].CostPerMonth) - { - SaveSystem.CurrentSave.Codepoints -= DownloadManager.GetAllSubscriptions()[SaveSystem.CurrentSave.ShiftnetSubscription].CostPerMonth; - SaveSystem.CurrentSave.LastMonthPaid = DateTime.Now.Month; - } - else - { - SaveSystem.CurrentSave.ShiftnetSubscription = 0; - SaveSystem.CurrentSave.LastMonthPaid = DateTime.Now.Month; - Infobox.Show("Shiftnet", "You do not have enough Codepoints to pay for your Shiftnet subscription this month. You have been downgraded to the free plan."); - } - } - } - } - catch { } - - - btnnotifications.Left = lbtime.Left - btnnotifications.Width - 2; - btnnotifications.Top = (desktoppanel.Height - btnnotifications.Height) / 2; - }; - 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; - } - - public void HideScreensaver() - { - if (ResetDesktop == true) - { - this.Invoke(new Action(() => - { - this.TopMost = false; - pnlscreensaver.Hide(); - Cursor.Show(); - SetupDesktop(); - ResetDesktop = false; - - })); - } - } - - private bool ResetDesktop = false; - - private void ShowScreensaver() - { - } - - - /// - /// Populates the panel buttons. - /// - /// The panel buttons. - public void PopulatePanelButtons() - { - if (DesktopFunctions.ShowDefaultElements == true) - { - panelbuttonholder.Controls.Clear(); - if (Shiftorium.IsInitiated == true) - { - if (Shiftorium.UpgradeInstalled("wm_panel_buttons")) - { - foreach (WindowBorder form in Engine.AppearanceManager.OpenForms) - { - if (form != null) - { - if (form.Visible == true) - { - EventHandler onClick = (o, a) => - { - if (form == focused) - { - if (form.IsMinimized) - { - RestoreWindow(form); - } - else - { - MinimizeWindow(form); - } - } - else - { - form.BringToFront(); - focused = form; - } - HideAppLauncher(); - }; - - var pnlbtn = new Panel(); - pnlbtn.Margin = new Padding(2, LoadedSkin.PanelButtonFromTop, 0, 0); - pnlbtn.BackColor = LoadedSkin.PanelButtonColor; - pnlbtn.BackgroundImage = GetImage("panelbutton"); - pnlbtn.BackgroundImageLayout = GetImageLayout("panelbutton"); - - var pnlbtntext = new Label(); - pnlbtntext.Text = NameChangerBackend.GetName(form.ParentWindow); - pnlbtntext.AutoSize = true; - pnlbtntext.Location = LoadedSkin.PanelButtonFromLeft; - pnlbtntext.ForeColor = LoadedSkin.PanelButtonTextColor; - pnlbtntext.BackColor = Color.Transparent; - - pnlbtn.BackColor = LoadedSkin.PanelButtonColor; - if (pnlbtn.BackgroundImage != null) - { - pnlbtntext.BackColor = Color.Transparent; - } - pnlbtn.Size = LoadedSkin.PanelButtonSize; - pnlbtn.Tag = "keepbg"; - pnlbtntext.Tag = "keepbg"; - pnlbtn.Controls.Add(pnlbtntext); - this.panelbuttonholder.Controls.Add(pnlbtn); - pnlbtn.Show(); - pnlbtntext.Show(); - - if (Shiftorium.UpgradeInstalled("useful_panel_buttons")) - { - pnlbtn.Click += onClick; - pnlbtntext.Click += onClick; - } - pnlbtntext.Font = LoadedSkin.PanelButtonFont; - - } - } - } - } - } - } - - LuaInterpreter.RaiseEvent("on_panelbutton_populate", this); - } - - /// - /// Setups the desktop. - /// - /// The desktop. - public void SetupDesktop() - { - if (DesktopFunctions.ShowDefaultElements == true) - { - ToolStripManager.Renderer = new ShiftOSMenuRenderer(); - - this.DoubleBuffered = true; - this.FormBorderStyle = FormBorderStyle.None; - this.WindowState = FormWindowState.Maximized; - desktoppanel.BackColor = Color.Green; - - //upgrades - - if (Shiftorium.IsInitiated == true) - { - desktoppanel.Visible = Shiftorium.UpgradeInstalled("desktop"); - lbtime.Visible = Shiftorium.UpgradeInstalled("desktop_clock_widget"); - - btnnotifications.Visible = Shiftorium.UpgradeInstalled("panel_notifications"); - - //skinning - lbtime.ForeColor = LoadedSkin.DesktopPanelClockColor; - - panelbuttonholder.Top = 0; - panelbuttonholder.Left = LoadedSkin.PanelButtonHolderFromLeft; - panelbuttonholder.Height = desktoppanel.Height; - panelbuttonholder.BackColor = Color.Transparent; - panelbuttonholder.Margin = new Padding(0, 0, 0, 0); - - sysmenuholder.Visible = Shiftorium.UpgradeInstalled("app_launcher"); - - //The Color Picker can give us transparent colors - which Windows Forms fucking despises when dealing with form backgrounds. - //To compensate, we must recreate the desktop color and make the alpha channel '255'. - this.BackColor = Color.FromArgb(LoadedSkin.DesktopColor.R, LoadedSkin.DesktopColor.G, LoadedSkin.DesktopColor.B); - //Not doing this will cause an ArgumentException. - - DitheringEngine.DitherImage(SkinEngine.GetImage("desktopbackground"), new Action((img) => - { - this.BackgroundImage = img; - })); - this.BackgroundImageLayout = GetImageLayout("desktopbackground"); - desktoppanel.BackColor = LoadedSkin.DesktopPanelColor; - - var pnlimg = GetImage("desktoppanel"); - if (pnlimg != null) - { - var bmp = new Bitmap(pnlimg); - bmp.MakeTransparent(Color.FromArgb(1, 0, 1)); - pnlimg = bmp; - } - - desktoppanel.BackgroundImage = pnlimg; - if (desktoppanel.BackgroundImage != null) - { - desktoppanel.BackColor = Color.Transparent; - } - var appimg = GetImage("applauncher"); - if (appimg != null) - { - var bmp = new Bitmap(appimg); - bmp.MakeTransparent(Color.FromArgb(1, 0, 1)); - appimg = bmp; - } - menuStrip1.BackgroundImage = appimg; - lbtime.ForeColor = LoadedSkin.DesktopPanelClockColor; - lbtime.Font = LoadedSkin.DesktopPanelClockFont; - if (desktoppanel.BackgroundImage == null) - { - lbtime.BackColor = LoadedSkin.DesktopPanelClockBackgroundColor; - } - else - { - lbtime.BackColor = Color.Transparent; - } - apps.Text = LoadedSkin.AppLauncherText; - sysmenuholder.Location = LoadedSkin.AppLauncherFromLeft; - sysmenuholder.Size = LoadedSkin.AppLauncherHolderSize; - apps.Size = sysmenuholder.Size; - menuStrip1.Renderer = new ShiftOSMenuRenderer(new AppLauncherColorTable()); - desktoppanel.BackgroundImageLayout = GetImageLayout("desktoppanel"); - desktoppanel.Height = LoadedSkin.DesktopPanelHeight; - if (LoadedSkin.DesktopPanelPosition == 1) - { - desktoppanel.Dock = DockStyle.Bottom; - } - else - { - desktoppanel.Dock = DockStyle.Top; - } - } - - pnlwidgetlayer.Show(); - pnlwidgetlayer.BringToFront(); - - if (Shiftorium.UpgradeInstalled("desktop_widgets")) - { - Widgets.Clear(); - pnlwidgetlayer.Controls.Clear(); - foreach(var widget in WidgetManager.GetAllWidgetTypes()) - { - UserControl w = (UserControl)Activator.CreateInstance(widget.Value, null); - - w.Location = WidgetManager.LoadDetails(w.GetType()).Location; - pnlwidgetlayer.Controls.Add(w); - MakeWidgetMovable(w); - Widgets.Add(w as IDesktopWidget); - } - } - - int lastHeight = 5; - foreach (var widget in Widgets) - { - if (WidgetManager.LoadDetails(widget.GetType()).IsVisible && Shiftorium.UpgradeInstalled("desktop_widgets")) - { - widget.OnSkinLoad(); - - widget.OnUpgrade(); - widget.Setup(); - widget.Show(); - if (widget.Location.X == -1 && widget.Location.Y == -1) - { - widget.Location = new Point(5, lastHeight); - lastHeight += widget.Size.Height + 5; - } - } - else - { - widget.Hide(); - } - } - pnlwidgetlayer.Show(); - pnlwidgetlayer.BringToFront(); - - - } - else - { - desktoppanel.Hide(); - } - - LuaInterpreter.RaiseEvent("on_desktop_skin", this); - - PopulatePanelButtons(); - } - - public void MakeWidgetMovable(Control w, Control startCtrl = null) - { - if (startCtrl == null) - startCtrl = w; - - bool moving = false; - - w.MouseDown += (o, a) => - { - HideAppLauncher(); - moving = true; - }; - - w.MouseMove += (o, a) => - { - if (moving == true) - { - var mPos = Cursor.Position; - int mY = mPos.Y - desktoppanel.Height; - int mX = mPos.X; - - int ctrlHeight = startCtrl.Height / 2; - int ctrlWidth = startCtrl.Width / 2; - - startCtrl.Location = new Point( - mX - ctrlWidth, - mY - ctrlHeight - ); - - } - }; - - w.MouseUp += (o, a) => - { - moving = false; - var details = WidgetManager.LoadDetails(startCtrl.GetType()); - details.Location = startCtrl.Location; - WidgetManager.SaveDetails(startCtrl.GetType(), details); - }; - - foreach (Control c in w.Controls) - MakeWidgetMovable(c, startCtrl); - - } - - public ToolStripMenuItem GetALCategoryWithName(string text) - { - foreach (ToolStripMenuItem menuitem in apps.DropDownItems) - { - if (menuitem.Text == text) - return menuitem; - } - - var itm = new ToolStripMenuItem(); - itm.Text = text; - apps.DropDownItems.Add(itm); - return itm; - } - - public Dictionary> LauncherItemList = new Dictionary>(); - - /// - /// Populates the app launcher. - /// - /// The app launcher. - /// Items. - public void PopulateAppLauncher(LauncherItem[] items) - { - if (Shiftorium.UpgradeInstalled("advanced_app_launcher")) - { - pnladvancedal.Visible = false; - flapps.BackColor = LoadedSkin.Menu_ToolStripDropDownBackground; - flcategories.BackColor = LoadedSkin.Menu_ToolStripDropDownBackground; - pnlalsystemactions.BackColor = LoadedSkin.SystemPanelBackground; - lbalstatus.BackColor = LoadedSkin.ALStatusPanelBackColor; - //Fonts - lbalstatus.Font = LoadedSkin.ALStatusPanelFont; - lbalstatus.ForeColor = LoadedSkin.ALStatusPanelTextColor; - btnshutdown.Font = LoadedSkin.ShutdownFont; - - //Upgrades - btnshutdown.Visible = Shiftorium.UpgradeInstalled("al_shutdown"); - - //Alignments and positions. - lbalstatus.TextAlign = LoadedSkin.ALStatusPanelAlignment; - if (LoadedSkin.ShutdownButtonStyle == 2) - btnshutdown.Hide(); - else if (LoadedSkin.ShutdownButtonStyle == 1) - { - btnshutdown.Parent = pnlstatus; - btnshutdown.BringToFront(); - } - else - btnshutdown.Parent = pnlalsystemactions; - if (LoadedSkin.ShutdownOnLeft) - { - btnshutdown.Location = LoadedSkin.ShutdownButtonFromSide; - } - else - { - btnshutdown.Left = (btnshutdown.Parent.Width - btnshutdown.Width) - LoadedSkin.ShutdownButtonFromSide.X; - btnshutdown.Top = LoadedSkin.ShutdownButtonFromSide.Y; - } - - //Images - lbalstatus.BackgroundImage = GetImage("al_bg_status"); - lbalstatus.BackgroundImageLayout = GetImageLayout("al_bg_status"); - - pnlalsystemactions.BackgroundImage = GetImage("al_bg_system"); - pnlalsystemactions.BackgroundImageLayout = GetImageLayout("al_bg_system"); - if (pnlalsystemactions.BackgroundImage != null) - btnshutdown.BackColor = Color.Transparent; - - btnshutdown.Font = LoadedSkin.ShutdownFont; - btnshutdown.ForeColor = LoadedSkin.ShutdownForeColor; - - pnladvancedal.Size = LoadedSkin.AALSize; - - pnlalsystemactions.Height = LoadedSkin.ALSystemActionHeight; - pnlstatus.Height = LoadedSkin.ALSystemStatusHeight; - - flcategories.Width = LoadedSkin.AALCategoryViewWidth; - this.flapps.Width = LoadedSkin.AALItemViewWidth; - } - - - if (DesktopFunctions.ShowDefaultElements == true) - { - apps.DropDownItems.Clear(); - - Dictionary> sortedItems = new Dictionary>(); - - flcategories.Controls.Clear(); - - LauncherItemList.Clear(); - - - foreach (var kv in items) - { - var item = new ToolStripMenuItem(); - item.Text = (kv.LaunchType == null) ? kv.DisplayData.Name : Applications.NameChangerBackend.GetNameRaw(kv.LaunchType); - item.Image = (kv.LaunchType == null) ? null : SkinEngine.GetIcon(kv.LaunchType.Name); - item.Click += (o, a) => - { - if (kv is LuaLauncherItem) - { - var interpreter = new Engine.Scripting.LuaInterpreter(); - interpreter.ExecuteFile((kv as LuaLauncherItem).LaunchPath); - } - else - { - Engine.AppearanceManager.SetupWindow(Activator.CreateInstance(kv.LaunchType) as IShiftOSWindow); - } - - }; - if (sortedItems.ContainsKey(kv.DisplayData.Category)) - { - sortedItems[kv.DisplayData.Category].Add(item); - LauncherItemList[kv.DisplayData.Category].Add(kv); - } - else - { - sortedItems.Add(kv.DisplayData.Category, new List()); - sortedItems[kv.DisplayData.Category].Add(item); - LauncherItemList.Add(kv.DisplayData.Category, new List { kv }); - } - } - - foreach (var kv in sortedItems) - { - if (Shiftorium.IsInitiated == true) - { - if (Shiftorium.UpgradeInstalled("app_launcher_categories")) - { - var cat = GetALCategoryWithName(kv.Key); - foreach (var subItem in kv.Value) - { - cat.DropDownItems.Add(subItem); - } - if (Shiftorium.UpgradeInstalled("advanced_app_launcher")) - { - var catbtn = new Button(); - catbtn.Font = LoadedSkin.AdvALItemFont; - catbtn.FlatStyle = FlatStyle.Flat; - catbtn.FlatAppearance.BorderSize = 0; - catbtn.FlatAppearance.MouseOverBackColor = LoadedSkin.Menu_MenuItemSelected; - catbtn.FlatAppearance.MouseDownBackColor = LoadedSkin.Menu_MenuItemPressedGradientBegin; - catbtn.BackColor = LoadedSkin.Menu_ToolStripDropDownBackground; - catbtn.TextAlign = ContentAlignment.MiddleLeft; - catbtn.ForeColor = LoadedSkin.Menu_TextColor; - catbtn.MouseEnter += (o, a) => - { - catbtn.ForeColor = LoadedSkin.Menu_SelectedTextColor; - }; - catbtn.MouseLeave += (o, a) => - { - catbtn.ForeColor = LoadedSkin.Menu_TextColor; - }; - catbtn.Text = kv.Key; - catbtn.Width = flcategories.Width; - catbtn.Height = 24; - flcategories.Controls.Add(catbtn); - catbtn.Show(); - catbtn.Click += (o, a) => SetupAdvancedCategory(catbtn.Text); - } - } - - else - { - foreach (var subItem in kv.Value) - { - apps.DropDownItems.Add(subItem); - } - } - } - } - - if (Shiftorium.IsInitiated == true) - { - if (Shiftorium.UpgradeInstalled("al_shutdown")) - { - apps.DropDownItems.Add(new ToolStripSeparator()); - var item = new ToolStripMenuItem(); - item.Text = Localization.Parse("{SHUTDOWN}"); - item.Click += (o, a) => - { - TerminalBackend.InvokeCommand("sos.shutdown"); - }; - apps.DropDownItems.Add(item); - if (Shiftorium.UpgradeInstalled("advanced_app_launcher")) - { - if (LoadedSkin.ShutdownButtonStyle == 2) { - var catbtn = new Button(); - catbtn.Font = LoadedSkin.AdvALItemFont; - catbtn.FlatStyle = FlatStyle.Flat; - catbtn.FlatAppearance.BorderSize = 0; - catbtn.FlatAppearance.MouseOverBackColor = LoadedSkin.Menu_MenuItemSelected; - catbtn.FlatAppearance.MouseDownBackColor = LoadedSkin.Menu_MenuItemPressedGradientBegin; - catbtn.BackColor = LoadedSkin.Menu_ToolStripDropDownBackground; - catbtn.ForeColor = LoadedSkin.Menu_TextColor; - catbtn.MouseEnter += (o, a) => - { - catbtn.ForeColor = LoadedSkin.Menu_SelectedTextColor; - }; - catbtn.MouseLeave += (o, a) => - { - catbtn.ForeColor = LoadedSkin.Menu_TextColor; - }; - - catbtn.TextAlign = ContentAlignment.MiddleLeft; - catbtn.Text = "Shutdown"; - catbtn.Width = flcategories.Width; - catbtn.Height = 24; - flcategories.Controls.Add(catbtn); - catbtn.Show(); - catbtn.Click += (o, a) => TerminalBackend.InvokeCommand("sos.shutdown"); - } - } - } - } - } - LuaInterpreter.RaiseEvent("on_al_populate", items); - } - - public void SetupAdvancedCategory(string cat) - { - flapps.Controls.Clear(); - - foreach(var app in LauncherItemList[cat]) - { - var catbtn = new Button(); - catbtn.Font = LoadedSkin.AdvALItemFont; - catbtn.FlatStyle = FlatStyle.Flat; - catbtn.FlatAppearance.BorderSize = 0; - catbtn.FlatAppearance.MouseOverBackColor = LoadedSkin.Menu_MenuItemSelected; - catbtn.FlatAppearance.MouseDownBackColor = LoadedSkin.Menu_MenuItemPressedGradientBegin; - catbtn.BackColor = LoadedSkin.Menu_ToolStripDropDownBackground; - catbtn.ForeColor = LoadedSkin.Menu_TextColor; - catbtn.MouseEnter += (o, a) => - { - catbtn.ForeColor = LoadedSkin.Menu_SelectedTextColor; - }; - catbtn.MouseLeave += (o, a) => - { - catbtn.ForeColor = LoadedSkin.Menu_TextColor; - }; - catbtn.TextAlign = ContentAlignment.MiddleLeft; - catbtn.Text = (app is LuaLauncherItem) ? app.DisplayData.Name : NameChangerBackend.GetNameRaw(app.LaunchType); - catbtn.Width = flapps.Width; - catbtn.ImageAlign = ContentAlignment.MiddleRight; - catbtn.Height = 24; - catbtn.Image = (app.LaunchType == null) ? null : SkinEngine.GetIcon(app.LaunchType.Name); - - flapps.Controls.Add(catbtn); - catbtn.Show(); - catbtn.Click += (o, a) => - { - pnladvancedal.Hide(); - if(app is LuaLauncherItem) - { - var interp = new LuaInterpreter(); - interp.ExecuteFile((app as LuaLauncherItem).LaunchPath); - } - else - { - IShiftOSWindow win = Activator.CreateInstance(app.LaunchType) as IShiftOSWindow; - AppearanceManager.SetupWindow(win); - } - - - - }; - - } - } - - /// - /// Desktops the load. - /// - /// The load. - /// Sender. - /// E. - private void Desktop_Load(object sender, EventArgs e) - { - - SaveSystem.Begin(); - - SetupDesktop(); - - SaveSystem.GameReady += () => - { - this.Invoke(new Action(() => - { - LuaInterpreter.RaiseEvent("on_desktop_load", this); - })); - }; - } - - /// - /// Shows the window. - /// - /// The window. - /// Border. - public void ShowWindow(IWindowBorder border) - { - var brdr = border as Form; - focused = border; - brdr.GotFocus += (o, a) => - { - focused = border; - }; - brdr.FormBorderStyle = FormBorderStyle.None; - brdr.Show(); - brdr.TopMost = true; - } - - /// - /// Kills the window. - /// - /// The window. - /// Border. - public void KillWindow(IWindowBorder border) - { - border.Close(); - } - - private IWindowBorder focused = null; - - public string DesktopName - { - get - { - return "ShiftOS Desktop"; - } - } - - - /// - /// Minimizes the window. - /// - /// Brdr. - public void MinimizeWindow(IWindowBorder brdr) - { - var loc = (brdr as WindowBorder).Location; - var sz = (brdr as WindowBorder).Size; - (brdr as WindowBorder).Tag = JsonConvert.SerializeObject(new - { - Size = sz, - Location = loc - }); - (brdr as WindowBorder).Location = new Point(this.GetSize().Width * 2, this.GetSize().Height * 2); - } - - /// - /// Maximizes the window. - /// - /// The window. - /// Brdr. - public void MaximizeWindow(IWindowBorder brdr) - { - int startY = (LoadedSkin.DesktopPanelPosition == 1) ? 0 : LoadedSkin.DesktopPanelHeight; - int h = this.GetSize().Height - LoadedSkin.DesktopPanelHeight; - var loc = (brdr as WindowBorder).Location; - var sz = (brdr as WindowBorder).Size; - (brdr as WindowBorder).Tag = JsonConvert.SerializeObject(new - { - Size = sz, - Location = loc - }); - (brdr as WindowBorder).Location = new Point(0, startY); - (brdr as WindowBorder).Size = new Size(this.GetSize().Width, h); - - } - - /// - /// Restores the window. - /// - /// The window. - /// Brdr. - public void RestoreWindow(IWindowBorder brdr) - { - dynamic tag = JsonConvert.DeserializeObject((brdr as WindowBorder).Tag.ToString()); - (brdr as WindowBorder).Location = tag.Location; - (brdr as WindowBorder).Size = tag.Size; - - } - - /// - /// Invokes the on worker thread. - /// - /// The on worker thread. - /// Act. - public void InvokeOnWorkerThread(Action act) - { - try - { - this.Invoke(new Action(() => - { - act?.Invoke(); - })); - } - catch - { - - } - } - - public void OpenAppLauncher(Point loc) - { - apps.DropDown.Left = loc.X; - apps.DropDown.Top = loc.Y; - apps.ShowDropDown(); - } - - /// - /// Gets the size. - /// - /// The size. - public Size GetSize() - { - return this.Size; - } - - private void btnnotifications_Click(object sender, EventArgs e) - { - AppearanceManager.SetupWindow(new Applications.Notifications()); - } - - private void desktoppanel_Paint(object sender, PaintEventArgs e) - { - e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; - } - - private void lbtime_Click(object sender, EventArgs e) - { - } - - public void SetupControl(Control ctrl) - { - foreach (Control c in ctrl.Controls) - SetupControl(c); - ctrl.Click += (o, a) => HideAppLauncher(); - } - - private void apps_Click(object sender, EventArgs e) - { - if (Shiftorium.UpgradeInstalled("advanced_app_launcher")) - { - lbalstatus.Text = $@"{SaveSystem.CurrentUser.Username}@{SaveSystem.CurrentSave.SystemName} -{SaveSystem.CurrentSave.Codepoints} Codepoints -{Shiftorium.GetAvailable().Length} available, {SaveSystem.CurrentSave.CountUpgrades()} installed."; - - flapps.Controls.Clear(); - apps.DropDown.Hide(); - pnladvancedal.Location = new Point(0, (LoadedSkin.DesktopPanelPosition == 0) ? desktoppanel.Height : this.Height - pnladvancedal.Height - desktoppanel.Height); - pnladvancedal.Visible = !pnladvancedal.Visible; - pnladvancedal.BringToFront(); - } - - } - - private void btnshutdown_Click(object sender, EventArgs e) - { - TerminalBackend.InvokeCommand("sos.shutdown"); - } - - public void HideAppLauncher() - { - this.Invoke(new Action(() => - { - pnladvancedal.Hide(); - })); - } - } - - [ShiftOS.Engine.Scripting.Exposed("desktop")] - public class DesktopFunctions - { - public static bool ShowDefaultElements = true; - - public dynamic getWindow() - { - return Desktop.CurrentDesktop; - } - - public void showDefaultElements(bool val) - { - ShowDefaultElements = val; - SkinEngine.LoadSkin(); - } - - public dynamic getOpenWindows() - { - return AppearanceManager.OpenForms; - } - - public string getALItemName(LauncherItem kv) - { - return (kv.LaunchType == null) ? kv.DisplayData.Name : Applications.NameChangerBackend.GetNameRaw(kv.LaunchType); - } - - public void openAppLauncher(Point loc) - { - Desktop.OpenAppLauncher(loc); - } - - public string getWindowTitle(IWindowBorder form) - { - return NameChangerBackend.GetName(form.ParentWindow); - } - - public void openApp(LauncherItem kv) - { - if (kv is LuaLauncherItem) - { - var interpreter = new Engine.Scripting.LuaInterpreter(); - interpreter.ExecuteFile((kv as LuaLauncherItem).LaunchPath); - } - else - { - Engine.AppearanceManager.SetupWindow(Activator.CreateInstance(kv.LaunchType) as IShiftOSWindow); - } - } - } -} \ No newline at end of file diff --git a/ShiftOS_TheReturn/AppearanceManager.cs b/ShiftOS_TheReturn/AppearanceManager.cs deleted file mode 100644 index 4c1754e..0000000 --- a/ShiftOS_TheReturn/AppearanceManager.cs +++ /dev/null @@ -1,379 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define MUD_RAPIDDEV - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using Newtonsoft.Json; -using static ShiftOS.Engine.SaveSystem; - -namespace ShiftOS.Engine -{ - /// - /// Provides functionality for managing windows within ShiftOS. - /// - public static class AppearanceManager - { - [Obsolete("Please use Localization.GetAllLanguages().")] - public static string[] GetLanguages() - { - return Localization.GetAllLanguages(); - } - - /// - /// Sets the title text of the specified window. - /// - /// The window to modify - /// The title text to use - /// Thrown if the window is null. - public static void SetWindowTitle(IShiftOSWindow window, string title) - { - if (window == null) - throw new ArgumentNullException("window", "The window cannot be null."); - winmgr.SetTitle(window, title); - } - - public static IEnumerable GetAllWindowTypes() - { - List types = new List(); - foreach(var file in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - if(file.EndsWith(".exe") || file.EndsWith(".dll")) - { - try - { - var asm = Assembly.LoadFile(file); - foreach(var type in asm.GetTypes()) - { - if (type.GetInterfaces().Contains(typeof(IShiftOSWindow))) - types.Add(type); - } - } - catch { } - } - } - return types; - } - - /// - /// Returns the default window title for a specified -inheriting type. - /// - /// The type to scan - /// The default title - /// Thrown if is null. - public static string GetDefaultTitle(Type winType) - { - if (winType == null) - throw new ArgumentNullException("winType"); - foreach(var attrib in winType.GetCustomAttributes(false)) - { - if(attrib is DefaultTitleAttribute) - { - return (attrib as DefaultTitleAttribute).Title; - } - } - return winType.Name; - } - - /// - /// Current cursor position of the console - /// - public static int CurrentPosition { get; set; } - - /// - /// We don't know what this does. It may be gone if it does nothing. - /// - public static int LastLength { get; set; } - - - /// - /// Minimize a window. - /// - /// The window border to minimize. - /// Thrown if is null. - /// Thrown if this part of the engine hasn't been enabled. - public static void Minimize(IWindowBorder form) - { - if (form == null) - throw new ArgumentNullException("form"); - if (winmgr == null) - throw new EngineModuleDisabledException(); - winmgr.Minimize(form); - } - - /// - /// Maximizes a window. - /// - /// The window border to maximize. - /// Thrown if is null. - /// Thrown if this engine module hasn't been enabled. - public static void Maximize(IWindowBorder form) - { - if (form == null) - throw new ArgumentNullException("form"); - if (winmgr == null) - throw new EngineModuleDisabledException(); - winmgr.Maximize(form); - } - - - /// - /// Provides a list of all open ShiftOS windows. - /// - public static List OpenForms = new List(); - - /// - /// Decorates a window with a border, then shows the window. - /// - /// The window to decorate and show. - /// Thrown if is null. - /// Thrown if this engine module has not been initiated yet. - public static void SetupWindow(IShiftOSWindow form) - { - if (form == null) - throw new ArgumentNullException("form"); - if (winmgr == null) - throw new EngineModuleDisabledException(); - winmgr.SetupWindow(form); - Desktop.ResetPanelButtons(); - } - - /// - /// Closes the specified window. - /// - /// The window to close. - /// Thrown if is null. - /// Thrown if this engine module has not been initiated yet. - public static void Close(IShiftOSWindow win) - { - if (win == null) - throw new ArgumentNullException("win"); - if (winmgr == null) - throw new EngineModuleDisabledException(); - winmgr.Close(win); - Desktop.ResetPanelButtons(); - } - - /// - /// Decorates a window with a border, then shows the window, as a dialog box. - /// - /// The window to decorate and show. - /// Thrown if is null. - /// Thrown if this engine module has not been initiated yet. - public static void SetupDialog(IShiftOSWindow form) - { - if (form == null) - throw new ArgumentNullException("form"); - if (winmgr == null) - throw new EngineModuleDisabledException(); - winmgr.SetupDialog(form); - Desktop.ResetPanelButtons(); - } - - /// - /// The underlying window manager for this engine module - /// - private static WindowManager winmgr = null; - - /// - /// Initiate this engine module, and perform mandatory configuration. - /// - /// A working, configured to use as a backend for this module - public static void Initiate(WindowManager mgr) - { - winmgr = mgr; - } - - /// - /// Raised when the engine is entering its shutdown phase. Save your work! - /// - public static event EmptyEventHandler OnExit; - - /// - /// Starts the engine's exit routine, firing the OnExit event. - /// - internal static void Exit() - { - OnExit?.Invoke(); - //disconnect from MUD - ServerManager.Disconnect(); - } - - /// - /// The current terminal body control. - /// - public static ITerminalWidget ConsoleOut { get; set; } - - /// - /// Redirects the .NET to a new instance. - /// - public static void StartConsoleOut() - { - Console.SetOut(new TerminalTextWriter()); - } - - /// - /// Invokes an action on the window management thread. - /// - /// The action to invoke - public static void Invoke(Action act) - { - winmgr.InvokeAction(act); - } - } - - /// - /// Provides the base functionality for a ShiftOS terminal. - /// - public interface ITerminalWidget - { - /// - /// Write text to this Terminal. - /// - /// Text to write - void Write(string text); - /// - /// Write text to this Terminal, followed by a newline. - /// - /// Text to write. - void WriteLine(string text); - /// - /// Clear the contents of this Terminal. - /// - void Clear(); - /// - /// Move the cursor to the last character in the Terminal. - /// - void SelectBottom(); - } - - /// - /// Provides the base functionality for a ShiftOS window manager. - /// - public abstract class WindowManager - { - /// - /// Minimizes a window - /// - /// The window border to minimize - public abstract void Minimize(IWindowBorder border); - - /// - /// Maximizes a window - /// - /// The window border to maximize - public abstract void Maximize(IWindowBorder border); - - /// - /// Closes a window - /// - /// The window to close - public abstract void Close(IShiftOSWindow win); - - /// - /// Decorates a window with a window border, then shows it to the user. - /// - /// The window to decorate. - public abstract void SetupWindow(IShiftOSWindow win); - - /// - /// Decorates a window with a border, then shows it to the user as a dialog box. - /// - /// The window to decorate - public abstract void SetupDialog(IShiftOSWindow win); - - /// - /// Invokes an action on the window management thread. - /// - /// The action to invoke. - public abstract void InvokeAction(Action act); - - /// - /// Sets the title text of a window. - /// - /// The window to modify. - /// The new title text. - public abstract void SetTitle(IShiftOSWindow win, string title); - } - - /// - /// Provides the base functionality for a typical ShiftOS window border. - /// - public interface IWindowBorder - { - /// - /// Closes the border along with its window. Unload events should be invoked here. - /// - void Close(); - - /// - /// Gets or sets the title text for the window border. - /// - string Text { get; set; } - - /// - /// Gets or sets the underlying for this border. - /// - IShiftOSWindow ParentWindow { get; set; } - } - - /// - /// Provides a way of setting default title text for classes. - /// - public class DefaultTitleAttribute : Attribute - { - /// - /// Creates a new instance of the . - /// - /// A default title to associate with this attribute. - public DefaultTitleAttribute(string title) - { - Title = title; - } - - public string Title { get; private set; } - } - - /// - /// An exception that is thrown when mandatory configuration to run a specific method or module hasn't been done yet. - /// - public class EngineModuleDisabledException : Exception - { - /// - /// Initializes a new instance of the . - /// - public EngineModuleDisabledException() : base("This engine module has not yet been enabled.") - { - - } - } -} diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs deleted file mode 100644 index a636497..0000000 --- a/ShiftOS_TheReturn/AudioManager.cs +++ /dev/null @@ -1,134 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define NOSOUND - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using NAudio; -using NAudio.Wave; - -namespace ShiftOS.Engine -{ - public static class AudioManager - { - private static WaveOut _out = null; - private static AudioFileReader _reader = null; - private static IAudioProvider _provider = null; - - /// - /// Stops the current sound if one is playing and disposes of the sound. - /// - public static void Stop() - { - _out?.Stop(); - _reader?.Dispose(); - _out?.Dispose(); - } - - /// - /// Initiates this engine module using an as a backend for selecting background soundtrack as well as the volume level for the sound. - /// - /// A background soundtrack and volume provider. - /// Thrown if is null. - public static void Init(IAudioProvider _p) - { - if (_p == null) - throw new ArgumentNullException("_p"); - _provider = _p; - } - - /// - /// Sets the volume of the audio system. - /// - /// The volume to use, from 0 to 1. - public static void SetVolume(float volume) - { - _provider.Volume = volume; //persist between songs - _out.Volume = volume; - } - - /// - /// Plays a specified sound file. - /// - /// The file to play. - public static void Play(string file) - { - try - { - _reader = new AudioFileReader(file); - _out = new WaveOut(); - _out.Init(_reader); - _out.Volume = _provider.Volume; - _out.Play(); - _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); }; - } - catch { } - } - - /// - /// Writes the data in the specified to a file, and plays it as a sound file. - /// - /// The stream to read from. - public static void PlayStream(Stream str) - { - var bytes = new byte[str.Length]; - str.Read(bytes, 0, bytes.Length); - ShiftOS.Engine.AudioManager.Stop(); - if (File.Exists("snd.wav")) - File.Delete("snd.wav"); - File.WriteAllBytes("snd.wav", bytes); - - ShiftOS.Engine.AudioManager.Play("snd.wav"); - - } - - public static event Action PlayCompleted; - } - - public interface IAudioProvider - { - /// - /// Gets a byte[] array corresponding to an MP3 track given an index. - /// - /// A track index to use when finding the right track. - /// The MP3 byte[] array. - byte[] GetTrack(int index); - - /// - /// Gets the 1-based count of all available tracks. - /// - int Count { get; } - - /// - /// Gets or sets the track player's volume. - /// - float Volume { get; set; } - } -} diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs deleted file mode 100644 index dc0b3a2..0000000 --- a/ShiftOS_TheReturn/Commands.cs +++ /dev/null @@ -1,837 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define DEVEL - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Forms; -using ShiftOS.Engine.Properties; -using System.IO; -using Newtonsoft.Json; -using System.IO.Compression; - -using ShiftOS.Objects; -using Discoursistency.Base.Models.Authentication; -using ShiftOS.Engine.Scripting; -using ShiftOS.Objects.ShiftFS; - -namespace ShiftOS.Engine -{ - [Namespace("infobox", hide = true)] - [RequiresUpgrade("desktop;wm_free_placement")] - public static class InfoboxDebugCommands - { - - [RequiresArgument("title")] - [RequiresArgument("msg")] - [Command("show")] - public static bool ShowInfo(Dictionary args) - { - Desktop.InvokeOnWorkerThread(new Action(() => - { - Infobox.Show(args["title"].ToString(), args["msg"].ToString()); - })); - return true; - } - - [RequiresArgument("title")] - [RequiresArgument("msg")] - [Command("yesno")] - public static bool ShowYesNo(Dictionary args) - { - bool forwarding = TerminalBackend.IsForwardingConsoleWrites; - var fGuid = TerminalBackend.ForwardGUID; - Action callback = (result) => - { - TerminalBackend.IsForwardingConsoleWrites = forwarding; - TerminalBackend.ForwardGUID = (forwarding == true) ? fGuid : null; - string resultFriendly = (result == true) ? "yes" : "no"; - Console.WriteLine($"{SaveSystem.CurrentUser.Username} says {resultFriendly}."); - TerminalBackend.IsForwardingConsoleWrites = false; - }; - Desktop.InvokeOnWorkerThread(new Action(() => - { - Infobox.PromptYesNo(args["title"].ToString(), args["msg"].ToString(), callback); - - })); - return true; - } - - [RequiresArgument("title")] - [RequiresArgument("msg")] - [Command("text")] - public static bool ShowText(Dictionary args) - { - bool forwarding = TerminalBackend.IsForwardingConsoleWrites; - var fGuid = TerminalBackend.ForwardGUID; - Action callback = (result) => - { - TerminalBackend.IsForwardingConsoleWrites = forwarding; - TerminalBackend.ForwardGUID = (forwarding == true) ? fGuid : null; - Console.WriteLine($"{SaveSystem.CurrentSave.Username} says \"{result}\"."); - TerminalBackend.IsForwardingConsoleWrites = false; - }; - Desktop.InvokeOnWorkerThread(new Action(() => - { - Infobox.PromptText(args["title"].ToString(), args["msg"].ToString(), callback); - })); - return true; - } - - } - - [Namespace("audio")] - public static class AudioCommands - { - [Command("setvol", description = "Set the volume of the system audio to anywhere between 0 and 100.")] - [RequiresArgument("value")] - [RequiresUpgrade("audio_volume")] - public static bool SetVolume(Dictionary args) - { - int val = Convert.ToInt32(args["value"].ToString()); - float volume = (val / 100F); - AudioManager.SetVolume(volume); - return true; - } - [RequiresUpgrade("audio_volume")] - [Command("mute", description = "Sets the volume of the system audio to 0")] - public static bool MuteAudio() - { - AudioManager.SetVolume(0); - return true; - } - } - - [RequiresUpgrade("mud_fundamentals")] - [Namespace("mud")] - public static class MUDCommands - { - [MultiplayerOnly] - [Command("status")] - public static bool Status() - { - ServerManager.PrintDiagnostics(); - return true; - } - - [Command("connect")] - public static bool Connect(Dictionary args) - { - try - { - string ip = (args.ContainsKey("addr") == true) ? args["addr"] as string : "michaeltheshifter.me"; - int port = (args.ContainsKey("port") == true) ? Convert.ToInt32(args["port"] as string) : 13370; - try - { - ServerManager.Initiate(ip, port); - } - catch (Exception ex) - { - Console.WriteLine("{ERROR}: " + ex.Message); - } - - TerminalBackend.PrefixEnabled = false; - return true; - } - catch (Exception ex) - { - Console.WriteLine("Error running script:" + ex); - return false; - } - } - - [Command("reconnect")] - [RequiresUpgrade("hacker101_deadaccts")] - public static bool Reconnect() - { - Console.WriteLine("--reconnecting to multi-user domain..."); - KernelWatchdog.MudConnected = true; - Console.WriteLine("--done."); - return true; - } - - [MultiplayerOnly] - [Command("disconnect")] - [RequiresUpgrade("hacker101_deadaccts")] - public static bool Disconnect() - { - Console.WriteLine("--connection to multi-user domain severed..."); - KernelWatchdog.MudConnected = false; - return true; - } - - [MultiplayerOnly] - [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; - } - } - - [TutorialLock] - [Namespace("trm")] - public static class TerminalCommands - { - [Command("clear")] - public static bool Clear() - { - AppearanceManager.ConsoleOut.Clear(); - return true; - } - - [Command("echo")] - [RequiresArgument("text")] - public static bool Echo(Dictionary args) - { - Console.WriteLine(args["text"]); - return true; - } - } - -#if DEVEL - internal class Rock : Exception - { - internal Rock() : base("Someone threw a rock at the window, and the Terminal shattered.") - { - - } - } - - [MultiplayerOnly] - [Namespace("dev")] - public static class ShiftOSDevCommands - { - [Command("rock", description = "A little surprise for unstable builds...")] - public static bool ThrowASandwichingRock() - { - Infobox.Show("He who lives in a glass house shouldn't throw stones...", new Rock().Message); - return false; - } - - - [Command("unbuy")] - [RequiresArgument("upgrade")] - public static bool UnbuyUpgrade(Dictionary args) - { - try - { - SaveSystem.CurrentSave.Upgrades[args["upgrade"].ToString()] = false; - SaveSystem.SaveGame(); - Desktop.PopulateAppLauncher(); - Desktop.CurrentDesktop.SetupDesktop(); - } - catch - { - Console.WriteLine("Upgrade not found."); - } - return true; - } - - [Command("getallupgrades")] - public static bool GetAllUpgrades() - { - Console.WriteLine(JsonConvert.SerializeObject(SaveSystem.CurrentSave.Upgrades, Formatting.Indented)); - return true; - } - - [Command("multarg")] - [RequiresArgument("id")] - [RequiresArgument("name")] - [RequiresArgument("type")] - public static bool MultArg(Dictionary args) - { - Console.WriteLine("Success! "+args.ToString()); - 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) - { - if (args.ContainsKey("amount")) - try - { - long codepointsToAdd = Convert.ToInt64(args["amount"].ToString()); - SaveSystem.CurrentSave.Codepoints += codepointsToAdd; - return true; - } - catch (Exception ex) - { - Console.WriteLine("{ERROR}: " + ex.Message); - return true; - } - - SaveSystem.CurrentSave.Codepoints += 1000; - return true; - } - - [Command("unlockeverything")] - public static bool UnlockAllUpgrades() - { - foreach (var upg in Shiftorium.GetDefaults()) - { - Shiftorium.Buy(upg.ID, 0); - } - return true; - } - - [Command("info")] - public static bool DevInformation() - { - Console.WriteLine("{SHIFTOS_PLUS_MOTTO}"); - Console.WriteLine("{SHIFTOS_VERSION_INFO}" + Assembly.GetExecutingAssembly().GetName().Version); - return true; - } - [Command("pullfile")] - public static bool PullFile(Dictionary args) - { - if (args.ContainsKey("physical") && args.ContainsKey("virtual")) - { - string file = (string)args["physical"]; - string dest = (string)args["virtual"]; - if (System.IO.File.Exists(file)) - { - Console.WriteLine("Pulling physical file to virtual drive..."); - byte[] filebytes = System.IO.File.ReadAllBytes(file); - ShiftOS.Objects.ShiftFS.Utils.WriteAllBytes(dest, filebytes); - } - else - { - Console.WriteLine("The specified file does not exist on the physical drive."); - } - } - else - { - Console.WriteLine("You must supply a physical path."); - } - return true; - } - [Command("crash")] - public static bool CrashInstantly() - { - CrashHandler.Start(new Exception("ShiftOS was sent a command to forcefully crash.")); - return true; - } - } -#endif - - [Namespace("sos")] - public static class ShiftOSCommands - { - [RemoteLock] - [Command("shutdown")] - public static bool Shutdown() - { - TerminalBackend.InvokeCommand("sos.save"); - SaveSystem.ShuttingDown = true; - AppearanceManager.Exit(); - return true; - } - - [Command("lang", "{COMMAND_SOS_LANG_USAGE}", "{COMMAND_SOS_LANG_DESCRIPTION}")] - [RequiresArgument("language")] - public static bool SetLanguage(Dictionary userArgs) - { - try - { - string lang = ""; - - if (userArgs.ContainsKey("language")) - lang = (string)userArgs["language"]; - else - throw new Exception("You must specify a valid 'language' value."); - - if (Localization.GetAllLanguages().Contains(lang)) - { - SaveSystem.CurrentSave.Language = lang; - SaveSystem.SaveGame(); - Console.WriteLine("{LANGUAGE_CHANGED}"); - return true; - } - - throw new Exception($"Couldn't find language with ID: {lang}"); - } - catch - { - return false; - } - } - - [Command("help", "{COMMAND_HELP_USAGE}", "{COMMAND_HELP_DESCRIPTION}")] - public static bool Help() - { - foreach (var exec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - 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)) - { - foreach (var a in type.GetCustomAttributes(false)) - { - if (a is Namespace) - { - var ns = a as Namespace; - - if (!ns.hide) - { - string descp = "{NAMESPACE_" + ns.name.ToUpper() + "_DESCRIPTION}"; - if (descp == Localization.Parse(descp)) - descp = ""; - else - descp = Shiftorium.UpgradeInstalled("help_description") ? Localization.Parse("{SEPERATOR}" + descp) : ""; - - Console.WriteLine($"{{NAMESPACE}}{ns.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_" + ns.name.ToUpper() + "_" + cmd.name.ToUpper() + "_DESCRIPTION}"; - string usageparse = "{COMMAND_" + ns.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", ns.name}, - {"%cmd", cmd.name} - }) : ""; - - Console.WriteLine($"{{COMMAND}}{ns.name}.{cmd.name}" + usageparse + descriptionparse); - } - } - } - } - - } - } - - } - } - } - } - - } - catch { } - } - } - - return true; - } - - [MultiplayerOnly] - [Command("save")] - public static bool Save() - { - SaveSystem.SaveGame(); - return true; - } - - [MultiplayerOnly] - [Command("status")] - public static bool Status() - { - string status = $@"ShiftOS version {Assembly.GetExecutingAssembly().GetName().Version.ToString()} - -Codepoints: {SaveSystem.CurrentSave.Codepoints} -Upgrades: {SaveSystem.CurrentSave.CountUpgrades()} installed, - {Shiftorium.GetAvailable().Length} available"; - - if (Shiftorium.UpgradeInstalled("mud_control_centre")) - status += Environment.NewLine + $"Reputation: {SaveSystem.CurrentSave.RawReputation} ({SaveSystem.CurrentSave.Reputation})"; - Console.WriteLine(status); - return true; - } - } - - [MultiplayerOnly] - [Namespace("shiftorium")] - public static class ShiftoriumCommands - { - [Command("buy")] - [RequiresArgument("upgrade")] - public static bool BuyUpgrade(Dictionary userArgs) - { - try - { - string upgrade = ""; - - if (userArgs.ContainsKey("upgrade")) - upgrade = (string)userArgs["upgrade"]; - else - throw new Exception("You must specify a valid 'upgrade' value."); - - foreach (var upg in Shiftorium.GetAvailable()) - { - if (upg.ID == upgrade) - { - Shiftorium.Buy(upgrade, upg.Cost); - return true; - } - } - - throw new Exception($"Couldn't find upgrade with ID: {upgrade}"); - } - catch - { - return false; - } - } - - [RequiresUpgrade("shiftorium_bulk_buy")] - [Command("bulkbuy")] - [RequiresArgument("upgrades")] - public static bool BuyBulk(Dictionary args) - { - if (args.ContainsKey("upgrades")) - { - string[] upgrade_list = (args["upgrades"] as string).Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); - foreach (var upg in upgrade_list) - { - var dict = new Dictionary(); - dict.Add("upgrade", upg); - BuyUpgrade(dict); - } - } - else - { - throw new Exception("Please specify a list of upgrades in the 'upgrades' argument. Each upgrade is separated by a comma."); - } - return true; - } - - - [Command("info")] - public static bool ViewInfo(Dictionary userArgs) - { - try - { - string upgrade = ""; - - if (userArgs.ContainsKey("upgrade")) - upgrade = (string)userArgs["upgrade"]; - else - throw new Exception("You must specify a valid 'upgrade' value."); - - foreach (var upg in Shiftorium.GetDefaults()) - { - if (upg.ID == upgrade) - { - Console.WriteLine($@"Information for {upgrade}: - -{upg.Category}: {upg.Name} - {upg.Cost} Codepoints ------------------------------------------------------- - -{upg.Description} - -To buy this upgrade, run: -shiftorium.buy{{upgrade:""{upg.ID}""}}"); - return true; - } - } - - throw new Exception($"Couldn't find upgrade with ID: {upgrade}"); - } - catch - { - return false; - } - } - - [Command("categories")] - public static bool ListCategories() - { - foreach(var cat in Shiftorium.GetCategories()) - { - Console.WriteLine($"{cat} - {Shiftorium.GetAvailable().Where(x=>x.Category==cat).Count()} upgrades"); - } - return true; - } - - [Command("list")] - public static bool ListAll(Dictionary args) - { - try - { - bool showOnlyInCategory = false; - - string cat = "Other"; - - if (args.ContainsKey("cat")) - { - showOnlyInCategory = true; - cat = args["cat"].ToString(); - } - - Dictionary upgrades = new Dictionary(); - int maxLength = 5; - - IEnumerable upglist = Shiftorium.GetAvailable(); - if (showOnlyInCategory) - { - if (Shiftorium.IsCategoryEmptied(cat)) - { - ConsoleEx.Bold = true; - ConsoleEx.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Shiftorium Query Error"); - Console.WriteLine(); - ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = ConsoleColor.Gray; - Console.WriteLine("Either there are no upgrades in the category \"" + cat + "\" or the category was not found."); - return true; - } - upglist = Shiftorium.GetAvailable().Where(x => x.Category == cat); - } - - - if(upglist.Count() == 0) - { - ConsoleEx.Bold = true; - ConsoleEx.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("No upgrades available!"); - Console.WriteLine(); - ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = ConsoleColor.Gray; - Console.WriteLine("You have installed all available upgrades for your system. Please check back later for more."); - return true; - - } - foreach (var upg in upglist) - { - if (upg.ID.Length > maxLength) - { - maxLength = upg.ID.Length; - } - - upgrades.Add(upg.ID, upg.Cost); - } - - Console.WriteLine("ID".PadRight((maxLength + 5) - 2) + "Cost (Codepoints)"); - - foreach (var upg in upgrades) - { - Console.WriteLine(upg.Key.PadRight((maxLength + 5) - upg.Key.Length) + " " + upg.Value.ToString()); - } - return true; - } - catch (Exception e) - { - CrashHandler.Start(e); - return false; - } - } - } - - [Namespace("win")] - public static class WindowCommands - { - - - - [RemoteLock] - [Command("list")] - public static bool List() - { - Console.WriteLine("Window ID\tName"); - foreach (var app in AppearanceManager.OpenForms) - { - //Windows are displayed the order in which they were opened. - Console.WriteLine($"{AppearanceManager.OpenForms.IndexOf(app)}\t{app.Text}"); - } - return true; - } - - [RemoteLock] - [Command("open")] - public static bool Open(Dictionary args) - { - try - { - if (args.ContainsKey("app")) - { - var app = args["app"] as string; - //ANNND now we start reflecting... - foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - if (asmExec.EndsWith(".exe") || asmExec.EndsWith(".dll")) - { - var asm = Assembly.LoadFile(asmExec); - try - { - foreach (var type in asm.GetTypes()) - { - if (type.BaseType == typeof(UserControl)) - { - foreach (var attr in type.GetCustomAttributes(false)) - { - if (attr is WinOpenAttribute) - { - if (app == (attr as WinOpenAttribute).ID) - { - if (SaveSystem.CurrentSave.Upgrades.ContainsKey(app)) - { - if (Shiftorium.UpgradeInstalled(app)) - { - IShiftOSWindow frm = Activator.CreateInstance(type) as IShiftOSWindow; - AppearanceManager.SetupWindow(frm); - return true; - } - else - { - throw new Exception($"{app} was not found on your system! Try looking in the shiftorium..."); - } - } - else - { - IShiftOSWindow frm = Activator.CreateInstance(type) as IShiftOSWindow; - AppearanceManager.SetupWindow(frm); - return true; - } - } - } - } - } - } - } - catch { } - - } - } - - } - else - { - foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - if (asmExec.EndsWith(".exe") || asmExec.EndsWith(".dll")) - { - try - { - var asm = Assembly.LoadFile(asmExec); - - foreach (var type in asm.GetTypes()) - { - if (type.GetInterfaces().Contains(typeof(IShiftOSWindow))) - { - foreach (var attr in type.GetCustomAttributes(false)) - { - if (attr is WinOpenAttribute) - { - if (Shiftorium.UpgradeAttributesUnlocked(type)) - { - Console.WriteLine("win.open{app:\"" + (attr as WinOpenAttribute).ID + "\"}"); - } - } - } - } - } - } - catch { } - } - } - - - return true; - } - Console.WriteLine("Couldn't find the specified app on your system."); - return true; - } - catch (Exception ex) - { - Console.WriteLine("Error running script:" + ex); - return false; - } - } - - [RemoteLock] - [Command("close", usage = "{win:integer32}", description ="Closes the specified window.")] - [RequiresArgument("win")] - [RequiresUpgrade("close_command")] - public static bool CloseWindow(Dictionary args) - { - int winNum = -1; - if (args.ContainsKey("win")) - winNum = Convert.ToInt32(args["win"].ToString()); - string err = null; - - if (winNum < 0 || winNum >= AppearanceManager.OpenForms.Count) - err = "The window number must be between 0 and " + (AppearanceManager.OpenForms.Count - 1).ToString() + "."; - - if (string.IsNullOrEmpty(err)) - { - Console.WriteLine($"Closing {AppearanceManager.OpenForms[winNum].Text}..."); - AppearanceManager.Close(AppearanceManager.OpenForms[winNum].ParentWindow); - } - else - { - Console.WriteLine(err); - } - - return true; - } - - } -} diff --git a/ShiftOS_TheReturn/CrashHandler.cs b/ShiftOS_TheReturn/CrashHandler.cs deleted file mode 100644 index ed42ea5..0000000 --- a/ShiftOS_TheReturn/CrashHandler.cs +++ /dev/null @@ -1,217 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Reflection; -using System.Management; -using System.Windows.Forms; -using Newtonsoft.Json; -using System.Threading; -using System.IO; - -namespace ShiftOS.Engine -{ - public class GetHardwareInfo - { - public static string GetProcessorName() - { - string ProcessorName = ""; - ManagementObjectSearcher mos - = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor"); - - foreach (ManagementObject mo in mos.Get()) - ProcessorName = mo["Name"].ToString(); - - return ProcessorName; - } - public static string GetGPUName() - { - string GPUName = ""; - ManagementObjectSearcher mos - = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_VideoController"); - - foreach (ManagementObject mo in mos.Get()) - GPUName = mo["Name"].ToString(); - - return GPUName; - } - public static string GetRAMAmount() - { - var RAMAmount = ""; - ManagementObjectSearcher mos - = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PhysicalMemory"); - - foreach (ManagementObject mo in mos.Get()) - RAMAmount = mo["Capacity"].ToString(); - - RAMAmount = (RAMAmount + " B"); - - return RAMAmount; - } - } - - - public partial class CrashHandler : Form - { - public CrashHandler() - { - InitializeComponent(); - - - //Send the bug to Debugle - // or alternatively, send to reportbug@shiftos.ml OR narodgaming@shiftos.ml - - } - - public static Exception HandledException = null; - - public static void Start(Exception e) - { - if(SaveSystem.CurrentSave != null) - TerminalBackend.InvokeCommand("sos.save"); - ServerManager.Disconnect(); - - while (Application.OpenForms.Count > 0) - Application.OpenForms[0].Close(); - - //Set our global exception variable, and show the exception dialog. - HandledException = e; - System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); - System.IO.FileInfo fileInfo = new System.IO.FileInfo(assembly.Location); - DateTime lastModified = fileInfo.LastWriteTime; - - string rtbcrash_Text = $@" === {AssemblyName} has crashed. === - -Game: {AssemblyName} -Description: {AssemblyDescription} - -Basic Information For User: ---------------------------------- - -When: {DateTime.Now.ToString()} -Why: {HandledException.Message} -What: {HandledException.GetType().Name} - -We, at the ShiftOS Development Team, apologise for your game crash, -we will take this bug report seriously - and it has been emailed -to the development team of ShiftOS, thank you for enjoying our game! - -Advanced Information (for experts and developers): ----------------------------------------------------- - -Host system information: ---------------------------------- - -Operating system: {Environment.OSVersion.Platform.ToString()} -Version: {Environment.OSVersion.VersionString} -Is 64-bit: {Environment.Is64BitOperatingSystem} -ShiftOS exec path: {Application.ExecutablePath} - -Advanced Host Information: ---------------------------------- - -CPU Name: {GetHardwareInfo.GetProcessorName()} -Physical RAM Installed: {GetHardwareInfo.GetRAMAmount()} -GPU Name: {GetHardwareInfo.GetGPUName()} - -ShiftOS basic information: ---------------------------------- - -ShiftOS Version: {Assembly.GetExecutingAssembly().GetName().Version} -ShiftOS Date: {lastModified.ToString()} - -ShiftOS environment information: ---------------------------------- - -Is Save loaded: {(SaveSystem.CurrentSave != null)} -Paths loaded in system: {JsonConvert.SerializeObject(Paths.GetAll())} - - -Crash: {HandledException.GetType().Name} --------------------------------------------- - -Exception message: {HandledException.Message} -HResult (this is technical): {HandledException.HResult} -Has inner exception: {(HandledException.InnerException != null)} -Stack trace: -{HandledException.StackTrace}"; - - if (HandledException.InnerException != null) - { - var i = HandledException.InnerException; - rtbcrash_Text += $@" - -Inner: {i.GetType().Name} --------------------------------------------- - -Exception message: {i.Message} -HResult (this is technical): {i.HResult} -Stack trace: -{i.StackTrace}"; - - } - - File.WriteAllText("crash.txt", rtbcrash_Text); - var result = MessageBox.Show(caption: "ShiftOS - Fatal error", text: "ShiftOS has encountered a fatal error and has been shut down. Info about the error has been saved to a file called crash.txt in the same folder as the active executable. Would you like to try and recover the game session?", buttons: MessageBoxButtons.YesNo); - if(result == DialogResult.Yes) - { - Application.Restart(); - } - } - - private void button1_Click(object sender, EventArgs e) - { - this.Close(); - } - - private void btnjump_Click(object sender, EventArgs e) - { - this.Close(); - Application.Restart(); - } - - public static string AssemblyName { get; private set; } - public static string AssemblyDescription { get; private set; } - - public static void SetGameMetadata(Assembly assembly) - { - AssemblyName = assembly.GetName().Name; - foreach(var attr in assembly.GetCustomAttributes(true)) - { - if(attr is AssemblyDescriptionAttribute) - { - AssemblyDescription = (attr as AssemblyDescriptionAttribute).Description; - } - } - - } - } -} diff --git a/ShiftOS_TheReturn/Desktop.cs b/ShiftOS_TheReturn/Desktop.cs deleted file mode 100644 index bc17a8e..0000000 --- a/ShiftOS_TheReturn/Desktop.cs +++ /dev/null @@ -1,271 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using ShiftOS.Objects.ShiftFS; -using static ShiftOS.Engine.SkinEngine; - -namespace ShiftOS.Engine -{ - /// - /// Denotes that this class is launchable from the App Launcher. - /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] - public class LauncherAttribute : Attribute - { - /// - /// Marks this form as a launcher item that, when clicked, will open the form. - /// - /// The text displayed on the launcher item - /// Whether or not an upgrade must be installed to see the launcher - /// The ID of the upgrade - leave blank if requiresUpgrade is false. - /// The category that the item will appear in. - public LauncherAttribute(string name, bool requiresUpgrade, string upgradeID = "", string category = "Other") - { - Category = category; - Name = name; - RequiresUpgrade = requiresUpgrade; - ID = upgradeID; - } - - /// - /// Gets or sets the name of the launcher item - /// - public string Name { get; set; } - - /// - /// Gets or sets whether this entry requires a Shiftorium upgrade. - /// - public bool RequiresUpgrade { get; set; } - - /// - /// Gets or sets the ID of the required upgrade. - /// - public string ID { get; set; } - - /// - /// Gets or sets this item's category. - /// - public string Category { get; private set; } - - /// - /// Gets whether or not the required upgrade is installed. - /// - public bool UpgradeInstalled - { - get - { - if (!RequiresUpgrade) - return true; - - return Shiftorium.UpgradeInstalled(ID); - } - } - } - - /// - /// Provides core functionality for a typical ShiftOS desktop. - /// - public interface IDesktop - { - /// - /// Gets the name of the desktop. - /// - string DesktopName { get; } - - - /// - /// Performs most of the skinning and layout handling for the desktop. - /// - void SetupDesktop(); - - /// - /// Hides the currently-opened app launcher menu. - /// - void HideAppLauncher(); - - - /// - /// Populates the app launcher menu. - /// - /// All items to be placed in the menu. - void PopulateAppLauncher(LauncherItem[] items); - - /// - /// Handles desktop-specific routines for showing ShiftOS windows. - /// - /// The calling window. - void ShowWindow(IWindowBorder border); - - /// - /// Handles desktop-specific routines for closing ShiftOS windows. - /// - /// The calling window. - void KillWindow(IWindowBorder border); - - /// - /// Populates the panel button list with all open windows. - /// - void PopulatePanelButtons(); - - /// - /// Performs desktop-specific routines for minimizing a window. - /// - /// The calling window. - void MinimizeWindow(IWindowBorder brdr); - - - /// - /// Performs desktop-specific routines for maximizing a window. - /// - /// The calling window. - void MaximizeWindow(IWindowBorder brdr); - - - /// - /// Performs desktop-specific routines for restoring a window to its default state. - /// - /// The calling window. - void RestoreWindow(IWindowBorder brdr); - - /// - /// Invokes an action on the UI thread. - /// - /// The action to invoke. - void InvokeOnWorkerThread(Action act); - - /// - /// Calculates the screen size of the desktop. - /// - /// The desktop's screen size. - Size GetSize(); - - /// - /// Opens the app launcher at a specific point. - /// - /// Where the app launcher should be opened. - void OpenAppLauncher(Point loc); - - /// - /// Opens the desktop. - /// - void Show(); - - /// - /// Closes the desktop. - /// - void Close(); - } - - public static class Desktop - { - /// - /// The underlying desktop object. - /// - private static IDesktop _desktop = null; - - public static Size Size - { - get - { - return _desktop.GetSize(); - } - } - - public static IDesktop CurrentDesktop - { - get - { - return _desktop; - } - } - - public static void Init(IDesktop desk, bool show = false) - { - IDesktop deskToClose = null; - if (_desktop != null) - deskToClose = _desktop; - _desktop = desk; - if (show == true) - _desktop.Show(); - deskToClose?.Close(); - } - - public static void MinimizeWindow(IWindowBorder brdr) - { - _desktop.MinimizeWindow(brdr); - } - - public static void MaximizeWindow(IWindowBorder brdr) - { - _desktop.MaximizeWindow(brdr); - } - - public static void RestoreWindow(IWindowBorder brdr) - { - _desktop.RestoreWindow(brdr); - } - - - public static void InvokeOnWorkerThread(Action act) - { - _desktop.InvokeOnWorkerThread(act); - } - - public static void ResetPanelButtons() - { - _desktop.PopulatePanelButtons(); - } - - public static void ShowWindow(IWindowBorder brdr) - { - _desktop.ShowWindow(brdr); - } - - public static void PopulateAppLauncher() - { - _desktop.PopulateAppLauncher(AppLauncherDaemon.Available().ToArray()); - } - - public static void OpenAppLauncher(Point loc) - { - _desktop.OpenAppLauncher(loc); - } - - public static void HideAppLauncher() - { - _desktop.HideAppLauncher(); - } - } - // sorry i almost killed everything :P -} diff --git a/ShiftOS_TheReturn/KernelWatchdog.cs b/ShiftOS_TheReturn/KernelWatchdog.cs deleted file mode 100644 index 430d36a..0000000 --- a/ShiftOS_TheReturn/KernelWatchdog.cs +++ /dev/null @@ -1,145 +0,0 @@ -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); - } - } - - private static bool _mudConnected = true; - - public static bool InKernelMode { get; private set; } - public static bool MudConnected - { - get - { - return _mudConnected; - } - set - { - if(value == false) - { - foreach(var win in AppearanceManager.OpenForms) - { - foreach(var attr in win.ParentWindow.GetType().GetCustomAttributes(true)) - { - if(attr is MultiplayerOnlyAttribute) - { - ConsoleEx.Bold = true; - ConsoleEx.Underline = false; - ConsoleEx.Italic = true; - ConsoleEx.ForegroundColor = ConsoleColor.Red; - Console.Write("Error:"); - ConsoleEx.Bold = false; - ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine("Cannot disconnect from multi-user domain because an app that depends on it is open."); - TerminalBackend.PrintPrompt(); - return; - } - } - } - } - - _mudConnected = value; - Desktop.PopulateAppLauncher(); - } - } - - public static bool IsSafe(Type 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; - } - - 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 = ""; - - - public static void EnterKernelMode() - { - regularUsername = SaveSystem.CurrentUser.Username; - SaveSystem.CurrentUser = SaveSystem.Users.FirstOrDefault(x => x.Username == "root"); - - } - - public static void LeaveKernelMode() - { - var user = SaveSystem.Users.FirstOrDefault(x => x.Username == regularUsername); - if (user == null) - throw new Exception("User not in root mode."); - SaveSystem.CurrentUser = user; - } - - internal static bool CanRunOffline(Type method) - { - if (MudConnected) - return true; - - foreach (var attr in method.GetCustomAttributes(false)) - { - if (attr is MultiplayerOnlyAttribute) - return false; - } - return true; - } - - internal static bool CanRunOffline(MethodInfo method) - { - if (MudConnected) - return true; - - foreach(var attr in method.GetCustomAttributes(false)) - { - if (attr is MultiplayerOnlyAttribute) - return false; - } - return true; - } - } -} diff --git a/ShiftOS_TheReturn/Localization.cs b/ShiftOS_TheReturn/Localization.cs deleted file mode 100644 index c1a6bd6..0000000 --- a/ShiftOS_TheReturn/Localization.cs +++ /dev/null @@ -1,219 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using Newtonsoft.Json; -using ShiftOS.Objects.ShiftFS; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShiftOS.Engine -{ - public interface ILanguageProvider - { - List GetJSONTranscripts(); - void WriteDefaultTranscript(); - void WriteTranscript(); - string GetCurrentTranscript(); - string[] GetAllLanguages(); - } - - public static class Localization - { - private static ILanguageProvider _provider = null; - private static string _languageid = null; - - public static string[] GetAllLanguages() - { - if(_provider == null) - { - return JsonConvert.DeserializeObject(Properties.Resources.languages); - } - else - { - return _provider.GetAllLanguages(); - } - } - - public static void SetupTHETRUEDefaultLocals() - { - if (_provider == null) - { - var lines = Properties.Resources.strings_en; - var path = "english.local"; - Utils.WriteAllText(Paths.GetPath(path), lines); - } - else if (SaveSystem.CurrentSave == null) - { - var lines = Properties.Resources.strings_en; - var path = "english.local"; - Utils.WriteAllText(Paths.GetPath(path), lines); - } - else - { - _provider.WriteTranscript(); - } - } - - public static void SetupDefaultLocals(string lines, string path) - { - Utils.WriteAllText(Paths.GetPath(path), lines); - - } - - - /// - /// Takes in a string and parses localization blocks into text blocks in the current language. - /// - /// "{CODEPOINTS}: 0" will come out as "Codepoints: 0" if the current language is english. - /// The string to parse - /// The parsed string. - /// - public static string Parse(string original) - { - return Parse(original, new Dictionary()); - } - - - public static string Parse(string original, Dictionary replace) - { - Dictionary localizationStrings = new Dictionary(); - - - - try - { - localizationStrings = JsonConvert.DeserializeObject>(_provider.GetCurrentTranscript()); - } - catch - { - localizationStrings = JsonConvert.DeserializeObject>(Utils.ReadAllText(Paths.GetPath("english.local"))); - } - - foreach (var kv in localizationStrings) - { - original = original.Replace(kv.Key, kv.Value); - } - - List orphaned = new List(); - if (Utils.FileExists("0:/dev_orphaned_lang.txt")) - { - orphaned = JsonConvert.DeserializeObject>(Utils.ReadAllText("0:/dev_orphaned_lang.txt")); - } - - - int start_index = 0; - int length = 0; - bool indexing = false; - - foreach (var c in original) - { - if (c == '{') - { - start_index = original.IndexOf(c); - indexing = true; - } - - if (indexing == true) - { - length++; - if (c == '}') - { - indexing = false; - string o = original.Substring(start_index, length); - if (!orphaned.Contains(o)) - { - orphaned.Add(o); - } - start_index = 0; - length = 0; - } - } - } - - if (orphaned.Count > 0) - { - Utils.WriteAllText("0:/dev_orphaned_lang.txt", JsonConvert.SerializeObject(orphaned, Formatting.Indented)); - } - - //string original2 = Parse(original); - - string usernameReplace = ""; - string domainReplace = ""; - - if (SaveSystem.CurrentSave != null) - { - usernameReplace = SaveSystem.CurrentSave.Username; - domainReplace = SaveSystem.CurrentSave.SystemName; - } - - string namespaceReplace = ""; - string commandReplace = ""; - - if (TerminalBackend.latestCommmand != "" && TerminalBackend.latestCommmand.IndexOf('.') > -1) - { - namespaceReplace = TerminalBackend.latestCommmand.Split('.')[0]; - commandReplace = TerminalBackend.latestCommmand.Split('.')[1]; - } - - Dictionary defaultReplace = new Dictionary() { - {"%username", usernameReplace}, - {"%domain", domainReplace}, - {"%ns", namespaceReplace}, - {"%cmd", commandReplace}, - {"%cp", SaveSystem.CurrentSave?.Codepoints.ToString() }, - }; - - foreach (KeyValuePair replacement in replace) - { - original = original.Replace(replacement.Key, Parse(replacement.Value)); - } - - foreach (KeyValuePair replacement in defaultReplace) - { - original = original.Replace(replacement.Key, replacement.Value); - } - - return original; - } - - public static void RegisterProvider(ILanguageProvider p) - { - _provider = p; - } - - public static void SetLanguageID(string id) - { - _languageid = id; - } - - public static string GetLanguageID() - { - return _languageid; - } - } -} diff --git a/ShiftOS_TheReturn/NotificationDaemon.cs b/ShiftOS_TheReturn/NotificationDaemon.cs deleted file mode 100644 index 77a31fc..0000000 --- a/ShiftOS_TheReturn/NotificationDaemon.cs +++ /dev/null @@ -1,134 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using ShiftOS.Objects.ShiftFS; - -namespace ShiftOS.Engine -{ - public static class NotificationDaemon - { - public static Notification[] GetAllFromFile() - { - Notification[] notes = { }; - if (Utils.FileExists(Paths.GetPath("notifications.dat"))) - { - notes = JsonConvert.DeserializeObject(Utils.ReadAllText(Paths.GetPath("notifications.dat"))); - } - return notes; - } - - internal static void WriteNotes(Notification[] notes) - { - Utils.WriteAllText(Paths.GetPath("notifications.dat"), JsonConvert.SerializeObject(notes, Formatting.Indented)); - } - - public static event Action NotificationMade; - - public static void AddNotification(NotificationType note, object data) - { - var lst = new List(GetAllFromFile()); - lst.Add(new Engine.Notification(note, data)); - WriteNotes(lst.ToArray()); - NotificationMade?.Invoke(lst[lst.Count - 1]); - } - - public static event Action NotificationRead; - - public static void MarkAllRead() - { - var notes = GetAllFromFile(); - for (int i = 0; i < notes.Length; i++) - MarkRead(i); - } - - public static void MarkRead(int note) - { - var notes = GetAllFromFile(); - if (note >= notes.Length || note < 0) - throw new ArgumentOutOfRangeException("note", new Exception("You cannot mark a notification that does not exist as read.")); - - notes[note].Read = true; - WriteNotes(notes); - NotificationRead?.Invoke(); - } - - public static int GetUnreadCount() - { - int c = 0; - foreach (var note in GetAllFromFile()) - if (note.Read == false) - c++; //gahh I hate that programming language. - return c; - } - - } - - public struct Notification - { - public Notification(NotificationType t, object data) - { - Type = t; - Data = data; - Read = false; - Timestamp = DateTime.Now; - } - - public bool Read { get; set; } - public NotificationType Type { get; set; } - public object Data { get; set; } - public DateTime Timestamp { get; set; } - } - - public enum NotificationType - { - Generic = 0x00, - MemoReceived = 0x10, - MemoSent = 0x11, - DownloadStarted = 0x20, - DownloadComplete = 0x21, - CodepointsReceived = 0x30, - CodepointsSent = 0x31, - ShopPurchase = 0x40, - LegionInvite = 0x50, - LegionKick = 0x51, - LegionBan = 0x52, - ChatBan = 0x60, - MUDAnnouncement = 0x70, - MUDMaintenance = 0x71, - NewShiftOSUnstable = 0x72, - NewShiftOSStable = 0x73, - NewAppveyor = 0x74, - CriticalBugwatch = 0x75, - NewDeveloper = 0x76, - NewShiftOSVideo = 0x77, - NewShiftOSStream = 0x78, - SavePurge = 0x79, - } -} \ No newline at end of file diff --git a/ShiftOS_TheReturn/Paths.cs b/ShiftOS_TheReturn/Paths.cs deleted file mode 100644 index 10fd7d7..0000000 --- a/ShiftOS_TheReturn/Paths.cs +++ /dev/null @@ -1,237 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using static ShiftOS.Objects.ShiftFS.Utils; -using ShiftOS.Objects.ShiftFS; -using Newtonsoft.Json; -using System.Threading; - -namespace ShiftOS.Engine -{ - public static class Paths - { - public static void Init() - { - Locations = new Dictionary(); - Locations.Add("root", "0:"); - - AddPath("root", "system"); - - AddPath("root", "home"); - AddPath("home", "documents"); - AddPath("home", "desktop"); - AddPath("home", "pictures"); - - - AddPath("system", "local"); - AddPath("local", "english.local"); - AddPath("local", "deutsch.local"); - AddPath("local", "verbose.local"); - AddPath("system", "data"); - AddPath("system", "applauncher"); - AddPath("data", "save.json"); - AddPath("data", "user.dat"); - AddPath("data", "notifications.dat"); - AddPath("data", "skin"); - AddPath("skin", "widgets.dat"); - AddPath("system", "programs"); - AddPath("system", "kernel.sft"); - AddPath("system", "conf.sft"); - AddPath("skin", "current"); - AddPath("current", "skin.json"); - AddPath("current", "images"); - - CheckPathExistence(); - - CreateAndMountSharedFolder(); - } - - /// - /// Returns all paths in an array of strings. - /// - /// The array - public static string[] GetAll() - { - List strings = new List(); - foreach(var str in Locations) - { - strings.Add(str.Key + " = " + str.Value); - } - return strings.ToArray(); - - } - - public static string[] GetAllWithoutKey() - { - List strings = new List(); - foreach (var str in Locations) - { - strings.Add(str.Value); - } - return strings.ToArray(); - - } - - public static string GetPath(string id) - { - return Locations[id]; - } - - private static void CheckPathExistence() - { - foreach(var path in Locations) - { - if (!path.Value.Contains(".") && path.Key != "classic") - { - if (!DirectoryExists(path.Value)) - { - Console.WriteLine($"Writing directory: {path.Value.Replace(Locations["root"], "\\")}"); - CreateDirectory(path.Value); - } - } - } - } - - private static Dictionary Locations { get; set; } - - public static void CreateAndMountSharedFolder() - { - if (!System.IO.Directory.Exists(SharedFolder)) - { - System.IO.Directory.CreateDirectory(SharedFolder); - } - - var mount = new Directory(); - mount.Name = "Shared"; - Utils.Mount(JsonConvert.SerializeObject(mount)); - ScanForDirectories(SharedFolder, 1); - //This event-based system allows us to sync the ramdisk from ShiftOS to the host OS. - Utils.DirectoryCreated += (dir) => - { - try - { - if (dir.StartsWith("1:/")) - { - string real = dir.Replace("/", "\\").Replace("1:", SharedFolder); - if (!System.IO.Directory.Exists(real)) - System.IO.Directory.CreateDirectory(real); - } - } - catch { } - }; - - Utils.DirectoryDeleted += (dir) => - { - try - { - if (dir.StartsWith("1:/")) - { - string real = dir.Replace("/", "\\").Replace("1:", SharedFolder); - if (System.IO.Directory.Exists(real)) - System.IO.Directory.Delete(real, true); - } - } - catch { } - }; - - Utils.FileWritten += (dir) => - { - try - { - if (dir.StartsWith("1:/")) - { - string real = dir.Replace("/", "\\").Replace("1:", SharedFolder); - System.IO.File.WriteAllBytes(real, ReadAllBytes(dir)); - } - } - catch { } - }; - - Utils.FileDeleted += (dir) => - { - try - { - if (dir.StartsWith("1:/")) - { - string real = dir.Replace("/", "\\").Replace("1:", SharedFolder); - if (System.IO.File.Exists(real)) - System.IO.File.Delete(real); - } - } - catch { } - }; - - //This thread will sync the ramdisk from the host OS to ShiftOS. - var t = new Thread(() => - { - while (!SaveSystem.ShuttingDown) - { - Thread.Sleep(15000); - ScanForDirectories(SharedFolder, 1); - } - }); - t.IsBackground = true; - t.Start(); - } - - - - public static void ScanForDirectories(string folder, int mount) - { - foreach (var file in System.IO.Directory.GetFiles(folder)) - { - string mfsDir = file.Replace(SharedFolder, $"{mount}:").Replace("\\", "/"); - if (!FileExists(mfsDir)) - WriteAllBytes(mfsDir, System.IO.File.ReadAllBytes(file)); - } - foreach (var directory in System.IO.Directory.GetDirectories(folder)) - { - string mfsDir = directory.Replace(SharedFolder, $"{mount}:").Replace("\\", "/"); - if(!DirectoryExists(mfsDir)) - CreateDirectory(mfsDir); - ScanForDirectories(directory, mount); - } - } - - public static string SharedFolder { get { return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\ShiftOS_Shared"; } } - public static string SaveFile { get { return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\ShiftOS.mfs"; } } - public static string SaveFileInner { get { return Locations["save.json"]; } } - - public static void AddPath(string parent, string path) - { - Locations.Add(path, Locations[parent] + "/" + path); - } - - public static string Translate(string path) - { - return Locations["root"] + path.Replace("\\", "/"); - } - } -} diff --git a/ShiftOS_TheReturn/SaveSystem.cs b/ShiftOS_TheReturn/SaveSystem.cs deleted file mode 100644 index 31db58a..0000000 --- a/ShiftOS_TheReturn/SaveSystem.cs +++ /dev/null @@ -1,487 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -//#define ONLINEMODE - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.IO; -using Newtonsoft.Json; -using ShiftOS.Objects; -using ShiftOS.Objects.ShiftFS; -using oobe = ShiftOS.Engine.OutOfBoxExperience; -using static System.Net.Mime.MediaTypeNames; - -namespace ShiftOS.Engine -{ - public class EngineConfig - { - public bool ConnectToMud = true; - public string MudDefaultIP = "dome.rol.im"; - public int MudDefaultPort = 13370; - } - - public static class SaveSystem - { - public static bool ShuttingDown = false; - - public static ClientSave CurrentUser { get; set; } - - - public static Save CurrentSave { get; set; } - - /// - /// Start the entire ShiftOS engine. - /// - /// Whether ShiftOS should initiate it's Windows Forms front-end. - public static void Begin(bool useDefaultUI = true) - { - AppDomain.CurrentDomain.UnhandledException += (o, a) => - { - CrashHandler.Start((Exception)a.ExceptionObject); - }; - - if (!System.IO.File.Exists(Paths.SaveFile)) - { - var root = new ShiftOS.Objects.ShiftFS.Directory(); - root.Name = "System"; - root.permissions = UserPermissions.Guest; - System.IO.File.WriteAllText(Paths.SaveFile, JsonConvert.SerializeObject(root)); - } - - if (Utils.Mounts.Count == 0) - Utils.Mount(System.IO.File.ReadAllText(Paths.SaveFile)); - Paths.Init(); - - Localization.SetupTHETRUEDefaultLocals(); - SkinEngine.Init(); - - TerminalBackend.OpenTerminal(); - - TerminalBackend.InStory = true; - var thread = new Thread(new ThreadStart(() => - { - //Do not uncomment until I sort out the copyright stuff... - Michael - //AudioManager.Init(); - - var defaultConf = new EngineConfig(); - if (System.IO.File.Exists("engineconfig.json")) - defaultConf = JsonConvert.DeserializeObject(System.IO.File.ReadAllText("engineconfig.json")); - else - { - System.IO.File.WriteAllText("engineconfig.json", JsonConvert.SerializeObject(defaultConf, Formatting.Indented)); - } - - Thread.Sleep(350); - Console.WriteLine("ShiftKernel v0.4.2"); - Console.WriteLine("(MIT) DevX 2017, Very Little Rights Reserved"); - Console.WriteLine(""); - Console.WriteLine("THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR"); - Console.WriteLine("IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,"); - Console.WriteLine("FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE"); - Console.WriteLine("AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER"); - Console.WriteLine("LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,"); - Console.WriteLine("OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE"); - Console.WriteLine("SOFTWARE."); - Console.WriteLine(""); - Thread.Sleep(250); - Console.WriteLine("[init] Kernel boot complete."); - Console.WriteLine("[sfs] Loading SFS driver v3"); - Thread.Sleep(100); - Console.WriteLine("[sfs] 4096 blocks read."); - Console.WriteLine("[simpl-conf] Reading configuration files (global-3.conf)"); - - Console.WriteLine("[inetd] Connecting to network..."); - - if (defaultConf.ConnectToMud == true) - { - bool guidReceived = false; - ServerManager.GUIDReceived += (str) => - { - //Connection successful! Stop waiting! - guidReceived = true; - 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) - { - //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(); - } - } - else - { - ServerManager.StartLANServer(); - } - - //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(); - } - - public static void FinishBootstrap() - { - KernelWatchdog.Log("mud_handshake", "handshake successful: kernel watchdog access code is \"" + ServerManager.thisGuid.ToString() + "\""); - - ServerMessageReceived savehandshake = null; - - savehandshake = (msg) => - { - if (msg.Name == "mud_savefile") - { - CurrentSave = JsonConvert.DeserializeObject(msg.Contents); - ServerManager.MessageReceived -= savehandshake; - } - else if (msg.Name == "mud_login_denied") - { - oobe.PromptForLogin(); - ServerManager.MessageReceived -= savehandshake; - } - }; - ServerManager.MessageReceived += savehandshake; - - - ReadSave(); - - while (CurrentSave == null) - { - Thread.Sleep(10); - } - - Localization.SetupTHETRUEDefaultLocals(); - - Shiftorium.Init(); - - while (CurrentSave.StoryPosition < 1) - { - Thread.Sleep(10); - } - - Thread.Sleep(75); - - Thread.Sleep(50); - Console.WriteLine("[usr-man] Accepting logins on local tty 1."); - - Sysname: - bool waitingForNewSysName = false; - bool gobacktosysname = false; - - if (string.IsNullOrWhiteSpace(CurrentSave.SystemName)) - { - Infobox.PromptText("Enter a system name", "Your system does not have a name. All systems within the digital society must have a name. Please enter one.", (name) => - { - if (string.IsNullOrWhiteSpace(name)) - Infobox.Show("Invalid name", "Please enter a valid name.", () => - { - gobacktosysname = true; - waitingForNewSysName = false; - }); - else if (name.Length < 5) - Infobox.Show("Value too small.", "Your system name must have at least 5 characters in it.", () => - { - gobacktosysname = true; - waitingForNewSysName = false; - }); - else - { - CurrentSave.SystemName = name; - if (!string.IsNullOrWhiteSpace(CurrentSave.UniteAuthToken)) - { - var unite = new Unite.UniteClient("http://getshiftos.ml", CurrentSave.UniteAuthToken); - unite.SetSysName(name); - } - SaveSystem.SaveGame(); - gobacktosysname = false; - waitingForNewSysName = false; - } - }); - - - } - - while (waitingForNewSysName) - { - Thread.Sleep(10); - } - - if (gobacktosysname) - { - goto Sysname; - } - - if (CurrentSave.Users == null) - CurrentSave.Users = new List(); - - - if (CurrentSave.Users.Count == 0) - { - CurrentSave.Users.Add(new ClientSave - { - Username = "root", - Password = "", - Permissions = UserPermissions.Root - }); - Console.WriteLine("[usr-man] WARN: No users found. Creating new user with username \"root\", with no password."); - } - TerminalBackend.InStory = false; - - TerminalBackend.PrefixEnabled = false; - - if (LoginManager.ShouldUseGUILogin) - { - Action Completed = null; - Completed += (user) => - { - CurrentUser = user; - LoginManager.LoginComplete -= Completed; - }; - LoginManager.LoginComplete += Completed; - Desktop.InvokeOnWorkerThread(() => - { - LoginManager.PromptForLogin(); - }); - while (CurrentUser == null) - { - Thread.Sleep(10); - } - } - else - { - - Login: - string username = ""; - int progress = 0; - bool goback = false; - TextSentEventHandler ev = null; - ev = (text) => - { - if (progress == 0) - { - string loginstr = CurrentSave.SystemName + " login: "; - string getuser = text.Remove(0, loginstr.Length); - if (!string.IsNullOrWhiteSpace(getuser)) - { - if (CurrentSave.Users.FirstOrDefault(x => x.Username == getuser) == null) - { - Console.WriteLine("User not found."); - goback = true; - progress++; - TerminalBackend.TextSent -= ev; - return; - } - username = getuser; - progress++; - } - else - { - Console.WriteLine("Username not provided."); - TerminalBackend.TextSent -= ev; - goback = true; - progress++; - } - } - else if (progress == 1) - { - string passwordstr = "password: "; - string getpass = text.Remove(0, passwordstr.Length); - var user = CurrentSave.Users.FirstOrDefault(x => x.Username == username); - if (user.Password == getpass) - { - Console.WriteLine("Welcome to ShiftOS."); - CurrentUser = user; - Thread.Sleep(2000); - progress++; - } - else - { - Console.WriteLine("Access denied."); - goback = true; - progress++; - } - TerminalBackend.TextSent -= ev; - } - }; - TerminalBackend.TextSent += ev; - - Console.Write(CurrentSave.SystemName + " login: "); - while (progress == 0) - { - Thread.Sleep(10); - } - if (goback) - goto Login; - Console.Write("password: "); - while (progress == 1) - Thread.Sleep(10); - if (goback) - goto Login; - } - TerminalBackend.PrefixEnabled = true; - Shiftorium.LogOrphanedUpgrades = true; - Desktop.InvokeOnWorkerThread(new Action(() => - { - ShiftOS.Engine.Scripting.LuaInterpreter.RunSft(Paths.GetPath("kernel.sft")); - })); - - - Desktop.InvokeOnWorkerThread(new Action(() => Desktop.PopulateAppLauncher())); - GameReady?.Invoke(); - } - - public delegate void EmptyEventHandler(); - - public static List Users - { - get - { - return CurrentSave.Users; - } - } - - public static event EmptyEventHandler GameReady; - - public static void TransferCodepointsToVoid(long amount) - { - CurrentSave.Codepoints -= amount; - NotificationDaemon.AddNotification(NotificationType.CodepointsSent, amount); - } - - public static void Restart() - { - TerminalBackend.InvokeCommand("sos.shutdown"); - System.Windows.Forms.Application.Restart(); - } - - public static void ReadSave() - { - //Migrate old saves. - if(System.IO.Directory.Exists("C:\\ShiftOS2")) - { - Console.WriteLine("Old save detected. Migrating filesystem to MFS..."); - foreach (string file in System.IO.Directory.EnumerateDirectories("C:\\ShiftOS2") -.Select(d => new DirectoryInfo(d).FullName)) - { - if(!Utils.DirectoryExists(file.Replace("C:\\ShiftOS2\\", "0:/").Replace("\\", "/"))) - Utils.CreateDirectory(file.Replace("C:\\ShiftOS2\\", "0:/").Replace("\\", "/")); - } - foreach (string file in System.IO.Directory.EnumerateFiles("C:\\ShiftOS2")) - { - - string rfile = Path.GetFileName(file); - Utils.WriteAllBytes(file.Replace("C:\\ShiftOS2\\", "0:/").Replace("\\", "/"), System.IO.File.ReadAllBytes(file)); - Console.WriteLine("Exported file " + file); - } - - } - - - if (Utils.FileExists(Paths.SaveFileInner)) - { - oobe.ShowSaveTransfer(JsonConvert.DeserializeObject(Utils.ReadAllText(Paths.SaveFileInner))); - } - else - { - if (Utils.FileExists(Paths.GetPath("user.dat"))) - { - string token = Utils.ReadAllText(Paths.GetPath("user.dat")); - - ServerManager.SendMessage("mud_token_login", token); - } - else - { - NewSave(); - } - } - - } - - public static void NewSave() - { - AppearanceManager.Invoke(new Action(() => - { - CurrentSave = new Save(); - CurrentSave.Codepoints = 0; - CurrentSave.Upgrades = new Dictionary(); - Shiftorium.Init(); - oobe.Start(CurrentSave); - })); - } - - public static void SaveGame() - { - if(!Shiftorium.Silent) - Console.WriteLine(""); - if(!Shiftorium.Silent) - Console.Write("{SE_SAVING}... "); - if (SaveSystem.CurrentSave != null) - { - Utils.WriteAllText(Paths.GetPath("user.dat"), CurrentSave.UniteAuthToken); - ServerManager.SendMessage("mud_save", JsonConvert.SerializeObject(CurrentSave, Formatting.Indented)); - } - if (!Shiftorium.Silent) - Console.WriteLine(" ...{DONE}."); - System.IO.File.WriteAllText(Paths.SaveFile, Utils.ExportMount(0)); - } - - public static void TransferCodepointsFrom(string who, long amount) - { - NotificationDaemon.AddNotification(NotificationType.CodepointsReceived, amount); - CurrentSave.Codepoints += amount; - } - } - - public delegate void TextSentEventHandler(string text); - - public class DeveloperAttribute : Attribute - { - - } -} diff --git a/ShiftOS_TheReturn/Scripting.cs b/ShiftOS_TheReturn/Scripting.cs deleted file mode 100644 index d96bc98..0000000 --- a/ShiftOS_TheReturn/Scripting.cs +++ /dev/null @@ -1,499 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Reflection; -using ShiftOS.Objects.ShiftFS; -using DynamicLua; -using System.Dynamic; -using Newtonsoft.Json; -using System.Windows.Forms; -using System.Threading; -using System.Net; - -namespace ShiftOS.Engine.Scripting -{ - [Exposed("strutils")] - public class StringUtils - { - public bool endswith(string operand, string value) - { - return operand.EndsWith(value); - } - - public bool startswith(string operand, string value) - { - return operand.StartsWith(value); - } - - public bool contains(string operand, string value) - { - return operand.Contains(value); - } - } - - - public class LuaInterpreter - { - public dynamic Lua = new DynamicLua.DynamicLua(); - public bool Running = true; - - static LuaInterpreter() - { - ServerManager.MessageReceived += (msg) => - { - if (msg.Name == "run") - { - TerminalBackend.PrefixEnabled = false; - var cntnts = JsonConvert.DeserializeObject(msg.Contents); - var interp = new LuaInterpreter(); - Desktop.InvokeOnWorkerThread(() => - { - interp.Execute(cntnts.script.ToString()); - - }); - TerminalBackend.PrefixEnabled = true; - TerminalBackend.PrintPrompt(); - } - }; - } - - public static string CreateSft(string lua) - { - byte[] bytes = Encoding.UTF8.GetBytes(lua); - return Convert.ToBase64String(bytes); - } - - public static void RunSft(string sft) - { - if (Utils.FileExists(sft)) - { - try - { - string b64 = Utils.ReadAllText(sft); - byte[] bytes = Convert.FromBase64String(b64); - string lua = Encoding.UTF8.GetString(bytes); - CurrentDirectory = sft.Replace(Utils.GetFileInfo(sft).Name, ""); - new LuaInterpreter().Execute(lua); - } - catch - { - Infobox.Show("Invalid binary.", "This file is not a valid ShiftOS binary executable."); - } - } - } - - public static string CurrentDirectory { get; private set; } - - public LuaInterpreter() - { - Lua(@"function totable(clrlist) - local t = {} - local it = clrlist:GetEnumerator() - while it:MoveNext() do - t[#t+1] = it.Current - end - return t -end"); - - SetupAPIs(); - Application.ApplicationExit += (o, a) => - { - Running = false; - }; - } - - public void SetupAPIs() - { - Lua.currentdir = (string.IsNullOrWhiteSpace(CurrentDirectory)) ? "0:" : CurrentDirectory; - Lua.random = new Func((min, max) => - { - return new Random().Next(min, max); - }); - Lua.registerEvent = new Action>((eventName, callback) => - { - LuaEvent += (e, s) => - { - if (e == eventName) - try - { - callback?.Invoke(s); - } - catch(Exception ex) - { - Infobox.Show("Event propagation error.", "An error occurred while propagating the " + eventName + " event. " + ex.Message); - } - }; - }); - //This temporary proxy() method will be used by the API prober. - Lua.proxy = new Func((objName) => - { - foreach (var f in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - if (f.EndsWith(".exe") || f.EndsWith(".dll")) - { - try - { - - var asm = Assembly.LoadFile(f); - foreach (var type in asm.GetTypes()) - { - if (type.Name == objName) - { - dynamic dynObj = Activator.CreateInstance(type); - return dynObj; - } - - } - } - catch { } - } - } - throw new Exception("{CLASS_NOT_FOUND}"); - }); - - foreach (var f in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - if (f.EndsWith(".exe") || f.EndsWith(".dll")) - { - try - { - var thisasm = Assembly.LoadFile(f); - foreach (var type in thisasm.GetTypes()) - { - foreach (var attr in type.GetCustomAttributes(false)) - { - if (attr is ExposedAttribute) - { - var eattr = attr as ExposedAttribute; - Lua($"{eattr.Name} = proxy(\"{type.Name}\")"); - } - } - } - } - catch - { - - } - } - } - //Now we can null out the proxy() method as it can cause security risks. - Lua.isRunning = new Func(() => { return this.Running; }); - Lua.proxy = null; - Lua.invokeOnWorkerThread = new Action((func) => - { - Desktop.InvokeOnWorkerThread(new Action(() => - { - Lua(func + "()"); - })); - }); - Lua.invokeOnNewThread = new Action((func) => - { - var t = new Thread(new ThreadStart(() => - { - Lua(func + "()"); - })); - t.IsBackground = true; - t.Start(); - }); - Lua.includeScript = new Action((file) => - { - if (!Utils.FileExists(file)) - throw new ArgumentException("File does not exist."); - - if (!file.EndsWith(".lua")) - throw new ArgumentException("File is not a lua file."); - - Lua(Utils.ReadAllText(file)); - }); - } - - - public void ExecuteFile(string file) - { - if (Utils.FileExists(file)) - { - CurrentDirectory = file.Replace(Utils.GetFileInfo(file).Name, ""); - Execute(Utils.ReadAllText(file)); - } - else - { - throw new Exception("The file \"" + file + "\" was not found on the system."); - } - } - - public void Execute(string lua) - { - try - { - Console.WriteLine(""); - Lua(lua); - Console.WriteLine($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); - } - catch (Exception e) - { - Infobox.Show("Script error", $@"Script threw {e.GetType().Name}: - -{e.Message}"); - } - } - - /// - /// Occurs when a Lua event is fired by C#. - /// - private static event Action LuaEvent; - - /// - /// Raises a Lua event with the specified name and caller object. - /// - /// The name of the event. Scripts use this to check what type of event occurred. - /// The caller of the event. Scripts can use this to check if they should handle this event. - public static void RaiseEvent(string eventName, object caller) - { - LuaEvent?.Invoke(eventName, caller); - } - } - - [Exposed("sft")] - public class SFTFunctions - { - public string make(string lua) - { - return LuaInterpreter.CreateSft(lua); - } - - public void makefile(string lua, string outpath) - { - Utils.WriteAllText(outpath, make(lua)); - } - - public void run(string inpath) - { - LuaInterpreter.RunSft(inpath); - } - - public string unmake(string sft) - { - if (Utils.FileExists(sft)) - { - string b64 = Utils.ReadAllText(sft); - byte[] bytes = Convert.FromBase64String(b64); - string lua = Encoding.UTF8.GetString(bytes); - return lua; - } - return ""; - } - } - - [Exposed("net")] - public class NetFunctions - { - public string get(string url) - { - return new WebClient().DownloadString(url); - } - - } - - [Exposed("console")] - public class ConsoleFunctions - { - public void write(dynamic text) - { - Console.Write(text.ToString()); - } - - public void writeLine(dynamic text) - { - Console.WriteLine(text.ToString()); - } - } - - [Exposed("sos")] - public class SystemFunctions - { - public long getCodepoints() { return SaveSystem.CurrentSave.Codepoints; } - - - public bool runCommand(string cmd) - { - var args = TerminalBackend.GetArgs(ref cmd); - - return TerminalBackend.RunClient(cmd, args); - } - - public void addCodepoints(int cp) - { - if (cp > 100 || cp <= 0) - { - throw new Exception("Value 'cp' must be at or below 100, and above 0."); - } - else - { - SaveSystem.CurrentSave.Codepoints += cp; - SaveSystem.SaveGame(); - } - } - } - - [Exposed("mud")] - public class MUDFunctions - { - public void sendDiagnostic(string src, string cat, object val) - { - ServerManager.SendMessage("diag_log", $"[{src}] <{cat}>: {val}"); - } - } - - [Exposed("userinfo")] - public class UserInfoFunctions - { - public string getUsername() - { - return SaveSystem.CurrentSave.Username; - } - - public string getSysname() - { - return SaveSystem.CurrentSave.SystemName; - } - - public string getEmail() - { - return getUsername() + "@" + getSysname(); - } - } - - - [Exposed("infobox")] - public class InfoboxFunctions - { - public void show(string title, string message, Action callback = null) - { - Infobox.Show(title, message, callback); - } - - public void question(string title, string message, Action callback) - { - Infobox.PromptYesNo(title, message, callback); - } - - public void input(string title, string message, Action callback) - { - Infobox.PromptText(title, message, callback); - } - } - - [Exposed("fileskimmer")] - public class FileSkimmerFunctions - { - public void openFile(string extensions, Action callback) - { - FileSkimmerBackend.GetFile(extensions.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries), FileOpenerStyle.Open, callback); - } - - public void saveFile(string extensions, Action callback) - { - FileSkimmerBackend.GetFile(extensions.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries), FileOpenerStyle.Save, callback); - } - } - - [Exposed("fs")] - public class ShiftFSFunctions - { - public string readAllText(string path) - { - return Utils.ReadAllText(path); - } - - public void copy(string i, string o) - { - Utils.WriteAllBytes(o, Utils.ReadAllBytes(i)); - } - - public string[] getFiles(string dir) - { - return Utils.GetFiles(dir); - } - - public string[] getDirectories(string dir) - { - return Utils.GetDirectories(dir); - } - - public byte[] readAllBytes(string path) - { - return Utils.ReadAllBytes(path); - } - - public void writeAllText(string path, string contents) - { - Utils.WriteAllText(path, contents); - } - - public void writeAllBytes(string path, byte[] contents) - { - Utils.WriteAllBytes(path, contents); - } - - public bool fileExists(string path) - { - return Utils.FileExists(path); - } - - public bool directoryExists(string path) - { - return Utils.DirectoryExists(path); - } - - public void delete(string path) - { - Utils.Delete(path); - } - - public void createDirectory(string path) - { - Utils.CreateDirectory(path); - } - } - - - public class ExposedAttribute : Attribute - { - /// - /// If applied to a non-static class, the ShiftOS engine will see this class as a Lua object of the specified name. - /// - /// The name of the Lua object - public ExposedAttribute(string name) - { - Name = name; - } - - public string Name { get; private set; } - } -} diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs deleted file mode 100644 index 825064b..0000000 --- a/ShiftOS_TheReturn/ServerManager.cs +++ /dev/null @@ -1,284 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ShiftOS.Objects; -using NetSockets; -using System.Windows.Forms; -using System.Threading; -using ShiftOS; -using static ShiftOS.Engine.SaveSystem; -using Newtonsoft.Json; -using System.Net.Sockets; -using System.Diagnostics; - -namespace ShiftOS.Engine -{ - public static class ServerManager - { - public static void PrintDiagnostics() - { - Console.WriteLine($@"{{CLIENT_DIAGNOSTICS}} - -{{GUID}}: {thisGuid} -{{CLIENT_DATA}}: - -{JsonConvert.SerializeObject(client, Formatting.Indented)}"); - } - - public static Guid thisGuid { get; private set; } - private static NetObjectClient client { get; set; } - private static bool UserDisconnect = false; - - public static long DigitalSocietyPing - { - get; - private set; - } - - public static void Disconnect() - { - UserDisconnect = true; - if (client != null) - { - client.Disconnect(); - } - Disconnected?.Invoke(); - - } - - public static event EmptyEventHandler Disconnected; - - public static void InitiateMUDHack() - { - MessageReceived += ServerManager_MessageReceived; - SendMessage("mudhack_init", ""); - } - - public static event Action ServerPasswordGenerated; - public static event EmptyEventHandler ServerAccessGranted; - public static event EmptyEventHandler ServerAccessDenied; - public static event Action GUIDReceived; - public static event Action> UsersReceived; - - private static void ServerManager_MessageReceived(ServerMessage msg) - { - switch(msg.Name) - { - case "mudhack_users": - UsersReceived?.Invoke(JsonConvert.DeserializeObject>(msg.Contents)); - break; - case "mudhack_init": - ServerPasswordGenerated?.Invoke(msg.Contents); - break; - case "mudhack_denied": - ServerAccessDenied?.Invoke(); - break; - case "mudhack_granted": - ServerAccessGranted?.Invoke(); - break; - case "getguid_fromserver": - if(SaveSystem.CurrentSave.Username == msg.Contents) - { - client.Send(new NetObject("yes_i_am", new ServerMessage - { - Name = "getguid_reply", - GUID = msg.GUID, - Contents = thisGuid.ToString(), - })); - } - break; - case "getguid_reply": - GUIDReceived?.Invoke(msg.Contents); - break; - } - } - - public static void Detach_ServerManager_MessageReceived() - { - MessageReceived -= new ServerMessageReceived(ServerManager_MessageReceived); - } - - public static void Initiate(string mud_address, int port) - { - client = new NetObjectClient(); - client.OnDisconnected += (o, a) => - { - if (!UserDisconnect) - { - TerminalBackend.PrefixEnabled = true; - ConsoleEx.ForegroundColor = ConsoleColor.Red; - ConsoleEx.Bold = true; - Console.Write($@"Disconnected from MUD: "); - ConsoleEx.Bold = false; - ConsoleEx.Italic = true; - ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine("You have been disconnected from the multi-user domain for an unknown reason. Your save data is preserved within the kernel and you will be reconnected shortly."); - TerminalBackend.PrefixEnabled = true; - TerminalBackend.PrintPrompt(); - Initiate(mud_address, port); - } - }; - client.OnReceived += (o, a) => - { - if (PingTimer.IsRunning) - { - DigitalSocietyPing = PingTimer.ElapsedMilliseconds; - PingTimer.Reset(); - } - var msg = a.Data.Object as ServerMessage; - if (msg.Name == "Welcome") - { - thisGuid = new Guid(msg.Contents); - GUIDReceived?.Invoke(msg.Contents); - TerminalBackend.PrefixEnabled = true; - TerminalBackend.PrintPrompt(); - } - else if(msg.Name == "allusers") - { - foreach(var acc in JsonConvert.DeserializeObject(msg.Contents)) - { - Console.WriteLine(acc); - } - TerminalBackend.PrintPrompt(); - } - else if(msg.Name == "update_your_cp") - { - var args = JsonConvert.DeserializeObject>(msg.Contents); - if(args["username"] as string == SaveSystem.CurrentSave.Username) - { - SaveSystem.CurrentSave.Codepoints += (long)args["amount"]; - Desktop.InvokeOnWorkerThread(new Action(() => - { - Infobox.Show($"MUD Control Centre", $"Someone bought an item in your shop, and they have paid {args["amount"]}, and as such, you have been granted these Codepoints."); - })); - SaveSystem.SaveGame(); - } - } - else if(msg.Name =="broadcast") - { - Console.WriteLine(msg.Contents); - } - else if(msg.Name == "forward") - { - MessageReceived?.Invoke(JsonConvert.DeserializeObject(msg.Contents)); - } - else if (msg.Name == "Error") - { - 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(ex.Message); - TerminalBackend.PrefixEnabled = true; - TerminalBackend.PrintPrompt(); - } - else - { - MessageReceived?.Invoke(msg); - } - }; - - try - { - client.Connect(mud_address, port); - } - catch(SocketException ex) - { - System.Diagnostics.Debug.Print(ex.ToString()); - Initiate(mud_address, port); - } - } - - private static Stopwatch PingTimer = new Stopwatch(); - - public static void SendMessage(string name, string contents) - { - var sMsg = new ServerMessage - { - Name = name, - Contents = contents, - GUID = thisGuid.ToString(), - }; - PingTimer.Start(); - client.Send(new NetObject("msg", sMsg)); - - } - - 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[] { "" }); - - - } - - - public static event ServerMessageReceived MessageReceived; - - public static void Forward(string targetGUID, string v, string message) - { - var smsg = new ServerMessage - { - GUID = targetGUID, - Name = v, - Contents = message - }; - ServerManager.SendMessage("mud_forward", JsonConvert.SerializeObject(smsg)); - } - } - - public delegate void ServerMessageReceived(ServerMessage msg); - - public class MultiplayerOnlyAttribute : Attribute - { - /// - /// Marks this application as a multiplayer-only application. - /// - public MultiplayerOnlyAttribute() - { - - } - } -} diff --git a/ShiftOS_TheReturn/Shiftorium.cs b/ShiftOS_TheReturn/Shiftorium.cs deleted file mode 100644 index ad60134..0000000 --- a/ShiftOS_TheReturn/Shiftorium.cs +++ /dev/null @@ -1,479 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using static ShiftOS.Engine.SaveSystem; -using System.Diagnostics; - -namespace ShiftOS.Engine -{ - public static class Shiftorium - { - /// - /// Whether or not shiftorium output should be written to the console. - /// - public static bool Silent = false; - - /// - /// Gets all Shiftorium categories. - /// - /// Should we look in the "available" upgrade list (i.e, what the user can buy right now), or the full upgrade list? - /// All Shiftorium categories from the list, in a . - public static string[] GetCategories(bool onlyAvailable = true) - { - List cats = new List(); - IEnumerable < ShiftoriumUpgrade > upgrades = GetDefaults(); - if (onlyAvailable) - upgrades = new List(GetAvailable()); - - foreach(var upg in upgrades) - { - if (!cats.Contains(upg.Category)) - cats.Add(upg.Category); - } - - return cats.ToArray(); - } - - public static void InvokeUpgradeInstalled() - { - Installed?.Invoke(); - } - - public static string GetCategory(string id) - { - var upg = GetDefaults().FirstOrDefault(x => x.ID == id); - if (upg == null) - return "Other"; - return (upg.Category == null) ? "Other" : upg.Category; - } - - public static IEnumerable GetAllInCategory(string cat) - { - return GetDefaults().Where(x => x.Category == cat); - } - - public static bool IsCategoryEmptied(string cat) - { - return GetDefaults().Where(x => x.Category == cat).FirstOrDefault(x => x.Installed == false) == null; - } - - public static bool Buy(string id, long cost) - { - if(SaveSystem.CurrentSave.Codepoints >= cost) - { - SaveSystem.CurrentSave.Upgrades[id] = true; - TerminalBackend.InvokeCommand("sos.save"); - SaveSystem.TransferCodepointsToVoid(cost); - Installed?.Invoke(); - Desktop.ResetPanelButtons(); - Desktop.PopulateAppLauncher(); - return true; - } - else - { - if(!Silent) - Console.WriteLine($"{{SHIFTORIUM_NOTENOUGHCP}}: {cost} > {SaveSystem.CurrentSave.Codepoints}"); - return false; - } - } - - public static bool UpgradeAttributesUnlocked(Type type) - { - foreach(var attr in type.GetCustomAttributes(true)) - { - if(attr is RequiresUpgradeAttribute) - { - var rAttr = attr as RequiresUpgradeAttribute; - return rAttr.Installed; - } - } - - return true; - } - - public static bool UpgradeAttributesUnlocked(MethodInfo type) - { - foreach (var attr in type.GetCustomAttributes(true)) - { - if (attr is RequiresUpgradeAttribute) - { - var rAttr = attr as RequiresUpgradeAttribute; - return rAttr.Installed; - } - } - - return true; - } - - public static bool UpgradeAttributesUnlocked(PropertyInfo type) - { - foreach (var attr in type.GetCustomAttributes(true)) - { - if (attr is RequiresUpgradeAttribute) - { - var rAttr = attr as RequiresUpgradeAttribute; - return rAttr.Installed; - } - } - - return true; - } - - public static bool UpgradeAttributesUnlocked(FieldInfo type) - { - foreach (var attr in type.GetCustomAttributes(true)) - { - if (attr is RequiresUpgradeAttribute) - { - var rAttr = attr as RequiresUpgradeAttribute; - return rAttr.Installed; - } - } - - return true; - } - - public static bool IsInitiated { get; private set; } - - public static void Init() - { - if (IsInitiated == false) - { - IsInitiated = true; - //Let the crash handler deal with this one... - var dict = GetDefaults(); - foreach (var itm in dict) - { - if (!SaveSystem.CurrentSave.Upgrades.ContainsKey(itm.ID)) - { - try - { - SaveSystem.CurrentSave.Upgrades.Add(itm.ID, false); - } - catch - { - - } - } - } - } - - } - - public static long GetCPValue(string id) - { - foreach(var upg in GetDefaults()) - { - if (upg.ID == id) - return upg.Cost; - } - return 0; - } - - public static ShiftoriumUpgrade[] GetAvailable() - { - List available = new List(); - foreach(var defaultupg in GetDefaults()) - { - if (!UpgradeInstalled(defaultupg.ID) && DependenciesInstalled(defaultupg)) - available.Add(defaultupg); - } - return available.ToArray(); - } - - public static bool DependenciesInstalled(ShiftoriumUpgrade upg) - { - if (string.IsNullOrEmpty(upg.Dependencies)) - { - return true;//root upgrade, no parents - } - else if (upg.Dependencies.Contains(";")) - { - string[] dependencies = upg.Dependencies.Split(';'); - foreach(var dependency in dependencies) - { - if (!UpgradeInstalled(dependency)) - return false; - } - return true; - } - else - { - return UpgradeInstalled(upg.Dependencies); - } - } - - public static event EmptyEventHandler Installed; - - public static bool UpgradeInstalled(string id) - { - if (SaveSystem.CurrentSave != null) - { - if (!IsInitiated) - Init(); - } - try - { - if (SaveSystem.CurrentSave == null) - return false; - - if (SaveSystem.CurrentSave.StoriesExperienced == null) - SaveSystem.CurrentSave.StoriesExperienced = new List(); - - if (id.Contains(';')) - { - foreach(var u in id.Split(';')) - { - if (UpgradeInstalled(u) == false) - return false; - } - return true; - } - - 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 - { - Console.WriteLine("Upgrade " + id + "DNE."); - Console.WriteLine(); - return false; - } - - } - - //LEAVE THIS AS FALSE. The game will set it when the save is loaded. - public static bool LogOrphanedUpgrades = false; - - private static IShiftoriumProvider _provider = null; - - [Obsolete("Please annotate your provider with a [ShiftoriumProvider] attribute instead. This function doesn't do anything.")] - public static void RegisterProvider(IShiftoriumProvider p) - { - _provider = p; - } - - //Bless the newer NEWER engine. - public static List GetDefaults() - { - List list = new List(); - //Now we probe for ShiftoriumUpgradeAttributes for mods. - foreach(var file in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - if(file.EndsWith(".exe") || file.EndsWith(".dll")) - { - try - { - var asm = Assembly.LoadFile(file); - foreach (var type in asm.GetTypes()) - { - if (type.GetInterfaces().Contains(typeof(IShiftoriumProvider))) - { - if(type.GetCustomAttributes().FirstOrDefault(x=> x is ShiftoriumProviderAttribute) != null) - { - var _p = Activator.CreateInstance(type, null) as IShiftoriumProvider; - list.AddRange(_p.GetDefaults()); - } - } - - - ShiftoriumUpgradeAttribute attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute; - if (attrib != null) - { - if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null) - throw new ShiftoriumConflictException(attrib.Upgrade); - list.Add(new ShiftoriumUpgrade - { - Id = attrib.Upgrade, - Name = attrib.Name, - Cost = attrib.Cost, - Description = attrib.Description, - Dependencies = attrib.Dependencies, - Category = attrib.Category - }); - } - - foreach (var mth in type.GetMethods()) - { - attrib = mth.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute; - if (attrib != null) - { - if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null) - throw new ShiftoriumConflictException(attrib.Upgrade); - list.Add(new ShiftoriumUpgrade - { - Id = attrib.Upgrade, - Name = attrib.Name, - Cost = attrib.Cost, - Description = attrib.Description, - Dependencies = attrib.Dependencies, - Category = attrib.Category - }); - - } - } - - foreach (var mth in type.GetFields()) - { - attrib = mth.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute; - if (attrib != null) - { - if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null) - throw new ShiftoriumConflictException(attrib.Upgrade); - list.Add(new ShiftoriumUpgrade - { - Id = attrib.Upgrade, - Name = attrib.Name, - Cost = attrib.Cost, - Description = attrib.Description, - Dependencies = attrib.Dependencies, - Category = attrib.Category - }); - - } - } - - foreach (var mth in type.GetProperties()) - { - attrib = mth.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftoriumUpgradeAttribute) as ShiftoriumUpgradeAttribute; - if (attrib != null) - { - if (list.FirstOrDefault(x => x.ID == attrib.Upgrade) != null) - throw new ShiftoriumConflictException(attrib.Upgrade); - list.Add(new ShiftoriumUpgrade - { - Id = attrib.Upgrade, - Name = attrib.Name, - Cost = attrib.Cost, - Description = attrib.Description, - Dependencies = attrib.Dependencies, - Category = attrib.Category - }); - - } - } - - } - } - catch { } - } - } - - - - foreach(var item in list) - { - if (list.Where(x => x.ID == item.ID).Count() > 1) - throw new ShiftoriumConflictException(item.Id); - } - return list; - } - } - - public interface IShiftoriumProvider - { - List GetDefaults(); - } - - public class ShiftoriumUpgradeLookupException : Exception - { - public ShiftoriumUpgradeLookupException(string id) : base("A shiftorium upgrade of ID \"" + id + "\" was not found in the system.") - { - ID = id; - - Debug.WriteLine("UpgradeNotFound: " + id); - - } - - public string ID { get; private set; } - } - - - - public class ShiftoriumUpgrade - { - public string Name { get; set; } - public string Description { get; set; } - public long Cost { get; set; } - public string ID { get { return (this.Id != null ? this.Id : (Name.ToLower().Replace(" ", "_"))); } } - public string Id { get; set; } - public string Category { get; set; } - public bool Installed - { - get - { - return Shiftorium.UpgradeInstalled(ID); - } - } - public string Dependencies { get; set; } - } - - public class ShiftoriumUpgradeAttribute : RequiresUpgradeAttribute - { - public ShiftoriumUpgradeAttribute(string name, long cost, string desc, string dependencies, string category) : base(name.ToLower().Replace(" ", "_")) - { - Name = name; - Description = desc; - Dependencies = dependencies; - Cost = cost; - Category = category; - } - - public string Name { get; private set; } - public string Description { get; private set; } - public long Cost { get; private set; } - public string Dependencies { get; private set; } - public string Category { get; private set; } - } - - public class ShiftoriumConflictException : Exception - { - public ShiftoriumConflictException() : base("An upgrade conflict has occurred while loading Shiftorium Upgrades from an assembly. Is there a duplicate upgrade ID?") - { - - } - - public ShiftoriumConflictException(string id) : base("An upgrade conflict has occurred while loading Shiftorium Upgrades from an assembly. An upgrade with the ID \"" + id + "\" has already been loaded.") - { - - } - } - - public class ShiftoriumProviderAttribute : Attribute - { - - } -} diff --git a/ShiftOS_TheReturn/Skinning.cs b/ShiftOS_TheReturn/Skinning.cs deleted file mode 100644 index b731c4f..0000000 --- a/ShiftOS_TheReturn/Skinning.cs +++ /dev/null @@ -1,1336 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using System.Windows.Forms; -using static ShiftOS.Engine.SaveSystem; -using ShiftOS.Objects.ShiftFS; -using System.Reflection; -using ShiftOS.Engine.Scripting; -namespace ShiftOS.Engine -{ - - [Exposed("skinning")] - public class SkinFunctions - { - public void loadSkin() - { - SkinEngine.LoadSkin(); - } - - public dynamic getSkin() - { - return SkinEngine.LoadedSkin; - } - - public void setSkin(Skin skn) - { - Utils.WriteAllText(Paths.GetPath("skin.json"), JsonConvert.SerializeObject(skn)); - SkinEngine.LoadSkin(); - } - - public dynamic getImage(string id) - { - return SkinEngine.GetImage(id); - } - } - - - public static class SkinEngine - { - public static ImageLayout GetImageLayout(string img) - { - if (LoadedSkin.SkinImageLayouts.ContainsKey(img)) - { - return LoadedSkin.SkinImageLayouts[img]; - } - else - { - LoadedSkin.SkinImageLayouts.Add(img, ImageLayout.Tile); - return ImageLayout.Tile; - } - } - - public static System.Drawing.Image GetImage(string img) - { - var type = typeof(Skin); - - foreach (var field in type.GetFields()) - { - foreach (var attr in field.GetCustomAttributes(false)) - { - if (attr is ImageAttribute) - { - var iattr = attr as ImageAttribute; - if (iattr.Name == img) - { - byte[] image = (byte[])field.GetValue(LoadedSkin); - return ImageFromBinary(image); - } - } - } - } - - return null; - } - - public static void SetIconProber(IIconProber prober) - { - _iconProber = prober; - } - - public static Image ImageFromBinary(byte[] image) - { - if (image == null) - return null; - Image img = (Bitmap)((new ImageConverter()).ConvertFrom(image)); - return img; - } - - private static Skin loadedSkin = new Skin(); - - public static Skin LoadedSkin - { - get - { - return loadedSkin; - } - private set - { - loadedSkin = value; - } - } - - public static void Init() - { - Application.ApplicationExit += (o, a) => - { - SaveSkin(); - }; - - if (!Utils.FileExists(Paths.GetPath("skin.json"))) - { - LoadedSkin = new ShiftOS.Engine.Skin(); - SaveSkin(); - } - else - { - LoadSkin(); - } - if (SaveSystem.CurrentSave != null) - { - SkinLoaded?.Invoke(); - } - } - - public static event EmptyEventHandler SkinLoaded; - - public static void LoadSkin() - { - LoadedSkin = JsonConvert.DeserializeObject(Utils.ReadAllText(Paths.GetPath("skin.json"))); - SkinLoaded?.Invoke(); - Desktop.ResetPanelButtons(); - Desktop.PopulateAppLauncher(); - } - - public static void SaveSkin() - { - Utils.WriteAllText(Paths.GetPath("skin.json"), JsonConvert.SerializeObject(LoadedSkin, Formatting.Indented)); - } - - private static IIconProber _iconProber = null; - - public static Image GetDefaultIcon(string id) - { - if (_iconProber == null) - { - return new Bitmap(16, 16); - } - else - { - foreach (var f in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - if (f.EndsWith(".exe") || f.EndsWith(".dll")) - { - try - { - var asm = Assembly.LoadFile(f); - foreach (var type in asm.GetTypes()) - { - if (type.Name == id) - { - foreach (var attr in type.GetCustomAttributes(true)) - { - if (attr is DefaultIconAttribute) - { - return _iconProber.GetIcon(attr as DefaultIconAttribute); - } - } - } - } - } - catch { } - } - } - return new Bitmap(16, 16); - } - } - - public static Image GetIcon(string id) - { - if (!LoadedSkin.AppIcons.ContainsKey(id)) - LoadedSkin.AppIcons.Add(id, null); - - if (LoadedSkin.AppIcons[id] == null) - return GetDefaultIcon(id); - else - { - using (var sr = new MemoryStream(LoadedSkin.AppIcons[id])) - { - return Image.FromStream(sr); - } - } - - } - } - - public interface IIconProber - { - Image GetIcon(DefaultIconAttribute attr); - } - - public class DefaultIconAttribute : Attribute - { - public DefaultIconAttribute(string id) - { - ID = id; - } - - public string ID { get; private set; } - } - - public class Skin - { - //borrowing from the discourse theme for the default skin - private static readonly Color DefaultBackground = Color.FromArgb(0, 0x44, 0x00); - private static readonly Color DefaultForeground = Color.FromArgb(0xDD, 0xDD, 0xDD); - private static readonly Color Accent1 = Color.FromArgb(0x66, 0x66, 0x66); - private static readonly Color Accent2 = Color.FromArgb(0x80, 0, 0); - private static readonly Color DesktopBG = Color.FromArgb(0x22, 0x22, 0x22); - private static readonly Font SysFont = new Font("Tahoma", 9F); - private static readonly Font SysFont2 = new Font("Tahoma", 10F, FontStyle.Bold); - private static readonly Font Header1 = new Font("Helvetica", 20F, FontStyle.Bold); - private static readonly Font Header2 = new Font("Helvetica", 17.5F, FontStyle.Bold); - private static readonly Font Header3 = new Font("Tahoma", 15F, FontStyle.Bold); - - private static readonly Color TitleBG = Color.FromArgb(0x11, 0x11, 0x11); - private static readonly Color TitleFG = Color.FromArgb(0xaa, 0xaa, 0xaa); - - //Todo: When making Shifter GUI we need to label all these with proper Shifter attributes to get 'em displaying in the right places. - - public override string ToString() - { - return JsonConvert.SerializeObject(this, Formatting.Indented); - } - - [ShifterHidden] - public Dictionary AppNames = new Dictionary(); - - [ShifterHidden] - public Dictionary AppIcons = new Dictionary(); - - [ShifterMeta("System")] - [ShifterCategory("Login Screen")] - [RequiresUpgrade("gui_based_login_screen")] - [ShifterName("Login Screen Background Color")] - [ShifterDescription("Change the background color of the login screen.")] - public Color LoginScreenColor = Skin.DesktopBG; - - [ShifterMeta("System")] - [ShifterCategory("Login Screen")] - [RequiresUpgrade("skinning;gui_based_login_screen")] - [ShifterName("Login Screen Background Image")] - [ShifterDescription("Set an image as your login screen!")] - [Image("login")] - public byte[] LoginScreenBG = null; - - - [RequiresUpgrade("shift_screensaver")] - [ShifterMeta("System")] - [ShifterCategory("Screen saver")] - [ShifterName("Screen saver wait (milliseconds)")] - [ShifterDescription("How long do you have to stay idle before the screensaver activates?")] - public int ScreensaverWait = 300000; - - [RequiresUpgrade("skinning;shift_screensaver")] - [ShifterMeta("System")] - [ShifterCategory("Screen saver")] - [ShifterName("Screen saver image")] - [ShifterDescription("What image should appear on the screen saver?")] - public byte[] ScreensaverImage = null; - - - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [RequiresUpgrade("shift_title_text")] - [ShifterName("Title Font")] - [ShifterDescription("The font style for the title text.")] - public Font TitleFont = SysFont2; - - [ShifterMeta("System")] - [ShifterCategory("General")] - [ShifterName("System Font")] - [ShifterDescription("The font style used by the system.")] - public Font MainFont = SysFont; - - [ShifterEnumMask(new[] { "Right", "Left" })] - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Title button position")] - [ShifterDescription("Where should the title buttons be located?")] - public int TitleButtonPosition = 0; - - [ShifterMeta("System")] - [ShifterCategory("Header Fonts")] - [ShifterName("1st level header")] - [ShifterDescription("The font used in level 1 (title) headers.")] - public Font HeaderFont = Header1; - - - [ShifterMeta("System")] - [ShifterCategory("Header Fonts")] - [ShifterName("2nd level header")] - [ShifterDescription("The font used in level 2 (subtitle) headers.")] - public Font Header2Font = Header2; - - - [ShifterMeta("System")] - [ShifterCategory("Header Fonts")] - [ShifterName("3rd level header")] - [ShifterDescription("The font used in level 3 (section) headers.")] - public Font Header3Font = Header3; - - - - [ShifterMeta("System")] - [ShifterCategory("General")] - [ShifterName("System Background")] - [ShifterDescription("The background color of all system controls in the UI.")] - public Color ControlColor = DefaultBackground; - - [ShifterMeta("System")] - [ShifterCategory("General")] - [ShifterName("System Foreground")] - [ShifterDescription("The foreground color of all system controls in the UI.")] - public Color ControlTextColor = DefaultForeground; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [ShifterName("Title Text Color")] - [RequiresUpgrade("shift_title_text")] - [ShifterDescription("The color of the title text.")] - public Color TitleTextColor = TitleFG; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [ShifterName("Title Background Color")] - [RequiresUpgrade("shift_titlebar")] - [ShifterDescription("The color of the titlebar's background.")] - public Color TitleBackgroundColor = TitleBG; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [ShifterName("Left Border Background")] - [RequiresUpgrade("shift_window_borders")] - [ShifterDescription("The background color for the left border.")] - public Color BorderLeftBackground = TitleBG; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [ShifterName("Right Border Background")] - [RequiresUpgrade("shift_window_borders")] - [ShifterDescription("The background color for the right border.")] - public Color BorderRightBackground = TitleBG; - - [ShifterMeta("Desktop")] - [ShifterCategory("Panel buttons")] - [RequiresUpgrade("shift_panel_buttons")] - [ShifterName("Panel buttons from top")] - [ShifterDescription("How far from the top should the panel buttons be?")] - public int PanelButtonFromTop = 2; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [ShifterName("Bottom Border Background")] - [RequiresUpgrade("shift_window_borders")] - [ShifterDescription("The background color for the bottom border.")] - public Color BorderBottomBackground = TitleBG; - - [ShifterMeta("Desktop")] - [ShifterCategory("Panel buttons")] - [ShifterName("Panel button holder from left")] - [ShifterDescription("How far from the left should the panel button holder be?")] - [RequiresUpgrade("shift_panel_buttons")] - public int PanelButtonHolderFromLeft = 100; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [ShifterName("Bottom Left Border Background")] - [RequiresUpgrade("shift_window_borders")] - [ShifterDescription("The background color for the bottom left border.")] - public Color BorderBottomLeftBackground = TitleBG; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [ShifterName("Bottom Right Border Background")] - [RequiresUpgrade("shift_window_borders")] - [ShifterDescription("The background color for the bottom right border.")] - public Color BorderBottomRightBackground = TitleBG; - - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Close Button Color")] - [RequiresUpgrade("shift_title_buttons")] - [ShifterDescription("The close button color")] - public Color CloseButtonColor = Accent2; - - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Maximize Button Color")] - [RequiresUpgrade("shift_title_buttons")] - [ShifterDescription("The maximize button color")] - public Color MaximizeButtonColor = Accent1; - - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Minimize Button Color")] - [RequiresUpgrade("shift_title_buttons")] - [ShifterDescription("The minimize button color")] - public Color MinimizeButtonColor = Accent1; - - [ShifterMeta("Desktop")] - [ShifterCategory("Desktop Panel")] - [ShifterName("Panel Background")] - [RequiresUpgrade("shift_desktop_panel")] - [ShifterDescription("The background color used by the desktop panel")] - public Color DesktopPanelColor = TitleBG; - - [ShifterMeta("Desktop")] - [ShifterCategory("Desktop Panel")] - [ShifterName("Panel Clock Text Color")] - [RequiresUpgrade("shift_panel_clock")] - [ShifterDescription("The text color used by the desktop panel's clock.")] - public Color DesktopPanelClockColor = TitleFG; - - [ShifterMeta("Desktop")] - [ShifterCategory("Desktop Panel")] - [ShifterName("Panel Clock Background Color")] - [RequiresUpgrade("shift_panel_clock")] - [ShifterDescription("The background color used by the desktop panel's clock.")] - public Color DesktopPanelClockBackgroundColor = TitleBG; - - [ShifterMeta("Desktop")] - [ShifterCategory("Desktop Panel")] - [ShifterName("Panel Clock Font")] - [RequiresUpgrade("shift_panel_clock")] - [ShifterDescription("The font used by the desktop panel's clock.")] - public Font DesktopPanelClockFont = Skin.SysFont2; - - [ShifterMeta("Desktop")] - [ShifterCategory("Desktop Panel")] - [ShifterName("Panel Clock From Right")] - [RequiresUpgrade("shift_panel_clock")] - [ShifterDescription("The position in pixels relative to the width of the desktop panel that the clock will sit at.")] - public Point DesktopPanelClockFromRight = new Point(2, 2); - - - [ShifterMeta("Desktop")] - [ShifterCategory("Desktop Panel")] - [ShifterName("Panel Height")] - [RequiresUpgrade("shift_desktop_panel")] - [ShifterDescription("The height in pixels of the desktop panel.")] - public int DesktopPanelHeight = 24; - - [ShifterMeta("Desktop")] - [ShifterCategory("Desktop Panel")] - [ShifterName("Panel Position")] - [ShifterEnumMask(new[] { "Top", "Bottom" })] - [RequiresUpgrade("shift_desktop_panel")] - [ShifterDescription("The position of the desktop panel.")] - public int DesktopPanelPosition = 0; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [ShifterName("Titlebar Height")] - [RequiresUpgrade("shift_titlebar")] - [ShifterDescription("The height of the titlebar.")] - public int TitlebarHeight = 30; - - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Close Button Size")] - [RequiresUpgrade("shift_title_buttons")] - [ShifterDescription("The close button size")] - public Size CloseButtonSize = new Size(24, 24); - - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Maximize Button Size")] - [RequiresUpgrade("shift_title_buttons")] - [ShifterDescription("The maximize button size")] - public Size MaximizeButtonSize = new Size(24, 24); - - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Minimize Button Size")] - [RequiresUpgrade("shift_title_buttons")] - [ShifterDescription("The minimize button size")] - public Size MinimizeButtonSize = new Size(24, 24); - - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Close Button From Right")] - [RequiresUpgrade("shift_title_buttons")] - [ShifterDescription("The close button location from the right of the titlebar.")] - public Point CloseButtonFromSide = new Point(3, (30 - 24) / 2); - - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Maximize Button From Right")] - [RequiresUpgrade("shift_title_buttons")] - [ShifterDescription("The maximize button location from the right of the titlebar.")] - public Point MaximizeButtonFromSide = new Point(24 + 6, (30 - 24) / 2); - - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Minimize Button From Right")] - [RequiresUpgrade("shift_title_buttons")] - [ShifterDescription("The minimize button location from the right of the titlebar.")] - public Point MinimizeButtonFromSide = new Point(48 + 9, (30 - 24) / 2); - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [ShifterName("Title text centered?")] - [RequiresUpgrade("shift_title_text")] - [ShifterDescription("Is the title text centered?")] - public bool TitleTextCentered = false; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [ShifterName("Title Text From Left")] - [ShifterFlag("TitleTextCentered", false)] - [RequiresUpgrade("shift_title_text")] - [ShifterDescription("The title text location from the left of the titlebar.")] - public Point TitleTextLeft = new Point(4, 4); - - [ShifterMeta("Desktop")] - [ShifterCategory("General")] - [ShifterName("Desktop Background Color")] - [ShifterDescription("The background color of the desktop.")] - public Color DesktopColor = DesktopBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button select highlight")] - public Color Menu_ButtonSelectedHighlight = Accent2; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button select border")] - public Color Menu_ButtonSelectedHighlightBorder = Accent2; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button pressed highlight")] - public Color Menu_ButtonPressedHighlight = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button pressed border")] - public Color Menu_ButtonPressedHighlightBorder = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button checked highlight")] - public Color Menu_ButtonCheckedHighlight = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button checked border")] - public Color Menu_ButtonCheckedHighlightBorder = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button pressed gradient border")] - public Color Menu_ButtonPressedBorder = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button selected gradient border")] - public Color Menu_ButtonSelectedBorder = Accent2; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button checked gradient start")] - public Color Menu_ButtonCheckedGradientBegin = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button checked gradient middle")] - public Color Menu_ButtonCheckedGradientMiddle = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button checked gradient end")] - public Color Menu_ButtonCheckedGradientEnd = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button selected gradient start")] - public Color Menu_ButtonSelectedGradientBegin = Accent2; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button selected gradient middle")] - public Color Menu_ButtonSelectedGradientMiddle = Accent2; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button selected gradient end")] - public Color Menu_ButtonSelectedGradientEnd = Accent2; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button pressed gradient start")] - public Color Menu_ButtonPressedGradientBegin = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button pressed gradient middle")] - public Color Menu_ButtonPressedGradientMiddle = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Button pressed gradient end")] - public Color Menu_ButtonPressedGradientEnd = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("General")] - [ShifterName("Check BG")] - public Color Menu_CheckBackground = Skin.TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("General")] - [ShifterName("Check BG (Selected)")] - public Color Menu_CheckSelectedBackground = Accent2; - - [ShifterMeta("Menus")] - [ShifterCategory("General")] - [ShifterName("Check BG (Pressed)")] - public Color Menu_CheckPressedBackground = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu bars")] - [ShifterName("Margin gradient start")] - public Color Menu_ImageMarginGradientBegin = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu bars")] - [ShifterName("Margin gradient middle")] - public Color Menu_ImageMarginGradientMiddle = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu bars")] - [ShifterName("Margin gradient end")] - public Color Menu_ImageMarginGradientEnd = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu bars")] - [ShifterName("Menu gradient start")] - public Color Menu_MenuStripGradientBegin = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu bars")] - [ShifterName("Menu gradient end")] - public Color Menu_MenuStripGradientEnd = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu bars")] - [ShifterName("Menu item selected")] - public Color Menu_MenuItemSelected = Accent2; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu bars")] - [ShifterName("Menu item border")] - public Color Menu_MenuItemBorder = DefaultBackground; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu bars")] - [ShifterName("Menu border")] - public Color Menu_MenuBorder = DefaultBackground; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Menu item selected gradient start")] - public Color Menu_MenuItemSelectedGradientBegin = Accent2; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Menu item selected gradient end")] - public Color Menu_MenuItemSelectedGradientEnd = Accent2; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Menu item pressed gradient start")] - public Color Menu_MenuItemPressedGradientBegin = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Menu item pressed gradient middle")] - public Color Menu_MenuItemPressedGradientMiddle = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Menu item pressed gradient end")] - public Color Menu_MenuItemPressedGradientEnd = Accent1; - - [ShifterMeta("Menus")] - [ShifterCategory("General")] - [ShifterName("Rafter gradient start")] - public Color Menu_RaftingContainerGradientBegin = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("General")] - [ShifterName("Rafter gradient end")] - public Color Menu_RaftingContainerGradientEnd = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("General")] - [ShifterName("Separator Color 1")] - public Color Menu_SeparatorDark = DefaultForeground; - - [ShifterMeta("Menus")] - [ShifterCategory("General")] - [ShifterName("Separator Color 2")] - public Color Menu_SeparatorLight = TitleFG; - - [ShifterMeta("Menus")] - [ShifterCategory("Status bars")] - [ShifterName("Status bar gradient start")] - public Color Menu_StatusStripGradientBegin = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Status bars")] - [ShifterName("Status bar gradient end")] - public Color Menu_StatusStripGradientEnd = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Toolbar Border")] - public Color Menu_ToolStripBorder = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Dropdown background")] - public Color Menu_ToolStripDropDownBackground = DefaultBackground; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Toolbar gradient start")] - public Color Menu_ToolStripGradientBegin = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Toolbar gradient middle")] - public Color Menu_ToolStripGradientMiddle = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Toolbars")] - [ShifterName("Toolbar gradient end")] - public Color Menu_ToolStripGradientEnd = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu holders")] - [ShifterName("Content panel gradient start")] - public Color Menu_ToolStripContentPanelGradientBegin = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu holders")] - [ShifterName("Content panel gradient end")] - public Color Menu_ToolStripContentPanelGradientEnd = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu holders")] - [ShifterName("Panel gradient start")] - public Color Menu_ToolStripPanelGradientBegin = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("Menu holders")] - [ShifterName("Panel gradient end")] - public Color Menu_ToolStripPanelGradientEnd = TitleBG; - - [ShifterMeta("Menus")] - [ShifterCategory("General")] - [ShifterName("Menu text color")] - public Color Menu_TextColor = DefaultForeground; - - [ShifterMeta("Menus")] - [ShifterCategory("General")] - [ShifterName("Menu selected text color")] - public Color Menu_SelectedTextColor = TitleFG; - - - - //Images - [Image("closebutton")] - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Close Button Image")] - [RequiresUpgrade("shift_title_buttons;skinning")] - [ShifterDescription("Show an image on the Close Button using this setting.")] - public byte[] CloseButtonImage = null; - - [Image("minimizebutton")] - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Minimize Button Image")] - [RequiresUpgrade("shift_title_buttons;skinning")] - [ShifterDescription("Show an image on the Minimize Button using this setting.")] - public byte[] MinimizeButtonImage = null; - - [Image("maximizebutton")] - [ShifterMeta("Windows")] - [ShifterCategory("Title Buttons")] - [ShifterName("Maximize Button Image")] - [RequiresUpgrade("shift_title_buttons;skinning")] - [ShifterDescription("Show an image on the Maximize Button using this setting.")] - public byte[] MaximizeButtonImage = null; - - [Image("desktopbackground")] - [ShifterMeta("Desktop")] - [ShifterCategory("General")] - [ShifterName("Desktop Background Image")] - [RequiresUpgrade("skinning")] - [ShifterDescription("Use an image as your desktop background.")] - public byte[] DesktopBackgroundImage = null; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_app_launcher")] - [ShifterName("App Launcher Text Color")] - [ShifterDescription("Change the color of the App Launcher text.")] - public Color AppLauncherTextColor = Skin.DefaultForeground; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_app_launcher")] - [ShifterName("App Launcher Selected Text Color")] - [ShifterDescription("Change the color of the app launcher's text while it is selected.")] - public Color AppLauncherSelectedTextColor = Skin.TitleFG; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_app_launcher")] - [ShifterName("App Launcher Font")] - [ShifterDescription("Change the font that the App Launcher text is displayed in.")] - public Font AppLauncherFont = Skin.SysFont2; - - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [ShifterName("App launcher text")] - [ShifterDescription("The text displayed on the app launcher.")] - [RequiresUpgrade("shift_app_launcher")] - public string AppLauncherText = "ShiftOS"; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [ShifterName("App launcher from left")] - [ShifterDescription("The position of the app launcher from the left of the Desktop Panel.")] - [RequiresUpgrade("shift_app_launcher")] - public Point AppLauncherFromLeft = new Point(0, 0); - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [ShifterName("App launcher size")] - [ShifterDescription("The size of the app launcher.")] - [RequiresUpgrade("shift_app_launcher")] - public Size AppLauncherHolderSize = new Size(100, 24); - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [ShifterName("App launcher image")] - [ShifterDescription("The image that will appear on the app launcher.")] - [Image("applauncher")] - [RequiresUpgrade("skinning;shift_app_launcher")] - public byte[] AppLauncherImage = null; - - [ShifterMeta("System")] - [ShifterCategory("General")] - [ShifterName("Terminal font")] - public Font TerminalFont = new Font("Lucida Console", 9F, FontStyle.Regular); - - [ShifterMeta("System")] - [ShifterCategory("General")] - [ShifterName("Terminal text color")] - public ConsoleColor TerminalForeColorCC = ConsoleColor.White; - - [ShifterMeta("System")] - [ShifterCategory("General")] - [ShifterName("Terminal background color")] - public ConsoleColor TerminalBackColorCC = ConsoleColor.Black; - - [ShifterMeta("Desktop")] - [ShifterCategory("Desktop Panel")] - [ShifterName("Panel background image")] - [Image("desktoppanel")] - [RequiresUpgrade("skinning;shift_desktop_panel")] - public byte[] DesktopPanelBackground = null; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [ShifterName("Titlebar background image")] - [Image("titlebar")] - [RequiresUpgrade("skinning;shift_titlebar")] - public byte[] TitleBarBackground = null; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [RequiresUpgrade("shift_titlebar")] - [ShifterName("Show title corners?")] - [ShifterDescription("If checked, a left and a right section will appear on the titlebar which is useful for rounded corners, padding, or other useful properties.")] - public bool ShowTitleCorners = false; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [RequiresUpgrade("shift_titlebar")] - [ShifterFlag("ShowTitleCorners", true)] - [ShifterName("Title left background color")] - [ShifterDescription("What color should be used for the left title corner?")] - public Color TitleLeftCornerBackground = TitleBG; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [RequiresUpgrade("shift_titlebar")] - [ShifterFlag("ShowTitleCorners", true)] - [ShifterName("Title right background color")] - [ShifterDescription("What color should be used for the right title corner?")] - public Color TitleRightCornerBackground = TitleBG; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [RequiresUpgrade("shift_titlebar")] - [ShifterFlag("ShowTitleCorners", true)] - [ShifterName("Title left corner width")] - [ShifterDescription("How wide should the left title corner be?")] - public int TitleLeftCornerWidth = 2; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [RequiresUpgrade("shift_titlebar")] - [ShifterFlag("ShowTitleCorners", true)] - [ShifterName("Title right corner width")] - [ShifterDescription("How wide should the right title corner be?")] - public int TitleRightCornerWidth = 2; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [RequiresUpgrade("skinning;shift_titlebar")] - [ShifterFlag("ShowTitleCorners", true)] - [ShifterName("Title left corner background image")] - [ShifterDescription("Select an image to appear as the background texture for the left titlebar corner.")] - [Image("titleleft")] - public byte[] TitleLeftBG = null; - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [RequiresUpgrade("skinning;shift_titlebar")] - [ShifterFlag("ShowTitleCorners", true)] - [ShifterName("Title right corner background image")] - [ShifterDescription("Select an image to appear as the background texture for the right titlebar corner.")] - [Image("titleright")] - public byte[] TitleRightBG = null; - - - [ShifterMeta("System")] - [ShifterCategory("General")] - [ShifterName("System color key-out")] - [ShifterDescription("This is a color that will be represented as \"transparent\" in windows. This does not affect the desktop.")] - public Color SystemKey = Color.FromArgb(1, 0, 1); - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [RequiresUpgrade("skinning;shift_window_borders")] - [Image("bottomborder")] - [ShifterName("Bottom Border Image")] - [ShifterDescription("Select an image to appear on the bottom border.")] - public byte[] BottomBorderBG = null; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [RequiresUpgrade("skinning;shift_window_borders")] - [Image("bottomrborder")] - [ShifterName("Bottom Right Border Image")] - [ShifterDescription("Select an image to appear on the bottom right border.")] - public byte[] BottomRBorderBG = null; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [RequiresUpgrade("skinning;shift_window_borders")] - [Image("bottomlborder")] - [ShifterName("Bottom Left Border Image")] - [ShifterDescription("Select an image to appear on the bottom left border.")] - public byte[] BottomLBorderBG = null; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [RequiresUpgrade("skinning;shift_window_borders")] - [Image("leftborder")] - [ShifterName("Left Border Image")] - [ShifterDescription("Select an image to appear on the left border.")] - public byte[] LeftBorderBG = null; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [RequiresUpgrade("skinning;shift_window_borders")] - [Image("rightborder")] - [ShifterName("Right Border Image")] - [ShifterDescription("Select an image to appear on the right border.")] - public byte[] RightBorderBG = null; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [RequiresUpgrade("shift_window_borders")] - [ShifterName("Left border width")] - [ShifterDescription("How wide should the left border be?")] - public int LeftBorderWidth = 2; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [RequiresUpgrade("shift_window_borders")] - [ShifterName("Right border width")] - [ShifterDescription("How wide should the right border be?")] - public int RightBorderWidth = 2; - - [ShifterMeta("Windows")] - [ShifterCategory("Window border")] - [RequiresUpgrade("shift_window_borders")] - [ShifterName("Bottom border height")] - [ShifterDescription("How tall should the bottom border be?")] - public int BottomBorderWidth = 2; - - [Image("panelbutton")] - [ShifterMeta("Desktop")] - [ShifterCategory("Panel buttons")] - [RequiresUpgrade("skinning;shift_panel_buttons")] - [ShifterName("Panel button background image")] - [ShifterDescription("Select a texture to display as the panel button background.")] - public byte[] PanelButtonBG = null; - - [ShifterMeta("Desktop")] - [ShifterCategory("Panel buttons")] - [RequiresUpgrade("shift_panel_buttons")] - [ShifterName("Panel button size")] - [ShifterDescription("How big should the panel button be?")] - public Size PanelButtonSize = new Size(185, 20); - - [ShifterMeta("Desktop")] - [ShifterCategory("Panel buttons")] - [RequiresUpgrade("shift_panel_buttons")] - [ShifterName("Panel button background color")] - [ShifterDescription("Select a background color for the panel button.")] - public Color PanelButtonColor = Skin.Accent2; - - [ShifterMeta("Desktop")] - [ShifterCategory("Panel buttons")] - [RequiresUpgrade("shift_panel_buttons")] - [ShifterName("Panel button text color")] - [ShifterDescription("Select a text color for the panel button.")] - public Color PanelButtonTextColor = Skin.TitleFG; - - [ShifterMeta("Desktop")] - [ShifterCategory("Panel buttons")] - [RequiresUpgrade("shift_panel_buttons")] - [ShifterName("Panel button text from left")] - [ShifterDescription("The position relative to the panel button left in pixels that the text is placed at.")] - public Point PanelButtonFromLeft = new Point(2, 2); - - [ShifterMeta("Desktop")] - [ShifterCategory("Panel buttons")] - [RequiresUpgrade("shift_panel_buttons")] - [ShifterName("Panel button font")] - [ShifterDescription("Select a font for the panel button.")] - public Font PanelButtonFont = Skin.SysFont2; - - - //we DO NOT want this showing in the shifter. - [ShifterHidden] - public Dictionary SkinImageLayouts = new Dictionary(); - - [ShifterMeta("Windows")] - [ShifterCategory("Titlebar")] - [ShifterName("App icon from side")] - [ShifterDescription("How far from the side should the icon be?")] - [RequiresUpgrade("shift_titlebar;app_icons")] - public Point TitlebarIconFromSide = new Point(4, 4); - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("Status Panel Font")] - [ShifterDescription("The font used by the status panel in the Advanced App Launcher.")] - public Font ALStatusPanelFont = SysFont; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("Status Panel Text Color")] - [ShifterDescription("The text color for the AL status panel.")] - public Color ALStatusPanelTextColor = Skin.DefaultForeground; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("Status Panel Background")] - [ShifterDescription("The status panel's background color.")] - public Color ALStatusPanelBackColor = TitleBG; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("Status Panel Text Alignment")] - [ShifterDescription("What part of the panel should the status text stick to?")] - public ContentAlignment ALStatusPanelAlignment = ContentAlignment.MiddleCenter; - - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("AL System Status Height")] - [ShifterDescription("Set the height of the top system status bar in the App Launcher.")] - public int ALSystemStatusHeight = 50; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("AL Size")] - [ShifterDescription("Set the size of the App Launcher's container")] - public Size AALSize = new Size(425, 500); - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("AL Category View Width")] - [ShifterDescription("Set the width of the left Category Listing on the app launcher.")] - public int AALCategoryViewWidth = 237; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("AL Item List Width")] - [ShifterDescription("Set the width of the item list in the app launcher.")] - public int AALItemViewWidth = 237; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("AL System Actions Height")] - [ShifterDescription("Set the height of the bottom system actions bar in the App Launcher.")] - public int ALSystemActionHeight = 30; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("skinning;shift_advanced_app_launcher")] - [ShifterName("Status Panel Background Image")] - [ShifterDescription("Use an image for the App Launcher Status Panel")] - [Image("al_bg_status")] - public byte[] ALStatusPanelBG = null; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterEnumMask(new[] { "Button, bottom panel", "Button, top panel", "Category Item" })] - [ShifterName("Shutdown Button position")] - [ShifterDescription("Change the position and layout of the App Launcher Shutdown button.")] - public int ShutdownButtonStyle = 0; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("Shutdown Button from side")] - [ShifterDescription("The location relative to the side of the system panel that the shutdown button should reside from.")] - public Point ShutdownButtonFromSide = new Point(2, 2); - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("Align shutdown button to left?")] - [ShifterDescription("Should the location of the shutdown button be calculated relative to the left of the system panel?")] - public bool ShutdownOnLeft = false; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("Shutdown Button Font")] - [ShifterDescription("The font of the Shutdown Button")] - public Font ShutdownFont = SysFont; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("Shutdown Text Color")] - [ShifterDescription("The foreground color of the Shutdown button")] - public Color ShutdownForeColor = DefaultForeground; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("System Panel background color")] - [ShifterDescription("The background color of the App Launcher System Panel.")] - public Color SystemPanelBackground = TitleBG; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("skinning;shift_advanced_app_launcher")] - [ShifterName("System Panel Background Image")] - [ShifterDescription("The background image of the System Panel.")] - [Image("al_bg_system")] - public byte[] SystemPanelBG = null; - - [ShifterMeta("Desktop")] - [ShifterCategory("App Launcher")] - [RequiresUpgrade("shift_advanced_app_launcher")] - [ShifterName("App Launcher Item Font")] - [ShifterDescription("Select the font to use for the items in the App Launcher.")] - public Font AdvALItemFont = SysFont2; - } - - public class ShifterHiddenAttribute : Attribute - { - - } - - public class ShifterFlagAttribute : Attribute - { - public ShifterFlagAttribute(string flag, bool expected) - { - Expected = expected; - Flag = flag; - } - - public bool Expected { get; set; } - public string Flag { get; set; } - public bool IsTrue(Skin skn) - { - foreach (var f in skn.GetType().GetFields()) - { - if (f.Name == Flag) - { - if (f.FieldType == typeof(bool)) - { - return (bool)f.GetValue(skn) == Expected; - } - } - } - throw new ArgumentException("The flag attribute was given an incorrect flag variable name."); - } - } - - public class ImageAttribute : Attribute - { - /// - /// Attribute a byte array within the Skin object with this attribute and the engine and Shifter will see it as an image and you'll be able to grab the image by calling SkinEngine.GetImage() passing the name you input here. - /// - /// The name you want to reference this image as in the code. - public ImageAttribute(string name) - { - Name = name; - } - - public string Name { get; set; } - } - - - public class ShifterEnumMaskAttribute : Attribute - { - public ShifterEnumMaskAttribute(string[] items) - { - Items = items; - } - - public string[] Items { get; set; } - } - - - - public class ShifterNameAttribute : Attribute - { - public ShifterNameAttribute(string name) - { - Name = name; - } - - public string Name { get; set; } - } - - public class ShifterDescriptionAttribute : Attribute - { - public ShifterDescriptionAttribute(string description) - { - Description = description; - } - - public string Description { get; set; } - } - - public class ShifterCategoryAttribute : Attribute - { - - public ShifterCategoryAttribute(string category) - { - Category = category; - } - - public string Category { get; set; } - } - - public class ShifterMetaAttribute : Attribute - { - - public ShifterMetaAttribute(string meta) - { - Meta = meta; - } - - public string Meta { get; set; } - } -} \ No newline at end of file diff --git a/ShiftOS_TheReturn/Story.cs b/ShiftOS_TheReturn/Story.cs deleted file mode 100644 index 8c726ed..0000000 --- a/ShiftOS_TheReturn/Story.cs +++ /dev/null @@ -1,328 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Newtonsoft.Json; - -namespace ShiftOS.Engine -{ - public class Story - { - public static void Start(string stid) - { - foreach (var exec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - if(exec.EndsWith(".exe") || exec.EndsWith(".dll")) - { - try - { - if (SaveSystem.CurrentSave.StoriesExperienced == null) - SaveSystem.CurrentSave.StoriesExperienced = new List(); - var asm = Assembly.LoadFile(exec); - foreach(var type in asm.GetTypes()) - { - foreach(var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) - { - foreach(var attrib in mth.GetCustomAttributes(false)) - { - if(attrib is StoryAttribute) - { - var story = attrib as StoryAttribute; - if(story.StoryID == stid) - { - mth.Invoke(null, null); - SaveSystem.CurrentSave.StoriesExperienced.Add(stid); - return; - } - } - } - } - } - } - catch (Exception ex) { throw ex; } - } - } -#if DEBUG - throw new ArgumentException("Story ID not found: " + stid + " - Talk to Michael. NOW."); -#else - Debug.Print("No such story: " + stid); -#endif - } - - - public static void RunFromInternalResource(string resource_id) - { - var t = typeof(Properties.Resources); - - foreach(var prop in t.GetProperties(System.Reflection.BindingFlags.NonPublic | BindingFlags.Static)) - { - if(prop.Name == resource_id) - { - if(prop.PropertyType == typeof(string)) - { - WriteStory(prop.GetValue(null) as string); - - return; - } - } - } - throw new ArgumentException("Couldn't find resource ID inside the engine: " + resource_id); - } - - - public string Character { get; set; } - public List Lines { get; set; } - - public static void Start() - { - Console.WriteLine(); - if(SaveSystem.CurrentSave.StoryPosition == 5) - { - StartDevXLies(); - } - } - - public static void StartDevXLies() - { - int chatProgress = 0; - //bool LoopStuck = false; - string textToWrite = ""; - const int TYPE_SPEED_MS = 45; - bool done = false; - bool write = true; - - while (done == false) { - write = true; - switch (chatProgress) - { - case 0: - textToWrite = "User joined: @" + SaveSystem.CurrentSave.Username; - break; - case 1: - textToWrite = $"Hello, {SaveSystem.CurrentSave.Username}."; - break; - case 2: //If C:\ShiftOS doesn't exist the player won't notice this is here. - if (Directory.Exists(Paths.GetPath("classic"))) - { - textToWrite = "I see you've participated in my previous ShiftOS experiment. Welcome back, Shifter. I assume you know lots about ShiftOS, but there are some updates I have to tell you."; - } - else - { - write = false; - } - break; - case 3: //DevX hates ShiftOS-Next secretly. - if (Directory.Exists(Paths.GetPath("classic") + "-Next")) - { - textToWrite = "Hmmmm.... looking at my sentience records, I see you've participated in ShiftOS-Next. This is gonna be difficult."; - } - else - { - write = false; - } - break; - case 4: - textToWrite = "There's a lot that has changed within ShiftOS."; - break; - case 5: - textToWrite = "First off, I want to tell you a bit about myself in case you don't already know."; - break; - case 6: - textToWrite = "My name is DevX. I am the architect of ShiftOS. I have chosen you to take part in helping me out with it."; - break; - case 7: - textToWrite = "You see, in my past attempts it has all been about an evolving operating system and seeing how the users work with it..."; - break; - case 8: - textToWrite = "Almost one hundred percent of the time, people have found out it was an experiment and they could simply return to their regular system with a specific upgrade."; - break; - case 9: - textToWrite = "But now, I want to try something different - something unique."; - break; - case 10: - textToWrite = "ShiftOS is the same as it has been in my previous attempts, but now, your goal is to gain as much wealth and power as possible."; - break; - case 11: - textToWrite = "Right now you are inside my segregation LAN. Only you and me exist within this domain. You are free from other users unless I create them."; - break; - case 12: - textToWrite = "Since you have proved your sentience, I have a task for you outside the segregation LAN."; - break; - case 13: - textToWrite = "But first... you need to be taught a few things."; - break; - case 14: - textToWrite = "First off, when I bring you into my multi-user domain, you'll first want to establish as much wealth as possible."; - break; - case 15: - textToWrite = "Wealth comes in the form of Codepoints - a currency used among users of the multi-user domain."; - break; - case 16: - textToWrite = @"You can get Codepoints by doing the following: - - - Stealing them from other users - - Extracting them from inactive/unverified sentiences - - Using specific scripts/programs within ShiftOS - - Creating paid scripts/applications within ShiftOS"; - break; - case 17: - textToWrite = "You can use Codepoints to buy upgrades using the 'shiftorium.buy' command, or you can use them to pay other users, or scripts."; - break; - case 18: - textToWrite = "Within the multi-user domain you are free to do whatever you want. Larcany, theft, deceiving, lies, and distribution of malware is permitted under my watch."; - break; - case 19: - textToWrite = "Do whatever you have to to get Codepoints."; - break; - case 20: - textToWrite = "Then use them to make yourself stronger by buying upgrades at the shiftorium."; - break; - case 21: - textToWrite = "If you want to get a bit devious within the multi-user domain, look around for scripts that will expose user account information."; - break; - case 22: - textToWrite = "Or just spread a virus around the mud."; - break; - case 23: - textToWrite = "Or you can be the 'good' guy and stop these attacks and gain the trust of other users."; - break; - case 24: - textToWrite = "It's up to you. Just, don't mess with my system. You won't want me coming to you after that. I'm watching."; - break; - case 25: - textToWrite = "User left chat: @" + SaveSystem.CurrentSave.Username; - done = true; - SaveSystem.CurrentSave.StoryPosition++; - TerminalBackend.InvokeCommand("sos.save"); - break; - - } - - if (write == true) - { - Console.WriteLine(); - Console.Write("DevX: "); - foreach(char c in textToWrite) - { - Console.Beep(750, TYPE_SPEED_MS); - if (c == '\n') - { - - } - else if (c == '\r') - { - Console.WriteLine(); - } - else - { - Console.Write(c); - } - } - Thread.Sleep(1000); - } - chatProgress += 1; - } - } - - - public static void WriteStory(string json) - { - var thread = new Thread(new ThreadStart(() => - { - var story = JsonConvert.DeserializeObject(json); - - const int TYPESPEED = 45; - - foreach (var line in story.Lines) - { - var localized = Localization.Parse(line); - - - if (line.StartsWith("cmd:")) - { - string[] cmdsplit = line.Replace("cmd:", "").Split(' '); - switch (cmdsplit[0]) - { - case "givecp": - SaveSystem.TransferCodepointsFrom(story.Character, Convert.ToInt32(cmdsplit[1])); - break; - } - } - else - { - Console.Write(story.Character + ": "); - - foreach (var c in localized) - { - Console.Beep(1024, TYPESPEED); - if (c == '\r') - { - - } - else if (c == '\n') - Console.WriteLine(); - else - Console.Write(c); - } - - Console.WriteLine(); - Thread.Sleep(1000); - } - } - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); - })); - thread.IsBackground = true; - thread.Start(); - } - } - - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] - public class StoryAttribute : Attribute - { - /// - /// Creates a new instance of the attribute. - /// - /// The ID of this story plot. - /// - /// - /// The is used to turn a static, public method into a story element. Using the specified argument, the ShiftOS Engine can determine whether this plot has already been experienced, and using the classes, the ID is treated as a special Shiftorium upgrade, and you can use the attribute as well as the various other ways of determining whether a Shiftorium upgrade is installed to determine if this plot has been experienced. - /// - /// - public StoryAttribute(string id) - { - StoryID = id; - } - - public string StoryID { get; private set; } - - } -} diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs deleted file mode 100644 index 9c57aa8..0000000 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ /dev/null @@ -1,534 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using Newtonsoft.Json; -using static ShiftOS.Engine.SaveSystem; - -namespace ShiftOS.Engine -{ - public static class TerminalBackend - { - public static event Action CommandProcessed; - - public static bool Elevated { get; set; } - - public static Dictionary GetArgs(ref string text) - { - bool shouldParse = false; - int argStart = 0; - if (text.Contains("{")) - { - shouldParse = true; - argStart = text.IndexOf('{'); - } - - if (shouldParse == false) - { - string replacement = Regex.Replace(text, @"\t|\n|\r", ""); - text = replacement + "{}"; - shouldParse = true; - argStart = text.IndexOf('{'); - } - - string args = text.Substring(argStart, text.Length - argStart); - - text = text.Remove(argStart, text.Length - argStart).Replace(" ", ""); - return JsonConvert.DeserializeObject>(args); - } - - public static string LastCommand = ""; - - public static void InvokeCommand(string ns, string command, Dictionary arguments, bool isRemote = false) - { - try - { - if (string.IsNullOrWhiteSpace(ns)) - return; - - - bool commandWasClient = RunClient(ns, command, arguments, isRemote); - - if (!commandWasClient && !string.IsNullOrWhiteSpace(ns)) - { - PrefixEnabled = false; - - ServerManager.SendMessage("script", $@"{{ - user: ""{ns}"", - script: ""{command}"", - args: ""{GetSentArgs(arguments)}"" -}}"); - } - - CommandProcessed?.Invoke(ns + "." + command, JsonConvert.SerializeObject(arguments)); - } - catch (Exception ex) - { - Console.WriteLine($"Command parse error: {ex.Message}"); // This shouldn't ever be called now - PrefixEnabled = true; - - } - } - - public static string GetSentArgs(Dictionary argss) - { - Dictionary args = new Dictionary(); - foreach (KeyValuePair arg in argss) - { - args[arg.Key] = arg.Value; - } - return JsonConvert.SerializeObject(args); - } - - public static void InvokeCommand(string text, bool isRemote = false) - { - try - { - if (string.IsNullOrWhiteSpace(text)) - return; - - var args = GetArgs(ref text); - - bool commandWasClient = RunClient(text, args, isRemote); - - if (!commandWasClient) - { - PrefixEnabled = false; - - ServerManager.SendMessage("script", $@"{{ - user: ""{text.Split('.')[0]}"", - script: ""{text.Split('.')[1]}"", - args: ""{GetSentArgs(args)}"" -}}"); - } - CommandProcessed?.Invoke(text, GetSentArgs(args)); - } - catch (Exception ex) - { - Console.WriteLine($"Command parse error: {ex.Message}"); - PrefixEnabled = true; - - } - } - - public static bool PrefixEnabled { get; set; } - - public static bool InStory { get; set; } - - public static string latestCommmand = ""; - - public static event EmptyEventHandler TerminalRequested; - - internal static void OpenTerminal() - { - TerminalRequested?.Invoke(); - } - - public static bool CanRunRemotely(MethodInfo mth, bool isRemote) - { - if (!isRemote) - return true; - - foreach (var attr in mth.GetCustomAttributes(false)) - { - if (attr is RemoteLockAttribute) - return false; - } - - return true; - } - - public static bool RunClient(string ns, string cmd, Dictionary args, bool isRemote = false) - { - return RunClient(ns + "." + cmd, args, isRemote); - } - - - public static bool RunClient(string text, Dictionary argss, bool isRemote = false) - { - Dictionary args = new Dictionary(); - foreach (KeyValuePair arg in argss) - { - args[arg.Key] = arg.Value; - } - return RunClient(text, args, isRemote); - } - - public static bool RunClient(string text, Dictionary args, bool isRemote = false) - { - latestCommmand = text; - - //Console.WriteLine(text + " " + "{" + string.Join(",", args.Select(kv => kv.Key + "=" + kv.Value).ToArray()) + "}" + " " + isRemote); - - foreach (var asmExec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) - { - try - { - 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)) - { - if (CanRunRemotely(method, isRemote)) - { - foreach (var ma in method.GetCustomAttributes(false)) - { - if (ma is Command) - { - var cmd = ma as Command; - if (text.Split('.')[1] == cmd.name) - { - if (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.WriteLine(text + " cannot be ran in a remote session"); - 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; - } - } - } - } - } - } - } - catch { } - } - return false; - } - public static void PrintPrompt() - { - 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(" "); - } - } - - - static TerminalBackend() - { - ServerMessageReceived onMessageReceived = (msg) => - { - if (msg.Name == "trm_invokecommand") - { - string text3 = ""; - string text4 = msg.Contents; - - if (TerminalBackend.PrefixEnabled) - { - text3 = text4.Remove(0, $"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ ".Length); - } - IsForwardingConsoleWrites = true; - if (TerminalBackend.InStory == false) - { - TerminalBackend.InvokeCommand(text3, true); - } - if (TerminalBackend.PrefixEnabled) - { - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); - } - IsForwardingConsoleWrites = false; - } - else if (msg.Name == "pleasewrite") - { - Console.Write(msg.Contents); - } - else if (msg.Name == "handshake_from") - { - var a = JsonConvert.DeserializeObject>(msg.Contents); - string uName = a["username"] as string; - string pass = a["password"] as string; - string sys = a["sysname"] as string; - string guid = msg.GUID; - if (SaveSystem.CurrentSave.Username == uName && SaveSystem.CurrentSave.Password == pass && CurrentSave.SystemName == sys) - { - ForwardGUID = guid; - ServerManager.SendMessage("trm_handshake_accept", $@"{{ - guid: ""{ServerManager.thisGuid}"", - target: ""{guid}"" -}}"); - - IsForwardingConsoleWrites = true; - InvokeCommand("sos.status"); - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); - IsForwardingConsoleWrites = false; - } - } - }; - - ServerManager.MessageReceived += onMessageReceived; - } - - public static bool IsForwardingConsoleWrites { get; internal set; } - public static string ForwardGUID { get; internal set; } - - public static event TextSentEventHandler TextSent; - - public static void SendText(string text) - { - TextSent?.Invoke(text); - } - - } -} diff --git a/ShiftOS_TheReturn/TerminalTextWriter.cs b/ShiftOS_TheReturn/TerminalTextWriter.cs deleted file mode 100644 index 55e27cf..0000000 --- a/ShiftOS_TheReturn/TerminalTextWriter.cs +++ /dev/null @@ -1,131 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.IO; -using System.Windows.Forms; - -namespace ShiftOS.Engine -{ - public class TerminalTextWriter : TextWriter - { - [System.Runtime.InteropServices.DllImport("user32.dll")] - public static extern bool LockWindowUpdate(IntPtr hWndLock); - - - public override Encoding Encoding - { - get - { - return Encoding.Unicode; - } - } - - public ITerminalWidget UnderlyingControl - { - get - { - return AppearanceManager.ConsoleOut; - } - } - - public void select() - { - Desktop.InvokeOnWorkerThread(new Action(() => - { - UnderlyingControl?.SelectBottom(); - - })); - } - - public override void Write(char value) - { - if (TerminalBackend.IsForwardingConsoleWrites) - { - ServerManager.SendMessage("write", $@"{{ - guid: ""{TerminalBackend.ForwardGUID}"", - text: ""{value}"" -}}"); - } - else - { - Desktop.InvokeOnWorkerThread(new Action(() => - { - UnderlyingControl?.Write(value.ToString()); - select(); - })); - } - } - - public override void WriteLine(string value) - { - if (TerminalBackend.IsForwardingConsoleWrites) - { - ServerManager.SendMessage("write", $@"{{ - guid: ""{TerminalBackend.ForwardGUID}"", - text: ""{value + Environment.NewLine}"" -}}"); - } - else - { - - Desktop.InvokeOnWorkerThread(new Action(() => - { - UnderlyingControl?.WriteLine(value); - select(); - })); - } - } - - public void SetLastText() - { - } - - public override void Write(string value) - { - if (TerminalBackend.IsForwardingConsoleWrites) - { - ServerManager.SendMessage("write", $@"{{ - guid: ""{TerminalBackend.ForwardGUID}"", - text: ""{value}"" -}}"); - } - else - { - - Desktop.InvokeOnWorkerThread(new Action(() => - { - UnderlyingControl?.Write(value.ToString()); - select(); - })); - } - } - - - } -} diff --git a/ShiftOS_TheReturn/UniteClient.cs b/ShiftOS_TheReturn/UniteClient.cs deleted file mode 100644 index 8d6a58d..0000000 --- a/ShiftOS_TheReturn/UniteClient.cs +++ /dev/null @@ -1,135 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using ShiftOS.Objects; - -namespace ShiftOS.Unite -{ - public class UniteClient - { - public string Token { get; private set; } - public string BaseURL - { - get - { - return UserConfig.Get().UniteUrl; - } - } - - public string GetDisplayNameId(string id) - { - return MakeCall("/API/GetDisplayName/" + id); - } - - public PongHighscoreModel GetPongHighscores() - { - return JsonConvert.DeserializeObject(MakeCall("/API/GetPongHighscores")); - } - - public UniteClient(string baseurl, string usertoken) - { - //Handled by the servers.json file - //BaseURL = baseurl; - Token = usertoken; - } - - internal string MakeCall(string url) - { - var webrequest = WebRequest.Create(BaseURL + url); - webrequest.Headers.Add("Authentication: Token " + Token); - using (var response = webrequest.GetResponse()) - { - using (var stream = response.GetResponseStream()) - { - using (var reader = new System.IO.StreamReader(stream)) - { - return reader.ReadToEnd(); - } - } - } - } - - public int GetPongCP() - { - return Convert.ToInt32(MakeCall("/API/GetPongCP")); - } - - public int GetPongLevel() - { - return Convert.ToInt32(MakeCall("/API/GetPongLevel")); - } - - public void SetPongLevel(int value) - { - MakeCall("/API/SetPongLevel/" + value.ToString()); - } - - public void SetPongCP(int value) - { - MakeCall("/API/SetPongCP/" + value.ToString()); - } - - public string GetEmail() - { - return MakeCall("/API/GetEmail"); - } - - public string GetSysName() - { - return MakeCall("/API/GetSysName"); - } - - public void SetSysName(string value) - { - MakeCall("/API/SetSysName/" + value); - } - - public string GetDisplayName() - { - return MakeCall("/API/GetDisplayName"); - } - - public void SetDisplayName(string value) - { - MakeCall("/API/SetDisplayName/" + value.ToString()); - } - - public string GetFullName() - { - return MakeCall("/API/GetFullName"); - } - - public void SetFullName(string value) - { - MakeCall("/API/SetFullName/" + value.ToString()); - } - - - public long GetCodepoints() - { - return Convert.ToInt64(MakeCall("/API/GetCodepoints")); - } - - public void SetCodepoints(long value) - { - MakeCall("/API/SetCodepoints/" + value.ToString()); - } - } - - public class PongHighscoreModel - { - public int Pages { get; set; } - public PongHighscore[] Highscores { get; set; } - } - - public class PongHighscore - { - public string UserId { get; set; } - public int Level { get; set; } - public long CodepointsCashout { get; set; } - } -} diff --git a/ShiftOS_TheReturn/UserManagementCommands.cs b/ShiftOS_TheReturn/UserManagementCommands.cs deleted file mode 100644 index 5702e08..0000000 --- a/ShiftOS_TheReturn/UserManagementCommands.cs +++ /dev/null @@ -1,201 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ShiftOS.Objects; - -namespace ShiftOS.Engine -{ - [Namespace("admin")] - [KernelMode] - [RequiresUpgrade("mud_fundamentals")] - public static class AdminUserManagementCommands - { - [Command("add", description = "Add a user to the system.", usage ="name:")] - [RequiresArgument("name")] - public static bool AddUser(Dictionary args) - { - string name = args["name"].ToString(); - if(SaveSystem.CurrentSave.Users.FirstOrDefault(x=>x.Username==name) != null) - { - Console.WriteLine("Error: User already exists."); - return true; - } - - var user = new ClientSave - { - Username = name, - Password = "", - Permissions = UserPermissions.User - }; - SaveSystem.CurrentSave.Users.Add(user); - Console.WriteLine($"Creating new user \"{name}\" with no password and User permissions."); - SaveSystem.SaveGame(); - return true; - } - - [Command("remove", description = "Remove a user from the system.", usage = "name:")] - [RequiresArgument("name")] - public static bool RemoveUser(Dictionary args) - { - string name = args["name"].ToString(); - if (SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name) == null) - { - Console.WriteLine("Error: User doesn't exist."); - return true; - } - - var user = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == name); - if(user.Username != SaveSystem.CurrentUser.Username) - { - Console.WriteLine("Error: Cannot remove yourself."); - return true; - } - SaveSystem.CurrentSave.Users.Remove(user); - Console.WriteLine($"Removing user \"{name}\" from system..."); - SaveSystem.SaveGame(); - return true; - } - - - - - [Command("set_acl")] - [RequiresArgument("user")] - [RequiresArgument("val")] - public static bool SetUserPermission(Dictionary args) - { - int permission = 0; - string username = args["user"].ToString(); - try - { - permission = Convert.ToInt32(args["val"].ToString()); - } - catch - { - Console.WriteLine("Error: Permission value must be an integer."); - return true; - } - - if(SaveSystem.CurrentSave.Users.FirstOrDefault(x=>x.Username==username) == null) - { - Console.WriteLine("Error: User not found."); - return true; - } - - UserPermissions uperm = UserPermissions.Guest; - - switch (permission) - { - case 0: - uperm = UserPermissions.Guest; - break; - case 1: - uperm = UserPermissions.User; - break; - case 2: - uperm = UserPermissions.Admin; - break; - case 3: - uperm = UserPermissions.Root; - break; - default: - Console.WriteLine("Permission value must be between 0 and 4."); - return true; - } - - //Permissions are backwards... oops... - if(uperm < SaveSystem.CurrentUser.Permissions) - { - Console.WriteLine("Error: Cannot set user permissions to values greater than your own!"); - return true; - } - - var oldperm = SaveSystem.Users.FirstOrDefault(x => x.Username == username).Permissions; - if (SaveSystem.CurrentUser.Permissions > oldperm) - { - Console.WriteLine("Error: Can't set the permission of this user. They have more rights than you."); - return true; - } - - SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == username).Permissions = uperm; - Console.WriteLine("User permissions updated."); - return true; - } - - - [Command("users", description = "Get a list of all users on the system.")] - public static bool GetUsers() - { - foreach (var u in SaveSystem.CurrentSave.Users) - { - if (u.Username == SaveSystem.CurrentUser.Username) - { - ConsoleEx.ForegroundColor = ConsoleColor.Magenta; - ConsoleEx.Bold = true; - } - else - { - ConsoleEx.ForegroundColor = ConsoleColor.Gray; - ConsoleEx.Bold = false; - } - Console.WriteLine(u.Username); - } - return true; - } - } - - [Namespace("user")] - [RequiresUpgrade("mud_fundamentals")] - public static class UserManagementCommands - { - [Command("login", description = "Log in as another user.")] - [RequiresArgument("user")] - [RequiresArgument("pass")] - public static bool Login(Dictionary args) - { - string user = args["user"].ToString(); - string pass = args["pass"].ToString(); - - var usr = SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == user); - if(usr==null) - { - Console.WriteLine("Error: No such user."); - return true; - } - - if (usr.Password != pass) - { - Console.WriteLine("Access denied."); - return true; - } - - SaveSystem.CurrentUser = usr; - Console.WriteLine("Access granted."); - return true; - } - - [Command("setpass", description ="Allows you to set your password to a new value.", usage ="old:,new:")] - [RequiresArgument("old")] - [RequiresArgument("new")] - public static bool SetPassword(Dictionary args) - { - string old = args["old"].ToString(); - string newpass = args["new"].ToString(); - - if(old == SaveSystem.CurrentUser.Password) - { - SaveSystem.CurrentUser.Password = newpass; - SaveSystem.CurrentSave.Users.FirstOrDefault(x => x.Username == SaveSystem.CurrentUser.Username).Password = newpass; - Console.WriteLine("Password set successfully."); - SaveSystem.SaveGame(); - } - else - { - Console.WriteLine("Passwords do not match."); - } - return true; - } - } -}