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
- Imports System.ComponentModel
- Imports Gecko
- Public Class myDownload
- Inherits nsIDownload
- <Serializable()>
- Public Delegate Sub SimpleEventHandler(ByVal sender As Object)
- Private _download As nsIDownload
- #Region "Events"
- Protected Events As EventHandlerList = New EventHandlerList
- Private Shared StartEvent As Object = New Object
- Private Shared CompleteEvent As Object = New Object
- Private Shared FailEvent As Object = New Object
- Private Shared ProgressEvent As Object = New Object
- #Region "public event DownloadStarted"
- <Category("DownloadStarted"),
- Description("Occurs before the Download was started.")>
- Public Event DownloadStarted As SimpleEventHandler
- ''' <summary>Raises the <see cref="DownloadStarted"/> event.</summary>
- ''' <param name="e">The data for the event.</param>
- Protected Overridable Sub OnDownloadStarted()
- Dim evnt = CType(Me.Events(StartEvent), SimpleEventHandler)
- If (Not (evnt) Is Nothing) Then
- evnt(Me)
- End If
- End Sub
- #End Region
- #Region "public event DownloadProgress"
- <Category("DownloadProgress"),
- Description("Occurs before the Download is progressing.")>
- Public Event DownloadProgress As EventHandler(Of GeckoDownloadProgressEventArgs)
- ''' <summary>Raises the <see cref="DownloadStarted"/> event.</summary>
- ''' <param name="e">The data for the event.</param>
- Protected Overridable Sub OnDownloadProgress(ByVal e As GeckoDownloadProgressEventArgs)
- Dim evnt = CType(Me.Events(ProgressEvent), EventHandler(Of GeckoDownloadProgressEventArgs))
- If (Not (evnt) Is Nothing) Then
- evnt(Me, e)
- End If
- End Sub
- #End Region
- #Region "public event DownloadComplete"
- <Category("DownloadComplete"),
- Description("Occurs before the Download was completed.")>
- Public Event DownloadComplete As SimpleEventHandler
- ''' <summary>Raises the <see cref="DownloadStarted"/> event.</summary>
- ''' <param name="e">The data for the event.</param>
- Protected Overridable Sub OnDownloadComplete()
- Dim evnt = CType(Me.Events(CompleteEvent), SimpleEventHandler)
- If (Not (evnt) Is Nothing) Then
- evnt(Me)
- End If
- End Sub
- #End Region
- #Region "public event DownloadFailed"
- <Category("DownloadFailed"),
- Description("Occurs before the Download was started.")>
- Public Event DownloadFailed As SimpleEventHandler
- ''' <summary>Raises the <see cref="DownloadStarted"/> event.</summary>
- ''' <param name="e">The data for the event.</param>
- Protected Overridable Sub OnDownloadFailed()
- Dim evnt = CType(Me.Events(FailEvent), SimpleEventHandler)
- If (Not (evnt) Is Nothing) Then
- evnt(Me)
- End If
- End Sub
- #End Region
- #End Region
- Public ID As Long
- Public Source As Uri
- Public File As String
- Public Size As Long
- Public Mime As String
- Public Sub New(ByVal download As nsIDownload)
- MyBase.New
- Me._download = download
- Me.ID = DateTime.Now.Ticks
- Me.Source = New nsURI(Me._download.GetSourceAttribute).ToUri
- Me.File = nsString.Get(Me._download.GetTargetFileAttribute.GetTargetAttribute)
- Me.Size = Me._download.GetSizeAttribute
- Dim a = Me._download.GetMIMEInfoAttribute
- If (Not (a) Is Nothing) Then
- Me.Mime = nsString.Get(a.GetMIMETypeAttribute)
- End If
- End Sub
- #Region "STATIC Downloads Methods"
- Private Shared DownloadManager As nsIDownloadManager = Nothing
- Public Shared Sub CleanUpDownloads()
- If (DownloadManager Is Nothing) Then
- DownloadManager = Xpcom.CreateInstance(Of nsIDownloadManager)("@mozilla.org/download-manager;1")
- End If
- Dim enu As nsISimpleEnumerator = DownloadManager.GetActiveDownloadsAttribute
- While enu.HasMoreElements
- Dim d As nsIDownload = CType(enu.GetNext, nsIDownload)
- Dim c As nsICancelable = d.GetCancelableAttribute
- DownloadManager.CancelDownload(d.GetIdAttribute)
- End While
- DownloadManager.CleanUp()
- End Sub
- Public Shared Function downloadFile(ByVal localfile As String, ByVal url As String) As myDownload
- If (DownloadManager Is Nothing) Then
- DownloadManager = Xpcom.CreateInstance(Of nsIDownloadManager)("@mozilla.org/download-manager;1")
- End If
- Dim source As nsIURI = IOService.CreateNsIUri(url)
- Dim dest As nsIURI = IOService.CreateFileNsIUri(localfile)
- Dim objTarget = Xpcom.CreateInstance(Of nsILocalFile)("@mozilla.org/file/local;1")
- Dim tmp As nsAString = New nsAString(localfile)
- objTarget.InitWithPath(tmp)
- Dim persist As nsIWebBrowserPersist = Xpcom.CreateInstance(Of nsIWebBrowserPersist)("@mozilla.org/embedding/browser/nsWebBrowserPersist;1")
- Dim download As nsIDownload = Nothing
- Dim t As nsAStringBase = CType(New nsAString(Path.GetFileName(localfile)), nsAStringBase)
- download = DownloadManager.AddDownload(0, source, dest, t, Nothing, 0, Nothing, CType(persist, nsICancelable))
- If (Not (download) Is Nothing) Then
- Dim myD As myDownload = New myDownload(download)
- persist.SetPersistFlagsAttribute((2 Or (32 Or 16384)))
- persist.SetProgressListenerAttribute(CType(myD, nsIWebProgressListener))
- persist.SaveURI(source, Nothing, Nothing, Nothing, Nothing, CType(dest, nsISupports))
- Return myD
- End If
- Return Nothing
- End Function
- #End Region
- Public Sub CancelDownload()
- If (DownloadManager Is Nothing) Then
- DownloadManager = Xpcom.CreateInstance(Of nsIDownloadManager)("@mozilla.org/download-manager;1")
- End If
- DownloadManager.CancelDownload(Me.GetIdAttribute)
- DownloadManager.RemoveDownload(Me.GetIdAttribute)
- End Sub
- Public Sub PauseDownload()
- DownloadManager.PauseDownload(Me.GetIdAttribute)
- End Sub
- Public Sub ResumeDownload()
- DownloadManager.ResumeDownload(Me.GetIdAttribute)
- End Sub
- Public Function GetAmountTransferredAttribute() As Long
- Return Me._download.GetAmountTransferredAttribute
- End Function
- Public Function GetCancelableAttribute() As Gecko.nsICancelable
- Return Me._download.GetCancelableAttribute
- End Function
- Public Sub GetDisplayNameAttribute(ByVal aDisplayName As Gecko.nsAStringBase)
- Me._download.GetDisplayNameAttribute(aDisplayName)
- End Sub
- Public Function GetIdAttribute() As UInteger
- Return Me._download.GetIdAttribute
- End Function
- Public Function GetMIMEInfoAttribute() As Gecko.nsIMIMEInfo
- Return Me._download.GetMIMEInfoAttribute
- End Function
- Public Function GetPercentCompleteAttribute() As Integer
- Return Me._download.GetPercentCompleteAttribute
- End Function
- Public Function GetReferrerAttribute() As Gecko.nsIURI
- Return Me._download.GetReferrerAttribute
- End Function
- Public Function GetResumableAttribute() As Boolean
- Return Me._download.GetResumableAttribute
- End Function
- Public Function GetSizeAttribute() As Long
- Return Me._download.GetSizeAttribute
- End Function
- Public Function GetSourceAttribute() As nsIURI
- Return Me._download.GetSourceAttribute
- End Function
- Public Function GetSpeedAttribute() As Double
- Return Me._download.GetSpeedAttribute
- End Function
- Public Function GetStartTimeAttribute() As Long
- Return Me._download.GetStartTimeAttribute
- End Function
- Public Function GetStateAttribute() As Short
- Return Me._download.GetStateAttribute
- End Function
- Public Function GetTargetAttribute() As nsIURI
- Return Me._download.GetTargetAttribute
- End Function
- Public Function GetTargetFileAttribute() As nsIFile
- Return Me._download.GetTargetFileAttribute
- End Function
- 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)
- Me._download.Init(aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aTempFile, aCancelable)
- End Sub
- Public Sub OnLocationChange(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRequest As Gecko.nsIRequest, ByVal aLocation As Gecko.nsIURI, ByVal aFlags As UInteger)
- Me._download.OnLocationChange(aWebProgress, aRequest, aLocation, aFlags)
- End Sub
- 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)
- Me.OnDownloadProgress(New GeckoDownloadProgressEventArgs(aCurTotalProgress, aMaxTotalProgress, Me._download.GetPercentCompleteAttribute, Me._download.GetSpeedAttribute))
- Me._download.OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
- End Sub
- 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)
- Me.OnDownloadProgress(New GeckoDownloadProgressEventArgs(aCurTotalProgress, aMaxTotalProgress, Me._download.GetPercentCompleteAttribute, Me._download.GetSpeedAttribute))
- Me._download.OnProgressChange64(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
- End Sub
- Public Function OnRefreshAttempted(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRefreshURI As Gecko.nsIURI, ByVal aMillis As Integer, ByVal aSameURI As Boolean) As Boolean
- Return Me._download.OnRefreshAttempted(aWebProgress, aRefreshURI, aMillis, aSameURI)
- End Function
- Public Sub OnSecurityChange(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRequest As Gecko.nsIRequest, ByVal aState As UInteger)
- Me._download.OnSecurityChange(aWebProgress, aRequest, aState)
- End Sub
- Public Sub OnStateChange(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRequest As Gecko.nsIRequest, ByVal aStateFlags As UInteger, ByVal aStatus As Integer)
- If ((aStateFlags And nsIWebProgressListenerConstants.STATE_START) _
- <> 0) Then
- ' Start
- Me.OnDownloadStarted()
- End If
- If ((aStateFlags And nsIWebProgressListenerConstants.STATE_STOP) _
- <> 0) Then
- ' Stop
- If (aStatus <> 0) Then
- ' ERROR FailEvent
- Me.OnDownloadFailed()
- Else
- ' COMPLETE CompleteEvent
- Me.OnDownloadComplete()
- End If
- End If
- Me._download.OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus)
- End Sub
- Public Sub OnStatusChange(ByVal aWebProgress As Gecko.nsIWebProgress, ByVal aRequest As Gecko.nsIRequest, ByVal aStatus As Integer, ByVal aMessage As String)
- Me._download.OnStatusChange(aWebProgress, aRequest, aStatus, aMessage)
- End Sub
- End Class
- UnknownPublic Class GeckoDownloadProgressEventArgs
- Inherits EventArgs
- Public CurrentProgress As Long
- Public MaxProgress As Long
- Public ProgressPercent As Integer
- Public Speed As Double
- Public LeftTime As TimeSpan
- ''' <summary>Creates a new instance of a <see cref="GeckoDownloadEventArgs"/> object.</summary>
- ''' <param name="value"></param>
- ''' <param name="response"></param>
- Friend Sub New(ByVal currentProgress As Long, ByVal maxProgress As Long, ByVal progressPercent As Integer, ByVal speed As Double)
- MyBase.New
- Me.CurrentProgress = currentProgress
- Me.MaxProgress = maxProgress
- Me.ProgressPercent = progressPercent
- Me.Speed = speed
- If (speed > 100) Then
- Me.LeftTime = New TimeSpan(0, 0, CType(((maxProgress - currentProgress) _
- / speed), Integer))
- Else
- Me.LeftTime = New TimeSpan(0)
- End If
- End Sub
- End Class
Wie man mich kontaktieren kann:
thiemo-melhorn.de
thiemo-melhorn.de
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Thiemo1991“ ()