PageRenderTime 56ms CodeModel.GetById 49ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Source Code/FileArchiveEditor/frmMain.vb

#
Visual Basic | 75 lines | 54 code | 20 blank | 1 comment | 1 complexity | 228acf1759883c0c7733264df8389cf7 MD5 | raw file
 1Imports System.IO.Path
 2Imports PowerSong.FileArchive
 3
 4Public Class frmMain
 5
 6    Private Sub btnSelectArchiveFilename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectArchiveFilename.Click
 7        If dlgSaveArchive.ShowDialog = Windows.Forms.DialogResult.OK Then
 8            txtArchiveFilename.Text = dlgSaveArchive.FileName
 9        End If
10    End Sub
11
12    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
13
14        If dlgAddFile.ShowDialog = Windows.Forms.DialogResult.OK Then
15            For Each Filename As String In dlgAddFile.FileNames
16                Dim Item As ListViewItem = lvFiles.Items.Add(GetFileName(Filename))
17                Item.SubItems.Add(Filename)
18            Next
19        End If
20
21    End Sub
22
23    Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
24
25        Dim Table As New FileTable
26        For Each Item As ListViewItem In lvFiles.Items
27            Table.AddFile(Item.Text, Item.SubItems(1).Text)
28        Next
29        ArchiveFile.Create(txtArchiveFilename.Text, Table)
30        MsgBox("The archive has been created.", MsgBoxStyle.Information)
31
32    End Sub
33
34    Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
35
36        If lvFiles.SelectedItems.Count = 0 Then
37            MsgBox("Please select a file to remove first.", MsgBoxStyle.Information)
38            Exit Sub
39        End If
40
41        If MsgBox("Are you sure you wish to remove the selected files?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
42            For Each Item As ListViewItem In lvFiles.SelectedItems
43                Item.Remove()
44            Next
45        End If
46
47    End Sub
48
49    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
50
51        If lvFiles.SelectedItems.Count = 0 Then
52            MsgBox("Please select a file to edit first.", MsgBoxStyle.Information)
53            Exit Sub
54        End If
55
56        ' Change the file name of the selected file
57        Dim SelectedFile As String = lvFiles.SelectedItems(0).Text
58        SelectedFile = InputBox("Please enter the new virtual file name for this file:", "Change Filename", SelectedFile)
59        lvFiles.SelectedItems(0).Text = SelectedFile
60
61    End Sub
62
63    Private Sub btnAddFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddFolder.Click
64
65        If dlgAddFolder.ShowDialog = Windows.Forms.DialogResult.OK Then
66            For Each Filename As String In IO.Directory.GetFiles(dlgAddFolder.SelectedPath, "*.*", IO.SearchOption.AllDirectories)
67                Dim NewFilename As String = Filename.Remove(0, dlgAddFolder.SelectedPath.Length + 1)
68                Dim Item As ListViewItem = lvFiles.Items.Add(NewFilename)
69                Item.SubItems.Add(Filename)
70            Next
71        End If
72
73    End Sub
74
75End Class