Example #1
0
void SFTWorker::finishFile()
{
	m_hFh.close();

	std::string file = m_pCurFile->getFullPath();
	gcString str("{0}", m_pCurFile->getTimeStamp());

	try
	{
		UTIL::FS::setLastWriteTime(file, parseTimeStamp(str));
	}
	catch (...)
	{
		Warning(gcString("Failed to change {0} time stamp to {1}.\n", m_pCurFile->getName(), str));
	}

	safe_delete(m_pBzs);

	std::string hash = "Failed to generate hash";

#ifdef NIX
	bool isWinExe = false;
	
	if (file.size() > 4)
	{
		std::string lastFour(file.end() - 4, file.end());
		std::transform(lastFour.begin(), lastFour.end(), lastFour.begin(), ::toupper);
		if (lastFour == ".EXE")
			isWinExe = true;
	}
	
	//( && stat(file.c_str(), &s) == 0) 
	
	bool isExecutable = HasAnyFlags(m_pCurFile->getFlags(), MCFCore::MCFFileI::FLAG_XECUTABLE);

	if (isExecutable || isWinExe)
		chmod(file.c_str(), (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH));
#endif

	if (m_pCurFile->isZeroSize() || m_pCurFile->hashCheckFile(&hash))
	{
		m_pCT->endTask(m_uiId, BaseMCFThread::SF_STATUS_COMPLETE);
	}
	else
	{
		Warning(gcString("Hash check failed for file [{0}]: Cur: {1} !=  Should: {2}\n", m_pCurFile->getName(), hash, m_pCurFile->getCsum()));
		m_pCT->endTask(m_uiId, BaseMCFThread::SF_STATUS_HASHMISSMATCH);
	}
}
Example #2
0
int_least32_t SidDatabase::length (const char *md5, uint_least16_t song)
{
    int_least32_t  time = 0;

    if (!database)
    {
        errorString = ERR_NO_DATABASE_LOADED;
        return -1;
    }

    // Now set up array access
    if (ini_listDelims  (database, " ") == -1)
    {
        errorString = ERR_MEM_ALLOC;
        return -1;
    }

    // Read Time (and check times before hand)
    (void) ini_locateHeading (database, "Database");
    (void) ini_locateKey     (database, md5);
    // If length return is -1 then no entry found in database
    if (ini_dataLength (database) != -1)
    {
        char timeStamp[10];

        for (uint_least16_t i = 0; i < song; i++)
        {
            if (ini_readString (database, timeStamp, sizeof (timeStamp)) == -1)
            {   // No time found
                errorString = ERR_DATABASE_CORRUPT;
                return -1;
            }

            // Validate Time
            if (timesFound (timeStamp) != 1)
            {
                errorString = ERR_DATABASE_CORRUPT;
                return -1;
            }
        }

        // Parse timestamp
        time = parseTimeStamp (timeStamp);
    }

    return time;
}
Example #3
0
    bool parseJSON(rapidjson::Document & jsonDocument)
    {
        /// TODO: parse error

        // request id
        rapidjson::Value jsonValue = rapidjson::Value();
        
        if (!getJSONMemberSafe(jsonDocument, "id", jsonValue) || !jsonValue.IsString())
            return false;

        m_id = jsonValue.GetString();

        // timestamp
        if (!getJSONMemberSafe(jsonDocument, "timestamp", jsonValue) || !jsonValue.IsString())
            return false;

        parseTimeStamp(jsonValue.GetString(), m_timeStamp);
        
        // result
        rapidjson::Value jsonResult = rapidjson::Value();
        if (!getJSONMemberSafe(jsonDocument, "result", jsonResult) || !jsonResult.IsObject())
            return false;

        // result source
        if (getJSONMemberSafe(jsonResult, "source", jsonValue) && jsonValue.IsString())
            m_resultSource = jsonValue.GetString();

        // result resolved query
        if (getJSONMemberSafe(jsonResult, "resolvedQuery", jsonValue) && jsonValue.IsString())
            m_resolvedQuery = jsonValue.GetString();

        // result action
        if (getJSONMemberSafe(jsonResult, "action", jsonValue) && jsonValue.IsString())
            m_action = jsonValue.GetString();

        // result actionIncomplete
        if (getJSONMemberSafe(jsonResult, "actionIncomplete", jsonValue) && jsonValue.IsBool())
            m_isActionIncomplete = jsonValue.GetBool();

        // result parameters
        if (getJSONMemberSafe(jsonResult, "parameters", jsonValue) && jsonValue.IsObject())
        {
            rapidjson::Value::ConstMemberIterator iter;
            for (iter = jsonValue.MemberBegin(); iter != jsonValue.MemberEnd(); ++iter)
            {
                if (iter->name.IsString() && iter->value.IsString())
                m_resultParameters[iter->name.GetString()] = iter->value.GetString();
            }
        }

        // contexts
        if (getJSONMemberSafe(jsonResult, "contexts", jsonValue) && jsonValue.IsArray())
        {
            rapidjson::Value::Array const arr = jsonValue.GetArray();
            m_contexts.resize(arr.Size());
            for (size_t i = 0; i < m_contexts.size(); ++i)
            {
                m_contexts[i].parseJSON(arr[(rapidjson::SizeType)i]);
            }
        }

        // metadata
        if (getJSONMemberSafe(jsonResult, "metadata", jsonValue) && jsonValue.IsObject())
            m_metaData.parseJSON(jsonValue);

        // fulfillment
        if (getJSONMemberSafe(jsonResult, "fulfillment", jsonValue) && jsonValue.IsObject())
            m_fulfillment.parseJSON(jsonValue);

        // status
        if (getJSONMemberSafe(jsonDocument, "status", jsonValue) && jsonValue.IsObject())
            m_status.parseJSON(jsonValue);
        
        return true;
    }