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, Handle(Storage_BaseDriver)& aBaseDriver)
42 if(FSD_CmpFile::IsGoodFileType(aFileName) == Storage_VSOk) {
43 aBaseDriver=new FSD_CmpFile;
44 return PCDM_TOFD_CmpFile;
46 else if(FSD_File::IsGoodFileType(aFileName) == Storage_VSOk) {
47 aBaseDriver=new FSD_File;
48 return PCDM_TOFD_File;
50 else if(FSD_BinaryFile::IsGoodFileType(aFileName) == Storage_VSOk) {
51 aBaseDriver=new FSD_BinaryFile;
52 return PCDM_TOFD_File;
56 return PCDM_TOFD_Unknown;
60 //=======================================================================
61 //function : FileDriverType
63 //=======================================================================
65 PCDM_TypeOfFileDriver PCDM::FileDriverType (Standard_IStream& theIStream, Handle(Storage_BaseDriver)& theBaseDriver)
67 TCollection_AsciiString aReadMagicNumber;
69 // read magic number from the file
70 if (theIStream.good())
72 aReadMagicNumber = Storage_BaseDriver::ReadMagicNumber (theIStream);
75 if(aReadMagicNumber == FSD_CmpFile::MagicNumber())
77 theBaseDriver = new FSD_CmpFile;
78 return PCDM_TOFD_CmpFile;
80 else if (aReadMagicNumber == FSD_File::MagicNumber())
82 theBaseDriver = new FSD_File;
83 return PCDM_TOFD_File;
85 else if (aReadMagicNumber == FSD_BinaryFile::MagicNumber())
87 theBaseDriver = new FSD_BinaryFile;
88 return PCDM_TOFD_File;
90 else if (aReadMagicNumber.Search ("<?xml") != -1)
92 // skip xml declaration
94 while (theIStream.good() && !theIStream.eof() && aChar != '>')
96 theIStream.get(aChar);
99 return PCDM_TOFD_XmlFile;
102 theBaseDriver = NULL;
103 return PCDM_TOFD_Unknown;