Jump to content

Como verificar se ficheiros remotos existem?


almenorocha

Recommended Posts

Boa tarde, não sou programador mas ao fim de umas boas horas a pesquisar consegui fazer isto. A ideia inicial era actualizar os clientes de uma forma fácil, saber as versões instaladas, etc... O software dos clientes é de terceiros e eu queria ter controlo nas actualizações

Aparentemente tudo funciona como pretendo, ou seja: coloco os ficheiros online e um txt com as versões, o programa verifica e actualiza... Mas preciso verificar se os ficheiros existem remotamente e não sei como.

Alguém dá uma ajudinha? 🙂

O que melhoravam aqui? (muita coisa, acredito... 🙂 )

MAIN:

main.jpg

Imports System.ServiceProcess
Imports System.IO
Public Class main

Dim file1 = "ZSRest.exe"
Dim file2 = "ZSyncServer.exe"
Dim file3 = "ZAuthServer.exe"
Dim file4 = "ZSRestWebService.exe"
Dim file5 = "ZSPDAServer.exe"
Dim file6 = "SAF_PT.exe"
Dim datadia = Now.Date
Dim updatedlocalfile = " actualizado com sucesso."
Dim instaledlocalfile = " instalado com sucesso."
Dim errorlocalfile = "O ficheiro não existe nesta instalação. Pretende fazer a instalação do: "
Dim restoredsucess = " rastaurado com sucesso."
Dim nobackuprestore = " Não existe backup de ficheiro: "
Dim nolocalrestore = "O ficheiro não existe nesta instalação. Pretende fazer o restauro do ficheiro: "
Dim remoteversionsfile = config.pathremote & "versoes.txt"
Dim localversionsfile = config.pathbackups & "versoes.txt"
Public Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 createpathbackups()
 checkpath()
 getversion()
 checkurl()
 getremoteversion()
End Sub
Private Sub btactualizar_Click(sender As Object, e As EventArgs) Handles btactualizar.Click
 createpathbackups()
 checkpath()
 checkurl()
 If ch1.Checked Then
	 updatezsrest()
 Else
 End If
 If ch2.Checked Then
	 updatezsrestservice()
 Else
 End If
 If ch3.Checked Then
	 updatezsauthservice()
 Else
 End If
 If ch4.Checked Then
	 updatezswebservice()
 Else
 End If
 If ch5.Checked Then
	 updatezspda()
 Else
 End If
 If ch6.Checked Then
	 updatesafpt()
 Else
 End If
 getversion()
End Sub

Private Sub btconfigurar_Click(sender As Object, e As EventArgs) Handles btconfigurar.Click
 config.Show()
End Sub
Private Sub btanular_Click(sender As Object, e As EventArgs) Handles btanular.Click
 createpathbackups()
 checkpath()
 If ch1.Checked Then
	 restorezsrest()
 Else
 End If
 If ch2.Checked Then
	 restorezsrestservice()
 Else
 End If
 If ch3.Checked Then
	 restorezsauthservice()
 Else
 End If
 If ch4.Checked Then
	 restorezswebservice()
 Else
 End If
 If ch5.Checked Then
	 restorezspda()
 Else
 End If
 If ch6.Checked Then
	 restoresafpt()
 Else
 End If
 getversion()
End Sub


Public Sub checkurl()
 Dim url As New System.Uri(config.pathremote)
 Dim req As System.Net.WebRequest
 req = System.Net.WebRequest.Create(url)
 Dim resp As System.Net.WebResponse
 Try
	 resp = req.GetResponse()
	 resp.Close()
	 req = Nothing
 Catch ex As Exception
	 MessageBox.Show("O endereço remoto não está correcto. Verifique se tem Internet e/ou corrija o endereço.", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error)
	 config.Show()
 End Try
End Sub
Public Sub checkpath()
 If My.Computer.FileSystem.DirectoryExists(config.pathlocal) Then
 Else
	 MessageBox.Show("A directoria de instalação não existe, configure o local de instalação.", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error)
	 config.Show()
 End If
