Ejemplo n.º 1
0
	void SourceTASReader::CommonExecuteScript(bool search)
	{
		try
		{
			Reset();
#if OE
			const char* dir = y_spt_gamedir.GetString();
			if (dir == NULL || dir[0] == '\0')
				Msg("WARNING: Trying to load a script file without setting the game directory with y_spt_gamedir in old engine!\n");
#endif

			std::string gameDir = GetGameDir();
			scriptStream.open(gameDir + "\\" + fileName + SCRIPT_EXT);

			if (!scriptStream.is_open())
				throw std::exception("File does not exist");
			ParseProps();

			if (search && searchType == SearchType::None)
				throw std::exception("In search mode but search property is not set");
			else if (!search && searchType != SearchType::None)
				throw std::exception("Not in search mode but search property is set");

			while (!scriptStream.eof())
			{
				if (IsFramesLine())
					ParseFrames();
				else if (IsVarsLine())
					ParseVariables();
				else
					throw std::exception(
					    "Unexpected section order in file. Expected order is props - variables - frames");
			}

			Execute();
		}
		catch (const std::exception& ex)
		{
			Msg("Error in line %i: %s!\n", currentLine, ex.what());
		}
		catch (const SearchDoneException&)
		{
			Msg("Search done.\n");
			variables.PrintBest();
		}
		catch (...)
		{
			Msg("Unexpected exception on line %i\n", currentLine);
		}

		scriptStream.close();
	}
Ejemplo n.º 2
0
void cRawParser::ParseVariables(cXmlNode& node, bool command, const wxString& path) {
    wxString inc = wxT("");
    ParseStringOption(inc, node, wxT("include"), NULL);
    if (!inc.IsEmpty()) {
        wxFSFileName src;
        if (path.IsEmpty()) {
            src = m_input.GetPath();
        } else {
            src = wxFSFileName(path, true);
        }
        wxFSFileName filename = inc;
        if (!filename.IsAbsolute())
            filename.MakeAbsolute(src.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME));
        LoadVariables(filename, command, (m_bake.Index(wxT(RAWXML_VARIABLES))!=wxNOT_FOUND)?&node:NULL );

        if (m_mode == MODE_BAKE) {
            if (m_bake.Index(wxT(RAWXML_VARIABLES)) == wxNOT_FOUND) {
                wxString newfile;
                if (m_bake.Index(wxT(RAWBAKE_ABSOLUTE)) == wxNOT_FOUND) {
                    filename.MakeRelativeTo(m_bakeroot.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME));
                }
                newfile = filename.GetFullPath();
                node.delProp("include");
                node.addProp("include", newfile.utf8_str());
            } else {
                node.delProp("include");
            }
        }
    }

    cXmlNode child(node.children());
    while (child) {
        DO_CONDITION_COMMENT(child);

        if (child(RAWXML_SET)) {
            ParseSet(child, command);
        } else if (child(RAWXML_UNSET)) {
            ParseUnset(child, command);
        } else if (child(RAWXML_VARIABLES)) {
            ParseVariables(child, command, path);
        } else if (child.is(XML_ELEMENT_NODE)) {
            throw MakeNodeException<RCT3Exception>(wxString::Format(_("Unknown tag '%s' in variables tag"), child.wxname().c_str()), child);
        }
        child.go_next();
    }
}
Ejemplo n.º 3
0
// -----------------------------------------------------------------------
bool ParseParameters(int Argc_, char *Argv_[], TParameters &Parameters_)
{
QSet<QString> Patterns;

for(int i = 1; i < Argc_; ++i) {
	const char *Argument = Argv_[i];
	size_t ArgLen = strlen(Argument);
	if(ArgLen < 2 || Argument[0] != '-') {
		std::cerr << "Invalid argument: '" << Argument << "'.";
		return false;
		}
	//
	switch(Argument[1]) {
	case 'i':
		Parameters_.InputFolder = QString::fromLocal8Bit(Argument + 2);
		break;
	case 'o':
		Parameters_.OutputFolder = QString::fromLocal8Bit(Argument + 2);
		break;
	case 'v':
		if(!ParseVariables(Argument + 2, Parameters_)) return false;
		break;
	case 'e':
		if(!ParseMasks(Argument + 2, Patterns, Parameters_.ExcludePatterns)) {
			std::cerr << "Invalid file mask found: '" << Argument + 2 << "'.";
			return false;
			}
		break;
	default:
		std::cerr << "Invalid switch: '" << Argument[0] << "'.";
		return false;
		} // switch
	}
	
if(Parameters_.InputFolder.isEmpty() || Parameters_.OutputFolder.isEmpty()) {
	std::cerr << "No input or output folder was specified.";
	return false;
	}
return true;	
}