Introduce plat_file_check and use it for ROM existence checking

This commit is contained in:
Cacodemon345
2025-09-20 00:30:29 +06:00
parent 9cdb597760
commit fdbf4a066b
4 changed files with 59 additions and 9 deletions

View File

@@ -64,6 +64,8 @@
# include <sys/mman.h>
#endif
#include <sys/stat.h>
#ifdef Q_OS_OPENBSD
# include <pthread_np.h>
#endif
@@ -250,6 +252,22 @@ plat_dir_check(char *path)
return fi.isDir() ? 1 : 0;
}
int
plat_file_check(const char *path)
{
#ifdef _WIN32
auto data = QString::fromUtf8(path).toStdWString();
auto res = GetFileAttributesW(data.c_str());
return (res != INVALID_FILE_ATTRIBUTES && !(res & FILE_ATTRIBUTE_DIRECTORY));
#else
struct stat dummy;
if (stat(path, &dummy) < 0) {
return 0;
}
return !S_ISDIR(dummy.st_mode);
#endif
}
int
plat_getcwd(char *bufp, int max)
{