SolvedUpdater

Posts 1–15 of 21 · Page 1 of 2
Updater
Not for publishing just learning ....

I want to create an updater without the internet opening to download.... and If I can, can I make it save to desktop automatically

Thanks
Quote Originally Posted by NucleaR View Post
Not for publishing just learning ....

I want to create an updater without the internet opening to download.... and If I can, can I make it save to desktop automatically

Thanks
What do you mean without the internet opening? You must only have the connection.
Perchance do you open the download with the browser? btw. You can use the constructor WebRequest and let return a response from the resource.
Quote Originally Posted by Raydenman View Post
What do you mean without the internet opening? You must only have the connection.
Perchance do you open the download with the browser? btw. You can use the constructor WebRequest and let return a response from the resource.
I mean when I want to update my program it opens the internet browser but I don't want it like that, If you understand could you help
Quote Originally Posted by NucleaR View Post
I mean when I want to update my program it opens the internet browser but I don't want it like that, If you understand could you help
Using WebRequest.DownloadFile should cover it all.
Quote Originally Posted by Mayion View Post


Using WebRequest.DownloadFile should cover it all.
The routine DownloadFile doesn't exists in the class WebRequest

Anyway, @NucleaR I already said you what you should do, what stops you? Try it and let me know
Quote Originally Posted by Raydenman View Post
The routine DownloadFile doesn't exists in the class WebRequest
Meant WebClient, my bad.
thank you guys

- - - Updated - - -

What do you mean? I put webclient.downloadfile but that's not a code its an error lol @Mayion
Quote Originally Posted by NucleaR View Post
thank you guys

- - - Updated - - -

What do you mean? I put webclient.downloadfile but that's not a code its an error lol @Mayion
Code:
Dim WC As New WebClient()
WC.DownloadFile("FileLink", "Path")
Don't remember exactly but it should work.
How can I make it search for desktop and save their automatically? @Mayion
Try this.
2x Button (DownloadButton, CancelButton)
1x ProgressBar (DownloadProgressBar)

Code:
Imports System.Net
Public Class MainForm
    Private WithEvents httpClient As WebClient

    Dim DesktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
    Dim CurrentURL As String
    Dim FileName As String
    Dim FileFormat As String

    Private Sub DeletePermanently()
        My.Computer.FileSystem.DeleteFile(DesktopPath & "\" & FileName + FileFormat,
        Microsoft.VisualBasic.FileIO.RecycleOption.DeletePermanently,
        Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)
    End Sub

    Private Sub DownloadButton_Click(sender As Object, e As EventArgs) Handles DownloadButton.Click
        'CurrentURL = "URL.de/Download/ImageName.jpg" : FileName = "ImageName" : CurrentFormat = ".jpg"
        httpClient.DownloadFileAsync(New Uri(CurrentURL), DesktopPath & "\" & FileName + FileFormat)
        '= ...Desktop\ImageName.jpg
        'Download File with Format from URL
    End Sub

    Private Sub CancelButton_Click(sender As Object, e As EventArgs) Handles CancelButton.Click
        httpClient.CancelAsync() 'Cancel the Download
        DeletePermanently() 'Delete the faulty file.
    End Sub

    Private Sub httpClient_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) _
    Handles httpClient.DownloadProgressChanged
        DownloadProgressBar.Value = e.ProgressPercentage
        Dim Bytes As Double = e.BytesReceived / 1000
        Dim TotalBytes As Double = e.TotalBytesToReceive / 1000
        StatusLabel.Text = _
        """" & FileName + FileFormat & """" & " is downloaded..." & vbNewLine & Bytes & " KB / " & TotalBytes & " KB"
        '= "ImageName.jpg" is downloaded... 300 KB / 900 KB
        End If
    End Sub

End Class
I'm not Sure, but this must works.
Quote Originally Posted by ISD View Post
2x Button (DownloadButton, CancelButton)
1x ProgressBar (DownloadProgressBar)