End Sub
Public Sub getversion()
 If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "ZSRest.exe") Then
	 Dim FileProperties1 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "ZSRest.exe")
	 txtfileversion1.Text = FileProperties1.FileVersion
 Else
	 txtfileversion1.Text = ("Não Existe")
 End If
 If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "ZSyncServer.exe") Then
	 Dim FileProperties2 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "ZSyncServer.exe")
	 txtfileversion2.Text = FileProperties2.FileVersion
 Else
	 txtfileversion2.Text = ("Não Existe")
 End If
 If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "ZAuthServer.exe") Then
	 Dim FileProperties3 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "ZAuthServer.exe")
	 txtfileversion3.Text = FileProperties3.FileVersion
 Else
	 txtfileversion3.Text = ("Não Existe")
 End If
 If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "ZSRestWebService.exe") Then
	 Dim FileProperties4 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "ZSRestWebService.exe")
	 txtfileversion4.Text = FileProperties4.FileVersion
 Else
	 txtfileversion4.Text = ("Não Existe")
 End If
 If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "ZSPDAServer.exe") Then
	 Dim FileProperties5 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "ZSPDAServer.exe")
	 txtfileversion5.Text = FileProperties5.FileVersion
 Else
	 txtfileversion5.Text = ("Não Existe")
 End If
 If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "SAF_PT.exe") Then
	 Dim FileProperties6 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "SAF_PT.exe")
	 txtfileversion6.Text = FileProperties6.FileVersion
 Else
	 txtfileversion6.Text = ("Não Existe")
 End If

End Sub
Public Sub getremoteversion()
 Dim FileText As String
 Dim FileLines() As String
 Dim OneLine() As String
 Dim SeparatorChar As String
 Dim i As Integer
 SeparatorChar = "|"
 If My.Computer.FileSystem.FileExists(localversionsfile) Then
	 My.Computer.FileSystem.DeleteFile(localversionsfile)
	 My.Computer.Network.DownloadFile(remoteversionsfile, localversionsfile)
 Else
	 My.Computer.Network.DownloadFile(remoteversionsfile, localversionsfile)
 End If
 FileText = My.Computer.FileSystem.ReadAllText(localversionsfile)
 FileLines = FileText.Split(CChar(Environment.NewLine))
 FileLines = FileText.Split(CChar(Environment.NewLine))
 OneLine = FileLines(0).Split(CChar(SeparatorChar))

 For i = 0 To FileLines.GetUpperBound(0)
	 OneLine = FileLines(i).Split(CChar(SeparatorChar))
 Next i
 txtremoteversion1.Text = OneLine(0)
 txtremoteversion2.Text = OneLine(1)
 txtremoteversion3.Text = OneLine(2)
 txtremoteversion4.Text = OneLine(3)
 txtremoteversion5.Text = OneLine(4)
 txtremoteversion6.Text = OneLine(5)
End Sub
Public Sub createpathbackups()
 Try
	 If Not Directory.Exists(config.pathbackups) Then
		 Directory.CreateDirectory(config.pathbackups)
	 End If
 Catch ex As System.Exception
	 MessageBox.Show("Não foi possivel criar a directoria de Backups.", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error)
 End Try
End Sub
Private Sub updatezsrest()
 'ACTUALIZAÇÃO APLICAÇÃO
 Dim file = file1
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filebackup)
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 Else
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 End If
	 My.Computer.Network.DownloadFile(fileremote, filelocal)
	 MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 My.Computer.Network.DownloadFile(fileremote, filelocal)
		 MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
	 End If
 End If

End Sub
Private Sub updatezsrestservice()
 'ACTUALIZAÇÃO SERVIÇO SINCRONIZAÇAO
 Dim file = file2
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filebackup)
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 Else
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 End If
	 My.Computer.Network.DownloadFile(fileremote, filelocal)
	 MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 My.Computer.Network.DownloadFile(fileremote, filelocal)
		 MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
	 End If
 End If
End Sub
Private Sub updatezsauthservice()
 'ACTUALIZAÇÃO SERVIÇO VERIFICAÇÃO LICENÇA

 Dim file = file3
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filebackup)
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 Else
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 End If
	 My.Computer.Network.DownloadFile(fileremote, filelocal)
	 MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 My.Computer.Network.DownloadFile(fileremote, filelocal)
		 MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
	 End If
 End If
