diff options
Diffstat (limited to 'source/WindowsFormsApplication1/API.cs')
| -rw-r--r-- | source/WindowsFormsApplication1/API.cs | 1282 |
1 files changed, 628 insertions, 654 deletions
diff --git a/source/WindowsFormsApplication1/API.cs b/source/WindowsFormsApplication1/API.cs index 4199223..a1be389 100644 --- a/source/WindowsFormsApplication1/API.cs +++ b/source/WindowsFormsApplication1/API.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Media; using System.Text; using System.Threading.Tasks; -using System.Windows.Forms; +using ShiftUI; using System.IO.Compression; using System.Drawing; using Newtonsoft.Json; @@ -80,337 +80,391 @@ namespace ShiftOS } - public class API - { - public static Dictionary<Form, string> OpenGUIDs = new Dictionary<Form, string>(); - public static Dictionary<string, Control> DEF_PanelGUIDs = new Dictionary<string, Control>(); - - - /// <summary> - /// Settings file. - /// </summary> - public static Settings LoadedSettings = null; - - /// <summary> - /// Whether or not dev commands like '05tray' are available. - /// Typically, this is set to true if the release is classified as - /// an alpha, beta, or release candidate. - /// - /// Turn it off if the release is the final RC, or the stable release! - /// - /// Enabling developer mode will cause the save engine to not encrypt the save file - /// or Shiftorium Registry on save, enabling you to easily modify your save - /// to test new features or to bring in lots of codepoints. This is why - /// Developer mode should ALWAYS be off in non-dev releases, to prevent cheating. - /// </summary> - public static bool DeveloperMode = true; - - /// <summary> - /// If this is true, only certain applications will open and only - /// certain features will work. - /// - /// This is useful for story plots like the End Game where you don't - /// want the user being distracted by novelty features when they should - /// be focusing on what's happening. - /// - /// Think of it like the opposite of what Developer Mode would do. - /// </summary> - public static bool LimitedMode = false; - - public static bool InfoboxesPlaySounds = true; - - public static void SkinControl(Control c) - { - if(c is Button) - { - var b = c as Button; - b.FlatStyle = FlatStyle.Flat; - } - if(c is Panel || c is FlowLayoutPanel) - { - foreach(Control child in c.Controls) - { - SkinControl(child); - } - } - } - - public static List<Process> RunningModProcesses = new List<Process>(); - public static Dictionary<string, string> CommandAliases = new Dictionary<string, string>(); - public static Terminal LoggerTerminal = null; - - /// <summary> - /// Logs an exception to the log. - /// </summary> - /// <param name="Message">The text to log.</param> - /// <param name="fatal">Is it a fatal crash?</param> - public static void LogException(string Message, bool fatal) - { - if(!File.Exists(Paths.SystemDir + "_Log.txt")) - { - if (fatal == true) - { - File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " [ExWatch/WARNING] ShiftOS has encountered an UNHANDLED exception with message \"" + Message + "\". Report this to Michael as well as what you were doing when it happened ASAP."); - } - else - { - File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " ShiftOS encountered a handled exception with message \"" + Message + "\" and was able to keep going. Ignore this."); - } - } - else - { - List<string> Entries = new List<string>(); - foreach(string entry in File.ReadAllLines(Paths.SystemDir + "_Log.txt")) { - Entries.Add(entry); - } - if (fatal == true) - { - Entries.Add(GetLogTime() + " [ExWatch/WARNING] ShiftOS has encountered an UNHANDLED exception with message \"" + Message + "\". Report this to Michael as well as what you were doing when it happened ASAP."); - } - else - { - Entries.Add(GetLogTime() + " ShiftOS encountered a handled exception with message \"" + Message + "\" and was able to keep going. Ignore this."); - } - File.WriteAllLines(Paths.SystemDir + "_Log.txt", Entries.ToArray()); - } - } - - /// <summary> - /// Logs text to the log file. - /// </summary> - /// <param name="Message">The text to log.</param> - public static void Log(string Message) - { - if (!File.Exists(Paths.SystemDir + "_Log.txt")) - { - File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " " + Message); - } - else - { - List<string> Entries = new List<string>(); - foreach (string entry in File.ReadAllLines(Paths.SystemDir + "_Log.txt")) - { - Entries.Add(entry); - } - Entries.Add(GetLogTime() + " " + Message); - File.WriteAllLines(Paths.SystemDir + "_Log.txt", Entries.ToArray()); - } - } - - /// <summary> - /// Gets a proper-formatted date/time string for the log. - /// </summary> - /// <returns></returns> - public static string GetLogTime() - { - return "[" + DateTime.Now.ToLongDateString() + "\\" + DateTime.Now.ToLongTimeString() + "]"; - } - - /// <summary> - /// Property representing the currently loaded name pack. - /// </summary> - public static Skinning.NamePack LoadedNames - { - get - { - if (Skinning.Utilities.LoadedNames != null) - { - return Skinning.Utilities.LoadedNames; - } - else - { - Skinning.Utilities.LoadedNames = new Skinning.NamePack(); - Skinning.Utilities.loadedSkin.EmbeddedNamePackPath = "names.npk"; - Skinning.Utilities.SaveEmbeddedNamePack(); - Log("[Name Changer] Couldn't locate loaded name pack, using default name pack."); - return Skinning.Utilities.LoadedNames; - } - } - } - - /// <summary> - /// Adds a command line alias. - /// </summary> - /// <param name="key">Alias name</param> - /// <param name="value">Command to run.</param> - /// <returns></returns> - public static bool AddAlias(string key, string value) - { - if(!AliasExists(key)) - { - CommandAliases.Add(key, value); - return true; - } - else - { - return false; - } - } - - /// <summary> - /// Saves alias list to save game. - /// </summary> - public static void SaveAliases() - { - string json = JsonConvert.SerializeObject(CommandAliases); - File.WriteAllText(Paths.SystemDir + "_aliases.json", json); - } - - /// <summary> - /// Loads alias list from the save game. - /// </summary> - public static void LoadAliases() - { - if (File.Exists(Paths.SystemDir + "_aliases.json")) { - string json = File.ReadAllText(Paths.SystemDir + "_aliases.json"); - CommandAliases = JsonConvert.DeserializeObject<Dictionary<string, string>>(json); - } - else - { - CommandAliases = new Dictionary<string, string>(); - } - - } - - /// <summary> - /// Removes an alias from the list. - /// </summary> - /// <param name="key">Alias to remove.</param> - /// <returns>Whether the alias could be removed.</returns> - public static bool RemoveAlias(string key) - { - if(AliasExists(key)) - { - CommandAliases.Remove(key); - return true; - } - else - { - return false; - } - } - - /// <summary> - /// Checks if the provided alias exists. - /// </summary> - /// <param name="key">The alias to check.</param> - /// <returns>Whether the alias exists.</returns> - public static bool AliasExists(string key) - { - bool no = false; - foreach(KeyValuePair<string, string> kv in CommandAliases) - { - if(kv.Key == key) - { - no = true; - } - } - return no; - } - - /// <summary> - /// I have no idea what this does - Michael - /// </summary> - /// <param name="AppName"></param> - public static void CreateNewLoggerTerminal(string AppName) - { - CreateForm(new Terminal(true), AppName, Properties.Resources.iconTerminal); - } - - public const string HiddenAPMCommand = "0Ifm0DcBBy10VZo/p4r1Jg=="; - public const string HiddenBTNConvertCommand = "js2qrls5kvZnutMbfH46sUKzKVrBtjzPlWn/wIIe/3g="; - public const string HiddenDodgeCommand = "mpL4WPUoDcZrsXnNUJ5RWQ=="; - public const string HiddenLabyrinthCommand = "NbNzpplGKaS5D/RdwrQMXw=="; - public const string HiddenQuickChatCommand = "iQm+/qDqgkHT/zgPiYRlZQ=="; - public const string HiddenShiftnetCommand = "NCM++hbZox7B+m9tXRXGnw=="; - public const string HiddenBWalletCommand = "1nLiZELFcaxkXDufrLuyfw=="; - public const string HiddenBDiggerCommand = "g/efSjsaglt//dr3XHnPOw=="; - public const string HiddenDecryptorCommand = "CYPXaweggfWAuS7ONt/OPQ=="; - - /// <summary> - /// Launches an saa file, hooks it up to the Lua API, and runs it. - /// </summary> - /// <param name="modSAA">File to run.</param> - public static void LaunchMod(string modSAA) - { - if (!LimitedMode) - { - if (Upgrades["shiftnet"] == true) - { - if (File.Exists(modSAA)) - { - if (File.ReadAllText(modSAA) == HiddenAPMCommand) - { - CreateForm(new Appscape(), "Appscape Package Manager", Properties.Resources.iconAppscape); - } - else if (File.ReadAllText(modSAA) == HiddenDecryptorCommand) - { - CreateForm(new ShiftnetDecryptor(), "Shiftnet Decryptor", Properties.Resources.iconShiftnet); - } - else if (File.ReadAllText(modSAA) == HiddenBDiggerCommand) - { - CreateForm(new BitnoteDigger(), "Bitnote Digger", Properties.Resources.iconBitnoteDigger); - } - else if (File.ReadAllText(modSAA) == HiddenBWalletCommand) - { - CreateForm(new BitnoteWallet(), "Bitnote Wallet", Properties.Resources.iconBitnoteWallet); - } - else if (File.ReadAllText(modSAA) == HiddenShiftnetCommand) - { - CreateForm(new Shiftnet(), "Shiftnet", Properties.Resources.iconShiftnet); - } - else if (File.ReadAllText(modSAA) == HiddenBTNConvertCommand) - { - CreateForm(new BitnoteConverter(), "Bitnote Converter", Properties.Resources.iconBitnoteWallet); - } - else if (File.ReadAllText(modSAA) == HiddenDodgeCommand) - { - CreateForm(new Dodge(), "Dodge", Properties.Resources.iconDodge); - } - else if (File.ReadAllText(modSAA) == HiddenLabyrinthCommand) - { - CreateForm(new Labyrinth(), "Labyrinth", null); - } - else - { - try - { - ExtractFile(modSAA, Paths.Mod_Temp, true); - var l = new LuaInterpreter(Paths.Mod_Temp + "main.lua"); - } - catch (Exception ex) - { - LogException("Error launching mod file (.saa): " + ex.Message, false); - CreateInfoboxSession("Error", "Could not launch the .saa file you specified. It is unsupported by this version of ShiftOS.", infobox.InfoboxMode.Info); - } - } - var story_rnd = new Random(); - int story_chance = story_rnd.Next(0, 3); - switch (story_chance) { - case 2: - if(API.Upgrades["holochat"] == false) - { - var t = new Terminal(); - API.CreateForm(t, API.LoadedNames.TerminalName, API.GetIcon("Terminal")); - t.StartDevXFuriousStory(); - t.BringToFront(); - } - break; - } - - } - else - { - throw new ModNotFoundException(); - } - } - } - else - { - CreateInfoboxSession("Limited mode", "ShiftOS is in limited mode and cannot perform this action. Please complete the current Mission first.", infobox.InfoboxMode.Info); - } - } - + public class API + { + public static Dictionary<Form, string> OpenGUIDs = new Dictionary<Form, string>(); + public static Dictionary<string, Widget> DEF_PanelGUIDs = new Dictionary<string, Widget>(); + + + /// <summary> + /// Settings file. + /// </summary> + public static Settings LoadedSettings = null; + + /// <summary> + /// Whether or not dev commands like '05tray' are available. + /// Typically, this is set to true if the release is classified as + /// an alpha, beta, or release candidate. + /// + /// Turn it off if the release is the final RC, or the stable release! + /// + /// Enabling developer mode will cause the save engine to not encrypt the save file + /// or Shiftorium Registry on save, enabling you to easily modify your save + /// to test new features or to bring in lots of codepoints. This is why + /// Developer mode should ALWAYS be off in non-dev releases, to prevent cheating. + /// </summary> + public static bool DeveloperMode = true; + + /// <summary> + /// If this is true, only certain applications will open and only + /// certain features will work. + /// + /// This is useful for story plots like the End Game where you don't + /// want the user being distracted by novelty features when they should + /// be focusing on what's happening. + /// + /// Think of it like the opposite of what Developer Mode would do. + /// </summary> + public static bool LimitedMode = false; + + public static bool InfoboxesPlaySounds = true; + + public static void SkinWidget(Widget c) + { + if (c is Button) + { + var b = c as Button; + b.FlatStyle = FlatStyle.Standard; + } + if (c is Panel || c is FlowLayoutPanel) + { + foreach (Widget child in c.Widgets) + { + SkinWidget(child); + } + } + } + + public static List<Process> RunningModProcesses = new List<Process>(); + public static Dictionary<string, string> CommandAliases = new Dictionary<string, string>(); + public static Terminal LoggerTerminal = null; + + // Alternate Names for True and False + public static bool yes = true; + public static bool no = false; + + /// <summary> + /// Logs an exception to the log. + /// </summary> + /// <param name="Message">The text to log.</param> + /// <param name="fatal">Is it a fatal crash?</param> + public static void LogException(string Message, bool fatal) + { + if (!File.Exists(Paths.SystemDir + "_Log.txt")) + { + if (fatal == true) + { + File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " [ExWatch/WARNING] ShiftOS has encountered an UNHANDLED exception with message \"" + Message + "\". Report this to Michael as well as what you were doing when it happened ASAP."); + } + else + { + File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " ShiftOS encountered a handled exception with message \"" + Message + "\" and was able to keep going. Ignore this."); + } + } + else + { + List<string> Entries = new List<string>(); + foreach (string entry in File.ReadAllLines(Paths.SystemDir + "_Log.txt")) + { + Entries.Add(entry); + } + if (fatal == true) + { + Entries.Add(GetLogTime() + " [ExWatch/WARNING] ShiftOS has encountered an UNHANDLED exception with message \"" + Message + "\". Report this to Michael as well as what you were doing when it happened ASAP."); + } + else + { + Entries.Add(GetLogTime() + " ShiftOS encountered a handled exception with message \"" + Message + "\" and was able to keep going. Ignore this."); + } + File.WriteAllLines(Paths.SystemDir + "_Log.txt", Entries.ToArray()); + } + } + + /// <summary> + /// Logs text to the log file. + /// </summary> + /// <param name="Message">The text to log.</param> + public static void Log(string Message) + { + if (!File.Exists(Paths.SystemDir + "_Log.txt")) + { + File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " " + Message); + } + else + { + List<string> Entries = new List<string>(); + foreach (string entry in File.ReadAllLines(Paths.SystemDir + "_Log.txt")) + { + Entries.Add(entry); + } + Entries.Add(GetLogTime() + " " + Message); + File.WriteAllLines(Paths.SystemDir + "_Log.txt", Entries.ToArray()); + } + } + + /// <summary> + /// Gets a proper-formatted date/time string for the log. + /// </summary> + /// <returns></returns> + public static string GetLogTime() + { + return "[" + DateTime.Now.ToLongDateString() + "\\" + DateTime.Now.ToLongTimeString() + "]"; + } + + /// <summary> + /// Property representing the currently loaded name pack. + /// </summary> + public static Skinning.NamePack LoadedNames + { + get + { + if (Skinning.Utilities.LoadedNames != null) + { + return Skinning.Utilities.LoadedNames; + } + else + { + Skinning.Utilities.LoadedNames = new Skinning.NamePack(); + Skinning.Utilities.loadedSkin.EmbeddedNamePackPath = "names.npk"; + Skinning.Utilities.SaveEmbeddedNamePack(); + Log("[Name Changer] Couldn't locate loaded name pack, using default name pack."); + return Skinning.Utilities.LoadedNames; + } + } + } + + /// <summary> + /// Adds a command line alias. + /// </summary> + /// <param name="key">Alias name</param> + /// <param name="value">Command to run.</param> + /// <returns></returns> + public static bool AddAlias(string key, string value) + { + if (!AliasExists(key)) + { + CommandAliases.Add(key, value); + return true; + } + else + { + return false; + } + } + + /// <summary> + /// Saves alias list to save game. + /// </summary> + public static void SaveAliases() + { + string json = JsonConvert.SerializeObject(CommandAliases); + File.WriteAllText(Paths.SystemDir + "_aliases.json", json); + } + + /// <summary> + /// Loads alias list from the save game. + /// </summary> + public static void LoadAliases() + { + if (File.Exists(Paths.SystemDir + "_aliases.json")) + { + string json = File.ReadAllText(Paths.SystemDir + "_aliases.json"); + CommandAliases = JsonConvert.DeserializeObject<Dictionary<string, string>>(json); + } + else + { + CommandAliases = new Dictionary<string, string>(); + } + + } + + /// <summary> + /// Removes an alias from the list. + /// </summary> + /// <param name="key">Alias to remove.</param> + /// <returns>Whether the alias could be removed.</returns> + public static bool RemoveAlias(string key) + { + if (AliasExists(key)) + { + CommandAliases.Remove(key); + return true; + } + else + { + return false; + } + } + + /// <summary> + /// Checks if the provided alias exists. + /// </summary> + /// <param name="key">The alias to check.</param> + /// <returns>Whether the alias exists.</returns> + public static bool AliasExists(string key) + { + bool nay = false; + foreach (KeyValuePair<string, string> kv in CommandAliases) + { + if (kv.Key == key) + { + nay = true; + } + } + return nay; + } + + /// <summary> + /// I have no idea what this does - Michael + /// </summary> + /// <param name="AppName"></param> + public static void CreateNewLoggerTerminal(string AppName) + { + CreateForm(new Terminal(true), AppName, Properties.Resources.iconTerminal); + } + + public const string HiddenAPMCommand = "0Ifm0DcBBy10VZo/p4r1Jg=="; + public const string HiddenBTNConvertCommand = "js2qrls5kvZnutMbfH46sUKzKVrBtjzPlWn/wIIe/3g="; + public const string HiddenDodgeCommand = "mpL4WPUoDcZrsXnNUJ5RWQ=="; + public const string HiddenLabyrinthCommand = "NbNzpplGKaS5D/RdwrQMXw=="; + public const string HiddenQuickChatCommand = "iQm+/qDqgkHT/zgPiYRlZQ=="; + public const string HiddenShiftnetCommand = "NCM++hbZox7B+m9tXRXGnw=="; + public const string HiddenBWalletCommand = "1nLiZELFcaxkXDufrLuyfw=="; + public const string HiddenBDiggerCommand = "g/efSjsaglt//dr3XHnPOw=="; + public const string HiddenDecryptorCommand = "CYPXaweggfWAuS7ONt/OPQ=="; + + /// <summary> + /// Launches an saa file, hooks it up to the Lua API, and runs it. + /// </summary> + /// <param name="modSAA">File to run.</param> + public static void LaunchMod(string modSAA) + { + if (!LimitedMode) + { + if (Upgrades["shiftnet"] == true) + { + if (File.Exists(modSAA)) + { + if (File.ReadAllText(modSAA) == HiddenAPMCommand) + { + CreateForm(new Appscape(), "Appscape Package Manager", Properties.Resources.iconAppscape); + } + else if (File.ReadAllText(modSAA) == HiddenDecryptorCommand) + { + CreateForm(new ShiftnetDecryptor(), "Shiftnet Decryptor", Properties.Resources.iconShiftnet); + } + else if (File.ReadAllText(modSAA) == HiddenBDiggerCommand) + { + CreateForm(new BitnoteDigger(), "Bitnote Digger", Properties.Resources.iconBitnoteDigger); + } + else if (File.ReadAllText(modSAA) == HiddenBWalletCommand) + { + CreateForm(new BitnoteWallet(), "Bitnote Wallet", Properties.Resources.iconBitnoteWallet); + } + else if (File.ReadAllText(modSAA) == HiddenShiftnetCommand) + { + CreateForm(new Shiftnet(), "Shiftnet", Properties.Resources.iconShiftnet); + } + else if (File.ReadAllText(modSAA) == HiddenBTNConvertCommand) + { + CreateForm(new BitnoteConverter(), "Bitnote Converter", Properties.Resources.iconBitnoteWallet); + } + else if (File.ReadAllText(modSAA) == HiddenDodgeCommand) + { + CreateForm(new Dodge(), "Dodge", Properties.Resources.iconDodge); + } + else if (File.ReadAllText(modSAA) == HiddenLabyrinthCommand) + { + CreateForm(new Labyrinth(), "Labyrinth", null); + } + else + { + try + { + ExtractFile(modSAA, Paths.Mod_Temp, true); + var l = new LuaInterpreter(Paths.Mod_Temp + "main.lua"); + } + catch (Exception ex) + { + LogException("Error launching mod file (.saa): " + ex.Message, false); + CreateInfoboxSession("Error", "Could not launch the .saa file you specified. It is unsupported by this version of ShiftOS.", infobox.InfoboxMode.Info); + } + } + var story_rnd = new Random(); + int story_chance = story_rnd.Next(0, 3); + switch (story_chance) + { + case 2: + if (API.Upgrades["holochat"] == false) + { + var t = new Terminal(); + API.CreateForm(t, API.LoadedNames.TerminalName, API.GetIcon("Terminal")); + t.StartDevXFuriousStory(); + t.BringToFront(); + } + break; + } + + } + else + { + throw new ModNotFoundException(); + } + } + } + else + { + CreateInfoboxSession("Limited mode", "ShiftOS is in limited mode and cannot perform this action. Please complete the current Mission first.", infobox.InfoboxMode.Info); + } + } + + /// <summary> + /// Base64 Function + /// </summary> + public static class Base64 + { + public static string Encrypt(string text) + { + return Convert.ToBase64String(Encoding.UTF8.GetBytes(text)); + } + + public static string Decrypt(string text) + { + return Encoding.UTF8.GetString(Convert.FromBase64String(text)); + } + } + + /// <summary> + /// Hashing API + /// By Carver Harrison (@carverh) + /// </summary> + public static class Hash + { + public static string MD5(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.MD5.Create(text).Hash); + } + public static string SHA1(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.SHA1.Create(text).Hash); + } + public static string SHA256(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.SHA256.Create(text).Hash); + } + public static string SHA384(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.SHA384.Create(text).Hash); + } + public static string SHA512(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.SHA512.Create(text).Hash); + } + public static string DSA(string text) + { + return Encoding.UTF8.GetString(System.Security.Cryptography.DSA.Create().CreateSignature(Encoding.UTF8.GetBytes(text))); + } + } /// <summary> /// Source: http://stackoverflow.com/questions/10168240/encrypting-decrypting-a-string-in-c-sharp @@ -661,7 +715,7 @@ namespace ShiftOS public static void CreateFileSkimmerSession(string Filters, File_Skimmer.FileSkimmerMode mode) { FileSkimmerSession = new File_Skimmer(mode, Filters); - CreateForm(FileSkimmerSession, "File Skimmer", Properties.Resources.iconFileSkimmer); + CreateForm(FileSkimmerSession, "File Skimmer", ShiftOS.Properties.Resources.iconFileSkimmer); } /// <summary> @@ -1070,136 +1124,44 @@ namespace ShiftOS { API.CurrentSession = new ShiftOSDesktop(); } - try + + formToCreate.Text = AppName; + formToCreate.TopMost = true; + formToCreate.Show(); + var brdr = new WindowBorder(AppName, AppIcon); + brdr.Tag = "api_brdr"; + brdr.justopened = true; + formToCreate.Widgets.Add(brdr); + brdr.Show(); + foreach(Widget widget in formToCreate.Body.Widgets) { - if (Upgrades["multitasking"] == false && formToCreate.Name != "infobox") + if(widget != brdr) { - CloseEverything(); + brdr.pgcontents.Widgets.Add(widget); + widget.Show(); } - var bw = new BackgroundWorker(); - bw.DoWork += (object sen, DoWorkEventArgs eva) => - { - WindowComposition.SafeToAddControls = false; - //bugfix: Close any terminal if WindowedTerminal isn't installed. - if (Upgrades["windowedterminal"] == false) - { - API.CurrentSession.Invoke(new Action(() => - { - foreach (Form frm in OpenPrograms) - { - if (frm.Name.ToLower() == "terminal") - { - API.CurrentSession.Invoke(new Action(() => - { - frm.Close(); - })); - } - } - })); - } - WindowBorder brdr = new WindowBorder(AppName, AppIcon); - brdr.Name = "api_brdr"; - formToCreate.Controls.Add(brdr); - formToCreate.ShowInTaskbar = false; - brdr.Show(); - formToCreate.FormBorderStyle = FormBorderStyle.None; - brdr.Dock = DockStyle.Fill; - BordersToUpdate.Add(brdr); - List<Control> duplicates = new List<Control>(); - foreach (Control ctrl in formToCreate.Controls) - { - if (ctrl.Name != "api_brdr") - { - ctrl.Hide(); - brdr.pgcontents.Controls.Add(ctrl); - duplicates.Add(ctrl); - } - } - foreach (Control ctrl in duplicates) - { - try - { - formToCreate.Controls.Remove(ctrl); - ctrl.Show(); - SkinControl(ctrl); - } - catch - { - API.CurrentSession.Invoke(new Action(() => - { - ctrl.Show(); - SkinControl(ctrl); - })); - } - } - WindowComposition.ShowForm(formToCreate, CurrentSkin.WindowOpenAnimation); - API.CurrentSession.Invoke(new Action(() => - { - brdr.justopened = true; - formToCreate.TopMost = true; - - //Open terminal on CTRL+T press on any form. - formToCreate.KeyDown += (object sender, KeyEventArgs e) => - { - if (e.KeyCode == Keys.T && e.Control && formToCreate.Name != "Terminal") - { - CurrentSession.InvokeCTRLT(); - } - if (formToCreate.Name != "Terminal" || Upgrades["windowedterminal"] == true) - { - //Movable Windows - if (API.Upgrades["movablewindows"] == true) - { - if (e.KeyCode == Keys.A && e.Control) - { - e.Handled = true; - formToCreate.Location = new Point(formToCreate.Location.X - 30, formToCreate.Location.Y); - } - if (e.KeyCode == Keys.D && e.Control) - { - e.Handled = true; - formToCreate.Location = new Point(formToCreate.Location.X + 30, formToCreate.Location.Y); - } - if (e.KeyCode == Keys.W && e.Control) - { - e.Handled = true; - formToCreate.Location = new Point(formToCreate.Location.X, formToCreate.Location.Y - 30); - } - if (e.KeyCode == Keys.S && e.Control) - { - e.Handled = true; - formToCreate.Location = new Point(formToCreate.Location.X, formToCreate.Location.Y + 30); - } - } - } - }; - formToCreate.TransparencyKey = Skinning.Utilities.globaltransparencycolour; - OpenPrograms.Add(formToCreate); - if (AppName == "Enemy Hacker") - { - API.CurrentSession.Invoke(new Action(() => - { - formToCreate.Left = Screen.PrimaryScreen.Bounds.Width - formToCreate.Width; - })); - } - else if (AppName == "You") - { - API.CurrentSession.Invoke(new Action(() => - { - formToCreate.Left = 0; - })); - } - })); - WindowComposition.SafeToAddControls = true; - API.OpenGUIDs.Add(formToCreate, Guid.NewGuid().ToString()); - API.CurrentSession.Invoke(new Action(() => { CurrentSession.InvokeWindowOp("open", formToCreate); })); - }; - bw.RunWorkerAsync(); - } - catch - { - } + brdr.Dock = DockStyle.Fill; + BordersToUpdate.Add(brdr); + formToCreate.Body.BorderStyle = BorderStyle.None; + formToCreate.TopMost = true; + brdr.setupall(); + formToCreate.FormBorderStyle = FormBorderStyle.None; + brdr.BringToFront(); + //REALLY HACKY WAY TO FIX BORDERS. it works. + Form formToRoll = formToCreate; + formToRoll.Tag = formToRoll.Width.ToString() + "," + formToRoll.Height.ToString() + "," + formToRoll.MinimumSize.Width.ToString() + "," + formToRoll.MinimumSize.Height.ToString() + " " + formToRoll.Location.X.ToString() + "," + formToRoll.Location.Y.ToString(); + formToRoll.MinimumSize = new Size(0, 0); + formToRoll.Height = API.CurrentSkin.titlebarheight; + string xyraw = (string)formToRoll.Tag; + string[] data = xyraw.Split(' '); + string[] xy = data[0].Split(','); + int x = Convert.ToInt16(xy[0]); + int y = Convert.ToInt16(xy[1]); + int mx = Convert.ToInt16(xy[2]); + int my = Convert.ToInt16(xy[3]); + formToRoll.Size = new Size(x, y); + formToRoll.MinimumSize = new Size(mx, my); } /// <summary> @@ -1784,204 +1746,215 @@ namespace ShiftOS /// <returns>Whether the program could be opened.</returns> public static bool OpenProgram(string cmd) { - bool succeeded = true; - switch (cmd) - { - - case "settings": - API.CreateForm(new GameSettings(), "Settings", API.GetIcon("Settings")); - break; - case "credits": - var c = new CreditScroller(); - c.FormBorderStyle = FormBorderStyle.None; - c.Show(); - c.WindowState = FormWindowState.Maximized; - c.TopMost = true; - break; - case "netbrowse": - if(Upgrades["networkbrowser"]) - { - CreateForm(new NetworkBrowser(), "Network Browser", GetIcon("NetworkBrowser")); - } - else - { - succeeded = false; - } - break; - case "quests": - if(LimitedMode) - { - CreateForm(new FinalMission.QuestViewer(), "Quest Viewer", GetIcon("QuestViewer")); - } - else - { - succeeded = false; - } - break; - case "iconmanager": - if (!LimitedMode) - { - if (API.Upgrades["iconmanager"]) - { - CreateForm(new IconManager(), "Icon Manager", GetIcon("IconManager")); - - } - else - { - succeeded = false; - } - } - else - { - succeeded = false; - } - break; - case "knowledge_input": - case "ki": - if (!LimitedMode) - { - API.CreateForm(new KnowledgeInput(), API.LoadedNames.KnowledgeInputName, GetIcon("KI")); - } - else - { - succeeded = false; - } - break; - case "holochat": - if(API.Upgrades["holochat"] == true) - { - API.CreateForm(new HoloChat(), "HoloChat", GetIcon("HoloChat")); - } - else - { - succeeded = false; - } - break; - case "namechanger": - case "name_changer": - if (!LimitedMode) - { - if (API.Upgrades["namechanger"] == true) - { - CreateForm(new NameChanger(), LoadedNames.NameChangerName, GetIcon("NameChanger")); - } - else - { - succeeded = false; - } - } - else - { - succeeded = false; - } - break; - case "artpad": - if (!LimitedMode) - { - if (API.Upgrades["artpad"] == true) - { - CreateForm(new Artpad(), LoadedNames.ArtpadName, GetIcon("Artpad")); - } - else - { - succeeded = false; - } - } - else - { - succeeded = false; - } - break; - case "textpad": - if(Upgrades["textpad"] == true) - { - CreateForm(new TextPad(), "TextPad", GetIcon("TextPad")); - } else - { - succeeded = false; - } - break; - case "skinloader": - case "skin_loader": - if (!LimitedMode) - { - if (Upgrades["skinning"] == true) - { - CreateForm(new SkinLoader(), "Skin Loader", GetIcon("SkinLoader")); - } - else - { - succeeded = false; - } - } - else - { - succeeded = false; - } - break; - case "shifter": - if (!LimitedMode) - { - if (Upgrades["shifter"] == true) - { - CreateForm(new Shifter(), "Shifter", GetIcon("Shifter")); - } - else - { - succeeded = false; - } - } - else - { - succeeded = false; - } - break; - case "pong": - if (!LimitedMode) - { - if (Upgrades["pong"] == true) - { - CreateForm(new Pong(), "Pong", GetIcon("Pong")); - } - else - { - succeeded = false; - } - } - else - { - succeeded = false; - } - break; - case "file_skimmer": - if (Upgrades["fileskimmer"] == true) - { - CreateForm(new File_Skimmer(), CurrentSave.FileSkimmerName, GetIcon("FileSkimmer")); - } - else - { - succeeded = false; - } - break; - case "shiftorium": - if (!LimitedMode) - { - CreateForm(new Shiftorium.Frontend(), LoadedNames.ShiftoriumName, GetIcon("Shiftorium")); - } - else - { - succeeded = false; - } - break; - default: - succeeded = false; - break; - - } + bool succeeded = true; + try + { + switch (cmd) + { + case "settings": + API.CreateForm(new GameSettings(), "Settings", API.GetIcon("Settings")); + break; + case "credits": + var c = new CreditScroller(); + c.FormBorderStyle = FormBorderStyle.None; + c.Show(); + c.WindowState = FormWindowState.Maximized; + c.TopMost = true; + break; + case "netbrowse": + if (Upgrades["networkbrowser"]) + { + CreateForm(new NetworkBrowser(), "Network Browser", GetIcon("NetworkBrowser")); + } + else + { + succeeded = false; + } + break; + case "quests": + if (LimitedMode) + { + CreateForm(new FinalMission.QuestViewer(), "Quest Viewer", GetIcon("QuestViewer")); + } + else + { + succeeded = false; + } + break; + case "iconmanager": + if (!LimitedMode) + { + if (API.Upgrades["iconmanager"]) + { + CreateForm(new IconManager(), "Icon Manager", GetIcon("IconManager")); + + } + else + { + succeeded = false; + } + } + else + { + succeeded = false; + } + break; + case "knowledge_input": + case "ki": + if (!LimitedMode) + { + API.CreateForm(new KnowledgeInput(), API.LoadedNames.KnowledgeInputName, GetIcon("KI")); + } + else + { + succeeded = false; + } + break; + case "holochat": + if (API.Upgrades["holochat"] == true) + { + API.CreateForm(new HoloChat(), "HoloChat", GetIcon("HoloChat")); + } + else + { + succeeded = false; + } + break; + case "namechanger": + case "name_changer": + if (!LimitedMode) + { + if (API.Upgrades["namechanger"] == true) + { + CreateForm(new NameChanger(), LoadedNames.NameChangerName, GetIcon("NameChanger")); + } + else + { + succeeded = false; + } + } + else + { + succeeded = false; + } + break; + case "artpad": + if (!LimitedMode) + { + if (API.Upgrades["artpad"] == true) + { + CreateForm(new Artpad(), LoadedNames.ArtpadName, GetIcon("Artpad")); + } + else + { + succeeded = false; + } + } + else + { + succeeded = false; + } + break; + case "textpad": + if (Upgrades["textpad"] == true) + { + CreateForm(new TextPad(), "TextPad", GetIcon("TextPad")); + } + else + { + succeeded = false; + } + break; + case "skinloader": + case "skin_loader": + if (!LimitedMode) + { + if (Upgrades["skinning"] == true) + { + CreateForm(new SkinLoader(), "Skin Loader", GetIcon("SkinLoader")); + } + else + { + succeeded = false; + } + } + else + { + succeeded = false; + } + break; + case "shifter": + if (!LimitedMode) + { + if (Upgrades["shifter"] == true) + { + CreateForm(new Shifter(), "Shifter", GetIcon("Shifter")); + } + else + { + succeeded = false; + } + } + else + { + succeeded = false; + } + break; + case "pong": + if (!LimitedMode) + { + if (Upgrades["pong"] == true) + { + CreateForm(new Pong(), "Pong", GetIcon("Pong")); + } + else + { + succeeded = false; + } + } + else + { + succeeded = false; + } + break; + case "file_skimmer": + if (Upgrades["fileskimmer"] == true) + { + CreateForm(new File_Skimmer(), CurrentSave.FileSkimmerName, GetIcon("FileSkimmer")); + } + else + { + succeeded = false; + } + break; + case "shiftorium": + if (!LimitedMode) + { + CreateForm(new Shiftorium.Frontend(), LoadedNames.ShiftoriumName, GetIcon("Shiftorium")); + } + else + { + succeeded = false; + } + break; + default: + succeeded = false; + break; + + } + } + catch (Exception launcherror) + { + API.Crash(launcherror); + } return succeeded; - } + public static void Crash(Exception ex) + { + API.CreateInfoboxSession("Application Crashed", $"This Application Has Been Closed To Protect ShiftOS \n {ex.Message}", infobox.InfoboxMode.Info); + } + /// <summary> /// Creates a new color picker session. /// </summary> @@ -2036,6 +2009,7 @@ namespace ShiftOS public static Color[] yellowmemory = new Color[16]; public static Color[] pinkmemory = new Color[16]; internal static Dictionary<string, Dictionary<string, object>> LuaShifterRegistry = null; + public static bool ShouldLoadEngine = true; #endregion } |
