Skip to content

Commit

Permalink
Test and warn of case mismatch on Windows
Browse files Browse the repository at this point in the history
Will throw a warning when a file is opened with a different case than what is stored on the Windows filesystem.
  • Loading branch information
reduz authored and akien-mga committed Apr 18, 2018
1 parent 3018132 commit 44989bc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions drivers/windows/file_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,31 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
/* pretty much every implementation that uses fopen as primary
backend supports utf8 encoding */


struct _stat st;
if (_wstat(path.c_str(), &st) == 0) {

if (!S_ISREG(st.st_mode))
return ERR_FILE_CANT_OPEN;
};

#ifdef TOOLS_ENABLED
if (p_mode_flags==READ) {
WIN32_FIND_DATAW d = {0};
HANDLE f = FindFirstFileW(filename.c_str(),&d);
if (f) {
String fname = d.cFileName;
if (fname!=String()) {

String base_file = filename.get_file();
if (base_file!=fname && base_file.findn(fname)==0) {
WARN_PRINTS("Case mismatch opening file '"+base_file+"', stored as '"+fname+"' in the filesystem. This file will not open when exported to other platforms.");
}
}
FindClose(f);
}
}
#endif
if (is_backup_save_enabled() && p_mode_flags & WRITE && !(p_mode_flags & READ)) {
save_path = path;
path = path + ".tmp";
Expand Down

0 comments on commit 44989bc

Please sign in to comment.