|
using System;
namespace XDesigner.Development.Dom
{
/// <summary>
/// Delphi�����ļ�����
/// </summary>
public class DelphiProjectDocument : ProjectElement
{
/// <summary>
/// ��ʼ������
/// </summary>
public DelphiProjectDocument()
{
this.Style = ProjectStyle.Delphi ;
}
/// <summary>
/// ����ļ���չ��
/// </summary>
/// <param name="strFileName">�ļ���</param>
/// <returns>�ļ���չ��</returns>
public override bool CheckFileName(string strFileName)
{
return FileHelper.GetExtension( strFileName ) == "BDSPROJ";
}
/// <summary>
/// ������Ŀ�ļ�
/// </summary>
/// <param name="strFileName"></param>
public override void LoadProjectFile(string strFileName)
{
myFiles.Clear();
FileElement PrjFile = new FileElement();
PrjFile.FileName = System.IO.Path.GetFileName( strFileName );
PrjFile.FullFileName = strFileName ;
myFiles.Add( PrjFile );
this.strProjectFileName = strFileName ;
this.strRootPath = System.IO.Path.GetDirectoryName( strFileName );
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load( strFileName );
foreach( System.Xml.XmlElement element in doc.SelectNodes("BorlandProject/Delphi.Personality/Source/Source"))
{
string name = element.InnerText ;
name = System.IO.Path.Combine( strRootPath , name );
if( System.IO.File.Exists( name ))
{
this.LoadDelphiPackage( name );
}
}//foreach
}
public void LoadDelphiPackage( string strFileName )
{
System.IO.StreamReader myReader = new System.IO.StreamReader( strFileName , System.Text.Encoding.GetEncoding( 936 ));
string strLine = myReader.ReadLine();
bool ReadingContains = false;
while( strLine != null )
{
int index = 0 ;
strLine = strLine.Trim();
if( strLine.Length == 0 )
{
strLine = myReader.ReadLine();
continue ;
}
if( strLine == "contains" )
{
ReadingContains = true ;
}
else if( strLine == "end.")
{
ReadingContains = false;
}
if( ReadingContains == false )
{
if( strLine.StartsWith("{$") && strLine.EndsWith("}"))
{
strLine = strLine.Substring( 2 , strLine.Length - 3 );
index = strLine.IndexOf(' ');
if( index > 0 )
{
string name = strLine.Substring( 0 , index ).Trim();
strLine = strLine.Substring( index + 1 ).Trim();
if( name == "DESCRIPTION" )
{
if( this.strName == null || strName.Trim().Length == 0 )
{
strName = RemoveFlag( strLine );
}
}
else if( name == "R" )
{
FileElement rf = new FileElement();
rf.FileName = RemoveFlag( strLine );
rf.FullFileName = System.IO.Path.Combine( strRootPath , rf.FileName );
myFiles.Add( rf );
}
else if( name == "I" )
{
FileElement ifile = new FileElement();
ifile.FileName = RemoveFlag( strLine );
ifile.FullFileName = System.IO.Path.Combine( strRootPath , ifile.FileName );
myFiles.Add( ifile );
}
}
}
}
else
{
index = strLine.IndexOf(" in ");
if( index > 0 )
{
strLine = strLine.Substring( index + 4 ).Trim();
if( strLine.EndsWith(",") || strLine.EndsWith(";"))
{
strLine = strLine.Substring( 0 , strLine.Length - 1 );
}
strLine = RemoveFlag( strLine );
FileElement NewFile = new FileElement();
NewFile.FileName = strLine ;
NewFile.FullFileName = System.IO.Path.Combine( strRootPath , strLine );
if( strLine.ToLower().EndsWith(".pas"))
{
NewFile.Style = FileStyle.SourceCode ;
}
myFiles.Add( NewFile );
string name2 = System.IO.Path.ChangeExtension( strLine , "dfm");
string name3 = System.IO.Path.Combine( strRootPath , name2 );
if( System.IO.File.Exists( name3 ))
{
NewFile = new FileElement();
NewFile.FileName = name2 ;
NewFile.FullFileName = name3 ;
NewFile.Style = FileStyle.Resource ;
myFiles.Add( NewFile );
}
}
}//else
strLine = myReader.ReadLine();
}//while
myReader.Close();
}
private string RemoveFlag( string txt )
{
txt = txt.Trim();
if( txt.StartsWith("'") && txt.EndsWith("'"))
{
txt = txt.Substring( 1 , txt.Length - 2 );
}
return txt.Trim();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.