bsnes/purify/nall/zip.hpp

96 lines
3.5 KiB
C++
Raw Normal View History

Update to purify v02 release. byuu says: purify has been rewritten. It now resembles the older snespurify, and lets you import multiple game files+archives and regenerate manifests for multiple game folders. It is also recursive. So you can now import all of your games for all systems at once, or you can update all of your bsnes v091 game folders to the new higan v092 format at once. Caveats: First, I am now using std::thread, so that the GUI doesn't freeze. Instead, you get a nice progress bar. Unfortunately, I was mislead and TDM/GCC 4.7 still does not have std::thread support. So ... sorry, but I can't compile purify for Windows. I am sick and tired of not being able to write multi-threaded code, so fuck it. If anyone can get it to build on Windows, whether that be by using Windows threads, hacking in std::thread support, skipping threading all together, whatever ... that'll be great. Otherwise, sorry, purify is Linux only until MinGW can get its god damned shit together and offers threading support. Second, there's no way to regenerate Famicom (NES) manifests, because we discard the iNES header. We are going to need a database for that. So, all I can suggest is that if you use bsnes/higan, keep all your iNES images around to re-import as new releases come out. Third, when you purify game folders, it will back up the ROM and RAM files only. Your save states, cheat codes, debug logs, etc will be wiped out. There's a whole lot of reasons for this, the most pertinent is that it's meant to clean up the folder to a pristine state. It also fixes the game folder name, etc. So ... sorry, but this is how it works. New releases rarely if ever allow old save states to work anyway. Lastly, I am not going to have purify contain infinite backward compatibility for updating manifests. You will want to keep up with purifying the collection, otherwise you'll have to grab older purify copies and convert your way along. Although hopefully the format won't be so volatile and this won't be necessary very often.
2013-01-17 11:19:42 +00:00
#ifndef NALL_ZIP_HPP
#define NALL_ZIP_HPP
Update to purify v02 release. byuu says: purify has been rewritten. It now resembles the older snespurify, and lets you import multiple game files+archives and regenerate manifests for multiple game folders. It is also recursive. So you can now import all of your games for all systems at once, or you can update all of your bsnes v091 game folders to the new higan v092 format at once. Caveats: First, I am now using std::thread, so that the GUI doesn't freeze. Instead, you get a nice progress bar. Unfortunately, I was mislead and TDM/GCC 4.7 still does not have std::thread support. So ... sorry, but I can't compile purify for Windows. I am sick and tired of not being able to write multi-threaded code, so fuck it. If anyone can get it to build on Windows, whether that be by using Windows threads, hacking in std::thread support, skipping threading all together, whatever ... that'll be great. Otherwise, sorry, purify is Linux only until MinGW can get its god damned shit together and offers threading support. Second, there's no way to regenerate Famicom (NES) manifests, because we discard the iNES header. We are going to need a database for that. So, all I can suggest is that if you use bsnes/higan, keep all your iNES images around to re-import as new releases come out. Third, when you purify game folders, it will back up the ROM and RAM files only. Your save states, cheat codes, debug logs, etc will be wiped out. There's a whole lot of reasons for this, the most pertinent is that it's meant to clean up the folder to a pristine state. It also fixes the game folder name, etc. So ... sorry, but this is how it works. New releases rarely if ever allow old save states to work anyway. Lastly, I am not going to have purify contain infinite backward compatibility for updating manifests. You will want to keep up with purifying the collection, otherwise you'll have to grab older purify copies and convert your way along. Although hopefully the format won't be so volatile and this won't be necessary very often.
2013-01-17 11:19:42 +00:00
//creates uncompressed ZIP archives
#include <nall/crc32.hpp>
#include <nall/string.hpp>
namespace nall {
struct zip {
Update to purify v02 release. byuu says: purify has been rewritten. It now resembles the older snespurify, and lets you import multiple game files+archives and regenerate manifests for multiple game folders. It is also recursive. So you can now import all of your games for all systems at once, or you can update all of your bsnes v091 game folders to the new higan v092 format at once. Caveats: First, I am now using std::thread, so that the GUI doesn't freeze. Instead, you get a nice progress bar. Unfortunately, I was mislead and TDM/GCC 4.7 still does not have std::thread support. So ... sorry, but I can't compile purify for Windows. I am sick and tired of not being able to write multi-threaded code, so fuck it. If anyone can get it to build on Windows, whether that be by using Windows threads, hacking in std::thread support, skipping threading all together, whatever ... that'll be great. Otherwise, sorry, purify is Linux only until MinGW can get its god damned shit together and offers threading support. Second, there's no way to regenerate Famicom (NES) manifests, because we discard the iNES header. We are going to need a database for that. So, all I can suggest is that if you use bsnes/higan, keep all your iNES images around to re-import as new releases come out. Third, when you purify game folders, it will back up the ROM and RAM files only. Your save states, cheat codes, debug logs, etc will be wiped out. There's a whole lot of reasons for this, the most pertinent is that it's meant to clean up the folder to a pristine state. It also fixes the game folder name, etc. So ... sorry, but this is how it works. New releases rarely if ever allow old save states to work anyway. Lastly, I am not going to have purify contain infinite backward compatibility for updating manifests. You will want to keep up with purifying the collection, otherwise you'll have to grab older purify copies and convert your way along. Although hopefully the format won't be so volatile and this won't be necessary very often.
2013-01-17 11:19:42 +00:00
zip(const string &filename) {
fp.open(filename, file::mode::write);
time_t currentTime = time(0);
tm *info = localtime(&currentTime);
dosTime = (info->tm_hour << 11) | (info->tm_min << 5) | (info->tm_sec >> 1);
dosDate = ((info->tm_year - 80) << 9) | ((1 + info->tm_mon) << 5) + (info->tm_mday);
}
Update to purify v02 release. byuu says: purify has been rewritten. It now resembles the older snespurify, and lets you import multiple game files+archives and regenerate manifests for multiple game folders. It is also recursive. So you can now import all of your games for all systems at once, or you can update all of your bsnes v091 game folders to the new higan v092 format at once. Caveats: First, I am now using std::thread, so that the GUI doesn't freeze. Instead, you get a nice progress bar. Unfortunately, I was mislead and TDM/GCC 4.7 still does not have std::thread support. So ... sorry, but I can't compile purify for Windows. I am sick and tired of not being able to write multi-threaded code, so fuck it. If anyone can get it to build on Windows, whether that be by using Windows threads, hacking in std::thread support, skipping threading all together, whatever ... that'll be great. Otherwise, sorry, purify is Linux only until MinGW can get its god damned shit together and offers threading support. Second, there's no way to regenerate Famicom (NES) manifests, because we discard the iNES header. We are going to need a database for that. So, all I can suggest is that if you use bsnes/higan, keep all your iNES images around to re-import as new releases come out. Third, when you purify game folders, it will back up the ROM and RAM files only. Your save states, cheat codes, debug logs, etc will be wiped out. There's a whole lot of reasons for this, the most pertinent is that it's meant to clean up the folder to a pristine state. It also fixes the game folder name, etc. So ... sorry, but this is how it works. New releases rarely if ever allow old save states to work anyway. Lastly, I am not going to have purify contain infinite backward compatibility for updating manifests. You will want to keep up with purifying the collection, otherwise you'll have to grab older purify copies and convert your way along. Although hopefully the format won't be so volatile and this won't be necessary very often.
2013-01-17 11:19:42 +00:00
//append path: append("path/");
//append file: append("path/file", data, size);
void append(string filename, const uint8_t *data = nullptr, unsigned size = 0u) {
filename.transform("\\", "/");
uint32_t checksum = crc32_calculate(data, size);
directory.append({filename, checksum, size, fp.offset()});
fp.writel(0x04034b50, 4); //signature
fp.writel(0x0014, 2); //minimum version (2.0)
fp.writel(0x0000, 2); //general purpose bit flags
fp.writel(0x0000, 2); //compression method (0 = uncompressed)
fp.writel(dosTime, 2);
fp.writel(dosDate, 2);
fp.writel(checksum, 4);
fp.writel(size, 4); //compressed size
fp.writel(size, 4); //uncompressed size
fp.writel(filename.length(), 2); //file name length
fp.writel(0x0000, 2); //extra field length
fp.print(filename); //file name
fp.write(data, size); //file data
}
~zip() {
Update to purify v02 release. byuu says: purify has been rewritten. It now resembles the older snespurify, and lets you import multiple game files+archives and regenerate manifests for multiple game folders. It is also recursive. So you can now import all of your games for all systems at once, or you can update all of your bsnes v091 game folders to the new higan v092 format at once. Caveats: First, I am now using std::thread, so that the GUI doesn't freeze. Instead, you get a nice progress bar. Unfortunately, I was mislead and TDM/GCC 4.7 still does not have std::thread support. So ... sorry, but I can't compile purify for Windows. I am sick and tired of not being able to write multi-threaded code, so fuck it. If anyone can get it to build on Windows, whether that be by using Windows threads, hacking in std::thread support, skipping threading all together, whatever ... that'll be great. Otherwise, sorry, purify is Linux only until MinGW can get its god damned shit together and offers threading support. Second, there's no way to regenerate Famicom (NES) manifests, because we discard the iNES header. We are going to need a database for that. So, all I can suggest is that if you use bsnes/higan, keep all your iNES images around to re-import as new releases come out. Third, when you purify game folders, it will back up the ROM and RAM files only. Your save states, cheat codes, debug logs, etc will be wiped out. There's a whole lot of reasons for this, the most pertinent is that it's meant to clean up the folder to a pristine state. It also fixes the game folder name, etc. So ... sorry, but this is how it works. New releases rarely if ever allow old save states to work anyway. Lastly, I am not going to have purify contain infinite backward compatibility for updating manifests. You will want to keep up with purifying the collection, otherwise you'll have to grab older purify copies and convert your way along. Although hopefully the format won't be so volatile and this won't be necessary very often.
2013-01-17 11:19:42 +00:00
//central directory
unsigned baseOffset = fp.offset();
for(auto &entry : directory) {
fp.writel(0x02014b50, 4); //signature
fp.writel(0x0014, 2); //version made by (2.0)
fp.writel(0x0014, 2); //version needed to extract (2.0)
fp.writel(0x0000, 2); //general purpose bit flags
fp.writel(0x0000, 2); //compression method (0 = uncompressed)
fp.writel(dosTime, 2);
fp.writel(dosDate, 2);
fp.writel(entry.checksum, 4);
fp.writel(entry.size, 4); //compressed size
fp.writel(entry.size, 4); //uncompressed size
fp.writel(entry.filename.length(), 2); //file name length
fp.writel(0x0000, 2); //extra field length
fp.writel(0x0000, 2); //file comment length
fp.writel(0x0000, 2); //disk number start
fp.writel(0x0000, 2); //internal file attributes
fp.writel(0x00000000, 4); //external file attributes
fp.writel(entry.offset, 4); //relative offset of file header
fp.print(entry.filename);
}
unsigned finishOffset = fp.offset();
//end of central directory
fp.writel(0x06054b50, 4); //signature
fp.writel(0x0000, 2); //number of this disk
fp.writel(0x0000, 2); //disk where central directory starts
fp.writel(directory.size(), 2); //number of central directory records on this disk
fp.writel(directory.size(), 2); //total number of central directory records
fp.writel(finishOffset - baseOffset, 4); //size of central directory
fp.writel(baseOffset, 4); //offset of central directory
fp.writel(0x0000, 2); //comment length
fp.close();
}
protected:
Update to purify v02 release. byuu says: purify has been rewritten. It now resembles the older snespurify, and lets you import multiple game files+archives and regenerate manifests for multiple game folders. It is also recursive. So you can now import all of your games for all systems at once, or you can update all of your bsnes v091 game folders to the new higan v092 format at once. Caveats: First, I am now using std::thread, so that the GUI doesn't freeze. Instead, you get a nice progress bar. Unfortunately, I was mislead and TDM/GCC 4.7 still does not have std::thread support. So ... sorry, but I can't compile purify for Windows. I am sick and tired of not being able to write multi-threaded code, so fuck it. If anyone can get it to build on Windows, whether that be by using Windows threads, hacking in std::thread support, skipping threading all together, whatever ... that'll be great. Otherwise, sorry, purify is Linux only until MinGW can get its god damned shit together and offers threading support. Second, there's no way to regenerate Famicom (NES) manifests, because we discard the iNES header. We are going to need a database for that. So, all I can suggest is that if you use bsnes/higan, keep all your iNES images around to re-import as new releases come out. Third, when you purify game folders, it will back up the ROM and RAM files only. Your save states, cheat codes, debug logs, etc will be wiped out. There's a whole lot of reasons for this, the most pertinent is that it's meant to clean up the folder to a pristine state. It also fixes the game folder name, etc. So ... sorry, but this is how it works. New releases rarely if ever allow old save states to work anyway. Lastly, I am not going to have purify contain infinite backward compatibility for updating manifests. You will want to keep up with purifying the collection, otherwise you'll have to grab older purify copies and convert your way along. Although hopefully the format won't be so volatile and this won't be necessary very often.
2013-01-17 11:19:42 +00:00
file fp;
uint16_t dosTime, dosDate;
struct entry_t {
string filename;
uint32_t checksum;
uint32_t size;
uint32_t offset;
};
vector<entry_t> directory;
};
}
#endif