aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS-TheRevival/MainForms/Applications/Universal/File Skimmer/Uni_FileSkimmer.vb
blob: 1095248084ad6902b9ba13a497fbe9106eea407d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
Imports System.IO

Public Class Uni_FileSkimmer
    Public CurrentDir As String
    Dim FileType As Integer
    Dim ItemsDeleted As Integer

    Private Sub Uni_FileSkimmer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CheckAvailable()
        'Sets icons for buttons in here, for some reason
        btn_Up.BackgroundImage = My.Resources.FileSkimmerFunctionIcons.ico_up1
        'End thingy
        CurrentDir = Strings.OnceInfo(1)
        txt_AddressBar.Text = CurrentDir.Replace(Strings.OnceInfo(1), "!\")
        pic_Icon.Image = My.Resources.FileSkimmerFileIcons.ico_folder
        ShowContent()
    End Sub

    Private Sub CheckAvailable()
        'btn_NewFolder.Text = "???"
        'btn_NewFolder.Image = Nothing
    End Sub

    Private Sub PropertyPaneToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PropertyPaneToolStripMenuItem.Click
        If PropertyPaneToolStripMenuItem.CheckState = False Then
            pnl_Properties.Visible = False
        Else
            pnl_Properties.Visible = True
        End If
    End Sub

    Private Sub CloseToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CloseToolStripMenuItem.Click
        Dispose()
    End Sub

    Private Sub cmb_Layout_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmb_Layout.SelectedIndexChanged
        Select Case cmb_Layout.SelectedItem.ToString
            Case "Large Icons"
                lsv_Content.View = View.LargeIcon
            Case "Small Icons"
                lsv_Content.View = View.SmallIcon
            Case "List"
                lsv_Content.View = View.List
        End Select
    End Sub

    Private Sub cmb_Layout_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles cmb_Layout.DrawItem
        e.DrawBackground()
        If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
            e.Graphics.FillRectangle(Brushes.Black, e.Bounds)
        End If
        Dim sf As New StringFormat
        Using b As New SolidBrush(e.ForeColor)
            e.Graphics.DrawString(cmb_Layout.GetItemText(cmb_Layout.Items(e.Index)), e.Font, b, e.Bounds, sf)
        End Using
        e.DrawFocusRectangle()
    End Sub

    Private Sub btn_Up_Click(sender As Object, e As EventArgs) Handles btn_Up.Click
        Try
            If txt_AddressBar.Text = "!\" Or txt_AddressBar.Text = "!" Then

            Else
                Dim directoryInfo As System.IO.DirectoryInfo
                directoryInfo = System.IO.Directory.GetParent(CurrentDir.Replace("!\", Strings.OnceInfo(1) & "\"))

                'Dim endloop As Boolean = False
                'lbllocation.Text = lbllocation.Text.Substring(0, lbllocation.Text.Length - 1)

                'While endloop = False
                '    Try
                '        If lbllocation.Text.Substring(lbllocation.Text.Length - 1) = "/" Then
                '            endloop = True
                '        Else
                '            lbllocation.Text = lbllocation.Text.Substring(0, lbllocation.Text.Length - 1)
                '        End If
                '    Catch
                '        infobox.title = "File Skimmer - Error!"
                '        infobox.textinfo = "Unable to move into a higher directory due to error reading the requested folder on the drive." & Environment.NewLine & Environment.NewLine & "An error occured going up"
                '        infobox.Show()
                '    End Try
                'End While
                Dim DirFullName As String = directoryInfo.FullName
                txt_AddressBar.Text = DirFullName.Replace(Strings.OnceInfo(1), "!")
                CurrentDir = DirFullName
                ShowContent()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btn_Refresh_Click(sender As Object, e As EventArgs) Handles btn_Refresh.Click
        ShowContent()
    End Sub

    Private Sub txt_AddressBar_TextChanged(sender As Object, e As KeyEventArgs) Handles txt_AddressBar.KeyDown
        If e.KeyCode = Keys.Enter Then
            If txt_AddressBar.Text Like "!*" Then
                Dim BackupCurrentDir As String = txt_AddressBar.Text
                BackupCurrentDir = BackupCurrentDir.Replace("!", Strings.OnceInfo(1))
                If BackupCurrentDir Like "*.*" Then

                Else
                    If Directory.Exists(BackupCurrentDir) = True Then
                        txt_AddressBar.Text = BackupCurrentDir.Replace(Strings.OnceInfo(1), "!")
                        CurrentDir = BackupCurrentDir
                        ShowContent()
                    End If
                End If
                End If
        End If
    End Sub

    Private Sub lsv_Content_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles lsv_Content.MouseDoubleClick
        If txt_AddressBar.Text Like "*\" Then
        Else
            txt_AddressBar.Text = txt_AddressBar.Text + "\"
        End If
        ExecuteFile(txt_AddressBar.Text + lsv_Content.SelectedItems(0).Text)
    End Sub

    Private Sub lsv_Content_MouseClick(sender As Object, e As MouseEventArgs) Handles lsv_Content.MouseClick
        Select Case e.Button
            Case MouseButtons.Left
                If pnl_Properties.Visible = True Then
                    Dim IsFile As Boolean = False
                    If lsv_Content.SelectedItems(0).Text = Nothing Then
                        pic_Icon.Image = Nothing
                        lbl_filename.Visible = False
                        lbl_filetype.Visible = False
                        lbl_filesize.Visible = False
                    Else
                        lbl_filename.Visible = True
                        lbl_filetype.Visible = True
                        If lsv_Content.SelectedItems(0).Text Like "*.txt" Then
                            pic_Icon.Image = My.Resources.FileSkimmerFileIcons.ico_textfile
                            lbl_filetype.Text = "Text File"
                            IsFile = True
                        ElseIf lsv_Content.SelectedItems(0).Text Like "*.*" Then
                            pic_Icon.Image = My.Resources.FileSkimmerFileIcons.ico_unknown
                            lbl_filetype.Text = "Unknown File Type"
                            IsFile = True
                        End If
                        If IsFile = True Then
                            lbl_filesize.Visible = True
                            Dim filinf As New IO.FileInfo(CurrentDir & "\" & lsv_Content.SelectedItems(0).Text)
                            Dim filsize As Long = filinf.Length / 1024
                            Dim thesize As Integer = 1
                            Do
                                If filsize >= 1024 Then
                                    filsize = filsize / 1024
                                    thesize = thesize + 1
                                Else
                                    Exit Do
                                End If
                            Loop
                            Select Case thesize
                                Case 1
                                    lbl_filesize.Text = filsize & " KB"
                                Case 2
                                    lbl_filesize.Text = filsize & " MB"
                                Case 3
                                    lbl_filesize.Text = filsize & " GB"
                            End Select
                        Else
                            pic_Icon.Image = My.Resources.FileSkimmerFileIcons.ico_folder
                            lbl_filetype.Text = "Folder"
                            lbl_filesize.Visible = False
                        End If
                        lbl_filename.Text = lsv_Content.SelectedItems(0).Text
                    End If
                End If
        End Select
    End Sub

    Public Sub ExecuteFile(path As String)
        If path Like "*.txt" Then
            Undeveloped()
        Else
            path = path.Replace("!\", Strings.OnceInfo(1) & "\")
            If My.Computer.FileSystem.DirectoryExists(path) Then
                CurrentDir = path
                txt_AddressBar.Text = CurrentDir.Replace(Strings.OnceInfo(1), "!")
                ShowContent()
            Else
            End If
        End If
    End Sub

    Public Sub ShowContent()
        Show()

        lsv_Content.Items.Clear()

        Dim Dir As New DirectoryInfo(CurrentDir)
        Dim Files As FileInfo() = Dir.GetFiles()
        Dim File As FileInfo
        Dim Folders As DirectoryInfo() = Dir.GetDirectories()
        Dim Folder As DirectoryInfo

        'For Each Dir As String In IO.Directory.GetDirectories(CurrentDir)
        '    Dim Dirinfo As New IO.DirectoryInfo(Dir)
        '    lsv_Content.Items.Add(Dirinfo.Name, 0)
        '    'NewLine("[DIR]     0 KB " & dirinf.Name)
        'Next

        For Each Folder In Folders
            Dim FolderName As String = Folder.Name
            lsv_Content.Items.Add(FolderName, 0)
        Next

        For Each File In Files
            Dim filename As String = File.Name
            Dim fileex As String = File.Extension

            FileType = GetFileType(fileex)(0)

            lsv_Content.Items.Add(filename, FileType)
        Next
    End Sub

    Public Function GetFileType(fileex As String)

        Dim FileType As Integer
        Dim Program As String

        Select Case fileex
            Case ".txt"
                FileType = 1
                Program = "Text Document"
            'Case ".doc"
            '    filetype = 5
            '    program = "Word Document"
            'Case ".docx"
            '    filetype = 5
            '    program = "Word Document"
            Case ".png"
                FileType = 3
                Program = "Picture"
            Case ".jpg"
                FileType = 3
                Program = "Picture"
            Case ".jpeg"
                FileType = 3
                Program = "Picture"
            Case ".bmp"
                FileType = 3
                Program = "Bitmap"
            Case ".gif"
                FileType = 3
                Program = "Animated Picture"
                'Case ".avi"
                '    filetype = 10
                '    program = "Video Clip"
                'Case ".m4v"
                '    filetype = 10
                '    program = "MPEG-4 Video"
                'Case ".mp4"
                '    filetype = 10
                '    program = "MPEG-4 Video"
                'Case ".wmv"
                '    filetype = 10
                '    program = "Windows Media Video"
                'Case ".mp3"
                '    filetype = 9
                '    program = "MPEG-3 Song"
                'Case ".zip"
                '    filetype = 11
                '    program = "Compressed Files"
                'Case ".dll"
                '    filetype = 8
                '    program = "System File"
                'Case ".exe"
                '    filetype = 6
                '    program = "MS-DOS Executable"
                'Case ".sh"
                '    filetype = 7
                '    program = "BASH Script"
                'Case ".bat"
                '    filetype = 6
                '    program = "MS-DOS Batch File"
                'Case ".url"
                '    filetype = 5
                '    program = "Shortcut"
                'Case ".htm", ".html"
                '    filetype = 5
                '    program = "Web Page"
            Case Else
                FileType = 2
                Program = "Unknown File Type"
        End Select

        Dim array() As String = {CStr(FileType), Program}

        Return (array)
        If txt_AddressBar.Text = "!\" Then
            'WARNING TO GET BACK BUTTON DISABLED
        End If
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btn_Delete.Click
        DeleteFile(CurrentDir & lsv_Content.SelectedItems(0).Text)
    End Sub
End Class