End Sub
Private Sub updatezswebservice()
 'ACTUALIZAÇÃO ZSRESTWEBSERVICE

 Dim file = file4
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filebackup)
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 Else
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 End If
	 My.Computer.Network.DownloadFile(fileremote, filelocal)
	 MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 My.Computer.Network.DownloadFile(fileremote, filelocal)
		 MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
	 End If
 End If
End Sub
Private Sub updatezspda()
 'ACTUALIZAÇÃO ZSPDA

 Dim file = file5
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filebackup)
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 Else
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 End If
	 My.Computer.Network.DownloadFile(fileremote, filelocal)
	 MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 My.Computer.Network.DownloadFile(fileremote, filelocal)
		 MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
	 End If
 End If

End Sub
Private Sub updatesafpt()
 'ACTUALIZAÇÃO APLICAÇÃO

 Dim file = file6
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filebackup)
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 Else
		 My.Computer.FileSystem.MoveFile(filelocal, filebackup)
	 End If
	 My.Computer.Network.DownloadFile(fileremote, filelocal)
	 MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 My.Computer.Network.DownloadFile(fileremote, filelocal)
		 MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
	 End If
 End If
End Sub
Private Sub restorezsrest()
 'Restauro APLICAÇÃO
 Dim file = file1
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filelocal)
		 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
		 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
		 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 End If
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 If My.Computer.FileSystem.FileExists(filebackup) Then
			 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
			 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 Else
			 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 End If
	 Else
	 End If
 End If
End Sub
Private Sub restorezsrestservice()
 'Restauro APLICAÇÃO
 Dim file = file2
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filelocal)
		 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
		 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
		 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 End If
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 If My.Computer.FileSystem.FileExists(filebackup) Then
			 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
			 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 Else
			 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 End If
	 Else
	 End If
 End If
End Sub
Private Sub restorezsauthservice()
 'Restauro APLICAÇÃO
 Dim file = file3
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filelocal)
		 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
		 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
		 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 End If
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 If My.Computer.FileSystem.FileExists(filebackup) Then
			 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
			 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 Else
			 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 End If
	 Else
	 End If
 End If
End Sub
Private Sub restorezswebservice()
 'Restauro APLICAÇÃO
 Dim file = file4
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filelocal)
		 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
		 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
		 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 End If
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 If My.Computer.FileSystem.FileExists(filebackup) Then
			 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
			 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 Else
			 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 End If
	 Else
	 End If
 End If
End Sub
Private Sub restorezspda()
 'Restauro APLICAÇÃO
 Dim file = file5
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filelocal)
		 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
		 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
		 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 End If
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 If My.Computer.FileSystem.FileExists(filebackup) Then
			 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
			 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 Else
			 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 End If
	 Else
	 End If
 End If
End Sub
Private Sub restoresafpt()
 'Restauro APLICAÇÃO
 Dim file = file6
 Dim filelocal = config.pathlocal & file
 Dim filebackup = config.pathbackups & datadia & "\" & file
 Dim fileremote = config.pathremote & file
 If My.Computer.FileSystem.FileExists(filelocal) Then
	 If My.Computer.FileSystem.FileExists(filebackup) Then
		 My.Computer.FileSystem.DeleteFile(filelocal)
		 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
		 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 Else
		 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
	 End If
 Else
	 Dim confirma As DialogResult
	 confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
	 If confirma = Windows.Forms.DialogResult.Yes Then
		 If My.Computer.FileSystem.FileExists(filebackup) Then
			 My.Computer.FileSystem.CopyFile(filebackup, filelocal)
			 MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 Else
			 MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
		 End If
	 Else
	 End If
 End If
