Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit f0d3bba

Browse files
committed
Windows path fixes.
1 parent 7a0d090 commit f0d3bba

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

appshell/appshell_extensions_win.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323

2424
#include "appshell_extensions.h"
2525

26+
#include <algorithm>
2627
#include <CommDlg.h>
2728
#include <ShlObj.h>
2829

2930
// Forward declarations for functions at the bottom of this file
31+
void FixFilename(ExtensionString& filename);
3032
int ConvertErrnoCode(int errorCode, bool isReading = true);
3133
int ConvertWinErrorCode(int errorCode, bool isReading = true);
3234

@@ -50,6 +52,8 @@ int32 ShowOpenDialog(bool allowMulitpleSelection,
5052
wchar_t szFile[MAX_PATH];
5153
szFile[0] = 0;
5254

55+
FixFilename(initialDirectory);
56+
5357
// TODO (issue #64) - This method should be using IFileDialog instead of the
5458
/* outdated SHGetPathFromIDList and GetOpenFileName.
5559
@@ -172,6 +176,8 @@ int32 ShowOpenDialog(bool allowMulitpleSelection,
172176

173177
int32 ReadDir(ExtensionString path, CefRefPtr<CefListValue>& directoryContents)
174178
{
179+
FixFilename(path);
180+
175181
path += L"\\*";
176182

177183
WIN32_FIND_DATA ffd;
@@ -213,6 +219,8 @@ int32 ReadDir(ExtensionString path, CefRefPtr<CefListValue>& directoryContents)
213219

214220
int32 GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& isDir)
215221
{
222+
FixFilename(filename);
223+
216224
DWORD dwAttr = GetFileAttributes(filename.c_str());
217225

218226
if (dwAttr == INVALID_FILE_ATTRIBUTES) {
@@ -233,6 +241,8 @@ int32 GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& i
233241

234242
int32 ReadFile(ExtensionString filename, ExtensionString encoding, std::string& contents)
235243
{
244+
FixFilename(filename);
245+
236246
if (encoding != L"utf8")
237247
return ERR_UNSUPPORTED_ENCODING;
238248

@@ -272,6 +282,8 @@ int32 ReadFile(ExtensionString filename, ExtensionString encoding, std::string&
272282

273283
int32 WriteFile(ExtensionString filename, std::string contents, ExtensionString encoding)
274284
{
285+
FixFilename(filename);
286+
275287
if (encoding != L"utf8")
276288
return ERR_UNSUPPORTED_ENCODING;
277289

@@ -304,6 +316,11 @@ int32 DeleteFileOrDirectory(ExtensionString filename)
304316
return NO_ERROR;
305317
}
306318

319+
void FixFilename(ExtensionString& filename)
320+
{
321+
// Convert '/' to '\'
322+
replace(filename.begin(), filename.end(), '/', '\\');
323+
}
307324

308325
// Maps errors from errno.h to the brackets error codes
309326
// found in brackets_extensions.js

0 commit comments

Comments
 (0)