forked from olaeld/vwin32fh
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvWin32fh.pkg
More file actions
237 lines (218 loc) · 8.4 KB
/
vWin32fh.pkg
File metadata and controls
237 lines (218 loc) · 8.4 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
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
// This code is part of VDF GUIdance
// Visit us @ http://www.vdf-guidance.com
// e-Mail us @ info@vdf-guidance.com
// VDF GUIdance is a mutual project of
// Frank Vandervelpen - Vandervelpen Systems and
// Wil van Antwerpen - Antwise Solutions
// All software source code should be used <<AS IS>> without any warranty.
//
//
// *** Windows 32bit file handling wrapper class ***
//
#IFNDEF Is$WebApp
Use File_Dlg.pkg // Contains OpenDialog class definition
Use cvFileDialogs.pkg
#ENDIF
Use Seq_chnl.pkg
Use windows.pkg
Use Dll.pkg
#IF (!@ < 200)
Use vWin32fhA.pkg // WinAPI ANSI legacy interface
#ELSE
Use vWin32fhW.pkg // WinAPI Unicode version
#ENDIF
//
// Gets the string from the right of the last sStopChar in sFrom
// If sStopChar has no occurences in the string an empty string is
// returned.
Function StringFromRightOfChar Global String sFrom String sStopChar Returns String
String sRetVal
String sChar
Integer iLength
Integer iPos
Boolean bStopChar
Move "" to sRetval
Move (Length(sFrom)) to iLength
If ((iLength>0) And (Pos(sStopChar,sFrom) <> 0)) Begin
Move iLength to iPos
Move (False) to bStopChar
While Not bStopChar
Move (Mid(sFrom,1,iPos)) to sChar
Decrement iPos
If ((sChar=sStopChar) Or (iPos<1)) Begin
Move (True) to bStopChar
End
Else Begin
Move (sChar+sRetVal) to sRetVal
End
Loop
End
Function_Return sRetVal
End_Function
// Pre: sFileName contains the complete path of the file.
// Post: returns the complete path of the file.
// This function is inspired on function SEQ_ExtractPathFromFileName of Sture Andersen.
Function ParseFolderName Global String sFileName Returns String
String sFile
String sFolderName
String sDirSep // this is "\" for windows, or "/" for unix
Move "" to sFolderName
Move (SysConf(SYSCONF_DIR_SEPARATOR)) to sDirSep
If sDirSep In sFileName Begin
Move (StringFromRightOfChar(sFileName,sDirSep)) to sFile
Move (Left(sFileName,Length(sFileName)-Length(sFile))) to sFolderName
End
Else If ":" In sFileName Begin
Move (StringFromRightOfChar(sFileName,":")) to sFile
Move (Replace(sFile,sFileName,"")) to sFolderName
End
Function_Return sFolderName
End_Function
// Pre: sFileName contains the complete path of the file.
// post: The returned filename has it's path removed, but will have a extension
Function ParseFileName Global String sFileName Returns String
String sFolderName
String sDirSep // this is "\" for windows, or "/" for unix
Move (sysconf(SYSCONF_DIR_SEPARATOR)) to sDirSep
Get ParseFolderName sFileName to sFolderName
If (sFolderName <> "") Begin
Move (Replace(sFolderName,sFileName,"")) to sFileName
End
Move (Replace(sDirSep,sFileName,"")) to sFileName
Function_Return sFilename
End_Function
// Pre: sFileName may contain the complete path of the file.
// or contain multiple dots in the filename, so temp.gif.bak will
// return "bak" as the extension and not "gif"
// Post: returns the extension only, this extension can be a valid unixlike extension
// such as "html" or "java"
Function ParseFileExtension Global String sFileName Returns String
String sFileExtension
Get ParseFileName sFileName to sFileName // takes care of corner case with path containing a ".". eg. c:\frank.cheng\hello
Get StringFromRightOfChar sFileName "." to sFileExtension
Function_Return sFileExtension
End_Function
Define CS_DDE_ERR_UNKNOWN_LINE2 For ".\n"
Function DDE_Error_To_String Integer iErrorID Returns String
String sMessage
Case Begin
Case (iErrorID = vERROR_FILE_NOT_FOUND)
Move CS_DDE_ERR_FILE_NOT_FOUND to sMessage
Case Break
Case (iErrorID = vERROR_PATH_NOT_FOUND)
Move CS_DDE_ERR_PATH_NOT_FOUND to sMessage
Case Break
Case (iErrorID = vERROR_BAD_FORMAT)
Move CS_DDE_ERR_BAD_FORMAT to sMessage
Case Break
Case (iErrorID = vSE_ERR_ACCESSDENIED)
Move CS_DDE_ERR_ACCESSDENIED to sMessage
Case Break
Case (iErrorID = vSE_ERR_ASSOCINCOMPLETE)
Move CS_DDE_ERR_ASSOCINCOMPLETE to sMessage
Case Break
Case (iErrorID = vSE_ERR_DDEBUSY)
Move CS_DDE_ERR_DDEBUSY to sMessage
Case Break
Case (iErrorID = vSE_ERR_DDEFAIL)
Move CS_DDE_ERR_DDEFAIL to sMessage
Case Break
Case (iErrorID = vSE_ERR_DDETIMEOUT)
Move CS_DDE_ERR_DDETIMEOUT to sMessage
Case Break
Case (iErrorID = vSE_ERR_DLLNOTFOUND)
Move CS_DDE_ERR_DLLNOTFOUND to sMessage
Case Break
Case (iErrorID = vSE_ERR_NOASSOC)
Move CS_DDE_ERR_NOASSOC to sMessage
Case Break
Case ((iErrorID = vSE_ERR_OOM) Or (iErrorID = 0))
Move CS_DDE_ERR_OOM to sMessage
Case Break
Case (iErrorID = vSE_ERR_PNF)
Move CS_DDE_ERR_PNF to sMessage
Case Break
Case (iErrorID = vSE_ERR_SHARE)
Move CS_DDE_ERR_SHARE to sMessage
Case Break
Case Else
Move CS_DDE_ERR_UNKNOWN_LINE1 to sMessage
Move (sMessage*Trim(iErrorID)*CS_DDE_ERR_UNKNOWN_LINE2) to sMessage
Case Break
Case End
Function_Return sMessage
End_Function
Procedure vDDE_Error_Handler Integer iErrorID
String sMessage
Get DDE_Error_To_String iErrorID to sMessage
Append sMessage CS_DDE_ERR_HANDL_PAKTC // "Press a key to continue..."
Send Stop_Box sMessage CS_DDE_ERR_HANDL_CAPTION
End_Procedure
// This function informs the user that he entered a yet unknown folder and
// asks if he/she wants to create the folder (Yes/No)
// Choice: "Yes" - this creates the folder
// if successful, the function returns false
// else it will be true.
// Choice: "No" - returns TRUE, This allows the programmer to take action
// For example: to stop a save
// Precondition: A foldername must be entered. We do not check for empty paths
// This function returns a non-zero value if the folder isn't created afterwards
Function vVerifyNewFolder Global String sFolderName Returns Integer
Integer bIsNotValid
Integer iUsers_Choice
String sMessage
If (vFolderExists(sFolderName) Eq 0) Begin
Move "The folder '" to sMessage
Append sMessage sFolderName
Append sMessage "' does not yet exist,\n"
Append sMessage "Do you want to create it now?"
Get YesNo_Box sMessage "Confirm" MB_DefButton1 to iUsers_Choice
Case Begin
Case (iUsers_Choice = MBR_Yes)
Move (vCreateDirectory(sFolderName)) to bIsNotValid
If bIsNotValid Begin
Move "An error occurred while trying to create folder '" to sMessage
Append sMessage sFolderName "'.\n\n"
Send Info_Box sMessage "Info"
End
Case Break
Case (iUsers_Choice = MBR_No)
Move dfTrue to bIsNotValid // Cancel the save
Case Break
Case End
End
Function_Return bIsNotValid
End_Function
// **WvA
// Formats a foldername by first trimming it and after that by sticking a
// directory separator (/\) to the end if it doesn't have one there already.
// The folder may contain a drive letter or UNC encoding.
Function vFolderFormat Global String sFolderName Returns String
String sDirSep
Move (sysconf(SYSCONF_DIR_SEPARATOR)) to sDirSep // normally \ (backslash)
Move (Trim(sFolderName)) to sFolderName
If (Right(sFolderName,1)<>sDirSep) Begin
Move (sFolderName+sDirSep) to sFolderName
End
Function_Return sFolderName
End_Function
//
// Gets the parent path of the currently supplied path
// Returns "" when we are at the root folder.
//
Function vParentPath Global String sPath Returns String
String sStrip sDirSep
Move (SysConf(SYSCONF_DIR_SEPARATOR)) to sDirSep
Move (Trim(sPath)) to sPath
If (Right(sPath,1) = sDirSep) Begin
Move (Left(sPath,Length(sPath)-1)) to sPath
End
If (Pos(sDirSep, sPath)) Begin
Move (StringFromRightOfChar(sPath, sDirSep)) to sStrip
Move (Left(sPath,Length(sPath)-Length(sStrip))) to sPath
End
Else Begin
Move "" to sPath
End
Function_Return sPath
End_Function