End Sub
Public Sub Stopservicezssync()
 Dim service As ServiceController = New ServiceController("ZsyncSrv")
 If ((service.Status.Equals(ServiceControllerStatus.Running))) Then
	 Try
		 service.Stop()
	 Catch ex As Exception
		 MessageBox.Show("Não foi possivel parar o ZSyncServer...", "!!!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
	 End Try
 Else
 End If
End Sub
Public Sub Stopservicezsauth()
 Dim service As ServiceController = New ServiceController("ZAuthSrv")
 If ((service.Status.Equals(ServiceControllerStatus.Running))) Then
	 Try
		 service.Stop()
	 Catch ex As Exception
		 MessageBox.Show("Não foi possivel parar o ZAuthServer...", "!!!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
	 End Try
 Else
 End If
End Sub
Public Sub Startservicezssync()
 Dim service As ServiceController = New ServiceController("ZsyncSrv")
 If ((service.Status.Equals(ServiceControllerStatus.Stopped))) Then
	 Try
		 service.Start()
	 Catch ex As Exception
		 MessageBox.Show("Não foi possivel iniciar o ZSyncServer...", "!!!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
	 End Try
 Else
 End If
End Sub
Public Sub Startservicezsauth()
 Dim service As ServiceController = New ServiceController("ZAuthSrv")
 If ((service.Status.Equals(ServiceControllerStatus.Stopped))) Then
	 Try
		 service.Start()
	 Catch ex As Exception
		 MessageBox.Show("Não foi possivel iniciar o ZAuthServer...", "!!!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
	 End Try
 Else
 End If
End Sub

End Class

CONFIG:

config.jpg

Public Class config

Public ReadOnly Property pathlocal As String
 Get
	 Return "" & txtlocal.Text & ""
 End Get
End Property
Public ReadOnly Property pathremote As String
 Get
	 Return "" & txthost.Text & ""
 End Get
End Property
Public ReadOnly Property pathbackups As String
 Get
	 Return "" & txtbackups.Text & ""
 End Get
End Property
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 Me.Hide()
 main.checkpath()
 main.getversion()
 main.createpathbackups()
 main.checkurl()
 main.getremoteversion()

End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
 Me.Hide()
End Sub

End Class
Link to comment
Share on other sites

Podes utilizar um WebRequest com o URL que pretendes.

Se obtiveres resposta, o ficheiro existe. Se apanhares 404... não existe.

Tens de fazer o tratamento de excepção porque o 404 não sai como resposta. Sai como excepção.

A forma mais simples do o fazer, para começares, é utilizar a implementação WebClient.

Dá uma vista de olhos. Se precisares de ajuda, cá estaremos 🙂

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Link to comment
Share on other sites

o ficheiro já existe ? se existir fazes uma comparação do assembly

E o Impossível foi criado por pessoas fracas pra acabar com o sonho das pessoas fortes. Não deixes que acabem com o teu. Sonha , luta , ambiciona e realiza. Se amas , se gostas tu vais conseguir. Cala todas as pessoas que um dia duvidaram de ti e prova que foste mais forte de qualquer outro.

Link to comment
Share on other sites

  • 6 months later...

Boas,

consegui fazer o que queria com este código...

tools.jpg

Imports System.ServiceProcess
Imports System.IO
Public Class zsupdate
Dim file1 = "ZSRest.exe"
Dim file2 = "ZSyncServer.exe"
Dim file3 = "ZAuthServer.exe"
Dim file4 = "ZSRestWebService.exe"
Dim file5 = "ZSPDAServer.exe"
Dim file6 = "SAF_PT.exe"
Dim file7 = "ca-cert.pem"
Dim datadia = Now.Date
Dim updatedlocalfile = " actualizado com sucesso."
Dim instaledlocalfile = " instalado com sucesso."
Dim errorlocalfile = "O ficheiro não existe nesta instalação. Pretende fazer a instalação do: "
Dim restoredsucess = " rastaurado com sucesso."
Dim nobackuprestore = " Não existe backup de ficheiro: "
Dim nolocalrestore = "O ficheiro não existe nesta instalação. Pretende fazer o restauro do ficheiro: "
Dim remoteversionsfile = config.pathremote & "versoes.txt"
Dim localversionsfile = config.pathbackups & "versoes.txt"
Public Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    createpathbackups()
    checkpath()
    getversion()
    checkurl()
    getremoteversion()
End Sub
Private Sub btactualizar_Click(sender As Object, e As EventArgs) Handles btactualizar.Click
    createpathbackups()
    checkpath()
    checkurl()
    If ch1.Checked Then
        updatezsrest()
        updatecacert()
    Else
    End If
    If ch2.Checked Then
        updatezsrestservice()
    Else
    End If
    If ch3.Checked Then
        updatezsauthservice()
    Else
    End If
    If ch4.Checked Then
        updatezswebservice()
    Else
    End If
    If ch5.Checked Then
        updatezspda()
    Else
    End If
    If ch6.Checked Then
        updatesafpt()
    Else
    End If
    getversion()
End Sub
Private Sub btconfigurar_Click(sender As Object, e As EventArgs) Handles btconfigurar.Click
    config.Show()
End Sub
Private Sub btanular_Click(sender As Object, e As EventArgs) Handles btanular.Click
    createpathbackups()
    checkpath()
    If ch1.Checked Then
        restorezsrest()
    Else
    End If
    If ch2.Checked Then
        restorezsrestservice()
    Else
    End If
    If ch3.Checked Then
        restorezsauthservice()
    Else
    End If
    If ch4.Checked Then
        restorezswebservice()
    Else
    End If
    If ch5.Checked Then
        restorezspda()
    Else
    End If
    If ch6.Checked Then
        restoresafpt()
    Else
    End If
    getversion()
End Sub
Public Sub checkurl()
    Dim url As New System.Uri(config.pathremote)
    Dim req As System.Net.WebRequest
    req = System.Net.WebRequest.Create(url)
    Dim resp As System.Net.WebResponse
    Try
        resp = req.GetResponse()
        resp.Close()
        req = Nothing
    Catch ex As Exception
        MessageBox.Show("O endereço remoto não está correcto. Verifique se tem Internet e/ou corrija o endereço.", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error)
        config.Show()
    End Try
End Sub
Public Sub checkpath()
    If My.Computer.FileSystem.DirectoryExists(config.pathlocal) Then
    Else
        MessageBox.Show("A directoria de instalação não existe, configure o local de instalação.", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error)
        config.Show()
    End If
End Sub
Public Sub getversion()
    If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "ZSRest.exe") Then
        Dim FileProperties1 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "ZSRest.exe")
        txtfileversion1.Text = FileProperties1.FileVersion
    Else
        txtfileversion1.Text = ("Não Existe")
    End If
    If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "ZSyncServer.exe") Then
        Dim FileProperties2 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "ZSyncServer.exe")
        txtfileversion2.Text = FileProperties2.FileVersion
    Else
        txtfileversion2.Text = ("Não Existe")
    End If
    If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "ZAuthServer.exe") Then
        Dim FileProperties3 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "ZAuthServer.exe")
        txtfileversion3.Text = FileProperties3.FileVersion
    Else
        txtfileversion3.Text = ("Não Existe")
    End If
    If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "ZSRestWebService.exe") Then
        Dim FileProperties4 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "ZSRestWebService.exe")
        txtfileversion4.Text = FileProperties4.FileVersion
    Else
        txtfileversion4.Text = ("Não Existe")
    End If
    If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "ZSPDAServer.exe") Then
        Dim FileProperties5 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "ZSPDAServer.exe")
        txtfileversion5.Text = FileProperties5.FileVersion
    Else
        txtfileversion5.Text = ("Não Existe")
    End If
    If My.Computer.FileSystem.FileExists("" & config.txtlocal.Text & "SAF_PT.exe") Then
        Dim FileProperties6 As FileVersionInfo = FileVersionInfo.GetVersionInfo("" & config.txtlocal.Text & "SAF_PT.exe")
        txtfileversion6.Text = FileProperties6.FileVersion
    Else
        txtfileversion6.Text = ("Não Existe")
    End If