Code:
Imports System.Net
Public Class MainForm
    Private WithEvents httpClient As WebClient

    Dim DesktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
    Dim CurrentURL As String
    Dim FileName As String
    Dim FileFormat As String

    Private Sub DeletePermanently()
        My.Computer.FileSystem.DeleteFile(DesktopPath & "\" & FileName + FileFormat,
        Microsoft.VisualBasic.FileIO.RecycleOption.DeletePermanently,
        Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)
    End Sub

    Private Sub DownloadButton_Click(sender As Object, e As EventArgs) Handles DownloadButton.Click
        'CurrentURL = "URL.de/Download/ImageName.jpg" : FileName = "ImageName" : CurrentFormat = ".jpg"
        httpClient.DownloadFileAsync(New Uri(CurrentURL), DesktopPath & "\" & FileName + FileFormat)
        '= ...Desktop\ImageName.jpg
        'Download File with Format from URL
    End Sub

    Private Sub CancelButton_Click(sender As Object, e As EventArgs) Handles CancelButton.Click
        httpClient.CancelAsync() 'Cancel the Download
        DeletePermanently() 'Delete the faulty file.
    End Sub

    Private Sub httpClient_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) _
    Handles httpClient.DownloadProgressChanged
        DownloadProgressBar.Value = e.ProgressPercentage
        Dim Bytes As Double = e.BytesReceived / 1000
        Dim TotalBytes As Double = e.TotalBytesToReceive / 1000
        StatusLabel.Text = _
        """" & FileName + FileFormat & """" & " is downloaded..." & vbNewLine & Bytes & " KB / " & TotalBytes & " KB"
        '= "ImageName.jpg" is downloaded... 300 KB / 900 KB
        End If
    End Sub

End Class
I'm not Sure, but this must works.
Ok, Looks like it works. Ill test it after work
Quote Originally Posted by ISD View Post
2x Button (DownloadButton, CancelButton)
1x ProgressBar (DownloadProgressBar)

Code:
Imports System.Net
Public Class MainForm
    Private WithEvents httpClient As WebClient

    Dim DesktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
    Dim CurrentURL As String
    Dim FileName As String
    Dim FileFormat As String

    Private Sub DeletePermanently()
        My.Computer.FileSystem.DeleteFile(DesktopPath & "\" & FileName + FileFormat,
        Microsoft.VisualBasic.FileIO.RecycleOption.DeletePermanently,
        Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing)
    End Sub

    Private Sub DownloadButton_Click(sender As Object, e As EventArgs) Handles DownloadButton.Click
        'CurrentURL = "URL.de/Download/ImageName.jpg" : FileName = "ImageName" : CurrentFormat = ".jpg"
        httpClient.DownloadFileAsync(New Uri(CurrentURL), DesktopPath & "\" & FileName + FileFormat)
        '= ...Desktop\ImageName.jpg
        'Download File with Format from URL
    End Sub

    Private Sub CancelButton_Click(sender As Object, e As EventArgs) Handles CancelButton.Click
        httpClient.CancelAsync() 'Cancel the Download
        DeletePermanently() 'Delete the faulty file.
    End Sub

    Private Sub httpClient_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) _
    Handles httpClient.DownloadProgressChanged
        DownloadProgressBar.Value = e.ProgressPercentage
        Dim Bytes As Double = e.BytesReceived / 1000
        Dim TotalBytes As Double = e.TotalBytesToReceive / 1000
        StatusLabel.Text = _
        """" & FileName + FileFormat & """" & " is downloaded..." & vbNewLine & Bytes & " KB / " & TotalBytes & " KB"
        '= "ImageName.jpg" is downloaded... 300 KB / 900 KB
        End If
    End Sub

End Class
I'm not Sure, but this must works.
I just have a error at current format and it is stuffed up soo

- - - Updated - - -

This is the screen shot
I don't know why this aint working!!
Try this:
Change the CurrentURL from
/s/4mck5jv0y4x4ss0/MegTool.exe?dl=0 to /s/4mck5jv0y4x4ss0/MegTool.exe?dl=1
You must change the 0 to a 1.
If this not works, write me a private message.
use dl. instead of www. for direct ******* links.

Here is an AutoUpdate class that you can use to make things easier. You need plain text page containing the asm version info ie 1.0.0.0
And you need the direct .exe link (like I said use dl. instead of www. in your ******* link without the extra shit at end of url)

Code:
Imports System.Net
Imports System****

