Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

SchemaCache.cpp

Go to the documentation of this file.
00001 //
00002 // SchemaCache.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "SchemaCache.h"
00026 #include "Schema.h"
00027 
00028 #ifdef _DEBUG
00029 #undef THIS_FILE
00030 static char THIS_FILE[]=__FILE__;
00031 #define new DEBUG_NEW
00032 #endif
00033 
00034 CSchemaCache SchemaCache;
00035 
00036 
00038 // CSchemaCache construction
00039 
00040 CSchemaCache::CSchemaCache()
00041 {
00042 }
00043 
00044 CSchemaCache::~CSchemaCache()
00045 {
00046         Clear();
00047 }
00048 
00050 // CSchemaCache load
00051 
00052 int CSchemaCache::Load()
00053 {
00054         WIN32_FIND_DATA pFind;
00055         CString strPath;
00056         HANDLE hSearch;
00057         int nCount;
00058 
00059         Clear();
00060 
00061         strPath.Format( _T("%s\\Schemas\\*.xsd"), (LPCTSTR)Settings.General.Path );
00062         hSearch = FindFirstFile( strPath, &pFind );
00063         if ( hSearch == INVALID_HANDLE_VALUE ) return 0;
00064         nCount = 0;
00065 
00066         do
00067         {
00068                 strPath.Format( _T("%s\\Schemas\\%s"), (LPCTSTR)Settings.General.Path, pFind.cFileName );
00069                 
00070                 CSchema* pSchema = new CSchema();
00071 
00072                 if ( pSchema->Load( strPath ) )
00073                 {
00074                         CString strURI( pSchema->m_sURI );
00075                         CharLower( strURI.GetBuffer() );
00076                         strURI.ReleaseBuffer();
00077                         m_pURIs.SetAt( strURI, pSchema );
00078                         
00079                         CString strName( pSchema->m_sSingular );
00080                         CharLower( strName.GetBuffer() );
00081                         strName.ReleaseBuffer();
00082                         m_pNames.SetAt( strName, pSchema );
00083                 }
00084                 else
00085                 {
00086                         delete pSchema;
00087                 }
00088         }
00089         while ( FindNextFile( hSearch, &pFind ) );
00090 
00091         FindClose( hSearch );
00092 
00093         return nCount;
00094 }
00095 
00097 // CSchemaCache clear
00098 
00099 void CSchemaCache::Clear()
00100 {
00101         for ( POSITION pos = GetIterator() ; pos ; )
00102         {
00103                 delete GetNext( pos );
00104         }
00105         
00106         m_pURIs.RemoveAll();
00107         m_pNames.RemoveAll();
00108 }

Generated on Thu Dec 15 10:39:47 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2