End Sub
Public Sub getremoteversion()
    Dim FileText As String
    Dim FileLines() As String
    Dim OneLine() As String
    Dim SeparatorChar As String
    Dim i As Integer
    SeparatorChar = "|"
    If My.Computer.FileSystem.FileExists(localversionsfile) Then
        My.Computer.FileSystem.DeleteFile(localversionsfile)
        My.Computer.Network.DownloadFile(remoteversionsfile, localversionsfile)
    Else
        My.Computer.Network.DownloadFile(remoteversionsfile, localversionsfile)
    End If
    FileText = My.Computer.FileSystem.ReadAllText(localversionsfile)
    FileLines = FileText.Split(CChar(Environment.NewLine))
    FileLines = FileText.Split(CChar(Environment.NewLine))
    OneLine = FileLines(0).Split(CChar(SeparatorChar))
    For i = 0 To FileLines.GetUpperBound(0)
        OneLine = FileLines(i).Split(CChar(SeparatorChar))
    Next i
    txtremoteversion1.Text = OneLine(0)
    txtremoteversion2.Text = OneLine(1)
    txtremoteversion3.Text = OneLine(2)
    txtremoteversion4.Text = OneLine(3)
    txtremoteversion5.Text = OneLine(4)
    txtremoteversion6.Text = OneLine(5)
