diff --git a/Common/ChunkFile.cpp b/Common/ChunkFile.cpp index 284e774562c6..23df5078f678 100644 --- a/Common/ChunkFile.cpp +++ b/Common/ChunkFile.cpp @@ -169,7 +169,7 @@ CChunkFileReader::Error CChunkFileReader::LoadFile(const std::string& _rFilename } // Check file size - const u64 fileSize = File::GetSize(_rFilename); + const u64 fileSize = File::GetFileSize(_rFilename); static const u64 headerSize = sizeof(SChunkHeader); if (fileSize < headerSize) { diff --git a/Common/CommonFuncs.h b/Common/CommonFuncs.h index 69850cb4f91b..c26b696afbce 100644 --- a/Common/CommonFuncs.h +++ b/Common/CommonFuncs.h @@ -77,8 +77,6 @@ inline u64 __rotr64(u64 x, unsigned int shift){ #define fseeko _fseeki64 #define ftello _ftelli64 #define atoll _atoi64 - #define stat64 _stat64 - #define fstat64 _fstat64 #define fileno _fileno #ifndef _XBOX #if _M_IX86 diff --git a/Common/FileUtil.cpp b/Common/FileUtil.cpp index a9620f4fade1..673875cf190a 100644 --- a/Common/FileUtil.cpp +++ b/Common/FileUtil.cpp @@ -154,33 +154,31 @@ bool Exists(const std::string &filename) { #endif } -// Returns true if stat represents a directory -bool IsDirectory(const struct stat64 &file_info) -{ - return S_ISDIR(file_info.st_mode); -} - // Returns true if filename is a directory bool IsDirectory(const std::string &filename) { std::string fn = filename; StripTailDirSlashes(fn); - struct stat64 file_info; -#if defined(_WIN32) && defined(UNICODE) +#if defined(_WIN32) std::wstring copy = ConvertUTF8ToWString(fn); - int result = _wstat64(copy.c_str(), &file_info); + DWORD result = GetFileAttributes(copy.c_str()); + if (result == INVALID_FILE_ATTRIBUTES) { + WARN_LOG(COMMON, "GetFileAttributes failed on %s: %08x", fn.c_str(), GetLastError()); + return false; + } + return (result & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY; #else std::string copy(fn); + struct stat64 file_info; int result = stat64(copy.c_str(), &file_info); -#endif if (result < 0) { WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s", fn.c_str(), GetLastErrorMsg()); return false; } - - return IsDirectory(file_info); + return S_ISDIR(file_info.st_mode); +#endif } // Deletes a given filename, return true on success @@ -423,72 +421,67 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename) #endif } -bool GetModifTime(const std::string &filename, tm &return_time) -{ +bool GetModifTime(const std::string &filename, tm &return_time) { memset(&return_time, 0, sizeof(return_time)); - if (!Exists(filename)) - { + if (!Exists(filename)) { WARN_LOG(COMMON, "GetCreateTime: failed %s: No such file", filename.c_str()); return false; } - if (IsDirectory(filename)) - { + if (IsDirectory(filename)) { WARN_LOG(COMMON, "GetCreateTime: failed %s: is a directory", filename.c_str()); return false; } +#ifdef _WIN32 + struct _stat64 buf; + // TODO: Find a Win32 way + if (_wstat64(ConvertUTF8ToWString(filename.c_str()).c_str(), &buf) == 0) { + INFO_LOG(COMMON, "GetCreateTime: %s: %lld", filename.c_str(), (long long)buf.st_mtime); + localtime_r((time_t*)&buf.st_mtime, &return_time); + return true; + } +#else struct stat64 buf; - if (stat64(filename.c_str(), &buf) == 0) - { + if (stat64(ConvertUTF8ToWString(filename.c_str()).c_str(), &buf) == 0) { INFO_LOG(COMMON, "GetCreateTime: %s: %lld", filename.c_str(), (long long)buf.st_mtime); localtime_r((time_t*)&buf.st_mtime, &return_time); return true; } - +#endif ERROR_LOG(COMMON, "GetCreateTime: Stat failed %s: %s", filename.c_str(), GetLastErrorMsg()); return false; } -// Returns the size of filename (64bit) -u64 GetSize(const std::string &filename) -{ - struct stat64 file_info; +// Returns the size of file (64bit) +// TODO: Add a way to return an error. +u64 GetFileSize(const std::string &filename) { #if defined(_WIN32) && defined(UNICODE) - int result = _wstat64(ConvertUTF8ToWString(filename).c_str(), &file_info); + WIN32_FILE_ATTRIBUTE_DATA attr; + if (!GetFileAttributesEx(ConvertUTF8ToWString(filename).c_str(), GetFileExInfoStandard, &attr)) + return 0; + if (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + return 0; + return ((u64)attr.nFileSizeHigh << 32) | (u64)attr.nFileSizeLow; #else + struct stat64 file_info; int result = stat64(filename.c_str(), &file_info); -#endif - if (result != 0) - { + if (result != 0) { WARN_LOG(COMMON, "GetSize: failed %s: No such file", filename.c_str()); return 0; } - - if (IsDirectory(file_info)) - { + if (IsDirectory(file_info)) { WARN_LOG(COMMON, "GetSize: failed %s: is a directory", filename.c_str()); return 0; } DEBUG_LOG(COMMON, "GetSize: %s: %lld", filename.c_str(), (long long)file_info.st_size); return file_info.st_size; -} - -// Overloaded GetSize, accepts file descriptor -u64 GetSize(const int fd) -{ - struct stat64 buf; - if (fstat64(fd, &buf) != 0) { - ERROR_LOG(COMMON, "GetSize: stat failed %i: %s", - fd, GetLastErrorMsg()); - return 0; - } - return buf.st_size; +#endif } // Overloaded GetSize, accepts FILE* -u64 GetSize(FILE *f) +u64 GetFileSize(FILE *f) { // can't use off_t here because it can be 32-bit u64 pos = ftello(f); @@ -780,7 +773,7 @@ void IOFile::SetHandle(std::FILE* file) u64 IOFile::GetSize() { if (IsOpen()) - return File::GetSize(m_file); + return File::GetFileSize(m_file); else return 0; } diff --git a/Common/FileUtil.h b/Common/FileUtil.h index d903a1ba24e9..26e9713dc366 100644 --- a/Common/FileUtil.h +++ b/Common/FileUtil.h @@ -59,13 +59,10 @@ bool IsDirectory(const std::string &filename); bool GetModifTime(const std::string &filename, tm &return_time); // Returns the size of filename (64bit) -u64 GetSize(const std::string &filename); - -// Overloaded GetSize, accepts file descriptor -u64 GetSize(const int fd); +u64 GetFileSize(const std::string &filename); // Overloaded GetSize, accepts FILE* -u64 GetSize(FILE *f); +u64 GetFileSize(FILE *f); // Returns true if successful, or path already exists. bool CreateDir(const std::string &filename); diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 35bd4cec6ebc..66f469bc4b0e 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -660,7 +660,7 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) { x.name = filename; std::string fullName = GetLocalPath(filename); - if (! File::Exists(fullName)) { + if (!File::Exists(fullName)) { #if HOST_IS_CASE_SENSITIVE if (! FixPathCase(basePath,filename, FPC_FILE_MUST_EXIST)) return x; @@ -675,21 +675,23 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) { x.type = File::IsDirectory(fullName) ? FILETYPE_DIRECTORY : FILETYPE_NORMAL; x.exists = true; - if (x.type != FILETYPE_DIRECTORY) - { + if (x.type != FILETYPE_DIRECTORY) { #ifdef _WIN32 struct _stat64i32 s; - _wstat64i32(ConvertUTF8ToWString(fullName).c_str(), &s); + // TODO: Find a Win32 way to get the atime, ctime etc. + if (_wstat64i32(ConvertUTF8ToWString(fullName).c_str(), &s) != 0) { + ERROR_LOG(FILESYS, "DirectoryFileSystem::GetFileInfo: _wstat64i32 failed: %s", fullName.c_str()); + } #else struct stat s; stat(fullName.c_str(), &s); #endif - x.size = File::GetSize(fullName); + x.size = File::GetFileSize(fullName); x.access = s.st_mode & 0x1FF; - localtime_r((time_t*)&s.st_atime,&x.atime); - localtime_r((time_t*)&s.st_ctime,&x.ctime); - localtime_r((time_t*)&s.st_mtime,&x.mtime); + localtime_r((time_t*)&s.st_atime, &x.atime); + localtime_r((time_t*)&s.st_ctime, &x.ctime); + localtime_r((time_t*)&s.st_mtime, &x.mtime); } return x; @@ -703,8 +705,7 @@ bool DirectoryFileSystem::GetHostPath(const std::string &inpath, std::string &ou #ifdef _WIN32 #define FILETIME_FROM_UNIX_EPOCH_US 11644473600000000ULL -static void tmFromFiletime(tm &dest, FILETIME &src) -{ +static void tmFromFiletime(tm &dest, FILETIME &src) { u64 from_1601_us = (((u64) src.dwHighDateTime << 32ULL) + (u64) src.dwLowDateTime) / 10ULL; u64 from_1970_us = from_1601_us - FILETIME_FROM_UNIX_EPOCH_US; diff --git a/Core/FileSystems/VirtualDiscFileSystem.cpp b/Core/FileSystems/VirtualDiscFileSystem.cpp index 3cdc69701218..ab401597f4bf 100644 --- a/Core/FileSystems/VirtualDiscFileSystem.cpp +++ b/Core/FileSystems/VirtualDiscFileSystem.cpp @@ -130,7 +130,7 @@ void VirtualDiscFileSystem::LoadFileListIndex() { ERROR_LOG(FILESYS, "Unable to open virtual file: %s", entry.fileName.c_str()); } } else { - entry.totalSize = File::GetSize(GetLocalPath(entry.fileName)); + entry.totalSize = File::GetFileSize(GetLocalPath(entry.fileName)); } // Try to keep currentBlockIndex sane, in case there are other files. @@ -272,7 +272,7 @@ int VirtualDiscFileSystem::getFileListIndex(std::string& fileName) FileListEntry entry = {""}; entry.fileName = fileName; - entry.totalSize = File::GetSize(fullName); + entry.totalSize = File::GetFileSize(fullName); entry.firstBlock = currentBlockIndex; currentBlockIndex += (entry.totalSize+2047)/2048; @@ -595,10 +595,18 @@ PSPFileInfo VirtualDiscFileSystem::GetFileInfo(std::string filename) { } if (x.type != FILETYPE_DIRECTORY) { +#ifdef _WIN32 + struct _stat64i32 s; + // TODO: Find a Win32 way to get the atime, ctime etc. + if (_wstat64i32(ConvertUTF8ToWString(fullName).c_str(), &s) != 0) { + ERROR_LOG(FILESYS, "DirectoryFileSystem::GetFileInfo: _wstat64i32 failed: %s", fullName.c_str()); + } +#else struct stat s; stat(fullName.c_str(), &s); +#endif - x.size = File::GetSize(fullName); + x.size = File::GetFileSize(fullName); x.startSector = fileList[fileIndex].firstBlock; x.numSectors = (x.size+2047)/2048; diff --git a/Core/System.cpp b/Core/System.cpp index ea49f8777f49..d728a45dfb11 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -591,6 +591,7 @@ void InitSysDirectories() { if (!File::Exists(g_Config.memStickDirectory)) { if (!File::CreateDir(g_Config.memStickDirectory)) g_Config.memStickDirectory = myDocsPath; + INFO_LOG(COMMON, "Memstick directory not present, creating at '%s'", g_Config.memStickDirectory.c_str()); } const std::string testFile = g_Config.memStickDirectory + "/_writable_test.$$$"; diff --git a/ext/native/gfx_es2/glsl_program.cpp b/ext/native/gfx_es2/glsl_program.cpp index a620e29fdb04..c5e534adaa8c 100644 --- a/ext/native/gfx_es2/glsl_program.cpp +++ b/ext/native/gfx_es2/glsl_program.cpp @@ -74,28 +74,6 @@ GLSLProgram *glsl_create_source(const char *vshader_src, const char *fshader_src return program; } -bool glsl_up_to_date(GLSLProgram *program) { - struct stat vs, fs; - stat(program->vshader_filename, &vs); - stat(program->fshader_filename, &fs); - if ((time_t)vs.st_mtime != program->vshader_mtime || - (time_t)fs.st_mtime != program->fshader_mtime) { - return false; - } else { - return true; - } -} - -void glsl_refresh() { - ILOG("glsl_refresh()"); - for (std::set::const_iterator iter = active_programs.begin(); - iter != active_programs.end(); ++iter) { - if (!glsl_up_to_date(*iter)) { - glsl_recompile(*iter); - } - } -} - // Not wanting to change ReadLocalFile semantics. // Needs to use delete [], not delete like auto_ptr, and can't use unique_ptr because of Symbian. struct AutoCharArrayBuf { diff --git a/ext/native/gfx_es2/glsl_program.h b/ext/native/gfx_es2/glsl_program.h index c6ee880d273a..cb4861aa81c5 100644 --- a/ext/native/gfx_es2/glsl_program.h +++ b/ext/native/gfx_es2/glsl_program.h @@ -61,8 +61,3 @@ void glsl_bind(const GLSLProgram *program); void glsl_unbind(); int glsl_attrib_loc(const GLSLProgram *program, const char *name); int glsl_uniform_loc(const GLSLProgram *program, const char *name); - -// Expensive, try to only call this once per second or so and only when developing. -// fstat-s all the source files of all the shaders to see if they -// should be recompiled, and recompiles them if so. -void glsl_refresh();