示例#1
0
文件: LngRc.cpp 项目: BigVal71/ConEmu
// Concatenate strings from array and set resource item
bool CLngRc::SetResource(MArray<LngRcItem>& arr, int idx, MJsonValue* pJson)
{
	CEStr lsValue;
	MJsonValue jStr;

	// [ "Decrease window height ", "(check ‘Resize with arrows’)" ]
	size_t iCount = pJson->getLength();

	for (size_t i = 0; i < iCount; i++)
	{
		if (!pJson->getItem(i, jStr) || (jStr.getType() != MJsonValue::json_String))
		{
			_ASSERTE(FALSE && "String format failure");
			return false;
		}
		lstrmerge(&lsValue.ms_Val, jStr.getString());
	}

	if (lsValue.IsEmpty())
	{
		_ASSERTE(FALSE && "Empty resource string (array)");
		return false;
	}

	return SetResource(arr, idx, lsValue.ms_Val, true);
}
    void MaterialLibrary::Load()
    {
        ResourceType* currMat = nullptr;
        std::string currLine;
        auto filename = Resource::application->GetConfig().resourceBase + "/" + GetParameters()[0];
        std::ifstream inFile(filename);

        if (!inFile.is_open()) {
            throw resource_loading_error() << ::boost::errinfo_file_name(filename) << resid_info(id) << errdesc_info("Cannot open file.");
        }

        boost::regex reg_newmtl("^newmtl\\s+(\\w+)$");
        boost::regex reg_Ka("^Ka\\s+" + regex_help::flt3 + "$");
        boost::regex reg_Kd("^Kd\\s+" + regex_help::flt3 + "$");
        boost::regex reg_Ks("^Ks\\s+" + regex_help::flt3 + "$");
        boost::regex reg_d("^d\\s+" + regex_help::flt + "$");
        boost::regex reg_d_halo("^d\\s+-halo\\s+" + regex_help::flt + "$");
        boost::regex reg_Ns("^Ns\\s+" + regex_help::flt + "$");
        boost::regex reg_Ni("^Ni\\s+" + regex_help::flt + "$");
        boost::regex reg_map_Kd("^map_Kd\\s+(.*\\s+)?([\\w-]+\\.\\w+)$");
        boost::regex reg_map_bump("^(map_bump|bump)\\s+(.*\\s+)?([\\w-]+\\.\\w+)$");

        boost::smatch lineMatch;

        while (inFile.good()) {
            std::getline(inFile, currLine);

            boost::trim(currLine);
            if (currLine.length() == 0 || boost::starts_with(currLine, "#"))
                continue; // comment or empty line
            if (boost::regex_match(currLine, lineMatch, reg_newmtl)) {
                auto mtlName = lineMatch[1].str();
                currMat = SetResource(mtlName, std::move(std::make_unique<Material>()));
            } else if (boost::regex_match(currLine, lineMatch, reg_Ka) && currMat) {
                currMat->ambient = parseColor(lineMatch);
            } else if (boost::regex_match(currLine, lineMatch, reg_Kd) && currMat) {
                currMat->diffuse = parseColor(lineMatch);
            } else if (boost::regex_match(currLine, lineMatch, reg_Ks) && currMat) {
                currMat->specular = parseColor(lineMatch);
            } else if (boost::regex_match(currLine, lineMatch, reg_d) && currMat) {
                currMat->alpha = boost::lexical_cast<float>(lineMatch[1].str());
            } else if (boost::regex_match(currLine, lineMatch, reg_d_halo) && currMat) {
                currMat->minOrientedAlpha = boost::lexical_cast<float>(lineMatch[1].str());
            } else if (boost::regex_match(currLine, lineMatch, reg_Ns) && currMat) {
                currMat->N_s = boost::lexical_cast<float>(lineMatch[1].str());
            } else if (boost::regex_match(currLine, lineMatch, reg_Ni) && currMat) {
                currMat->N_i = boost::lexical_cast<float>(lineMatch[1].str());
            } else if (boost::regex_match(currLine, lineMatch, reg_map_Kd) && currMat) {
                currMat->diffuseTex = parseTexture(lineMatch[2].str(), "sRGB");
            } else if (boost::regex_match(currLine, lineMatch, reg_map_bump) && currMat) {
                currMat->bumpTex = parseTexture(lineMatch[3].str(), "");
                currMat->bumpMultiplier = parseFloatParameter("-bm", lineMatch[2].str(), 1.0f);
            } else {
                notImplemented(currLine);
            }
        }
        inFile.close();

        Resource::Load();
    }