End Sub
Public Sub createpathbackups()
    Try
        If Not Directory.Exists(config.pathbackups) Then
            Directory.CreateDirectory(config.pathbackups)
        End If
    Catch ex As System.Exception
        MessageBox.Show("Não foi possivel criar a directoria de Backups.", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub
Private Sub updatecacert()
    'ACTUALIZAÇÃO APLICAÇÃO
    Dim file = file7
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filebackup)
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        Else
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        End If
        My.Computer.Network.DownloadFile(fileremote, filelocal)
        MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            My.Computer.Network.DownloadFile(fileremote, filelocal)
            MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
        End If
    End If
End Sub
Private Sub updatezsrest()
    'ACTUALIZAÇÃO APLICAÇÃO
    Dim file = file1
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filebackup)
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        Else
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        End If
        My.Computer.Network.DownloadFile(fileremote, filelocal)
        MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            My.Computer.Network.DownloadFile(fileremote, filelocal)
            MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
        End If
    End If
End Sub
Private Sub updatezsrestservice()
    'ACTUALIZAÇÃO SERVIÇO SINCRONIZAÇAO
    Dim file = file2
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filebackup)
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        Else
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        End If
        My.Computer.Network.DownloadFile(fileremote, filelocal)
        MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            My.Computer.Network.DownloadFile(fileremote, filelocal)
            MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
        End If
    End If
End Sub
Private Sub updatezsauthservice()
    'ACTUALIZAÇÃO SERVIÇO VERIFICAÇÃO LICENÇA
    Dim file = file3
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filebackup)
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        Else
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        End If
        My.Computer.Network.DownloadFile(fileremote, filelocal)
        MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            My.Computer.Network.DownloadFile(fileremote, filelocal)
            MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
        End If
    End If
End Sub
Private Sub updatezswebservice()
    'ACTUALIZAÇÃO ZSRESTWEBSERVICE
    Dim file = file4
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filebackup)
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        Else
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        End If
        My.Computer.Network.DownloadFile(fileremote, filelocal)
        MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            My.Computer.Network.DownloadFile(fileremote, filelocal)
            MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
        End If
    End If
End Sub
Private Sub updatezspda()
    'ACTUALIZAÇÃO ZSPDA
    Dim file = file5
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filebackup)
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        Else
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        End If
        My.Computer.Network.DownloadFile(fileremote, filelocal)
        MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            My.Computer.Network.DownloadFile(fileremote, filelocal)
            MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
        End If
    End If
End Sub
Private Sub updatesafpt()
    'ACTUALIZAÇÃO APLICAÇÃO
    Dim file = file6
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filebackup)
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        Else
            My.Computer.FileSystem.MoveFile(filelocal, filebackup)
        End If
        My.Computer.Network.DownloadFile(fileremote, filelocal)
        MessageBox.Show(file & updatedlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(errorlocalfile & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            My.Computer.Network.DownloadFile(fileremote, filelocal)
            MessageBox.Show(file & instaledlocalfile, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
        End If
    End If
End Sub
Private Sub restorezsrest()
    'Restauro APLICAÇÃO
    Dim file = file1
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filelocal)
            My.Computer.FileSystem.CopyFile(filebackup, filelocal)
            MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            If My.Computer.FileSystem.FileExists(filebackup) Then
                My.Computer.FileSystem.CopyFile(filebackup, filelocal)
                MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Else
        End If
    End If
End Sub
Private Sub restorezsrestservice()
    'Restauro APLICAÇÃO
    Dim file = file2
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filelocal)
            My.Computer.FileSystem.CopyFile(filebackup, filelocal)
            MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            If My.Computer.FileSystem.FileExists(filebackup) Then
                My.Computer.FileSystem.CopyFile(filebackup, filelocal)
                MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Else
        End If
    End If
End Sub
Private Sub restorezsauthservice()
    'Restauro APLICAÇÃO
    Dim file = file3
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filelocal)
            My.Computer.FileSystem.CopyFile(filebackup, filelocal)
            MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            If My.Computer.FileSystem.FileExists(filebackup) Then
                My.Computer.FileSystem.CopyFile(filebackup, filelocal)
                MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Else
        End If
    End If
