Esempio n. 1
0
	void SaveSlot(const std::string &gameFilename, int slot, Callback callback, void *cbUserData)
	{
		std::string fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
		std::string shot = GenerateSaveSlotFilename(gameFilename, slot, SCREENSHOT_EXTENSION);
		if (!fn.empty()) {
			auto renameCallback = [=](bool status, const std::string &message, void *data) {
				if (status) {
					if (File::Exists(fn)) {
						File::Delete(fn);
					}
					File::Rename(fn + ".tmp", fn);
				}
				if (callback) {
					callback(status, message, data);
				}
			};
			// Let's also create a screenshot.
			SaveScreenshot(shot, Callback(), 0);
			Save(fn + ".tmp", renameCallback, cbUserData);
		} else {
			I18NCategory *sy = GetI18NCategory("System");
			if (callback)
				callback(false, sy->T("Failed to save state. Error in the file system."), cbUserData);
		}
	}
Esempio n. 2
0
	void SaveSlot(int slot, Callback callback, void *cbUserData)
	{
		std::string fn = GenerateSaveSlotFilename(slot);
		if (!fn.empty()) {
			Save(fn, callback, cbUserData);
		} else {
			I18NCategory *s = GetI18NCategory("Screen");
			osm.Show("Failed to save state. Error in the file system.", 2.0);
			(*callback)(false, cbUserData);
		}
	}
Esempio n. 3
0
	void LoadSlot(int slot, Callback callback, void *cbUserData)
	{
		std::string fn = GenerateSaveSlotFilename(slot, STATE_EXTENSION);
		if (!fn.empty()) {
			Load(fn, callback, cbUserData);
		} else {
			I18NCategory *s = GetI18NCategory("Screen");
			osm.Show("Failed to load state. Error in the file system.", 2.0);
			if (callback)
				(*callback)(false, cbUserData);
		}
	}
Esempio n. 4
0
	std::string GetSlotDateAsString(const std::string &gameFilename, int slot) {
		std::string fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
		if (File::Exists(fn)) {
			tm time;
			if (File::GetModifTime(fn, time)) {
				char buf[256];
				// TODO: Use local time format? Americans and some others might not like ISO standard :)
				strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &time);
				return std::string(buf);
			}
		}
		return "";
	}
Esempio n. 5
0
	void LoadSlot(const std::string &gameFilename, int slot, Callback callback, void *cbUserData)
	{

          printf("SLOT: %d\n", slot);
		std::string fn = GenerateSaveSlotFilename(gameFilename, slot, STATE_EXTENSION);
		if (!fn.empty()) {
			Load(fn, callback, cbUserData);
		} else {
			I18NCategory *sy = GetI18NCategory("System");
			if (callback)
				callback(false, sy->T("Failed to load state. Error in the file system."), cbUserData);
		}
	}
Esempio n. 6
0
	int GetNewestSlot() {
		int newestSlot = -1;
		tm newestDate = {0};
		for (int i = 0; i < SAVESTATESLOTS; i++) {
			std::string fn = GenerateSaveSlotFilename(i, STATE_EXTENSION);
			if (File::Exists(fn)) {
				tm time = File::GetModifTime(fn);
				if (newestDate < time) {
					newestDate = time;
					newestSlot = i;
				}
			}
		}
		return newestSlot;
	}
Esempio n. 7
0
	int GetNewestSlot(const std::string &gameFilename) {
		int newestSlot = -1;
		tm newestDate = {0};
		for (int i = 0; i < NUM_SLOTS; i++) {
			std::string fn = GenerateSaveSlotFilename(gameFilename, i, STATE_EXTENSION);
			if (File::Exists(fn)) {
				tm time;
				bool success = File::GetModifTime(fn, time);
				if (success && newestDate < time) {
					newestDate = time;
					newestSlot = i;
				}
			}
		}
		return newestSlot;
	}
Esempio n. 8
0
	bool HasScreenshotInSlot(int slot)
	{
		std::string fn = GenerateSaveSlotFilename(slot, SCREENSHOT_EXTENSION);
		return File::Exists(fn);
	}
Esempio n. 9
0
	bool HasSaveInSlot(int slot)
	{
		std::string fn = GenerateSaveSlotFilename(slot, STATE_EXTENSION);
		return File::Exists(fn);
	}