1 /* 2 * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3 3 * http://www.gnu.org/licenses/lgpl-3.0.html 4 */ 5 6 #ifndef PROJECTLOADER_H 7 #define PROJECTLOADER_H 8 9 #include <wx/hashmap.h> 10 #include "ibaseloader.h" 11 12 #define PROJECT_FILE_VERSION_MAJOR 1 13 #define PROJECT_FILE_VERSION_MINOR 6 14 15 class cbProject; 16 class ProjectBuildTarget; 17 class ProjectFile; 18 19 WX_DECLARE_STRING_HASH_MAP(wxString, CompilerSubstitutes); 20 21 /** Code::Blocks project file loader. */ 22 class DLLIMPORT ProjectLoader : public IBaseLoader 23 { 24 public: 25 /** Constructor. 26 * @param project The project to handle (load/save). */ 27 ProjectLoader(cbProject* project); 28 /// Destructor. 29 ~ProjectLoader() override; 30 31 /** Open a file. 32 * @param filename The file to open. 33 * @return True on success, false on failure. */ 34 bool Open(const wxString& filename) override; 35 36 /** Save a file. 37 * @param filename The file to save. 38 * @return True on success, false on failure. */ 39 bool Save(const wxString& filename) override; 40 41 /** Open a file. 42 * This version of Open, will return a copy of the \<Extensions\> element (if found). 43 * @param filename The file to open. 44 * @param ppExtensions A pointer to a pointer of type TiXmlElement. This is where 45 * the copy of the \<Extensions\> element will be placed. 46 * @return True on success, false on failure. */ 47 bool Open(const wxString& filename, TiXmlElement** ppExtensions); 48 49 /** Save a file. 50 * This version of Save, can override the \<Extensions\> element. 51 * @param filename The file to save. 52 * @param pExtensions A pointer of type TiXmlElement. This will be added as 53 * the \<Extensions\> element. 54 * @return True on success, false on failure. */ 55 bool Save(const wxString& filename, TiXmlElement* pExtensions); 56 57 /** Export a target as a new project. 58 * In other words, save a copy of the project containing only the specified target. 59 * @param filename The new project filename. 60 * @param pExtensions A pointer of type TiXmlElement. This will be added as 61 * the \<Extensions\> element. 62 * @param onlyTarget The target name. If empty, it's like saving the project under a different name 63 * (i.e. all targets are exported to the new project). */ 64 bool ExportTargetAsProject(const wxString& filename, const wxString& onlyTarget, TiXmlElement* pExtensions); 65 66 /** @return True if the file was upgraded after load, false if not. */ FileUpgraded()67 bool FileUpgraded(){ return m_Upgraded; } 68 69 /** @return True if the file was modified while loading, false if not. This is usually true if FileUpgraded() returned true. */ FileModified()70 bool FileModified(){ return m_OpenDirty; } 71 protected: 72 void DoProjectOptions(TiXmlElement* parentNode); 73 void DoCompilerOptions(TiXmlElement* parentNode, ProjectBuildTarget* target = nullptr); 74 void DoResourceCompilerOptions(TiXmlElement* parentNode, ProjectBuildTarget* target = nullptr); 75 void DoLinkerOptions(TiXmlElement* parentNode, ProjectBuildTarget* target = nullptr); 76 void DoIncludesOptions(TiXmlElement* parentNode, ProjectBuildTarget* target = nullptr); 77 void DoLibsOptions(TiXmlElement* parentNode, ProjectBuildTarget* target = nullptr); 78 void DoExtraCommands(TiXmlElement* parentNode, ProjectBuildTarget* target = nullptr); 79 void DoMakeCommands(TiXmlElement* parentNode, CompileTargetBase* target); 80 void DoVirtualTargets(TiXmlElement* parentNode); 81 82 void DoBuild(TiXmlElement* parentNode); 83 void DoBuildTarget(TiXmlElement* parentNode); 84 void DoBuildTargetOptions(TiXmlElement* parentNode, ProjectBuildTarget* target); 85 86 void DoEnvironment(TiXmlElement* parentNode, CompileOptionsBase* base); 87 88 void DoUnits(const TiXmlElement* parentNode); 89 void DoUnitOptions(const TiXmlElement* parentNode, ProjectFile* file); 90 private: 91 void ConvertVersion_Pre_1_1(); 92 void ConvertLibraries(CompileTargetBase* object); 93 94 // accepts a questionable compiler index and returns a valid compiler index 95 // (popping up a selection dialog if needed) 96 wxString GetValidCompilerID(const wxString& proposal, const wxString& scope); 97 ProjectLoader()98 ProjectLoader(){} // no default ctor 99 100 cbProject* m_pProject; 101 bool m_Upgraded; 102 bool m_OpenDirty; // set this to true if the project is loaded but modified (like the case when setting another compiler, if invalid) 103 bool m_IsPre_1_2; 104 int m_1_4_to_1_5_deftarget; 105 bool m_IsPre_1_6; 106 CompilerSubstitutes m_CompilerSubstitutes; 107 }; 108 109 #endif // PROJECTLOADER_H 110 111