Public Class AutoUpdateClass
    Public Event UpdatePercent(ByVal nCompleted As Integer)
    Public Event DownloadComplete()
    Public Event Status(ByVal sStatus As String)

    Private sVersion As String

    Private VersionURL As String
    Private ApplicationURL As String
    Private PathOldFile As String

    Private _CurrentPath As CurrentPath
    Private Structure CurrentPath
        Dim Path As String
        Dim FileName As String
    End Structure

    Private _TempPath As TempPath
    Private Structure TempPath
        Dim Path As String
        Dim FileName As String
    End Structure

    Public Sub New(ByVal sVersionURL As String, _
                   ByVal sApplicationURL As String, _
                   ByVal sPathOldFile As String)

        VersionURL = sVersionURL
        ApplicationURL = sApplicationURL
        PathOldFile = sPathOldFile

        _CurrentPath.Path = Path.GetDirectoryName(sPathOldFile) & "\"
        _CurrentPath.FileName = Path.GetFileName(sPathOldFile)

    End Sub

    Public Sub Run()
        GetVersion(VersionURL)
    End Sub

    Private Sub GetApplication()
        If Not String.IsNullOrEmpty(sVersion) Then
            If sVersion <> Application.ProductVersion Then
                DownloadApplication(ApplicationURL)
            Else
                RaiseEvent Status("Version: " & Application.ProductVersion)
            End If
        Else
            'TODO: Error while downloading version, do what you want (You can also raise DownloadComplete event and manage it)
        End If
    End Sub