示例#3
0
status_t
GoogleTalk::UpdateSettings( BMessage & msg )
{
	const char *username = NULL;
	const char *password = NULL;
	const char *res = NULL;
	
	msg.FindString("username", &username);
	msg.FindString("password", &password);
	msg.FindString("resource", &res);
	
	if ( (username == NULL) || (password == NULL) ){ 
		LOG( kProtocolName, liHigh, "Invalid settings!");
		return B_ERROR;
	};
	
	fUsername = username;
	int32 atpos=fUsername.FindLast("@");
	if(	 atpos> 0 ) {
		BString server;
		fUsername.CopyInto(server,atpos + 1,fUsername.Length()-atpos);
		fUsername.Remove(atpos,fUsername.Length()-atpos);
		LOG( kProtocolName, liHigh, "Server %s\n",server.String());
		fServer = server;		
	}
	else
		fServer.SetTo("gmail.com");
		
	
	fPassword = password;
	
	SetUsername(fUsername);
	SetHost(fServer);
	SetPassword(fPassword);
	
	if(strlen(res)==0)
		SetResource("IMKit GoogleTalk AddOn");
	else
		SetResource(res);
	
	SetPriority(5);
	SetPort(5222);
	
	return B_OK;
}
void AirsideFollowMeCarInSim::UpdateState( const ClearanceItem& item )
{
	SetTime(item.GetTime());
	SetResource(item.GetResource());
	SetPosition(item.GetPosition());
	SetSpeed(item.GetSpeed());
	SetDistInResource(item.GetDistInResource());
	SetMode(item.GetMode());	
}
bool PerformFlowLicenseeVerification(AwaClientSession *session, Verification *verificationData, const char *licenseeSecret)
{
    uint8_t licenseeHash[SHA256_HASH_LENGTH] = {0};
    char licenseeHashResourcePath[URL_PATH_SIZE] = {0};
    AwaError error;

    if (session == NULL || verificationData == NULL)
    {
        LOG(LOG_ERR, "Null params passed to %s()", __func__);
        return false;
    }

    LOG(LOG_INFO, "Performing flow license verification");

    // Calculate the LicenseeHash based-on challenge
    if (!CalculateLicenseeHash(licenseeHash, verificationData->challenge.Data,
        verificationData->challenge.Size, verificationData->iterations, licenseeSecret))
    {
        LOG(LOG_ERR, "Failed to calculate licensee hash");
        verificationData->waitForServerResponse = false;
        return false;
    }

    if (verificationData->licenseeHash.Data != NULL)
    {
        free(verificationData->licenseeHash.Data);
    }

    verificationData->licenseeHash.Data = malloc(SHA256_HASH_LENGTH);

    if (verificationData->licenseeHash.Data != NULL)
    {
        memcpy(verificationData->licenseeHash.Data , licenseeHash, SHA256_HASH_LENGTH);
    }

    verificationData->licenseeHash.Size = SHA256_HASH_LENGTH;

    // Write the hash to the Flow object
    if ((error = MAKE_FLOW_OBJECT_RESOURCE_PATH(licenseeHashResourcePath, FlowObjectResourceId_LicenseeHash)) == AwaError_Success)
    {
        if(!SetResource(session, licenseeHashResourcePath, (void *)&verificationData->licenseeHash, AwaResourceType_Opaque))
        {
            LOG(LOG_ERR, "Failed to set licensee hash");
            return false;
        }
    }
    else
    {
        LOG(LOG_ERR, "Failed to create licensee hash resource path\nerror: %s", AwaError_ToString(error));
        return false;
    }
    return true;
}
示例#6
0
status_t
Jabber::UpdateSettings( BMessage & msg )
{
	const char *username = NULL;
	const char *server=NULL;
	const char *password = NULL;
	const char *res = NULL;
	
	msg.FindString("username", &username);
	msg.FindString("server",&server);
	msg.FindString("password", &password);
	msg.FindString("resource", &res);
	
	if ( (username == NULL) || (password == NULL) || (server == NULL)) {
//		invalid settings, fail
		LOG( kProtocolName, liHigh, "Invalid settings!");
		return B_ERROR;
	};
	
	fUsername = username;
	fServer = server;
	fPassword = password;
	
	SetUsername(fUsername);
	SetHost(fServer);
	SetPassword(fPassword);
	
	if(strlen(res)==0)
		SetResource("IMKit Jabber AddOn");
	else
		SetResource(res);
	
	SetPriority(5);
	SetPort(5222);
	
	return B_OK;
}
示例#7
0
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Performs the specified operation.
///
void MgdResourcePackageLoader::PerformOperation(const MgOperationInfo& opInfo)
{
    MG_RESOURCE_SERVICE_TRY()

    CREFSTRING opName = opInfo.GetName();

    if (MgdOperationName::UpdateRepository == opName)
    {
        UpdateRepository(opInfo);
    }
    else if (MgdOperationName::SetResource == opName)
    {
        SetResource(opInfo);
    }
    else if (MgdOperationName::DeleteResource == opName)
    {
        DeleteResource(opInfo);
    }
    else if (MgdOperationName::MoveResource == opName)
    {
        MoveResource(opInfo);
    }
    else if (MgdOperationName::CopyResource == opName)
    {
        CopyResource(opInfo);
    }
    else if (MgdOperationName::ChangeResourceOwner == opName)
    {
        ChangeResourceOwner(opInfo);
    }
    else if (MgdOperationName::InheritPermissionsFrom == opName)
    {
        InheritPermissionsFrom(opInfo);
    }
    else if (MgdOperationName::SetResourceData == opName)
    {
        SetResourceData(opInfo);
    }
    else if (MgdOperationName::DeleteResourceData == opName)
    {
        DeleteResourceData(opInfo);
    }
    else if (MgdOperationName::RenameResourceData == opName)
    {
        RenameResourceData(opInfo);
    }

    MG_RESOURCE_SERVICE_CATCH_AND_THROW(L"MgdResourcePackageLoader.PerformOperation")
}
示例#8
0
void VScriptInstance::Serialize( VArchive &ar )
{
  IVScriptInstance::Serialize(ar);
  if (ar.IsLoading())
  {
    char iVersion;
    ar >> iVersion; VVERIFY(iVersion==0 && "invalid version number");
    VScriptResource *pRes = (VScriptResource *)ar.ReadProxyObject();
    Init();
    SetResource(pRes);
    if (pRes)
    {
      VScriptResourceManager *pManager = (VScriptResourceManager *)pRes->GetParentManager();
      pManager->Instances().Add(this);
    }
  }
示例#9
0
/**
 * Construct a shader from shader compiler output.
 */
FShader::FShader(const CompiledShaderInitializerType& Initializer):
	MaterialShaderMapHash(Initializer.MaterialShaderMapHash),
	VFType(Initializer.VertexFactoryType),
	Type(Initializer.Type),
	Target(Initializer.Target),
	NumRefs(0),
	SetParametersId(0),
	Canary(ShaderMagic_Initialized)
{
	OutputHash = Initializer.OutputHash;
	checkSlow(OutputHash != FSHAHash());

	if (Type)
	{
		// Store off the source hash that this shader was compiled with
		// This will be used as part of the shader key in order to identify when shader files have been changed and a recompile is needed
		SourceHash = Type->GetSourceHash();
	}

	if (VFType)
	{
		// Store off the VF source hash that this shader was compiled with
		VFSourceHash = VFType->GetSourceHash();
	}

	// Bind uniform buffer parameters automatically 
	for (TLinkedList<FUniformBufferStruct*>::TIterator StructIt(FUniformBufferStruct::GetStructList()); StructIt; StructIt.Next())
	{
		if (Initializer.ParameterMap.ContainsParameterAllocation(StructIt->GetShaderVariableName()))
		{
			UniformBufferParameterStructs.Add(*StructIt);
			UniformBufferParameters.Add(StructIt->ConstructTypedParameter());
			FShaderUniformBufferParameter* Parameter = UniformBufferParameters.Last();
			Parameter->Bind(Initializer.ParameterMap, StructIt->GetShaderVariableName(), SPF_Mandatory);
		}
	}

	SetResource(Initializer.Resource);

	// Register the shader now that it is valid, so that it can be reused
	Register();
}
void AirsideFollowMeCarInSim::ServicingFlight()
{
	double dDist = m_pServiceFlight->GetDistInResource() + m_pServiceFlight->GetLogEntry().GetAirsideDescStruct().dLength;
	CPoint2008 CarPos = m_pServiceFlight->GetResource()->GetDistancePoint(dDist);

	SetMode(OnService);
	SetSpeed(m_pServiceFlight->GetSpeed());
	ElapsedTime tTime = ElapsedTime(2.0*CarPos.distance(GetPosition())/GetSpeed()) + GetTime();
	SetTime(tTime);
	if(GetResource() != m_pServiceFlight->GetResource())
		GetResource()->SetExitTime(this,tTime);
	SetResource(m_pServiceFlight->GetResource());
	SetPosition(CarPos);
	SetDistInResource(dDist);
	WirteLog(CarPos,GetSpeed(),tTime);

	m_pServiceFlight->SetBeginFollowMeCarService();

	AirsideFollowMeCarServiceEvent* pEvent = new AirsideFollowMeCarServiceEvent(m_pServiceFlight);
	pEvent->setTime(tTime);
	pEvent->addEvent();
}
示例#11
0
文件: LngRc.cpp 项目: BigVal71/ConEmu
bool CLngRc::LoadSection(MJsonValue* pJson, MArray<LngRcItem>& arr, int idDiff)
{
	bool bRc = false;
	MJsonValue jRes, jItem;

	_ASSERTE(!ms_Lng.IsEmpty());

	for (INT_PTR i = arr.size()-1; i >= 0; --i)
	{
		LngRcItem& l = arr[i];
		l.Processed = false;
		l.Localized = false;
	}

	size_t iCount = pJson->getLength();

	for (size_t i = 0; i < iCount; i++)
	{
		if (!pJson->getItem(i, jRes) || (jRes.getType() != MJsonValue::json_Object))
			continue;

		// Now, jRes contains something like this:
	    // {
	    //  "en": "Decrease window height (check ‘Resize with arrows’)",
	    //  "ru": [ "Decrease window height ", "(check ‘Resize with arrows’)" ],
	    //  "id": 2046
		// }
		LPCWSTR lsLoc = NULL;
		i64 id = -1;
		size_t childCount = jRes.getLength();

		for (INT_PTR c = (childCount - 1); c >= 0; --c)
		{
			LPCWSTR pszName = jRes.getObjectName(c);
			if (!pszName || !*pszName)
			{
				_ASSERTE(FALSE && "Invalid object name!");
				return false;
			}

			// "id" field must be LAST!
			if (wcscmp(pszName, L"id") == 0)
			{
				if (!jRes.getItem(c, jItem) || (jItem.getType() != MJsonValue::json_Integer))
				{
					_ASSERTE(FALSE && "Invalid 'id' field");
					return false;
				}
				id = jItem.getInt();
				if ((id <= idDiff) || ((id - idDiff) > 0xFFFF))
				{
					_ASSERTE(FALSE && "Invalid 'id' value");
					return false;
				}

			} // "id"

			// "en" field must be FIRST!
			else if ((wcscmp(pszName, ms_Lng) == 0)
				|| (wcscmp(pszName, L"en") == 0)
				)
			{
				if (id == -1)
				{
					_ASSERTE(FALSE && "Wrong format, 'id' not found!");
					return false;
				}

				if (!jRes.getItem(c, jItem)
					|| ((jItem.getType() != MJsonValue::json_String)
						&& (jItem.getType() != MJsonValue::json_Array))
					)
				{
					_ASSERTE(FALSE && "Invalid 'lng' field");
					return false;
				}

				switch (jItem.getType())
				{
				case MJsonValue::json_String:
					if (!SetResource(arr, (id - idDiff), jItem.getString(), true))
					{
						// Already asserted
						return false;
					}
					bRc = true;
					break;
				case MJsonValue::json_Array:
					if (!SetResource(arr, (id - idDiff), &jItem))
					{
						// Already asserted
						return false;
					}
					bRc = true;
					break;
				default:
					_ASSERTE(FALSE && "Unsupported object type!")
					return false;
				} // switch (jItem.getType())

				// proper lng string found and processed, go to next resource
				break; // for (size_t c = 0; c < childCount; c++)

			} // ms_Lng || "en"

		} // for (size_t c = 0; c < childCount; c++)

	} // for (size_t i = 0; i < iCount; i++)

	return bRc;
}
示例#12
0
bool FShader::SerializeBase(FArchive& Ar, bool bShadersInline)
{
	Serialize(Ar);

	Ar << OutputHash;
	Ar << MaterialShaderMapHash;
	Ar << VFType;
	Ar << VFSourceHash;
	Ar << Type;
	Ar << SourceHash;
	Ar << Target;

	if (Ar.IsLoading())
	{
		int32 NumUniformParameters;
		Ar << NumUniformParameters;

		for (int32 ParameterIndex = 0; ParameterIndex < NumUniformParameters; ParameterIndex++)
		{
			FString StructName;
			Ar << StructName;

			FUniformBufferStruct* Struct = FindUniformBufferStructByName(*StructName);
			FShaderUniformBufferParameter* Parameter = Struct ? Struct->ConstructTypedParameter() : new FShaderUniformBufferParameter();

			Ar << *Parameter;

			UniformBufferParameterStructs.Add(Struct);
			UniformBufferParameters.Add(Parameter);
		}

		// The shader has been serialized in, so this shader is now initialized.
		check(Canary != ShaderMagic_CleaningUp);
		Canary = ShaderMagic_Initialized;
	}
	else
	{
		int32 NumUniformParameters = UniformBufferParameters.Num();
		Ar << NumUniformParameters;

		for (int32 StructIndex = 0; StructIndex < UniformBufferParameters.Num(); StructIndex++)
		{
			FString StructName(UniformBufferParameterStructs[StructIndex]->GetStructTypeName());
			Ar << StructName;
			Ar << *UniformBufferParameters[StructIndex];
		}
	}

	if (bShadersInline)
	{
		// Save the shader resource if we are inlining shaders
		if (Ar.IsSaving())
		{
			Resource->Serialize(Ar);
		}

		if (Ar.IsLoading())
		{
			// Load the inlined shader resource
			FShaderResource* ShaderResource = new FShaderResource();
			ShaderResource->Serialize(Ar);

			TRefCountPtr<FShaderResource> ExistingResource = FShaderResource::FindShaderResourceById(ShaderResource->GetId());

			// Reuse an existing shader resource if a matching one already exists in memory
			if (ExistingResource)
			{
				delete ShaderResource;
				ShaderResource = ExistingResource;
			}
			else
			{
				// Register the newly loaded shader resource so it can be reused by other shaders
				ShaderResource->Register();
			}
			
			SetResource(ShaderResource);
		}
	}
	else
	{
		// if saving, there's nothing to, the required data is already saved above to look it up at load time
		if (Ar.IsLoading())
		{
			// generate a resource id
			FShaderResourceId ResourceId;
			ResourceId.Target = Target;
			ResourceId.OutputHash = OutputHash;
			ResourceId.SpecificShaderTypeName = Type->LimitShaderResourceToThisType() ? Type->GetName() : NULL;

			// use it to look up in the registered resource map
			TRefCountPtr<FShaderResource> ExistingResource = FShaderResource::FindShaderResourceById(ResourceId);
			SetResource(ExistingResource);
		}
	}

	return false;
}
示例#13
0
void CCursorDoc::SetCursorResource(std::auto_ptr<CCursorResource> pCursor, int id)
{
    SetResource(pCursor.get(), id);
    pCursor.release();
}
示例#14
0
ECode CWallpaperManager::Clear()
{
    SetResource(R::drawable::default_wallpaper);
    return NOERROR;
}