'
' Created by SharpDevelop.
' User: Jano
' Date: 9.8.2017
' Time: 14:20
' 
' To change this template use Tools | Options | Coding | Edit Standard Headers.
'
Imports System.Net
Imports System.IO

Module Program
Public verzia=7000	
	Sub Main()
		Console.WriteLine("Updater The school of drive!")
		Try
		
		' TODO: Implement Functionality Here
				Dim remoteUri As String = readRemote("http://www.autoskola-free.szm.sk/rserver.txt") & "/"
				Dim v As String = readRemote(remoteUri & "verzia.txt")
				Console.WriteLine("There is the newest version on the server " & v.ToString())
				verzia = verzia + 1
				Dim fileName As String = "aktualizujautoskola" & verzia.ToString() & ".exe"
				Dim myStringWebResource As String = Nothing
				' Create a new WebClient instance.
				Dim myWebClient As New WebClient()
				' Concatenate the domain with the Web resource filename. Because DownloadFile 
				'requires a fully qualified resource name, concatenate the domain with the Web resource file name.
				myStringWebResource = remoteUri + fileName
				Console.WriteLine("Downloading the file ""{0}"" z ""{1}"" ......." + ControlChars.Cr + ControlChars.Cr, fileName, myStringWebResource)
				' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
				myWebClient.DownloadFile(myStringWebResource, fileName)
				Console.WriteLine("Successfully downloaded file ""{0}"" z ""{1}""", fileName, myStringWebResource)
				Console.WriteLine((ControlChars.Cr + "Downloaded file saved in this directory:" + ControlChars.Cr + ControlChars.Tab + My.Application.Info.DirectoryPath))
				Dim app As String = My.Application.Info.DirectoryPath & "/" & fileName 
				Dim AppParam As String = "none"
				System.Diagnostics.Process.Start(app, AppParam)
				Console.Write("Press any key to continue . . . ")
				Console.ReadKey(True)
		Catch ex As Exception
			'Console.WriteLine(My.Application.Info.DirectoryPath)
			Console.WriteLine(ex.Message)
			Console.Write("Press any key to continue . . . ")
				Console.ReadKey(True)
		End Try
	End Sub
	Public function readRemote(addr As String)
		Dim client As WebClient = New WebClient()
		Dim reader As StreamReader = New StreamReader(client.OpenRead(addr))
		Return reader.ReadToEnd
	End Function
	
End Module