#Region "Get version number"
    Private Sub GetVersion(ByVal sVersionURL As String)
        RaiseEvent Status("Checking for an update...")
        Dim wc As New WebClient
        AddHandler wc.DownloadStringCompleted, AddressOf DownloadStringCompleted
        wc.DownloadStringAsync(New Uri(sVersionURL))
    End Sub

    Private Sub DownloadStringCompleted(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
        If e.Cancelled = False AndAlso e.Error Is Nothing Then
            sVersion = e.Result
            GetApplication()
        Else

        End If
    End Sub
#End Region

#Region "Download updated exe"

    Private Sub DownloadApplication(ByVal sURL As String)
        RaiseEvent Status("Dowloading update...")
        Dim wc As New WebClient
        AddHandler wc.DownloadProgressChanged, AddressOf ProgressChanged
        AddHandler wc.DownloadFileCompleted, AddressOf DownloadCompleted
        _TempPath.Path = Path.GetTempPath
        _TempPath.FileName = _CurrentPath.FileName
        wc.DownloadFileAsync(New Uri(sURL), _TempPath.Path & _TempPath.FileName)
    End Sub

    Private Sub ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
        Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
        Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
        Dim percent As Double = bytesIn / totalBytes * 100
        RaiseEvent UpdatePercent(Int32.Parse(Math.Truncate(percent).ToString()))
    End Sub

    Private Sub DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
        If e.Error Is Nothing Then
            RaiseEvent Status("Update Finished")
            RaiseEvent DownloadComplete()
            GenerateAndRunCMD()
        Else
            'TODO: Error while downloading your new .exe, do what you want (You can also raise DownloadComplete event and manage it)
        End If
    End Sub

#End Region

    Private Sub GenerateAndRunCMD()
        Dim sCMDcommands As New System.Text.StringBuilder
        With sCMDcommands
            .Append("/C """)
            .Append("timeout /t 2 /nobreak > NUL && ")
            .Append("del """ & _CurrentPath.Path & _CurrentPath.FileName & """ && ")
            .Append("move /y """ & _TempPath.Path & _TempPath.FileName & """ """ & _CurrentPath.Path & """ && ")
            .Append(" start """" """ & _CurrentPath.Path & _CurrentPath.FileName & """""")
        End With

        Dim p As Process = New Process()
        Dim pi As ProcessStartInfo = New ProcessStartInfo()
        pi.Arguments = sCMDcommands.ToString
        pi.FileName = "cmd.exe"
        pi.UseShellExecute = False
        pi.CreateNoWindow = True
        p.StartInfo = pi
        p.Start()
        Application.Exit()
    End Sub

End Class
Usage Example
Code:
        Try
            AU = New AutoUpdateClass(URLversiontxt, URLUpdatedApplication, Application.ExecutablePath)
            AU.Run()
        Catch ex As Exception : End Try
Quote Originally Posted by Dab View Post
use dl. instead of www. for direct ******* links.

Here is an AutoUpdate class that you can use to make things easier. You need plain text page containing the asm version info ie 1.0.0.0
And you need the direct .exe link (like I said use dl. instead of www. in your ******* link without the extra shit at end of url)

Code:
Imports System.Net
Imports System****

Public Class AutoUpdateClass
    Public Event UpdatePercent(ByVal nCompleted As Integer)
    Public Event DownloadComplete()
    Public Event Status(ByVal sStatus As String)

    Private sVersion As String

    Private VersionURL As String
    Private ApplicationURL As String
    Private PathOldFile As String

    Private _CurrentPath As CurrentPath
    Private Structure CurrentPath
        Dim Path As String
        Dim FileName As String
    End Structure

    Private _TempPath As TempPath
    Private Structure TempPath
        Dim Path As String
        Dim FileName As String
    End Structure

    Public Sub New(ByVal sVersionURL As String, _
                   ByVal sApplicationURL As String, _
                   ByVal sPathOldFile As String)

        VersionURL = sVersionURL
        ApplicationURL = sApplicationURL
        PathOldFile = sPathOldFile

        _CurrentPath.Path = Path.GetDirectoryName(sPathOldFile) & "\"
        _CurrentPath.FileName = Path.GetFileName(sPathOldFile)

    End Sub

    Public Sub Run()
        GetVersion(VersionURL)
    End Sub

    Private Sub GetApplication()
        If Not String.IsNullOrEmpty(sVersion) Then
            If sVersion <> Application.ProductVersion Then
                DownloadApplication(ApplicationURL)
            Else
                RaiseEvent Status("Version: " & Application.ProductVersion)
            End If
        Else
            'TODO: Error while downloading version, do what you want (You can also raise DownloadComplete event and manage it)
        End If
    End Sub

#Region "Get version number"
    Private Sub GetVersion(ByVal sVersionURL As String)
        RaiseEvent Status("Checking for an update...")
        Dim wc As New WebClient
        AddHandler wc.DownloadStringCompleted, AddressOf DownloadStringCompleted
        wc.DownloadStringAsync(New Uri(sVersionURL))
    End Sub

    Private Sub DownloadStringCompleted(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
        If e.Cancelled = False AndAlso e.Error Is Nothing Then
            sVersion = e.Result
            GetApplication()
        Else

        End If
    End Sub
#End Region

#Region "Download updated exe"

    Private Sub DownloadApplication(ByVal sURL As String)
        RaiseEvent Status("Dowloading update...")
        Dim wc As New WebClient
        AddHandler wc.DownloadProgressChanged, AddressOf ProgressChanged
        AddHandler wc.DownloadFileCompleted, AddressOf DownloadCompleted
        _TempPath.Path = Path.GetTempPath
        _TempPath.FileName = _CurrentPath.FileName
        wc.DownloadFileAsync(New Uri(sURL), _TempPath.Path & _TempPath.FileName)
    End Sub

    Private Sub ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
        Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
        Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
        Dim percent As Double = bytesIn / totalBytes * 100
        RaiseEvent UpdatePercent(Int32.Parse(Math.Truncate(percent).ToString()))
    End Sub

    Private Sub DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
        If e.Error Is Nothing Then
            RaiseEvent Status("Update Finished")
            RaiseEvent DownloadComplete()
            GenerateAndRunCMD()
        Else
            'TODO: Error while downloading your new .exe, do what you want (You can also raise DownloadComplete event and manage it)
        End If
    End Sub

#End Region

    Private Sub GenerateAndRunCMD()
        Dim sCMDcommands As New System.Text.StringBuilder
        With sCMDcommands
            .Append("/C """)
            .Append("timeout /t 2 /nobreak > NUL && ")
            .Append("del """ & _CurrentPath.Path & _CurrentPath.FileName & """ && ")
            .Append("move /y """ & _TempPath.Path & _TempPath.FileName & """ """ & _CurrentPath.Path & """ && ")
            .Append(" start """" """ & _CurrentPath.Path & _CurrentPath.FileName & """""")
        End With

        Dim p As Process = New Process()
        Dim pi As ProcessStartInfo = New ProcessStartInfo()
        pi.Arguments = sCMDcommands.ToString
        pi.FileName = "cmd.exe"
        pi.UseShellExecute = False
        pi.CreateNoWindow = True
        p.StartInfo = pi
        p.Start()
        Application.Exit()
    End Sub

End Class
Usage Example
Code:
        Try
            AU = New AutoUpdateClass(URLversiontxt, URLUpdatedApplication, Application.ExecutablePath)
            AU.Run()
        Catch ex As Exception : End Try
So many errors, anyone else ?
Posts 1–15 of 21 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?