GeckoFX

  • VB.NET

Es gibt 43 Antworten in diesem Thema. Der letzte Beitrag () ist von Thiemo1991.

    Ich habe glaube ich den Code dafür gefunden aber der eigentlich nur 12 Fehler und 8 Warnungen beinhaltet. Wie kann man aus diesem Code der 22 Fehler aufweist, einen funktionierenden Code machen?

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.ComponentModel
    2. Imports Gecko
    3. Public Class myDownload
    4. Inherits nsIDownload
    5. <Serializable()>
    6. Public Delegate Sub SimpleEventHandler(ByVal sender As Object)
    7. Private _download As nsIDownload
    8. #Region "Events"
    9. Protected Events As EventHandlerList = New EventHandlerList
    10. Private Shared StartEvent As Object = New Object
    11. Private Shared CompleteEvent As Object = New Object
    12. Private Shared FailEvent As Object = New Object
    13. Private Shared ProgressEvent As Object = New Object
    14. #Region "public event DownloadStarted"
    15. <Category("DownloadStarted"),
    16. Description("Occurs before the Download was started.")>
    17. Public Event DownloadStarted As SimpleEventHandler
    18. ''' <summary>Raises the <see cref="DownloadStarted"/> event.</summary>
    19. ''' <param name="e">The data for the event.</param>
    20. Protected Overridable Sub OnDownloadStarted()
    21. Dim evnt = CType(Me.Events(StartEvent), SimpleEventHandler)
    22. If (Not (evnt) Is Nothing) Then
    23. evnt(Me)
    24. End If
    25. End Sub
    26. #End Region
    27. #Region "public event DownloadProgress"
    28. <Category("DownloadProgress"),
    29. Description("Occurs before the Download is progressing.")>
    30. Public Event DownloadProgress As EventHandler(Of GeckoDownloadProgressEventArgs)
    31. ''' <summary>Raises the <see cref="DownloadStarted"/> event.</summary>
    32. ''' <param name="e">The data for the event.</param>
    33. Protected Overridable Sub OnDownloadProgress(ByVal e As GeckoDownloadProgressEventArgs)
    34. Dim evnt = CType(Me.Events(ProgressEvent), EventHandler(Of GeckoDownloadProgressEventArgs))
    35. If (Not (evnt) Is Nothing) Then
    36. evnt(Me, e)
    37. End If
    38. End Sub
    39. #End Region
    40. #Region "public event DownloadComplete"
    41. <Category("DownloadComplete"),
    42. Description("Occurs before the Download was completed.")>
    43. Public Event DownloadComplete As SimpleEventHandler
    44. ''' <summary>Raises the <see cref="DownloadStarted"/> event.</summary>
    45. ''' <param name="e">The data for the event.</param>
    46. Protected Overridable Sub OnDownloadComplete()
    47. Dim evnt = CType(Me.Events(CompleteEvent), SimpleEventHandler)
    48. If (Not (evnt) Is Nothing) Then
    49. evnt(Me)
    50. End If
    51. End Sub
    52. #End Region
    53. #Region "public event DownloadFailed"
    54. <Category("DownloadFailed"),
    55. Description("Occurs before the Download was started.")>
    56. Public Event DownloadFailed As SimpleEventHandler
    57. ''' <summary>Raises the <see cref="DownloadStarted"/> event.</summary>
    58. ''' <param name="e">The data for the event.</param>
    59. Protected Overridable Sub OnDownloadFailed()
    60. Dim evnt = CType(Me.Events(FailEvent), SimpleEventHandler)
    61. If (Not (evnt) Is Nothing) Then
    62. evnt(Me)
    63. End If
    64. End Sub
    65. #End Region
    66. #End Region
    67. Public ID As Long
    68. Public Source As Uri
    69. Public File As String
    70. Public Size As Long
    71. Public Mime As String
    72. Public Sub New(ByVal download As nsIDownload)
    73. MyBase.New
    74. Me._download = download
    75. Me.ID = DateTime.Now.Ticks
    76. Me.Source = New nsURI(Me._download.GetSourceAttribute).ToUri
    77. Me.File = nsString.Get(Me._download.GetTargetFileAttribute.GetTargetAttribute)
    78. Me.Size = Me._download.GetSizeAttribute
    79. Dim a = Me._download.GetMIMEInfoAttribute
    80. If (Not (a) Is Nothing) Then
    81. Me.Mime = nsString.Get(a.GetMIMETypeAttribute)
    82. End If
    83. End Sub
    84. #Region "STATIC Downloads Methods"
    85. Private Shared DownloadManager As nsIDownloadManager = Nothing
    86. Public Shared Sub CleanUpDownloads()
    87. If (DownloadManager Is Nothing) Then
    88. DownloadManager = Xpcom.CreateInstance(Of nsIDownloadManager)("@mozilla.org/download-manager;1")
    89. End If
    90. Dim enu As nsISimpleEnumerator = DownloadManager.GetActiveDownloadsAttribute
    91. While enu.HasMoreElements
    92. Dim d As nsIDownload = CType(enu.GetNext, nsIDownload)
    93. Dim c As nsICancelable = d.GetCancelableAttribute
    94. DownloadManager.CancelDownload(d.GetIdAttribute)
    95. End While
    96. DownloadManager.CleanUp()
    97. End Sub
    98. Public Shared Function downloadFile(ByVal localfile As String, ByVal url As String) As myDownload
    99. If (DownloadManager Is Nothing) Then
    100. DownloadManager = Xpcom.CreateInstance(Of nsIDownloadManager)("@mozilla.org/download-manager;1")
    101. End If
    102. Dim source As nsIURI = IOService.CreateNsIUri(url)
    103. Dim dest As nsIURI = IOService.CreateFileNsIUri(localfile)
    104. Dim objTarget = Xpcom.CreateInstance(Of nsILocalFile)("@mozilla.org/file/local;1")
    105. Dim tmp As nsAString = New nsAString(localfile)
    106. objTarget.InitWithPath(tmp)
    107. Dim persist As nsIWebBrowserPersist = Xpcom.CreateInstance(Of nsIWebBrowserPersist)("@mozilla.org/embedding/browser/nsWebBrowserPersist;1")
    108. Dim download As nsIDownload = Nothing
    109. Dim t As nsAStringBase = CType(New nsAString(Path.GetFileName(localfile)), nsAStringBase)
    110. download = DownloadManager.AddDownload(0, source, dest, t, Nothing, 0, Nothing, CType(persist, nsICancelable))
    111. If (Not (download) Is Nothing) Then
    112. Dim myD As myDownload = New myDownload(download)
    113. persist.SetPersistFlagsAttribute((2 Or (32 Or 16384)))
    114. persist.SetProgressListenerAttribute(CType(myD, nsIWebProgressListener))
    115. persist.SaveURI(source, Nothing, Nothing, Nothing, Nothing, CType(dest, nsISupports))
    116. Return myD
    117. End If
    118. Return Nothing
    119. End Function
    120. #End Region
    121. Public Sub CancelDownload()
    122. If (DownloadManager Is Nothing) Then
    123. DownloadManager = Xpcom.CreateInstance(Of nsIDownloadManager)("@mozilla.org/download-manager;1")
    124. End If
    125. DownloadManager.CancelDownload(Me.GetIdAttribute)
    126. DownloadManager.RemoveDownload(Me.GetIdAttribute)
    127. End Sub
    128. Public Sub PauseDownload()
    129. DownloadManager.PauseDownload(Me.GetIdAttribute)
    130. End Sub
    131. Public Sub ResumeDownload()
    132. DownloadManager.ResumeDownload(Me.GetIdAttribute)
    133. End Sub
    134. Public Function GetAmountTransferredAttribute() As Long
    135. Return Me._download.GetAmountTransferredAttribute
    136. End Function
    137. Public Function GetCancelableAttribute() As Gecko.nsICancelable
    138. Return Me._download.GetCancelableAttribute
    139. End Function
    140. Public Sub GetDisplayNameAttribute(ByVal aDisplayName As Gecko.nsAStringBase)
    141. Me._download.GetDisplayNameAttribute(aDisplayName)
    142. End Sub
    143. Public Function GetIdAttribute() As UInteger
    144. Return Me._download.GetIdAttribute
    145. End Function
    146. Public Function GetMIMEInfoAttribute() As Gecko.nsIMIMEInfo
    147. Return Me._download.GetMIMEInfoAttribute
    148. End Function
    149. Public Function GetPercentCompleteAttribute() As Integer
    150. Return Me._download.GetPercentCompleteAttribute
    151. End Function
    152. Public Function GetReferrerAttribute() As Gecko.nsIURI
    153. Return Me._download.GetReferrerAttribute
    154. End Function
    155. Public Function GetResumableAttribute() As Boolean
    156. Return Me._download.GetResumableAttribute
    157. End Function
    158. Public Function GetSizeAttribute() As Long
    159. Return Me._download.GetSizeAttribute
    160. End Function
    161. Public Function GetSourceAttribute() As nsIURI
    162. Return Me._download.GetSourceAttribute
    163. End Function
    164. Public Function GetSpeedAttribute() As Double
    165. Return Me._download.GetSpeedAttribute
    166. End Function
    167. Public Function GetStartTimeAttribute() As Long
    168. Return Me._download.GetStartTimeAttribute
    169. End Function
    170. Public Function GetStateAttribute() As Short
    171. Return Me._download.GetStateAttribute
    172. End Function
    173. Public Function GetTargetAttribute() As nsIURI
    174. Return Me._download.GetTargetAttribute
    175. End Function
    176. Public Function GetTargetFileAttribute() As nsIFile
    177. Return Me._download.GetTargetFileAttribute
    178. End Function
    179. Public Sub Init(ByVal aSource As Gecko.nsIURI, ByVal aTarget As Gecko.nsIURI, ByVal aDisplayName As Gecko.nsAStringBase, ByVal aMIMEInfo As Gecko.nsIMIMEInfo, ByVal startTime As Long, ByVal aTempFile As Gecko.nsIFile, ByVal aCancelable As Gecko.nsICancelable)
    180. Me._download.Init(aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aTempFile, aCancelable)
    181. End Sub
    182. Public Sub OnLocationChange(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRequest As Gecko.nsIRequest, ByVal aLocation As Gecko.nsIURI, ByVal aFlags As UInteger)
    183. Me._download.OnLocationChange(aWebProgress, aRequest, aLocation, aFlags)
    184. End Sub
    185. Public Sub OnProgressChange(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRequest As Gecko.nsIRequest, ByVal aCurSelfProgress As Integer, ByVal aMaxSelfProgress As Integer, ByVal aCurTotalProgress As Integer, ByVal aMaxTotalProgress As Integer)
    186. Me.OnDownloadProgress(New GeckoDownloadProgressEventArgs(aCurTotalProgress, aMaxTotalProgress, Me._download.GetPercentCompleteAttribute, Me._download.GetSpeedAttribute))
    187. Me._download.OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
    188. End Sub
    189. Public Sub OnProgressChange64(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRequest As Gecko.nsIRequest, ByVal aCurSelfProgress As Long, ByVal aMaxSelfProgress As Long, ByVal aCurTotalProgress As Long, ByVal aMaxTotalProgress As Long)
    190. Me.OnDownloadProgress(New GeckoDownloadProgressEventArgs(aCurTotalProgress, aMaxTotalProgress, Me._download.GetPercentCompleteAttribute, Me._download.GetSpeedAttribute))
    191. Me._download.OnProgressChange64(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
    192. End Sub
    193. Public Function OnRefreshAttempted(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRefreshURI As Gecko.nsIURI, ByVal aMillis As Integer, ByVal aSameURI As Boolean) As Boolean
    194. Return Me._download.OnRefreshAttempted(aWebProgress, aRefreshURI, aMillis, aSameURI)
    195. End Function
    196. Public Sub OnSecurityChange(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRequest As Gecko.nsIRequest, ByVal aState As UInteger)
    197. Me._download.OnSecurityChange(aWebProgress, aRequest, aState)
    198. End Sub
    199. Public Sub OnStateChange(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRequest As Gecko.nsIRequest, ByVal aStateFlags As UInteger, ByVal aStatus As Integer)
    200. If ((aStateFlags And nsIWebProgressListenerConstants.STATE_START) _
    201. <> 0) Then
    202. ' Start
    203. Me.OnDownloadStarted()
    204. End If
    205. If ((aStateFlags And nsIWebProgressListenerConstants.STATE_STOP) _
    206. <> 0) Then
    207. ' Stop
    208. If (aStatus <> 0) Then
    209. ' ERROR FailEvent
    210. Me.OnDownloadFailed()
    211. Else
    212. ' COMPLETE CompleteEvent
    213. Me.OnDownloadComplete()
    214. End If
    215. End If
    216. Me._download.OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus)
    217. End Sub
    218. Public Sub OnStatusChange(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRequest As Gecko.nsIRequest, ByVal aStatus As Integer, ByVal aMessage As String)
    219. Me._download.OnStatusChange(aWebProgress, aRequest, aStatus, aMessage)
    220. End Sub
    221. End Class
    222. UnknownPublic Class GeckoDownloadProgressEventArgs
    223. Inherits EventArgs
    224. Public CurrentProgress As Long
    225. Public MaxProgress As Long
    226. Public ProgressPercent As Integer
    227. Public Speed As Double
    228. Public LeftTime As TimeSpan
    229. ''' <summary>Creates a new instance of a <see cref="GeckoDownloadEventArgs"/> object.</summary>
    230. ''' <param name="value"></param>
    231. ''' <param name="response"></param>
    232. Friend Sub New(ByVal currentProgress As Long, ByVal maxProgress As Long, ByVal progressPercent As Integer, ByVal speed As Double)
    233. MyBase.New
    234. Me.CurrentProgress = currentProgress
    235. Me.MaxProgress = maxProgress
    236. Me.ProgressPercent = progressPercent
    237. Me.Speed = speed
    238. If (speed > 100) Then
    239. Me.LeftTime = New TimeSpan(0, 0, CType(((maxProgress - currentProgress) _
    240. / speed), Integer))
    241. Else
    242. Me.LeftTime = New TimeSpan(0)
    243. End If
    244. End Sub
    245. End Class

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Thiemo1991“ ()

    Thiemo1991 schrieb:

    Wie kann man aus diesem Code der 22 Fehler aufweist, einen funktionierenden Code machen?

    Naja, durch das Beheben der selbigen würde ich behaupten.

    Hier sind 317 Zeilen Code, und in diesen sollen 12 (bzw. 22) Fehler drin sein. Am besten du schaust dir für jeden einzelnen die Meldungen an und versuchst die Fehler Stück für Stück zu beheben. Hierzu findest du sicherlich bei Google zu jedem Fehler zumindest einen Ansatz oder gar eine Lösung.


    LG, Acr0most
    Wenn das Leben wirklich nur aus Nullen und Einsen besteht, dann laufen sicherlich genügen Nullen frei herum. :D
    Signature-Move 8o
    kein Problem mit privaten Konversationen zu Thema XY :thumbup:
    Ich wollte den Code verwenden aber der beinhaltet WIRKLICH, 12 Fehler und auch 8 Warnungen. Könnt bzw. kannst du @Acr0most mir bitte dabei helfen? Ich bin am verzweifeln da ich sowas leider NICHT selbstständig beheben kann.
    Wie bekomme ich die Parameter des Download Links heraus die ich für den Downloader brauche? Ich habe mich dafür entschieden, das ich das mit VB-Mitteln mache.

    VB.NET-Quellcode

    1. Imports System.Net
    2. Public Class download
    3. Dim wc As New WebClient
    4. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    5. AddHandler wc.DownloadProgressChanged, AddressOf DownloadProgressChanged
    6. AddHandler wc.DownloadFileCompleted, AddressOf DownloadFileCompleted
    7. If tmBrowser.sfd.ShowDialog() = DialogResult.OK Then
    8. wc.DownloadFileAsync(New Uri(tmBrowser.cmbURL.Text), tmBrowser.sfd_Download.FileName)
    9. End If
    10. End Sub
    11. Public Sub DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
    12. tmBrowser.pgbLoad.Value = e.ProgressPercentage
    13. tmBrowser.lblStatus.Text = e.BytesReceived & "/" & e.TotalBytesToReceive
    14. End Sub
    15. Public Sub DownloadFileCompleted(ByVal sender As Object, ByVal e As EventArgs)
    16. tmBrowser.pgbLoad.Value = 0
    17. tmBrowser.lblStatus.Text = "Download fertig"
    18. End Sub
    19. End Class