diff --git a/audio/mixer.cpp b/audio/mixer.cpp index de19807f4..45d6c4c3b 100644 --- a/audio/mixer.cpp +++ b/audio/mixer.cpp @@ -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; diff --git a/file/chunk_file.cpp b/file/chunk_file.cpp index 738c32ad2..396b07753 100644 --- a/file/chunk_file.cpp +++ b/file/chunk_file.cpp @@ -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'; diff --git a/file/easy_file.cpp b/file/easy_file.cpp index 30851dff4..f8d73d125 100644 --- a/file/easy_file.cpp +++ b/file/easy_file.cpp @@ -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 { diff --git a/file/easy_file.h b/file/easy_file.h index b7114050b..fbc439adf 100644 --- a/file/easy_file.h +++ b/file/easy_file.h @@ -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(); diff --git a/file/file_util.cpp b/file/file_util.cpp index 681a6464b..c95422841 100644 --- a/file/file_util.cpp +++ b/file/file_util.cpp @@ -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) : ""; diff --git a/file/file_util.h b/file/file_util.h index b17a804d0..867f1a9d3 100644 --- a/file/file_util.h +++ b/file/file_util.h @@ -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 *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); diff --git a/file/zip_read.cpp b/file/zip_read.cpp index 02add6f0f..cb210b703 100644 --- a/file/zip_read.cpp +++ b/file/zip_read.cpp @@ -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 *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 *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); diff --git a/image/zim_load.cpp b/image/zim_load.cpp index 7b5bf3e85..5f78345ed 100644 --- a/image/zim_load.cpp +++ b/image/zim_load.cpp @@ -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); }