Cleanup.
This commit is contained in:
parent
062e7273b7
commit
114ea1f406
|
@ -32,46 +32,48 @@
|
|||
#include "project_template.h"
|
||||
|
||||
|
||||
#define SEP() wxFileName::GetPathSeparator()
|
||||
#define SEP wxFileName::GetPathSeparator()
|
||||
|
||||
|
||||
PROJECT_TEMPLATE::PROJECT_TEMPLATE( const wxString& aPath )
|
||||
{
|
||||
templateBasePath = wxFileName::DirName( aPath );
|
||||
templateMetaPath = wxFileName::DirName( aPath + SEP() + METADIR );
|
||||
templateMetaHtmlFile = wxFileName::FileName( aPath + SEP() + METADIR + SEP() +
|
||||
METAFILE_INFO_HTML );
|
||||
templateMetaIconFile = wxFileName::FileName( aPath + SEP() + METADIR + SEP() + METAFILE_ICON );
|
||||
m_basePath = wxFileName::DirName( aPath );
|
||||
m_metaPath = wxFileName::DirName( aPath + SEP + METADIR );
|
||||
m_metaHtmlFile = wxFileName::FileName( aPath + SEP + METADIR + SEP + METAFILE_INFO_HTML );
|
||||
m_metaIconFile = wxFileName::FileName( aPath + SEP + METADIR + SEP + METAFILE_ICON );
|
||||
|
||||
title = wxEmptyString;
|
||||
m_title = wxEmptyString;
|
||||
|
||||
// Test the project template requirements to make sure aPath is a valid template structure.
|
||||
if( !wxFileName::DirExists( templateBasePath.GetPath() ) )
|
||||
if( !wxFileName::DirExists( m_basePath.GetPath() ) )
|
||||
{
|
||||
// Error, the path doesn't exist!
|
||||
title = _( "Could open the template path! " ) + aPath;
|
||||
m_title = _( "Could open the template path! " ) + aPath;
|
||||
}
|
||||
else if( !wxFileName::DirExists( templateMetaPath.GetPath() ) )
|
||||
else if( !wxFileName::DirExists( m_metaPath.GetPath() ) )
|
||||
{
|
||||
// Error, the meta information directory doesn't exist!
|
||||
title = _( "Couldn't open the meta information directory for this template! " ) +
|
||||
templateMetaPath.GetPath();
|
||||
m_title = _( "Couldn't open the meta information directory for this template! " ) +
|
||||
m_metaPath.GetPath();
|
||||
}
|
||||
else if( !wxFileName::FileExists( templateMetaHtmlFile.GetFullPath() ) )
|
||||
else if( !wxFileName::FileExists( m_metaHtmlFile.GetFullPath() ) )
|
||||
{
|
||||
// Error, the meta information directory doesn't contain the informational html file!
|
||||
title = _( "Cound't find the meta HTML information file for this template!" );
|
||||
m_title = _( "Cound't find the meta HTML information file for this template!" );
|
||||
}
|
||||
|
||||
// Try to load an icon
|
||||
metaIcon = new wxBitmap( templateMetaIconFile.GetFullPath(), wxBITMAP_TYPE_PNG );
|
||||
if( !wxFileName::FileExists( m_metaIconFile.GetFullPath() ) )
|
||||
m_metaIcon = &wxNullBitmap;
|
||||
else
|
||||
m_metaIcon = new wxBitmap( m_metaIconFile.GetFullPath(), wxBITMAP_TYPE_PNG );
|
||||
}
|
||||
|
||||
|
||||
std::vector<wxFileName> PROJECT_TEMPLATE::GetFileList()
|
||||
{
|
||||
std::vector<wxFileName> files;
|
||||
wxString f = templateBasePath.GetPath();
|
||||
wxString f = m_basePath.GetPath();
|
||||
wxArrayString allfiles;
|
||||
wxFileName p;
|
||||
|
||||
|
@ -83,7 +85,7 @@ std::vector<wxFileName> PROJECT_TEMPLATE::GetFileList()
|
|||
p = allfiles[i];
|
||||
|
||||
// Files that are in the meta directory must not be included
|
||||
if( !p.GetPath().StartsWith( templateMetaPath.GetPath() ) )
|
||||
if( !p.GetPath().StartsWith( m_metaPath.GetPath() ) )
|
||||
files.push_back( allfiles[i] );
|
||||
}
|
||||
|
||||
|
@ -93,7 +95,7 @@ std::vector<wxFileName> PROJECT_TEMPLATE::GetFileList()
|
|||
|
||||
wxString PROJECT_TEMPLATE::GetPrjDirName()
|
||||
{
|
||||
return templateBasePath.GetDirs()[ templateBasePath.GetDirCount()-1 ];
|
||||
return m_basePath.GetDirs()[ m_basePath.GetDirCount() - 1 ];
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,13 +107,13 @@ PROJECT_TEMPLATE::~PROJECT_TEMPLATE()
|
|||
|
||||
wxFileName PROJECT_TEMPLATE::GetHtmlFile()
|
||||
{
|
||||
return templateMetaHtmlFile;
|
||||
return m_metaHtmlFile;
|
||||
}
|
||||
|
||||
|
||||
wxBitmap* PROJECT_TEMPLATE::GetIcon()
|
||||
{
|
||||
return metaIcon;
|
||||
return m_metaIcon;
|
||||
}
|
||||
|
||||
|
||||
|
@ -122,19 +124,24 @@ size_t PROJECT_TEMPLATE::GetDestinationFiles( const wxFileName& aNewProjectPath,
|
|||
|
||||
// Find the template file name base. this is the name of the .pro template file
|
||||
wxString basename;
|
||||
int projectCount = 0;
|
||||
|
||||
for( const auto& file : srcFiles )
|
||||
for( wxFileName& file : srcFiles )
|
||||
{
|
||||
if( file.GetExt() == wxT( "pro" ) )
|
||||
{
|
||||
basename = file.GetName();
|
||||
break;
|
||||
projectCount++;
|
||||
}
|
||||
}
|
||||
|
||||
for( const auto& file : srcFiles )
|
||||
if( projectCount != 1 )
|
||||
basename = GetPrjDirName();
|
||||
|
||||
for( wxFileName& srcFile : srcFiles )
|
||||
{
|
||||
wxFileName destFile = file;
|
||||
// Replace the template path
|
||||
wxFileName destFile = srcFile;
|
||||
|
||||
// Replace the template filename with the project filename for the new project creation
|
||||
wxString name = destFile.GetName();
|
||||
|
@ -143,7 +150,7 @@ size_t PROJECT_TEMPLATE::GetDestinationFiles( const wxFileName& aNewProjectPath,
|
|||
|
||||
// Replace the template path with the project path.
|
||||
wxString path = destFile.GetPathWithSep();
|
||||
path.Replace( templateBasePath.GetPathWithSep(), aNewProjectPath.GetPathWithSep() );
|
||||
path.Replace( m_basePath.GetPathWithSep(), aNewProjectPath.GetPathWithSep() );
|
||||
destFile.SetPath( path );
|
||||
|
||||
aDestFiles.push_back( destFile );
|
||||
|
@ -163,40 +170,45 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath, wxString* aEr
|
|||
|
||||
// Find the template file name base. this is the name of the .pro template file
|
||||
wxString basename;
|
||||
int projectCount = 0;
|
||||
|
||||
for( size_t i=0; i < srcFiles.size(); i++ )
|
||||
for( wxFileName& file : srcFiles )
|
||||
{
|
||||
if( srcFiles[i].GetExt() == wxT( "pro" ) )
|
||||
if( file.GetExt() == wxT( "pro" ) )
|
||||
{
|
||||
basename = srcFiles[i].GetName();
|
||||
break;
|
||||
basename = file.GetName();
|
||||
projectCount++;
|
||||
}
|
||||
}
|
||||
|
||||
for( size_t i=0; i < srcFiles.size(); i++ )
|
||||
if( projectCount != 1 )
|
||||
basename = GetPrjDirName();
|
||||
|
||||
for( wxFileName& srcFile : srcFiles )
|
||||
{
|
||||
// Replace the template path
|
||||
wxFileName destination = srcFiles[i];
|
||||
wxFileName destFile = srcFile;
|
||||
|
||||
// Replace the template filename with the project filename for the new project creation
|
||||
wxString currname = destination.GetName();
|
||||
wxString currname = destFile.GetName();
|
||||
|
||||
// Do not rename project specific symbol libraries. This will break the symbol library
|
||||
// table which will cause broken symbol library links in the schematic.
|
||||
if( !( destination.GetExt() == "dcm"
|
||||
|| ( destination.GetExt() == "lib" && !destination.GetName().EndsWith( "-cache" ) ) ) )
|
||||
if( !( destFile.GetExt() == "dcm"
|
||||
|| ( destFile.GetExt() == "lib" && !destFile.GetName().EndsWith( "-cache" ) ) ) )
|
||||
{
|
||||
currname.Replace( basename, aNewProjectPath.GetName() );
|
||||
}
|
||||
|
||||
destination.SetName( currname );
|
||||
destFile.SetName( currname );
|
||||
|
||||
// Replace the template path with the project path for the new project creation
|
||||
// but keep the sub directory name, if exists
|
||||
wxString destpath = destination.GetPathWithSep();
|
||||
destpath.Replace( templateBasePath.GetPathWithSep(), aNewProjectPath.GetPathWithSep() );
|
||||
wxString destpath = destFile.GetPathWithSep();
|
||||
destpath.Replace( m_basePath.GetPathWithSep(), aNewProjectPath.GetPathWithSep() );
|
||||
|
||||
// Check to see if the path already exists, if not attempt to create it here. Don't worry
|
||||
// about error checking, if the path isn't created the file copy will fail anyway
|
||||
|
||||
if( !wxFileName::DirExists( destpath ) )
|
||||
{
|
||||
if( !wxFileName::Mkdir( destpath, 0777, wxPATH_MKDIR_FULL ) )
|
||||
|
@ -216,12 +228,9 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath, wxString* aEr
|
|||
}
|
||||
}
|
||||
|
||||
destination.SetPath( destpath );
|
||||
destFile.SetPath( destpath );
|
||||
|
||||
wxString srcFile = srcFiles[i].GetFullPath();
|
||||
wxString dstFile = destination.GetFullPath();
|
||||
|
||||
if( !wxCopyFile( srcFile, dstFile ) )
|
||||
if( !wxCopyFile( srcFile.GetFullPath(), destFile.GetFullPath() ) )
|
||||
{
|
||||
if( aErrorMsg )
|
||||
{
|
||||
|
@ -230,11 +239,10 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath, wxString* aEr
|
|||
|
||||
wxString msg;
|
||||
|
||||
msg.Printf( _( "Cannot copy file \"%s\"." ), dstFile );
|
||||
msg.Printf( _( "Cannot copy file \"%s\"." ), destFile.GetFullPath() );
|
||||
*aErrorMsg += msg;
|
||||
}
|
||||
|
||||
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
@ -243,14 +251,14 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath, wxString* aEr
|
|||
}
|
||||
|
||||
|
||||
wxString* PROJECT_TEMPLATE::GetTitle(void)
|
||||
wxString* PROJECT_TEMPLATE::GetTitle()
|
||||
{
|
||||
wxFileInputStream input( GetHtmlFile().GetFullPath() );
|
||||
wxString separator( wxT( "\x9" ) );
|
||||
wxTextInputStream text( input, separator, wxConvUTF8 );
|
||||
|
||||
/* Open HTML file and get the text between the title tags */
|
||||
if( title == wxEmptyString )
|
||||
if( m_title == wxEmptyString )
|
||||
{
|
||||
int start = 0;
|
||||
int finish = 0;
|
||||
|
@ -270,11 +278,11 @@ wxString* PROJECT_TEMPLATE::GetTitle(void)
|
|||
{
|
||||
if( finish != wxNOT_FOUND )
|
||||
{
|
||||
title = line( start + 7, length );
|
||||
m_title = line( start + 7, length );
|
||||
}
|
||||
else
|
||||
{
|
||||
title = line.Mid( start + 7 );
|
||||
m_title = line.Mid( start + 7 );
|
||||
}
|
||||
|
||||
done = true;
|
||||
|
@ -283,16 +291,16 @@ wxString* PROJECT_TEMPLATE::GetTitle(void)
|
|||
{
|
||||
if( finish != wxNOT_FOUND )
|
||||
{
|
||||
title += line.SubString( 0, finish );
|
||||
m_title += line.SubString( 0, finish );
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove line endings
|
||||
title.Replace( wxT( "\r" ), wxT( " " ) );
|
||||
title.Replace( wxT( "\n" ), wxT( " " ) );
|
||||
m_title.Replace( wxT( "\r" ), wxT( " " ) );
|
||||
m_title.Replace( wxT( "\n" ), wxT( " " ) );
|
||||
}
|
||||
}
|
||||
|
||||
return &title;
|
||||
return &m_title;
|
||||
}
|
||||
|
|
|
@ -143,12 +143,12 @@ class wxFileName;
|
|||
class PROJECT_TEMPLATE
|
||||
{
|
||||
protected:
|
||||
wxFileName templateBasePath;
|
||||
wxFileName templateMetaPath;
|
||||
wxFileName templateMetaHtmlFile;
|
||||
wxFileName templateMetaIconFile;
|
||||
wxBitmap* metaIcon;
|
||||
wxString title;
|
||||
wxFileName m_basePath;
|
||||
wxFileName m_metaPath;
|
||||
wxFileName m_metaHtmlFile;
|
||||
wxFileName m_metaIconFile;
|
||||
wxBitmap* m_metaIcon;
|
||||
wxString m_title;
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in New Issue