📄 projectfilebuffer.cpp
字号:
/************************************************************************
*
* Resource ID Organiser Core Library
*
* (c) Copyright 2000-2003 by Anna-Jayne Metcalfe (resorg@annasplace.me.uk)
* All rights reserved.
*
************************************************************************
*
* Filename : ProjectFileBuffer.cpp
*
* Description : CProjectFileBuffer - A string array buffer class for
* parsing Visual Studio Project (.dsp) files
*
* Compiler : Microsoft Visual C++ 6.0, Service Pack 3 or later
* Microsoft Visual C++ .NET 2002
*
* Target
* Environment : Windows 98/NT/2000/XP
*
* NOTE:
*
* This software is provided "as is" free for personal use. All
* title and copyrights in and to the software, including but not
* limited to any images, text, etc. incorporated into it, are
* owned by Anna-Jayne Metcalfe, except where acknowledged otherwise.
*
* Your may freely to use this code in your own products, PROVIDED
* this notice is not removed or modified.
*
*
* Visit http://www.annasplace.me.uk/resorg for latest updates
*
************************************************************************
*
* MODIFICATION HISTORY:
*
* This is a controlled document. See project configuration
* control tool for latest version and full version history.
*
* $Archive: /Projects/AddIns/ResOrg/ResOrgCore/ProjectFileBuffer.cpp $
* $Revision: 11 $
* $Date: 15/04/03 20:38 $
* $Author: Anna $
*
* $History: ProjectFileBuffer.cpp $
*
* ***************** Version 11 *****************
* User: Anna Date: 15/04/03 Time: 20:38
* Updated in $/Projects/AddIns/ResOrg/ResOrgCore
* 1. Removed unnecessary file guards (#pragma once works well enough)
* 2. Updated file banners
*
* ***************** Version 10 *****************
* User: Anna Date: 25/11/02 Time: 15:10
* Updated in $/Projects/AddIns/ResOrg/ResOrgCore
* Changed website address in banner
*
* ***************** Version 9 *****************
* User: Anna Date: 22/10/02 Time: 13:24
* Updated in $/Projects/AddIns/ResOrg/ResOrgCore
* Changed name/mail address (at last!)
*
* ***************** Version 8 *****************
* User: Andy Date: 1/08/02 Time: 15:39
* Updated in $/Projects/AddIns/ResOrg/ResOrgCore
* Made CProjectFileBuffer::ParseVc7Project() a bit safer
*
* ***************** Version 7 *****************
* User: Andy Date: 7/06/02 Time: 17:04
* Updated in $/Projects/AddIns/ResOrg/ResOrgCore
* Renamed the ResOrgUtils module to ResOrgCore. Updated file banners
* accordingly
*
* ***************** Version 6 *****************
* User: Andy Date: 1/24/02 Time: 10:15p
* Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
* Added support for VC7 workspaces and project files
*
* ***************** Version 5 *****************
* User: Europa Date: 19/01/02 Time: 17:48
* Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
* Started preparing to add VC7 compatibility
*
* ***************** Version 4 *****************
* User: Andy Date: 15/08/01 Time: 14:45
* Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
* No longer includes ReservedSymbolsDlg.h (not sure why it did anyway!)
*
* ***************** Version 3 *****************
* User: Andy Date: 24/07/01 Time: 11:40
* Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
* Shlwapi is no longer used for the PathCombine() function. A wrapper
* function [CombinePath()] in NGLibrary is used instead.
*
* ***************** Version 2 *****************
* User: Andy Date: 29/11/00 Time: 18:37
* Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
* Added file banners
*
* $Nokeywords: $
*
************************************************************************/
#include "StdAfx.h"
#include <math.h>
#include "ResOrgCore_Priv.h"
#include "ResourceSymbol.h"
#include "ProjectFileBuffer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CProjectFileBuffer
#define BUFFER_GROWBY 100 // Grow file buffer by 100 lines at a time
#define BUF_SIZE 1024
#define WHITE_SPACE _T(" \t")
IMPLEMENT_DYNCREATE(CProjectFileBuffer, CProjectFileBuffer_BASE)
CProjectFileBuffer::CProjectFileBuffer(void)
{
m_eFormat = Project_VC6;
m_bParsingFile = FALSE;
}
CProjectFileBuffer::~CProjectFileBuffer(void)
{
}
/////////////////////////////////////////////////////////////////////////////
// CProjectFileBuffer message handlers
void CProjectFileBuffer::Serialize(CArchive& ar)
{
ASSERT_VALID(this);
CProjectFileBuffer_BASE::Serialize(ar);
}
/////////////////////////////////////////////////////////////////////////////
// Virtual Overrides
/******************************************************************************
* Read from an archive
*
******************************************************************************/
BOOL CProjectFileBuffer::Read(CArchive& ar)
{
CNGSplitPath splitpath(m_sFileName);
CString sExt = splitpath.GetExtension();
if (0 == sExt.CompareNoCase( _T(".dsp") ) )
{
m_eFormat = Project_VC6;
}
else
{
m_eFormat = Project_VC7;
}
return CProjectFileBuffer_BASE::Read(ar);
}
/////////////////////////////////////////////////////////////////////////////
// Operations
int CProjectFileBuffer::GetFiles( CStringArray& rarrayFiles,
const CString& sExt /*= _T("")*/ ) const
{
rarrayFiles.RemoveAll();
if (sExt.IsEmpty())
{
rarrayFiles.Append(m_arrayFiles);
}
else
{
for (int n = 0; n < m_arrayFiles.GetSize(); n++)
{
CString sFile = m_arrayFiles[n];
CNGSplitPath path(sFile);
if (path.GetExtension() == sExt)
{
rarrayFiles.Add(sFile);
}
}
}
return rarrayFiles.GetSize();
}
/////////////////////////////////////////////////////////////////////////////
// Implementation
/////////////////////////////////////////////////////////////////////////////
// File Read Implementation
/******************************************************************************
* Parse the whole buffer
*
******************************************************************************/
BOOL CProjectFileBuffer::Parse(void)
{
BOOL bResult = FALSE;
switch (m_eFormat)
{
case Project_VC6:
bResult = CProjectFileBuffer_BASE::Parse();
break;
case Project_VC7:
bResult = ParseVc7Project();
break;
default:
ASSERT(FALSE);
break;
}
return bResult;
}
/******************************************************************************
* Parse the given line
*
******************************************************************************/
BOOL CProjectFileBuffer::Parse(const CString& sLine)
{
if (!sLine.IsEmpty())
{
if (sLine.Find( _T("# Begin Source File") ) == 0)
{
m_bParsingFile = TRUE;
}
else if (sLine.Find( _T("# End Source File") ) == 0)
{
m_bParsingFile = FALSE;
}
else if (m_bParsingFile)
{
if (sLine.Find( _T("SOURCE") ) == 0)
{
CString sFile = ::After( sLine, _T("=") );
// Strip quotes
sFile.TrimLeft( _T("\"") );
sFile.TrimRight( _T("\"") );
if (!sFile.IsEmpty() )
{
CString sPathName = GetPathName(sFile);
if (!sPathName.IsEmpty())
{
m_arrayFiles.Add(sPathName);
}
}
}
}
return TRUE;
}
return FALSE;
}
BOOL CProjectFileBuffer::ParseVc7Project(void)
{
int nLine = 0;
CString sBuffer;
while (nLine < m_arrayLines.GetSize() )
{
CString sLine = m_arrayLines[nLine++];
if (!sLine.IsEmpty())
{
sLine.TrimLeft();
sLine.TrimRight();
sBuffer += sLine + _T(" ");
}
}
int nFilesBlockStart = sBuffer.Find( _T("<Files>") );
if (nFilesBlockStart > 0)
{
int nFilesBlockEnd = sBuffer.Find( _T("</Files>"), nFilesBlockStart );
if (nFilesBlockEnd > nFilesBlockStart)
{
int nCurrentBlockStart = nFilesBlockStart;
while (nCurrentBlockStart > 0)
{
nCurrentBlockStart = sBuffer.Find( _T("<File "), nCurrentBlockStart);
if (nCurrentBlockStart > 0)
{
int nCurrentBlockEnd = sBuffer.Find( _T("</File>"), nCurrentBlockStart);
CString sFileTag = sBuffer.Mid(nCurrentBlockStart, nCurrentBlockEnd - nCurrentBlockStart + 1);
CString sRelativePathName = ::Between(sFileTag, _T("RelativePath"), _T(">") );
sRelativePathName.TrimLeft( _T(" =\"") );
sRelativePathName.TrimRight( _T(" \"") );
CString sPathName = GetPathName(sRelativePathName);
if (!sPathName.IsEmpty())
{
m_arrayFiles.Add(sPathName);
}
nCurrentBlockStart = nCurrentBlockEnd;
}
}
}
}
return (m_arrayFiles.GetSize() > 0);
}
CString CProjectFileBuffer::GetPathName(const CString& sRelativePath) const
{
CString sPathName;
if (!sRelativePath.IsEmpty())
{
CNGSplitPath path(m_sFileName);
sPathName = ::CombinePath(path.GetDrive() + path.GetDirectory(), sRelativePath);
}
return sPathName;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -