11using System ;
22using System . Collections . Generic ;
3- using System . Drawing . Text ;
43using System . IO ;
54using System . Text . RegularExpressions ;
65using System . Threading . Tasks ;
@@ -38,7 +37,14 @@ static void Main(string[] args)
3837 Application . SetCompatibleTextRenderingDefault ( false ) ;
3938 Application . ApplicationExit += ( obj , e ) => cancellationToken . Cancel ( ) ;
4039 app = new Form1 ( ) ;
41- OnLog += ( msg , type ) => app . Log ( msg , type ) ;
40+ OnLog += ( msg , type ) =>
41+ {
42+ WriteToLogFileAsync ( msg , LogType . error ) ;
43+ if ( app != null )
44+ {
45+ app . Log ( msg , type ) ;
46+ }
47+ } ;
4248 LogFileStart ( ) ;
4349 if ( args . Length > 0 )
4450 {
@@ -48,7 +54,7 @@ static void Main(string[] args)
4854 }
4955 Startup ( ) ;
5056
51- Stack < EventHandler > eventHandlers = new Stack < EventHandler > ( ) ; //Ïðñîòî äëÿ óäîáíîãî íàçíà÷åíèÿ êíîïîê .
57+ Stack < EventHandler > eventHandlers = new Stack < EventHandler > ( ) ; //Buttons from the form .
5258 eventHandlers . Push ( new EventHandler ( ( obj , args ) => SendActiveStatus ( true ) ) ) ;
5359 eventHandlers . Push ( new EventHandler ( ( obj , args ) => SendActiveStatus ( false ) ) ) ;
5460 eventHandlers . Push ( new EventHandler ( ( obj , args ) => AppManifest ( WithManifestTask . add ) ) ) ;
@@ -72,7 +78,7 @@ private static async Task Startup()
7278 try
7379 {
7480 EVRInitError error = EVRInitError . None ;
75- OVRSystem = OpenVR . Init ( ref error , EVRApplicationType . VRApplication_Background ) ; //çàïóñêàåòñÿ è âûðóáàåòñÿ ñ SteamVR
81+ OVRSystem = OpenVR . Init ( ref error , EVRApplicationType . VRApplication_Background ) ; //starts and shuts down with SteamVR.
7682 if ( error == EVRInitError . Init_NoServerForBackgroundApp || error != EVRInitError . None )
7783 {
7884 Log ( "Init without SteamVR;" ) ;
@@ -203,11 +209,39 @@ public static void SendActiveStatus(bool status)
203209 }
204210 #endregion
205211
212+ #region Logs
213+
214+ private static void Log ( object msg )
215+ {
216+ OnLog . Invoke ( msg , LogType . log ) ;
217+ }
218+
219+ private static void LogError ( object msg )
220+ {
221+ OnLog . Invoke ( msg , LogType . error ) ;
222+ }
223+
224+ private static void LogFileStart ( )
225+ {
226+ File . WriteAllText ( logFileName , null ) ;
227+ }
228+
229+ private async static Task WriteToLogFileAsync ( object msg , LogType type = LogType . log )
230+ {
231+ string res = $ "[{ DateTime . Now } ]";
232+ res += "[" + ( ( type == LogType . log ) ? "Log" : "ERROR" ) + "] " ;
233+ res += msg . ToString ( ) ;
234+ await File . AppendAllTextAsync ( logFileName , res + "\n " ) ;
235+ }
236+
237+ #endregion
238+
239+ #region StartupArgs
206240 /// <summary>
207241 /// Processing arguments at the start of the application.
208242 /// </summary>
209243 /// <param name="args"></param>
210- private static async void UseArgumentsAsync ( string [ ] args )
244+ private static async void UseArgumentsAsync ( string [ ] args )
211245 {
212246 if ( args [ 0 ] == "--powerOn" || args [ 0 ] == "--powerOff" )
213247 {
@@ -232,33 +266,6 @@ private static async void UseArgumentsAsync(string[] args)
232266 Exit ( ) ;
233267 }
234268
235- private static void Log ( object msg )
236- {
237- WriteToLogFile ( msg , LogType . log ) ;
238- if ( app == null ) return ;
239- OnLog . Invoke ( msg , LogType . log ) ;
240- }
241-
242- private static void LogError ( object msg )
243- {
244- WriteToLogFile ( msg , LogType . error ) ;
245- if ( app == null ) return ;
246- OnLog . Invoke ( msg , LogType . error ) ;
247- }
248-
249- private static void LogFileStart ( )
250- {
251- File . WriteAllText ( logFileName , null ) ;
252- }
253-
254- private async static Task WriteToLogFile ( object msg , LogType type )
255- {
256- string res = $ "[{ DateTime . Now } ]";
257- res += "[" + ( ( type == LogType . log ) ? "Log" : "ERROR" ) + "] " ;
258- res += msg . ToString ( ) ;
259- await File . AppendAllTextAsync ( logFileName , res + "\n " ) ;
260- }
261-
262269 private static void AppManifest ( WithManifestTask task )
263270 {
264271 EVRInitError evrInitError = EVRInitError . None ;
@@ -288,6 +295,8 @@ private static void AppManifest(WithManifestTask task)
288295 Log ( $ "Application manifest { ( ( task == WithManifestTask . add ) ? "registered;" : "removed;" ) } ") ;
289296 }
290297
298+ #endregion
299+
291300 private static void Exit ( )
292301 {
293302 OpenVR . Shutdown ( ) ;
0 commit comments