1 // Created on: 1997-11-05
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <CDM_Application.hxx>
19 #include <CDM_Document.hxx>
20 #include <FSD_BinaryFile.hxx>
21 #include <FSD_CmpFile.hxx>
22 #include <FSD_File.hxx>
24 #include <PCDM_StorageDriver.hxx>
26 #include <Resource_Manager.hxx>
27 #include <Standard_GUID.hxx>
28 #include <Standard_NoSuchObject.hxx>
29 #include <Standard_SStream.hxx>
30 #include <Storage_Schema.hxx>
31 #include <TCollection_AsciiString.hxx>
32 #include <TCollection_ExtendedString.hxx>
35 //=======================================================================
36 //function : FileDriverType
38 //=======================================================================
40 PCDM_TypeOfFileDriver PCDM::FileDriverType(const TCollection_AsciiString& aFileName, PCDM_BaseDriverPointer& aBaseDriver) {
41 if(FSD_CmpFile::IsGoodFileType(aFileName) == Storage_VSOk) {
42 aBaseDriver=new FSD_CmpFile;
43 return PCDM_TOFD_CmpFile;
45 else if(FSD_File::IsGoodFileType(aFileName) == Storage_VSOk) {
46 aBaseDriver=new FSD_File;
47 return PCDM_TOFD_File;
49 else if(FSD_BinaryFile::IsGoodFileType(aFileName) == Storage_VSOk) {
50 aBaseDriver=new FSD_BinaryFile;
51 return PCDM_TOFD_File;
55 return PCDM_TOFD_Unknown;
59 //=======================================================================
60 //function : FileDriverType
62 //=======================================================================
64 PCDM_TypeOfFileDriver PCDM::FileDriverType (Standard_IStream& theIStream, PCDM_BaseDriverPointer& theBaseDriver)
66 TCollection_AsciiString aReadMagicNumber;
68 // read magic number from the file
69 if (theIStream.good())
71 aReadMagicNumber = Storage_BaseDriver::ReadMagicNumber (theIStream);
74 if(aReadMagicNumber == FSD_CmpFile::MagicNumber())
76 theBaseDriver = new FSD_CmpFile;
77 return PCDM_TOFD_CmpFile;
79 else if (aReadMagicNumber == FSD_File::MagicNumber())
81 theBaseDriver = new FSD_File;
82 return PCDM_TOFD_File;
84 else if (aReadMagicNumber == FSD_BinaryFile::MagicNumber())
86 theBaseDriver = new FSD_BinaryFile;
87 return PCDM_TOFD_File;
89 else if (aReadMagicNumber.Search ("<?xml") != -1)
91 // skip xml declaration
93 while (theIStream.good() && !theIStream.eof() && aChar != '>')
95 theIStream.get(aChar);
98 return PCDM_TOFD_XmlFile;
101 theBaseDriver = NULL;
102 return PCDM_TOFD_Unknown;