| 453 | |
| 454 | |
| 455 | void CServerList::LoadStaticServers() |
| 456 | { |
| 457 | if ( !CPath::FileExists(m_staticServersConfig) ) { |
| 458 | return; |
| 459 | } |
| 460 | |
| 461 | wxFileInputStream stream(m_staticServersConfig); |
| 462 | wxTextInputStream f(stream); |
| 463 | |
| 464 | while ( !stream.Eof() ) { |
| 465 | wxString line = f.ReadLine(); |
| 466 | |
| 467 | // Skip comments |
| 468 | if (line.IsEmpty() || line.GetChar(0) == '#' || line.GetChar(0) == '/') { |
| 469 | continue; |
| 470 | } |
| 471 | |
| 472 | wxStringTokenizer tokens( line, "," ); |
| 473 | |
| 474 | if ( tokens.CountTokens() != 3 ) { |
| 475 | continue; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | // format is host:port,priority,Name |
| 480 | wxString addy = tokens.GetNextToken().Strip( wxString::both ); |
| 481 | wxString prio = tokens.GetNextToken().Strip( wxString::both ); |
| 482 | wxString name = tokens.GetNextToken().Strip( wxString::both ); |
| 483 | |
| 484 | wxString host = addy.BeforeFirst( ':' ); |
| 485 | wxString port = addy.AfterFirst( ':' ); |
| 486 | |
| 487 | |
| 488 | int priority = StrToLong( prio ); |
| 489 | if (priority < SRV_PR_MIN || priority > SRV_PR_MAX) { |
| 490 | priority = SRV_PR_NORMAL; |
| 491 | } |
| 492 | |
| 493 | |
| 494 | // We need a valid name for the list |
| 495 | if ( name.IsEmpty() ) { |
| 496 | name = addy; |
| 497 | } |
| 498 | |
| 499 | |
| 500 | // create server object and add it to the list |
| 501 | CServer* server = new CServer( StrToLong( port ), host ); |
| 502 | |
| 503 | server->SetListName( name ); |
| 504 | server->SetIsStaticMember( true ); |
| 505 | server->SetPreference( priority ); |
| 506 | |
| 507 | |
| 508 | // Try to add the server to the list |
| 509 | if ( !theApp->AddServer( server ) ) { |
| 510 | delete server; |
| 511 | CServer* existing = GetServerByAddress( host, StrToULong( port ) ); |
| 512 | if ( existing) { |
nothing calls this directly
no test coverage detected