bool StateManager::save(const char *filename, uint8 slot, serializer &s, const char *description) { //if no state archive exists ... if(file::exists(filename) == false) { //try and create one if(create(filename) == false) return false; } //if we cannot load the existing state archive ... if(load(filename) == false) { //it's probably an older version, try and create a new one if(create(filename) == false) return false; //it still needs to be loaded before we can write to it if(load(filename) == false) return false; } uint8 index = findslot(slot); if(index == SlotInvalid) { //create new slot instead of over-writing existing slot if(info.slotcount >= 255) return false; index = info.slotcount; slot = info.slotcount; } file fp; if(fp.open(filename, file::mode_readwrite) == false) return false; fp.seek(SlotIndex + index); fp.write(slot); time_t current = time(0); tm *ts = localtime(¤t); char timestamp[32]; sprintf(timestamp, "%.4u-%.2u-%.2u %.2u:%.2u:%.2u", 1900 + ts->tm_year, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec, (ts->tm_hour < 12 ? "AM" : "PM") ); fp.seek(DateTimeIndex + index * DateTimeSize); fp.write((uint8*)×tamp[0], DateTimeSize); char desc[DescriptionSize]; memset(&desc, 0, DescriptionSize); strlcpy(desc, description, DescriptionSize); fp.seek(DescIndex + index * DescriptionSize); fp.write((uint8*)&desc[0], DescriptionSize); fp.seek(HeaderSize + index * system.serialize_size); fp.write(s.data(), s.size()); for(unsigned n = 0; n < system.serialize_size - s.size(); n++) fp.write(0x00); fp.close(); return true; }