我想让这个程序通过每个旧版本进行更新 [英] i want to make this program to get update through each old versions
问题描述
你好,
i我在这里是新的我正在尝试制作一个自动更新程序我已经完成了一些部分,但我被困在程序的大部分。
i希望让这个程序通过每个旧版本得到更新。比如,如果启动器版本是1.0,最新版本是3.0,那么它应该从2.0更新,然后从3.0获取更新是否可能?
谢谢
这里是我的代码
Hello,
i am new here i am trying to make an auto updater i have finished some parts but i am stuck at big part of program.
i want to make this program to get update through each old versions..like if launcher version is 1.0 and latest version is 3.0 so it should take update from 2.0 then take update from 3.0 is it possible?
thank you
here is my code
Imports System
Imports System.IO
Imports System.Net
Public Class Form1
Dim File = Application.StartupPath + "\launcher"
Dim Section3 = "AutoUpdate"
Dim AutoUpdateFunction = "AutoUpdateFunction"
Dim Version = "Version"
Dim Status = "Status"
Dim Section4 = "Version"
Dim Ver = "ver"
Dim WithEvents WC As New WebClient
Private WithEvents httpclient As WebClient
Dim imageAddress As String = String.Empty
Dim filename As String = String.Empty
Dim Check As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
persent.Text = ""
End Sub
Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles httpclient.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub dpc(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles httpclient.DownloadProgressChanged
persent.Text = e.ProgressPercentage
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If ReadIni(File, Section3, AutoUpdateFunction, "") = "on" Then
Try
Dim web As New WebClient()
Update.Text = "Checking for Update!"
Dim response = web.DownloadString("http://107.170.123.131/ver.txt")
Dim check = (ReadIni(File, Section4, Ver, "ver"))
If check = response Then
Button3.Enabled = True
Update.Text = "Game Updated"
Else
httpclient = New WebClient
imageAddress = "http://www.wratho.net/patch_31.dat.zip"
filename = imageAddress.Substring(imageAddress.LastIndexOf("/") + 1)
AddHandler httpclient.DownloadFileCompleted, AddressOf Downloaded
Try
httpclient.DownloadFileAsync(New Uri(imageAddress), (filename))
Update.Text = "Updating!"
Catch ex As HttpListenerException
MsgBox("SH*T!!!!!!")
Catch ex As Exception
Update.Text = "No Response From Server"
End Try
End If
Catch ex As HttpListenerException
MsgBox("Error accessing " + imageAddress + " - " + ex.Message)
Catch ex As Exception
MsgBox("No Response From Server")
End Try
Else
End If
End Sub
Private Sub Downloaded()
If System.IO.File.Exists(filename) = True Then
Button3.Enabled = "True"
Update.Text = "Updates are done!"
Else
MsgBox("Doesn't exist", 64, "Open")
End If
End Sub
End Class
Module modINI
Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Int32, _
ByVal lpFileName As String) As Int32
Public Function ReadIni(ByVal IniFileName As String, ByVal Section As String, ByVal ParamName As String, ByVal ParamDefault As String) As String
Dim ParamVal As String = Space$(1024)
Dim LenParamVal As Long = GetPrivateProfileString(Section, ParamName, ParamDefault, ParamVal, Len(ParamVal), IniFileName)
ReadIni = Left$(ParamVal, LenParamVal)
End Function
End Module
这里是我链接更新程序的文件
and here is file that i link for updater
Auto Updater v1.0
[Settings]
Title=Auto Updater
[Website]
Notice=News link
Register=Register page link
[AutoUpdate]
AutoUpdateFunction=on
Status="Version link" (IMPORTANT)'i used this link <a href="http://107.170.123.131:80/ver.txt">http://107.170.123.131:80/ver.txt</a>
[Version]
Ver=1.0
推荐答案
( 1024 )
Dim LenParamVal As Long = GetPrivateProfileString(Section,ParamName,ParamDefault,ParamVal,Len(ParamVal),IniFileName)
ReadIni = Left
(1024) Dim LenParamVal As Long = GetPrivateProfileString(Section, ParamName, ParamDefault, ParamVal, Len(ParamVal), IniFileName) ReadIni = Left
(ParamVal,LenParamVal)
结束 功能
结束 模块
(ParamVal, LenParamVal) End Function End Module
这里是我链接更新程序的文件
and here is file that i link for updater
Auto Updater v1.0
[Settings]
Title=Auto Updater
[Website]
Notice=News link
Register=Register page link
[AutoUpdate]
AutoUpdateFunction=on
Status="Version link" (IMPORTANT)'i used this link <a href="http://107.170.123.131:80/ver.txt">http://107.170.123.131:80/ver.txt</a>
[Version]
Ver=1.0
创建一个间接级别。
现在,您有v.1,v.2,v.3.0,v3.1等的单独URL。难怪,您不能保证您的应用程序可以找到最新的URL,或者除了应用程序附带的更新之外的任何其他URL。这个问题以一种非常简单的方式解决。
再添加一个URL,一个固定的,你永远不会修改它。在此URL处,您应该放置一些文件,该文件为您提供最新更新的URL,或者,如果您希望应用程序从一组更新中进行选择,则可以放置所有更新的所有URL。最好的方法是将此信息放在某个XML文件中。例如:
Create one level of indirection.
Right now, you have separate URLs for v.1, v.2, v.3.0, v3.1, etc. No wonder, you cannot guarantee that your application can find the latest URL, or any other URL with the update except the one which comes with your application. This problems is solved in a really simple way.
Add one more URL, a fixed one, which you never modify. At this URL you should place some file which gives you the URL of the latest update or, if you want your application to choose from a set of updates, all the URLs of all the updates. The best way to do so would be put this information in some XML file. For example:
<?xml version="1.0"?>
<MyApplicationUpdates>
<versions>
<version verisionid="1" url="http://www.mySite.net/myApplication/updates/v.1" />
<version verisionid="2.0" url="http://www.mySite.net/myApplication/updates/v.2.0" />
<version verisionid="3.0" url="http://www.mySite.net/myApplication/updates/v.3.0" />
<version verisionid="3.1" url="http://www.mySite.net/myApplication/updates/v.3.1" />
</versions>
<!-- whatever else you may need need -->
</MyApplicationUpdates>
如您所见,版本和各个URL的格式可能不同,但您的XML文件将提供所有信息。它可以是具有相同信息的任何其他类型的文件,但XML是最方便的;它是标准化的;和.NET FCL提供了不同的类来解析它。
现在,发布更新的过程将是这样的:首先,你开发一个新版本的产品新版本的装配(组件)并放在您的网站上。如果此时有人从您的应用程序启动更新,则XML仍将提供用户可访问的最新版本。然后,您需要通过向其添加一个< version>
元素来更新XML。然后您的应用程序将获得它:它将首先访问XML,解析它,找到最新版本,然后使用从XML获得的URL下载所需的产品版本。
As you can see, the format of versions and respective URLs can be different, but your XML file would provide all the information. It can be any other kind of file with the same information, but XML is the most convenient; it is standardized; and .NET FCL provides different classes to parse it.
Now, the procedure for publishing updates will be this: first, you develop a new version of the product under the new version of its assembly (assemblies) and put on your site. If at this moment someone initiate update from your application, the XML will still provide the previous version as the latest accessible to the user. Then you need to update the XML by adding one <version>
element to it. Then your application will get it: it will first access XML, parse it, find the latest version and then will download the required version of the product using URL obtained from your XML.
这篇关于我想让这个程序通过每个旧版本进行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!