NewUpdater.vb 4.8 KB
Newer Older
leaky114's avatar
leaky114 已提交
1 2 3
Imports FSLib.App.SimpleUpdater
Module NewUpdater

leaky114's avatar
leaky114 已提交
4 5 6
    Const InNewVisonTXT As String = "\\Likai-pc\发行版\2011\NewVersion.txt"
    Const GitWeb As String = "https://codechina.csdn.net/leaky114/inventoraddin"

7
    Public Sub UpDate1()
leaky114's avatar
leaky114 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
        Try

            '  Updater.CheckUpdateSimple("\\likai-pc\发行版\更新包\{0}", "update.xml")

            Dim UpdaterInstance = FSLib.App.SimpleUpdater.Updater.CreateUpdaterInstance()

            With UpdaterInstance.Context
                .UpdateDownloadUrl = "\\likai-pc\发行版\更新包\{0}"   '获得或设置用于更新的模板地址
                .UpdateInfoFileName = "update.xml"                      '获得或设置更新时使用的 XML 文件名

                .MultipleDownloadCount = 5                      '获得或设置同时下载的文件数,默认为 3

            End With

            '开始更新

            UpdaterInstance.BeginCheckUpdateInProcess()

            UpdaterInstance.Dispose()

        Catch ex As Exception
leaky114's avatar
leaky114 已提交
29

leaky114's avatar
leaky114 已提交
30
            'MsgBox(ex.Message)
leaky114's avatar
leaky114 已提交
31

leaky114's avatar
leaky114 已提交
32 33 34
        End Try
    End Sub

35
    Public Sub UpDate2(ByVal IsPutOutMsg As Boolean)
leaky114's avatar
leaky114 已提交
36 37 38
        Try

            Dim fileReader As System.IO.StreamReader
leaky114's avatar
leaky114 已提交
39
            fileReader = My.Computer.FileSystem.OpenTextFileReader(InNewVisonTXT)
leaky114's avatar
leaky114 已提交
40 41
            Dim NewVersion As String
            NewVersion = fileReader.ReadLine()
leaky114's avatar
leaky114 已提交
42
            fileReader.Close()
leaky114's avatar
leaky114 已提交
43 44 45 46 47
            'MsgBox(NewVersion)

            Dim MyVersion As String = _
            My.Application.Info.Version.Major & "." & _
            My.Application.Info.Version.Minor & "." & _
leaky114's avatar
leaky114 已提交
48 49
            Format(My.Application.Info.Version.Build, "00") & "." & _
           Format(My.Application.Info.Version.Revision, "00")
leaky114's avatar
leaky114 已提交
50 51 52

            'MsgBox(MyVersion)

leaky114's avatar
leaky114 已提交
53
            If NewVersion <> "" Then
leaky114's avatar
leaky114 已提交
54 55 56 57 58 59 60 61
                Dim shortMyversion As Long
                Dim shortNewVersion As Long

                shortMyversion = ShortVersion(MyVersion)
                shortNewVersion = ShortVersion(NewVersion)

                If shortNewVersion > shortMyversion Then
                    MsgBox("InventorAddIn插件" & vbCrLf & "当前版本:" & MyVersion & vbCrLf & "检查到 新版本:" & NewVersion, MsgBoxStyle.OkOnly, " 检查更新")
leaky114's avatar
leaky114 已提交
62

leaky114's avatar
leaky114 已提交
63 64
                    Dim simupdate As String

leaky114's avatar
leaky114 已提交
65
                    simupdate = My.Application.Info.DirectoryPath & "\simupdater.exe"
leaky114's avatar
leaky114 已提交
66
                    If IsFileExsts(simupdate) = True Then
leaky114's avatar
22.2.25  
leaky114 已提交
67 68


leaky114's avatar
leaky114 已提交
69 70 71 72 73
                        Process.Start(simupdate)
                    Else
                        MsgBox("缺失升级程序 simupdater.exe,请到本软件仓库下载。", MsgBoxStyle.OkOnly, "检查更新")
                        Process.Start(GitWeb)
                    End If
leaky114's avatar
leaky114 已提交
74 75 76 77
                Else
                    If IsPutOutMsg = True Then
                        MsgBox("当前是最新版本。", MsgBoxStyle.OkOnly, "检查更新")
                    End If
leaky114's avatar
leaky114 已提交
78 79 80
                End If
            End If
        Catch ex As Exception
leaky114's avatar
leaky114 已提交
81
            'MsgBox(ex.Message)
leaky114's avatar
22.2.25  
leaky114 已提交
82
            'MsgBox("未链接到服务器。", MsgBoxStyle.OkOnly, "检查更新")
leaky114's avatar
leaky114 已提交
83 84 85 86 87 88 89 90 91 92
        End Try
    End Sub

    Public Function ShortVersion(ByVal LongVesion As String) As Long

        ShortVersion = Val(Strings.Replace(LongVesion, ".", ""))

        Return ShortVersion
    End Function

leaky114's avatar
leaky114 已提交
93
    Public Function CreateUpdate() As Boolean
94
        Try
leaky114's avatar
leaky114 已提交
95 96 97 98 99

            Dim path As String = My.Application.Info.DirectoryPath & "\simupdater.exe" '文件释放路径
            Dim resources As System.Resources.ResourceManager = My.Resources.ResourceManager
            Dim b() As Byte = resources.GetObject("simupdater")
            Dim s As IO.Stream
100 101 102
            s = IO.File.Create(path)
            s.Write(b, 0, b.Length)
            s.Close()
leaky114's avatar
leaky114 已提交
103 104 105 106 107 108 109 110 111 112


            path = My.Application.Info.DirectoryPath & "\SimpleUpdater.dll" '文件释放路径

            b = resources.GetObject("SimpleUpdater")
            s = IO.File.Create(path)
            s.Write(b, 0, b.Length)
            s.Close()


113 114 115 116 117 118 119 120 121
            'MessageBox.Show("资源释放成功")
            Return True
        Catch ex As Exception
            'MessageBox.Show("资源释放失败!Result=" + ex.Message)
        End Try
    End Function

    Public Sub Update3()
        Try
leaky114's avatar
leaky114 已提交
122
            Dim path As String = My.Application.Info.DirectoryPath & "\simupdater.exe '文件释放路径"
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

            Dim DisplayVersion As String
            DisplayVersion = ThisApplication.SoftwareVersion.DisplayVersion

            Dim MyVersion As String = _
                My.Application.Info.Version.Major & "." & _
            My.Application.Info.Version.Minor & "." & _
            Format(My.Application.Info.Version.Build, "00") & "." & _
           Format(My.Application.Info.Version.Revision, "00")

            Dim arguments As String
            arguments = DisplayVersion & " " & MyVersion

            Process.Start(path, arguments)
        Catch ex As Exception

        End Try

    End Sub
leaky114's avatar
21.12.3  
leaky114 已提交
142
End Module