예제 #1
0
bool getSavedGamesStack (stackHandler * sH, char * ext) {
	char * pattern = joinStrings ("*", ext);
	if (! pattern) return false;

	variable newName;
	newName.varType = SVT_NULL;

#ifdef _WIN32

    WCHAR *w_pattern = ConvertToUTF16(pattern);

	WIN32_FIND_DATA theData;
	HANDLE handle = FindFirstFile (w_pattern, & theData);

    delete w_pattern;

	if (handle != INVALID_HANDLE_VALUE) {
		bool keepGoing;
		do {
			theData.cFileName[lstrlen (theData.cFileName) - strlen (ext)] = TEXT('\0');
			char * fileName = ConvertFromUTF16(theData.cFileName);
			char * decoded = decodeFilename (fileName);
			makeTextVar (newName, decoded);
			delete fileName;
			delete decoded;
			if (! addVarToStack (newName, sH -> first)) return false;
			if (sH -> last == NULL) sH -> last = sH -> first;
			keepGoing = FindNextFile (handle, & theData);
		} while (keepGoing);
		FindClose (handle);
	}

#else

		DIR * dir = opendir (".");
		if (! dir) return false;

		struct dirent *d = readdir (dir);
		while (d != NULL) {
			if (! strcmp(d->d_name + strlen (d->d_name) - strlen (ext), ext)) {
				d->d_name[strlen (d->d_name) - strlen (ext)] = 0;
				char * decoded = decodeFilename (d->d_name);
				makeTextVar (newName, decoded);
				delete[] decoded;
				if (! addVarToStack (newName, sH -> first)) return false;
				if (sH -> last == NULL) sH -> last = sH -> first;
			}

			d = readdir (dir);
		}


		closedir (dir);

#endif

	delete[] pattern;
	pattern = NULL;
	return true;
}
예제 #2
0
bool getSavedGamesStack(StackHandler *sH, const Common::String &ext) {

	// Make pattern
	uint len = ext.size();
	Common::String pattern = "*";
	pattern += ext;

	// Get all saved files
	Common::StringArray sa = g_system->getSavefileManager()->listSavefiles(pattern);

	// Save file names to stacks
	Variable newName;
	newName.varType = SVT_NULL;
	Common::StringArray::iterator it;
	for (it = sa.begin(); it != sa.end(); ++it) {
		(*it).erase((*it).size() - len, len);
		makeTextVar(newName, (*it));
		if (!addVarToStack(newName, sH->first))
			return false;
		if (sH->last == NULL)
			sH->last = sH->first;
	}

	return true;
}
예제 #3
0
bool loadStringToVar (variable & thisVar, int value) {
	makeTextVar (thisVar, getNumberedString (value));
	return (bool) (thisVar.varData.theString != NULL);
}
예제 #4
0
bool fileToStack(const Common::String &filename, StackHandler *sH) {

	Variable stringVar;
	stringVar.varType = SVT_NULL;
	Common::String checker = saveEncoding ? "[Custom data (encoded)]\r\n" : "[Custom data (ASCII)]\n";

	Common::File fd;

	if (!fd.open(filename)) {
#if 0
		char currentDir[1000];
		if (!getcwd(currentDir, 998)) {
			debugOut("Can't get current directory.\n");
		}

		if (chdir(gamePath)) {
			debugOut("Error: Failed changing to directory %s\n", gamePath);
		}

		if (chdir(currentDir)) {
			debugOut("Error: Failed changing to directory %s\n", currentDir);
		}

		if (!fd.open(filename)) {
			return fatal("No such file", filename);
		}
#endif
		return fatal("No such file", filename); //TODO: false value
	}

	encode1 = (byte)saveEncoding & 255;
	encode2 = (byte)(saveEncoding >> 8);

	for (uint i = 0; i < checker.size(); ++i) {
		if (fd.readByte() != checker[i]) {
			fd.close();
			return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:", filename);
		}
	}

	if (saveEncoding) {
		checker = readStringEncoded(&fd);
		if (checker == UTF8_CHECKER) {
			fd.close();
			return fatal(
			LOAD_ERROR "The current file encoding setting does not match the encoding setting used when this file was created:", filename);
		}
	}

	for (;;) {
		if (saveEncoding) {
			char i = fd.readByte() ^ encode1;

			if (fd.eos())
				break;
			switch (i) {
				case 0: {
					Common::String g = readStringEncoded(&fd);
					makeTextVar(stringVar, g);
				}
					break;

				case 1:
					setVariable(stringVar, SVT_INT, fd.readUint32LE());
					break;

				case 2:
					setVariable(stringVar, SVT_INT, fd.readByte());
					break;

				default:
					fatal(LOAD_ERROR "Corrupt custom data file:", filename);
					fd.close();
					return false;
			}
		} else {
			char *line = readTextPlain(&fd);
			if (!line)
				break;
			makeTextVar(stringVar, line);
		}

		if (sH->first == NULL) {
			// Adds to the TOP of the array... oops!
			if (!addVarToStackQuick(stringVar, sH->first))
				return false;
			sH->last = sH->first;
		} else {
			// Adds to the END of the array... much better
			if (!addVarToStackQuick(stringVar, sH->last->next))
				return false;
			sH->last = sH->last->next;
		}
	}
	fd.close();

	return true;
}
예제 #5
0
bool handleInput () {
	static int l = 0;
	static Uint32 theTime;

	theTime = SDL_GetTicks() / 1000;
	if (lastSeconds != theTime) {
		lastSeconds = theTime;
		lastFramesPerSecond = thisFramesPerSecond;
		thisFramesPerSecond = 1;
	} else {
		thisFramesPerSecond ++;
	}
//	lastFramesPerSecond = theTime.wSecond;

	if (launchMe) {
		if (l) {
			// Still paused because of spawned thingy...
		} else {
			l = 1;

			setVariable (* launchResult, SVT_INT, launch(launchMe) > 31);
			launchMe = NULL;
			launchResult = NULL;
		}
		return true;
	} else {
		 l = 0;
	}

	if (! overRegion) getOverRegion ();

	if (input.justMoved) {
		if (currentEvents -> moveMouseFunction) {
			if (! startNewFunctionNum (currentEvents -> moveMouseFunction, 0, NULL, noStack)) return false;
		}
	}
	input.justMoved = false;

	if (lastRegion != overRegion && currentEvents -> focusFunction) {
		variableStack * tempStack = new variableStack;
		if (! checkNew (tempStack)) return false;
		
		initVarNew (tempStack -> thisVar);
		if (overRegion) {
			setVariable (tempStack -> thisVar, SVT_OBJTYPE, overRegion -> thisType -> objectNum);
		} else {
			setVariable (tempStack -> thisVar, SVT_INT, 0);
		}
		tempStack -> next = NULL;
		if (! startNewFunctionNum (currentEvents -> focusFunction, 1, NULL, tempStack)) return false;
	}
	if (input.leftRelease && currentEvents -> leftMouseUpFunction)  {
		if (! startNewFunctionNum (currentEvents -> leftMouseUpFunction, 0, NULL, noStack)) return false;
	}
	if (input.rightRelease && currentEvents -> rightMouseUpFunction) {
		if (! startNewFunctionNum (currentEvents -> rightMouseUpFunction, 0, NULL, noStack)) return false;
	}
	if (input.leftClick && currentEvents -> leftMouseFunction)
		if (! startNewFunctionNum (currentEvents -> leftMouseFunction, 0, NULL, noStack)) return false;
	if (input.rightClick && currentEvents -> rightMouseFunction) {
		if (! startNewFunctionNum (currentEvents -> rightMouseFunction, 0, NULL, noStack)) return false;
	}
	if (input.keyPressed && currentEvents -> spaceFunction) {
		char * tempString = NULL;
		switch (input.keyPressed) {
			case 127:	
				tempString = copyString ("BACKSPACE");	break;
			case 9:		tempString = copyString ("TAB");		break;
			case 13:	tempString = copyString ("ENTER");		break;
			case 27:	tempString = copyString ("ESCAPE");		break;
			/*
			case 1112:	tempString = copyString ("ALT+F1");		break;
			case 1113:	tempString = copyString ("ALT+F2");		break;
			case 1114:	tempString = copyString ("ALT+F3");		break;
			case 1115:	tempString = copyString ("ALT+F4");		break;
			case 1116:	tempString = copyString ("ALT+F5");		break;
			case 1117:	tempString = copyString ("ALT+F6");		break;
			case 1118:	tempString = copyString ("ALT+F7");		break;
			case 1119:	tempString = copyString ("ALT+F8");		break;
			case 1120:	tempString = copyString ("ALT+F9");		break;
			case 1121:	tempString = copyString ("ALT+F10");	break;
			case 1122:	tempString = copyString ("ALT+F11");	break;
			case 1123:	tempString = copyString ("ALT+F12");	break;

			case 2019:	tempString = copyString ("PAUSE");		break;
			*/
			case 63276:	tempString = copyString ("PAGE UP");	break;
			case 63277:	tempString = copyString ("PAGE DOWN");	break;
			case 63275:	tempString = copyString ("END");		break;
			case 63273:	tempString = copyString ("HOME");		break;
			case 63234:	tempString = copyString ("LEFT");		break;
			case 63232:	tempString = copyString ("UP");			break;
			case 63235:	tempString = copyString ("RIGHT");		break;
			case 63233:	tempString = copyString ("DOWN");		break;
				/*
			case 2045:	tempString = copyString ("INSERT");		break;
			case 2046:	tempString = copyString ("DELETE");		break;
				*/
			case 63236:	tempString = copyString ("F1");			break;
			case 63237:	tempString = copyString ("F2");			break;
			case 63238:	tempString = copyString ("F3");			break;
			case 63239:	tempString = copyString ("F4");			break;
			case 63240:	tempString = copyString ("F5");			break;
			case 63241:	tempString = copyString ("F6");			break;
			case 63242:	tempString = copyString ("F7");			break;
			case 63243:	tempString = copyString ("F8");			break;
			case 63244:	tempString = copyString ("F9");			break;
			case 63245:	tempString = copyString ("F10");		break;
			case 63246:	tempString = copyString ("F11");		break;
			case 63247:	tempString = copyString ("F12");		break;

			default:
			if (input.keyPressed >= 256) {
				//if (captureAllKeys) {
					tempString = copyString ("ABCDEF");
					sprintf (tempString, "%i", input.keyPressed);
				//}
			} else {
				tempString = copyString (" ");
				tempString[0] = input.keyPressed;
			}
		}

		if (tempString) {
			variableStack * tempStack = new variableStack;
			if (! checkNew (tempStack)) return false;
			initVarNew (tempStack -> thisVar);
			makeTextVar (tempStack -> thisVar, tempString);
			delete tempString;
			tempString = NULL;
			tempStack -> next = NULL;
			if (! startNewFunctionNum (currentEvents -> spaceFunction, 1, NULL, tempStack)) return false;
		}
	}
	input.rightClick = false;
	input.leftClick = false;
	input.rightRelease = false;
	input.leftRelease = false;
	input.keyPressed = 0;
	lastRegion = overRegion;
	return runSludge ();
}