diff --git a/bsnes/nall/config.hpp b/bsnes/nall/config.hpp index 1e1f8162..f555158e 100755 --- a/bsnes/nall/config.hpp +++ b/bsnes/nall/config.hpp @@ -102,7 +102,7 @@ namespace nall { virtual bool save(const char *filename) const { file fp; - if(fp.open(filename, file::mode_write)) { + if(fp.open(filename, file::mode::write)) { for(unsigned i = 0; i < list.size(); i++) { string output; output << list[i].name << " = " << list[i].get(); diff --git a/bsnes/nall/directory.hpp b/bsnes/nall/directory.hpp index 7ee3398f..73da6e33 100755 --- a/bsnes/nall/directory.hpp +++ b/bsnes/nall/directory.hpp @@ -81,7 +81,7 @@ struct directory { inline lstring directory::contents(const string &pathname, const string &pattern) { lstring folders = directory::folders(pathname); //pattern search of contents() should only filter files lstring files = directory::files(pathname, pattern); - foreach(file, files) folders.append(file, pattern); + foreach(file, files) folders.append(file); return folders; } #else diff --git a/bsnes/nall/file.hpp b/bsnes/nall/file.hpp index 6c73e544..103c7d4a 100755 --- a/bsnes/nall/file.hpp +++ b/bsnes/nall/file.hpp @@ -26,12 +26,12 @@ namespace nall { class file { public: - enum FileMode { mode_read, mode_write, mode_readwrite, mode_writeread }; - enum SeekMode { seek_absolute, seek_relative }; + enum class mode : unsigned { read, write, readwrite, writeread }; + enum class index : unsigned { absolute, relative }; uint8_t read() { if(!fp) return 0xff; //file not open - if(file_mode == mode_write) return 0xff; //reads not permitted + if(file_mode == mode::write) return 0xff; //reads not permitted if(file_offset >= file_size) return 0xff; //cannot read past end of file buffer_sync(); return buffer[(file_offset++) & buffer_mask]; @@ -59,8 +59,8 @@ namespace nall { } void write(uint8_t data) { - if(!fp) return; //file not open - if(file_mode == mode_read) return; //writes not permitted + if(!fp) return; //file not open + if(file_mode == mode::read) return; //writes not permitted buffer_sync(); buffer[(file_offset++) & buffer_mask] = data; buffer_dirty = true; @@ -95,19 +95,19 @@ namespace nall { fflush(fp); } - void seek(int offset, SeekMode mode = seek_absolute) { + void seek(int offset, index index_ = index::absolute) { if(!fp) return; //file not open buffer_flush(); uintmax_t req_offset = file_offset; - switch(mode) { - case seek_absolute: req_offset = offset; break; - case seek_relative: req_offset += offset; break; + switch(index_) { + case index::absolute: req_offset = offset; break; + case index::relative: req_offset += offset; break; } if(req_offset < 0) req_offset = 0; //cannot seek before start of file if(req_offset > file_size) { - if(file_mode == mode_read) { //cannot seek past end of file + if(file_mode == mode::read) { //cannot seek past end of file req_offset = file_size; } else { //pad file to requested location file_offset = file_size; @@ -174,20 +174,20 @@ namespace nall { return fp; } - bool open(const char *fn, FileMode mode) { + bool open(const char *fn, mode mode_) { if(fp) return false; - switch(file_mode = mode) { + switch(file_mode = mode_) { #if !defined(_WIN32) - case mode_read: fp = fopen(fn, "rb"); break; - case mode_write: fp = fopen(fn, "wb+"); break; //need read permission for buffering - case mode_readwrite: fp = fopen(fn, "rb+"); break; - case mode_writeread: fp = fopen(fn, "wb+"); break; + case mode::read: fp = fopen(fn, "rb"); break; + case mode::write: fp = fopen(fn, "wb+"); break; //need read permission for buffering + case mode::readwrite: fp = fopen(fn, "rb+"); break; + case mode::writeread: fp = fopen(fn, "wb+"); break; #else - case mode_read: fp = _wfopen(utf16_t(fn), L"rb"); break; - case mode_write: fp = _wfopen(utf16_t(fn), L"wb+"); break; - case mode_readwrite: fp = _wfopen(utf16_t(fn), L"rb+"); break; - case mode_writeread: fp = _wfopen(utf16_t(fn), L"wb+"); break; + case mode::read: fp = _wfopen(utf16_t(fn), L"rb"); break; + case mode::write: fp = _wfopen(utf16_t(fn), L"wb+"); break; + case mode::readwrite: fp = _wfopen(utf16_t(fn), L"rb+"); break; + case mode::writeread: fp = _wfopen(utf16_t(fn), L"wb+"); break; #endif } if(!fp) return false; @@ -213,7 +213,7 @@ namespace nall { fp = 0; file_offset = 0; file_size = 0; - file_mode = mode_read; + file_mode = mode::read; } ~file() { @@ -231,7 +231,7 @@ namespace nall { FILE *fp; unsigned file_offset; unsigned file_size; - FileMode file_mode; + mode file_mode; void buffer_sync() { if(!fp) return; //file not open @@ -245,14 +245,14 @@ namespace nall { } void buffer_flush() { - if(!fp) return; //file not open - if(file_mode == mode_read) return; //buffer cannot be written to - if(buffer_offset < 0) return; //buffer unused - if(buffer_dirty == false) return; //buffer unmodified since read + if(!fp) return; //file not open + if(file_mode == mode::read) return; //buffer cannot be written to + if(buffer_offset < 0) return; //buffer unused + if(buffer_dirty == false) return; //buffer unmodified since read fseek(fp, buffer_offset, SEEK_SET); unsigned length = (buffer_offset + buffer_size) <= file_size ? buffer_size : (file_size & buffer_mask); if(length) unsigned unused = fwrite(buffer, 1, length, fp); - buffer_offset = -1; //invalidate buffer + buffer_offset = -1; //invalidate buffer buffer_dirty = false; } }; diff --git a/bsnes/nall/filemap.hpp b/bsnes/nall/filemap.hpp index a99d162b..52acb2fa 100755 --- a/bsnes/nall/filemap.hpp +++ b/bsnes/nall/filemap.hpp @@ -19,14 +19,16 @@ namespace nall { class filemap { public: - enum filemode { mode_read, mode_write, mode_readwrite, mode_writeread }; + enum class mode : unsigned { read, write, readwrite, writeread }; - bool open(const char *filename, filemode mode) { return p_open(filename, mode); } + bool opened() const { return p_opened(); } + bool open(const char *filename, mode mode_) { return p_open(filename, mode_); } void close() { return p_close(); } unsigned size() const { return p_size; } - uint8_t* handle() { return p_handle; } - const uint8_t* handle() const { return p_handle; } + uint8_t* data() { return p_handle; } + const uint8_t* data() const { return p_handle; } filemap() : p_size(0), p_handle(0) { p_ctor(); } + filemap(const char *filename, mode mode_) : p_size(0), p_handle(0) { p_ctor(); p_open(filename, mode_); } ~filemap() { p_dtor(); } private: @@ -40,31 +42,35 @@ namespace nall { HANDLE p_filehandle, p_maphandle; - bool p_open(const char *filename, filemode mode) { + bool p_opened() const { + return p_handle; + } + + bool p_open(const char *filename, mode mode_) { int desired_access, creation_disposition, flprotect, map_access; - switch(mode) { + switch(mode_) { default: return false; - case mode_read: + case mode::read: desired_access = GENERIC_READ; creation_disposition = OPEN_EXISTING; flprotect = PAGE_READONLY; map_access = FILE_MAP_READ; break; - case mode_write: + case mode::write: //write access requires read access desired_access = GENERIC_WRITE; creation_disposition = CREATE_ALWAYS; flprotect = PAGE_READWRITE; map_access = FILE_MAP_ALL_ACCESS; break; - case mode_readwrite: + case mode::readwrite: desired_access = GENERIC_READ | GENERIC_WRITE; creation_disposition = OPEN_EXISTING; flprotect = PAGE_READWRITE; map_access = FILE_MAP_ALL_ACCESS; break; - case mode_writeread: + case mode::writeread: desired_access = GENERIC_READ | GENERIC_WRITE; creation_disposition = CREATE_NEW; flprotect = PAGE_READWRITE; @@ -122,24 +128,28 @@ namespace nall { int p_fd; - bool p_open(const char *filename, filemode mode) { + bool p_opened() const { + return p_handle; + } + + bool p_open(const char *filename, mode mode_) { int open_flags, mmap_flags; - switch(mode) { + switch(mode_) { default: return false; - case mode_read: + case mode::read: open_flags = O_RDONLY; mmap_flags = PROT_READ; break; - case mode_write: + case mode::write: open_flags = O_RDWR | O_CREAT; //mmap() requires read access mmap_flags = PROT_WRITE; break; - case mode_readwrite: + case mode::readwrite: open_flags = O_RDWR; mmap_flags = PROT_READ | PROT_WRITE; break; - case mode_writeread: + case mode::writeread: open_flags = O_RDWR | O_CREAT; mmap_flags = PROT_READ | PROT_WRITE; break; diff --git a/bsnes/nall/string.hpp b/bsnes/nall/string.hpp index 70029861..2835022a 100755 --- a/bsnes/nall/string.hpp +++ b/bsnes/nall/string.hpp @@ -2,6 +2,7 @@ #define NALL_STRING_HPP #include +#include #include #include @@ -13,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +22,7 @@ #include #include #include +#include #include namespace nall { diff --git a/bsnes/nall/string/base.hpp b/bsnes/nall/string/base.hpp index f4556e70..a1c6b641 100755 --- a/bsnes/nall/string/base.hpp +++ b/bsnes/nall/string/base.hpp @@ -17,7 +17,6 @@ namespace nall { class string { public: inline void reserve(unsigned); - inline unsigned length() const; inline string& assign(const char*); inline string& append(const char*); @@ -26,6 +25,35 @@ namespace nall { inline string& append(unsigned int value); inline string& append(double value); + inline bool readfile(const char*); + + inline string& replace (const char*, const char*); + inline string& qreplace(const char*, const char*); + + inline unsigned length() const; + + inline bool equals(const char*) const; + inline bool iequals(const char*) const; + + inline bool wildcard(const char*) const; + inline bool iwildcard(const char*) const; + + inline bool beginswith(const char*) const; + inline bool ibeginswith(const char*) const; + inline bool endswith(const char*) const; + inline bool iendswith(const char*) const; + + inline string& lower(); + inline string& upper(); + inline string& transform(const char *before, const char *after); + + template inline string& ltrim(const char *key = " "); + template inline string& rtrim(const char *key = " "); + template inline string& trim (const char *key = " "); + + inline optional position(const char *key) const; + inline optional qposition(const char *key) const; + template inline string& operator= (T value); template inline string& operator<<(T value); @@ -48,17 +76,6 @@ namespace nall { inline string(string&&); inline ~string(); - inline bool readfile(const char*); - inline string& replace (const char*, const char*); - inline string& qreplace(const char*, const char*); - - inline string& lower(); - inline string& upper(); - inline string& transform(const char *before, const char *after); - template inline string& ltrim(const char *key = " "); - template inline string& rtrim(const char *key = " "); - template inline string& trim (const char *key = " "); - protected: char *data; unsigned size; @@ -73,7 +90,7 @@ namespace nall { public: template inline lstring& operator<<(T value); - inline optional find(const char*); + inline optional find(const char*) const; template inline void split (const char*, const char*); template inline void qsplit(const char*, const char*); @@ -84,9 +101,7 @@ namespace nall { //compare.hpp inline char chrlower(char c); inline char chrupper(char c); - inline int stricmp(const char *dest, const char *src); - inline int strwcmp(const char *str, const char *pattern, unsigned length); - inline int strwicmp(const char *str, const char *pattern, unsigned length); + inline int stricmp(const char *str1, const char *str2); inline bool wildcard(const char *str, const char *pattern); inline bool iwildcard(const char *str, const char *pattern); inline bool strbegin (const char *str, const char *key); @@ -111,10 +126,19 @@ namespace nall { inline bool strint (const char *str, int &result); inline bool strmath(const char *str, int &result); + //platform.hpp + inline string realpath(const char *name); + inline string userpath(); + inline string currentpath(); + //strl.hpp inline unsigned strlcpy(char *dest, const char *src, unsigned length); inline unsigned strlcat(char *dest, const char *src, unsigned length); + //strpos.hpp + inline optional strpos(const char *str, const char *key); + inline optional qstrpos(const char *str, const char *key); + //trim.hpp template inline char* ltrim(char *str, const char *key = " "); template inline char* rtrim(char *str, const char *key = " "); @@ -124,7 +148,6 @@ namespace nall { inline unsigned strlcpy(string &dest, const char *src, unsigned length); inline unsigned strlcat(string &dest, const char *src, unsigned length); inline string substr(const char *src, unsigned start = 0, unsigned length = 0); - inline string& strtr(string &dest, const char *before, const char *after); template inline string strhex(uintmax_t value); template inline string strsigned(intmax_t value); template inline string strunsigned(uintmax_t value); diff --git a/bsnes/nall/string/compare.hpp b/bsnes/nall/string/compare.hpp index 45f22a06..bce0895b 100755 --- a/bsnes/nall/string/compare.hpp +++ b/bsnes/nall/string/compare.hpp @@ -11,82 +11,52 @@ char chrupper(char c) { return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c; } -int stricmp(const char *dest, const char *src) { - while(*dest) { - if(chrlower(*dest) != chrlower(*src)) break; - dest++; - src++; +int stricmp(const char *str1, const char *str2) { + while(*str1) { + if(chrlower(*str1) != chrlower(*str2)) break; + str1++, str2++; } - - return (int)chrlower(*dest) - (int)chrlower(*src); + return (int)chrlower(*str1) - (int)chrlower(*str2); } -int strwcmp(const char *str, const char *pattern, unsigned length) { - while(length && *str) { - if(*pattern != '?' && *str != *pattern) break; - pattern++, str++, length--; +bool wildcard(const char *s, const char *p) { + const char *cp = 0, *mp = 0; + while(*s && *p != '*') { + if(*p != '?' && *s != *p) return false; + p++, s++; } - - if(length == 0 || *pattern == '?') return 0; - return (int)chrlower(*str) - (int)chrlower(*pattern); -} - -int strwicmp(const char *str, const char *pattern, unsigned length) { - while(length && *str) { - if(*pattern != '?' && chrlower(*str) != chrlower(*pattern)) break; - pattern++, str++, length--; - } - - if(length == 0 || *pattern == '?') return 0; - return (int)chrlower(*str) - (int)chrlower(*pattern); -} - -bool wildcard(const char *str, const char *pattern) { - while(*pattern) { - char n = *pattern++; - if(n == '*') { - unsigned length = 0; - while(true) { - n = pattern[length]; - if(n == 0 || n == '*') break; - length++; - } - if(length) while(true) { - if(*str == 0) return false; - if(!strwcmp(str, pattern, length)) break; - str++; - } - } else if(n == '?') { - str++; + while(*s) { + if(*p == '*') { + if(!*++p) return true; + mp = p, cp = s + 1; + } else if(*p == '?' || *p == *s) { + p++, s++; } else { - if(*str++ != n) return false; + p = mp, s = cp++; } } - return true; + while(*p == '*') p++; + return !*p; } -bool iwildcard(const char *str, const char *pattern) { - while(*pattern) { - char n = *pattern++; - if(n == '*') { - unsigned length = 0; - while(true) { - n = pattern[length]; - if(n == 0 || n == '*') break; - length++; - } - if(length) while(true) { - if(*str == 0) return false; - if(!strwicmp(str, pattern, length)) break; - str++; - } - } else if(n == '?') { - str++; +bool iwildcard(const char *s, const char *p) { + const char *cp = 0, *mp = 0; + while(*s && *p != '*') { + if(*p != '?' && chrlower(*s) != chrlower(*p)) return false; + p++, s++; + } + while(*s) { + if(*p == '*') { + if(!*++p) return true; + mp = p, cp = s + 1; + } else if(*p == '?' || chrlower(*p) == chrlower(*s)) { + p++, s++; } else { - if(chrlower(*str++) != chrlower(n)) return false; + p = mp, s = cp++; } } - return true; + while(*p == '*') p++; + return !*p; } bool strbegin(const char *str, const char *key) { diff --git a/bsnes/nall/string/convert.hpp b/bsnes/nall/string/convert.hpp index 3b8f155d..12a6c1ff 100755 --- a/bsnes/nall/string/convert.hpp +++ b/bsnes/nall/string/convert.hpp @@ -40,10 +40,6 @@ char* strtr(char *dest, const char *before, const char *after) { return dest; } -string& string::lower() { nall::strlower(data); return *this; } -string& string::upper() { nall::strupper(data); return *this; } -string& string::transform(const char *before, const char *after) { nall::strtr(data, before, after); return *this; } - uintmax_t strhex(const char *str) { if(!str) return 0; uintmax_t result = 0; diff --git a/bsnes/nall/string/core.hpp b/bsnes/nall/string/core.hpp index 3ce361a6..bad29030 100755 --- a/bsnes/nall/string/core.hpp +++ b/bsnes/nall/string/core.hpp @@ -11,10 +11,6 @@ void string::reserve(unsigned size_) { } } -unsigned string::length() const { - return strlen(data); -} - string& string::assign(const char *s) { unsigned length = strlen(s); reserve(length); @@ -122,7 +118,7 @@ bool string::readfile(const char *filename) { return true; } -optional lstring::find(const char *key) { +optional lstring::find(const char *key) const { for(unsigned i = 0; i < size(); i++) { if(operator[](i) == key) return { true, i }; } diff --git a/bsnes/nall/string/filename.hpp b/bsnes/nall/string/filename.hpp index f3750760..93d605ae 100755 --- a/bsnes/nall/string/filename.hpp +++ b/bsnes/nall/string/filename.hpp @@ -3,7 +3,9 @@ namespace nall { -// "foo/bar.c" -> "foo/", "bar.c" -> "./" +// "foo/bar.c" -> "foo/" +// "foo/" -> "foo/" +// "bar.c" -> "./" inline string dir(char const *name) { string result = name; for(signed i = strlen(result); i >= 0; i--) { diff --git a/bsnes/nall/string/platform.hpp b/bsnes/nall/string/platform.hpp new file mode 100755 index 00000000..42c1a756 --- /dev/null +++ b/bsnes/nall/string/platform.hpp @@ -0,0 +1,41 @@ +#ifndef NALL_STRING_PLATFORM_HPP +#define NALL_STRING_PLATFORM_HPP + +namespace nall { + +string realpath(const char *name) { + char path[PATH_MAX]; + if(::realpath(name, path)) { + string result(path); + result.transform("\\", "/"); + if(result.endswith("/") == false) result.append("/"); + return result; + } + return ""; +} + +string userpath() { + char path[PATH_MAX]; + if(::userpath(path)) { + string result(path); + result.transform("\\", "/"); + if(result.endswith("/") == false) result.append("/"); + return result; + } + return ""; +} + +string currentpath() { + char path[PATH_MAX]; + if(::getcwd(path)) { + string result(path); + result.transform("\\", "/"); + if(result.endswith("/") == false) result.append("/"); + return result; + } + return ""; +} + +} + +#endif diff --git a/bsnes/nall/string/strpos.hpp b/bsnes/nall/string/strpos.hpp index 8d880cce..1907a2f3 100755 --- a/bsnes/nall/string/strpos.hpp +++ b/bsnes/nall/string/strpos.hpp @@ -7,7 +7,7 @@ namespace nall { -inline optional strpos(const char *str, const char *key) { +optional strpos(const char *str, const char *key) { unsigned ssl = strlen(str), ksl = strlen(key); if(ksl > ssl) return { false, 0 }; @@ -18,7 +18,7 @@ inline optional strpos(const char *str, const char *key) { return { false, 0 }; } -inline optional qstrpos(const char *str, const char *key) { +optional qstrpos(const char *str, const char *key) { unsigned ssl = strlen(str), ksl = strlen(key); if(ksl > ssl) return { false, 0 }; diff --git a/bsnes/nall/string/trim.hpp b/bsnes/nall/string/trim.hpp index ba577856..f5355d7d 100755 --- a/bsnes/nall/string/trim.hpp +++ b/bsnes/nall/string/trim.hpp @@ -33,10 +33,6 @@ template char* trim(char *str, const char *key) { return ltrim(rtrim(str, key), key); } -template string& string::ltrim(const char *key) { nall::ltrim(data, key); return *this; } -template string& string::rtrim(const char *key) { nall::rtrim(data, key); return *this; } -template string& string::trim (const char *key) { nall::trim (data, key); return *this; } - } #endif diff --git a/bsnes/nall/string/wrapper.hpp b/bsnes/nall/string/wrapper.hpp new file mode 100755 index 00000000..eadf0a10 --- /dev/null +++ b/bsnes/nall/string/wrapper.hpp @@ -0,0 +1,33 @@ +#ifndef NALL_STRING_WRAPPER_HPP +#define NALL_STRING_WRAPPER_HPP + +namespace nall { + +unsigned string::length() const { return strlen(data); } + +bool string::equals(const char *str) const { return !strcmp(data, str); } +bool string::iequals(const char *str) const { return !stricmp(data, str); } + +bool string::wildcard(const char *str) const { return nall::wildcard(data, str); } +bool string::iwildcard(const char *str) const { return nall::iwildcard(data, str); } + +bool string::beginswith(const char *str) const { return strbegin(data, str); } +bool string::ibeginswith(const char *str) const { return stribegin(data, str); } + +bool string::endswith(const char *str) const { return strend(data, str); } +bool string::iendswith(const char *str) const { return striend(data, str); } + +string& string::lower() { nall::strlower(data); return *this; } +string& string::upper() { nall::strupper(data); return *this; } +string& string::transform(const char *before, const char *after) { nall::strtr(data, before, after); return *this; } + +template string& string::ltrim(const char *key) { nall::ltrim(data, key); return *this; } +template string& string::rtrim(const char *key) { nall::rtrim(data, key); return *this; } +template string& string::trim (const char *key) { nall::trim (data, key); return *this; } + +optional string::position(const char *key) const { return strpos(data, key); } +optional string::qposition(const char *key) const { return qstrpos(data, key); } + +} + +#endif diff --git a/bsnes/nall/ups.hpp b/bsnes/nall/ups.hpp index 9835f4ab..246405cc 100755 --- a/bsnes/nall/ups.hpp +++ b/bsnes/nall/ups.hpp @@ -9,7 +9,7 @@ namespace nall { struct ups { - enum class result_t : unsigned { + enum class result : unsigned { unknown, success, patch_unwritable, @@ -24,17 +24,17 @@ struct ups { function progress; - result_t create( - const uint8_t *source_data_, unsigned source_length_, - const uint8_t *target_data_, unsigned target_length_, - const char *patch_filename + result create( + const uint8_t *sourcedata, unsigned sourcelength, + const uint8_t *targetdata, unsigned targetlength, + const char *patchfilename ) { - source_data = (uint8_t*)source_data_, target_data = (uint8_t*)target_data_; - source_length = source_length_, target_length = target_length_; + source_data = (uint8_t*)sourcedata, target_data = (uint8_t*)targetdata; + source_length = sourcelength, target_length = targetlength; source_offset = target_offset = 0; source_checksum = target_checksum = patch_checksum = ~0; - if(patch_file.open(patch_filename, file::mode_write) == false) return result_t::patch_unwritable; + if(patch_file.open(patchfilename, file::mode::write) == false) return result::patch_unwritable; patch_write('U'); patch_write('P'); @@ -81,32 +81,32 @@ struct ups { for(unsigned i = 0; i < 4; i++) patch_write(patch_result_checksum >> (i * 8)); patch_file.close(); - return result_t::success; + return result::success; } - result_t apply( - const uint8_t *patch_data_, unsigned patch_length_, - const uint8_t *source_data_, unsigned source_length_, - uint8_t *target_data_, unsigned &target_length_ + result apply( + const uint8_t *patchdata, unsigned patchlength, + const uint8_t *sourcedata, unsigned sourcelength, + uint8_t *targetdata, unsigned &targetlength ) { - patch_data = (uint8_t*)patch_data_, source_data = (uint8_t*)source_data_, target_data = target_data_; - patch_length = patch_length_, source_length = source_length_, target_length = target_length_; + patch_data = (uint8_t*)patchdata, source_data = (uint8_t*)sourcedata, target_data = targetdata; + patch_length = patchlength, source_length = sourcelength, target_length = targetlength; patch_offset = source_offset = target_offset = 0; patch_checksum = source_checksum = target_checksum = ~0; - if(patch_length < 18) return result_t::patch_invalid; - if(patch_read() != 'U') return result_t::patch_invalid; - if(patch_read() != 'P') return result_t::patch_invalid; - if(patch_read() != 'S') return result_t::patch_invalid; - if(patch_read() != '1') return result_t::patch_invalid; + if(patch_length < 18) return result::patch_invalid; + if(patch_read() != 'U') return result::patch_invalid; + if(patch_read() != 'P') return result::patch_invalid; + if(patch_read() != 'S') return result::patch_invalid; + if(patch_read() != '1') return result::patch_invalid; unsigned source_read_length = decode(); unsigned target_read_length = decode(); - if(source_length != source_read_length && source_length != target_read_length) return result_t::source_invalid; - target_length_ = (source_length == source_read_length ? target_read_length : source_read_length); - if(target_length < target_length_) return result_t::target_too_small; - target_length = target_length_; + if(source_length != source_read_length && source_length != target_read_length) return result::source_invalid; + targetlength = (source_length == source_read_length ? target_read_length : source_read_length); + if(target_length < targetlength) return result::target_too_small; + target_length = targetlength; while(patch_offset < patch_length - 12) { unsigned length = decode(); @@ -126,15 +126,15 @@ struct ups { target_checksum = ~target_checksum; for(unsigned i = 0; i < 4; i++) patch_read_checksum |= patch_read() << (i * 8); - if(patch_result_checksum != patch_read_checksum) return result_t::patch_invalid; + if(patch_result_checksum != patch_read_checksum) return result::patch_invalid; if(source_checksum == source_read_checksum && source_length == source_read_length) { - if(target_checksum == target_read_checksum && target_length == target_read_length) return result_t::success; - return result_t::target_invalid; + if(target_checksum == target_read_checksum && target_length == target_read_length) return result::success; + return result::target_invalid; } else if(source_checksum == target_read_checksum && source_length == target_read_length) { - if(target_checksum == source_read_checksum && target_length == source_read_length) return result_t::success; - return result_t::target_invalid; + if(target_checksum == source_read_checksum && target_length == source_read_length) return result::success; + return result::target_invalid; } else { - return result_t::source_invalid; + return result::source_invalid; } } diff --git a/bsnes/phoenix/gtk/gtk.cpp b/bsnes/phoenix/gtk/gtk.cpp index 7cdba210..381e3250 100755 --- a/bsnes/phoenix/gtk/gtk.cpp +++ b/bsnes/phoenix/gtk/gtk.cpp @@ -108,6 +108,7 @@ string OS::folderSelect(Window &parent, const string &path) { } gtk_widget_destroy(dialog); + if(name.endswith("/") == false) name.append("/"); return name; } diff --git a/bsnes/phoenix/qt/qt.cpp b/bsnes/phoenix/qt/qt.cpp index 1f7e76fe..203b4b6f 100755 --- a/bsnes/phoenix/qt/qt.cpp +++ b/bsnes/phoenix/qt/qt.cpp @@ -74,7 +74,9 @@ string OS::folderSelect(Window &parent, const string &path) { &parent != &Window::None ? parent.window : 0, "Select Directory", QString::fromUtf8(path), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks ); - return directory.toUtf8().constData(); + string name = directory.toUtf8().constData(); + if(name.endswith("/") == false) name.append("/"); + return name; } string OS::fileOpen(Window &parent, const string &filter, const string &path) { diff --git a/bsnes/phoenix/qt/qt.moc b/bsnes/phoenix/qt/qt.moc index dd6540cd..5bb99a3b 100755 --- a/bsnes/phoenix/qt/qt.moc +++ b/bsnes/phoenix/qt/qt.moc @@ -1,7 +1,7 @@ /**************************************************************************** ** Meta object code from reading C++ file 'qt.moc.hpp' ** -** Created: Thu Oct 7 19:16:16 2010 +** Created: Mon Oct 11 13:03:04 2010 ** by: The Qt Meta Object Compiler version 62 (Qt 4.6.2) ** ** WARNING! All changes made in this file will be lost! diff --git a/bsnes/phoenix/windows/windows.cpp b/bsnes/phoenix/windows/windows.cpp index b81aac8e..697f8eec 100755 --- a/bsnes/phoenix/windows/windows.cpp +++ b/bsnes/phoenix/windows/windows.cpp @@ -166,7 +166,10 @@ string OS::folderSelect(Window &parent, const string &path) { } } if(result == false) return ""; - return utf8_t(wfilename); + string name = utf8_t(wfilename); + name.transform("\\", "/"); + if(name.endswith("/") == false) name.append("/"); + return name; } string OS::fileOpen(Window &parent, const string &filter, const string &path) { @@ -212,7 +215,9 @@ string OS::fileOpen(Window &parent, const string &filter, const string &path) { bool result = GetOpenFileName(&ofn); if(result == false) return ""; - return utf8_t(wfilename); + string name = utf8_t(wfilename); + name.transform("\\", "/"); + return name; } string OS::fileSave(Window &parent, const string &filter, const string &path) { @@ -258,7 +263,9 @@ string OS::fileSave(Window &parent, const string &filter, const string &path) { bool result = GetSaveFileName(&ofn); if(result == false) return ""; - return utf8_t(wfilename); + string name = utf8_t(wfilename); + name.transform("\\", "/"); + return name; } static void OS_keyboardProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { diff --git a/bsnes/snes/chip/msu1/msu1.cpp b/bsnes/snes/chip/msu1/msu1.cpp index 9d5c2c02..fa58d457 100755 --- a/bsnes/snes/chip/msu1/msu1.cpp +++ b/bsnes/snes/chip/msu1/msu1.cpp @@ -53,7 +53,7 @@ void MSU1::enable() { audio.coprocessor_frequency(44100.0); if(datafile.open()) datafile.close(); - datafile.open(string(cartridge.basename(), ".msu"), file::mode_read); + datafile.open(string(cartridge.basename(), ".msu"), file::mode::read); } void MSU1::power() { @@ -129,7 +129,7 @@ void MSU1::mmio_write(unsigned addr, uint8 data) { if(addr == 0x2005) { mmio.audio_track = (mmio.audio_track & 0x00ff) | (data << 8); if(audiofile.open()) audiofile.close(); - if(audiofile.open(string(cartridge.basename(), "-", mmio.audio_track, ".pcm"), file::mode_read)) { + if(audiofile.open(string(cartridge.basename(), "-", mmio.audio_track, ".pcm"), file::mode::read)) { uint32 header = audiofile.readm(4); if(header != 0x4d535531) { //verify 'MSU1' header audiofile.close(); diff --git a/bsnes/snes/chip/msu1/serialization.cpp b/bsnes/snes/chip/msu1/serialization.cpp index 2764536f..6c73a82b 100755 --- a/bsnes/snes/chip/msu1/serialization.cpp +++ b/bsnes/snes/chip/msu1/serialization.cpp @@ -16,12 +16,12 @@ void MSU1::serialize(serializer &s) { s.integer(mmio.audio_play); if(datafile.open()) datafile.close(); - if(datafile.open(string(cartridge.basename(), ".msu"), file::mode_read)) { + if(datafile.open(string(cartridge.basename(), ".msu"), file::mode::read)) { datafile.seek(mmio.data_offset); } if(audiofile.open()) audiofile.close(); - if(audiofile.open(string(cartridge.basename(), "-", mmio.audio_track, ".pcm"), file::mode_read)) { + if(audiofile.open(string(cartridge.basename(), "-", mmio.audio_track, ".pcm"), file::mode::read)) { audiofile.seek(mmio.audio_offset); } } diff --git a/bsnes/snes/snes.hpp b/bsnes/snes/snes.hpp index c0db3ba3..b255dad6 100755 --- a/bsnes/snes/snes.hpp +++ b/bsnes/snes/snes.hpp @@ -1,7 +1,7 @@ namespace SNES { namespace Info { static const char Name[] = "bsnes"; - static const char Version[] = "070.14"; + static const char Version[] = "070.16"; static const unsigned SerializerVersion = 14; } } diff --git a/bsnes/ui-phoenix/cartridge/cartridge.cpp b/bsnes/ui-phoenix/cartridge/cartridge.cpp index 415a8fb2..0f887ea0 100755 --- a/bsnes/ui-phoenix/cartridge/cartridge.cpp +++ b/bsnes/ui-phoenix/cartridge/cartridge.cpp @@ -5,7 +5,7 @@ bool Cartridge::loadNormal(const char *basename) { unload(); if(loadCartridge(SNES::memory::cartrom, baseXML, basename) == false) return false; baseName = nall::basename(basename); - SNES::cartridge.load(SNES::Cartridge::Mode::Normal, lstring() << baseXML); + SNES::cartridge.load(SNES::Cartridge::Mode::Normal, { baseXML }); loadMemory(SNES::memory::cartram, baseName, ".srm"); loadMemory(SNES::memory::cartrtc, baseName, ".rtc"); utility.cartridgeLoaded(); @@ -18,7 +18,7 @@ bool Cartridge::loadBsxSlotted(const char *basename, const char *slotname) { loadCartridge(SNES::memory::bsxflash, slotAXML, slotname); baseName = nall::basename(basename); slotAName = nall::basename(slotname); - SNES::cartridge.load(SNES::Cartridge::Mode::BsxSlotted, lstring() << baseXML << slotAXML); + SNES::cartridge.load(SNES::Cartridge::Mode::BsxSlotted, { baseXML, slotAXML }); loadMemory(SNES::memory::cartram, baseName, ".srm"); loadMemory(SNES::memory::cartrtc, baseName, ".rtc"); utility.cartridgeLoaded(); @@ -31,7 +31,7 @@ bool Cartridge::loadBsx(const char *basename, const char *slotname) { loadCartridge(SNES::memory::bsxflash, slotAXML, slotname); baseName = nall::basename(basename); slotAName = nall::basename(slotname); - SNES::cartridge.load(SNES::Cartridge::Mode::Bsx, lstring() << baseXML << slotAXML); + SNES::cartridge.load(SNES::Cartridge::Mode::Bsx, { baseXML, slotAXML }); loadMemory(SNES::memory::bsxram, baseName, ".srm"); loadMemory(SNES::memory::bsxpram, baseName, ".psr"); utility.cartridgeLoaded(); @@ -46,7 +46,7 @@ bool Cartridge::loadSufamiTurbo(const char *basename, const char *slotAname, con baseName = nall::basename(basename); slotAName = nall::basename(slotAname); slotBName = nall::basename(slotBname); - SNES::cartridge.load(SNES::Cartridge::Mode::SufamiTurbo, lstring() << baseXML << slotAXML << slotBXML); + SNES::cartridge.load(SNES::Cartridge::Mode::SufamiTurbo, { baseXML, slotAXML, slotBXML }); loadMemory(SNES::memory::stAram, slotAName, ".srm"); loadMemory(SNES::memory::stBram, slotBName, ".srm"); utility.cartridgeLoaded(); @@ -59,7 +59,7 @@ bool Cartridge::loadSuperGameBoy(const char *basename, const char *slotname) { loadCartridge(SNES::memory::gbrom, slotAXML, slotname); baseName = nall::basename(basename); slotAName = nall::basename(slotname); - SNES::cartridge.load(SNES::Cartridge::Mode::SuperGameBoy, lstring() << baseXML << slotAXML); + SNES::cartridge.load(SNES::Cartridge::Mode::SuperGameBoy, { baseXML, slotAXML }); loadMemory(SNES::memory::gbram, slotAName, ".sav"); loadMemory(SNES::memory::gbrtc, slotAName, ".rtc"); utility.cartridgeLoaded(); @@ -84,7 +84,7 @@ void Cartridge::unload() { bool Cartridge::loadCartridge(SNES::MappedRAM &memory, string &XML, const char *filename) { if(file::exists(filename) == false) return false; file fp; - if(fp.open(filename, file::mode_read) == false) return false; + if(fp.open(filename, file::mode::read) == false) return false; if(XML.readfile(string(nall::basename(filename), ".xml")) == false) XML = ""; unsigned size = fp.size(); @@ -92,20 +92,19 @@ bool Cartridge::loadCartridge(SNES::MappedRAM &memory, string &XML, const char * fp.read(data, size); fp.close(); - filemap patchFile; - if(XML == "" && patchFile.open(string(nall::basename(filename), ".ups"), filemap::mode_read)) { + filemap patch(string(nall::basename(filename), ".ups"), filemap::mode::read); + if(patch.opened()) { unsigned targetSize; ups patcher; - if(patcher.apply(patchFile.handle(), patchFile.size(), data, size, (uint8_t*)0, targetSize) == ups::result_t::target_too_small) { + if(patcher.apply(patch.data(), patch.size(), data, size, (uint8_t*)0, targetSize) == ups::result::target_too_small) { uint8_t *targetData = new uint8_t[targetSize]; - if(patcher.apply(patchFile.handle(), patchFile.size(), data, size, targetData, targetSize) == ups::result_t::success) { + if(patcher.apply(patch.data(), patch.size(), data, size, targetData, targetSize) == ups::result::success) { delete[] data; data = targetData; size = targetSize; patchApplied = true; } } - patchFile.close(); } if(XML == "") XML = snes_information(data, size).xml_memory_map; @@ -116,10 +115,10 @@ bool Cartridge::loadCartridge(SNES::MappedRAM &memory, string &XML, const char * bool Cartridge::loadMemory(SNES::MappedRAM &memory, string filename, const char *extension) { if(memory.size() == 0 || memory.size() == ~0) return true; - filename = string(filename, extension); + filename = { filename, extension }; if(file::exists(filename) == false) return false; file fp; - if(fp.open(filename, file::mode_read)) { + if(fp.open(filename, file::mode::read)) { fp.read(memory.data(), min(memory.size(), fp.size())); fp.close(); } @@ -128,9 +127,9 @@ bool Cartridge::loadMemory(SNES::MappedRAM &memory, string filename, const char bool Cartridge::saveMemory(SNES::MappedRAM &memory, string filename, const char *extension) { if(memory.size() == 0 || memory.size() == ~0) return true; - filename = string(filename, extension); + filename = { filename, extension }; file fp; - if(fp.open(filename, file::mode_write) == false) return false; + if(fp.open(filename, file::mode::write) == false) return false; fp.write(memory.data(), memory.size()); fp.close(); return true; diff --git a/bsnes/ui-phoenix/general/file-browser.cpp b/bsnes/ui-phoenix/general/file-browser.cpp index 9218bc44..bc6dedb4 100755 --- a/bsnes/ui-phoenix/general/file-browser.cpp +++ b/bsnes/ui-phoenix/general/file-browser.cpp @@ -71,7 +71,7 @@ void FileBrowser::fileOpen(FileBrowser::Mode requestedMode, functionmapping; if(mapping == "") mapping = "None"; - mappingList.addItem(string(controller[i]->name, "\t", mapping)); + mappingList.addItem({ controller[i]->name, "\t", mapping }); } mappingList.resizeColumnsToContent(); } @@ -94,7 +94,7 @@ void InputSettings::mappingChanged() { for(unsigned i = 0; i < controller.size(); i++) { string mapping = controller[i]->mapping; if(mapping == "") mapping = "None"; - mappingList.setItem(i, string(controller[i]->name, "\t", mapping)); + mappingList.setItem(i, { controller[i]->name, "\t", mapping }); } mappingList.resizeColumnsToContent(); } @@ -113,7 +113,7 @@ void InputSettings::assignInput() { mappingList.setEnabled(false); inputMapper.poll(); //flush any pending keypresses activeInput = controller[position()]; - setStatusText(string("Set assignment for [", activeInput->name, "] ...")); + setStatusText({ "Set assignment for [", activeInput->name, "] ..." }); if(dynamic_cast(activeInput)) { mouseLeft.setVisible(false); mouseMiddle.setVisible(false); @@ -145,7 +145,7 @@ void InputSettings::clearInput() { } } -void InputSettings::setMapping(const char *mapping) { +void InputSettings::setMapping(const string &mapping) { activeInput->mapping = mapping; inputMapper.bind(); endAssignment(); @@ -179,19 +179,19 @@ void InputSettings::inputEvent(uint16_t scancode, int16_t value) { } else if(Mouse::isAnyButton(scancode) && value) { activeMouse = Mouse::numberDecode(scancode); } else if(Joypad::isAnyHat(scancode) && value) { - if(value == Joypad::HatUp) setMapping(string(mapping, ".Up")); - else if(value == Joypad::HatDown) setMapping(string(mapping, ".Down")); - else if(value == Joypad::HatLeft) setMapping(string(mapping, ".Left")); - else if(value == Joypad::HatRight) setMapping(string(mapping, ".Right")); + if(value == Joypad::HatUp) setMapping({ mapping, ".Up" }); + else if(value == Joypad::HatDown) setMapping({ mapping, ".Down" }); + else if(value == Joypad::HatLeft) setMapping({ mapping, ".Left" }); + else if(value == Joypad::HatRight) setMapping({ mapping, ".Right" }); } else if(Joypad::isAnyAxis(scancode)) { if(joypadsCalibrated == false) return calibrateJoypads(); unsigned joypadNumber = Joypad::numberDecode(scancode); unsigned axisNumber = Joypad::axisDecode(scancode); int16_t calibration = joypadCalibration[joypadNumber][axisNumber]; - if(calibration > -12288 && calibration < +12288 && value < -24576) setMapping(string(mapping, ".Lo")); - else if(calibration > -12288 && calibration < +12288 && value > +24576) setMapping(string(mapping, ".Hi")); - else if(calibration <= -12288 && value >= +12288) setMapping(string(mapping, ".Hi")); - else if(calibration >= +12288 && value <= -12288) setMapping(string(mapping, ".Lo")); + if(calibration > -12288 && calibration < +12288 && value < -24576) setMapping({ mapping, ".Lo" }); + else if(calibration > -12288 && calibration < +12288 && value > +24576) setMapping({ mapping, ".Hi" }); + else if(calibration <= -12288 && value >= +12288) setMapping({ mapping, ".Hi" }); + else if(calibration >= +12288 && value <= -12288) setMapping({ mapping, ".Lo" }); } else if(Joypad::isAnyButton(scancode) && value) { setMapping(mapping); } diff --git a/bsnes/ui-phoenix/settings/input.hpp b/bsnes/ui-phoenix/settings/input.hpp index bb9a5e4d..db9da37c 100755 --- a/bsnes/ui-phoenix/settings/input.hpp +++ b/bsnes/ui-phoenix/settings/input.hpp @@ -25,7 +25,7 @@ private: void portChanged(); void deviceChanged(); void mappingChanged(); - void setMapping(const char *mapping); + void setMapping(const string &mapping); void assignInput(); void clearInput(); void endAssignment(); diff --git a/bsnes/ui-phoenix/settings/video.cpp b/bsnes/ui-phoenix/settings/video.cpp index e3ebcd0e..5487187d 100755 --- a/bsnes/ui-phoenix/settings/video.cpp +++ b/bsnes/ui-phoenix/settings/video.cpp @@ -58,9 +58,9 @@ void VideoSettings::create() { } void VideoSettings::adjust() { - brightnessValue.setText(string(brightnessSlider.position(), "%")); - contrastValue.setText(string(contrastSlider.position(), "%")); - gammaValue.setText(string(gammaSlider.position(), "%")); + brightnessValue.setText({ brightnessSlider.position(), "%" }); + contrastValue.setText({ contrastSlider.position(), "%" }); + gammaValue.setText({ gammaSlider.position(), "%" }); config.video.brightness = brightnessSlider.position(); config.video.contrast = contrastSlider.position(); diff --git a/bsnes/ui-phoenix/tools/cheat-editor.cpp b/bsnes/ui-phoenix/tools/cheat-editor.cpp index 4747a6c0..f2a2c4fd 100755 --- a/bsnes/ui-phoenix/tools/cheat-editor.cpp +++ b/bsnes/ui-phoenix/tools/cheat-editor.cpp @@ -57,7 +57,7 @@ void CheatEditor::save(string filename) { } file fp; - if(fp.open(string(filename, ".cht"), file::mode_write)) { + if(fp.open(string(filename, ".cht"), file::mode::write)) { fp.print("\n"); fp.print(string("\n")); for(unsigned i = 0; i <= lastSave; i++) { @@ -170,9 +170,9 @@ void CheatEditor::refresh() { if(list.size() > 1) cheatCode.append("..."); cheatList.setChecked(i, SNES::cheat[i].enabled); - cheatList.setItem(i, string( + cheatList.setItem(i, { cheatText[i][CheatSlot], "\t", cheatCode, "\t", cheatText[i][CheatDesc] - )); + }); } cheatList.resizeColumnsToContent(); } @@ -198,11 +198,11 @@ void CheatEditor::findCodes() { if(auto position = strpos(data, SNES::cartridge.sha256())) { auto startPosition = strpos((const char*)data + position(), ">"); auto endPosition = strpos((const char*)data + position(), ""); - string xmlData = string( + string xmlData = { "\n", substr((const char*)data + position() + 1, startPosition(), endPosition() - startPosition() - 1), "\n" - ); + }; databaseWindow.setTitle(""); databaseList.reset(); diff --git a/bsnes/ui-phoenix/tools/state-manager.cpp b/bsnes/ui-phoenix/tools/state-manager.cpp index 4850a604..07f2f317 100755 --- a/bsnes/ui-phoenix/tools/state-manager.cpp +++ b/bsnes/ui-phoenix/tools/state-manager.cpp @@ -40,10 +40,10 @@ void StateManager::synchronize() { void StateManager::refresh() { for(unsigned i = 0; i < 32; i++) { - stateList.setItem(i, string( + stateList.setItem(i, { strunsigned<2, ' '>(i + 1), "\t", slotLoadDescription(i) - )); + }); } stateList.resizeColumnsToContent(); } @@ -55,9 +55,9 @@ void StateManager::load() { stateList.addItem(""); } - string filename = string(cartridge.baseName, ".bsa"); + string filename = { cartridge.baseName, ".bsa" }; file fp; - if(fp.open(string(cartridge.baseName, ".bsa"), file::mode_read)) { + if(fp.open(string(cartridge.baseName, ".bsa"), file::mode::read)) { if(fp.readl(4) == 0x31415342) { if(fp.readl(4) == SNES::Info::SerializerVersion) { for(unsigned i = 0; i < 32; i++) { @@ -84,7 +84,7 @@ void StateManager::save() { unlink(string(cartridge.baseName, ".bsa")); } else { file fp; - if(fp.open(string(cartridge.baseName, ".bsa"), file::mode_write)) { + if(fp.open(string(cartridge.baseName, ".bsa"), file::mode::write)) { fp.writel(0x31415342, 4); //'BSA1' fp.writel(SNES::Info::SerializerVersion, 4); diff --git a/bsnes/ui-phoenix/utility/utility.cpp b/bsnes/ui-phoenix/utility/utility.cpp index 5d225762..fc05b992 100755 --- a/bsnes/ui-phoenix/utility/utility.cpp +++ b/bsnes/ui-phoenix/utility/utility.cpp @@ -102,7 +102,7 @@ void Utility::saveState(unsigned slot) { SNES::system.runtosave(); serializer s = SNES::system.serialize(); file fp; - if(fp.open(filename, file::mode_write)) { + if(fp.open(filename, file::mode::write)) { fp.write(s.data(), s.size()); fp.close(); showMessage({ "Saved state ", slot }); @@ -114,7 +114,7 @@ void Utility::saveState(unsigned slot) { void Utility::loadState(unsigned slot) { string filename = { cartridge.baseName, "-", slot, ".bst" }; file fp; - if(fp.open(filename, file::mode_read)) { + if(fp.open(filename, file::mode::read)) { unsigned size = fp.size(); uint8_t *data = new uint8_t[size]; fp.read(data, size); diff --git a/bsnes/ui-qt/cartridge/cartridge.cpp b/bsnes/ui-qt/cartridge/cartridge.cpp index 357d5a5c..47d14d87 100755 --- a/bsnes/ui-qt/cartridge/cartridge.cpp +++ b/bsnes/ui-qt/cartridge/cartridge.cpp @@ -9,7 +9,7 @@ bool Cartridge::information(const char *filename, Cartridge::Information &info) if(extension(filename) != "sfc") return false; //do not parse compressed images file fp; - if(fp.open(filename, file::mode_read) == false) return false; + if(fp.open(filename, file::mode::read) == false) return false; unsigned offset = 0; if((fp.size() & 0x7fff) == 512) offset = 512; @@ -219,7 +219,7 @@ bool Cartridge::loadCartridge(string &filename, string &xml, SNES::MappedRAM &me string name(filepath(nall::basename(filename), config().path.patch), ".ups"); file fp; - if(config().file.applyPatches && fp.open(name, file::mode_read)) { + if(config().file.applyPatches && fp.open(name, file::mode::read)) { unsigned patchsize = fp.size(); uint8_t *patchdata = new uint8_t[patchsize]; fp.read(patchdata, patchsize); @@ -228,9 +228,9 @@ bool Cartridge::loadCartridge(string &filename, string &xml, SNES::MappedRAM &me uint8_t *outdata = 0; unsigned outsize = 0; ups patcher; - if(patcher.apply(patchdata, patchsize, data, size, outdata, outsize) == ups::result_t::target_too_small) { + if(patcher.apply(patchdata, patchsize, data, size, 0, outsize) == ups::result::target_too_small) { outdata = new uint8_t[outsize]; - if(patcher.apply(patchdata, patchsize, data, size, outdata, outsize) == ups::result_t::success) { + if(patcher.apply(patchdata, patchsize, data, size, outdata, outsize) == ups::result::success) { delete[] data; data = outdata; size = outsize; @@ -264,7 +264,7 @@ bool Cartridge::loadMemory(const char *filename, const char *extension, SNES::Ma name << extension; file fp; - if(fp.open(name, file::mode_read) == false) return false; + if(fp.open(name, file::mode::read) == false) return false; unsigned size = fp.size(); uint8_t *data = new uint8_t[size]; @@ -284,7 +284,7 @@ bool Cartridge::saveMemory(const char *filename, const char *extension, SNES::Ma name << extension; file fp; - if(fp.open(name, file::mode_write) == false) return false; + if(fp.open(name, file::mode::write) == false) return false; fp.write(memory.data(), memory.size()); fp.close(); diff --git a/bsnes/ui-qt/link/reader.cpp b/bsnes/ui-qt/link/reader.cpp index d840983b..b91040e2 100755 --- a/bsnes/ui-qt/link/reader.cpp +++ b/bsnes/ui-qt/link/reader.cpp @@ -8,7 +8,7 @@ bool Reader::direct_load(string &filename, uint8_t *&data, unsigned &size) { if(file::exists(filename) == false) return false; file fp; - if(fp.open(filename, file::mode_read) == false) return false; + if(fp.open(filename, file::mode::read) == false) return false; data = new uint8_t[size = fp.size()]; fp.read(data, size); diff --git a/bsnes/ui-qt/movie/movie.cpp b/bsnes/ui-qt/movie/movie.cpp index 8411c203..0097c297 100755 --- a/bsnes/ui-qt/movie/movie.cpp +++ b/bsnes/ui-qt/movie/movie.cpp @@ -18,7 +18,7 @@ void Movie::play(const string &filename) { if(Movie::state != Inactive) stop(); - if(fp.open(filename, file::mode_read)) { + if(fp.open(filename, file::mode::read)) { if(fp.size() < 32) goto corrupt; unsigned signature = fp.readm(4); @@ -59,7 +59,7 @@ void Movie::record() { Movie::state = Record; mainWindow->syncUi(); - fp.open(makeFilename(), file::mode_write); + fp.open(makeFilename(), file::mode::write); fp.writem(0x42535631, 4); fp.writel(SNES::Info::SerializerVersion, 4); fp.writel(SNES::cartridge.crc32(), 4); diff --git a/bsnes/ui-qt/state/state.cpp b/bsnes/ui-qt/state/state.cpp index b35a9929..4b13a76e 100755 --- a/bsnes/ui-qt/state/state.cpp +++ b/bsnes/ui-qt/state/state.cpp @@ -12,7 +12,7 @@ bool State::save(unsigned slot) { file fp; bool result = false; - if(fp.open(name(slot), file::mode_write)) { + if(fp.open(name(slot), file::mode::write)) { fp.write(state.data(), state.size()); fp.close(); result = true; @@ -34,7 +34,7 @@ bool State::load(unsigned slot) { file fp; bool result = false; - if(fp.open(name(slot), file::mode_read)) { + if(fp.open(name(slot), file::mode::read)) { unsigned size = fp.size(); uint8_t *data = new uint8_t[size]; fp.read(data, size); diff --git a/bsnes/ui-qt/tools/cheateditor.cpp b/bsnes/ui-qt/tools/cheateditor.cpp index a9348c74..07a5301f 100755 --- a/bsnes/ui-qt/tools/cheateditor.cpp +++ b/bsnes/ui-qt/tools/cheateditor.cpp @@ -146,7 +146,7 @@ void CheatEditorWindow::save(const char *filename) { unlink(filename); } else { file fp; - if(fp.open(filename, file::mode_write)) { + if(fp.open(filename, file::mode::write)) { //determine how many rows from the bottom up are empty, and exclude them from the file //eg if only the first three slots are used, don't save the last 125 empty slots unsigned last = 127; diff --git a/bsnes/ui-qt/tools/statemanager.cpp b/bsnes/ui-qt/tools/statemanager.cpp index c7cdad78..1c2845a9 100755 --- a/bsnes/ui-qt/tools/statemanager.cpp +++ b/bsnes/ui-qt/tools/statemanager.cpp @@ -170,7 +170,7 @@ string StateManagerWindow::filename() const { bool StateManagerWindow::isStateValid(unsigned slot) { if(SNES::cartridge.loaded() == false) return false; file fp; - if(fp.open(filename(), file::mode_read) == false) return false; + if(fp.open(filename(), file::mode::read) == false) return false; if(fp.size() < (slot + 1) * SNES::system.serialize_size()) { fp.close(); return false; } fp.seek(slot * SNES::system.serialize_size()); uint32_t signature = fp.readl(4); @@ -188,7 +188,7 @@ bool StateManagerWindow::isStateValid(unsigned slot) { string StateManagerWindow::getStateDescription(unsigned slot) { if(isStateValid(slot) == false) return ""; file fp; - fp.open(filename(), file::mode_read); + fp.open(filename(), file::mode::read); char description[512]; fp.seek(slot * SNES::system.serialize_size() + 28); fp.read((uint8_t*)description, 512); @@ -200,7 +200,7 @@ string StateManagerWindow::getStateDescription(unsigned slot) { void StateManagerWindow::setStateDescription(unsigned slot, const string &text) { if(isStateValid(slot) == false) return; file fp; - fp.open(filename(), file::mode_readwrite); + fp.open(filename(), file::mode::readwrite); char description[512]; memset(&description, 0, sizeof description); strncpy(description, text, 512); @@ -212,7 +212,7 @@ void StateManagerWindow::setStateDescription(unsigned slot, const string &text) void StateManagerWindow::loadState(unsigned slot) { if(isStateValid(slot) == false) return; file fp; - fp.open(filename(), file::mode_read); + fp.open(filename(), file::mode::read); fp.seek(slot * SNES::system.serialize_size()); unsigned size = SNES::system.serialize_size(); uint8_t *data = new uint8_t[size]; @@ -231,14 +231,14 @@ void StateManagerWindow::saveState(unsigned slot) { file fp; if(file::exists(filename()) == false) { //try and create the file, bail out on failure (eg read-only device) - if(fp.open(filename(), file::mode_write) == false) return; + if(fp.open(filename(), file::mode::write) == false) return; fp.close(); } SNES::system.runtosave(); serializer state = SNES::system.serialize(); - fp.open(filename(), file::mode_readwrite); + fp.open(filename(), file::mode::readwrite); //user may save to slot #2 when slot #1 is empty; pad file to current slot if needed unsigned stateOffset = SNES::system.serialize_size() * slot; @@ -253,7 +253,7 @@ void StateManagerWindow::saveState(unsigned slot) { void StateManagerWindow::eraseState(unsigned slot) { if(isStateValid(slot) == false) return; file fp; - fp.open(filename(), file::mode_readwrite); + fp.open(filename(), file::mode::readwrite); unsigned size = SNES::system.serialize_size(); fp.seek(slot * size); for(unsigned i = 0; i < size; i++) fp.write(0x00); @@ -276,7 +276,7 @@ void StateManagerWindow::eraseState(unsigned slot) { } else { unsigned neededFileSize = (lastValidState + 1) * SNES::system.serialize_size(); file fp; - if(fp.open(filename(), file::mode_readwrite)) { + if(fp.open(filename(), file::mode::readwrite)) { if(fp.size() > neededFileSize) fp.truncate(neededFileSize); fp.close(); }