End Sub
Private Sub restorezswebservice()
    'Restauro APLICAÇÃO
    Dim file = file4
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filelocal)
            My.Computer.FileSystem.CopyFile(filebackup, filelocal)
            MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            If My.Computer.FileSystem.FileExists(filebackup) Then
                My.Computer.FileSystem.CopyFile(filebackup, filelocal)
                MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Else
        End If
    End If
End Sub
Private Sub restorezspda()
    'Restauro APLICAÇÃO
    Dim file = file5
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filelocal)
            My.Computer.FileSystem.CopyFile(filebackup, filelocal)
            MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            If My.Computer.FileSystem.FileExists(filebackup) Then
                My.Computer.FileSystem.CopyFile(filebackup, filelocal)
                MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Else
        End If
    End If
End Sub
Private Sub restoresafpt()
    'Restauro APLICAÇÃO
    Dim file = file6
    Dim filelocal = config.pathlocal & file
    Dim filebackup = config.pathbackups & datadia & "\" & file
    Dim fileremote = config.pathremote & file
    If My.Computer.FileSystem.FileExists(filelocal) Then
        If My.Computer.FileSystem.FileExists(filebackup) Then
            My.Computer.FileSystem.DeleteFile(filelocal)
            My.Computer.FileSystem.CopyFile(filebackup, filelocal)
            MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    Else
        Dim confirma As DialogResult
        confirma = MessageBox.Show(nolocalrestore & file, "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If confirma = Windows.Forms.DialogResult.Yes Then
            If My.Computer.FileSystem.FileExists(filebackup) Then
                My.Computer.FileSystem.CopyFile(filebackup, filelocal)
                MessageBox.Show(file & restoredsucess, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show(nobackuprestore & file, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Else
        End If
    End If
End Sub
Public Sub Stopservicezssync()
    Dim service As ServiceController = New ServiceController("ZsyncSrv")
    If ((service.Status.Equals(ServiceControllerStatus.Running))) Then
        Try
            service.Stop()
        Catch ex As Exception
            MessageBox.Show("Não foi possivel parar o ZSyncServer...", "!!!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
        End Try
    Else
    End If
End Sub
Public Sub Stopservicezsauth()
    Dim service As ServiceController = New ServiceController("ZAuthSrv")
    If ((service.Status.Equals(ServiceControllerStatus.Running))) Then
        Try
            service.Stop()
        Catch ex As Exception
            MessageBox.Show("Não foi possivel parar o ZAuthServer...", "!!!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
        End Try
    Else
    End If
End Sub
Public Sub Startservicezssync()
    Dim service As ServiceController = New ServiceController("ZsyncSrv")
    If ((service.Status.Equals(ServiceControllerStatus.Stopped))) Then
        Try
            service.Start()
        Catch ex As Exception
            MessageBox.Show("Não foi possivel iniciar o ZSyncServer...", "!!!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
        End Try
    Else
    End If
End Sub
Public Sub Startservicezsauth()
    Dim service As ServiceController = New ServiceController("ZAuthSrv")
    If ((service.Status.Equals(ServiceControllerStatus.Stopped))) Then
        Try
            service.Start()
        Catch ex As Exception
            MessageBox.Show("Não foi possivel iniciar o ZAuthServer...", "!!!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
        End Try
    Else
    End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    zsservicos.Show()
End Sub
End Class
Edited by thoga31
GeSHi
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.