PDA

View Full Version : آموزش: آپدیت کردن برنامه



alimanam
یک شنبه 28 فروردین 1390, 22:05 عصر
با سلام

دوستی در این زمینه سوال داشتن گفتم شاید به درد بقیه دوستان هم بخوره .

توضیحات تکمیلی :

My Application برنامه فرضی شماست ( برنامه اصلی که قراره آپدیت یا همون به روز رسانی بشه )
برنامه updater.exe کار به روز رسانی رو به عهده داره .

نکته :

برای تست برنامه از محیط ویژوال استودیو استفاده نکنین ( کامپایل نکنین )

امیدوارم مفید باشه ...

موفق باشید ./

HAMRAHSOFT.IR
یک شنبه 04 اردیبهشت 1390, 22:36 عصر
من این برنامه دوست خوب به زیان سی شارپ تبدیل کردم ولی اجرا نمیشه مشه دوستان یک تگاهی بهش بکن بگن کجا باید اصلاح کنم

alimanam
یک شنبه 04 اردیبهشت 1390, 23:16 عصر
فکر کنم به خاطر پسوند exe. فایل باشه که سایتی که فایل اونجا آپلود شده بهش ایراد میگیره برای این کار از یه حقه ساده استفاده کن مشکل حل میشه کدها رو اینجوری که تغییر بدی حله :

Imports System.Net
Imports System.Threading
Public Class Form1
''' <summary>
''' Coding by : Ali Dakhilzadeh
''' Updater application
''' \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
''' Date : 2011-17-03
''' For any question about this code contact me by e-mail [ ali.dakhilzadeh@gmail.com ]
''' Enjoy it !!!
''' \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
''' </summary>
''' <remarks></remarks>
Dim whereToSave As String = Application.StartupPath & "\updatedApplication.myfile"
Delegate Sub ChangeTextsSafe(ByVal length As Long, ByVal position As Integer, ByVal percent As Integer, ByVal speed As Double)
Delegate Sub DownloadCompleteSafe(ByVal cancelled As Boolean)
Public Sub ChangeTexts(ByVal length As Long, ByVal position As Integer, ByVal percent As Integer, ByVal speed As Double)
Me.ProgressBar1.Value = percent
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
' theRequest = WebRequest.Create("http://alimanam.persiangig.com/document/updatedApplication.exe")

Try
Dim theResponse As HttpWebResponse
Dim theRequest As HttpWebRequest
Try
theRequest = WebRequest.Create("http://alimanam.persiangig.com/document/updatedApplication.myfile")
theResponse = theRequest.GetResponse
Catch ex As Exception
MessageBox.Show("An error occurred while downloading file. Possibe causes:" & ControlChars.CrLf & _
"1) File doesn't exist" & ControlChars.CrLf & _
"2) Remote server error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete)
Me.Invoke(cancelDelegate, True)
Exit Sub
End Try
Dim length As Long = theResponse.ContentLength
Dim safedelegate As New ChangeTextsSafe(AddressOf ChangeTexts)
Me.Invoke(safedelegate, length, 0, 0, 0)
Dim writeStream As New IO.FileStream(Me.whereToSave, IO.FileMode.Create)
Dim nRead As Integer
Dim speedtimer As New Stopwatch
Dim currentspeed As Double = -1
Dim readings As Integer = 0

Do
If BackgroundWorker1.CancellationPending Then
Exit Do
End If
speedtimer.Start()
Dim readBytes(4095) As Byte
Dim bytesread As Integer = theResponse.GetResponseStream.Read(readBytes, 0, 4096)
nRead += bytesread
Dim percent As Short = (nRead / length) * 100
Me.Invoke(safedelegate, length, nRead, percent, currentspeed)

If bytesread = 0 Then Exit Do
writeStream.Write(readBytes, 0, bytesread)
speedtimer.Stop()
readings += 1

If readings >= 5 Then
currentspeed = 20480 / (speedtimer.ElapsedMilliseconds / 1000)
speedtimer.Reset()
readings = 0
End If
Loop

theResponse.GetResponseStream.Close()
writeStream.Close()

If Me.BackgroundWorker1.CancellationPending Then
IO.File.Delete(Me.whereToSave)
Dim cancelDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete)
Me.Invoke(cancelDelegate, True)
Exit Sub
End If

Dim completeDelegate As New DownloadCompleteSafe(AddressOf DownloadComplete)
Me.Invoke(completeDelegate, False)
Catch ex As Exception
Me.Close()
End Try
End Sub
Public Sub DownloadComplete(ByVal cancelled As Boolean)
Try
If cancelled Then
' har code ke vaseye cancel mikhain einja benevisin
Else
Dim process As Process
For Each process In process.GetProcessesByName("My Application")
process.Kill()
Next
Me.ProgressBar1.Value = 0
Dim stopwatch As Stopwatch = stopwatch.StartNew
Thread.Sleep(1000)
My.Computer.FileSystem.DeleteFile("My Application.exe")
My.Computer.FileSystem.RenameFile("updatedApplication.myfile", "My Application.exe")
process.Start("My Application.exe")
Me.Close()
End If

Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Exclamation)
End Try
End Sub

Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
If My.Computer.FileSystem.FileExists("updatedApplication.myfile") = True Then My.Computer.FileSystem.DeleteFile("updatedApplication.myfile")
BackgroundWorker1.RunWorkerAsync()
End Sub
End Class


موفق باشید ./

barbodsoft.com
دوشنبه 05 اردیبهشت 1390, 09:55 صبح
برای من چیز خاصی انجام نشد. فقط یک صفحه dos می یاد که هر چقدر هم صبر می کنی خبری نیست.

alimanam
دوشنبه 05 اردیبهشت 1390, 10:35 صبح
با سلام

یعنی چی اونوقت ؟!!!!! شما این نمونه کد رو اجرا کن رو سیستمت فکر نکنم مشکلی داشته باشه ! ( برنامه رو کامپایل نکن از فایل اجرایی اجرا کن )

http://up.iranblog.com/images/64p8mbew7kme44ieh1g.gif

موفق باشید ./

barbodsoft.com
دوشنبه 05 اردیبهشت 1390, 12:49 عصر
با سلام

یعنی چی اونوقت ؟!!!!! شما این نمونه کد رو اجرا کن رو سیستمت فکر نکنم مشکلی داشته باشه ! ( برنامه رو کامپایل نکن از فایل اجرایی اجرا کن )

http://up.iranblog.com/images/64p8mbew7kme44ieh1g.gif

موفق باشید ./

همین کار رو کردم. فایل My Application.exe رو اجرا کردم. روی اپدیت کلیک کردم و بعدش صفحه به صورت dos نمایان شد که هیچ نوشته ای هم نداشت.