Imports System

Imports System . Net

Imports System . IO

Imports System . Text . RegularExpressions

Imports System . IO . Compression

Imports System . IO . Compression . ZipFileExtensions

Imports IWshRuntimeLibrary

'

Public Partial Class MainForm

Public Sub New ( )

' The Me.InitializeComponent call is required for Windows Forms designer support.

Me . InitializeComponent ( )

'Download Version.txt from github

Dim web_client As WebClient = New WebClient

Dim hostedVersion As String = web_client . DownloadString ( "VERSION URL" )

' Initial download

If Not My . Computer . FileSystem . FileExists ( My . Application . Info . DirectoryPath & "\Version.txt" ) Then

MessageBox . Show ( "Please wait while the application installs!" )

' Download the version string

Using sw As StreamWriter = New StreamWriter ( My . Application . Info . DirectoryPath & "\Version.txt" )

sw . Write ( hostedVersion . Trim )

End Using

' Download the package

downloadZip ( )

' Extract the Package

extractZip ( )

' Create a desktop Icon?

If MessageBox . Show ( "Would you like to create a desktop icon?" , "Update?" ,MessageBoxButtons . YesNo ) = DialogResult . Yes Then

Dim WshShell As WshShellClass = New WshShellClass

Dim MyShortcut As IWshRuntimeLibrary . IWshShortcut

' The shortcut will be created on the desktop

Dim DesktopFolder As String = Environment . GetFolderPath ( Environment . SpecialFolder . DesktopDirectory )

MyShortcut = CType ( WshShell . CreateShortcut ( DesktopFolder & "\PROGRAM NAME.lnk" ) , IWshRuntimeLibrary . IWshShortcut )

MyShortcut . TargetPath = Application . StartupPath & "\YourApp.exe" 'Specify target app full path

MyShortcut . Save ( )

End If

'Start the Package

Process . Start ( My . Application . Info . DirectoryPath & "\APP FOLDER\YourApp.exe" )

Else

' Read Current Version

Dim version As String = ""

Using sr As StreamReader = New StreamReader ( My . Application . Info . DirectoryPath & "\Version.txt" )

version = sr . ReadLine ( )

End Using

If version . Trim ( ) = hostedVersion . Trim Then

' Up to date

Process . Start ( My . Application . Info . DirectoryPath & "\APP FOLDER\YourApp.exe" )

Else

' Out of date

If MessageBox . Show ( "Your Draft Loadout is out of date do you want to Update it?" , "Update?" ,MessageBoxButtons . YesNo ) = DialogResult . Yes Then

' Download the version string

Using sw As StreamWriter = New StreamWriter ( My . Application . Info . DirectoryPath & "\Version.txt" )

sw . WriteLine ( hostedVersion . Trim )

End Using

' Download the package

downloadZip ( )

' Extract the Package

extractZip ( )

MessageBox . Show ( "Update Finished." )

Process . Start ( My . Application . Info . DirectoryPath & "\APP FOLDER\YourApp.exe" )

Else

'Start the Package

Process . Start ( My . Application . Info . DirectoryPath & "\APP FOLDER\YourApp.exe" )

End If

End If

End If

End Sub

Private Shared Sub downloadZip ( )

Dim web_client As WebClient = New WebClient

web_client . DownloadFile ( "ZIPPED ARCHIVE URL" ,My . Application . Info . DirectoryPath & "\YourApp.zip" )

End Sub

Private Shared Sub extractZip ( )

Dim zipPath As String = My . Application . Info . DirectoryPath & "\YourApp.zip"

Dim extractPath As String = My . Application . Info . DirectoryPath & "\APP FOLDER"

Using archive As ZipArchive = ZipFile . OpenRead ( zipPath )

For Each entry As ZipArchiveEntry In archive . Entries

Dim entryFullname = Path . Combine ( extractPath, entry . FullName )

Dim entryPath = Path . GetDirectoryName ( entryFullName )

If ( Not ( Directory . Exists ( entryPath ) ) ) Then

Directory . CreateDirectory ( entryPath )

End If

Dim entryFn = Path . GetFileName ( entryFullname )

If ( Not String . IsNullOrEmpty ( entryFn ) ) Then

entry . ExtractToFile ( entryFullname, True )

End If

Next

End Using

My . Computer . FileSystem . DeleteFile ( My . Application . Info . DirectoryPath & "\YourApp.zip" )

End Sub

Sub MainFormShown ( sender As Object , e As EventArgs )

Application . Exit

END

End Sub