应用程序更新检查问题 [英] Application updates check issue

查看:23
本文介绍了应用程序更新检查问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种方法让我的用户知道是否存在更新.我想要做的是将我的用户连接到我的 Dropbox 并获取当前从中更新版本.

i'm trying to find a way to let my users find out if an update exist. what i'm trying to do is to connect my user to my Dropbox an get the current update version from it.

这是我的代码(这不是我的......)

here is my code (wich is not really mine...)

 Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(" https://www.dropbox.com/s/MyDropBox/Version.txt?dl=0")
    Dim response As System.Net.HttpWebResponse = request.GetResponse()
    Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
    Dim newestversion As String = sr.ReadToEnd()
    Dim currentversion As String = Application.ProductVersion

    If newestversion.Contains(currentversion) Then
        MsgBox("You are up todate!")
    Else
        MsgBox("You are not up todate!")
    End If

我的问题是,无论我收到什么消息你不是最新的!".

My problam is that no matter what i'm getting the msg "You are not up todate!".

谁能告诉我为什么?

顺便说一句,在将我的问题发布到MyDropbox"之前,我更改了我的保管箱地址

BTW the address to my dropbox changed by me before publishing my question to "MyDropbox"

推荐答案

你的代码不合适的原因是 :

  • 过程太长
  • 它返回太多的文本
  • 您没有使用正确的 Dropbox 类型链接
  • 而且显然,返回的文本不包含您想要的文本(文件内容).
  • The process is too long,
  • It returns too much text for nothing,
  • You don't use the correct Dropbox type of link,
  • And apparently, the returned text doesn't contain the text you want (the file content).

所以,不要使用这种类型的链接:https://www.dropbox.com/s/MyDropBox/Version.txt?dl=0你应该使用这个 :https://dl.dropboxusercontent.com/s/MyDropBox/Version.txt?dl=0显示文件的原始内容.

So, instead of using this type of link : https://www.dropbox.com/s/MyDropBox/Version.txt?dl=0, you should use this one : https://dl.dropboxusercontent.com/s/MyDropBox/Version.txt?dl=0 which display the raw content of the file.

这是我在我的一个软件中使用的代码:

There's the code I'm using in one of my softwares :

它需要一个 BackgroundWorker(要求不要冻结 UI)和一个 Button.

It requires a BackgroundWorker (required to don't freeze the UI) and a Button.

Imports System.Net

Public Class Form1

    Private UpdateLink As String = "https://dl.dropboxusercontent.com/s/5ogqwr9kc31r61w/Update.txt?dl=0"
    Private InstalledVersion As String = Application.ProductVersion
    Private UpToDate As String = "UpToDate"
    Private Outdated As String = "Outdated"
    Private LatestVersion As String
    Private MAJ As New WebClient

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        BackgroundWorker1.RunWorkerAsync()
        Button1.Enabled = False
    End Sub

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Try
            'Original link is https://www.dropbox.com/s/5ogqwr9kc31r61w/Update.txt?dl=0
            'But it redirects to the file with Dropbox online interface.
            'If you replace "www.dropbox" by "dl.dropboxusercontent", the new link will redirect to the raw text.
            'New link is https://dl.dropboxusercontent.com/s/5ogqwr9kc31r61w/Update.txt?dl=0

            LatestVersion = MAJ.DownloadString(UpdateLink)

            If LatestVersion.Contains(InstalledVersion) Then
                e.Result = UpToDate
            Else
                e.Result = Outdated
            End If

            MAJ.Dispose()
        Catch ex As Exception
            e.Result = ex.Message
        End Try
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        Button1.Enabled = True

        Select Case e.Result
            Case UpToDate
                MsgBox("It's up to date (Latest : " & LatestVersion & ", Installed : " & InstalledVersion & ")")
            Case Outdated
                MsgBox("It's outdated (Latest : " & LatestVersion & ", Installed : " & InstalledVersion & ")")
            Case Else
                MsgBox(e.Result)
        End Select
    End Sub

End Class

您的 Update.txt 文件只能包含最新版本.

Your Update.txt file can contain only the latest version.

BackgroundWorker 的优点是它不会冻结 UI.因此,在示例中,您可以添加 ProgressBar.

Edit : The advantage with the BackgroundWorker is that it won't freeze the UI. So, in example, you can add a ProgressBar.

改进示例:

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Try
            BackgroundWorker1.ReportProgress(20)
            BackgroundWorker1.ReportProgress(30)

            'Original link is https://www.dropbox.com/s/5ogqwr9kc31r61w/Update.txt?dl=0
            'But it redirects to the file with Dropbox online interface.
            'If you replace "www.dropbox" by "dl.dropboxusercontent", the new link will redirect to the raw text.
            'New link is https://dl.dropboxusercontent.com/s/5ogqwr9kc31r61w/Update.txt?dl=0

            LatestVersion = MAJ.DownloadString(UpdateLink)
            BackgroundWorker1.ReportProgress(60)
            BackgroundWorker1.ReportProgress(80)

            If LatestVersion.Contains(InstalledVersion) Then
                BackgroundWorker1.ReportProgress(100)
                Threading.Thread.Sleep(1000)
                e.Result = UpToDate
            Else
                BackgroundWorker1.ReportProgress(100)
                Threading.Thread.Sleep(1000)
                e.Result = Outdated
            End If

            MAJ.Dispose()
        Catch ex As Exception
            BackgroundWorker1.ReportProgress(100)
            Threading.Thread.Sleep(1000)
            e.Result = ex.Message
        End Try
    End Sub

要更改 ProgressBar 值:

To change the ProgressBar Value :

    Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        ProgressBar1.Value = e.ProgressPercentage
    End Sub

并且您必须将 BackgroundWorker WorkerReportsProgress 属性设置为 True.

And you must set the BackgroundWorker WorkerReportsProgress property to True.

这篇关于应用程序更新检查问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