home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD 45 / SuperCD45.iso / talleres / vbasic / Form1.frm < prev    next >
Text File  |  2000-01-29  |  9KB  |  298 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. End
  134. Attribute VB_Name = "Form1"
  135. Attribute VB_GlobalNameSpace = False
  136. Attribute VB_Creatable = False
  137. Attribute VB_PredeclaredId = True
  138. Attribute VB_Exposed = False
  139. Option Explicit
  140.  
  141. Const MAX_PATH = 260
  142. Const INVALID_HANDLE = -1
  143.  
  144. Private Type FILETIME
  145.         dwLowDateTime As Long
  146.         dwHighDateTime As Long
  147. End Type
  148.  
  149. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
  150. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
  151. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
  152.  
  153. Private Type WIN32_FIND_DATA
  154.         dwFileAttributes As Long
  155.         ftCreationTime As FILETIME
  156.         ftLastAccessTime As FILETIME
  157.         ftLastWriteTime As FILETIME
  158.         nFileSizeHigh As Long
  159.         nFileSizeLow As Long
  160.         dwReserved0 As Long
  161.         dwReserved1 As Long
  162.         cFileName As String * MAX_PATH
  163.         cAlternate As String * 14
  164. End Type
  165.  
  166. Dim fd As WIN32_FIND_DATA
  167. Dim tree As BNodeList
  168. Dim changedTree As BNodeList
  169. Dim sDir As String, dDir As String
  170. Dim catalog As Catalogue
  171. ' this function creates a BNodeList of all the files in the currentPath.
  172. ' it is called recursively to build up a complete directory tree
  173. Function FindFiles(currentPath As String, prev As BNode) As BNodeList
  174. Dim h As Long, more As Boolean
  175. Dim n As BNode, p As BNodeList, list As BNodeList, fn As String, attr As Integer
  176.     
  177. Set list = New BNodeList
  178.  
  179. h = FindFirstFile(currentPath & "\*.*", fd)
  180. more = h <> INVALID_HANDLE
  181. While more
  182.     fn = TrimString(fd.cFileName)
  183.     If Left(fn, 1) <> "." Then
  184.         attr = fd.dwFileAttributes
  185.         Call list.Add(fn, attr, Nothing, fn)
  186.         Set n = list(fn)
  187.         Set n.prevBNode = prev
  188.         If attr And vbDirectory Then
  189.             Set p = FindFiles(currentPath & "\" & fn, n)
  190.             Set n.nextBNode = p
  191.         End If
  192.     End If
  193.     more = FindNextFile(h, fd)
  194. Wend
  195.  
  196. Set FindFiles = list
  197. FindClose (h)
  198.  
  199. End Function
  200. Private Sub Directory_Click()
  201. sDir = Source.Text
  202. dDir = Destination.Text
  203. If sDir = "" Or dDir = "" Then
  204.     MsgBox ("You must enter a source directory and a destination")
  205.     Exit Sub
  206. End If
  207.  
  208. Set tree = FindFiles(sDir, Nothing)
  209.  
  210. ' load the TreeView control
  211. Dim t As Node
  212. TreeView1.Nodes.Clear
  213. Set t = TreeView1.Nodes.Add()
  214. t.Key = "a1"
  215. t.Text = dDir
  216. t.Image = "closed"
  217. t.ExpandedImage = "open"
  218. AddTNodes TreeView1, tree, t.Key
  219.  
  220. End Sub
  221. Private Sub AddTNodes(tv As TreeView, bnlist As BNodeList, level As String)
  222. Dim bn As BNode, t As Node, nlevel As String, i As Integer
  223.  
  224. i = 1
  225. For Each bn In bnlist
  226. nlevel = level & "." & i
  227.     Set t = tv.Nodes.Add(level, tvwChild, level & "." & i)
  228.     t.Text = bn.fileName
  229.     If Not bn.nextBNode Is Nothing Then
  230.         t.Image = "closed"
  231.         t.ExpandedImage = "open"
  232.         AddTNodes tv, bn.nextBNode, nlevel
  233.     Else
  234.         t.Image = "file"
  235.     End If
  236.     i = i + 1
  237. Next
  238. End Sub
  239. Function TrimString(s1 As String) As String
  240. Dim i As Long
  241.  
  242. i = InStr(s1, Chr(0))
  243.  
  244. TrimString = Left(s1, i - 1)
  245. End Function
  246. ' builds the changedTree BNodeList from the files in the
  247. 'source directory and adds them to the catalogue
  248. Private Sub ChangedFiles_Click()
  249.  
  250. Set changedTree = tree.Changed(Nothing)
  251. If Not catalog Is Nothing Then
  252.     Call catalog.Add(changedTree)
  253. End If
  254.  
  255. End Sub
  256. ' copies files in changedTree from sDir to dDir
  257. Private Sub CopyFiles_Click()
  258.  
  259. If Not changedTree Is Nothing Then
  260.     Screen.MousePointer = vbHourglass
  261.     Call changedTree.CopyFiles(dDir, sDir)
  262.     Screen.MousePointer = vbDefault
  263. End If
  264.  
  265. End Sub
  266. Private Sub ListView1_ItemClick(ByVal i As MSComctlLib.ListItem)
  267. Dim x As ListItem
  268.  
  269. Set x = i
  270.  
  271. c.RestoreFile i
  272.  
  273. End Sub
  274. ' resets the archive bit on the files in changedTree
  275. Private Sub ResetArchive_Click()
  276. Dim fbu As Long
  277.  
  278. fbu = changedTree.ResetArchiveBit(sDir)
  279. MsgBox ("Total files backed up " & fbu)
  280.  
  281. End Sub
  282. ' saves the catalogue to disk
  283. Private Sub SaveCatalogue_Click()
  284.  
  285. catalog.WriteCatalogue
  286.  
  287. End Sub
  288. ' reads the catalogue from disk
  289. Private Sub ReadCatalogue_Click()
  290. Dim restoreTree As New BNodeList, t As New Token
  291. Set catalog = New Catalogue
  292.  
  293. dDir = Destination.Text
  294.  
  295. Call catalog.ReadCatalogue(dDir & "\" & "test.cat")
  296.     
  297. End Sub
  298.