void MapSettingsDialog::OnAdd(wxCommandEvent& event) { /*wxString files = _("Hoe script Files(*.lua)|*.lua|All files(*.*)|*.*"); wxFileDialog dialog(this,_("Add file..."),_T(""), _T(""), files, wxOPEN | wxHIDE_READONLY | wxFILE_MUST_EXIST | wxMULTIPLE); if (dialog.ShowModal() == wxID_OK) { wxArrayString paths; dialog.GetPaths(paths); for (unsigned int i=0;i < paths.Count();i++) { //AddFile(HoeUtils::relativepath(m_becherdir->GetValue().c_str(),paths[i].c_str()).c_str()); AddScriptFile(paths[i].c_str()); }*/ if (m_saddtext->GetValue() != "") { AddScriptFile(m_saddtext->GetValue()); m_saddtext->SetValue(""); UpdateButtons(); } }
void CPigEngine::ProcessScriptDirChanges() { XLock lock(this); // Copy the map of scripts XScriptMap mapScripts(m_mapScripts); // Loop thru the "*.pig" files in the script directory WIN32_FIND_DATA ffd; USES_CONVERSION; LPSTR pszScriptDirPatt = OLE2A(m_bstrScriptDir + "*.pig"); TCFileFindHandle hff = FindFirstFile(pszScriptDirPatt, &ffd); bool bContinue = !hff.IsNull() && INVALID_HANDLE_VALUE != hff; while (bContinue) { // Do not process directories, temporary or hidden files const DWORD dwIgnoreAttributes = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_HIDDEN; if (!(ffd.dwFileAttributes & dwIgnoreAttributes)) { // Attempt to find the file name in the map of scripts tstring strFile(ffd.cFileName); XScriptMapIt it = mapScripts.find(strFile); if (mapScripts.end() == it) AddScriptFile(&ffd, strFile); else { if (it->second->IsModified(&ffd)) ReloadScriptFile(&ffd, it); mapScripts.erase(it); } } // Get the next file in the directory bContinue = !!FindNextFile(hff, &ffd); } // Unload all files remaining in the local copy of the map of Scripts for (XScriptMapIt it = mapScripts.begin(); it != mapScripts.end(); ++it) UnloadScriptFile(it->first); /////////////////////////////////////////////////////////////////////////// // File Reconcilation is complete, now validate the files /////////////////////////////////////////////////////////////////////////// // Create a map of all behavior names, invalid or not XBehaviorMap mapGoodBadUgly; for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it) { CPigBehaviorScriptType* pType = it->second; // Get the collection of invoke commands for the new object XBehaviorMap mapCommands; ZSucceeded(GetInvokeCommands(pType, mapCommands)); // Add each invoke command to the map for (XBehaviorMapIt itCmd = mapCommands.begin(); itCmd != mapCommands.end(); ++itCmd) { mapGoodBadUgly.insert(*itCmd); debugf("inv command: %s\n", itCmd->first.c_str()); } } // Check for base behaviors that don't exist for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it) { CPigBehaviorScriptType* pType = it->second; if (pType->IsValid()) { tstring strBaseBehavior(pType->GetBaseBehaviorName()); if (strBaseBehavior.size() && _tcslen(strBaseBehavior.c_str())) { XBehaviorMapIt itFind = mapGoodBadUgly.find(strBaseBehavior); if (mapGoodBadUgly.end() == itFind) { RemoveInvokeCommands(pType); pType->SetBaseNonExistant(); } } } } // Check for recursive behavior derivations for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it) { CPigBehaviorScriptType* pType = it->second; if (pType->IsValid()) { std::set<tstring, ci_less> setNames; CPigBehaviorScriptType* pTypeBase = pType; while (!pTypeBase->GetBaseBehaviorName().empty()) { setNames.insert(pTypeBase->GetName()); if (setNames.end() == setNames.find(pTypeBase->GetBaseBehaviorName())) { XScriptMapIt itBase = mapGoodBadUgly.find(pTypeBase->GetBaseBehaviorName()); if (mapGoodBadUgly.end() != itBase) // KG- fix debug assert - was : m_mapBehaviors.end() != itBase { pTypeBase = itBase->second; continue; } } RemoveInvokeCommands(pType); pType->SetRecursionError(); break; } } } // Check for behaviors that have base behaviors with errors for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it) { CPigBehaviorScriptType* pType = it->second; if (pType->IsValid()) { std::vector<CPigBehaviorScriptType*> vecBaseTypes; vecBaseTypes.push_back(pType); tstring strBaseBehavior(pType->GetBaseBehaviorName()); while (strBaseBehavior.size() && _tcslen(strBaseBehavior.c_str())) { XBehaviorMapIt itBase = mapGoodBadUgly.find(strBaseBehavior); assert(mapGoodBadUgly.end() != itBase); pType = itBase->second; vecBaseTypes.push_back(pType); strBaseBehavior = pType->GetBaseBehaviorName(); } std::vector<CPigBehaviorScriptType*>::reverse_iterator rit1, rit2; rit1 = rit2 = vecBaseTypes.rbegin(); for (++rit2; rit2 != vecBaseTypes.rend(); ++rit1, ++rit2) { CPigBehaviorScriptType* pTypeBase = *rit1; CPigBehaviorScriptType* pType = *rit2; if (!pTypeBase->IsValid() && pType->IsValid()) { RemoveInvokeCommands(pType); pType->SetBaseError(); } } } } // Compute the stats on how many good and bad scripts are available int nValid = 0; for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it) if (it->second->IsValid()) ++nValid; // Display the stats on how many good and bad scripts are available #ifdef _DEBUG _TRACE_BEGIN _TRACE_PART1("CPigEngine::ProcessScriptDirChanges(): %d scripts loaded, ", m_mapScripts.size()); _TRACE_PART1("%d appear to be valid.\n", nValid); _TRACE_END #endif // _DEBUG // Trigger an event _AGCModule.TriggerEvent(NULL, PigEventID_ScriptsLoaded, L"", -1, -1, -1, 2, "TotalCount", VT_I4, m_mapScripts.size(), "ValidCount", VT_I4, nValid); }