Ok, I've been working on this project like 1 and a half week, now this super strange **** came out. Im tired and desperate.
So, I will try to explain you what I want to do. I have 2 programs, Updater and main one. I want Main program to download Version.txt (It does) and check if it is the same as its current version and if it is not, It will start the updater.
But theres the problem. If I do it in Debug, it's ok, because it says "You are up to date" what it in this case should, then I "Build" it and copy to my desktop, and guess what happens, It updates it self infinite times, even that it is Up To Date!
The Code for Main application:
The code for Updater:
I'm working on installer too, but till I dont fix this, I won't make it. I said this because in some cases you see there custom folders and stuff, It will get downloaded and created by the future installer.
Sorry If I just missed some obvious bug, but im really tired...
So, I will try to explain you what I want to do. I have 2 programs, Updater and main one. I want Main program to download Version.txt (It does) and check if it is the same as its current version and if it is not, It will start the updater.
But theres the problem. If I do it in Debug, it's ok, because it says "You are up to date" what it in this case should, then I "Build" it and copy to my desktop, and guess what happens, It updates it self infinite times, even that it is Up To Date!
The Code for Main application:
Code:
Imports IWshRuntimeLibrary
Public Class UpdateManager
Dim UserName As String = Environment.UserName
Dim UpdateAvialable As Boolean = False
Dim WebClient As New Net.WebClient
Dim Path As String = "C:\Users\" & UserName & "\AppData\Roaming\AppHolder"
Dim OldPath As String = Path & "\Updating\PathToProgram.txt"
Private Sub UpdateMe()
ProgressbarTick.Enabled = True
Dim NewVersion As String
If My.Computer.FileSystem.FileExists(Path & "/Updating/Version.txt") Then
My.Computer.FileSystem.DeleteFile(Path & "/Updating/Version.txt")
End If
WebClient.DownloadFile("https://dl.dropbox.com/u/149098029/App%20Holder/Updating/Version.txt", Path & "\Updating\Version.txt")
Dim StreamReader As IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(Path & "\Updating\Version.txt")
NewVersion = StreamReader.ReadToEnd
StreamReader.Close()
If NewVersion = My.Settings.CurrentVersion Then
My.Settings.CurrentVersion = NewVersion
My.Settings.Save()
If My.Computer.FileSystem.FileExists(OldPath) Then
My.Computer.FileSystem.DeleteFile(OldPath)
End If
Dim StreamWriter As System.IO.StreamWriter
Dim CurrentPath As String = Application.ExecutablePath
StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(OldPath, True)
StreamWriter.Write(CurrentPath)
StreamWriter.Close()
UpdateAvialable = True
End If
End Sub
Private Sub ProgressbarTick_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressbarTick.Tick
If PBar.Value <> 100 Then
PBar.Increment(1)
ElseIf PBar.Value = 100 And UpdateAvialable = True Then
Process.Start(Path & "\Updating\Updater")
Form1.Close()
StartUpSettings.Close()
Edit_Web_Page.Close()
Me.Close()
Else
ProgressbarTick.Enabled = False
MsgBox("You are Up to Date!", MsgBoxStyle.Information, "Updater")
Me.Hide()
Form1.ShowDialog()
End If
End Sub
Private Sub UpdateManager_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Settings.AutoUpdate = True Then
UpdateMe()
Else
Form1.ShowDialog()
End If
End Sub
End ClassThe code for Updater:
Code:
Imports IWshRuntimeLibrary
Public Class Form1
Dim UserName As String = Environment.UserName
Dim WebClient As New Net.WebClient
Dim Path As String = "C:\Users\" & UserName & "\AppData\Roaming\AppHolder\Updating\New Version.exe"
Dim ShortcutDirectory As String = "C:\Users\" & UserName & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
Dim OldPath As String = "C:\Users\" & UserName & "\AppData\Roaming\AppHolder\Updating\PathToProgram.txt"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim StreamReader As System.IO.StreamReader = New System.IO.StreamReader(OldPath)
OldPath = StreamReader.ReadToEnd
BtnFinish.Enabled = False
ProgressBarTimer.Enabled = True
End Sub
Private Sub ProgressBarTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBarTimer.Tick
If ProgressBar1.Value = 20 Then
Label1.Location = New Point(125, 9)
Label1.Text = "Downloading New Version..."
DownloadNewVersion()
BtnCancel.Enabled = False
ElseIf ProgressBar1.Value = 50 Then
Label1.Location = New Point(134, 9)
Label1.Text = "Removing Old Version..."
DeleteOldVersion()
ElseIf ProgressBar1.Value = 78 Then
Label1.Location = New Point(123, 9)
Label1.Text = "Creating ShortCut in StartUp..."
CreateShortCut(OldPath)
ElseIf ProgressBar1.Value = 100 Then
BtnFinish.Enabled = True
End If
ProgressBar1.Increment(1)
End Sub
Public Sub DownloadNewVersion()
WebClient.DownloadFile("https://dl.dropbox.com/u/149098029/App%20Holder/Updating/New%20Version.exe", Path)
End Sub
Private Sub DeleteOldVersion()
Try
My.Computer.FileSystem.DeleteFile(OldPath)
My.Computer.FileSystem.MoveFile(Path, OldPath)
Catch Exception As Exception
Me.Close()
End Try
End Sub
Private Sub CreateShortCut(ByVal FilePath As String)
Try
Dim Shortcut As IWshShortcut
Dim Wsh As New WshShell
Shortcut = CType(Wsh.CreateShortcut(ShortcutDirectory & "Application Holder.lnk"), IWshShortcut)
With Shortcut
.TargetPath = FilePath
.IconLocation = FilePath & ", 0"
.Save()
End With
Catch Excep As Exception
Me.Close()
End Try
End Sub
Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
End
End Sub
Private Sub BtnFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFinish.Click
Me.Close()
Process.Start(OldPath)
End Sub
End ClassSorry If I just missed some obvious bug, but im really tired...