Example #1
0
        static void Main()
        {
            bool firstProcess;
            Mutex singleMutex = new Mutex
            (
                true,
                "SteamChatLogger_4d8g8hisih39", // this is hopefully a unique mutex string not present on the current system
                out firstProcess
            );

            if ( !firstProcess )
            {
                // process already exists, so we exit
                Util.ShowWarning( null, "Steam chat logger is already running. You may control it through context menus in the task bar icon." );
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault( false );

            // load our settings
            try
            {
                sets = Settings.Load( Settings.BackingFile );
            }
            catch ( FileNotFoundException )
            {
                // if the file isn't found, no biggie
                sets = new Settings();
                sets.Save();
            }
            catch ( Exception ex )
            {
                Util.ShowError( null, "Unable to load settings: " + ex.Message + "\n\nResetting to defaults." );
                sets = new Settings();
                sets.Save();
            }

            setsForm = new SettingsForm( sets );

            // initialize the notification icon context
            notifyIcon = new Notification();
            notifyIcon.Exit += new EventHandler( notifyIcon_Exit );
            notifyIcon.ShowSettings += new EventHandler( notifyIcon_ShowSettings );


            // initialize logging
            logManager = new LogManager( sets );
            logManager.LogFailure += new EventHandler<LogFailureEventArgs>( logManager_LogFailure );


            // gasp a label.. what could it be for?
        //SteamInit: // maybe someday this will come back (not likely)

            bool waited = false;

            if ( !logManager.GetSteamClient() )
            {
                Util.ShowFatalError( null, "Unable get SteamClient interface.\nThis indicates a major change in the steam client, please contact [email protected]." );
                return;
            }

            if ( !logManager.GetPipe() )
            {
                notifyIcon.ShowError( "Steam is currently not running.. Waiting for it to startup." );
                waited = true;

                while ( !logManager.GetPipe() )
                {
                    Application.DoEvents();

                    Thread.Sleep( 2000 );
                }

                // get the pipe again just in case
                if ( !logManager.GetPipe() )
                {
                    Util.ShowFatalError( null, "Error getting steam pipe after steam startup!" );
                    return;
                }
            }

            while ( !logManager.GetUser() )
            {
                Application.DoEvents();

                Thread.Sleep( 2000 );
            }

            // wait for steam to full start itself
            if ( waited )
                Thread.Sleep( 10000 );

            // get the user again
            if ( !logManager.GetUser() )
            {
                Util.ShowFatalError( null, "Error getting steam user after steam startup!" );
                return;
            }


            if ( !logManager.GetInterface() )
            {
                Util.ShowFatalError( null, "Unable to get SteamFriends interface.\nThis indicates a major change in the steam client, please contact [email protected]." );
                return;
            }


            if ( waited )
                notifyIcon.ShowInfo( "Steam is now running, logging enabled." );
           

            while ( running )
            {
                // CreateSteamPipe causes deadlocks, not using this for now
                /*if ( !logManager.GetPipe() )
                {
                    Util.ShowError( null, "Steam pipe error!\nAttempting to regain pipe..." );
                    goto SteamInit; // gasp! a goto!?
                }*/

                Application.DoEvents();

                Thread.Sleep( 10 );
            }

            logManager.Close();

            GC.KeepAlive( singleMutex );
        }
Example #2
0
        static void Main()
        {
            bool firstProcess;
            Mutex singleMutex = new Mutex
            (
                true,
                "SteamChatLogger_4d8g8hisih39", // this is hopefully a unique mutex string not present on the current system
                out firstProcess
            );

            if ( !firstProcess )
            {
                // process already exists, so we exit
                Util.ShowWarning( null, "Steam chat logger is already running. You may control it through context menus in the task bar icon." );
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault( false );

            // load our settings
            try
            {
                sets = Settings.Load( Settings.BackingFile );
            }
            catch ( FileNotFoundException )
            {
                // if the file isn't found, no biggie
                sets = new Settings();
                sets.Save();
            }
            catch ( Exception ex )
            {
                Util.ShowError( null, "Unable to load settings: " + ex.Message + "\n\nResetting to defaults." );
                sets = new Settings();
                sets.Save();
            }

            setsForm = new SettingsForm( sets );

            // initialize the notification icon context
            notifyIcon = new Notification();
            notifyIcon.Exit += new EventHandler( notifyIcon_Exit );
            notifyIcon.ShowSettings += new EventHandler( notifyIcon_ShowSettings );

            // initialize logging
            logManager = new LogManager( sets );
            logManager.LogFailure += new EventHandler<LogFailureEventArgs>( logManager_LogFailure );

            if ( !logManager.Initialized )
            {
                notifyIcon.Visible = false;
                return;
            }

            while ( running )
            {
                Application.DoEvents();

                logManager.Update();

                Thread.Sleep( 10 );
            }
        }