You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

702 lines
22 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <kiface_base.h>
  24. #include <env_vars.h>
  25. #include <lib_id.h>
  26. #include <lib_table_lexer.h>
  27. #include <paths.h>
  28. #include <pgm_base.h>
  29. #include <search_stack.h>
  30. #include <settings/kicad_settings.h>
  31. #include <settings/settings_manager.h>
  32. #include <systemdirsappend.h>
  33. #include <wildcards_and_files_ext.h>
  34. #include <design_block_info.h>
  35. #include <design_block_lib_table.h>
  36. #include <design_block.h>
  37. #include <wx/dir.h>
  38. #include <wx/hash.h>
  39. #define OPT_SEP '|' ///< options separator character
  40. /// The global design block library table. This is not dynamically allocated because
  41. /// in a multiple project environment we must keep its address constant (since it is
  42. /// the fallback table for multiple projects).
  43. DESIGN_BLOCK_LIB_TABLE GDesignBlockTable;
  44. /// The global footprint info table. This is performance-intensive to build so we
  45. /// keep a hash-stamped global version. Any deviation from the request vs. stored
  46. /// hash will result in it being rebuilt.
  47. DESIGN_BLOCK_LIST_IMPL GDesignBlockList;
  48. using namespace LIB_TABLE_T;
  49. bool DESIGN_BLOCK_LIB_TABLE_ROW::operator==( const DESIGN_BLOCK_LIB_TABLE_ROW& aRow ) const
  50. {
  51. return LIB_TABLE_ROW::operator==( aRow ) && type == aRow.type;
  52. }
  53. void DESIGN_BLOCK_LIB_TABLE_ROW::SetType( const wxString& aType )
  54. {
  55. type = DESIGN_BLOCK_IO_MGR::EnumFromStr( aType );
  56. if( DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T( -1 ) == type )
  57. type = DESIGN_BLOCK_IO_MGR::KICAD_SEXP;
  58. plugin.reset();
  59. }
  60. DESIGN_BLOCK_LIB_TABLE::DESIGN_BLOCK_LIB_TABLE( DESIGN_BLOCK_LIB_TABLE* aFallBackTable ) :
  61. LIB_TABLE( aFallBackTable )
  62. {
  63. // not copying fall back, simply search aFallBackTable separately
  64. // if "nickName not found".
  65. }
  66. void DESIGN_BLOCK_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
  67. {
  68. T tok;
  69. wxString errMsg; // to collect error messages
  70. // This table may be nested within a larger s-expression, or not.
  71. // Allow for parser of that optional containing s-epression to have looked ahead.
  72. if( in->CurTok() != T_design_block_lib_table )
  73. {
  74. in->NeedLEFT();
  75. if( ( tok = in->NextTok() ) != T_design_block_lib_table )
  76. in->Expecting( T_design_block_lib_table );
  77. }
  78. while( ( tok = in->NextTok() ) != T_RIGHT )
  79. {
  80. std::unique_ptr<DESIGN_BLOCK_LIB_TABLE_ROW> row =
  81. std::make_unique<DESIGN_BLOCK_LIB_TABLE_ROW>();
  82. if( tok == T_EOF )
  83. in->Expecting( T_RIGHT );
  84. if( tok != T_LEFT )
  85. in->Expecting( T_LEFT );
  86. // in case there is a "row integrity" error, tell where later.
  87. int lineNum = in->CurLineNumber();
  88. tok = in->NextTok();
  89. // Optionally parse the current version number
  90. if( tok == T_version )
  91. {
  92. in->NeedNUMBER( "version" );
  93. m_version = std::stoi( in->CurText() );
  94. in->NeedRIGHT();
  95. continue;
  96. }
  97. if( tok != T_lib )
  98. in->Expecting( T_lib );
  99. // (name NICKNAME)
  100. in->NeedLEFT();
  101. if( ( tok = in->NextTok() ) != T_name )
  102. in->Expecting( T_name );
  103. in->NeedSYMBOLorNUMBER();
  104. row->SetNickName( in->FromUTF8() );
  105. in->NeedRIGHT();
  106. // After (name), remaining (lib) elements are order independent, and in
  107. // some cases optional.
  108. bool sawType = false;
  109. bool sawOpts = false;
  110. bool sawDesc = false;
  111. bool sawUri = false;
  112. bool sawDisabled = false;
  113. while( ( tok = in->NextTok() ) != T_RIGHT )
  114. {
  115. if( tok == T_EOF )
  116. in->Unexpected( T_EOF );
  117. if( tok != T_LEFT )
  118. in->Expecting( T_LEFT );
  119. tok = in->NeedSYMBOLorNUMBER();
  120. switch( tok )
  121. {
  122. case T_uri:
  123. if( sawUri )
  124. in->Duplicate( tok );
  125. sawUri = true;
  126. in->NeedSYMBOLorNUMBER();
  127. row->SetFullURI( in->FromUTF8() );
  128. break;
  129. case T_type:
  130. if( sawType )
  131. in->Duplicate( tok );
  132. sawType = true;
  133. in->NeedSYMBOLorNUMBER();
  134. row->SetType( in->FromUTF8() );
  135. break;
  136. case T_options:
  137. if( sawOpts )
  138. in->Duplicate( tok );
  139. sawOpts = true;
  140. in->NeedSYMBOLorNUMBER();
  141. row->SetOptions( in->FromUTF8() );
  142. break;
  143. case T_descr:
  144. if( sawDesc )
  145. in->Duplicate( tok );
  146. sawDesc = true;
  147. in->NeedSYMBOLorNUMBER();
  148. row->SetDescr( in->FromUTF8() );
  149. break;
  150. case T_disabled:
  151. if( sawDisabled )
  152. in->Duplicate( tok );
  153. sawDisabled = true;
  154. row->SetEnabled( false );
  155. break;
  156. case T_hidden:
  157. // Hiding design block libraries is not yet supported. Unclear what path can
  158. // set this attribute, but clear it on load.
  159. row->SetVisible();
  160. break;
  161. default:
  162. in->Unexpected( tok );
  163. }
  164. in->NeedRIGHT();
  165. }
  166. if( !sawType )
  167. in->Expecting( T_type );
  168. if( !sawUri )
  169. in->Expecting( T_uri );
  170. // All nickNames within this table fragment must be unique, so we do not use doReplace
  171. // in doInsertRow(). (However a fallBack table can have a conflicting nickName and ours
  172. // will supercede that one since in FindLib() we search this table before any fall back.)
  173. wxString nickname = row->GetNickName(); // store it to be able to used it
  174. // after row deletion if an error occurs
  175. bool doReplace = false;
  176. LIB_TABLE_ROW* tmp = row.release();
  177. if( !doInsertRow( tmp, doReplace ) )
  178. {
  179. delete tmp; // The table did not take ownership of the row.
  180. wxString msg = wxString::Format( _( "Duplicate library nickname '%s' found in "
  181. "design block library table file line %d." ),
  182. nickname, lineNum );
  183. if( !errMsg.IsEmpty() )
  184. errMsg << '\n';
  185. errMsg << msg;
  186. }
  187. }
  188. if( !errMsg.IsEmpty() )
  189. THROW_IO_ERROR( errMsg );
  190. }
  191. bool DESIGN_BLOCK_LIB_TABLE::operator==( const DESIGN_BLOCK_LIB_TABLE& aDesignBlockTable ) const
  192. {
  193. if( m_rows.size() == aDesignBlockTable.m_rows.size() )
  194. {
  195. for( unsigned i = 0; i < m_rows.size(); ++i )
  196. {
  197. if( (DESIGN_BLOCK_LIB_TABLE_ROW&) m_rows[i]
  198. != (DESIGN_BLOCK_LIB_TABLE_ROW&) aDesignBlockTable.m_rows[i] )
  199. {
  200. return false;
  201. }
  202. }
  203. return true;
  204. }
  205. return false;
  206. }
  207. void DESIGN_BLOCK_LIB_TABLE::Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const
  208. {
  209. aOutput->Print( aIndentLevel, "(design_block_lib_table\n" );
  210. aOutput->Print( aIndentLevel + 1, "(version %d)\n", m_version );
  211. for( const LIB_TABLE_ROW& row : m_rows)
  212. row.Format( aOutput, aIndentLevel + 1 );
  213. aOutput->Print( aIndentLevel, ")\n" );
  214. }
  215. long long DESIGN_BLOCK_LIB_TABLE::GenerateTimestamp( const wxString* aNickname )
  216. {
  217. long long hash = 0;
  218. if( aNickname )
  219. {
  220. const DESIGN_BLOCK_LIB_TABLE_ROW* row = FindRow( *aNickname, true );
  221. wxCHECK( row && row->plugin, hash );
  222. return row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) )
  223. + wxHashTable::MakeKey( *aNickname );
  224. }
  225. for( const wxString& nickname : GetLogicalLibs() )
  226. {
  227. const DESIGN_BLOCK_LIB_TABLE_ROW* row = nullptr;
  228. try
  229. {
  230. row = FindRow( nickname, true );
  231. }
  232. catch( ... )
  233. {
  234. // Do nothing if not found: just skip.
  235. }
  236. wxCHECK2( row && row->plugin, continue );
  237. hash += row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) )
  238. + wxHashTable::MakeKey( nickname );
  239. }
  240. return hash;
  241. }
  242. void DESIGN_BLOCK_LIB_TABLE::DesignBlockEnumerate( wxArrayString& aDesignBlockNames,
  243. const wxString& aNickname, bool aBestEfforts )
  244. {
  245. const DESIGN_BLOCK_LIB_TABLE_ROW* row = FindRow( aNickname, true );
  246. wxASSERT( row->plugin );
  247. row->plugin->DesignBlockEnumerate( aDesignBlockNames, row->GetFullURI( true ), aBestEfforts,
  248. row->GetProperties() );
  249. }
  250. const DESIGN_BLOCK_LIB_TABLE_ROW* DESIGN_BLOCK_LIB_TABLE::FindRow( const wxString& aNickname,
  251. bool aCheckIfEnabled )
  252. {
  253. DESIGN_BLOCK_LIB_TABLE_ROW* row =
  254. static_cast<DESIGN_BLOCK_LIB_TABLE_ROW*>( findRow( aNickname, aCheckIfEnabled ) );
  255. if( !row )
  256. {
  257. THROW_IO_ERROR( wxString::Format( _( "design-block-lib-table files contain no library "
  258. "named '%s'." ),
  259. aNickname ) );
  260. }
  261. if( !row->plugin )
  262. row->setPlugin( DESIGN_BLOCK_IO_MGR::FindPlugin( row->type ) );
  263. return row;
  264. }
  265. static void setLibNickname( DESIGN_BLOCK* aModule, const wxString& aNickname,
  266. const wxString& aDesignBlockName )
  267. {
  268. // The library cannot know its own name, because it might have been renamed or moved.
  269. // Therefore design blocks cannot know their own library nickname when residing in
  270. // a design block library.
  271. // Only at this API layer can we tell the design block about its actual library nickname.
  272. if( aModule )
  273. {
  274. // remove "const"-ness, I really do want to set nickname without
  275. // having to copy the LIB_ID and its two strings, twice each.
  276. LIB_ID& dbid = (LIB_ID&) aModule->GetLibId();
  277. // Catch any misbehaving plugin, which should be setting internal design block name
  278. // properly:
  279. wxASSERT( aDesignBlockName == dbid.GetLibItemName().wx_str() );
  280. // and clearing nickname
  281. wxASSERT( !dbid.GetLibNickname().size() );
  282. dbid.SetLibNickname( aNickname );
  283. }
  284. }
  285. const DESIGN_BLOCK*
  286. DESIGN_BLOCK_LIB_TABLE::GetEnumeratedDesignBlock( const wxString& aNickname,
  287. const wxString& aDesignBlockName )
  288. {
  289. const DESIGN_BLOCK_LIB_TABLE_ROW* row = FindRow( aNickname, true );
  290. wxASSERT( row->plugin );
  291. return row->plugin->GetEnumeratedDesignBlock( row->GetFullURI( true ), aDesignBlockName,
  292. row->GetProperties() );
  293. }
  294. bool DESIGN_BLOCK_LIB_TABLE::DesignBlockExists( const wxString& aNickname,
  295. const wxString& aDesignBlockName )
  296. {
  297. try
  298. {
  299. const DESIGN_BLOCK_LIB_TABLE_ROW* row = FindRow( aNickname, true );
  300. wxASSERT( row->plugin );
  301. return row->plugin->DesignBlockExists( row->GetFullURI( true ), aDesignBlockName,
  302. row->GetProperties() );
  303. }
  304. catch( ... )
  305. {
  306. return false;
  307. }
  308. }
  309. DESIGN_BLOCK* DESIGN_BLOCK_LIB_TABLE::DesignBlockLoad( const wxString& aNickname,
  310. const wxString& aDesignBlockName,
  311. bool aKeepUUID )
  312. {
  313. const DESIGN_BLOCK_LIB_TABLE_ROW* row = FindRow( aNickname, true );
  314. wxASSERT( row->plugin );
  315. DESIGN_BLOCK* ret = row->plugin->DesignBlockLoad( row->GetFullURI( true ), aDesignBlockName,
  316. aKeepUUID, row->GetProperties() );
  317. setLibNickname( ret, row->GetNickName(), aDesignBlockName );
  318. return ret;
  319. }
  320. DESIGN_BLOCK_LIB_TABLE::SAVE_T
  321. DESIGN_BLOCK_LIB_TABLE::DesignBlockSave( const wxString& aNickname,
  322. const DESIGN_BLOCK* aDesignBlock, bool aOverwrite )
  323. {
  324. const DESIGN_BLOCK_LIB_TABLE_ROW* row = FindRow( aNickname, true );
  325. wxASSERT( row->plugin );
  326. if( !aOverwrite )
  327. {
  328. // Try loading the design block to see if it already exists, caller wants overwrite
  329. // protection, which is atypical, not the default.
  330. wxString DesignBlockname = aDesignBlock->GetLibId().GetLibItemName();
  331. std::unique_ptr<DESIGN_BLOCK> design_block( row->plugin->DesignBlockLoad(
  332. row->GetFullURI( true ), DesignBlockname, row->GetProperties() ) );
  333. if( design_block.get() )
  334. return SAVE_SKIPPED;
  335. }
  336. row->plugin->DesignBlockSave( row->GetFullURI( true ), aDesignBlock, row->GetProperties() );
  337. return SAVE_OK;
  338. }
  339. void DESIGN_BLOCK_LIB_TABLE::DesignBlockDelete( const wxString& aNickname,
  340. const wxString& aDesignBlockName )
  341. {
  342. const DESIGN_BLOCK_LIB_TABLE_ROW* row = FindRow( aNickname, true );
  343. wxASSERT( row->plugin );
  344. return row->plugin->DesignBlockDelete( row->GetFullURI( true ), aDesignBlockName,
  345. row->GetProperties() );
  346. }
  347. bool DESIGN_BLOCK_LIB_TABLE::IsDesignBlockLibWritable( const wxString& aNickname )
  348. {
  349. const DESIGN_BLOCK_LIB_TABLE_ROW* row = FindRow( aNickname, true );
  350. wxASSERT( row->plugin );
  351. return row->plugin->IsLibraryWritable( row->GetFullURI( true ) );
  352. }
  353. void DESIGN_BLOCK_LIB_TABLE::DesignBlockLibDelete( const wxString& aNickname )
  354. {
  355. const DESIGN_BLOCK_LIB_TABLE_ROW* row = FindRow( aNickname, true );
  356. wxASSERT( row->plugin );
  357. row->plugin->DeleteLibrary( row->GetFullURI( true ), row->GetProperties() );
  358. }
  359. void DESIGN_BLOCK_LIB_TABLE::DesignBlockLibCreate( const wxString& aNickname )
  360. {
  361. const DESIGN_BLOCK_LIB_TABLE_ROW* row = FindRow( aNickname, true );
  362. wxASSERT( row->plugin );
  363. row->plugin->CreateLibrary( row->GetFullURI( true ), row->GetProperties() );
  364. }
  365. DESIGN_BLOCK*
  366. DESIGN_BLOCK_LIB_TABLE::DesignBlockLoadWithOptionalNickname( const LIB_ID& aDesignBlockId,
  367. bool aKeepUUID )
  368. {
  369. wxString nickname = aDesignBlockId.GetLibNickname();
  370. wxString DesignBlockname = aDesignBlockId.GetLibItemName();
  371. if( nickname.size() )
  372. {
  373. return DesignBlockLoad( nickname, DesignBlockname, aKeepUUID );
  374. }
  375. // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
  376. else
  377. {
  378. // Search each library going through libraries alphabetically.
  379. for( const wxString& library : GetLogicalLibs() )
  380. {
  381. // DesignBlockLoad() returns NULL on not found, does not throw exception
  382. // unless there's an IO_ERROR.
  383. DESIGN_BLOCK* ret = DesignBlockLoad( library, DesignBlockname, aKeepUUID );
  384. if( ret )
  385. return ret;
  386. }
  387. return nullptr;
  388. }
  389. }
  390. const wxString DESIGN_BLOCK_LIB_TABLE::GlobalPathEnvVariableName()
  391. {
  392. return ENV_VAR::GetVersionedEnvVarName( wxS( "DESIGN_BLOCK_DIR" ) );
  393. }
  394. class PCM_DESIGN_BLOCK_LIB_TRAVERSER final : public wxDirTraverser
  395. {
  396. public:
  397. explicit PCM_DESIGN_BLOCK_LIB_TRAVERSER( const wxString& aPath, DESIGN_BLOCK_LIB_TABLE& aTable,
  398. const wxString& aPrefix ) :
  399. m_lib_table( aTable ),
  400. m_path_prefix( aPath ),
  401. m_lib_prefix( aPrefix )
  402. {
  403. wxFileName f( aPath, wxS( "" ) );
  404. m_prefix_dir_count = f.GetDirCount();
  405. }
  406. wxDirTraverseResult OnFile( const wxString& aFilePath ) override { return wxDIR_CONTINUE; }
  407. wxDirTraverseResult OnDir( const wxString& dirPath ) override
  408. {
  409. wxFileName dir = wxFileName::DirName( dirPath );
  410. // consider a directory to be a lib if it's name ends with the design block lib dir
  411. // extension it is under $KICADn_3RD_PARTY/design_blocks/<pkgid>/ i.e. has nested
  412. // level of at least +3.
  413. if( dirPath.EndsWith( wxString::Format( wxS( ".%s" ),
  414. FILEEXT::KiCadDesignBlockLibPathExtension ) )
  415. && dir.GetDirCount() >= m_prefix_dir_count + 3 )
  416. {
  417. wxString versionedPath;
  418. versionedPath.Printf( wxS( "${%s}" ),
  419. ENV_VAR::GetVersionedEnvVarName( wxS( "3RD_PARTY" ) ) );
  420. wxArrayString parts = dir.GetDirs();
  421. parts.RemoveAt( 0, m_prefix_dir_count );
  422. parts.Insert( versionedPath, 0 );
  423. wxString libPath = wxJoin( parts, '/' );
  424. if( !m_lib_table.HasLibraryWithPath( libPath ) )
  425. {
  426. wxString name = parts.Last().substr( 0, parts.Last().length() - 7 );
  427. wxString nickname;
  428. nickname.Printf( wxS( "%s%s" ),
  429. m_lib_prefix,
  430. name );
  431. if( m_lib_table.HasLibrary( nickname ) )
  432. {
  433. int increment = 1;
  434. do
  435. {
  436. nickname.Printf( wxS( "%s%s_%d" ),
  437. m_lib_prefix,
  438. name,
  439. increment++ );
  440. } while( m_lib_table.HasLibrary( nickname ) );
  441. }
  442. m_lib_table.InsertRow( new DESIGN_BLOCK_LIB_TABLE_ROW(
  443. nickname, libPath, wxT( "KiCad" ), wxEmptyString,
  444. _( "Added by Plugin and Content Manager" ) ) );
  445. }
  446. }
  447. return wxDIR_CONTINUE;
  448. }
  449. private:
  450. DESIGN_BLOCK_LIB_TABLE& m_lib_table;
  451. wxString m_path_prefix;
  452. wxString m_lib_prefix;
  453. size_t m_prefix_dir_count;
  454. };
  455. bool DESIGN_BLOCK_LIB_TABLE::LoadGlobalTable( DESIGN_BLOCK_LIB_TABLE& aTable )
  456. {
  457. bool tableExists = true;
  458. wxFileName fn = GetGlobalTableFileName();
  459. if( !fn.FileExists() )
  460. {
  461. tableExists = false;
  462. if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
  463. {
  464. THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
  465. fn.GetPath() ) );
  466. }
  467. // Attempt to copy the default global file table from the KiCad
  468. // template folder to the user's home configuration path.
  469. SEARCH_STACK ss;
  470. SystemDirsAppend( &ss );
  471. const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables();
  472. std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( envVars,
  473. wxT( "TEMPLATE_DIR" ) );
  474. if( v && !v->IsEmpty() )
  475. ss.AddPaths( *v, 0 );
  476. wxString fileName = ss.FindValidPath( FILEEXT::DesignBlockLibraryTableFileName );
  477. // The fallback is to create an empty global design block table for the user to populate.
  478. if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
  479. {
  480. DESIGN_BLOCK_LIB_TABLE emptyTable;
  481. emptyTable.Save( fn.GetFullPath() );
  482. }
  483. }
  484. aTable.clear();
  485. aTable.Load( fn.GetFullPath() );
  486. SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
  487. KICAD_SETTINGS* settings = mgr.GetAppSettings<KICAD_SETTINGS>( "kicad" );
  488. const ENV_VAR_MAP& env = Pgm().GetLocalEnvVariables();
  489. wxString packagesPath;
  490. if( std::optional<wxString> v = ENV_VAR::GetVersionedEnvVarValue( env, wxT( "3RD_PARTY" ) ) )
  491. packagesPath = *v;
  492. if( settings->m_PcmLibAutoAdd )
  493. {
  494. // Scan for libraries in PCM packages directory
  495. wxFileName d( packagesPath, wxS( "" ) );
  496. d.AppendDir( wxS( "design_blocks" ) );
  497. if( d.DirExists() )
  498. {
  499. PCM_DESIGN_BLOCK_LIB_TRAVERSER traverser( packagesPath, aTable,
  500. settings->m_PcmLibPrefix );
  501. wxDir dir( d.GetPath() );
  502. dir.Traverse( traverser );
  503. }
  504. }
  505. if( settings->m_PcmLibAutoRemove )
  506. {
  507. // Remove PCM libraries that no longer exist
  508. std::vector<wxString> to_remove;
  509. for( size_t i = 0; i < aTable.GetCount(); i++ )
  510. {
  511. LIB_TABLE_ROW& row = aTable.At( i );
  512. wxString path = row.GetFullURI( true );
  513. if( path.StartsWith( packagesPath ) && !wxDir::Exists( path ) )
  514. to_remove.push_back( row.GetNickName() );
  515. }
  516. for( const wxString& nickName : to_remove )
  517. aTable.RemoveRow( aTable.FindRow( nickName ) );
  518. }
  519. return tableExists;
  520. }
  521. DESIGN_BLOCK_LIB_TABLE& DESIGN_BLOCK_LIB_TABLE::GetGlobalLibTable()
  522. {
  523. return GDesignBlockTable;
  524. }
  525. DESIGN_BLOCK_LIST_IMPL& DESIGN_BLOCK_LIB_TABLE::GetGlobalList()
  526. {
  527. return GDesignBlockList;
  528. }
  529. wxString DESIGN_BLOCK_LIB_TABLE::GetGlobalTableFileName()
  530. {
  531. wxFileName fn;
  532. fn.SetPath( PATHS::GetUserSettingsPath() );
  533. fn.SetName( FILEEXT::DesignBlockLibraryTableFileName );
  534. return fn.GetFullPath();
  535. }