Esempio n. 1
0
bool TRFactory::ReadDescriptions(const string& inRelativePathFilename, TRDescriptionList& outDescriptionList)
{
    bool theSuccess = false;
    bool theDescriptionRead = false;

    // Open file specified by relative path name
    fstream infile;
    infile.open(inRelativePathFilename.c_str(), ios::in);

    if(infile.is_open())
    {
        do
        {
            // Try to read the next description in
            TRDescription theNextDescription;
            theDescriptionRead = ReadDescription(infile, theNextDescription);

            // add it to the description list
            if(theDescriptionRead)
            {
                // Function is successful if at least one description was found
                outDescriptionList.push_back(theNextDescription);
                theSuccess = true;
            }

        } while(theDescriptionRead);

        infile.close();
    }
    return theSuccess;
}
void SQueueParameters::Read(const IRegistry& reg, const string& sname)
{
    qclass = reg.GetString(sname, "class", kEmptyStr);

    timeout = ReadTimeout(reg, sname);
    notif_hifreq_interval = ReadNotifHifreqInterval(reg, sname);
    notif_hifreq_period = ReadNotifHifreqPeriod(reg, sname);
    notif_lofreq_mult = ReadNotifLofreqMult(reg, sname);
    notif_handicap = ReadNotifHandicap(reg, sname);
    dump_buffer_size = ReadDumpBufferSize(reg, sname);
    run_timeout = ReadRunTimeout(reg, sname);
    program_name = ReadProgram(reg, sname);
    failed_retries = ReadFailedRetries(reg, sname);
    blacklist_time = ReadBlacklistTime(reg, sname);
    max_input_size = ReadMaxInputSize(reg, sname);
    max_output_size = ReadMaxOutputSize(reg, sname);
    subm_hosts = ReadSubmHosts(reg, sname);
    wnode_hosts = ReadWnodeHosts(reg, sname);
    wnode_timeout = ReadWnodeTimeout(reg, sname);
    pending_timeout = ReadPendingTimeout(reg, sname);
    max_pending_wait_timeout = ReadMaxPendingWaitTimeout(reg, sname);
    description = ReadDescription(reg, sname);
    run_timeout_precision = ReadRunTimeoutPrecision(reg, sname);
    return;
}
Esempio n. 3
0
HSaveError OpenSavegameBase(const String &filename, SavegameSource *src, SavegameDescription *desc, SavegameDescElem elems)
{
    UStream in(File::OpenFileRead(filename));
    if (!in.get())
        return new SavegameError(kSvgErr_FileOpenFailed, String::FromFormat("Requested filename: %s.", filename.GetCStr()));

    // Skip MS Windows Vista rich media header
    RICH_GAME_MEDIA_HEADER rich_media_header;
    rich_media_header.ReadFromFile(in.get());

    // Check saved game signature
    bool is_new_save = false;
    size_t pre_sig_pos = in->GetPosition();
    String svg_sig = String::FromStreamCount(in.get(), SavegameSource::Signature.GetLength());
    if (svg_sig.Compare(SavegameSource::Signature) == 0)
    {
        is_new_save = true;
    }
    else
    {
        in->Seek(pre_sig_pos, kSeekBegin);
        svg_sig = String::FromStreamCount(in.get(), SavegameSource::LegacySignature.GetLength());
        if (svg_sig.Compare(SavegameSource::LegacySignature) != 0)
            return new SavegameError(kSvgErr_SignatureFailed);
    }

    SavegameVersion svg_ver;
    SavegameDescription temp_desc;
    HSaveError err;
    if (is_new_save)
        err = ReadDescription(in.get(), svg_ver, temp_desc, desc ? elems : kSvgDesc_None);
    else
        err = ReadDescription_v321(in.get(), svg_ver, temp_desc, desc ? elems : kSvgDesc_None);
    if (!err)
        return err;

    if (src)
    {
        src->Filename = filename;
        src->Version = svg_ver;
        src->InputStream.reset(in.release()); // give the stream away to the caller
    }
    if (desc)
    {
        if (elems & kSvgDesc_EnvInfo)
        {
            desc->EngineName = temp_desc.EngineName;
            desc->EngineVersion = temp_desc.EngineVersion;
            desc->GameGuid = temp_desc.GameGuid;
            desc->GameTitle = temp_desc.GameTitle;
            desc->MainDataFilename = temp_desc.MainDataFilename;
            desc->MainDataVersion = temp_desc.MainDataVersion;
            desc->ColorDepth = temp_desc.ColorDepth;
        }
        if (elems & kSvgDesc_UserText)
            desc->UserText = temp_desc.UserText;
        if (elems & kSvgDesc_UserImage)
            desc->UserImage.reset(temp_desc.UserImage.release());
    }
    return err;
}
//-----------------------------------------------------------------------------
bool psNPCLoader::LoadFromFile(csString &filename)
{
    area.Clear();

    CPrintf(CON_DEBUG, "Importing NPC from file: %s\n",filename.GetData());

    // try to read data from the file

    csRef<iVFS> vfs =  csQueryRegistry<iVFS> (psserver->GetObjectReg());
    csRef<iDataBuffer> data(vfs->ReadFile(filename.GetData()));
    if(!data || !data->GetSize())
    {
        CPrintf(CON_ERROR, "Error: Couldn't load file '%s'.\n", filename.GetData());
        return false;
    }

    csRef<iDocumentSystem> xml;
    xml.AttachNew(new csTinyDocumentSystem);
    csRef<iDocument> doc = xml->CreateDocument();
    const char* error = doc->Parse(data);
    if(error)
    {
        Error2("Error in XML: %s", error);
        return false;
    }
    npcRoot = doc->GetRoot()->GetNode("npc");

    if(!npcRoot)
    {
        CPrintf(CON_ERROR, "Error: no <npc> tag found\n");
        return false;
    }


    dialogManager = new psDialogManager;
    npc = new psCharacter;
    npc->SetCharType(PSCHARACTER_TYPE_NPC);

    // process xml data
    if(!ReadBasicInfo() || !ReadLocation())
    {
        CPrintf(CON_ERROR, "Error: Failed to load NPC data\n");
        return false;
    }
    ReadDescription();
    ReadTraits();
    ReadStats();
    ReadMoney();
    ReadSkills();
    ReadTrainerInfo();
    ReadMerchantInfo();
    ReadFactions();
    ReadKnowledgeAreas();
    ReadSpecificKnowledge();
    ReadSpecialResponses();

    // insert processed data into the database
    if(!WriteToDatabase())
    {
        CPrintf(CON_ERROR, "Error: Failed to insert data into the database\n");
        return false;
    }

    return true;
}
Esempio n. 5
0
bool DefFile::Read()
{
    stream = new std::fstream(fileName.c_str(), std::ios::in);
    if (stream != NULL)
    {
        try
        {
            lineno = 0;
            NextToken();
            while (!stream->eof())
            {
                if (token->IsEnd())
                {
                    NextToken();
                }
                else if (!token->IsKeyword())
                {
                    throw new std::runtime_error("Invalid directive");
                }
                else
                {
                    switch(token->GetKeyword())
                    {
                        case edt_name:
                            ReadName();
                            break;
                        case edt_library:
                            ReadLibrary();
                            break;
                        case edt_exports:
                            ReadExports();
                            break;
                        case edt_imports:
                            ReadImports();
                            break;
                        case edt_description:
                            ReadDescription();
                            break;
                        case edt_stacksize:
                            ReadStacksize();
                            break;
                        case edt_heapsize:
                            ReadHeapsize();
                            break;
                        case edt_code:
                            ReadCode();
                            break;
                        case edt_data:
                            ReadData();
                            break;
                        case edt_sections:
                            ReadSections();
                            break;
                        default:
                            throw new std::runtime_error("Invalid directive");
                    }
                }
            }
        }
        catch (std::runtime_error *e)
        {
            std::cout << fileName << "(" << lineno << "): " << e->what() << std::endl ;
            delete e;
        }
        delete stream;
    }
    else
    {
        std::cout << "File '" << name << "' not found." << std::endl;
    }
    return true;
}