Exemplo n.º 1
0
        public Update()
        {
            InitializeComponent();
            new Task(() => {
                try {
                    GitHub Updater = new GitHub("Marcussacana", "Social-Savior");

                    if (Updater.FinishUpdatePending())
                    {
                        SingleInstanceService.RequestQuit();
                    }

                    string Result = Updater.FinishUpdate();
                    if (Result != null)
                    {
                        Process.Start(Result);
                        Environment.Exit(0);
                    }

                    if (Updater.HaveUpdate())
                    {
                        Invoke(new MethodInvoker(() => { lblStatus.Text = "Updating..."; }));
                        Updater.Update();
                    }

                    Invoke(new MethodInvoker(Close));
                } catch (Exception ex) {
                    MessageBox.Show("Auto Updater Exception: \n" + ex.Message + "\n\n" + ex.StackTrace);

                    Invoke(new MethodInvoker(Close));
                }
            }).Start();
        }
Exemplo n.º 2
0
        static void Main(string[] Args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (Args?.Length > 0)
            {
                string CMD = Args[0].Trim(' ', '/', '-', '\\', ';').ToLower();
                if (CMD.Contains("startup"))
                {
                    Startup = true;
                }

                if (CMD.Contains("restart"))
                {
                    Restart = true;
                }

                if (CMD.Contains("panic") && SingleInstanceService.PipeIsOpen())
                {
                    SingleInstanceService.RequestPanic();
                    return;
                }

                if (CMD.Contains("restore") && SingleInstanceService.PipeIsOpen())
                {
                    SingleInstanceService.RequestRestore();
                    return;
                }

                if (CMD.Contains("noupdate") || CMD.Contains("noup"))
                {
                    Updates = false;
                }
            }

            if (!IsElevated && !Debugger.IsAttached && !Restart)
            {
                Process.Start(new ProcessStartInfo()
                {
                    Arguments = Startup ? "startup;restart" : "restart",
                    FileName  = Application.ExecutablePath,
                    Verb      = "runas"
                });
                Process.GetCurrentProcess().Kill();
            }

            if (Restart)
            {
                Thread.Sleep(1000);
            }

            if (Startup && !File.Exists(Social_Savior.Main.SettingsPath))
            {
                return;
            }


            if (!Startup)
            {
                if (Updates)
                {
                    Application.Run(new Update());
                }
                if (!Debugger.IsAttached)
                {
                    Application.Run(new Welcome());
                }
            }

            if (Execute || Startup || Debugger.IsAttached)
            {
                Application.Run(new Main());
            }

            Environment.Exit(0);
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        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();
        }