26 #include <wx/bitmap.h> 28 #include <wx/txtstrm.h> 29 #include <wx/wfstream.h> 36 #define SEP wxFileName::GetPathSeparator() 49 if( !wxFileName::DirExists(
m_basePath.GetPath() ) )
52 m_title =
_(
"Could open the template path!" ) + wxS(
" " ) + aPath;
54 else if( !wxFileName::DirExists(
m_metaPath.GetPath() ) )
57 m_title =
_(
"Couldn't open the meta information directory for this template!" ) + wxS(
" " ) +
63 m_title =
_(
"Couldn't find the meta HTML information file for this template!" );
76 std::vector<wxFileName> files;
78 wxArrayString allfiles;
81 wxDir::GetAllFiles( f, &allfiles );
84 for(
size_t i=0; i < allfiles.size(); i++ )
89 if( !p.GetPath().StartsWith(
m_metaPath.GetPath() ) )
90 files.emplace_back(allfiles[i] );
122 std::vector< wxFileName >& aDestFiles )
124 std::vector< wxFileName > srcFiles =
GetFileList();
128 bool multipleProjectFilesFound =
false;
130 for( wxFileName& file : srcFiles )
134 if( !basename.IsEmpty() && basename != file.GetName() )
135 multipleProjectFilesFound =
true;
137 basename = file.GetName();
141 if( multipleProjectFilesFound )
144 for( wxFileName& srcFile : srcFiles )
147 wxFileName destFile = srcFile;
150 wxString
name = destFile.GetName();
151 name.Replace( basename, aNewProjectPath.GetName() );
152 destFile.SetName(
name );
155 wxString
path = destFile.GetPathWithSep();
156 path.Replace(
m_basePath.GetPathWithSep(), aNewProjectPath.GetPathWithSep() );
157 destFile.SetPath(
path );
159 aDestFiles.push_back( destFile );
162 return aDestFiles.size();
177 bool multipleProjectFilesFound =
false;
179 for( wxFileName& file : srcFiles )
183 if( !basename.IsEmpty() && basename != file.GetName() )
184 multipleProjectFilesFound =
true;
186 basename = file.GetName();
190 if( multipleProjectFilesFound )
193 for( wxFileName& srcFile : srcFiles )
196 wxFileName destFile = srcFile;
199 wxString currname = destFile.GetName();
205 if( destFile.GetName().EndsWith( wxT(
"-cache" ) ) || destFile.GetName().EndsWith( wxT(
"-rescue" ) ) )
207 currname.Replace( basename, aNewProjectPath.GetName() );
209 else if( destFile.GetExt() == wxT(
"dcm" ) || destFile.GetExt() == wxT(
"lib" ) )
216 currname.Replace( basename, aNewProjectPath.GetName() );
219 destFile.SetName( currname );
223 wxString destpath = destFile.GetPathWithSep();
224 destpath.Replace(
m_basePath.GetPathWithSep(), aNewProjectPath.GetPathWithSep() );
227 if( !wxFileName::DirExists( destpath ) )
229 if( !wxFileName::Mkdir( destpath, 0777, wxPATH_MKDIR_FULL ) )
233 if( !aErrorMsg->empty() )
234 *aErrorMsg += wxT(
"\n" );
238 msg.Printf(
_(
"Cannot create folder '%s'." ), destpath );
246 destFile.SetPath( destpath );
248 if( !wxCopyFile( srcFile.GetFullPath(), destFile.GetFullPath() ) )
252 if( !aErrorMsg->empty() )
253 *aErrorMsg += wxT(
"\n" );
257 msg.Printf(
_(
"Cannot copy file '%s'." ), destFile.GetFullPath() );
271 wxFFileInputStream input(
GetHtmlFile().GetFullPath() );
272 wxString separator( wxT(
"\x9" ) );
273 wxTextInputStream
text( input, separator, wxConvUTF8 );
282 while( input.IsOk() && !input.Eof() && !done )
284 wxString line =
text.ReadLine();
285 wxString upperline = line.Clone().Upper();
287 start = upperline.Find( wxT(
"<TITLE>" ) );
288 finish = upperline.Find( wxT(
"</TITLE>" ) );
289 int length = finish - start - 7;
292 if( start != wxNOT_FOUND )
294 if( finish != wxNOT_FOUND )
296 m_title = line( start + 7, length );
300 m_title = line.Mid( start + 7 );
307 if( finish != wxNOT_FOUND )
309 m_title += line.SubString( 0, finish );
315 m_title.Replace( wxT(
"\r" ), wxT(
" " ) );
316 m_title.Replace( wxT(
"\n" ), wxT(
" " ) );
wxFileName m_metaIconFile
std::vector< wxFileName > GetFileList()
Get a vector list of filenames for the template.
const std::string ProjectFileExtension
#define METADIR
A directory which contains information about the project template and does not get copied.
wxFileName GetHtmlFile()
Get the full Html filename for the project template.
wxFileName m_metaHtmlFile
#define METAFILE_INFO_HTML
A required html formatted file which contains information about the project template.
PROJECT_TEMPLATE(const wxString &aPath)
Create a new project instance from aPath.
#define METAFILE_ICON
An optional png icon, exactly 64px x 64px which is used in the template selector if present.
Definition of file extensions used in Kicad.
wxString * GetTitle()
Get the title of the project (extracted from the html title tag)
wxString GetPrjDirName()
Get the dir name of the project template (i.e.
const std::string LegacyProjectFileExtension
size_t GetDestinationFiles(const wxFileName &aNewProjectPath, std::vector< wxFileName > &aDestFiles)
Fetch the list of destination files to be copied when the new project is created.
const std::string DrawingSheetFileExtension
bool CreateProject(wxFileName &aNewProjectPath, wxString *aErrorMsg=nullptr)
Copies and renames all template files to create a new project.
~PROJECT_TEMPLATE()
Non-virtual destructor (so no derived classes)
wxBitmap * GetIcon()
Get the 64px^2 icon for the project template.