Well, I recently got a program from csharp . But im not familiar with c# . I only got codes from vb.net . Is it possible if you guys help me to translate these following codes to C# ?
First set of codes, it will download the file from the page wroted[with replacing if there is a file with the same name existed]
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblProgress.Text = String.Empty
txtURL.Text = URL_MESSAGE
txtDownloadTo.Text = DIR_MESSAGE
cmdGetFolder.Focus()
txtURL.Hide()
Show()
Timer2.Start()
cmdDownload.Enabled = False
cmdDownload.Enabled = False
cmdClose.Enabled = False
'DO THE DOWNLOAD
Try
_Downloader = New WebFileDownloader
_Downloader.DownloadFileWithProgress(txtURL.Text, ("") & filename)
Catch ex As Exception
MessageBox.Show("ERROR: " & ex.Message)
cmdClose.Enabled = True
cmdDownload.Enabled = True
End Try
End Sub
'returns all text from last "/" in URL, but puts a "\" in front of the file name..
Private Function GetFileNameFromURL(ByVal URL As String) As String
If URL.IndexOf("/"c) = -1 Then Return String.Empty
Return "\" & URL.Substring(URL.LastIndexOf("/"c) + 1)
End Function
'GET A FOLDER TO DOWNLOAD THE FILE TO
Private Sub cmdGetFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetFolder.Click
If dlgFolderBrowse.ShowDialog(Me) <> DialogResult.Cancel Then
txtDownloadTo.Text = dlgFolderBrowse.SelectedPath
End If
End Sub
'FIRES WHEN WE HAVE GOTTEN THE DOWNLOAD SIZE, SO WE KNOW WHAT BOUNDS TO GIVE THE PROGRESS BAR
Private Sub _Downloader_FileDownloadSizeObtained(ByVal iFileSize As Long) Handles _Downloader.FileDownloadSizeObtained
ProgBar.Value = 0
ProgBar.Maximum = Convert.ToInt32(iFileSize)
End Sub
'FIRES WHEN DOWNLOAD IS COMPLETE
Private Sub _Downloader_FileDownloadComplete() Handles _Downloader.FileDownloadComplete
ProgBar.Value = ProgBar.Maximum
My.Settings.Save()
'download.Show()
yourlogo.Close()
Process.Start(filename)
cmdClose.Text = "Close"
cmdClose.Enabled = True
ProgBar.Value = ProgBar.Minimum
lblProgress.Text = String.Empty
End Sub
'FIRES WHEN DOWNLOAD FAILES. PASSES IN EXCEPTION INFO
Private Sub _Downloader_FileDownloadFailed(ByVal ex As System.Exception) Handles _Downloader.FileDownloadFailed
MessageBox.Show("Error: " & ex.Message)
cmdClose.Enabled = True
cmdDownload.Enabled = True
End Sub
'FIRES WHEN MORE OF THE FILE HAS BEEN DOWNLOADED
Private Sub _Downloader_AmountDownloadedChanged(ByVal iNewProgress As Long) Handles _Downloader.AmountDownloadedChanged
ProgBar.Value = Convert.ToInt32(iNewProgress)
lblProgress.Text = WebFileDownloader.FormatFileSize(iNewProgress) & " of " & WebFileDownloader.FormatFileSize(ProgBar.Maximum) & " Downloaded."
Application.DoEvents()
End Sub
Here is second set of code. I'd like to convert it to c# too .
This set of code will detects if the file version is the same , if it does not match , it will goto patcher form or else it will continue the application.
Private Sub CheckUpdata(ByVal url As String)
WebClient1.DownloadFileAsync(New Uri(url), "updateinfo.ver")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
yourlogo.Show()
CheckUpdata("http://127.0.0.1/updateinfo.txt")
End Sub
Private Sub WebClient1_DownloadFileCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WebClient1.DownloadFileCompleted
ProgressBar1.Value = ProgressBar1.Maximum
Dim version As New TextBox
version.Text = My.Computer.FileSystem.ReadAllText("updateinfo.ver")
Label2.Text = version.Text
Dim new_ver As Double = version.Text
Dim cur_ver As Double = Application.ProductVersion
If new_ver > cur_ver Then
On Error Resume Next
If My.Computer.FileSystem.FileExists("updateinfo.ver") Then
My.Computer.FileSystem.DeleteFile("updateinfo.ver")
End If
MsgBox("New version detected!", MsgBoxStyle.Information, "Updater")
frmDLMain.Show()
Me.Close()
Else
If My.Computer.FileSystem.FileExists("updateinfo.ver") Then
My.Computer.FileSystem.DeleteFile("updateinfo.ver")
End If
yourlogo.Close()
yourapp.Show()
Me.Close()
End If
End Sub
The last set of codes.
This code bascially detects if a file is existed in the same directory and if it does not , it will download from a webpage.
If My.Computer.FileSystem.FileExists("Patcher.exe") Then
frmMain.show()
Else
[download the file from webpage, which the code above, the first set of codes, so you don't need to convert again.]
End If
I will really apreciate it if you guys are willing to help me . I am seriously sick of this thing ..
Thanks in advance.