log errno when failing to open a disk or folder. Better win32 errors
Log errno when failing to open a disk or folder (game scanner) Better win32 error codes with GetLastError() for opendir, stat, access
This commit is contained in:
parent
2f47f72957
commit
853830a446
|
@ -617,7 +617,7 @@ dirent_first(
|
|||
/* Failed to re-open directory: no directory entry in memory */
|
||||
dirp->cached = 0;
|
||||
datap = NULL;
|
||||
|
||||
dirent_set_errno(GetLastError()); /* Not a valid errno but better than nothing */
|
||||
}
|
||||
return datap;
|
||||
}
|
||||
|
@ -651,6 +651,8 @@ dirent_next(
|
|||
FindClose (dirp->handle);
|
||||
dirp->handle = INVALID_HANDLE_VALUE;
|
||||
p = NULL;
|
||||
if (GetLastError() != ERROR_NO_MORE_FILES)
|
||||
dirent_set_errno(GetLastError());
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
@ -11,7 +11,10 @@ Disc* cdi_parse(const char* file, std::vector<u8> *digest)
|
|||
FILE *fsource = nowide::fopen(file, "rb");
|
||||
|
||||
if (fsource == nullptr)
|
||||
{
|
||||
WARN_LOG(COMMON, "Cannot open file '%s' errno %d", file, errno);
|
||||
throw FlycastException(std::string("Cannot open CDI file ") + file);
|
||||
}
|
||||
|
||||
image_s image = { 0 };
|
||||
track_s track = { 0 };
|
||||
|
@ -78,10 +81,10 @@ Disc* cdi_parse(const char* file, std::vector<u8> *digest)
|
|||
#endif
|
||||
if (ft)
|
||||
{
|
||||
ft=false;
|
||||
ft = false;
|
||||
Session s;
|
||||
s.StartFAD=track.pregap_length + track.start_lba;
|
||||
s.FirstTrack=track.global_current_track;
|
||||
s.StartFAD = track.pregap_length + track.start_lba;
|
||||
s.FirstTrack = (u8)track.global_current_track;
|
||||
rv->sessions.push_back(s);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,10 @@ void CHDDisc::tryOpen(const char* file)
|
|||
{
|
||||
fp = nowide::fopen(file, "rb");
|
||||
if (fp == nullptr)
|
||||
{
|
||||
WARN_LOG(COMMON, "Cannot open file '%s' errno %d", file, errno);
|
||||
throw FlycastException(std::string("Cannot open CHD file ") + file);
|
||||
}
|
||||
|
||||
chd_error err = chd_open_file(fp, CHD_OPEN_READ, 0, &chd);
|
||||
|
||||
|
@ -117,23 +120,23 @@ void CHDDisc::tryOpen(const char* file)
|
|||
char type[16], subtype[16], pgtype[16], pgsub[16];
|
||||
int tkid=-1, frames=0, pregap=0, postgap=0, padframes=0;
|
||||
|
||||
err = chd_get_metadata(chd, CDROM_TRACK_METADATA2_TAG, tracks.size(), temp, sizeof(temp), &temp_len, &tag, &flags);
|
||||
err = chd_get_metadata(chd, CDROM_TRACK_METADATA2_TAG, (u32)tracks.size(), temp, sizeof(temp), &temp_len, &tag, &flags);
|
||||
if (err == CHDERR_NONE)
|
||||
{
|
||||
//"TRACK:%d TYPE:%s SUBTYPE:%s FRAMES:%d PREGAP:%d PGTYPE:%s PGSUB:%s POSTGAP:%d"
|
||||
sscanf(temp, CDROM_TRACK_METADATA2_FORMAT, &tkid, type, subtype, &frames, &pregap, pgtype, pgsub, &postgap);
|
||||
}
|
||||
else if (CHDERR_NONE== (err = chd_get_metadata(chd, CDROM_TRACK_METADATA_TAG, tracks.size(), temp, sizeof(temp), &temp_len, &tag, &flags)) )
|
||||
else if (CHDERR_NONE== (err = chd_get_metadata(chd, CDROM_TRACK_METADATA_TAG, (u32)tracks.size(), temp, sizeof(temp), &temp_len, &tag, &flags)) )
|
||||
{
|
||||
//CDROM_TRACK_METADATA_FORMAT "TRACK:%d TYPE:%s SUBTYPE:%s FRAMES:%d"
|
||||
sscanf(temp, CDROM_TRACK_METADATA_FORMAT, &tkid, type, subtype, &frames);
|
||||
}
|
||||
else
|
||||
{
|
||||
err = chd_get_metadata(chd, GDROM_OLD_METADATA_TAG, tracks.size(), temp, sizeof(temp), &temp_len, &tag, &flags);
|
||||
err = chd_get_metadata(chd, GDROM_OLD_METADATA_TAG, (u32)tracks.size(), temp, sizeof(temp), &temp_len, &tag, &flags);
|
||||
if (err != CHDERR_NONE)
|
||||
{
|
||||
err = chd_get_metadata(chd, GDROM_TRACK_METADATA_TAG, tracks.size(), temp, sizeof(temp), &temp_len, &tag, &flags);
|
||||
err = chd_get_metadata(chd, GDROM_TRACK_METADATA_TAG, (u32)tracks.size(), temp, sizeof(temp), &temp_len, &tag, &flags);
|
||||
}
|
||||
if (err == CHDERR_NONE)
|
||||
{
|
||||
|
|
|
@ -53,7 +53,10 @@ Disc* cue_parse(const char* file, std::vector<u8> *digest)
|
|||
FILE *fsource = nowide::fopen(file, "rb");
|
||||
|
||||
if (fsource == nullptr)
|
||||
{
|
||||
WARN_LOG(COMMON, "Cannot open file '%s' errno %d", file, errno);
|
||||
throw FlycastException(std::string("Cannot open CUE file ") + file);
|
||||
}
|
||||
|
||||
size_t cue_len = flycast::fsize(fsource);
|
||||
|
||||
|
@ -107,7 +110,7 @@ Disc* cue_parse(const char* file, std::vector<u8> *digest)
|
|||
current_fad += 11400;
|
||||
|
||||
Session ses;
|
||||
ses.FirstTrack = disc->tracks.size() + 1;
|
||||
ses.FirstTrack = (u8)disc->tracks.size() + 1;
|
||||
ses.StartFAD = current_fad;
|
||||
disc->sessions.push_back(ses);
|
||||
DEBUG_LOG(GDROM, "session[%zd]: 1st track: %d FAD:%d", disc->sessions.size(), ses.FirstTrack, ses.StartFAD);
|
||||
|
|
|
@ -64,7 +64,10 @@ Disc* load_gdi(const char* file, std::vector<u8> *digest)
|
|||
{
|
||||
FILE *t = nowide::fopen(file, "rb");
|
||||
if (t == nullptr)
|
||||
{
|
||||
WARN_LOG(COMMON, "Cannot open file '%s' errno %d", file, errno);
|
||||
throw FlycastException(std::string("Cannot open GDI file ") + file);
|
||||
}
|
||||
|
||||
size_t gdi_len = flycast::fsize(t);
|
||||
|
||||
|
|
|
@ -80,18 +80,30 @@ inline int closedir(DIR *dirstream)
|
|||
return ::_wclosedir((_WDIR *)dirstream);
|
||||
}
|
||||
|
||||
inline static void _set_errno(int error)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
::_set_errno (error);
|
||||
#else
|
||||
errno = error;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int stat(const char *filename, struct stat *buf)
|
||||
{
|
||||
nowide::wstackstring wname;
|
||||
if (!wname.convert(filename)) {
|
||||
errno = EINVAL;
|
||||
_set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
#ifdef TARGET_UWP
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrs;
|
||||
bool rc = GetFileAttributesExFromAppW(wname.c_str(), GetFileExInfoStandard, &attrs);
|
||||
if (!rc)
|
||||
{
|
||||
_set_errno(GetLastError());
|
||||
return -1;
|
||||
}
|
||||
memset(buf, 0, sizeof(struct stat));
|
||||
if (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
buf->st_mode = S_IFDIR;
|
||||
|
@ -129,16 +141,27 @@ inline int access(const char *filename, int how)
|
|||
{
|
||||
nowide::wstackstring wname;
|
||||
if (!wname.convert(filename)) {
|
||||
errno = EINVAL;
|
||||
_set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
#ifdef TARGET_UWP
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrs;
|
||||
bool rc = GetFileAttributesExFromAppW(wname.c_str(), GetFileExInfoStandard, &attrs);
|
||||
if (!rc)
|
||||
{
|
||||
if (GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_PATH_NOT_FOUND)
|
||||
_set_errno(ENOENT);
|
||||
else if (GetLastError() == ERROR_ACCESS_DENIED)
|
||||
_set_errno(EACCES);
|
||||
else
|
||||
_set_errno(GetLastError());
|
||||
return -1;
|
||||
}
|
||||
if (how != R_OK && (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
|
||||
{
|
||||
_set_errno(EACCES);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
#else
|
||||
|
@ -237,7 +260,10 @@ public:
|
|||
{
|
||||
struct stat st;
|
||||
if (flycast::stat(childPath.c_str(), &st) != 0)
|
||||
{
|
||||
WARN_LOG(COMMON, "Cannot stat file '%s' errno 0x%x", childPath.c_str(), errno);
|
||||
continue;
|
||||
}
|
||||
if (S_ISDIR(st.st_mode))
|
||||
isDir = true;
|
||||
}
|
||||
|
@ -250,7 +276,7 @@ public:
|
|||
DIR *childDir = flycast::opendir(childPath.c_str());
|
||||
if (childDir == nullptr)
|
||||
{
|
||||
INFO_LOG(COMMON, "Cannot read directory '%s'", childPath.c_str());
|
||||
WARN_LOG(COMMON, "Cannot read subdirectory '%s' errno 0x%x", childPath.c_str(), errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -275,7 +301,7 @@ public:
|
|||
{
|
||||
DIR *dir = flycast::opendir(root.c_str());
|
||||
if (dir == nullptr)
|
||||
INFO_LOG(COMMON, "Cannot read directory '%s'", root.c_str());
|
||||
WARN_LOG(COMMON, "Cannot read directory '%s' errno 0x%x", root.c_str(), errno);
|
||||
|
||||
return {dir, root};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue