bsnes/bsnes/nall/directory.hpp

153 lines
4.8 KiB
C++
Raw Normal View History

#ifndef NALL_DIRECTORY_HPP
#define NALL_DIRECTORY_HPP
#include <nall/sort.hpp>
#include <nall/string.hpp>
#include <nall/vector.hpp>
#if defined(_WIN32)
#include <nall/windows/utf8.hpp>
#else
#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>
#endif
namespace nall {
struct directory {
static bool exists(const string &pathname);
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
static lstring folders(const string &pathname, const string &pattern = "*");
static lstring files(const string &pathname, const string &pattern = "*");
static lstring contents(const string &pathname, const string &pattern = "*");
};
#if defined(_WIN32)
inline bool directory::exists(const string &pathname) {
DWORD result = GetFileAttributes(utf16_t(pathname));
if(result == INVALID_FILE_ATTRIBUTES) return false;
return (result & FILE_ATTRIBUTE_DIRECTORY);
}
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
inline lstring directory::folders(const string &pathname, const string &pattern) {
lstring list;
string path = pathname;
path.transform("/", "\\");
if(!strend(path, "\\")) path.append("\\");
path.append("*");
HANDLE handle;
WIN32_FIND_DATA data;
handle = FindFirstFile(utf16_t(path), &data);
if(handle != INVALID_HANDLE_VALUE) {
if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) {
if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
string name = (const char*)utf8_t(data.cFileName);
Update to v079 release. byuu says: This release includes Nintendo Super System DIP switch emulation and improved PPU rendering accuracy, among other things. Changelog: - added Nintendo Super System DIP switch emulation [requires XML setting maps] - emulated Super Game Boy $6001 VRAM offset selection port [ikari_01] - fixed randomness initialization of S-SMP port registers [fixes DBZ:Hyper Dimension and Ninja Warriors] - mosaic V-countdown caches BGOFS registers (fixes Super Turrican 2 effect) [reported by zal16] - non-mosaic BGOFS registers are always cached at H=60 (fixes NHL '94 and Super Mario World flickering) - fixed 2xSaI family of renderers on 64-bit systems - cleaned up SMP source code - phoenix: fixed a bug when closing bsnes while minimized Please note that the mosaic BGOFS fix is only for the accuracy profile. Unfortunately the older scanline-based compatibility renderer's code is nearly unmaintainable at this point, so I haven't yet been able to backport the fixes. Also, I have written a new cycle-accurate SMP core that does not use libco. The aim is to implement it into Snes9X v1.54. But it would of course be prudent to test the new core first. [...then in the next post...] Decided to keep that Super Mario World part a surprise, so ... surprise! Realized while working on the Super Turrican 2 mosaic fix, and from looking at NHL '94 and Dai Kaijuu Monogatari 2's behavior, that BGOFS registers must be cached between H=0 and H=88 for the entire scanline ... they can't work otherwise, and it'd be stupid for the PPU to re-add the offset to the position on every pixel anyway. I chose H=60 for now. Once I am set up with the RGB monitor and the North American cartridge dumping is completed, I'll set it on getting exact timings for all these things. It'll probably require a smallish speed hit to allow exact-cycle timing events for everything in the PPU.
2011-06-05 03:45:04 +00:00
if(wildcard(name, pattern)) list.append(name);
}
}
while(FindNextFile(handle, &data) != false) {
if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) {
if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
string name = (const char*)utf8_t(data.cFileName);
Update to v079 release. byuu says: This release includes Nintendo Super System DIP switch emulation and improved PPU rendering accuracy, among other things. Changelog: - added Nintendo Super System DIP switch emulation [requires XML setting maps] - emulated Super Game Boy $6001 VRAM offset selection port [ikari_01] - fixed randomness initialization of S-SMP port registers [fixes DBZ:Hyper Dimension and Ninja Warriors] - mosaic V-countdown caches BGOFS registers (fixes Super Turrican 2 effect) [reported by zal16] - non-mosaic BGOFS registers are always cached at H=60 (fixes NHL '94 and Super Mario World flickering) - fixed 2xSaI family of renderers on 64-bit systems - cleaned up SMP source code - phoenix: fixed a bug when closing bsnes while minimized Please note that the mosaic BGOFS fix is only for the accuracy profile. Unfortunately the older scanline-based compatibility renderer's code is nearly unmaintainable at this point, so I haven't yet been able to backport the fixes. Also, I have written a new cycle-accurate SMP core that does not use libco. The aim is to implement it into Snes9X v1.54. But it would of course be prudent to test the new core first. [...then in the next post...] Decided to keep that Super Mario World part a surprise, so ... surprise! Realized while working on the Super Turrican 2 mosaic fix, and from looking at NHL '94 and Dai Kaijuu Monogatari 2's behavior, that BGOFS registers must be cached between H=0 and H=88 for the entire scanline ... they can't work otherwise, and it'd be stupid for the PPU to re-add the offset to the position on every pixel anyway. I chose H=60 for now. Once I am set up with the RGB monitor and the North American cartridge dumping is completed, I'll set it on getting exact timings for all these things. It'll probably require a smallish speed hit to allow exact-cycle timing events for everything in the PPU.
2011-06-05 03:45:04 +00:00
if(wildcard(name, pattern)) list.append(name);
}
}
}
FindClose(handle);
}
Update to v070r04 release. byuu says: - fixed new config file input driver name (you'll have to delete your old config, or change to a different driver and back and restart) - fixed slot loader windows' OK button placement - fixed nall/directory.hpp when list size was zero - rewrote nall/function.hpp, no longer requires <functional> or union tricks - added state manager The state manager is a little bit different this time. It's functionally identical to bsnes/Qt, 100% of the way. But when you save slots, it stores them in RAM. It only writes the BSA archive upon ROM unload / program exit. Yes, this means that technically if the emulator crashes, you'll lose your states. But a) that very rarely happens, and b) the old way was thrashing the disk like crazy, every letter you typed dumped up to 8MB to disk. With this new method, I can simply store a boolean valid flag before each slot, and pack the file better. Before, a save on only slot 3 would be 3*state size (~1.2mb), it will now be 3bytes+state size (~400kb.) I have also added a proper signature because of this, so it will detect when you load an archive for a previous serializer version and ignore it. When you go to save (unload the game), if there are no valid slots, the BSA archive gets unlinked (deleted.) I am also planning a feature around the now-hidden "slot 0". My idea is for it to be a fallback slot. How many times have you loaded a state when you meant to save and said, "shit, now I lost some of my progress"? The idea is that whenever you load a state, right before loading, it will save to slot 0. When you unload the game, or exit the emulator, it will also save to slot 0. You will be able to load from slot 0 from the menu, but not save to it. It will appear at the bottom of the load list. And lastly, I'll add an advanced option to auto-load slot 0 if it exists, which will enable "close the emulator and restart where you left off." functionality.
2010-09-30 10:29:49 +00:00
if(list.size() > 0) sort(&list[0], list.size());
for(auto &name : list) name.append("/"); //must append after sorting
return list;
}
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
inline lstring directory::files(const string &pathname, const string &pattern) {
lstring list;
string path = pathname;
path.transform("/", "\\");
if(!strend(path, "\\")) path.append("\\");
path.append("*");
HANDLE handle;
WIN32_FIND_DATA data;
handle = FindFirstFile(utf16_t(path), &data);
if(handle != INVALID_HANDLE_VALUE) {
if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
string name = (const char*)utf8_t(data.cFileName);
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
if(wildcard(name, pattern)) list.append(name);
}
while(FindNextFile(handle, &data) != false) {
if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
string name = (const char*)utf8_t(data.cFileName);
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
if(wildcard(name, pattern)) list.append(name);
}
}
FindClose(handle);
}
Update to v070r04 release. byuu says: - fixed new config file input driver name (you'll have to delete your old config, or change to a different driver and back and restart) - fixed slot loader windows' OK button placement - fixed nall/directory.hpp when list size was zero - rewrote nall/function.hpp, no longer requires <functional> or union tricks - added state manager The state manager is a little bit different this time. It's functionally identical to bsnes/Qt, 100% of the way. But when you save slots, it stores them in RAM. It only writes the BSA archive upon ROM unload / program exit. Yes, this means that technically if the emulator crashes, you'll lose your states. But a) that very rarely happens, and b) the old way was thrashing the disk like crazy, every letter you typed dumped up to 8MB to disk. With this new method, I can simply store a boolean valid flag before each slot, and pack the file better. Before, a save on only slot 3 would be 3*state size (~1.2mb), it will now be 3bytes+state size (~400kb.) I have also added a proper signature because of this, so it will detect when you load an archive for a previous serializer version and ignore it. When you go to save (unload the game), if there are no valid slots, the BSA archive gets unlinked (deleted.) I am also planning a feature around the now-hidden "slot 0". My idea is for it to be a fallback slot. How many times have you loaded a state when you meant to save and said, "shit, now I lost some of my progress"? The idea is that whenever you load a state, right before loading, it will save to slot 0. When you unload the game, or exit the emulator, it will also save to slot 0. You will be able to load from slot 0 from the menu, but not save to it. It will appear at the bottom of the load list. And lastly, I'll add an advanced option to auto-load slot 0 if it exists, which will enable "close the emulator and restart where you left off." functionality.
2010-09-30 10:29:49 +00:00
if(list.size() > 0) sort(&list[0], list.size());
return list;
}
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
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);
for(auto &file : files) folders.append(file);
return folders;
}
#else
inline bool directory::exists(const string &pathname) {
DIR *dp = opendir(pathname);
if(!dp) return false;
closedir(dp);
return true;
}
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
inline lstring directory::folders(const string &pathname, const string &pattern) {
lstring list;
DIR *dp;
struct dirent *ep;
dp = opendir(pathname);
if(dp) {
while(ep = readdir(dp)) {
if(!strcmp(ep->d_name, ".")) continue;
if(!strcmp(ep->d_name, "..")) continue;
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
if(ep->d_type & DT_DIR) {
Update to v079 release. byuu says: This release includes Nintendo Super System DIP switch emulation and improved PPU rendering accuracy, among other things. Changelog: - added Nintendo Super System DIP switch emulation [requires XML setting maps] - emulated Super Game Boy $6001 VRAM offset selection port [ikari_01] - fixed randomness initialization of S-SMP port registers [fixes DBZ:Hyper Dimension and Ninja Warriors] - mosaic V-countdown caches BGOFS registers (fixes Super Turrican 2 effect) [reported by zal16] - non-mosaic BGOFS registers are always cached at H=60 (fixes NHL '94 and Super Mario World flickering) - fixed 2xSaI family of renderers on 64-bit systems - cleaned up SMP source code - phoenix: fixed a bug when closing bsnes while minimized Please note that the mosaic BGOFS fix is only for the accuracy profile. Unfortunately the older scanline-based compatibility renderer's code is nearly unmaintainable at this point, so I haven't yet been able to backport the fixes. Also, I have written a new cycle-accurate SMP core that does not use libco. The aim is to implement it into Snes9X v1.54. But it would of course be prudent to test the new core first. [...then in the next post...] Decided to keep that Super Mario World part a surprise, so ... surprise! Realized while working on the Super Turrican 2 mosaic fix, and from looking at NHL '94 and Dai Kaijuu Monogatari 2's behavior, that BGOFS registers must be cached between H=0 and H=88 for the entire scanline ... they can't work otherwise, and it'd be stupid for the PPU to re-add the offset to the position on every pixel anyway. I chose H=60 for now. Once I am set up with the RGB monitor and the North American cartridge dumping is completed, I'll set it on getting exact timings for all these things. It'll probably require a smallish speed hit to allow exact-cycle timing events for everything in the PPU.
2011-06-05 03:45:04 +00:00
if(wildcard(ep->d_name, pattern)) list.append(ep->d_name);
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
}
}
closedir(dp);
}
Update to v070r04 release. byuu says: - fixed new config file input driver name (you'll have to delete your old config, or change to a different driver and back and restart) - fixed slot loader windows' OK button placement - fixed nall/directory.hpp when list size was zero - rewrote nall/function.hpp, no longer requires <functional> or union tricks - added state manager The state manager is a little bit different this time. It's functionally identical to bsnes/Qt, 100% of the way. But when you save slots, it stores them in RAM. It only writes the BSA archive upon ROM unload / program exit. Yes, this means that technically if the emulator crashes, you'll lose your states. But a) that very rarely happens, and b) the old way was thrashing the disk like crazy, every letter you typed dumped up to 8MB to disk. With this new method, I can simply store a boolean valid flag before each slot, and pack the file better. Before, a save on only slot 3 would be 3*state size (~1.2mb), it will now be 3bytes+state size (~400kb.) I have also added a proper signature because of this, so it will detect when you load an archive for a previous serializer version and ignore it. When you go to save (unload the game), if there are no valid slots, the BSA archive gets unlinked (deleted.) I am also planning a feature around the now-hidden "slot 0". My idea is for it to be a fallback slot. How many times have you loaded a state when you meant to save and said, "shit, now I lost some of my progress"? The idea is that whenever you load a state, right before loading, it will save to slot 0. When you unload the game, or exit the emulator, it will also save to slot 0. You will be able to load from slot 0 from the menu, but not save to it. It will appear at the bottom of the load list. And lastly, I'll add an advanced option to auto-load slot 0 if it exists, which will enable "close the emulator and restart where you left off." functionality.
2010-09-30 10:29:49 +00:00
if(list.size() > 0) sort(&list[0], list.size());
for(auto &name : list) name.append("/"); //must append after sorting
return list;
}
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
inline lstring directory::files(const string &pathname, const string &pattern) {
lstring list;
DIR *dp;
struct dirent *ep;
dp = opendir(pathname);
if(dp) {
while(ep = readdir(dp)) {
if(!strcmp(ep->d_name, ".")) continue;
if(!strcmp(ep->d_name, "..")) continue;
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
if((ep->d_type & DT_DIR) == 0) {
if(wildcard(ep->d_name, pattern)) list.append(ep->d_name);
}
}
closedir(dp);
}
Update to v070r04 release. byuu says: - fixed new config file input driver name (you'll have to delete your old config, or change to a different driver and back and restart) - fixed slot loader windows' OK button placement - fixed nall/directory.hpp when list size was zero - rewrote nall/function.hpp, no longer requires <functional> or union tricks - added state manager The state manager is a little bit different this time. It's functionally identical to bsnes/Qt, 100% of the way. But when you save slots, it stores them in RAM. It only writes the BSA archive upon ROM unload / program exit. Yes, this means that technically if the emulator crashes, you'll lose your states. But a) that very rarely happens, and b) the old way was thrashing the disk like crazy, every letter you typed dumped up to 8MB to disk. With this new method, I can simply store a boolean valid flag before each slot, and pack the file better. Before, a save on only slot 3 would be 3*state size (~1.2mb), it will now be 3bytes+state size (~400kb.) I have also added a proper signature because of this, so it will detect when you load an archive for a previous serializer version and ignore it. When you go to save (unload the game), if there are no valid slots, the BSA archive gets unlinked (deleted.) I am also planning a feature around the now-hidden "slot 0". My idea is for it to be a fallback slot. How many times have you loaded a state when you meant to save and said, "shit, now I lost some of my progress"? The idea is that whenever you load a state, right before loading, it will save to slot 0. When you unload the game, or exit the emulator, it will also save to slot 0. You will be able to load from slot 0 from the menu, but not save to it. It will appear at the bottom of the load list. And lastly, I'll add an advanced option to auto-load slot 0 if it exists, which will enable "close the emulator and restart where you left off." functionality.
2010-09-30 10:29:49 +00:00
if(list.size() > 0) sort(&list[0], list.size());
return list;
}
Update to v070r14 release. (there was no r13 release posted to the WIP thread) byuu says: - nall/string: trim and split functions now take the limit as a template parameter for clarity, trim_once variants are removed - quotable.trim<1>("\""); //remove quotes from string - cheatcode.split<3>(","); //split up to three times, third one is a description that may have commas - foobar.trim(" "); //remove any and all spaces - nall/string: added wildcard() and iwildcard() functions for pattern matching - nall/directory: accepts an optional pattern parameter to perform wildcard matching - lstring cartridges = directory::contents(path, "*.sfc"); - some people may prefer directory::contents("/path/to/files/*.sfc"), but I like not having to build a string when you have the path separated already - nall/qt: removed entirely, now resides in bsnes/ui-qt/template; I do intend to replace the check/radio actions with native Qt versions later - bsnes/data: new folder, share the parts that both UIs use; bsnes.ico, bsnes.png, bsnes.Desktop, cheats.xml; simplify Makefile install target - Makefile: install target now creates .bsnes folder and copies cheats.xml there for you - Makefile: gconftool hack removed, not needed for phoenix, will work around with Qt later - will probably make bsnes/Qt read the cheats.xml file externally as well, as that file makes each profile 1MB bigger when embedded - as such, will probably make bsnes also look in the binary directory for that file, so Windows users don't have to copy it to their userdata folder
2010-10-11 10:39:14 +00:00
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);
for(auto &file : files) folders.append(file);
return folders;
}
#endif
}
#endif