-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUtilsFilenameCharmap.vb
More file actions
155 lines (121 loc) · 5.65 KB
/
UtilsFilenameCharmap.vb
File metadata and controls
155 lines (121 loc) · 5.65 KB
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
Option Strict On
Public Class UtilsFilenameCharmap
Private Charmap As New Dictionary(Of String, String)
Public Sub New()
LoadCharmap()
End Sub
Public Function SubstituteIllegalCharacters(Instring As String) As String
Dim Outstring As String = Instring
Dim Key As String
Dim Value As String
For Each Key In Charmap.Keys
Value = Charmap(Key)
Outstring = Outstring.Replace(Key, Value)
Next
Return Outstring
End Function
Private Sub LoadCharmap()
Dim StartupPath As String = System.Windows.Forms.Application.StartupPath()
Dim CharmapArray As String() = Nothing
Dim CharmapList As New List(Of String)
Dim KVPair As String
Dim Key As String
Dim Value As String
Dim CharmapFilename As String = String.Format("{0}\Preferences\filename_charmap.txt", StartupPath)
CreateCharmapFile()
CharmapArray = IO.File.ReadAllLines(CharmapFilename)
For Each KVPair In CharmapArray
If KVPair.Length > 0 Then ' Ignoring blank lines
Key = KVPair(0)
If Key.ToLower = "c" Then
Continue For ' Ignoring comment line
End If
If KVPair.Length = 1 Then
Value = ""
Charmap(Key) = Value
Continue For
End If
Value = KVPair.Substring(1).Trim()
If Value.Length = 0 Then
Value = " "
Charmap(Key) = Value
Else
Charmap(Key) = Value
End If
End If
Next
End Sub
Private Sub CreateCharmapFile()
Dim StartupPath As String = System.Windows.Forms.Application.StartupPath()
Dim Charmap As String() = Nothing
Dim CharmapList As New List(Of String)
Dim CharmapFilename As String = String.Format("{0}\Preferences\filename_charmap.txt", StartupPath)
Try
Charmap = IO.File.ReadAllLines(CharmapFilename)
Catch ex As Exception
' File does not exist. Create it.
' https://www.mtu.edu/umc/services/websites/writing/characters-avoid/
CharmapList.Add("c This file contains a list of common illegal characters")
CharmapList.Add("c for files and directories, and their replacements.")
CharmapList.Add("c ")
CharmapList.Add("c It covers operating systems such as Windows, Mac and Linux")
CharmapList.Add("c and devices such as desktops, tablets and smartphones.")
CharmapList.Add("c ")
CharmapList.Add("c The format is <illegal character><space><replacement value>")
CharmapList.Add("c ")
CharmapList.Add("c So for example, '# my_replacement' means ")
CharmapList.Add("c If '#' is found, replace it with the text 'my_replacement'.")
CharmapList.Add("c Another example, '#' means ")
CharmapList.Add("c If '#' is found, replace it with '' (ie, just delete it).")
CharmapList.Add("c ")
CharmapList.Add("c (Note, in the default mapping below, I replace all illegal")
CharmapList.Add("c characters with '~'. Feel free to change it to your preference.) ")
CharmapList.Add("c ")
CharmapList.Add("c If you're just using Windows, you probably only have to define")
CharmapList.Add("c replacements for the characters < > : "" / \ | ? * !")
CharmapList.Add("c and comment out or delete the rest.")
CharmapList.Add("c ")
CharmapList.Add("c (Actually Windows doesn't care about !, but Solid Edge does.")
CharmapList.Add("c It used to identify Assembly Family members.)")
CharmapList.Add("c ")
CharmapList.Add("c If you mess up, you can delete this file and Housekeeper will")
CharmapList.Add("c regenerate it next time you start the program.")
CharmapList.Add("c ")
CharmapList.Add("c To comment out a line (so Housekeeper ignores it) start the line")
CharmapList.Add("c with 'c' as done in this header text.")
CharmapList.Add("c ")
CharmapList.Add("c There is no error checking when the program reads in this file.")
CharmapList.Add("c So don't do stuff like '? *' or ' c This is too complicated!!!'.")
CharmapList.Add("c ")
CharmapList.Add("c ")
CharmapList.Add("c Character mapping below")
CharmapList.Add("")
CharmapList.Add("# ~")
CharmapList.Add("% ~")
CharmapList.Add("& ~")
CharmapList.Add("{ ~")
CharmapList.Add("} ~")
CharmapList.Add("\ ~")
CharmapList.Add("< ~")
CharmapList.Add("> ~")
CharmapList.Add("* ~")
CharmapList.Add("? ~")
CharmapList.Add("/ ~")
CharmapList.Add("$ ~")
CharmapList.Add("! ~")
CharmapList.Add("' ~")
'CharmapList.Add("".doublequote.")
CharmapList.Add(String.Format("{0} {1}", Chr(34), "~"))
CharmapList.Add(": ~")
CharmapList.Add("@ ~")
CharmapList.Add("+ ~")
CharmapList.Add("` ~")
CharmapList.Add("| ~")
CharmapList.Add("= ~")
CharmapList.Add("")
CharmapList.Add("c Note the following replacement (of a space character) is commented out.")
CharmapList.Add("c ~")
IO.File.WriteAllLines(CharmapFilename, CharmapList)
End Try
End Sub
End Class