using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Compression;
using System.Drawing;
using Newtonsoft.Json;
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
{
///
/// Initializes a new instance of a Panel Button model.
///
/// The text displayed on the button.
/// The icon displayed on the button.
/// The form that is managed by the button.
public PanelButton(string name, Image icon, ref Form formToManage)
{
Name = name;
Icon = icon;
FormToManage = formToManage;
}
public string Name { get; set; }
public Image Icon { get; set; }
public Form FormToManage { get; set; }
}
public class ApplauncherItem
{
public ApplauncherItem(string name, Image icn, string lua, bool disp)
{
Name = name;
Icon = icn;
Lua = lua;
Display = disp;
}
public string Name { get; set; }
public Image Icon { get; set; }
public string Lua { get; set; } //ShiftCode that decides what ShiftOS will do when the item is clicked.
public bool Display { get; set; }
}
public class ModApplauncherItem
{
public string Name { get; set; }
public string Icon { get; set; }
///
/// Legacy mod AL entries for compatibilty
///
public string ShiftCode { get; set; } //ShiftCode that decides what ShiftOS will do when the item is clicked.
public string Lua { get; set; }
public Form FormToOpen { get; set; } //If ShiftCode == "openForm", ShiftOS will open this form.
public bool Display { get; set; }
public string AppDirectory { get; set; }
}
public class API
{
///
/// Settings file.
///
public static Settings LoadedSettings = null;
///
/// 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.
///
public static bool DeveloperMode = true;
///
/// 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.
///
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 RunningModProcesses = new List();
public static Dictionary CommandAliases = new Dictionary();
public static Terminal LoggerTerminal = null;
///
/// Logs an exception to the log.
///
/// The text to log.
/// Is it a fatal crash?
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 Entries = new List();
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());
}
}
///
/// Logs text to the log file.
///
/// The text to log.
public static void Log(string Message)
{
if (!File.Exists(Paths.SystemDir + "_Log.txt"))
{
File.WriteAllText(Paths.SystemDir + "_Log.txt", GetLogTime() + " " + Message);
}
else
{
List Entries = new List();
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());
}
}
///
/// Gets a proper-formatted date/time string for the log.
///
///
public static string GetLogTime()
{
return "[" + DateTime.Now.ToLongDateString() + "\\" + DateTime.Now.ToLongTimeString() + "]";
}
///
/// Property representing the currently loaded name pack.
///
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;
}
}
}
///
/// Adds a command line alias.
///
/// Alias name
/// Command to run.
///
public static bool AddAlias(string key, string value)
{
if(!AliasExists(key))
{
CommandAliases.Add(key, value);
return true;
}
else
{
return false;
}
}
///
/// Saves alias list to save game.
///
public static void SaveAliases()
{
string json = JsonConvert.SerializeObject(CommandAliases);
File.WriteAllText(Paths.SystemDir + "_aliases.json", json);
}
///
/// Loads alias list from the save game.
///
public static void LoadAliases()
{
if (File.Exists(Paths.SystemDir + "_aliases.json")) {
string json = File.ReadAllText(Paths.SystemDir + "_aliases.json");
CommandAliases = JsonConvert.DeserializeObject>(json);
}
else
{
CommandAliases = new Dictionary();
}
}
///
/// Removes an alias from the list.
///
/// Alias to remove.
/// Whether the alias could be removed.
public static bool RemoveAlias(string key)
{
if(AliasExists(key))
{
CommandAliases.Remove(key);
return true;
}
else
{
return false;
}
}
///
/// Checks if the provided alias exists.
///
/// The alias to check.
/// Whether the alias exists.
public static bool AliasExists(string key)
{
bool no = false;
foreach(KeyValuePair kv in CommandAliases)
{
if(kv.Key == key)
{
no = true;
}
}
return no;
}
///
/// I have no idea what this does - Michael
///
///
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==";
///
/// Launches an saa file, hooks it up to the Lua API, and runs it.
///
/// File to run.
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);
}
}
///
/// Source: http://stackoverflow.com/questions/10168240/encrypting-decrypting-a-string-in-c-sharp
///
/// String cryptography wrapper for ShiftOS.
///
public static class Encryption
{
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.
private static readonly byte[] initVectorBytes = Encoding.ASCII.GetBytes("tu89geji340t89u2");
// This constant is used to determine the keysize of the encryption algorithm.
private const int keysize = 256;
///
/// Encrypt a string.
///
/// Raw string to encrypt.
/// The encrypted string.
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);
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);
}
}
}
}
}
}
///
/// Decrypts an encrypted string.
///
/// The encrypted string.
/// The decrypted string.
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))
{
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);
}
}
}
}
}
}
}
///
/// Property representing the current client Bitnote address.
///
public static SaveSystem.PrivateBitnoteAddress BitnoteAddress
{
get
{
return SaveSystem.Utilities.BitnoteAddress;
}
}
public static class BitnoteEncryption
{
private static readonly string passPhrase = "jonathan_ladouceur_sucks_and_bitnotes_rock";
// 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.
private static readonly byte[] initVectorBytes = Encoding.ASCII.GetBytes("tu89geji340t89u2");
// This constant is used to determine the keysize of the encryption algorithm.
private const int keysize = 256;
///
/// Encrypts text using the bitnote passphrase.
///
/// The raw string.
/// The encrypted string.
public static string Encrypt(string plainText)
{
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, 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);
}
}
}
}
}
}
///
/// Decrypts an encrypted string using the Bitnote passphrase.
///
/// The encrypted text.
/// The decrypted text.
public static string Decrypt(string cipherText)
{
byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
using (PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, 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);
}
}
}
}
}
}
}
///
/// Creates a new File Skimmer session.
///
/// What file types can be shown when the mode is set to Open, or what file types can be saved to when mode is set to Save.
/// The display mode of the File Skimmer.
public static void CreateFileSkimmerSession(string Filters, File_Skimmer.FileSkimmerMode mode)
{
FileSkimmerSession = new File_Skimmer(mode, Filters);
CreateForm(FileSkimmerSession, "File Skimmer", Properties.Resources.iconFileSkimmer);
}
///
/// Call this during a closing event on a File Skimmer session to get the user's input.
///
/// The user's input.
public static string GetFSResult()
{
string result = "";
if (FileSkimmerSession != null)
{
if (FileSkimmerSession.FileName != "")
{
result = FileSkimmerSession.FileName;
}
else
{
result = "fail";
}
}
else
{
result = "fail";
throw new InvalidSessionException("The File Skimmer session was not started. Try running API.CreateFileSkimmerSession().");
}
return result;
}
public static File_Skimmer FileSkimmerSession = null;
public static List PanelButtons = new List();
public static string LastRanCommand = "";
public static List AppLauncherItems = new List();
///
/// A dictionary of every single icon entry in the Icon Manager.
///
public static Dictionary IconRegistry
{
get
{
return Skinning.Utilities.IconRegistry;
}
}
///
/// Gets an icon from the Icon Registry.
///
/// The ID of the icon.
/// The icon, if it exists, null if it doesn't.
public static Image GetIcon(string id)
{
if(IconRegistry != null)
{
if(IconRegistry.ContainsKey(id))
{
return IconRegistry[id];
}
else
{
return Properties.Resources.NoIconFound;
}
}
else
{
return Properties.Resources.NoIconFound;
}
}
///
/// Creates a list of App Launcher Items based on what you've bought in the Shiftorium.
///
public static void GetAppLauncherItems()
{
Skinning.Utilities.LoadEmbeddedNamePack();
//System Applications
AppLauncherItems.Clear();
if (!LimitedMode)
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.ArtpadName, GetIcon("Artpad"), "open_program('artpad')", Upgrades["alartpad"]));
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.FileSkimmerName, GetIcon("FileSkimmer"), "open_program('file_skimmer')", Upgrades["alfileskimmer"]));
if (!LimitedMode)
{
AppLauncherItems.Add(new ApplauncherItem("Network Browser", GetIcon("NetworkBrowser"), "open_program('netbrowse')", Upgrades["networkbrowser"]));
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.SkinLoaderName, GetIcon("SkinLoader"), "open_program('skinloader')", Upgrades["skinning"]));
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.ShiftoriumName, GetIcon("Shiftorium"), "open_program('shiftorium')", Upgrades["alshiftorium"]));
}
AppLauncherItems.Add(new ApplauncherItem("HoloChat", GetIcon("HoloChat"), "open_program('holochat')", API.Upgrades["holochat"]));
if (!LimitedMode)
{
AppLauncherItems.Add(new ApplauncherItem("Icon Manager", GetIcon("IconManager"), "open_program('iconmanager')", Upgrades["iconmanager"]));
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.ShifterName, GetIcon("Shifter"), "open_program('shifter')", Upgrades["alshifter"]));
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.NameChangerName, GetIcon("NameChanger"), "open_program('name_changer')", Upgrades["namechanger"]));
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.PongName, GetIcon("Pong"), "open_program('pong')", Upgrades["alpong"]));
}
if(LimitedMode)
{
AppLauncherItems.Add(new ApplauncherItem("Quest Viewer", GetIcon("QuestViewer"), "open_program('quests')", true));
}
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.TextpadName, GetIcon("TextPad"), "open_program('textpad')", Upgrades["altextpad"]));
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.TerminalName, GetIcon("Terminal"), "open_terminal()", true));
if (!LimitedMode)
{
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.KnowledgeInputName, GetIcon("KI"), "open_program('ki')", true));
//System Features
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.UnityName, GetIcon("Unity"), "toggle_unity()", Upgrades["alunity"]));
AppLauncherItems.Add(new ApplauncherItem(LoadedNames.ShutdownName, GetIcon("Shutdown"), "shutdown()", Upgrades["applaunchershutdown"]));
}
}
///
/// The current Skin.
///
public static Skinning.Skin CurrentSkin
{
get
{
return Skinning.Utilities.loadedSkin;
}
}
public static ShiftOSDesktop CurrentSession = null; //The current ShiftOS desktop session.
///
/// All the graphical elements of the current Skin.
///
public static Skinning.Images CurrentSkinImages
{
get
{
return Skinning.Utilities.loadedskin_images;
}
}
///
/// Plays a sound inside the Properties.Resources class.
///
/// The unmanaged memory stream to play.
public static void PlaySound(UnmanagedMemoryStream file)
{
Stream str = file;
SoundPlayer player = new SoundPlayer(str);
player.Play();
}
///
/// Plays a sound from a byte[] array. Useful for MP3s and other formats.
///
/// The byte[] aray
public static void PlaySound(byte[] file)
{
Stream mstr = new MemoryStream(file);
SoundPlayer player = new SoundPlayer(mstr);
player.Play();
}
///
/// Shiftorium upgrades.
///
public static Dictionary Upgrades
{
get
{
return SaveSystem.ShiftoriumRegistry.ShiftoriumUpgrades;
}
}
///
/// Creates a graphic picker session.
///
/// The title of the graphic.
/// Should the user be able to pick mouse-over/mouse-down images?
public static void CreateGraphicPickerSession(string GraphicName, bool ShowMouseImages)
{
GraphicPickerSession = new Graphic_Picker(GraphicName, ShowMouseImages);
CreateForm(GraphicPickerSession, GraphicName, Properties.Resources.icongraphicpicker);
}
public static Graphic_Picker GraphicPickerSession = null;
///
/// Call this in a closing event of a Graphic Picker session to get whether the user actually chose images.
///
/// "OK" if the user chose an image, "fail" if not and "fail" if the session wasn't created.
public static string GetGraphicPickerResult()
{
if(GraphicPickerSession != null)
{
string result = null;
if (GraphicPickerSession.Result == "OK")
{
result = "OK";
}
else
{
result = "fail";
}
return result;
}
else {
return "fail";
throw new InvalidSessionException();
}
}
///
/// The name of the OS defined by the user.
///
public static string OSName
{
get
{
return SaveSystem.Utilities.LoadedSave.osname;
}
set
{
SaveSystem.Utilities.LoadedSave.osname = value;
}
}
///
/// The username defined by the user.
///
public static string Username
{
get
{
return SaveSystem.Utilities.LoadedSave.username;
}
set
{
SaveSystem.Utilities.LoadedSave.username = value;
}
}
///
/// Current ammount of codepoints.
///
public static int Codepoints
{
get
{
return SaveSystem.Utilities.LoadedSave.codepoints;
}
}
///
/// Adds the specified amount of Codepoints.
///
/// Amount to add.
public static void AddCodepoints(int cp)
{
SaveSystem.Utilities.LoadedSave.codepoints += cp * CurrentSave.CodepointMultiplier;
}
///
/// Removes the specified amount of Codepoints if you have enough.
///
/// Amount to remove.
public static void RemoveCodepoints(int cp)
{
if (Codepoints >= cp)
{
SaveSystem.Utilities.LoadedSave.codepoints -= cp;
}
}
///
/// The proper way to shut down ShiftOS.
///
public static void ShutDownShiftOS()
{
File.WriteAllText(Paths.SystemDir + "settings.json", JsonConvert.SerializeObject(LoadedSettings));
Audio.running = false;
if (!LimitedMode)
{
//Disconnect from server.
try
{
foreach (var ip in Package_Grabber.clients)
{
if (ip.Value.IsConnected)
ip.Value.Disconnect();
}
}
catch
{
}
//Close all mods.
WindowComposition.ShuttingDown = true;
if (RunningModProcesses.Count > 0)
{
foreach (Process mod in RunningModProcesses)
{
try
{
mod.Kill();
}
catch (Exception ex)
{
LogException(ex.Message, false);
}
}
SaveSystem.Utilities.saveGame();
Application.Exit();
}
SaveSystem.Utilities.saveGame();
//Right before the game closes...
try
{
if (Directory.Exists(Paths.Mod_Temp))
Directory.Delete(Paths.Mod_Temp, true);
}
catch (Exception ex)
{
API.LogException(ex.Message, false);
}
finally
{
//Alright, ShiftOS! HAVE AT IT!
Application.Exit();
}
}
else
{
CreateInfoboxSession("Limited mode", "ShiftOS is in limited mode and cannot be shut down. Please complete the current mission before shutting down.", infobox.InfoboxMode.Info);
}
}
///
/// Special zip file extractor method.
///
/// File to extract.
/// Target directory.
/// Delete the target first?
public static void ExtractFile(string zipFile, string dir, bool deleteDir)
{
if (Directory.Exists(dir) && deleteDir == true)
{
Directory.Delete(dir, true);
Directory.CreateDirectory(dir);
}
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
ZipFile.ExtractToDirectory(zipFile, dir);
}
///
/// Close all open applications (besides Desktop, and HijackScreen.)
///
public static void CloseEverything()
{
PanelButtons.Clear();
OpenPrograms.Clear();
List