11using System ;
22using System . IO ;
3- using System . Windows . Forms ;
43using System . Threading ;
54using System . Runtime . InteropServices ;
65
76namespace HourBoostr
87{
98 class Program
109 {
11- #region Imports
12-
13- /// <summary>
14- /// DllImport for setting foreground of a window
15- /// </summary>
16- /// <param name="hWnd">Hwnd of window to manage</param>
17- /// <returns>Returns bool</returns>
18- [ DllImport ( "user32.dll" ) ]
19- public static extern bool SetForegroundWindow ( IntPtr hWnd ) ;
20-
21-
22- /// <summary>
23- /// DllImport for getting current console window intptr
24- /// </summary>
25- /// <returns>Returns IntPtr</returns>
26- [ DllImport ( "kernel32.dll" ) ]
27- static extern IntPtr GetConsoleWindow ( ) ;
28-
29-
30- /// <summary>
31- /// DllImport for showing/hiding window
32- /// </summary>
33- /// <param name="hWnd">Hwnd of window to manage</param>
34- /// <param name="nCmdShow">Show parameter</param>
35- /// <returns>Returns bool</returns>
36- [ DllImport ( "user32.dll" ) ]
37- static extern bool ShowWindow ( IntPtr hWnd , int nCmdShow ) ;
38-
39-
40- /// <summary>
41- /// DllImport to catch the exit event
42- /// </summary>
43- /// <returns>Returns bool</returns>
44- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
45- private static extern bool SetConsoleCtrlHandler ( ConsoleEventDelegate callback , bool add ) ;
46- private delegate bool ConsoleEventDelegate ( int eventType ) ;
47-
48- #endregion Imports
49-
50-
51- /// <summary>
52- /// Application tray icon
53- /// Used for hiding/showing the application in a click
54- /// </summary>
55- static private NotifyIcon mTrayIcon = new NotifyIcon ( ) ;
56-
57-
58- /// <summary>
59- /// Console event handler
60- /// </summary>
61- static private ConsoleEventDelegate mEventHandler ;
62-
63-
64- /// <summary>
65- /// Application settings
66- /// </summary>
67- static private Config . Settings mSettings ;
68-
69-
70- /// <summary>
71- /// Thread variables
72- /// </summary>
73- static private Thread mThreadTray ;
74-
75-
7610 /// <summary>
7711 /// Global database
7812 /// </summary>
@@ -85,100 +19,6 @@ class Program
8519 static private Session mSession ;
8620
8721
88- /// <summary>
89- /// Represents if the console is hidden
90- /// </summary>
91- static private bool mIsHidden ;
92-
93-
94- /// <summary>
95- /// HACK HACK!
96- /// Initialize the tray icon thread
97- /// Keep it running
98- /// </summary>
99- static private void ToTray ( )
100- {
101- /*Set TrayIcon information*/
102- mTrayIcon . Text = "HourBoostr\n Click to Show/Hide" ;
103- mTrayIcon . Icon = Properties . Resources . icon ;
104- mTrayIcon . Click += new EventHandler ( TrayIcon_Click ) ;
105- mTrayIcon . Visible = true ;
106- Application . Run ( ) ;
107-
108- /*To keep TrayIcon from dissapearing,
109- we need to keep the thread running*/
110- while ( true ) { Thread . Sleep ( 250 ) ; }
111- }
112-
113-
114- /// <summary>
115- /// TrayIcon click event
116- /// Show/Hide the window depending on its state
117- /// </summary>
118- static private void TrayIcon_Click ( object sender , EventArgs e )
119- {
120- ShowConsole ( mIsHidden ) ;
121- }
122-
123-
124- /// <summary>
125- /// Show/Hide the console window
126- /// </summary>
127- /// <param name="show">True to show, false to hide</param>
128- static private void ShowConsole ( bool show )
129- {
130- if ( show )
131- {
132- ShowWindow ( GetConsoleWindow ( ) , 5 ) ;
133- SetForegroundWindow ( GetConsoleWindow ( ) ) ;
134- }
135- else
136- {
137- ShowWindow ( GetConsoleWindow ( ) , 0 ) ;
138- }
139-
140- mIsHidden = ! show ;
141- }
142-
143-
144- /// <summary>
145- /// Catch exit event
146- /// Realistically we have 4-5 seconds to preform this
147- /// action before windows forces the program to close
148- /// </summary>
149- /// <param name="eventType">Event type</param>
150- /// <returns>Returns bool</returns>
151- static bool ConsoleEventCallback ( int eventType )
152- {
153- /*eventType 2 being Exit event*/
154- if ( eventType == 2 )
155- {
156- if ( mSession != null )
157- {
158- /*Disconnect all clients*/
159- Console . WriteLine ( "\n \n Disconnecting..." ) ;
160- foreach ( var Bot in mSession . mActiveBotList )
161- {
162- Bot . mIsRunning = false ;
163- Bot . mSteam . client . Disconnect ( ) ;
164- }
165-
166- /*Update settings*/
167- if ( Settings . UpdateSettings ( mSettings , mSession . mSettings ) )
168- Console . WriteLine ( "Updated user settings" ) ;
169- }
170-
171- mTrayIcon . Visible = false ;
172- mTrayIcon . Dispose ( ) ;
173-
174- Console . WriteLine ( "Exiting..." ) ;
175- Thread . Sleep ( 500 ) ;
176- }
177-
178- return false ;
179- }
180-
181-
18222 /// <summary>
18323 /// Main function
18424 /// Too many comments
@@ -192,20 +32,6 @@ static void Main(string[] args)
19232 Directory . CreateDirectory ( EndPoint . SENTRY_FOLDER_PATH ) ;
19333 Directory . CreateDirectory ( EndPoint . LOG_FOLDER_PATH ) ;
19434
195- /*Set exit events so we'll log out all accounts if application is exited*/
196- mEventHandler = new ConsoleEventDelegate ( ConsoleEventCallback ) ;
197- SetConsoleCtrlHandler ( mEventHandler , true ) ;
198-
199- /*Start the trayicon thread*/
200- mThreadTray = new Thread ( ToTray ) ;
201- mThreadTray . Start ( ) ;
202-
203- /*We'll read and store the settings twice since we'll compare the two objects later on
204- to see if something has changed by the user during runtime*/
205- mSettings = Settings . GetSettings ( ) ;
206- if ( mSettings == null )
207- return ;
208-
20935 /*Load global database*/
21036 mGlobalDB = GlobalDB . Load ( EndPoint . GLOBAL_SETTINGS_FILE_PATH ) ;
21137 if ( mGlobalDB == null )
@@ -226,20 +52,12 @@ static void Main(string[] args)
22652 mSession = new Session ( settings ) ;
22753 while ( mSession . mBwg . IsBusy )
22854 Thread . Sleep ( 250 ) ;
229-
230- if ( settings . HideToTrayAutomatically )
231- {
232- mTrayIcon . ShowBalloonTip ( 1000 , "HourBoostr" , "I'm down here!" , ToolTipIcon . Info ) ;
233- ShowConsole ( false ) ;
234- }
23555 }
23656 else
23757 {
238- Console . WriteLine ( "No accounts were loaded from settings." ) ;
58+ Console . WriteLine ( "No accounts were loaded from settings. Press any key to exit." ) ;
59+ Console . ReadKey ( ) ;
23960 }
240-
241- while ( true )
242- Thread . Sleep ( 250 ) ;
24361 }
24462 }
24563 }
0 commit comments