i32 IResourceManager::LoadResource(ResourceWeakPtr *const ppRes, xst_castring& strFileName, xst_castring& strGroupName, bool bFullLoad) { xst_assert( m_pResFileMgr, "(IResourceManager::LoadResource) File manager not created" ); xst_assert2( (*ppRes).IsValid() ); Resources::IResource* pRes = (*ppRes).GetPtr(); //XST::FilePtr pFile = m_pResFileMgr->LoadFile( strFileName, strGroupName ); ResFileWeakPtr pFile2 = m_pResFileMgr->LoadFile2( strFileName, strGroupName ); if( pFile2.IsNull() /*&& pFile.IsNull()*/ ) { XST_LOG_ERR("Unable to load resource: " << strFileName << " in group: " << strGroupName); return XST_FAIL; } pRes->m_pResourceFile = pFile2; //pRes->_SetResourceFile( pFile ); //pRes->_SetResourceFile( pFile2 ); pRes->_SetResourceState( XST::ResourceStates::LOADED ); if( bFullLoad ) { if( XST_FAILED( PrepareResource( ppRes ) ) ) { return XST_FAIL; } } return XST_OK; }
ResourceWeakPtr IResourceManager::PrepareResource(xst_castring &strName, GroupWeakPtr pGroup) { xst_assert( pGroup.IsValid(), "(IResourceManager::PrepareResource) Group is null" ); ResourceWeakPtr pRes = pGroup->GetResource( strName ); if( !pRes ) { return XSE_NULLRES; } if( XST_FAILED( PrepareResource( &pRes ) ) ) { return XSE_NULLRES; } return pRes; }
void wxsNewWindowDlg::OnCreate(wxCommandEvent& event) { bool CreateXrc = m_UseXrc->GetValue(); cbProject* cbProj = m_Project->GetCBProject(); wxsItemRes::NewResourceParams Params; Params.Class = m_Class->GetValue(); Params.Src = m_Source->GetValue(); Params.Hdr = m_Header->GetValue(); Params.Xrc = CreateXrc ? m_Xrc->GetValue() : _T(""); Params.Pch = m_Pch->GetValue(); Params.Wxs = _T(""); Params.InitFunc = m_InitFunc->GetValue(); Params.BaseClass = m_BaseClass->GetValue(); Params.CustomCtorArgs = m_CtorCustom->GetValue(); Params.UsePch = m_UsePCH->GetValue(); Params.UseInitFunc = m_UseInitFunc->GetValue(); Params.CtorParent = m_CtorParent->GetValue(); Params.CtorParentDef = m_CtorParentDef->GetValue(); Params.CtorId = m_CtorId->GetValue(); Params.CtorIdDef = m_CtorIdDef->GetValue(); Params.CtorPos = m_CtorPos->GetValue(); Params.CtorPosDef = m_CtorPosDef->GetValue(); Params.CtorSize = m_CtorSize->GetValue(); Params.CtorSizeDef = m_CtorSizeDef->GetValue(); Params.ScopeIds = m_ScopeIdsVal; Params.ScopeMembers = m_ScopeMembersVal; Params.ScopeHandlers = m_ScopeHandlersVal; Params.UseFwdDecl = m_UseFwdDecl->GetValue(); Params.UseI18n = m_UseI18n->GetValue(); Params.PchGuard = m_PchGuard->GetValue(); // Need to do some checks // Validating name // TODO: Do not use fixed language if ( !wxsCodeMarks::ValidateIdentifier(wxsCPP,Params.Class) ) { wxMessageBox(_("Invalid class name")); return; } // Validating base class if ( !wxsCodeMarks::ValidateIdentifier(wxsCPP,Params.BaseClass) ) { wxMessageBox(_("Invalid name of base class")); return; } // Validating init function name if ( Params.UseInitFunc && !wxsCodeMarks::ValidateIdentifier(wxsCPP,Params.InitFunc) ) { wxMessageBox(_("Invalid name of init function")); return; } // Checking if there's given resoure in current project if ( m_Project->FindResource(Params.Class) ) { wxMessageBox(wxString::Format(_("Resource '%s' already exists"),Params.Class.c_str())); return; } // Validating PCH guard if needed if ( Params.UsePch && (Params.PchGuard.IsEmpty() || !wxsCodeMarks::ValidateIdentifier(wxsCPP,Params.PchGuard)) ) { wxMessageBox(_("Invalid name of pch guard")); return; } // Checking if files already exist wxString ProjectPrefix = m_Project->GetProjectPath(); Params.GenHdr = true; if ( wxFileName::FileExists(ProjectPrefix+Params.Hdr) ) { switch ( wxMessageBox(wxString::Format( _("File '%s' already exists. Overwrite it ?"),Params.Hdr.c_str()), _("File exists"), wxYES_NO|wxCANCEL|wxICON_ERROR) ) { case wxCANCEL: return; case wxNO: Params.GenHdr = false; break; } } Params.GenSrc = true; if ( wxFileName::FileExists(ProjectPrefix+Params.Src) ) { switch ( wxMessageBox(wxString::Format( _("File '%s' already exists. Overwrite it ?"),Params.Src.c_str()), _("File exists"),wxYES_NO|wxCANCEL|wxICON_ERROR) ) { case wxCANCEL: return; case wxNO: Params.GenSrc = false; break; } } Params.GenXrc = CreateXrc; if ( wxFileName::FileExists(ProjectPrefix+Params.Xrc) ) { // We will add new resource to existing one creating multi-resource xrc Params.GenXrc = false; } // Disable button to prevent more clicks while resource is created wxWindow* OkBtn = FindWindowById(wxID_OK); if ( OkBtn ) { OkBtn->Disable(); } // Creating new resource wxsItemRes* NewResource = 0; if ( m_Type == _T("wxDialog") ) { NewResource = new wxsDialogRes(m_Project); } else if ( m_Type == _T("wxScrollingDialog") ) { NewResource = new wxsScrollingDialogRes(m_Project); } else if ( m_Type == _T("wxFrame") ) { NewResource = new wxsFrameRes(m_Project); } else if ( m_Type == _T("wxPanel") ) { NewResource = new wxsPanelRes(m_Project); } else { Manager::Get()->GetLogManager()->DebugLog(_T("wxSmith: Internal error: unknown type when creating resource")); EndModal(wxID_CANCEL); return; } // Building new data if ( !NewResource->CreateNewResource(Params) ) { delete NewResource; Manager::Get()->GetLogManager()->DebugLog(_T("wxSmith: Couldn't generate new resource")); EndModal(wxID_CANCEL); return; } wxsItemResData* Data = NewResource->BuildResData(0); Data->BeginChange(); // Updating content of resource // This is done to allow XRC loader load proper data if ( !PrepareResource(NewResource,Data) ) { wxMessageBox(_("Error while initializing resource")); Data->EndChange(); delete Data; delete NewResource; EndModal(wxID_CANCEL); return; } if ( !m_Project->AddResource(NewResource) ) { wxMessageBox(_("Error while adding new resource into project")); Data->EndChange(); delete Data; delete NewResource; EndModal(wxID_CANCEL); return; } Data->EndChange(); Data->Save(); delete Data; // Register xrc file in autoload list if needed if ( m_AppManaged && CreateXrc && m_XRCAutoload->GetValue() && !Params.Xrc.IsEmpty() ) { wxWidgetsGUI* GUI = wxDynamicCast(m_Project->GetGUI(),wxWidgetsGUI); if ( GUI ) { wxArrayString& AutoList = GUI->GetLoadedResources(); if ( AutoList.Index(Params.Xrc) == wxNOT_FOUND ) { AutoList.Add(Params.Xrc); GUI->RebuildApplicationCode(); } } } // Adding new files to project wxArrayInt Targets; Manager::Get()->GetProjectManager()->AddFileToProject(Params.Hdr,cbProj,Targets); if (Targets.GetCount() != 0) { Manager::Get()->GetProjectManager()->AddFileToProject(Params.Src,cbProj,Targets); if ( !Params.Wxs.IsEmpty() && m_AddWxs->GetValue() ) { Manager::Get()->GetProjectManager()->AddFileToProject(Params.Wxs,cbProj,Targets); } } Manager::Get()->GetProjectManager()->RebuildTree(); // Opening editor for this resource NewResource->EditOpen(); // Saving configuration ConfigManager* Cfg = Manager::Get()->GetConfigManager(_T("wxsmith")); Cfg->Write(_T("/newresource/useinitfunc"),m_UseInitFunc->GetValue()); Cfg->Write(_T("/newresource/initfunc"),m_InitFunc->GetValue()); Cfg->Write(_T("/newresource/ctorparent"),m_CtorParent->GetValue()); Cfg->Write(_T("/newresource/ctorparentdef"),m_CtorParentDef->GetValue()); Cfg->Write(_T("/newresource/ctorid"),m_CtorId->GetValue()); Cfg->Write(_T("/newresource/ctorid"),m_CtorIdDef->GetValue()); Cfg->Write(_T("/newresource/ctorpos"),m_CtorPos->GetValue()); Cfg->Write(_T("/newresource/ctorpos"),m_CtorPosDef->GetValue()); Cfg->Write(_T("/newresource/ctorsize"),m_CtorSize->GetValue()); Cfg->Write(_T("/newresource/ctorsize"),m_CtorSizeDef->GetValue()); Cfg->Write(_T("/newresource/usexrc"),m_UseXrc->GetValue()); Cfg->Write(_T("/newresource/xrcautoloag"),m_XRCAutoload->GetValue()); Cfg->Write(_T("/newresource/addwxs"),m_AddWxs->GetValue()); Cfg->Write(_T("/newresource/scopeids"),(int)m_ScopeIdsVal); Cfg->Write(_T("/newresource/scopemembers"),(int)m_ScopeMembersVal); Cfg->Write(_T("/newresource/scopehandlers"),(int)m_ScopeHandlersVal); Cfg->Write(_T("/newresource/sourcedirectory"),m_SourceDirectory); Cfg->Write(_T("/newresource/usefwddecl"),m_UseFwdDecl->GetValue()); Cfg->Write(_T("/newresource/usei18n"),m_UseI18n->GetValue()); Cfg->Write(_T("/newresource/pchguard"),m_PchGuard->GetValue()); EndModal(wxID_OK); }
ResourceWeakPtr CMeshManager::CloneResource(const Resources::IResource* pSrcRes, xst_castring& strNewName /* = XST::StringUtil::EmptyAString */, bool bFullClone /* = true */) { XSTSimpleProfiler(); const Resources::CMesh* pSrcMesh = (const Resources::CMesh*)pSrcRes; ul32 ulID = XST::CTime::GetQPerfTickCount(); if( strNewName.empty() ) { //this->m_ssTmpName.str( XST::StringUtil::EmptyAString ); //this->m_ssTmpName << "xse_mesh_clone_" << ulID; xst_sprintf( g_astrName, 128, "xse_mesh_clone_%d", ulID ); g_strName.assign( g_astrName ); } ResourceWeakPtr pNewRes( this->CreateMesh( g_strName/*this->m_ssTmpName.str()*/, this->GetGroup( pSrcMesh->GetResourceGroupHandle() ) ) ); if( pNewRes == xst_null ) { return pNewRes; } if( XST_FAILED( PrepareResource( &pNewRes ) ) ) { this->DestroyResource( pNewRes ); return ResourcePtr(); } { XSTSimpleProfiler2( "clone mesh: set data" ); Resources::CMesh* pNewMesh = (Resources::CMesh*)pNewRes.GetPtr(); //if( bFullClone ) { for(int i = 0; i < pSrcMesh->m_vLODs.size(); ++i) { /*SMeshLOD* pCurrLOD = pSrcMesh->m_vLODs[ i ]; SMeshLOD* pNewLOD = pNewMesh->CreateLOD(); pNewLOD->byID = pCurrLOD->byID; pNewLOD->fDistance = pCurrLOD->fDistance; pNewLOD->pIndexBuffer = pCurrLOD->pIndexBuffer; pNewLOD->pMaterial = pCurrLOD->pMaterial; pNewLOD->pVertexBuffer = pCurrLOD->pVertexBuffer; pNewLOD->ulBeginIndexId = pCurrLOD->ulBeginIndexId; pNewLOD->ulBeginVertexId = pCurrLOD->ulBeginVertexId; pNewLOD->ulEndIndexId = pCurrLOD->ulEndIndexId; pNewLOD->ulEndVertexId = pCurrLOD->ulEndVertexId; pNewMesh->AddLOD( pNewLOD );*/ const SMeshLOD* pCurrLOD = &pSrcMesh->m_vLODs[ i ]; SMeshLOD& NewLOD = pNewMesh->AddLOD(); NewLOD.byID = pCurrLOD->byID; NewLOD.fDistance = pCurrLOD->fDistance; NewLOD.pIndexBuffer = pCurrLOD->pIndexBuffer; NewLOD.pMaterial = pCurrLOD->pMaterial; NewLOD.pVertexBuffer = pCurrLOD->pVertexBuffer; NewLOD.ulBeginIndexId = pCurrLOD->ulBeginIndexId; NewLOD.ulBeginVertexId = pCurrLOD->ulBeginVertexId; NewLOD.ulEndIndexId = pCurrLOD->ulEndIndexId; NewLOD.ulEndVertexId = pCurrLOD->ulEndVertexId; } } /*else { SMeshLOD& LOD = pNewMesh->AddLOD(); }*/ pNewMesh->m_ulCloneId = ulID; pNewMesh->m_bIsCloned = true; pNewMesh->m_bIndexedGeometry = pSrcMesh->m_bIndexedGeometry; pNewMesh->SetLOD( pSrcMesh->GetCurrentLODID() ); pNewMesh->SetResource( pSrcMesh ); pNewMesh->SetRenderableObject( pSrcMesh ); } return pNewRes; }
ResourceWeakPtr IResourceManager::PrepareResource(xst_castring &strName, xst_castring &strGroupName) { return PrepareResource( strName, GetGroup( strGroupName ) ); }