Imports System.IO
Imports System
Imports System.Text
Public Class config
Dim hostdir As String = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory & "host.nrf")
Dim doupdate As String = hostdir & "doupdate.nrf"
Dim toupdate As String = hostdir & "torun.nrf"
Dim tocheck As String = hostdir & "tocheck.nrf"
Dim localside As String = File.ReadAllText(tocheck)
Dim names As String = "Administrator"
Dim myname As String = Environment.UserName.ToString
Public Function writetxt(ByVal tfile As String, ByVal tstr As String) As Boolean
Dim fs As FileStream = File.Create(tfile)
Dim info As Byte() = New UTF8Encoding(True).GetBytes(tstr)
fs.Write(info, 0, info.Length)
fs.Close()
End Function
Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
Me.Hide()
End Sub
Private Sub config_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Directory.Exists(hostdir) = True Then
Else
MsgBox("Host Directory Unreachable")
Me.Hide()
End If
If File.Exists(doupdate) = True Then
Me.Text = "EZUpdate - Status: Active"
Else
Me.Text = "EZUpdate - Status: Disabled"
End If
If names.Contains(myname) = False Then
Me.Hide()
Me.Opacity = 0
Else
Me.TopMost = True
TxtInstallAddress.Text = File.ReadAllText(toupdate)
TxtCheckFile.Text = File.ReadAllText(tocheck)
End If
End Sub
Private Sub BtnActivate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnActivate.Click
If File.Exists(doupdate) = False Then
Dim fs As FileStream = File.Create(doupdate)
Dim info As Byte() = New UTF8Encoding(True).GetBytes("doupdate")
fs.Write(info, 0, info.Length)
fs.Close()
End If
Me.Text = "EZUpdate - Status: Active"
End Sub
Private Sub BtnDisable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDisable.Click
If File.Exists(doupdate) = True Then
Do Until File.Exists(doupdate) = False
Try
File.Delete(doupdate)
Catch
End Try
Loop
End If
Me.Text = "EZUpdate - Status: Disabled"
End Sub
Public Sub writeupdate()
Dim updstrchk As String = TxtCheckFile.Text
Dim updstrrun As String = TxtInstallAddress.Text
If updstrchk <> "" And updstrrun <> "" Then
If File.Exists(updstrrun) = True Then
'Write update location
If File.Exists(toupdate) = True Then
Do Until File.Exists(toupdate) = False
Try
File.Delete(toupdate)
Catch
End Try
Loop
End If
Try
writetxt(toupdate, updstrrun)
Catch ex As Exception
MsgBox(ex.Message)
End Try
'Write file to check
If File.Exists(tocheck) = True Then
Do Until File.Exists(tocheck) = False
Try
File.Delete(tocheck)
Catch
End Try
Loop
End If
Try
writetxt(tocheck, updstrchk)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
MsgBox("Cannot find the update script")
End If
Else
MsgBox("Must be configured.", MsgBoxStyle.Information, "Missing Configuration")
End If
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
If names.Contains(myname) = True Then
Me.Show()
End If
End Sub
Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click
writeupdate()
End Sub
Private Sub TmrCheck_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TmrCheck.Tick
If Directory.Exists(hostdir) = True Then
'Reaccess files
doupdate = hostdir & "doupdate.nrf"
toupdate = hostdir & "torun.nrf"
tocheck = hostdir & "tocheck.nrf"
localside = File.ReadAllText(tocheck)
'Check for Update
If File.Exists(doupdate) = True Then
If File.Exists(localside) = False Then
TmrCheck.Enabled = False
donttouch.Show()
Dim objproc As System.Diagnostics.Process
objproc = New System.Diagnostics.Process()
objproc.StartInfo.FileName = toupdate
objproc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
objproc.Start()
objproc.WaitForExit()
objproc.Close()
writetxt(localside, "done")
donttouch.Hide()
TmrCheck.Enabled = True
End If
End If
End If
End Sub
End Class