mirror of
https://github.com/libretro/ppsspp.git
synced 2025-02-21 17:30:46 +00:00
Warning fixes, add deleteDir()
This commit is contained in:
parent
c94767905a
commit
8e5890a7e2
@ -98,7 +98,7 @@ Clip *clip_load(const char *filename) {
|
||||
uint8_t *filedata;
|
||||
size_t size;
|
||||
filedata = VFSReadFile(filename, &size);
|
||||
num_samples = stb_vorbis_decode_memory(filedata, size, &num_channels, &data);
|
||||
num_samples = (int)stb_vorbis_decode_memory(filedata, size, &num_channels, &data);
|
||||
if (num_samples <= 0)
|
||||
return NULL;
|
||||
sample_rate = 44100;
|
||||
|
@ -216,7 +216,7 @@ void ChunkFile::writeWString(String str) {
|
||||
|
||||
void ChunkFile::writeWString(const std::string &str) {
|
||||
unsigned short *text;
|
||||
int len=str.length();
|
||||
size_t len = str.length();
|
||||
#ifdef UNICODE
|
||||
#error
|
||||
text = str.c_str();
|
||||
@ -234,7 +234,7 @@ void ChunkFile::writeWString(const std::string &str) {
|
||||
}
|
||||
|
||||
static void toUnicode(const std::string &str, uint16 *t) {
|
||||
for (int i=0; i<(int)str.size(); i++) {
|
||||
for (size_t i = 0; i < str.size(); i++) {
|
||||
*t++ = str[i];
|
||||
}
|
||||
*t++ = '\0';
|
||||
|
@ -49,7 +49,7 @@ std::string LAMEFile::readAll() {
|
||||
return s;
|
||||
}
|
||||
|
||||
int LAMEFile::write(const void *data, int size) {
|
||||
int LAMEFile::write(const void *data, size_t size) {
|
||||
if (isOpen) {
|
||||
return fwrite(data, 1, size, file_); //we return the number of bytes that actually got written
|
||||
} else {
|
||||
@ -57,7 +57,7 @@ int LAMEFile::write(const void *data, int size) {
|
||||
}
|
||||
}
|
||||
|
||||
int LAMEFile::read(void *data, int size) {
|
||||
int LAMEFile::read(void *data, size_t size) {
|
||||
if (isOpen) {
|
||||
return fread(data, 1, size, file_);
|
||||
} else {
|
||||
|
@ -29,14 +29,14 @@ public:
|
||||
|
||||
void writeInt(int i);
|
||||
void writeChar(char i);
|
||||
int write(const void *data, int size);
|
||||
int write(const void *data, size_t size);
|
||||
void write(const std::string &str) {
|
||||
write((void *)str.data(), str.size());
|
||||
}
|
||||
|
||||
int readInt();
|
||||
char readChar();
|
||||
int read(void *data, int size);
|
||||
int read(void *data, size_t size);
|
||||
|
||||
std::string readAll();
|
||||
|
||||
|
@ -171,11 +171,13 @@ bool getFileInfo(const char *path, FileInfo *fileInfo)
|
||||
if (!GetFileAttributesExA(path, GetFileExInfoStandard, &attrs)) {
|
||||
fileInfo->size = 0;
|
||||
fileInfo->isDirectory = false;
|
||||
fileInfo->exists = false;
|
||||
return false;
|
||||
}
|
||||
fileInfo->size = (uint64_t)attrs.nFileSizeLow | ((uint64_t)attrs.nFileSizeHigh << 32);
|
||||
fileInfo->isDirectory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
fileInfo->isWritable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
|
||||
fileInfo->exists = true;
|
||||
#else
|
||||
struct stat64 file_info;
|
||||
|
||||
@ -186,12 +188,14 @@ bool getFileInfo(const char *path, FileInfo *fileInfo)
|
||||
|
||||
if (result < 0) {
|
||||
WLOG("IsDirectory: stat failed on %s", path);
|
||||
fileInfo->exists = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
fileInfo->isDirectory = S_ISDIR(file_info.st_mode);
|
||||
fileInfo->isWritable = false;
|
||||
fileInfo->size = file_info.st_size;
|
||||
fileInfo->exists = true;
|
||||
// HACK: approximation
|
||||
if (file_info.st_mode & 0200)
|
||||
fileInfo->isWritable = true;
|
||||
@ -303,13 +307,25 @@ void deleteFile(const char *file)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void deleteDir(const char *dir)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!RemoveDirectory(dir)) {
|
||||
ELOG("Error deleting directory %s: %i", dir, GetLastError());
|
||||
}
|
||||
#else
|
||||
rmdir(dir);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
std::string getDir(const std::string &path)
|
||||
{
|
||||
if (path == "/")
|
||||
return path;
|
||||
int n = path.size() - 1;
|
||||
int n = (int)path.size() - 1;
|
||||
while (n >= 0 && path[n] != '\\' && path[n] != '/')
|
||||
n--;
|
||||
std::string cutpath = n > 0 ? path.substr(0, n) : "";
|
||||
|
@ -37,6 +37,7 @@ std::string getFileExtension(const std::string &fn);
|
||||
bool getFileInfo(const char *path, FileInfo *fileInfo);
|
||||
size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files, const char *filter = 0);
|
||||
void deleteFile(const char *file);
|
||||
void deleteDir(const char *file);
|
||||
bool exists(const std::string &filename);
|
||||
void mkDir(const std::string &path);
|
||||
std::string getDir(const std::string &path);
|
||||
|
@ -236,9 +236,9 @@ void VFSShutdown() {
|
||||
}
|
||||
|
||||
uint8_t *VFSReadFile(const char *filename, size_t *size) {
|
||||
int fn_len = strlen(filename);
|
||||
int fn_len = (int)strlen(filename);
|
||||
for (int i = 0; i < num_entries; i++) {
|
||||
int prefix_len = strlen(entries[i].prefix);
|
||||
int prefix_len = (int)strlen(entries[i].prefix);
|
||||
if (prefix_len >= fn_len) continue;
|
||||
if (0 == memcmp(filename, entries[i].prefix, prefix_len)) {
|
||||
ILOG("Prefix match: %s (%s) -> %s", entries[i].prefix, filename, filename + prefix_len);
|
||||
@ -256,9 +256,9 @@ uint8_t *VFSReadFile(const char *filename, size_t *size) {
|
||||
|
||||
bool VFSGetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter)
|
||||
{
|
||||
int fn_len = strlen(path);
|
||||
int fn_len = (int)strlen(path);
|
||||
for (int i = 0; i < num_entries; i++) {
|
||||
int prefix_len = strlen(entries[i].prefix);
|
||||
int prefix_len = (int)strlen(entries[i].prefix);
|
||||
if (prefix_len >= fn_len) continue;
|
||||
if (0 == memcmp(path, entries[i].prefix, prefix_len)) {
|
||||
if (entries[i].reader->GetFileListing(path + prefix_len, listing, filter))
|
||||
@ -273,9 +273,9 @@ bool VFSGetFileListing(const char *path, std::vector<FileInfo> *listing, const c
|
||||
|
||||
bool VFSGetFileInfo(const char *path, FileInfo *info)
|
||||
{
|
||||
int fn_len = strlen(path);
|
||||
int fn_len = (int)strlen(path);
|
||||
for (int i = 0; i < num_entries; i++) {
|
||||
int prefix_len = strlen(entries[i].prefix);
|
||||
int prefix_len = (int)strlen(entries[i].prefix);
|
||||
if (prefix_len >= fn_len) continue;
|
||||
if (0 == memcmp(path, entries[i].prefix, prefix_len)) {
|
||||
return entries[i].reader->GetFileInfo(path + prefix_len, info);
|
||||
|
@ -147,7 +147,7 @@ int LoadZIM(const char *filename, int *width, int *height, int *format, uint8_t
|
||||
if (!buffer) {
|
||||
return 0;
|
||||
}
|
||||
int retval = LoadZIMPtr(buffer, size, width, height, format, image);
|
||||
int retval = LoadZIMPtr(buffer, (int)size, width, height, format, image);
|
||||
if (!retval) {
|
||||
ELOG("Not a valid ZIM file: %s", filename);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user