1010Imports WinNUT_Params = WinNUT_Client_Common.WinNUT_Params
1111Imports Logger = WinNUT_Client_Common.Logger
1212Imports LogLvl = WinNUT_Client_Common.LogLvl
13- Imports WinNUT_Globals = WinNUT_Client_Common.WinNUT_Globals
13+ Imports WinNUT_Client_Common.WinNUT_Globals
14+ Imports System.IO
15+
1416Public Class Pref_Gui
1517 Private IsShowed As Boolean = False
1618 Private IsSaved As Boolean = False
17- Private LogFile As Logger
19+
1820 Private Sub Btn_Cancel_Click(sender As Object , e As EventArgs) Handles Btn_Cancel.Click
1921 LogFile.LogTracing( "Close Pref Gui from Button Cancel" , LogLvl.LOG_DEBUG, Me )
2022 Me .Close()
@@ -72,23 +74,13 @@ Public Class Pref_Gui
7274 LogFile.LogTracing( "WinNUT Removed From Startup." , LogLvl.LOG_DEBUG, Me )
7375 End If
7476 End If
75- If CB_Use_Logfile.Checked Then
76- WinNUT.LogFile.WriteLog = True
77- LogFile.LogTracing( "LogFile Enabled." , LogLvl.LOG_DEBUG, Me )
78- Else
79- WinNUT.LogFile.WriteLog = False
80- LogFile.LogTracing( "LogFile Disabled." , LogLvl.LOG_DEBUG, Me )
81- End If
82- WinNUT.LogFile.LogLevel = Cbx_LogLevel.SelectedIndex
8377
84- WinNUT.LogFile.LogTracing( "Pref_Gui Params Saved" , 1 , Me )
85- If My.Computer.FileSystem.FileExists(WinNUT_Globals.LogFilePath) Then
86- Btn_ViewLog.Enabled = True
87- Btn_DeleteLog.Enabled = True
88- Else
89- Btn_ViewLog.Enabled = False
90- Btn_DeleteLog.Enabled = False
91- End If
78+ LogFile.LogLevel = Cbx_LogLevel.SelectedIndex
79+ LogFile.IsWritingToFile = CB_Use_Logfile.Checked
80+
81+ LogFile.LogTracing( "Pref_Gui Params Saved" , 1 , Me )
82+
83+ SetLogControlsStatus()
9284 WinNUT.WinNUT_PrefsChanged()
9385 Me .IsSaved = True
9486 Catch e As Exception
@@ -326,35 +318,28 @@ Public Class Pref_Gui
326318 End Sub
327319
328320 Private Sub TabControl_Options_Selecting(sender As Object , e As TabControlCancelEventArgs) Handles TabControl_Options.Selecting
329- If My.Computer.FileSystem.FileExists(WinNUT_Globals.LogFilePath) Then
330- Btn_ViewLog.Enabled = True
331- Btn_DeleteLog.Enabled = True
332- Else
333- Btn_ViewLog.Enabled = False
334- Btn_DeleteLog.Enabled = False
321+ If TabControl_Options.SelectedTab Is Tab_Miscellanous Then
322+ SetLogControlsStatus()
335323 End If
336324 End Sub
337325
338326 Private Sub Btn_DeleteLog_Click(sender As Object , e As EventArgs) Handles Btn_DeleteLog.Click
339327 LogFile.LogTracing( "Delete LogFile" , LogLvl.LOG_DEBUG, Me )
340- If My.Computer.FileSystem.FileExists(WinNUT_Globals.LogFilePath) Then
341- WinNUT.LogFile.WriteLog = False
342- My.Computer.FileSystem.DeleteFile(WinNUT_Globals.LogFilePath)
343- WinNUT.LogFile.WriteLog = WinNUT_Params.Arr_Reg_Key.Item( "UseLogFile" )
344- Btn_ViewLog.Enabled = True
345- Btn_DeleteLog.Enabled = True
328+
329+ If LogFile.DeleteLogFile() Then
346330 LogFile.LogTracing( "LogFile Deleted" , LogLvl.LOG_DEBUG, Me )
347331 Else
348- LogFile.LogTracing( "LogFile does not exists" , LogLvl.LOG_WARNING, Me )
349- Btn_ViewLog.Enabled = False
350- Btn_DeleteLog.Enabled = False
332+ LogFile.LogTracing( "Error deleting log file." , LogLvl.LOG_WARNING, Me )
351333 End If
334+
335+ LogFile.IsWritingToFile = WinNUT_Params.Arr_Reg_Key.Item( "UseLogFile" )
336+ SetLogControlsStatus()
352337 End Sub
353338
354339 Private Sub Btn_ViewLog_Click(sender As Object , e As EventArgs) Handles Btn_ViewLog.Click
355340 LogFile.LogTracing( "Show LogFile" , LogLvl.LOG_DEBUG, Me )
356- If My.Computer.FileSystem.FileExists(WinNUT_Globals.LogFilePath ) Then
357- Process.Start(WinNUT_Globals.LogFilePath )
341+ If File.Exists(LogFile.LogFileLocation ) Then
342+ Process.Start(LogFile.LogFileLocation )
358343 Else
359344 LogFile.LogTracing( "LogFile does not exists" , LogLvl.LOG_WARNING, Me )
360345 Btn_ViewLog.Enabled = False
@@ -364,7 +349,6 @@ Public Class Pref_Gui
364349
365350 Private Sub Pref_Gui_Load(sender As Object , e As EventArgs) Handles MyBase .Load
366351 Me .Icon = WinNUT.Icon
367- Me .LogFile = WinNUT.LogFile
368352 LogFile.LogTracing( "Load Pref Gui" , LogLvl.LOG_DEBUG, Me )
369353 End Sub
370354
@@ -374,4 +358,19 @@ Public Class Pref_Gui
374358 Me .Btn_Apply.Enabled = True
375359 End If
376360 End Sub
361+
362+ ''' <summary>
363+ ''' Enable or disable controls to view and delete log data if it's available.
364+ ''' </summary>
365+ Private Sub SetLogControlsStatus()
366+ If WinNUT_Params.Arr_Reg_Key.Item( "UseLogFile" ) Then ' Directory.Exists(Logger.LogFolder)
367+ Btn_ViewLog.Enabled = True
368+ Btn_DeleteLog.Enabled = True
369+ Else
370+ Btn_ViewLog.Enabled = False
371+ Btn_DeleteLog.Enabled = False
372+ End If
373+
374+ LogFile.LogTracing( "Setting LogControl statuses." , LogLvl.LOG_DEBUG, Me )
375+ End Sub
377376End Class
0 commit comments