DWORD FindProcessId(std::string processName) { PROCESSENTRY32 processInfo; processInfo.dwSize = sizeof(processInfo); processName=MakeLower(processName); HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); if ( processesSnapshot == INVALID_HANDLE_VALUE ) return 0; Process32First(processesSnapshot, &processInfo); std::string nextprocessname = MakeLower(processInfo.szExeFile); if ( !processName.compare(nextprocessname) ) { CloseHandle(processesSnapshot); return processInfo.th32ProcessID; } while ( Process32Next(processesSnapshot, &processInfo) ) { nextprocessname = MakeLower(processInfo.szExeFile); if ( !processName.compare(nextprocessname) ) { CloseHandle(processesSnapshot); return processInfo.th32ProcessID; } } CloseHandle(processesSnapshot); return 0; }
HTREEITEM CTreeCtrl::FindItem(LPCWSTR pText,BOOL bBackwardDirection,BOOL bPartial,HTREEITEM hItem,HTREEITEM hEnd) const { TV_ITEMW ti; WCHAR szBuffer[1000]; ti.mask=TVIF_TEXT; ti.hItem=hItem; ti.pszText=szBuffer; ti.cchTextMax=1000; LPWSTR pTextMod; if (bPartial) { int iStrLen=istrlen(pText); pTextMod=new WCHAR[iStrLen+3]; if (pText[0]!='*') { pTextMod[0]='*'; MemCopyW(pTextMod+1,pText,iStrLen++); } else MemCopyW(pTextMod,pText,iStrLen); if (pTextMod[iStrLen-1]!='*') pTextMod[iStrLen++]='*'; pTextMod[iStrLen]='\0'; MakeLower(pTextMod); } while ((ti.hItem=bBackwardDirection?GetPrevItem(ti.hItem):GetNextItem(ti.hItem))!=NULL) { // Get next item if (ti.hItem==hEnd) return NULL; // Check text if (!GetItem(&ti)) continue; if (bPartial) { MakeLower(szBuffer); if (ContainString(szBuffer,pTextMod)) { delete[] pTextMod; return ti.hItem; } } else if (_wcsicmp(szBuffer,pText)==0) return ti.hItem; } if (bPartial) delete[] pTextMod; return NULL; }
inline void CCheckFileNotificationsThread::FileCreated(LPCWSTR szFile,DWORD dwLength,CLocateDlg* pLocateDlg) { //BkgDebugNumMessage("File created: %S",DWORD(szFile)); if (pLocateDlg->m_pListCtrl==NULL) return; BOOL bIsDirectory=FileSystem::IsDirectory(szFile); WCHAR szPath[MAX_PATH]; int nItem=pLocateDlg->m_pListCtrl->GetNextItem(-1,LVNI_ALL); while (nItem!=-1) { if (m_lFlags&fwStopWhenPossible) break; CLocatedItem* pItem=(CLocatedItem*)pLocateDlg->m_pListCtrl->GetItemData(nItem); if (pItem!=NULL) { if (pItem->GetPathLen()==dwLength) { if (pItem->IsDeleted()) { MemCopyW(szPath,pItem->GetPath(),pItem->GetPathLen()+1); MakeLower(szPath); if (wcsncmp(szPath,szFile,dwLength)==0) { if (pItem->RemoveFlagsForChanged()) pLocateDlg->m_pListCtrl->RedrawItems(nItem,nItem); } } } else if (bIsDirectory && pItem->GetPathLen()>dwLength) { if (pItem->IsDeleted() && pItem->GetPath()[dwLength]=='\\') { MemCopyW(szPath,pItem->GetPath(),dwLength); MakeLower(szPath,dwLength); // Can be subdiretory if (wcsncmp(szPath,szFile,dwLength)==0) { if (pItem->RemoveFlagsForChanged()) pLocateDlg->m_pListCtrl->RedrawItems(nItem,nItem); } } } } nItem=pLocateDlg->m_pListCtrl->GetNextItem(nItem,LVNI_ALL); } //BkgDebugMessage("File created ENF"); }
MTConnectDataModel MTConnectDeviceParser::ReadDeviceDescription(std::string filename) { MTConnectDataModel dataItems; dataItems.clear(); if(GetFileAttributesA(filename.c_str())== INVALID_FILE_ATTRIBUTES) { filename= ::ExeDirectory() + filename; } if(GetFileAttributesA(filename.c_str())== INVALID_FILE_ATTRIBUTES) throw std::exception("MTConnectDeviceParser::ReadDeviceDescription invalid devices file"); _devicesfilename = filename; try{ ParseXMLDocument(_devicesfilename.c_str()); MSXML2::IXMLDOMNodePtr root = m_pXMLDoc->GetdocumentElement(); MSXML2::IXMLDOMNodeListPtr nodes = root->selectNodes(_bstr_t("//DataItem")); for(int i=0; i< nodes->length; i++) { MSXML2::IXMLDOMNodePtr pNode = NULL; CDataItem dataItem; nodes->get_item(i, &pNode); dataItem.name = (LPCSTR) GetAttribute(pNode, "name"); dataItem.category = (LPCSTR) GetAttribute(pNode, "category"); dataItem.id = (LPCSTR) GetAttribute(pNode, "id"); dataItem.type = (LPCSTR) GetAttribute(pNode, "type"); dataItem.subType = (LPCSTR) GetAttribute(pNode, "subType"); dataItem.units = (LPCSTR) GetAttribute(pNode, "units"); dataItem.nativeUnits = (LPCSTR) GetAttribute(pNode, "nativeUnits"); if(dataItem.type == "ASSET_CHANGED") { dataItem.category = "ASSET_CHANGED"; } dataItem.category=MakeLower(dataItem.category); if(!dataItem.name.empty()) { dataItems[dataItem.name]=dataItem; } // Could get name or id via SHDR else if(!dataItem.id.empty()) { dataItems[dataItem.id]=dataItem; } else { continue; } } } catch(_com_error error) { std::cout << "MTConnectDeviceParser::ReadDeviceDescription" << error.ErrorMessage(); } return dataItems; }
inline void CCheckFileNotificationsThread::FileModified(LPCWSTR szFile,DWORD dwLength,CLocateDlg* pLocateDlg) { //BkgDebugNumMessage("File modified: %S",DWORD(szFile)); if (pLocateDlg->m_pListCtrl==NULL) return; WCHAR szPath[MAX_PATH]; int nItem=pLocateDlg->m_pListCtrl->GetNextItem(-1,LVNI_ALL); while (nItem!=-1) { if (m_lFlags&fwStopWhenPossible) break; CLocatedItem* pItem=(CLocatedItem*)pLocateDlg->m_pListCtrl->GetItemData(nItem); if (pItem!=NULL) { if (pItem->GetPathLen()==dwLength) { MemCopyW(szPath,pItem->GetPath(),pItem->GetPathLen()+1); MakeLower(szPath); if (wcsncmp(szPath,szFile,dwLength)==0) { if (pItem->RemoveFlagsForChanged()) pLocateDlg->m_pListCtrl->RedrawItems(nItem,nItem); } } } nItem=pLocateDlg->m_pListCtrl->GetNextItem(nItem,LVNI_ALL); } //BkgDebugMessage("File modified END"); }
// Constructor & Destructor Bounce::Bounce( FILE *f ) : start(0.0), speed(1.0), dir(0,1,0) { // Search the scene file. char buf[ MAXLINELENGTH ], token[256], *ptr; while( fgets(buf, MAXLINELENGTH, f) != NULL ) { // Is this line a comment? ptr = StripLeadingWhiteSpace( buf ); if (ptr[0] == '#') continue; // Nope. So find out what the command is... ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); // Take different measures, depending on the command. if (!strcmp(token,"end")) break; if (!strcmp(token,"dir") || !strcmp(token, "direction") || !strcmp(token, "vector")) dir = Vector( ptr ); else if (!strcmp(token,"speed")) { ptr = StripLeadingTokenToBuffer( ptr, token ); speed = (float)atof( token ); } else if (!strcmp(token,"start")) { ptr = StripLeadingTokenToBuffer( ptr, token ); start = (float)atof( token ); } else Error("Unknown command '%s' when loading Bounce!", token); } }
int CHpiHandler::GetFileSize(string name) { MakeLower(name); if(files.find(name)==files.end()) return 0; return files[name].size; }
int FileUtils::PrintLines(string fname) { char line[1024]; int ret; ret = OpenFileForRead(fname); if(!ret) return -1; ret = AllocBuffer(); if(!ret) return -1; ret = FirstRead(); if(!ret) { Release(); return -1; } while(1) { ret = GetLine(line,1024); Trim(line); MakeLower(line); cout<<"|"<<line<<"|"<<endl; if(ret) break; } Release(); return 1; }
Camera::Camera( FILE *f, Scene *s ) : fovy(90.f), eye( 0, 0, 1 ), at( 0, 0, 0 ), up( 0, 1, 0 ), _near(0.1), _far(20), ball(0) { // Setup default values, in case the scene file is defective... s->SetWidth ( 512 ); s->SetHeight( 512 ); // Search the scene file. char buf[ MAXLINELENGTH ], token[256], *ptr; while( fgets(buf, MAXLINELENGTH, f) != NULL ) { // Is this line a comment? ptr = StripLeadingWhiteSpace( buf ); if (ptr[0] == '#') continue; // Nope. So find out what the command is... ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); // Take different measures, depending on the command. if (!strcmp(token,"end")) break; if (!strcmp(token,"eye")) eye = Point( ptr ); else if (!strcmp(token,"at")) at = Point( ptr ); else if (!strcmp(token,"up")) up = Vector( ptr ); else if (!strcmp(token,"w") || !strcmp(token,"width") ) { ptr = StripLeadingTokenToBuffer( ptr, token ); s->SetWidth( (int)atof( token ) ); } else if (!strcmp(token,"h") || !strcmp(token,"height") ) { ptr = StripLeadingTokenToBuffer( ptr, token ); s->SetHeight( (int)atof( token ) ); } else if (!strcmp(token,"res") || !strcmp(token, "resolution")) { ptr = StripLeadingTokenToBuffer( ptr, token ); s->SetWidth( (int)atof( token ) ); ptr = StripLeadingTokenToBuffer( ptr, token ); s->SetHeight( (int)atof( token ) ); } else if (!strcmp(token,"trackball")) ball = new Trackball( s->GetWidth(), s->GetHeight() ); else if (!strcmp(token,"fovy")) ptr = StripLeadingNumber( ptr, &fovy ); else if (!strcmp(token,"near")) ptr = StripLeadingNumber( ptr, &_near ); else if (!strcmp(token,"far")) ptr = StripLeadingNumber( ptr, &_far ); else Error("Unknown command '%s' when loading Camera!", token); } }
Cylinder::Cylinder( FILE *f, Scene *s ) : Object( s->GetDefaultMaterial() ), center( Point::Origin() ), slices(50), stacks(25), displayList(0), radius(1.0f), axis( Vector::ZAxis() ), height(1.0f) { bool normalsDefined=false; // Search the scene file. char buf[ MAXLINELENGTH ], token[256], *ptr; while( fgets(buf, MAXLINELENGTH, f) != NULL ) { // Is this line a comment? ptr = StripLeadingWhiteSpace( buf ); if (ptr[0] == '#') continue; // Nope. So find out what the command is... ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); // Take different measures, depending on the command. if (!strcmp(token,"end")) break; if (TestCommonObjectProperties( token, ptr, s, f )) continue; else if (!strcmp(token,"center")) center = Point( ptr ); else if (!strcmp(token,"radius")) { ptr = StripLeadingTokenToBuffer( ptr, token ); radius = (float)atof( token ); } else if (!strcmp(token,"height")) { ptr = StripLeadingTokenToBuffer( ptr, token ); height = (float)atof( token ); } else if (!strcmp(token,"axis")) { axis = Vector( ptr ); axis.Normalize(); } else if (!strcmp(token, "stacks")) { ptr = StripLeadingTokenToBuffer( ptr, token ); stacks = (unsigned char)MIN(255,atoi( token )); } else if (!strcmp(token, "slices")) { ptr = StripLeadingTokenToBuffer( ptr, token ); slices = (unsigned char)MIN(255,atoi( token )); } else Error("Unknown command '%s' when loading Cylinder!", token); } }
void CHpiHandler::RegisterFile(char *hpi, char *name, int size) { MakeLower(name); if(files.find(name)==files.end()){ FileData fd; fd.hpiname=hpi; fd.size=size; files[name]=fd; } }
TLabel CModuleBuilder::declare( const CToken& nameToken ) { assert( isModuleExist() ); assert( !nameToken.word.empty() ); std::string name = nameToken.word; MakeLower( name ); const TLabel label = module->Functions.AddKey( name ); CPreparatoryFunctionPtr& function = module->Functions.GetData( label ); if( !static_cast<bool>( function ) ) { function.reset( new CPreparatoryFunction( nameToken ) ); } return label; }
int CHpiHandler::LoadFile(string name, void *buffer) { MakeLower(name); if(files.find(name)==files.end()) return 0; void* hpi=HPIOpen(files[name].hpiname.c_str()); char* file=HPIOpenFile(hpi, name.c_str()); HPIGet(buffer,file,0,files[name].size); HPICloseFile(file); HPIClose(hpi); return files[name].size; }
bool CModuleBuilder::GetNamedQualifier( const CToken& nameToken, CQualifier& qualifier ) { assert( isModuleExist() ); assert( nameToken.type == TT_Qualifier ); assert( !nameToken.word.empty() ); std::string qualifierName = nameToken.word; MakeLower( qualifierName ); CNamedQualifiers::const_iterator i = namedQualifiers.find( qualifierName ); if( i != namedQualifiers.end() ) { qualifier = i->second.qualifier; return true; } error( nameToken, "qualifier `" + nameToken.word + "` wasn't defined" ); return false; }
GLLambertianMaterial::GLLambertianMaterial( FILE *f, Scene *s ) : GLMaterial() { ambient = Color::Black(); diffuse = Color( 0.8f, 0.8f, 0.8f ); specular = Color::Black(); emission = Color::Black(); shininess = 0.0f; // Search the scene file. char buf[ MAXLINELENGTH ], token[256], *ptr; while( fgets(buf, MAXLINELENGTH, f) != NULL ) { // Is this line a comment? ptr = StripLeadingWhiteSpace( buf ); if (ptr[0] == '#') continue; // Nope. So find out what the command is... ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); // Take different measures, depending on the command. if (!strcmp(token,"end")) break; if (!strcmp(token,"rgb") || !strcmp(token,"color") || !strcmp(token,"albedo")) diffuse = Color( ptr ); else if (!strcmp(token,"spectral")) FatalError("Unable to handle keyword 'spectral' in GLLambertianMaterial!"); else if (!strcmp(token,"name")) { ptr = StripLeadingTokenToBuffer( ptr, token ); SetName( token ); } else if (!strcmp(token,"tex") || !strcmp(token,"texture") || !strcmp(token,"diffusetexture") || !strcmp(token,"dtex") || !strcmp(token,"clamp") || !strcmp(token,"mirror") || !strcmp(token,"repeat")) s->UnhandledKeyword( f, "lambertian material property", token ); else Error("Unknown command '%s' when loading GLMaterial!", token); } }
bool ChangeCase_Execute (COMMAND_ARGS, bool bUpper) { std::string converted = ""; ExpressionEvaluator eval (PASS_COMMAND_ARGS); if (eval.ExtractArgs() && eval.NumArgs() == 1) { const char* src = eval.Arg (0)->GetString(); if (src) { converted = src; if (bUpper) MakeUpper (converted); else MakeLower (converted); } } AssignToStringVar(PASS_COMMAND_ARGS, converted.c_str ()); return true; }
bool CModuleBuilder::SetNamedQualifier( const CToken& nameToken, CQualifier& qualifier ) { if( !attemptModule() ) { fatalError( nameToken, "Wrong named qualifier out of module" ); return false; } assert( nameToken.type == TT_Word ); std::string qualifierName = nameToken.word; MakeLower( qualifierName ); std::pair<CNamedQualifiers::iterator, bool> insertPair = namedQualifiers.insert( std::make_pair( qualifierName, CNamedQualifierInfo( nameToken ) ) ); if( insertPair.second ) { qualifier.Move( insertPair.first->second.qualifier ); return true; } error( nameToken, "qualifier `" + nameToken.word + "` already defined" ); return false; }
void MtcOpcAdapter::initialize(int aArgc, const char *aArgv[]) { static char name[] = "MtcOpcAdapter::initialize"; try{ GLogger << LDEBUG << "MTConnect Adapter Service Configure" << std::endl; _inifile = ChangeExtension(GetModulePath(), ".ini"); // ExeDirectory() + "\\adapter.ini"; if(!ATL::ATLPath::FileExists(_inifile.c_str())) throw std::exception(StdStringFormat("Config file missing %s\n", _inifile.c_str()).c_str()); _iniconfig.load(_inifile); MTConnectService::setName(_iniconfig.GetSymbolValue("Adapter.ServiceName", "MTCAdapter").c_str()); Adapter::mScanDelay = ConvertFromString<int>(_iniconfig.GetSymbolValue("Adapter.ScanDelay", "1000").str(), 1000); this->Adapter::mPort = ConvertFromString<int>(_iniconfig.GetSymbolValue("Adapter.Port", "7878").str(), 7878); std::string sLogLevel = _iniconfig.GetSymbolValue("logger_config.logging_level", "debug"); std::string nLogName = _iniconfig.GetSymbolValue("logger_config.output", "OuputDebugString"); //fatal, error, warn, info, debug GLogger.DebugLevel()= LDEBUG; if(MakeLower(sLogLevel) == "none") GLogger.DebugLevel()= FATAL; else if(MakeLower(sLogLevel) == "error") GLogger.DebugLevel()= ERROR; else if(MakeLower(sLogLevel) == "warn") GLogger.DebugLevel()= WARNING; else if(MakeLower(sLogLevel) == "info") GLogger.DebugLevel()= INFO; else if(MakeLower(sLogLevel) == "fatal") GLogger.DebugLevel()= FATAL; GLogger.Timestamping()= true; if(nLogName=="OuputDebugString") { GLogger.DebugString() = true; } else { GLogger.DebugString() = false; GLogger.Open(::ExeDirectory() + nLogName); } MTConnectService::initialize(aArgc, aArgv); if (aArgc > 1) { mPort = atoi(aArgv[1]); } _bResetAtMidnight = ConvertFromString<bool>(_iniconfig.GetSymbolValue("OPCSERVER.ResetAtMidnight", "false").str(), false); _bOPCEnabled = ConvertFromString<bool>(_iniconfig.GetSymbolValue("OPCSERVER.OPCEnabled", "false").str(), false);; _servers = Tokenize(_iniconfig.GetSymbolValue("OPCSERVER.ServerMachineName", "").str(), ","); _devices = Tokenize(_iniconfig.GetSymbolValue("OPCSERVER.MTConnectDevice", "").str(), ","); _tags = Tokenize(_iniconfig.GetSymbolValue("OPCSERVER.OpcTags", "").str(), ","); if(_servers.size() != _devices.size() && _servers.size() != _tags.size()) throw std::exception("OPC Number of Server IPs does not match number of MTConnect devices or Section Tags" ); } catch(std::exception e) { GLogger << FATAL << "Adapter::initialize() failed: " << e.what() << std::endl; throw e; } catch(...) {} }
void __stdcall CWtlHtmlView::OnBeforeNavigate2 ( IDispatch* pDisp, VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers, VARIANT_BOOL* Cancel ) { std::string url ((LPCSTR) bstr_t(URL)); std::string data ((LPCSTR) bstr_t(PostData)); std::string hdrs ((LPCSTR) bstr_t(Headers)); // STEP if(url.find("localhost") != std::string::npos ) // { //std::vector<FcnLognotify> &listeners(listenerMap["Step"]); //for(int i=0; i< listeners.size(); i++) // listeners[i](url.c_str() ); _wndMain->cond.notify_all(); // have to run once from "STEP" } if(url.find("runhost") != std::string::npos ) // { std::string loop ; this->GetElementId("Loop",loop); _wndMain->jobs->Deadline() += (double) ConvertString<int>(loop, -1); //_wndMain->_nLoopCounter = _wndMain->jobs->Deadline() - _wndMain->jobs->TimeElapsed(); _wndMain->cond.notify_all(); // have to run once from "STEP" } if(url.find("deadlinehost") != std::string::npos ) // { std::string loop ; this->GetElementId("ContinueLoop",loop); _wndMain->jobs->Deadline() += (double) ConvertString<int>(loop, -1); _wndMain->cond.notify_all(); // have to run once from "STEP" } //Stop if(url.find("stophost") != std::string::npos ) // { _wndMain->_bStopped = true; _wndMain->cond.notify_all(); // in case, have to run once } //Pause if(url.find("pausehost") != std::string::npos ) // { _wndMain->_bPaused=true; } //Resume if(url.find("resumehost") != std::string::npos ) // { _wndMain->_bPaused=false; _wndMain->cond.notify_all(); // have to run once from "STEP" } if(url.find("snapshothost") != std::string::npos ) // { // _wndMain->_bSnapshot=true; Reporting::GenerateHtmlReport(_wndMain->jobs, ::ExeDirectory() + "Doc.html"); ::PostMessage(_wndMain->m_hWnd, DISPLAY_SNAPSHOT,0,0); ::Sleep(500); } if(url.find("unitshost") != std::string::npos ) // { _wndMain->_bMinutes=!_wndMain->_bMinutes; if(_wndMain->_bMinutes) _wndMain->_timeDivisor=60.0; else _wndMain->_timeDivisor=1.0; } if(url.find("KPIhost") != std::string::npos ) // { _wndMain->_bKPISnapshot=true; } if(url.find("ziphost") != std::string::npos ) // { _wndMain->_bZip=!_wndMain->_bZip; } if(url.find("finishhost") != std::string::npos ) // { _wndMain->_bFinish=!_wndMain->_bFinish; } for(int i=0; i< Factory.size() ; i++) { std::string name = Factory[i]->_statemachine->Name(); name = MakeLower(name); if(url.find(name) != std::string::npos ) { Reporting::GenerateResourceReport(i); ::PostMessage(_wndMain->m_hWnd, DISPLAY_RESOURCE,(WPARAM) i ,0); ::Sleep(500); } } // Return TRUE to cancel *Cancel = VARIANT_TRUE; }
static std::string GetFanucDeviceXml(std::string config) { std::string xml; config=MakeLower(config); xml=" <Device id=\"####d1\" uuid=\"####xxx\" name=\"NNNNNN\">\n" " <Description serialNumber=\"####\">FanucCNC</Description>\n" " <DataItems>\n" " <DataItem id=\"####avail1\" name=\"avail\" type=\"AVAILABILITY\" category=\"EVENT\"/>\n" " </DataItems>\n" " <Components>\n" " <Axes id=\"####a1\" name=\"base\">\n" " <Components>\n"; if(config.find("x")!= std::string::npos) xml+=" <Linear id=\"####x1\" name=\"X\">\n" " <DataItems>\n" " <DataItem type=\"POSITION\" subType=\"ACTUAL\" id=\"####xp1\" category=\"SAMPLE\" name=\"Xabs\" units=\"MILLIMETER\" nativeUnits=\"MILLIMETER\" coordinateSystem=\"MACHINE\"/>\n" " </DataItems>\n" " </Linear>\n"; if(config.find("y")!= std::string::npos) xml+=" <Linear id=\"####y1\" name=\"Y\">\n" " <DataItems>\n" " <DataItem type=\"POSITION\" subType=\"ACTUAL\" id=\"####yp1\" category=\"SAMPLE\" name=\"Yabs\" units=\"MILLIMETER\" nativeUnits=\"MILLIMETER\" coordinateSystem=\"MACHINE\"/>\n" " </DataItems>\n" " </Linear>\n"; if(config.find("z")!= std::string::npos) xml+=" <Linear id=\"####z1\" name=\"Z\">\n" " <DataItems>\n" " <DataItem type=\"POSITION\" subType=\"ACTUAL\" id=\"####zp1\" category=\"SAMPLE\" name=\"Zabs\" units=\"MILLIMETER\" nativeUnits=\"MILLIMETER\" coordinateSystem=\"MACHINE\"/>\n" " </DataItems>\n" " </Linear>\n"; if(config.find("a")!= std::string::npos) xml+=" <Rotary id=\"####d1\" name=\"A\">\n" " <DataItems>\n" " <DataItem type=\"POSITION\" id=\"####a\" category=\"SAMPLE\" name=\"Aabs\" subType=\"ACTUAL\" nativeUnits=\"DEGREE\" />\n" " </DataItems>\n" " </Rotary>\n"; if(config.find("b")!= std::string::npos) xml+=" <Rotary id=\"####d1\" name=\"B\">\n" " <DataItems>\n" " <DataItem type=\"POSITION\" id=\"####b\" category=\"SAMPLE\" name=\"Babs\" subType=\"ACTUAL\" nativeUnits=\"DEGREE\" />\n" " </DataItems>\n" " </Rotary>\n"; if(config.find("c")!= std::string::npos) xml+=" <Rotary id=\"####d1\" name=\"C\">\n" " <DataItems>\n" " <DataItem type=\"POSITION\" id=\"####c\" category=\"SAMPLE\" name=\"Cabs\" subType=\"ACTUAL\" nativeUnits=\"DEGREE\" />\n" " </DataItems>\n" " </Rotary>\n"; if(config.find("u")!= std::string::npos) xml+=" <Rotary id=\"####d1\" name=\"U\">\n" " <DataItems>\n" " <DataItem type=\"POSITION\" id=\"####u\" category=\"SAMPLE\" name=\"Uabs\" subType=\"ACTUAL\" nativeUnits=\"DEGREE\" />\n" " </DataItems>\n" " </Rotary>\n"; if(config.find("v")!= std::string::npos) xml+=" <Rotary id=\"####d1\" name=\"V\">\n" " <DataItems>\n" " <DataItem type=\"POSITION\" id=\"####v\" category=\"SAMPLE\" name=\"Vabs\" subType=\"ACTUAL\" nativeUnits=\"DEGREE\" />\n" " </DataItems>\n" " </Rotary>\n"; xml+=" <Rotary id=\"####d1\" name=\"D\">\n" " <DataItems>\n" " <DataItem type=\"SPINDLE_SPEED\" id=\"####cs1\" category=\"SAMPLE\" name=\"Srpm\" units=\"REVOLUTION/MINUTE\" nativeUnits=\"REVOLUTION/MINUTE\"/>\n" " <DataItem type=\"SPINDLE_SPEED\" id=\"####cso1\" category=\"SAMPLE\" name=\"Sovr\" subType=\"OVERRIDE\" units=\"PERCENT\" nativeUnits=\"PERCENT\"/>\n" " </DataItems>\n" " </Rotary>\n" " </Components>\n" " </Axes>\n" " <Controller id=\"####cont1\" name=\"controller\">\n" " <Components>\n" " <Path id=\"####path1\" name=\"path\">\n" " <DataItems>\n" " <DataItem type=\"PROGRAM\" id=\"####pgm1\" category=\"EVENT\" name=\"program\"/>\n" " <DataItem type=\"PART_COUNT\" id=\"####pc1\" category=\"EVENT\" name=\"PartCountAct\" />\n" " <DataItem type=\"PATH_FEEDRATE\" id=\"####pf1\" category=\"SAMPLE\" name=\"path_feedratefrt\" units=\"MILLIMETER/SECOND\" subType=\"ACTUAL\" coordinateSystem=\"WORK\"/>\n" " <DataItem type=\"PATH_FEEDRATE\" id=\"####pfo1\" category=\"SAMPLE\" name=\"path_feedrateovr\" units=\"PERCENT\" nativeUnits=\"PERCENT\" subType=\"OVERRIDE\" />\n" " <DataItem type=\"TOOL_ID\" id=\"####tid1\" category=\"EVENT\" name=\"Tool_number\"/>\n" " <DataItem type=\"CODE\" id=\"####hb1\" category=\"EVENT\" name=\"heartbeat\" />\n" " <DataItem type=\"EXECUTION\" id=\"####exec1\" category=\"EVENT\" name=\"execution\"/>\n" " <DataItem type=\"CONTROLLER_MODE\" id=\"####mode1\" category=\"EVENT\" name=\"controllermode\"/>\n" " </DataItems>\n" " </Path>\n" " </Components>\n" " </Controller>\n" " <Systems id=\"####systems1\" name=\"systems\">\n" " <Components>\n" " <Electric name=\"electric\" id=\"####elec1\">\n" " <DataItems>\n" " <DataItem type=\"POWER_STATE\" category=\"EVENT\" id=\"####pwr1\" name=\"power\" />\n" " </DataItems>\n" " </Electric>\n" " </Components>\n" " </Systems>\n" " </Components>\n" " </Device>\n"; return xml; }
Mesh::Mesh( char *linePtr, FILE *f, Scene *s ) : Object(0), hem(0), glm(0), displayListID(0), meshXForm( Matrix4x4::Identity() ), modelType(-1), elementVBO(0), interleavedVertDataVBO(0), renderMode( MESH_RENDER_AS_VBO_VERTEX_ARRAY ), lowResFile(0), glm_lowRes(0), hem_lowRes(0) { char buf[ MAXLINELENGTH ], token[256], *ptr; char file[ MAXLINELENGTH ] = { "No mesh file specified!" }; char lowResFileName[ MAXLINELENGTH ] = { "No mesh file specified!" }; // Find out what type of object we've got... ptr = StripLeadingTokenToBuffer( linePtr, token ); MakeLower( token ); if (!strcmp(token,"obj")) modelType = TYPE_OBJ_FILE; else if (!strcmp(token,"m") || !strcmp(token,"dotm")) modelType = TYPE_M_FILE; else if (!strcmp(token,"hem")) modelType = TYPE_HEM_FILE; else FatalError("Unknown mesh type '%s'!", token); // Now find out the other model parameters while( fgets(buf, MAXLINELENGTH, f) != NULL ) { // Is this line a comment? ptr = StripLeadingWhiteSpace( buf ); if (ptr[0] == '#') continue; // Nope. So find out what the command is... ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); // Take different measures, depending on the command. if (!strcmp(token,"end")) break; if (TestCommonObjectProperties( token, ptr, s, f )) continue; else if (!strcmp(token, "file")) // The filename of the mesh! { ptr = StripLeadingTokenToBuffer( ptr, token ); strncpy( file, token, MAXLINELENGTH ); } else if (!strcmp(token, "lowres")) // The filename of the low resolution mesh! { ptr = StripLeadingTokenToBuffer( ptr, token ); strncpy( lowResFileName, token, MAXLINELENGTH ); objectOptionFlags |= OBJECT_OPTION_USE_LOWRES; } else if (!strcmp(token, "displaylist")) renderMode = MESH_RENDER_AS_DISPLAY_LIST; else if (!strcmp(token, "vbo") || !strcmp(token,"vertexarray") || !strcmp(token, "vertexbuffer")) renderMode = MESH_RENDER_AS_VBO_VERTEX_ARRAY; else if (!strcmp(token, "trackball")) { ptr = StripLeadingTokenToBuffer( ptr, token ); int id = atoi(token); ball = new Trackball( s->GetWidth(), s->GetHeight() ); s->SetupObjectTrackball( id, ball ); } else if (!strcmp(token,"edges") || !strcmp(token,"enableedges") || !strcmp(token,"edgeenable")) flags |= OBJECT_FLAGS_ALLOWDRAWEDGESONLY; else if (!strcmp(token, "scale") || !strcmp(token,"center")) Warning("Mesh keyword '%s' not currently supported in OpenGL!", token); else if (!strcmp(token, "naivebvh") || !strcmp(token, "iterativebvh") || !strcmp(token, "arraybvh") || !strcmp(token, "skiptreebvh") || !strcmp(token, "kdtree")) Warning("Mesh acceleration structures (%s) not supported in OpenGL!", token); else if (!strcmp(token, "matrix")) // Transform the mesh? { Matrix4x4 mat( f, ptr ); meshXForm *= mat; } else Error("Unknown command '%s' when loading Mesh!", token); } // Now load the mesh file(s)... First get the filename filename = s->paths->GetModelPath( file ); if (!filename) FatalError("Unable to open mesh '%s'!", file); // If we'll load a high and low res model, get the name of the low res version if ( objectOptionFlags & OBJECT_OPTION_USE_LOWRES ) { lowResFile = s->paths->GetModelPath( lowResFileName ); if (!lowResFile) FatalError("Unable to open mesh '%s'!", file); } // Load model. This varies depending on the input type if (modelType == TYPE_HEM_FILE) { // Get the full res model hem = new HalfEdgeModel( filename, TYPE_HEM_FILE ); // Check if we need a low res version if ( objectOptionFlags & OBJECT_OPTION_USE_LOWRES ) { hem_lowRes = new HalfEdgeModel( lowResFile, TYPE_HEM_FILE ); if (!hem_lowRes) flags &= ~OBJECT_OPTION_USE_LOWRES; } } else if (modelType == TYPE_OBJ_FILE || modelType == TYPE_SMF_FILE) { // OBJ files do not allow edge-only drawing! flags &= ~OBJECT_FLAGS_ALLOWDRAWEDGESONLY; // Get the full res model glm = glmReadOBJ( filename ); glmUnitize( glm ); glmFacetNormals( glm ); glmVertexNormals( glm, 180 ); // Check if we need a low res version if ( objectOptionFlags & OBJECT_OPTION_USE_LOWRES ) { glm_lowRes = glmReadOBJ( lowResFile ); if (!glm_lowRes) objectOptionFlags &= ~OBJECT_OPTION_USE_LOWRES; else { glmUnitize( glm_lowRes ); glmFacetNormals( glm_lowRes ); glmVertexNormals( glm_lowRes, 180 ); } } } else FatalError("Curently unhandled mesh type: '.m'!"); }
BOOL CCheckFileNotificationsThread::RunningProcNew() { FnDebugMessage("FN: RunningProcNew started"); // Delete this when this functions ends CAutoPtr<CCheckFileNotificationsThread> thisPtr=this; // Creating handles if (!CreateHandlesNew()) return FALSE; DWORD dwOut; for (;;) { FnDebugMessage("FN goes to sleep"); InterlockedExchange(&m_lState,sWaiting); DWORD nRet=WaitForMultipleObjects(m_nHandles,m_pEventHandles,FALSE,INFINITE); InterlockedExchange(&m_lState,sProcessing); FnDebugMessage1("FN waked nRet=%X",nRet); if (nRet==WAIT_OBJECT_0) { // First event signalled, this event is for stopping // So do nothing here and exit FnDebugMessage("FN stopping event signalled, exiting"); break; } else if (nRet>WAIT_OBJECT_0 && nRet<WAIT_OBJECT_0+m_nHandles) { CLocateDlg* pLocateDlg=GetLocateDlg(); // Locate dialog is also closed, stopping this process if (pLocateDlg==NULL) break; DIRCHANGEDATA* pChangeData=m_pDirDatas[nRet-WAIT_OBJECT_0]; // Asking changes if (!pLocateDlg->IsLocating()) // if locating in process, do nothing { if (GetOverlappedResult(pChangeData->hDirHandle,&pChangeData->ol,&dwOut,FALSE)) { // If GetOverlappedResults took so long that Stop() has given during this time // stop right now if (m_lFlags&fwStopWhenPossible) break; while (pLocateDlg->m_pBackgroundUpdater!=NULL && !pLocateDlg->m_pBackgroundUpdater->m_lIsWaiting) Sleep(200); if (dwOut==0) UpdateItemsInRoot(pChangeData->pRoot,pLocateDlg); else { FILE_NOTIFY_INFORMATION* pStruct=(FILE_NOTIFY_INFORMATION*)pChangeData->pBuffer; while (1) { // Check stop state again if (m_lFlags&fwStopWhenPossible) break; DWORD dwLength=pStruct->FileNameLength/2; // Skip log files BOOL bSkipThisFile=FALSE; int nFilePart; for (nFilePart=dwLength-1;nFilePart>=0 && pStruct->FileName[nFilePart]!=L'\\';nFilePart--); nFilePart++; // Skipping ntuser.dat.log file if (dwLength-nFilePart==14) { if (_wcsnicmp(pStruct->FileName+nFilePart,L"ntuser.dat.log",14)==0) bSkipThisFile=TRUE; } #ifdef _DEBUG // Skipping HFCDebug.log if (dwLength-nFilePart==12) { if (_wcsnicmp(pStruct->FileName+nFilePart,L"HFCDebug.log",12)==0) bSkipThisFile=TRUE; } #endif if (!bSkipThisFile) { m_pFile=new WCHAR[pChangeData->dwRootLength+dwLength+2]; MemCopyW(m_pFile,pChangeData->pRoot,pChangeData->dwRootLength); MemCopyW(m_pFile+pChangeData->dwRootLength,pStruct->FileName,dwLength); dwLength+=pChangeData->dwRootLength; m_pFile[dwLength]='\0'; MakeLower(m_pFile); //DebugFormatMessage("BN: file=%S action=%d",m_pFile,pStruct->Action); switch(pStruct->Action) { case FILE_ACTION_ADDED: case FILE_ACTION_RENAMED_NEW_NAME: FileCreated(m_pFile,dwLength,pLocateDlg); break; case FILE_ACTION_REMOVED: case FILE_ACTION_RENAMED_OLD_NAME: FileDeleted(m_pFile,dwLength,pLocateDlg); break; case FILE_ACTION_MODIFIED: FileModified(m_pFile,dwLength,pLocateDlg); break; } delete[] m_pFile; m_pFile=NULL; } if (pStruct->NextEntryOffset==0) break; *((char**)&pStruct)+=pStruct->NextEntryOffset; } } } } // Check this again if (m_lFlags&fwStopWhenPossible) break; // Coing to listen changes FnDebugMessage("FN: going to listen changes"); BOOL bRet=m_pReadDirectoryChangesW(pChangeData->hDirHandle,pChangeData->pBuffer,CHANGE_BUFFER_LEN,TRUE, FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME| FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_SIZE|FILE_NOTIFY_CHANGE_LAST_WRITE| FILE_NOTIFY_CHANGE_CREATION|FILE_NOTIFY_CHANGE_SECURITY, &dwOut,&pChangeData->ol,NULL); FnDebugMessage("FN: m_pReadDirectoryChangesW returned"); if (!bRet) { // ReadDirectoryChangesW failed, reset event manually FnDebugMessage("FN: ReadDirectoryChangesW failed"); ResetEvent(pChangeData->ol.hEvent); } // Finally, before going to sleep, check that shell we continue if (m_lFlags&fwStopWhenPossible) break; } } InterlockedExchange(&m_lState,sStopping); FnDebugMessage("FN RunningProcNew ends"); return FALSE; }
GLSLShaderMaterial::GLSLShaderMaterial( FILE *f, Scene *s ) : Material(), shader(0), propertyFlags(SHADERMATL_NO_SPECIAL_BITS), vertFile(0), geomFile(0), fragFile(0), geomSettingsUpdated(false), geomInputType(GL_TRIANGLES), geomOutputType(GL_TRIANGLE_STRIP), geomMaxEmittedVerts(0), enables(GLSL_NO_SPECIAL_STATE), disables(GLSL_NO_SPECIAL_STATE) { bindTexNames.SetSize( 8 ); bindTexs.SetSize( 8 ); for (unsigned int i=0; i<bindTexNames.Size();i++) { bindTexNames[i] = 0; bindTexs[i] = 0; } // Search the scene file. char buf[ MAXLINELENGTH ], token[256], *ptr; while( fgets(buf, MAXLINELENGTH, f) != NULL ) { // Is this line a comment? ptr = StripLeadingWhiteSpace( buf ); if (ptr[0] == '#') continue; // Nope. So find out what the command is... ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); // Take different measures, depending on the command. if (!strcmp(token,"end")) break; if (!strcmp(token,"vertex") || !strcmp(token,"vert") || !strcmp(token,"v")) { ptr = StripLeadingTokenToBuffer( ptr, token ); vertFile = strdup( token ); } else if (!strcmp(token,"geometry") || !strcmp(token,"geom") || !strcmp(token,"g")) { ptr = StripLeadingTokenToBuffer( ptr, token ); geomFile = strdup( token ); } else if (!strcmp(token,"fragment") || !strcmp(token,"frag") || !strcmp(token,"f") || !strcmp(token,"pixel") || !strcmp(token,"p")) { ptr = StripLeadingTokenToBuffer( ptr, token ); fragFile = strdup( token ); } else if (!strcmp(token,"isreflective") || !strcmp(token,"reflective")) propertyFlags |= SHADERMATL_IS_REFLECTIVE; else if (!strcmp(token,"isrefractive") || !strcmp(token,"refractive")) propertyFlags |= SHADERMATL_IS_REFRACTIVE; else if (!strcmp(token,"isglossy") || !strcmp(token,"glossy")) propertyFlags |= SHADERMATL_IS_GLOSSY; else if (!strcmp(token,"allowsshadowmap") || !strcmp(token,"allowsshadows") || !strcmp(token,"shadows") || !strcmp(token,"shadow")) propertyFlags |= SHADERMATL_ALLOWS_SHADOWMAPUSE; else if (!strcmp(token,"allowscausticmap") || !strcmp(token,"allowscaustics") || !strcmp(token,"caustics") || !strcmp(token,"allowcaustics")) propertyFlags |= SHADERMATL_ALLOWS_CAUSTICMAPUSE; else if (!strcmp(token,"depth") || !strcmp(token,"depth_test") || !strcmp(token,"gl_depth_test") ) { ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); if (!strcmp(token,"enable") || !strcmp(token,"enabled")) enables |= GLSL_DEPTH_TEST; if (!strcmp(token,"disable")||!strcmp(token,"disabled")) disables |= GLSL_DEPTH_TEST; } else if (!strcmp(token,"blend") || !strcmp(token,"gl_blend") ) { ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); if (!strcmp(token,"enable") || !strcmp(token,"enabled")) enables |= GLSL_BLEND; if (!strcmp(token,"disable")||!strcmp(token,"disabled")) disables |= GLSL_BLEND; } else if (!strcmp(token,"stencil") || !strcmp(token,"gl_stencil_test") || !strcmp(token,"stencil_test") ) { ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); if (!strcmp(token,"enable") || !strcmp(token,"enabled")) enables |= GLSL_STENCIL_TEST; if (!strcmp(token,"disable")||!strcmp(token,"disabled")) disables |= GLSL_STENCIL_TEST; } else if (!strcmp(token,"alpha") || !strcmp(token,"gl_alpha_test") || !strcmp(token,"alpha_test") ) { ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); if (!strcmp(token,"enable") || !strcmp(token,"enabled")) enables |= GLSL_ALPHA_TEST; if (!strcmp(token,"disable")||!strcmp(token,"disabled")) disables |= GLSL_ALPHA_TEST; } else if (!strcmp(token,"culling") || !strcmp(token,"gl_cull_face") || !strcmp(token,"cull_face") ) { ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); if (!strcmp(token,"enable") || !strcmp(token,"enabled")) enables |= GLSL_CULL_FACE; if (!strcmp(token,"disable")||!strcmp(token,"disabled")) disables |= GLSL_CULL_FACE; } else if (!strcmp(token,"lighting") || !strcmp(token,"gl_lighting") ) { ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); if (!strcmp(token,"enable") || !strcmp(token,"enabled")) enables |= GLSL_LIGHTING; if (!strcmp(token,"disable")||!strcmp(token,"disabled")) disables |= GLSL_LIGHTING; } else if (!strcmp(token,"bind")) { char shaderVarName[256]; ptr = StripLeadingTokenToBuffer( ptr, shaderVarName ); ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); if (!strcmp(token,"const")) { // Bind a constant value bindConstNames.Add( strdup( shaderVarName ) ); unsigned int idx = bindConstColors.Add( new Color( ptr ) ); } else if (!strcmp(token, "tex")) { // Bind a texture ptr = StripLeadingTokenToBuffer( ptr, token ); int texID = atoi(token); if (texID < 0 || (unsigned int)texID > bindTexNames.Size()) FatalError("Invalid texture ID number loading shader: %s", token); ptr = StripLeadingTokenToBuffer( ptr, token ); bindTexNames[texID] = strdup( shaderVarName ); GLTexture *tptr = s->GetNamedTexture( token ); char *texFile=0; if (!tptr) { texFile = s->paths->GetTexturePath( token ); tptr = s->ExistingTextureFromFile( texFile ); } if (!tptr) s->AddTexture( tptr = new GLTexture( texFile, TEXTURE_REPEAT_S | TEXTURE_REPEAT_T | TEXTURE_MIN_LINEAR_MIP_LINEAR, true ) ); bindTexs[texID] = tptr; if (texFile) free( texFile ); } else if (!strcmp(token, "vary")) { // Bind a variable defined earlier in the scene file ptr = StripLeadingTokenToBuffer( ptr, token ); MakeLower( token ); float *fptr = s->GetSceneFloatVar( token ); if (fptr) { bindNames.Add( strdup(shaderVarName) ); bindPtrs.Add( fptr ); } else Error("Unable to find scene variable named '%s'!", token); } } else Error("Unknown command '%s' when loading GLSLShaderMaterial!", token); } shaderPath = s->paths->GetShaderPathList(); }
void CCheckFileNotificationsThread::UpdateItemsInRoot(LPCWSTR szRoot,CLocateDlg* pLocateDlg) { //BkgDebugFormatMessage("CCheckFileNotificationsThread::UpdateItemsInRoot BEGIN szRoot=%s",szRoot); if (pLocateDlg->m_pListCtrl==NULL) return; if (pLocateDlg->m_pListCtrl->GetItemCount()==0) return; // Updating changed items by checking all items if (szRoot[1]=='\0') { //BkgDebugMessage("CCheckFileNotificationsThread::UpdateItemsInRoot 1a"); WCHAR szDriveLower=szRoot[0]; WCHAR szDriveUpper=szRoot[0]; MakeUpper(&szDriveUpper,1); //BkgDebugMessage("CCheckFileNotificationsThread::UpdateItemsInRoot 2a"); int nItem=pLocateDlg->m_pListCtrl->GetNextItem(-1,LVNI_ALL); while (nItem!=-1) { if (m_lFlags&fwStopWhenPossible) break; CLocatedItem* pItem=(CLocatedItem*)pLocateDlg->m_pListCtrl->GetItemData(nItem); if (pItem!=NULL) { // Checking whether path is in changed volume LPCWSTR szPath=pItem->GetPath(); if ((szPath[0]==szDriveLower || szPath[0]==szDriveUpper) && szPath[1]==L':') { // Just disabling flags, let background thread do the rest if (pItem->RemoveFlagsForChanged()) pLocateDlg->m_pListCtrl->RedrawItems(nItem,nItem); } } nItem=pLocateDlg->m_pListCtrl->GetNextItem(nItem,LVNI_ALL); } } else { DWORD dwLength=(DWORD)istrlenw(szRoot); //BkgDebugMessage("CCheckFileNotificationsThread::UpdateItemsInRoot 1b"); int nItem=pLocateDlg->m_pListCtrl->GetNextItem(-1,LVNI_ALL); while (nItem!=-1) { if (m_lFlags&fwStopWhenPossible) break; CLocatedItem* pItem=(CLocatedItem*)pLocateDlg->m_pListCtrl->GetItemData(nItem); if (pItem!=NULL) { if (pItem->GetPathLen()>=dwLength) { LPWSTR szPath=alloccopy(pItem->GetPath(),pItem->GetPathLen()); MakeLower(szPath); if (wcsncmp(szPath,szRoot,dwLength)==0) { // Just disabling flags, let background thread do the rest if (pItem->RemoveFlagsForChanged()) pLocateDlg->m_pListCtrl->RedrawItems(nItem,nItem); } delete[] szPath; } } nItem=pLocateDlg->m_pListCtrl->GetNextItem(nItem,LVNI_ALL); } } //DebugMessage("CCheckFileNotificationsThread::UpdateItemsInRoot END"); }
BOOL CCheckFileNotificationsThread::CreateHandlesOld() { ASSERT(m_pEventHandles==NULL); ASSERT(m_lState==sInitializing); FnDebugMessage("FN: creating handles (old method)"); CLocateDlg* pLocateDlg=GetLocateDlg(); ASSERT(pLocateDlg!=NULL); // Loads roods from databases so that we know what to listen CArrayFAP<LPWSTR> aRoots; const CArray<PDATABASE>& aAllDatabases=GetLocateApp()->GetDatabases(); CArray<PDATABASE> aUsedDatabases; for (int i=0;i<aAllDatabases.GetSize();i++) { if (pLocateDlg->IsDatabaseUsedInSearch(aAllDatabases[i]->GetID())) aUsedDatabases.Add(aAllDatabases[i]); } if (aUsedDatabases.GetSize()==0) return FALSE; CDatabaseInfo::GetRootsFromDatabases(aRoots,aUsedDatabases); if (aRoots.GetSize()==0) return FALSE; // Create arrays for event handles and data structures // // The first handle in m_pEventHandles is stop event, the rest are change notification // objects returned by FindFirstChangeNotification function. // The first pointer in m_pRoots is NULL, the rest are pointers // to root directory. The lists are terminated with NULL // Allocating arraysn, note that the size of the list is not // necessary aRoots.GetSize()+2 if FindFirstChangeNotification returns error m_pEventHandles=new HANDLE[aRoots.GetSize()+1]; ASSERT(m_pEventHandles!=NULL); m_pRoots=new LPWSTR[aRoots.GetSize()+1]; ASSERT(m_pRoots!=NULL); // First handle in event handles array is stop handle and // first pointer to root directory is NULL, // so that each element in m_pEventHandles (with index >0) // corresponds to element in m_pRoots array with the same index m_pEventHandles[0]=m_hStopEvent; m_pRoots[0]=NULL; // Creating handles for directories in aRoots array using FindFirstChangeNotification m_nHandles=1; for (int i=0;i<aRoots.GetSize();i++) { if (m_lFlags&fwStopWhenPossible) { // Notify to Stop() that we are going to stop what // we are doing SetEvent(m_hStopEvent); InterlockedExchange(&m_lState,sStopping); break; } CStringW sRoot=aRoots.GetAt(i); // If root of the type "X:", change it to "X:\" if (sRoot[1]==':' && sRoot[2]=='\0') sRoot << L'\\'; #ifdef _DEBUG_LOGGING // If logging is on, do not use change notifications for root containing log file LPCSTR pLogFile=GetDebugLoggingFile(); if (pLogFile!=NULL) { // No debug logging for drive containing hfcdebug.log char* szPath=alloccopyWtoA(sRoot); MakeLower(szPath); BOOL bSame=strncmp(szPath,pLogFile,sRoot.GetLength())==0; delete[] szPath; if (bSame) continue; } #endif // Create find change notification objects if (IsUnicodeSystem()) m_pEventHandles[m_nHandles]=FindFirstChangeNotificationW(sRoot,TRUE, FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME|FILE_NOTIFY_CHANGE_SIZE|FILE_NOTIFY_CHANGE_LAST_WRITE); else m_pEventHandles[m_nHandles]=FindFirstChangeNotification(W2A(sRoot),TRUE, FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME|FILE_NOTIFY_CHANGE_SIZE|FILE_NOTIFY_CHANGE_LAST_WRITE); if (m_pEventHandles[m_nHandles]==INVALID_HANDLE_VALUE) { // FindFirstChangeNotification returned error, skipping this directory continue; } DebugOpenEvent(m_pEventHandles[m_nHandles]); sRoot.MakeLower(); sRoot.FreeExtra(); m_pRoots[m_nHandles]=sRoot.GiveBuffer(); m_nHandles++; } FnDebugMessage("FN handles created"); return TRUE; }