home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Program_Up52528222002.psc / downloader / frmMain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2002-02-03  |  20.7 KB  |  595 lines

  1. VERSION 5.00
  2. Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomct2.ocx"
  3. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  4. Begin VB.Form frmMain 
  5.    Caption         =   "Onlinesoftweb.com Update Downloader"
  6.    ClientHeight    =   3720
  7.    ClientLeft      =   165
  8.    ClientTop       =   450
  9.    ClientWidth     =   6855
  10.    Icon            =   "frmMain.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    ScaleHeight     =   3720
  14.    ScaleWidth      =   6855
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin VB.CommandButton Command1 
  17.       Caption         =   "Please Vote"
  18.       Height          =   495
  19.       Left            =   5880
  20.       TabIndex        =   20
  21.       Top             =   1320
  22.       Width           =   735
  23.    End
  24.    Begin VB.TextBox FilePath 
  25.       Height          =   285
  26.       Left            =   2160
  27.       ScrollBars      =   2  'Vertical
  28.       TabIndex        =   18
  29.       Text            =   "C:\Program Files\Cub Scout.Net Explorer"
  30.       Top             =   3840
  31.       Visible         =   0   'False
  32.       Width           =   3615
  33.    End
  34.    Begin VB.CommandButton cmdRun 
  35.       Caption         =   "&Run"
  36.       Enabled         =   0   'False
  37.       Height          =   375
  38.       Left            =   1800
  39.       TabIndex        =   16
  40.       Top             =   2760
  41.       Width           =   1215
  42.    End
  43.    Begin VB.Timer tmrUpdateProgress 
  44.       Interval        =   1
  45.       Left            =   1200
  46.       Top             =   3720
  47.    End
  48.    Begin VB.TextBox Text1 
  49.       Height          =   285
  50.       Left            =   720
  51.       TabIndex        =   4
  52.       Text            =   "http://www.onlinesoftweb.com/cubnet.exe"
  53.       Top             =   3360
  54.       Visible         =   0   'False
  55.       Width           =   5055
  56.    End
  57.    Begin VB.Timer tmrTimeLeft 
  58.       Interval        =   1000
  59.       Left            =   720
  60.       Top             =   3720
  61.    End
  62.    Begin VB.CommandButton cmdDownload 
  63.       Caption         =   "&Download"
  64.       BeginProperty Font 
  65.          Name            =   "Tahoma"
  66.          Size            =   8.25
  67.          Charset         =   0
  68.          Weight          =   400
  69.          Underline       =   0   'False
  70.          Italic          =   0   'False
  71.          Strikethrough   =   0   'False
  72.       EndProperty
  73.       Height          =   375
  74.       Left            =   600
  75.       TabIndex        =   3
  76.       Top             =   2760
  77.       Width           =   1215
  78.    End
  79.    Begin VB.Frame Frame1 
  80.       Caption         =   "&File Download Progress"
  81.       BeginProperty Font 
  82.          Name            =   "Tahoma"
  83.          Size            =   8.25
  84.          Charset         =   0
  85.          Weight          =   400
  86.          Underline       =   0   'False
  87.          Italic          =   0   'False
  88.          Strikethrough   =   0   'False
  89.       EndProperty
  90.       Height          =   1335
  91.       Left            =   600
  92.       TabIndex        =   1
  93.       Top             =   1200
  94.       Width           =   5055
  95.       Begin VB.PictureBox Picture1 
  96.          Appearance      =   0  'Flat
  97.          BackColor       =   &H00FFFFFF&
  98.          FillColor       =   &H00C00000&
  99.          ForeColor       =   &H00C00000&
  100.          Height          =   255
  101.          Left            =   120
  102.          ScaleHeight     =   225
  103.          ScaleWidth      =   4785
  104.          TabIndex        =   2
  105.          Top             =   240
  106.          Width           =   4815
  107.       End
  108.       Begin VB.Label lblStatus 
  109.          Alignment       =   2  'Center
  110.          Appearance      =   0  'Flat
  111.          BackColor       =   &H80000005&
  112.          BorderStyle     =   1  'Fixed Single
  113.          ForeColor       =   &H80000008&
  114.          Height          =   255
  115.          Left            =   120
  116.          TabIndex        =   17
  117.          Top             =   240
  118.          Visible         =   0   'False
  119.          Width           =   4815
  120.       End
  121.       Begin VB.Label lblSize 
  122.          BeginProperty Font 
  123.             Name            =   "Tahoma"
  124.             Size            =   8.25
  125.             Charset         =   0
  126.             Weight          =   400
  127.             Underline       =   0   'False
  128.             Italic          =   0   'False
  129.             Strikethrough   =   0   'False
  130.          EndProperty
  131.          Height          =   255
  132.          Left            =   960
  133.          TabIndex        =   14
  134.          Top             =   600
  135.          Width           =   615
  136.       End
  137.       Begin VB.Label lblRecieve 
  138.          BeginProperty Font 
  139.             Name            =   "Tahoma"
  140.             Size            =   8.25
  141.             Charset         =   0
  142.             Weight          =   400
  143.             Underline       =   0   'False
  144.             Italic          =   0   'False
  145.             Strikethrough   =   0   'False
  146.          EndProperty
  147.          Height          =   255
  148.          Left            =   2880
  149.          TabIndex        =   13
  150.          Top             =   600
  151.          Width           =   735
  152.       End
  153.       Begin VB.Label lblSpeed 
  154.          BeginProperty Font 
  155.             Name            =   "Tahoma"
  156.             Size            =   8.25
  157.             Charset         =   0
  158.             Weight          =   400
  159.             Underline       =   0   'False
  160.             Italic          =   0   'False
  161.             Strikethrough   =   0   'False
  162.          EndProperty
  163.          Height          =   255
  164.          Left            =   4320
  165.          TabIndex        =   12
  166.          Top             =   600
  167.          Width           =   615
  168.       End
  169.       Begin VB.Label lblElapsed 
  170.          BeginProperty Font 
  171.             Name            =   "Tahoma"
  172.             Size            =   8.25
  173.             Charset         =   0
  174.             Weight          =   400
  175.             Underline       =   0   'False
  176.             Italic          =   0   'False
  177.             Strikethrough   =   0   'False
  178.          EndProperty
  179.          Height          =   255
  180.          Left            =   3720
  181.          TabIndex        =   11
  182.          Top             =   960
  183.          Width           =   1215
  184.       End
  185.       Begin VB.Label lblRemaining 
  186.          BeginProperty Font 
  187.             Name            =   "Tahoma"
  188.             Size            =   8.25
  189.             Charset         =   0
  190.             Weight          =   400
  191.             Underline       =   0   'False
  192.             Italic          =   0   'False
  193.             Strikethrough   =   0   'False
  194.          EndProperty
  195.          Height          =   255
  196.          Left            =   1320
  197.          TabIndex        =   10
  198.          Top             =   960
  199.          Width           =   1215
  200.       End
  201.       Begin VB.Label Label6 
  202.          AutoSize        =   -1  'True
  203.          Caption         =   "Elapsed Time:"
  204.          BeginProperty Font 
  205.             Name            =   "Tahoma"
  206.             Size            =   8.25
  207.             Charset         =   0
  208.             Weight          =   400
  209.             Underline       =   0   'False
  210.             Italic          =   0   'False
  211.             Strikethrough   =   0   'False
  212.          EndProperty
  213.          Height          =   195
  214.          Left            =   2640
  215.          TabIndex        =   9
  216.          Top             =   960
  217.          Width           =   990
  218.       End
  219.       Begin VB.Label Label5 
  220.          AutoSize        =   -1  'True
  221.          Caption         =   "Time Remaining:"
  222.          BeginProperty Font 
  223.             Name            =   "Tahoma"
  224.             Size            =   8.25
  225.             Charset         =   0
  226.             Weight          =   400
  227.             Underline       =   0   'False
  228.             Italic          =   0   'False
  229.             Strikethrough   =   0   'False
  230.          EndProperty
  231.          Height          =   195
  232.          Left            =   120
  233.          TabIndex        =   8
  234.          Top             =   960
  235.          Width           =   1170
  236.       End
  237.       Begin VB.Label Label4 
  238.          AutoSize        =   -1  'True
  239.          Caption         =   "Speed:"
  240.          BeginProperty Font 
  241.             Name            =   "Tahoma"
  242.             Size            =   8.25
  243.             Charset         =   0
  244.             Weight          =   400
  245.             Underline       =   0   'False
  246.             Italic          =   0   'False
  247.             Strikethrough   =   0   'False
  248.          EndProperty
  249.          Height          =   195
  250.          Left            =   3720
  251.          TabIndex        =   7
  252.          Top             =   600
  253.          Width           =   510
  254.       End
  255.       Begin VB.Label Label3 
  256.          AutoSize        =   -1  'True
  257.          Caption         =   "Bytes Recieved:"
  258.          BeginProperty Font 
  259.             Name            =   "Tahoma"
  260.             Size            =   8.25
  261.             Charset         =   0
  262.             Weight          =   400
  263.             Underline       =   0   'False
  264.             Italic          =   0   'False
  265.             Strikethrough   =   0   'False
  266.          EndProperty
  267.          Height          =   195
  268.          Left            =   1680
  269.          TabIndex        =   6
  270.          Top             =   600
  271.          Width           =   1290
  272.       End
  273.       Begin VB.Label Label2 
  274.          AutoSize        =   -1  'True
  275.          Caption         =   "File Size:"
  276.          BeginProperty Font 
  277.             Name            =   "Tahoma"
  278.             Size            =   8.25
  279.             Charset         =   0
  280.             Weight          =   400
  281.             Underline       =   0   'False
  282.             Italic          =   0   'False
  283.             Strikethrough   =   0   'False
  284.          EndProperty
  285.          Height          =   195
  286.          Left            =   120
  287.          TabIndex        =   5
  288.          Top             =   600
  289.          Width           =   630
  290.       End
  291.    End
  292.    Begin VB.CommandButton cmdStop 
  293.       Caption         =   "&Stop"
  294.       BeginProperty Font 
  295.          Name            =   "Tahoma"
  296.          Size            =   8.25
  297.          Charset         =   0
  298.          Weight          =   400
  299.          Underline       =   0   'False
  300.          Italic          =   0   'False
  301.          Strikethrough   =   0   'False
  302.       EndProperty
  303.       Height          =   375
  304.       Left            =   4560
  305.       TabIndex        =   0
  306.       Top             =   2760
  307.       Width           =   1095
  308.    End
  309.    Begin MSWinsockLib.Winsock Winsock 
  310.       Left            =   1680
  311.       Top             =   3720
  312.       _ExtentX        =   741
  313.       _ExtentY        =   741
  314.       _Version        =   393216
  315.       RemotePort      =   80
  316.    End
  317.    Begin VB.CommandButton cmdPause 
  318.       Caption         =   "&Pause"
  319.       Height          =   375
  320.       Left            =   3480
  321.       TabIndex        =   15
  322.       Top             =   2760
  323.       Width           =   1095
  324.    End
  325.    Begin MSComCtl2.Animation Animation1 
  326.       Height          =   1095
  327.       Left            =   1200
  328.       TabIndex        =   19
  329.       Top             =   0
  330.       Width           =   3975
  331.       _ExtentX        =   7011
  332.       _ExtentY        =   1931
  333.       _Version        =   393216
  334.       FullWidth       =   265
  335.       FullHeight      =   73
  336.    End
  337.    Begin VB.Menu mnuFile 
  338.       Caption         =   "&File"
  339.       Begin VB.Menu exit 
  340.          Caption         =   "E&xit"
  341.       End
  342.    End
  343.    Begin VB.Menu mnuAbout 
  344.       Caption         =   "&About"
  345.       Begin VB.Menu mnuOnline 
  346.          Caption         =   "&Online Soft Web"
  347.       End
  348.    End
  349. Attribute VB_Name = "frmMain"
  350. Attribute VB_GlobalNameSpace = False
  351. Attribute VB_Creatable = False
  352. Attribute VB_PredeclaredId = True
  353. Attribute VB_Exposed = False
  354. Option Explicit
  355. Dim Data As String
  356. Dim Percent%
  357. Dim BeginTransfer As Single
  358. Dim BytesAlreadySent As Single
  359. Dim BytesRemaining As Single
  360. Dim Header As Variant
  361. Dim Status As String
  362. Dim TransferRate As Single
  363. Function ConvertTime(TheTime As Single)
  364.     Dim NewTime As String
  365.     Dim Sec As Single
  366.     Dim Min As Single
  367.     Dim H As Single
  368.     If TheTime > 60 Then
  369.         Sec = TheTime
  370.         Min = Sec / 60
  371.         Min = Int(Min)
  372.         Sec = Sec - Min * 60
  373.         H = Int(Min / 60)
  374.         Min = Min - H * 60
  375.         NewTime = H & ":" & Min & ":" & Sec
  376.         If H < 0 Then H = 0
  377.         If Min < 0 Then Min = 0
  378.         If Sec < 0 Then Sec = 0
  379.         NewTime = Format(NewTime, "HH:MM:SS")
  380.         ConvertTime = NewTime
  381.     End If
  382.     If TheTime < 60 Then
  383.         NewTime = "00:00:" & TheTime
  384.         NewTime = Format(NewTime, "HH:MM:SS")
  385.         ConvertTime = NewTime
  386.     End If
  387. End Function
  388. Public Function StartUpdate(strURL As String)
  389.     BytesAlreadySent = 1
  390.     If strURL = "" Then Exit Function
  391.     Url = strURL
  392.     Dim Pos%, Length%, NextPos%, LENGTH2%, POS2%, POS3%
  393.         Pos = InStr(strURL, "://") 'Record position of ://
  394.         LENGTH2 = Len("://") 'Record the length of it
  395.         Length = Len(strURL) 'Length of the entire url
  396.             If InStr(strURL, "://") Then  ' check if they entered the http:// or ftp://
  397.             strURL = Right(strURL, Length - LENGTH2 - Pos + 1) ' remove http:// or ftp://
  398.             End If
  399.                 If InStr(strURL, "/") Then 'looks for the first / mark going from left to right
  400.                 POS2 = InStr(strURL, "/") 'gets the position of the / mark
  401.     '-----------------GET THE FILENAME-------------
  402.                 Dim StrFile$: StrFile = strURL 'load the variables into each other
  403.                 Do Until InStr(StrFile, "/") = 0 'Do the loop until all is left is the filename
  404.                 LENGTH2 = Len(StrFile) 'get the length of the filename every time its passed over by the loop
  405.                 POS3 = InStr(StrFile, "/") 'find the / mark
  406.                 StrFile = Right(strURL, LENGTH2 - POS3) 'slash it down removing everything before the / mark including the / mark...
  407.                 Loop
  408.                 Filename = StrFile
  409.     '----------------END GET FILE NAME--------------
  410.                 strSvrURL = Left(strURL, POS2 - 1) 'removes everything after the / mark leaving just the server name as the end result
  411.     End If
  412.     '-----------END TRIM THE URL FOR THE SERVER NAME-----------
  413. End Function
  414. Public Sub Reset()
  415.     CloseSocket
  416.     Data = ""
  417.     Percent = 0
  418.     BeginTransfer = 0
  419.     BytesAlreadySent = 0
  420.     BytesRemaining = 0
  421.     Status = ""
  422.     Header = ""
  423.     RESUMEFILE = False
  424.     UpdateProgress Picture1, 0
  425.     cmdDownload.Enabled = True
  426. End Sub
  427. Public Sub CloseSocket()
  428.     Do Until Winsock.State = 0
  429.         Winsock.Close
  430.         Winsock.LocalPort = 0
  431.         Close #1
  432.     Loop
  433. End Sub
  434. Private Sub cmdDownload_Click()
  435.     StartUpdate Text1.Text
  436.     frmSave.Show
  437.     lblStatus.Visible = False
  438.     Animation1.AutoPlay = True
  439. End Sub
  440. Private Sub cmdPause_Click()
  441.     If BytesRemaining > BytesAlreadySent Then
  442.         If Winsock.State > 0 Then
  443.             Data = ""
  444.             BeginTransfer = 0
  445.             Status = ""
  446.             Header = ""
  447.             CloseSocket
  448.             Picture1.Visible = False
  449.             lblStatus.Visible = True
  450.             lblStatus.Caption = "Download Paused"
  451.             cmdPause.Caption = "Restart"
  452.             cmdStop.Enabled = False
  453.             Animation1.AutoPlay = False
  454.             
  455.         Else
  456.             Picture1.Visible = True
  457.             lblStatus.Visible = False
  458.             FileLength = FileLen(FilePathName)
  459.             RESUMEFILE = True
  460.             frmMain.Winsock.Connect strSvrURL, 80
  461.             cmdPause.Caption = "Pause"
  462.             cmdStop.Enabled = True
  463.             Animation1.AutoPlay = True
  464.             
  465.         End If
  466.     End If
  467. End Sub
  468. Private Sub cmdRun_Click()
  469.     Const conBtns As Integer = vbYesNoCancel + vbExclamation _
  470.                             + vbDefaultButton3 + vbApplicationModal
  471.     Const conMsg As String = "Do you want Install Cub Scout Explorer Updates"
  472.     Dim intUserResponse As Integer
  473.                    'document was changed since last save
  474.         intUserResponse = MsgBox(conMsg, conBtns, "Cub Scout.Net")
  475.         Select Case intUserResponse
  476.             Case vbYes                      'user wants to Open Program Updates
  477.                 OpenIt frmMain, FilePathName
  478.                 End
  479.             Case vbNo
  480.                 'Do nothing user does not want to Open Program Updates
  481.             Case vbCancel
  482.                 'Do nothing return to Program-don't unload form
  483.         End Select
  484.         
  485. End Sub
  486. Private Sub cmdStop_Click()
  487.     Const conBtns As Integer = vbYesNoCancel + vbExclamation _
  488.                             + vbDefaultButton3 + vbApplicationModal
  489.     Const conMsg As String = "Do you want Stop The Download"
  490.     Dim intUserResponse As Integer
  491.         intUserResponse = MsgBox(conMsg, conBtns, "Online Soft Web.Com Updater")
  492.         Select Case intUserResponse
  493.             Case vbYes        'user wants to Stop Download
  494.                 If Winsock.State > 0 Then
  495.                     CloseSocket
  496.                     MsgBox "Download Aborted!", vbExclamation, "Download Aborted"
  497.                     Animation1.AutoPlay = False
  498.                     Reset
  499.         
  500.                 End If
  501.                 
  502.             Case vbNo                       'user does not want Stop The Download
  503.                 Exit Sub
  504.             Case vbCancel
  505.                 Exit Sub                 'user does not want Stop The Download
  506.         End Select
  507. End Sub
  508. Private Sub Command1_Click()
  509.     OpenIt Me, "http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=31440&lngWId=1"
  510. End Sub
  511. Private Sub exit_Click()
  512.     Unload frmMain
  513. End Sub
  514. Private Sub Form_Load()
  515.     RESUMEFILE = False
  516.     strFormLoaded = "Main"
  517.     Animation1.Open (App.Path & "\" & "Filemove.avi")
  518. End Sub
  519. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  520.     CloseSocket
  521. End Sub
  522. Private Sub Form_Unload(Cancel As Integer)
  523.     CloseSocket
  524. End Sub
  525. Private Sub mnuOnline_Click()
  526.     OpenIt Me, "http://www.onlinesoftweb.com"
  527. End Sub
  528. Private Sub tmrTimeLeft_Timer()
  529. 'On Error Resume Next
  530.     If BytesRemaining > 0 And BytesAlreadySent > 0 Then
  531.         If BytesRemaining <= BytesAlreadySent Then
  532.             lblSpeed = 0
  533.             CloseSocket
  534.             lblElapsed = Format(Hr & ":" & Min & ":" & Sec, "HH:MM:SS")
  535.             cmdDownload.Enabled = False
  536.             cmdRun.Enabled = True
  537.             Picture1.Visible = False
  538.             lblStatus.Visible = True
  539.             lblStatus.Caption = "Download Completed"
  540.             Reset
  541.         Else
  542.             Sec = Sec + 1
  543.             If Sec >= 60 Then
  544.             Sec = 0
  545.             Min = Min + 1
  546.             ElseIf Min >= 60 Then
  547.             Min = 0
  548.             Hr = Hr + 1
  549.             End If
  550.             cmdDownload.Enabled = False
  551.             cmdRun.Enabled = False
  552.             lblElapsed = Format(Hr & ":" & Min & ":" & Sec, "HH:MM:SS")
  553.             'The reason I divide the difference of bytesalreadysent and bytesremaining is becuase they are in bytes right now.. I want it to be in KB so it can be Kbps and not bps
  554.             lblRemaining = ConvertTime(Int(((BytesRemaining - BytesAlreadySent) / 1024) / TransferRate))
  555.             lblSpeed = TransferRate
  556.         End If
  557.     End If
  558. End Sub
  559. Private Sub tmrUpdateProgress_Timer()
  560. On Error Resume Next
  561.     If BytesAlreadySent > 0 And BytesRemaining > 0 Then
  562.         lblRecieve = File_ByteConversion(BytesAlreadySent)
  563.         lblSize = File_ByteConversion(BytesRemaining)
  564.         Percent = Format((BytesAlreadySent / BytesRemaining) * 100, "00") 'calculates the percentage completed
  565.         UpdateProgress Picture1, Percent 'updates progress bar with new percentage rate
  566.     End If
  567. End Sub
  568. Private Sub Winsock_Connect()
  569. On Error Resume Next
  570.     Dim strCommand As String
  571.     strCommand = "GET " + Url + " HTTP/1.0" + vbCrLf 'tells server to GET the file if you just want the header info and not the data change "GET " to "HEAD "
  572.     strCommand = strCommand + "Accept: *.*, */*" + vbCrLf
  573.     If RESUMEFILE = True Then
  574.         strCommand = strCommand + "Range: bytes=" & FileLength & "-" & vbCrLf
  575.     End If
  576.     strCommand = strCommand + "User-Agent: Online Soft Web.Com" & vbCrLf
  577.     strCommand = strCommand + "Referer: " & strSvrURL & vbCrLf
  578.     strCommand = strCommand + vbCrLf
  579.     Winsock.SendData strCommand 'sends a header to the server instructing it what to do!
  580.     BeginTransfer = Timer 'start timer for transfer rate
  581. End Sub
  582. Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
  583.     Winsock.GetData Data, vbates the peri EaSent) / 1024VyTTck.Skxt
  584.     Dimt
  585.     strCommand hiDimt
  586.     bBn
  587.        Dimt
  588. =A Dimt
  589.  tOr")
  590.         Select Case intUser3strComm!
  591.   esume Next
  592.     Ife     Selvu2leLen(FilePath ue Pro     f=ock_DatarLf
  593.     If RESUMEFILE e Pr. RESUMEFILE e Pr. RESUMEFILE e Pru/le = True
  594.   oCmxt4EFILEyteConverU'gILE=7Endutcot pee Pr.-Remaining <= BytesAlreadySent oAcceg <= 0rluktUand + "18i
  595.