home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 45 / SuperCD45.iso / talleres / vbasic / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-01-29  |  8.5 KB  |  266 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   5760
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   8175
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   5760
  11.    ScaleWidth      =   8175
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin MSComctlLib.ImageList ImageList1 
  14.       Left            =   240
  15.       Top             =   4560
  16.       _ExtentX        =   1005
  17.       _ExtentY        =   1005
  18.       BackColor       =   -2147483643
  19.       ImageWidth      =   16
  20.       ImageHeight     =   16
  21.       MaskColor       =   12632256
  22.       _Version        =   393216
  23.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  24.          NumListImages   =   3
  25.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  26.             Picture         =   "Form1.frx":0000
  27.             Key             =   "open"
  28.          EndProperty
  29.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  30.             Picture         =   "Form1.frx":0524
  31.             Key             =   "file"
  32.          EndProperty
  33.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  34.             Picture         =   "Form1.frx":0A72
  35.             Key             =   "closed"
  36.          EndProperty
  37.       EndProperty
  38.    End
  39.    Begin MSComctlLib.TreeView TreeView1 
  40.       Height          =   4695
  41.       Left            =   2520
  42.       TabIndex        =   10
  43.       Top             =   240
  44.       Width           =   5535
  45.       _ExtentX        =   9763
  46.       _ExtentY        =   8281
  47.       _Version        =   393217
  48.       Indentation     =   706
  49.       Style           =   5
  50.       ImageList       =   "ImageList1"
  51.       Appearance      =   1
  52.    End
  53.    Begin VB.TextBox Destination 
  54.       Height          =   375
  55.       Left            =   5520
  56.       TabIndex        =   8
  57.       Text            =   "e:\backup"
  58.       Top             =   5160
  59.       Width           =   2535
  60.    End
  61.    Begin VB.TextBox Source 
  62.       Height          =   375
  63.       Left            =   1440
  64.       TabIndex        =   6
  65.       Text            =   "f:\dermot"
  66.       Top             =   5160
  67.       Width           =   2535
  68.    End
  69.    Begin VB.CommandButton ReadCatalogue 
  70.       Caption         =   "Read Catalogue"
  71.       Height          =   495
  72.       Left            =   120
  73.       TabIndex        =   5
  74.       Top             =   240
  75.       Width           =   1215
  76.    End
  77.    Begin VB.CommandButton SaveCatalogue 
  78.       Caption         =   "Save Catalogue"
  79.       Height          =   495
  80.       Left            =   120
  81.       TabIndex        =   4
  82.       Top             =   3840
  83.       Width           =   1215
  84.    End
  85.    Begin VB.CommandButton ResetArchive 
  86.       Caption         =   "Reset Archive"
  87.       Height          =   495
  88.       Left            =   120
  89.       TabIndex        =   3
  90.       Top             =   3120
  91.       Width           =   1215
  92.    End
  93.    Begin VB.CommandButton CopyFiles 
  94.       Caption         =   "Copy Files"
  95.       Height          =   495
  96.       Left            =   120
  97.       TabIndex        =   2
  98.       Top             =   2400
  99.       Width           =   1215
  100.    End
  101.    Begin VB.CommandButton ChangedFiles 
  102.       Caption         =   "Changed Files"
  103.       Height          =   495
  104.       Left            =   120
  105.       TabIndex        =   1
  106.       Top             =   1680
  107.       Width           =   1215
  108.    End
  109.    Begin VB.CommandButton Directory 
  110.       Caption         =   "Directory"
  111.       Height          =   495
  112.       Left            =   120
  113.       TabIndex        =   0
  114.       Top             =   960
  115.       Width           =   1215
  116.    End
  117.    Begin VB.Label Label2 
  118.       Caption         =   "Destination"
  119.       Height          =   255
  120.       Left            =   4440
  121.       TabIndex        =   9
  122.       Top             =   5160
  123.       Width           =   975
  124.    End
  125.    Begin VB.Label Label1 
  126.       Caption         =   "Source"
  127.       Height          =   255
  128.       Left            =   720
  129.       TabIndex        =   7
  130.       Top             =   5160
  131.       Width           =   615
  132.    End
  133. Attribute VB_Name = "Form1"
  134. Attribute VB_GlobalNameSpace = False
  135. Attribute VB_Creatable = False
  136. Attribute VB_PredeclaredId = True
  137. Attribute VB_Exposed = False
  138. Option Explicit
  139. Const MAX_PATH = 260
  140. Const INVALID_HANDLE = -1
  141. Private Type FILETIME
  142.         dwLowDateTime As Long
  143.         dwHighDateTime As Long
  144. End Type
  145. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
  146. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
  147. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
  148. Private Type WIN32_FIND_DATA
  149.         dwFileAttributes As Long
  150.         ftCreationTime As FILETIME
  151.         ftLastAccessTime As FILETIME
  152.         ftLastWriteTime As FILETIME
  153.         nFileSizeHigh As Long
  154.         nFileSizeLow As Long
  155.         dwReserved0 As Long
  156.         dwReserved1 As Long
  157.         cFileName As String * MAX_PATH
  158.         cAlternate As String * 14
  159. End Type
  160. Dim fd As WIN32_FIND_DATA
  161. Dim tree As BNodeList
  162. Dim changedTree As BNodeList
  163. Dim sDir As String, dDir As String
  164. Dim catalog As Catalogue
  165. ' this function creates a BNodeList of all the files in the currentPath.
  166. ' it is called recursively to build up a complete directory tree
  167. Function FindFiles(currentPath As String, prev As BNode) As BNodeList
  168. Dim h As Long, more As Boolean
  169. Dim n As BNode, p As BNodeList, list As BNodeList, fn As String, attr As Integer
  170. Set list = New BNodeList
  171. h = FindFirstFile(currentPath & "\*.*", fd)
  172. more = h <> INVALID_HANDLE
  173. While more
  174.     fn = TrimString(fd.cFileName)
  175.     If Left(fn, 1) <> "." Then
  176.         attr = fd.dwFileAttributes
  177.         Call list.Add(fn, attr, Nothing, fn)
  178.         Set n = list(fn)
  179.         Set n.prevBNode = prev
  180.         If attr And vbDirectory Then
  181.             Set p = FindFiles(currentPath & "\" & fn, n)
  182.             Set n.nextBNode = p
  183.         End If
  184.     End If
  185.     more = FindNextFile(h, fd)
  186. Set FindFiles = list
  187. FindClose (h)
  188. End Function
  189. Private Sub Directory_Click()
  190. sDir = Source.Text
  191. dDir = Destination.Text
  192. If sDir = "" Or dDir = "" Then
  193.     MsgBox ("You must enter a source directory and a destination")
  194.     Exit Sub
  195. End If
  196. Set tree = FindFiles(sDir, Nothing)
  197. ' load the TreeView control
  198. Dim t As Node
  199. TreeView1.Nodes.Clear
  200. Set t = TreeView1.Nodes.Add()
  201. t.Key = "a1"
  202. t.Text = dDir
  203. t.Image = "closed"
  204. t.ExpandedImage = "open"
  205. AddTNodes TreeView1, tree, t.Key
  206. End Sub
  207. Private Sub AddTNodes(tv As TreeView, bnlist As BNodeList, level As String)
  208. Dim bn As BNode, t As Node, nlevel As String, i As Integer
  209. i = 1
  210. For Each bn In bnlist
  211. nlevel = level & "." & i
  212.     Set t = tv.Nodes.Add(level, tvwChild, level & "." & i)
  213.     t.Text = bn.fileName
  214.     If Not bn.nextBNode Is Nothing Then
  215.         t.Image = "closed"
  216.         t.ExpandedImage = "open"
  217.         AddTNodes tv, bn.nextBNode, nlevel
  218.     Else
  219.         t.Image = "file"
  220.     End If
  221.     i = i + 1
  222. End Sub
  223. Function TrimString(s1 As String) As String
  224. Dim i As Long
  225. i = InStr(s1, Chr(0))
  226. TrimString = Left(s1, i - 1)
  227. End Function
  228. ' builds the changedTree BNodeList from the files in the
  229. 'source directory and adds them to the catalogue
  230. Private Sub ChangedFiles_Click()
  231. Set changedTree = tree.Changed(Nothing)
  232. If Not catalog Is Nothing Then
  233.     Call catalog.Add(changedTree)
  234. End If
  235. End Sub
  236. ' copies files in changedTree from sDir to dDir
  237. Private Sub CopyFiles_Click()
  238. If Not changedTree Is Nothing Then
  239.     Screen.MousePointer = vbHourglass
  240.     Call changedTree.CopyFiles(dDir, sDir)
  241.     Screen.MousePointer = vbDefault
  242. End If
  243. End Sub
  244. Private Sub ListView1_ItemClick(ByVal i As MSComctlLib.ListItem)
  245. Dim x As ListItem
  246. Set x = i
  247. c.RestoreFile i
  248. End Sub
  249. ' resets the archive bit on the files in changedTree
  250. Private Sub ResetArchive_Click()
  251. Dim fbu As Long
  252. fbu = changedTree.ResetArchiveBit(sDir)
  253. MsgBox ("Total files backed up " & fbu)
  254. End Sub
  255. ' saves the catalogue to disk
  256. Private Sub SaveCatalogue_Click()
  257. catalog.WriteCatalogue
  258. End Sub
  259. ' reads the catalogue from disk
  260. Private Sub ReadCatalogue_Click()
  261. Dim restoreTree As New BNodeList, t As New Token
  262. Set catalog = New Catalogue
  263. dDir = Destination.Text
  264. Call catalog.ReadCatalogue(dDir & "\" & "test.cat")
  265. End Sub
  266.