aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS-TheRevival/MainForms/DirectoryManagements.vb
blob: 4179e6fdae634dfcf8cd7ad73622a424c1542c47 (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
Module DirectoryManagements
    Dim spaces As String
    Public Sub TerminalDirectories(TheDirectory As String)
        Terminal.Pseudodir = TheDirectory.Replace(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\ShiftOS\ShiftFS", "!")
        Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & "Contents of " & Terminal.Pseudodir & Environment.NewLine
        Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & "[DIR]     0 KB ."
        Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & "[DIR]     0 KB .."
        For Each Dir As String In IO.Directory.GetDirectories(TheDirectory)
            Dim dirinf As New IO.DirectoryInfo(Dir)
            Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & "[DIR]     0 KB " & dirinf.Name
        Next
        For Each file As String In IO.Directory.GetFiles(TheDirectory)
            Dim filinf As New IO.FileInfo(file)
            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 filsize
                Case 0 To 9
                    spaces = "          "
                Case 10 To 99
                    spaces = "         "
                Case 100 To 999
                    spaces = "        "
                Case 1000 To 1023
                    spaces = "       "
            End Select
            Select Case thesize
                Case 1
                    Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & spaces & filsize & " KB " & filinf.Name
                Case 2
                    Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & spaces & filsize & " MB " & filinf.Name
                Case 3
                    Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & spaces & filsize & " GB " & filinf.Name
            End Select
        Next
    End Sub

    Public Sub NavigateDir(TheDirectory As String)
        If TheDirectory = ".." Then
            If Terminal.CurrentDirectory = Strings.OnceInfo(1) Then
                Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & "!\"
            Else
                Terminal.CurrentDirectory = IO.Directory.GetParent(Terminal.CurrentDirectory).ToString
            End If
        Else
            If IO.Directory.Exists(Terminal.CurrentDirectory + "\" + TheDirectory) Then
                Terminal.CurrentDirectory = Terminal.CurrentDirectory & "\" & TheDirectory
            ElseIf IO.Directory.Exists(TheDirectory) Then
                Terminal.CurrentDirectory = TheDirectory
            Else
                Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & "The directory is not exist!"
            End If
        End If
    End Sub

    Public Sub CreateDir(TheDirectory As String)
        If IO.Directory.Exists(Terminal.CurrentDirectory + "\" + TheDirectory) Then
            Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & "Directory is already exists!"
        Else
            IO.Directory.CreateDirectory(Terminal.CurrentDirectory + "\" + TheDirectory)
        End If
    End Sub

    Public Sub RemoveDir(TheDirectory As String)
        If IO.Directory.Exists(Terminal.CurrentDirectory + "\" + TheDirectory) Then
            Try
                IO.Directory.Delete(Terminal.CurrentDirectory + "\" + TheDirectory)
            Catch ex As Exception
                Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & ex.Message
            End Try
        Else
            Terminal.TextBox1.Text = Terminal.TextBox1.Text & Environment.NewLine & "The directory is not exists!"
        End If
    End Sub
End Module