public Main() { if (File.Exists(SettingsPath)) { try { using (Stream ReaderStream = new StreamReader(SettingsPath).BaseStream) using (StructReader Reader = new StructReader(ReaderStream)) { if (Reader.ReadUInt32() != SignatureValue) { Reader.Close(); BadSettings(); } ushort Ver = Reader.ReadUInt16(); if (Ver < SettingsVersion) { try { Reader.BaseStream.Position = 0; Reader.ReadStruct(ref Settings); } catch { } Settings.Version = SettingsVersion; } else if (Ver != SettingsVersion) { Reader.Close(); BadSettings(); } else { Reader.BaseStream.Position = 0; Reader.ReadStruct(ref Settings); Reader.Close(); } } } catch { BadSettings(); } } if (Settings.AllowedUser == string.Empty || Settings.AllowedUser == null) { var Reply = MessageBox.Show("Allow the Social-Savior works only with the current user of this computer?", "Social Savior", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (Reply == DialogResult.Yes) { Settings.AllowedUser = Environment.UserName; } else { Settings.AllowedUser = "******"; } } else if (Settings.AllowedUser != Environment.UserName && Settings.AllowedUser != "ALLOWEVERYONE") { Environment.Exit(0); } InitializeComponent(); if (SingleInstanceService.PipeIsOpen() && !Debugger.IsAttached) { SingleInstanceService.RequestOpen(); Environment.Exit(0); } SingleInstanceService.StartPipe(); if (File.Exists(SettingsPath)) { SetReflexByCode(Settings.ReflexAction); PanicAltCK.Checked = Settings.Panic.Alt; PanicCtrlCK.Checked = Settings.Panic.Ctrl; PanicShiftCK.Checked = Settings.Panic.Shift; PanicTB.Text = KeyName((Keys)Settings.Panic.KeyCode); RestoreAltCK.Checked = Settings.Restore.Alt; RestoreCtrlCK.Checked = Settings.Restore.Ctrl; RestoreShiftCK.Checked = Settings.Restore.Shift; RestoreTB.Text = KeyName((Keys)Settings.Restore.KeyCode); ckIDLEAlt.Checked = Settings.AllowIdle.Alt; ckIDLECtrl.Checked = Settings.AllowIdle.Ctrl; ckIDLEShift.Checked = Settings.AllowIdle.Shift; tbIDLE.Text = KeyName((Keys)Settings.AllowIdle.KeyCode); MuteComputerCK.Checked = Settings.MuteAll; MuteBlackListCK.Checked = Settings.MuteBlacklist; InvokeScreenSaverCK.Checked = Settings.InvokeScreenSaver; FocusAProgramCK.Checked = Settings.FocusProcess; KillProcIfFailCK.Checked = Settings.KillProcessIfFails; MaxIDLE.Value = Settings.MaxIDLE; } else { FirstLaunch = true; } if (Settings.Blacklist == null) { Settings.Blacklist = new string[0]; } try { if ((Keys)Settings.Panic.KeyCode != Keys.None) { PanicHotkey.RegisterHotKey(GetPanicModifiers(), (Keys)Settings.Panic.KeyCode); PanicHotkey.KeyPressed += PanicHotkeyPressed; } } catch { MessageBox.Show("Failed to Register hotkey, Please Try a new Panic Hotkey.", "Social Savior", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { if ((Keys)Settings.Restore.KeyCode != Keys.None) { RestoreHotkey.RegisterHotKey(GetRestoreModifiers(), (Keys)Settings.Restore.KeyCode); RestoreHotkey.KeyPressed += RestoreHotkeyPressed; } } catch { MessageBox.Show("Failed to Register hotkey, Please Try a new Restore Hotkey.", "Social Savior", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { if ((Keys)Settings.AllowIdle.KeyCode != Keys.None) { IDLEHotkey.RegisterHotKey(GetIDLEModifiers(), (Keys)Settings.AllowIdle.KeyCode); IDLEHotkey.KeyPressed += IDLEHotkeyPressed; } } catch { MessageBox.Show("Failed to Register hotkey, Please Try a new Restore Hotkey.", "Social Savior", MessageBoxButtons.OK, MessageBoxIcon.Error); } MicroLevel.ColorList = new List <Color> { Color.Lime, Color.Yellow, Color.Red }; MainContainer.Text = "Social Savior - v" + GitHub.CurrentVersion; if (FirstLaunch) { HomeMainGB.Text = "Social Savior has not been configured"; } InitializeMicrophone(); ProcessScanTick(null, null); WineDeprecated(); StartWithWindowsCK.Checked = StartupStatus(); if (Program.Startup) { Shown += (a, b) => Close(); } else { Focus(); } Initialized = true; }
public Main() { if (File.Exists(SettingsPath)) { try { using (Stream ReaderStream = new StreamReader(SettingsPath).BaseStream) using (StructReader Reader = new StructReader(ReaderStream)) { string Sig = Reader.ReadString(StringStyle.CString); if (Sig != Signature) { Reader.Close(); BadSettings(); } ushort Ver = Reader.ReadUInt16(); if (Ver != SettingsVersion) { Reader.Close(); BadSettings(); } Reader.BaseStream.Position = 0; Reader.ReadStruct(ref Settings); Reader.Close(); } } catch { BadSettings(); } } InitializeComponent(); if (SingleInstanceService.PipeIsOpen()) { SingleInstanceService.RequestOpen(); Environment.Exit(0); } SingleInstanceService.StartPipe(); if (File.Exists(SettingsPath)) { SetReflexByCode(Settings.ReflexAction); PanicAltCK.Checked = Settings.Panic.Alt; PanicCtrlCK.Checked = Settings.Panic.Ctrl; PanicShiftCK.Checked = Settings.Panic.Shift; PanicTB.Text = KeyName((Keys)Settings.Panic.KeyCode); RestoreAltCK.Checked = Settings.Restore.Alt; RestoreCtrlCK.Checked = Settings.Restore.Ctrl; RestoreShiftCK.Checked = Settings.Restore.Shift; RestoreTB.Text = KeyName((Keys)Settings.Restore.KeyCode); MuteComputerCK.Checked = Settings.MuteAll; MuteBlackListCK.Checked = Settings.MuteBlacklist; InvokeScreenSaverCK.Checked = Settings.InvokeScreenSaver; FocusAProgramCK.Checked = Settings.FocusProcess; KillProcIfFailCK.Checked = Settings.KillProcessIfFails; } else { FirstLaunch = true; } if (Settings.Blacklist == null) { Settings.Blacklist = new string[0]; } try { if ((Keys)Settings.Panic.KeyCode != Keys.None) { PanicHotkey.RegisterHotKey(GetPanicModifiers(), (Keys)Settings.Panic.KeyCode); PanicHotkey.KeyPressed += PanicHotkeyPressed; } } catch { MessageBox.Show("Failed to Register hotkey, Please Try a new Panic Hotkey.", "Social Savior", MessageBoxButtons.OK, MessageBoxIcon.Error); } try { if ((Keys)Settings.Restore.KeyCode != Keys.None) { RestoreHotkey.RegisterHotKey(GetRestoreModifiers(), (Keys)Settings.Restore.KeyCode); RestoreHotkey.KeyPressed += RestoreHotkeyPressed; } } catch { MessageBox.Show("Failed to Register hotkey, Please Try a new Restore Hotkey.", "Social Savior", MessageBoxButtons.OK, MessageBoxIcon.Error); } MicroLevel.ColorList = new List <Color> { Color.Lime, Color.Yellow, Color.Red }; MainContainer.Text = "Social Savior - v" + AppVeyor.CurrentVersion; if (FirstLaunch) { HomeMainGB.Text = "Social Savior has not been configured"; } InitializeMicrophone(); ProcessScanTick(null, null); Focus(); }