Update to v070r16 release.

(there was no r15 release posted to the WIP thread)

byuu says:

This mostly contains improvements for nall, like path unification.
This should fix FitzRoy's issue with .. on Windows.
This commit is contained in:
Tim Allen 2010-10-14 21:07:38 +11:00
parent ce2b543679
commit 9e53c51b58
40 changed files with 338 additions and 264 deletions

View File

@ -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();

View File

@ -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

View File

@ -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;
}
};

View File

@ -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;

View File

@ -2,6 +2,7 @@
#define NALL_STRING_HPP
#include <initializer_list>
#include <nall/platform.hpp>
#include <nall/utility.hpp>
#include <nall/string/base.hpp>
@ -13,6 +14,7 @@
#include <nall/string/filename.hpp>
#include <nall/string/match.hpp>
#include <nall/string/math.hpp>
#include <nall/string/platform.hpp>
#include <nall/string/strl.hpp>
#include <nall/string/strpos.hpp>
#include <nall/string/trim.hpp>
@ -20,6 +22,7 @@
#include <nall/string/split.hpp>
#include <nall/string/utility.hpp>
#include <nall/string/variadic.hpp>
#include <nall/string/wrapper.hpp>
#include <nall/string/xml.hpp>
namespace nall {

View File

@ -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<unsigned limit = 0> inline string& ltrim(const char *key = " ");
template<unsigned limit = 0> inline string& rtrim(const char *key = " ");
template<unsigned limit = 0> inline string& trim (const char *key = " ");
inline optional<unsigned> position(const char *key) const;
inline optional<unsigned> qposition(const char *key) const;
template<typename T> inline string& operator= (T value);
template<typename T> 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<unsigned limit = 0> inline string& ltrim(const char *key = " ");
template<unsigned limit = 0> inline string& rtrim(const char *key = " ");
template<unsigned limit = 0> inline string& trim (const char *key = " ");
protected:
char *data;
unsigned size;
@ -73,7 +90,7 @@ namespace nall {
public:
template<typename T> inline lstring& operator<<(T value);
inline optional<unsigned> find(const char*);
inline optional<unsigned> find(const char*) const;
template<unsigned limit = 0> inline void split (const char*, const char*);
template<unsigned limit = 0> 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<unsigned> strpos(const char *str, const char *key);
inline optional<unsigned> qstrpos(const char *str, const char *key);
//trim.hpp
template<unsigned limit = 0> inline char* ltrim(char *str, const char *key = " ");
template<unsigned limit = 0> 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<unsigned length = 0, char padding = '0'> inline string strhex(uintmax_t value);
template<unsigned length = 0, char padding = '0'> inline string strsigned(intmax_t value);
template<unsigned length = 0, char padding = '0'> inline string strunsigned(uintmax_t value);

View File

@ -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) {

View File

@ -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;

View File

@ -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<unsigned> lstring::find(const char *key) {
optional<unsigned> lstring::find(const char *key) const {
for(unsigned i = 0; i < size(); i++) {
if(operator[](i) == key) return { true, i };
}

View File

@ -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--) {

41
bsnes/nall/string/platform.hpp Executable file
View File

@ -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

View File

@ -7,7 +7,7 @@
namespace nall {
inline optional<unsigned> strpos(const char *str, const char *key) {
optional<unsigned> 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<unsigned> strpos(const char *str, const char *key) {
return { false, 0 };
}
inline optional<unsigned> qstrpos(const char *str, const char *key) {
optional<unsigned> qstrpos(const char *str, const char *key) {
unsigned ssl = strlen(str), ksl = strlen(key);
if(ksl > ssl) return { false, 0 };

View File

@ -33,10 +33,6 @@ template<unsigned limit> char* trim(char *str, const char *key) {
return ltrim<limit>(rtrim<limit>(str, key), key);
}
template<unsigned limit> string& string::ltrim(const char *key) { nall::ltrim<limit>(data, key); return *this; }
template<unsigned limit> string& string::rtrim(const char *key) { nall::rtrim<limit>(data, key); return *this; }
template<unsigned limit> string& string::trim (const char *key) { nall::trim <limit>(data, key); return *this; }
}
#endif

33
bsnes/nall/string/wrapper.hpp Executable file
View File

@ -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<unsigned limit> string& string::ltrim(const char *key) { nall::ltrim<limit>(data, key); return *this; }
template<unsigned limit> string& string::rtrim(const char *key) { nall::rtrim<limit>(data, key); return *this; }
template<unsigned limit> string& string::trim (const char *key) { nall::trim <limit>(data, key); return *this; }
optional<unsigned> string::position(const char *key) const { return strpos(data, key); }
optional<unsigned> string::qposition(const char *key) const { return qstrpos(data, key); }
}
#endif

View File

@ -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<void (unsigned offset, unsigned length)> 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;
}
}

View File

@ -108,6 +108,7 @@ string OS::folderSelect(Window &parent, const string &path) {
}
gtk_widget_destroy(dialog);
if(name.endswith("/") == false) name.append("/");
return name;
}

View File

@ -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) {

View File

@ -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!

View File

@ -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) {

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -71,7 +71,7 @@ void FileBrowser::fileOpen(FileBrowser::Mode requestedMode, function<void (strin
contentsBox.setFocused();
}
void FileBrowser::setFolder(const char *pathname) {
void FileBrowser::setFolder(const string &pathname) {
contentsBox.reset();
contents.reset();
@ -111,7 +111,7 @@ void FileBrowser::fileActivate() {
if(strend(filename, "/")) {
string cartridgeName = cartridgeFolder(filename);
if(cartridgeName == "") {
setFolder(string(folder, filename));
setFolder({ folder, filename });
} else {
loadFile({ folder, cartridgeName });
}
@ -121,7 +121,7 @@ void FileBrowser::fileActivate() {
}
}
string FileBrowser::cartridgeFolder(const char *pathname) {
string FileBrowser::cartridgeFolder(const string &pathname) {
if(strend(pathname, ".sfc/") == false) return "";
lstring list = directory::files(string(folder, "/", pathname));
@ -133,7 +133,7 @@ string FileBrowser::cartridgeFolder(const char *pathname) {
}
}
return string(pathname, filename);
return { pathname, filename };
}
void FileBrowser::loadFile(const string &filename) {

View File

@ -17,8 +17,8 @@ private:
void folderBrowse();
void folderUp();
void fileActivate();
void setFolder(const char *pathname);
string cartridgeFolder(const char *pathname);
void setFolder(const string &pathname);
string cartridgeFolder(const string &pathname);
void loadFile(const string &filename);
};

View File

@ -1,7 +1,7 @@
MainWindow mainWindow;
void MainWindow::create() {
Window::create(0, 0, 595, 448, string(SNES::Info::Name, " v", SNES::Info::Version));
Window::create(0, 0, 595, 448, { SNES::Info::Name, " v", SNES::Info::Version });
application.addWindow(this, "MainWindow", "128,128");
setFont(application.proportionalFontBold);
setBackgroundColor(0, 0, 0);
@ -193,13 +193,13 @@ void MainWindow::create() {
toolsStateManager.onTick = []() { stateManager.setVisible(); };
helpAbout.onTick = []() {
MessageWindow::information(mainWindow, string(
MessageWindow::information(mainWindow, {
"bsnes\n\n",
"Version: ", SNES::Info::Version, "\n",
"Profile: ", SNES::Info::Profile, "\n",
"Author: byuu\n",
"Homepage: http://byuu.org/"
));
});
};
onClose = []() {

View File

@ -10,14 +10,9 @@ void Application::main(int argc, char **argv) {
config.create();
inputMapper.create();
char temp[PATH_MAX];
if(realpath(argv[0], temp)) config.path.base = temp;
config.path.base.transform("\\", "/");
config.path.base = dir(config.path.base);
if(userpath(temp)) config.path.user = temp;
config.path.user.transform("\\", "/");
if(strend(config.path.user, "/") == false) config.path.user.append("/");
config.path.user.append(".bsnes/");
config.path.base = realpath(argv[0]);
config.path.user = { userpath(), ".bsnes/" };
config.load();
config.save();
if(config.path.current == "") config.path.current = config.path.base;

View File

@ -19,13 +19,13 @@ void AudioSettings::create() {
volumeSlider.onChange = []() {
config.audio.volume = audioSettings.volumeSlider.position();
audio.set(Audio::Volume, config.audio.volume);
audioSettings.volumeValue.setText(string(config.audio.volume, "%"));
audioSettings.volumeValue.setText({ config.audio.volume, "%" });
};
frequencySlider.onChange = []() {
config.audio.inputFrequency = audioSettings.frequencySlider.position() + 31000;
audio.set(Audio::ResampleRatio, (double)config.audio.inputFrequency / (double)config.audio.outputFrequency);
audioSettings.frequencyValue.setText(string(config.audio.inputFrequency, "hz"));
audioSettings.frequencyValue.setText({ config.audio.inputFrequency, "hz" });
};
setGeometry(0, 0, 440, y);

View File

@ -78,7 +78,7 @@ void InputSettings::deviceChanged() {
for(unsigned i = 0; i < controller.size(); i++) {
string mapping = controller[i]->mapping;
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<InputMapper::AnalogInput*>(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);
}

View File

@ -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();

View File

@ -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();

View File

@ -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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
fp.print(string("<cartridge sha256=\"", SNES::cartridge.sha256(), "\">\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(), "</cartridge>");
string xmlData = string(
string xmlData = {
"<cartridge>\n",
substr((const char*)data + position() + 1, startPosition(), endPosition() - startPosition() - 1),
"</cartridge>\n"
);
};
databaseWindow.setTitle("");
databaseList.reset();

View File

@ -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);

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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();
}