aboutsummaryrefslogtreecommitdiff
path: root/source/WindowsFormsApplication1/API.cs
diff options
context:
space:
mode:
Diffstat (limited to 'source/WindowsFormsApplication1/API.cs')
-rw-r--r--source/WindowsFormsApplication1/API.cs155
1 files changed, 141 insertions, 14 deletions
diff --git a/source/WindowsFormsApplication1/API.cs b/source/WindowsFormsApplication1/API.cs
index b99f98f..4199223 100644
--- a/source/WindowsFormsApplication1/API.cs
+++ b/source/WindowsFormsApplication1/API.cs
@@ -13,9 +13,20 @@ using System.Security.Cryptography;
using System.Diagnostics;
using System.Net;
using System.ComponentModel;
+using System.Net.NetworkInformation;
namespace ShiftOS
{
+ public static class Consts
+ {
+ public const string Version = "0.1.2";
+ }
+
+ public class Settings
+ {
+ public int MusicVolume { get; set; }
+ }
+
public class PanelButton
{
/// <summary>
@@ -71,6 +82,15 @@ 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
@@ -83,7 +103,7 @@ namespace ShiftOS
/// 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 = false;
+ public static bool DeveloperMode = true;
/// <summary>
/// If this is true, only certain applications will open and only
@@ -99,6 +119,22 @@ namespace ShiftOS
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;
@@ -335,10 +371,6 @@ namespace ShiftOS
{
CreateForm(new Labyrinth(), "Labyrinth", null);
}
- else if (File.ReadAllText(modSAA) == HiddenQuickChatCommand)
- {
- CreateForm(new QuickChat(), "QuickChat", null);
- }
else
{
try
@@ -389,6 +421,23 @@ namespace ShiftOS
{
private static readonly string passPhrase = "h8gf9dh790df87h9";
+ private static string GetMacAddress()
+ {
+ string macAddresses = string.Empty;
+
+ foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
+ {
+ if (nic.OperationalStatus == OperationalStatus.Up)
+ {
+ macAddresses += nic.GetPhysicalAddress().ToString();
+ break;
+ }
+ }
+
+ return macAddresses;
+ }
+
+
// This constant string is used as a "salt" value for the PasswordDeriveBytes function calls.
// This size of the IV (in bytes) must = (keysize / 8). Default keysize is 256, so the IV must be
// 32 bytes long. Using a 16 character string here gives us 32 bytes when converted to a byte array.
@@ -405,6 +454,32 @@ namespace ShiftOS
public static string Encrypt(string plainText)
{
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
+ using (PasswordDeriveBytes password = new PasswordDeriveBytes(GetMacAddress(), null))
+ {
+ byte[] keyBytes = password.GetBytes(keysize / 8);
+ using (RijndaelManaged symmetricKey = new RijndaelManaged())
+ {
+ symmetricKey.Mode = CipherMode.CBC;
+ using (ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes))
+ {
+ using (MemoryStream memoryStream = new MemoryStream())
+ {
+ using (CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
+ {
+ cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
+ cryptoStream.FlushFinalBlock();
+ byte[] cipherTextBytes = memoryStream.ToArray();
+ return Convert.ToBase64String(cipherTextBytes);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public static string Encrypt_old(string plainText)
+ {
+ byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
{
byte[] keyBytes = password.GetBytes(keysize / 8);
@@ -428,6 +503,7 @@ namespace ShiftOS
}
}
+
/// <summary>
/// Decrypts an encrypted string.
/// </summary>
@@ -435,6 +511,38 @@ namespace ShiftOS
/// <returns>The decrypted string.</returns>
public static string Decrypt(string cipherText)
{
+ try
+ {
+ byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
+ using (PasswordDeriveBytes password = new PasswordDeriveBytes(GetMacAddress(), null))
+ {
+ byte[] keyBytes = password.GetBytes(keysize / 8);
+ using (RijndaelManaged symmetricKey = new RijndaelManaged())
+ {
+ symmetricKey.Mode = CipherMode.CBC;
+ using (ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes))
+ {
+ using (MemoryStream memoryStream = new MemoryStream(cipherTextBytes))
+ {
+ using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
+ {
+ byte[] plainTextBytes = new byte[cipherTextBytes.Length];
+ int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
+ return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
+ }
+ }
+ }
+ }
+ }
+ }
+ catch
+ {
+ return Decrypt_old(cipherText);
+ }
+ }
+
+ public static string Decrypt_old(string cipherText)
+ {
byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null))
{
@@ -830,16 +938,17 @@ namespace ShiftOS
/// </summary>
public static void ShutDownShiftOS()
{
+ File.WriteAllText(Paths.SystemDir + "settings.json", JsonConvert.SerializeObject(LoadedSettings));
+ Audio.running = false;
if (!LimitedMode)
{
- //dispose audio clients
- Audio.DisposeAll();
//Disconnect from server.
try
{
- foreach (string ip in Package_Grabber.clients.Keys)
+ foreach (var ip in Package_Grabber.clients)
{
- Package_Grabber.Disconnect(ip);
+ if (ip.Value.IsConnected)
+ ip.Value.Disconnect();
}
}
catch
@@ -1012,12 +1121,14 @@ namespace ShiftOS
{
formToCreate.Controls.Remove(ctrl);
ctrl.Show();
+ SkinControl(ctrl);
}
- catch (Exception ex)
+ catch
{
API.CurrentSession.Invoke(new Action(() =>
{
ctrl.Show();
+ SkinControl(ctrl);
}));
}
}
@@ -1032,7 +1143,7 @@ namespace ShiftOS
{
if (e.KeyCode == Keys.T && e.Control && formToCreate.Name != "Terminal")
{
- CreateForm(new Terminal(), CurrentSave.TerminalName, Properties.Resources.iconTerminal);
+ CurrentSession.InvokeCTRLT();
}
if (formToCreate.Name != "Terminal" || Upgrades["windowedterminal"] == true)
{
@@ -1080,6 +1191,8 @@ namespace ShiftOS
}
}));
WindowComposition.SafeToAddControls = true;
+ API.OpenGUIDs.Add(formToCreate, Guid.NewGuid().ToString());
+ API.CurrentSession.Invoke(new Action(() => { CurrentSession.InvokeWindowOp("open", formToCreate); }));
};
bw.RunWorkerAsync();
}
@@ -1197,7 +1310,8 @@ namespace ShiftOS
/// <returns>I don't know.</returns>
public static bool CloseProgram(string command)
{
- try {
+ try
+ {
List<PanelButton> PanelButtonsToKill = new List<PanelButton>();
bool closed = false;
foreach (Form app in OpenPrograms)
@@ -1236,7 +1350,8 @@ namespace ShiftOS
PanelButtons.Remove(pbtn);
}
return closed;
- } catch(Exception ex)
+ }
+ catch
{
return false;
}
@@ -1608,7 +1723,7 @@ namespace ShiftOS
return "success";
}
}
- catch (Exception ex)
+ catch
{
API.LogException("User didn't guess a valid knowledge input guess.", false);
return "not_valid";
@@ -1672,6 +1787,17 @@ namespace ShiftOS
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"])
{
@@ -1909,6 +2035,7 @@ namespace ShiftOS
public static Color[] graymemory = new Color[16];
public static Color[] yellowmemory = new Color[16];
public static Color[] pinkmemory = new Color[16];
+ internal static Dictionary<string, Dictionary<string, object>> LuaShifterRegistry = null;
#endregion
}