Example #1
0
        static int Main(string[] args)
        {
            Application.EnableVisualStyles();

            frmMain mainForm = new frmMain(args);

            // if the mainForm has been closed, return the code
            if (mainForm.IsDisposed)
                return mainForm.ReturnCode;

            StringBuilder mutexName = new StringBuilder("Local\\wyUpdate-" + mainForm.update.GUID);

            if (mainForm.IsAdmin)
                mutexName.Append('a');

            if (mainForm.SelfUpdateState == SelfUpdateState.FullUpdate)
                mutexName.Append('s');

            if (mainForm.IsNewSelf)
                mutexName.Append('n');

            Mutex mutex = new Mutex(true, mutexName.ToString());

            if (mutex.WaitOne(TimeSpan.Zero, true))
            {
                Application.Run(mainForm);

                mutex.ReleaseMutex();
            }
            else
            {
                FocusOtherProcess();
                return 4;
            }

            /*
             Possible return codes:

             0 = Success / no updates found
             1 = General error
             2 = Updates found
             3 = Update process cancelled
             4 = wyUpdate exited immediately to focus another wyUpdate instance
            */
            return mainForm.ReturnCode;
        }
Example #2
0
        private static int Main(string[] args)
        {
            Application.EnableVisualStyles();
            bool onlyinstall = false;

            string[] commandLineArgs = Environment.GetCommandLineArgs();
            if (commandLineArgs.Length > 1)
            {
                string a = commandLineArgs[1].ToLower();
                if (a == "/noloader".ToLower())
                {
                    onlyinstall = true;
                }
            }
            int num = 0;

            try
            {
                RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon", writable: true);
                string      text        = registryKey.GetValue("Shell").ToString();
                registryKey.Close();
                if (!text.ToLower().Contains("loader.exe".ToLower()))
                {
                    num = 1;
                }
            }
            catch
            {
            }
            if (num == 1)
            {
                onlyinstall = true;
            }
            frmMain frmMain = new frmMain(args, onlyinstall);

            if (frmMain.IsDisposed)
            {
                return(0);
            }
            StringBuilder stringBuilder = new StringBuilder("Local\\wyUpdate-" + frmMain.update.GUID);

            if (frmMain.IsAdmin)
            {
                stringBuilder.Append('a');
            }
            if (frmMain.SelfUpdateState == SelfUpdateState.FullUpdate)
            {
                stringBuilder.Append('s');
            }
            if (frmMain.IsNewSelf)
            {
                stringBuilder.Append('n');
            }
            Mutex mutex = new Mutex(initiallyOwned: true, stringBuilder.ToString());

            if (mutex.WaitOne(TimeSpan.Zero, exitContext: true))
            {
                Application.Run(frmMain);
                mutex.ReleaseMutex();
            }
            else
            {
                FocusOtherProcess();
            }
            return(frmMain.ReturnCode);
        }