23
23
24
24
#include " appshell_extensions.h"
25
25
26
+ #include < algorithm>
26
27
#include < CommDlg.h>
27
28
#include < ShlObj.h>
28
29
29
30
// Forward declarations for functions at the bottom of this file
31
+ void FixFilename (ExtensionString& filename);
30
32
int ConvertErrnoCode (int errorCode, bool isReading = true );
31
33
int ConvertWinErrorCode (int errorCode, bool isReading = true );
32
34
@@ -50,6 +52,8 @@ int32 ShowOpenDialog(bool allowMulitpleSelection,
50
52
wchar_t szFile[MAX_PATH];
51
53
szFile[0 ] = 0 ;
52
54
55
+ FixFilename (initialDirectory);
56
+
53
57
// TODO (issue #64) - This method should be using IFileDialog instead of the
54
58
/* outdated SHGetPathFromIDList and GetOpenFileName.
55
59
@@ -172,6 +176,8 @@ int32 ShowOpenDialog(bool allowMulitpleSelection,
172
176
173
177
int32 ReadDir (ExtensionString path, CefRefPtr<CefListValue>& directoryContents)
174
178
{
179
+ FixFilename (path);
180
+
175
181
path += L" \\ *" ;
176
182
177
183
WIN32_FIND_DATA ffd;
@@ -213,6 +219,8 @@ int32 ReadDir(ExtensionString path, CefRefPtr<CefListValue>& directoryContents)
213
219
214
220
int32 GetFileModificationTime (ExtensionString filename, uint32& modtime, bool & isDir)
215
221
{
222
+ FixFilename (filename);
223
+
216
224
DWORD dwAttr = GetFileAttributes (filename.c_str ());
217
225
218
226
if (dwAttr == INVALID_FILE_ATTRIBUTES) {
@@ -233,6 +241,8 @@ int32 GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& i
233
241
234
242
int32 ReadFile (ExtensionString filename, ExtensionString encoding, std::string& contents)
235
243
{
244
+ FixFilename (filename);
245
+
236
246
if (encoding != L" utf8" )
237
247
return ERR_UNSUPPORTED_ENCODING;
238
248
@@ -272,6 +282,8 @@ int32 ReadFile(ExtensionString filename, ExtensionString encoding, std::string&
272
282
273
283
int32 WriteFile (ExtensionString filename, std::string contents, ExtensionString encoding)
274
284
{
285
+ FixFilename (filename);
286
+
275
287
if (encoding != L" utf8" )
276
288
return ERR_UNSUPPORTED_ENCODING;
277
289
@@ -304,6 +316,11 @@ int32 DeleteFileOrDirectory(ExtensionString filename)
304
316
return NO_ERROR;
305
317
}
306
318
319
+ void FixFilename (ExtensionString& filename)
320
+ {
321
+ // Convert '/' to '\'
322
+ replace (filename.begin (), filename.end (), ' /' , ' \\ ' );
323
+ }
307
324
308
325
// Maps errors from errno.h to the brackets error codes
309
326
// found in brackets_extensions.js
0 commit comments