📄 workspacefilebuffer.cpp
字号:
/************************************************************************
*
* Resource ID Organiser Utility Library
*
* (c) Copyright 2000 by Andy Metcalfe (andy.metcalfe@lineone.net)
* All rights reserved.
*
************************************************************************
*
* Filename : WorkspaceFileBuffer.cpp
*
* Description : CWorkspaceFileBuffer - A string array buffer class for
* parsing Visual Studio Project (.dsp) files
*
* Compiler : Microsoft Visual C++ 6.0, Service Pack 3 or 4
*
* Target
* Environment : Windows 98/NT
*
* 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 Andy 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.resorg.co.uk 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/ResOrgUtils/WorkspaceFileBuffer.cpp $
* $Revision: 5 $
* $Date: 24/07/01 11:40 $
* $Author: Andy $
*
* $History: WorkspaceFileBuffer.cpp $
*
* ***************** Version 5 *****************
* 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 4 *****************
* User: Andy Date: 2/06/01 Time: 16:48
* Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
* Made the parser able to handle project specifications which aren't
* enclosed in quoted strings
*
* ***************** Version 3 *****************
* User: Andy Date: 2/03/01 Time: 17:12
* Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
* Implemented functionality for reading the list of projects from the
* .dsw files
*
* ***************** Version 2 *****************
* User: Andy Date: 29/11/00 Time: 18:37
* Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
* Added file banners
*
* $Nokeywords: $
*
************************************************************************/
// WorkspaceFileBuffer.cpp : implementation file
//
#include "StdAfx.h"
#include <math.h>
#include "ResOrgUtils_Priv.h"
#include "ResourceSymbol.h"
#include "ReservedSymbolsDlg.h"
#include "ProjectFileBuffer.h"
#include "WorkspaceFileBuffer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CProjectInfo::CProjectInfo(const CProjectInfo& src)
{
*this = src;
}
void CProjectInfo::operator=(const CProjectInfo& src)
{
m_sProject = src.m_sProject;
m_sPathName = src.m_sPathName;
m_arrayDependencies.RemoveAll();
m_arrayDependencies.Append(src.m_arrayDependencies);
}
/////////////////////////////////////////////////////////////////////////////
// CWorkspaceFileBuffer
IMPLEMENT_DYNCREATE(CWorkspaceFileBuffer, CWorkspaceFileBuffer_BASE)
CWorkspaceFileBuffer::CWorkspaceFileBuffer(void)
{
}
CWorkspaceFileBuffer::~CWorkspaceFileBuffer(void)
{
}
/////////////////////////////////////////////////////////////////////////////
// CWorkspaceFileBuffer message handlers
void CWorkspaceFileBuffer::Serialize(CArchive& ar)
{
ASSERT_VALID(this);
CWorkspaceFileBuffer_BASE::Serialize(ar);
}
/////////////////////////////////////////////////////////////////////////////
// Virtual Overrides
void CWorkspaceFileBuffer::DeleteContents(void)
{
m_sFileName = _T("");
m_arrayLines.RemoveAll();
m_mapProjects.RemoveAll();
}
/////////////////////////////////////////////////////////////////////////////
// Operations
int CWorkspaceFileBuffer::GetProjects(CStringArray& rarrayProjects) const
{
rarrayProjects.RemoveAll();
POSITION pos = m_mapProjects.GetStartPosition();
while (NULL != pos)
{
CString sProject;
CProjectInfo info;
m_mapProjects.GetNextAssoc(pos, sProject, info);
// rarrayProjects.Add(info.m_sPathName);
rarrayProjects.Add(info.m_sProject);
}
return rarrayProjects.GetSize();
}
int CWorkspaceFileBuffer::GetProjectCount(void) const
{
return m_mapProjects.GetCount();
}
CString CWorkspaceFileBuffer::GetResourceFileName(const CString& sProject) const
{
CString sResourceFile;
CProjectInfo info;
if (m_mapProjects.Lookup(sProject, info) )
{
CString sPathName = info.m_sPathName;
CProjectFileBuffer prj;
if (!sPathName.IsEmpty())
{
// Parse the DSP file to get the RC file
CStdioFile f;
CFileException e;
if (f.Open( sPathName,
CFile::modeRead |
CFile::shareDenyWrite,
&e) )
{
// File opened OK
//
// Now create an archive, and an empty text buffer
CArchive ar(&f, CArchive::load);
prj.Serialize(ar);
try
{
ar.Flush();
ar.Close();
f.Flush();
f.Close();
}
catch (CException* e)
{
TCHAR szCause[255];
e->GetErrorMessage(szCause, 255);
CString sMsg;
sMsg.Format( _T("Error closing project file\n\nDetails: %s\n"), szCause);
TRACE1("%s\n", sMsg);
AfxMessageBox(sMsg, MB_OK | MB_ICONSTOP);
e->Delete();
}
}
CStringArray arrayResourceFiles;
prj.GetFiles(arrayResourceFiles, _T(".rc"));
if (arrayResourceFiles.GetSize() > 0)
{
sResourceFile = arrayResourceFiles[0];
}
}
}
return sResourceFile;
}
/////////////////////////////////////////////////////////////////////////////
// Implementation
/////////////////////////////////////////////////////////////////////////////
// File Read Implementation
/******************************************************************************
* Read from an archive
*
******************************************************************************/
BOOL CWorkspaceFileBuffer::Read(CArchive& ar)
{
return CWorkspaceFileBuffer_BASE::Read(ar);
}
/******************************************************************************
* Parse the given line
*
*
******************************************************************************/
BOOL CWorkspaceFileBuffer::Parse(const CString& sLine)
{
if (!sLine.IsEmpty())
{
// Project: "CJLibrary"=".\CJLibrary\CJLibrary\CJLibrary.dsp" - Package Owner=<4>
if (sLine.Find( _T("Project:") ) == 0)
{
CString sProject = ::Between(sLine, _T("\""), _T("\"") );
CString sRemnant = ::After(sLine, _T("=") );
CString sRelativePath = ::Before(sRemnant, _T("-") );
sRelativePath.TrimLeft( _T("\" ") );
sRelativePath.TrimRight( _T("\" ") );
// Since the pathname returned is a relative one,
// we need to convert it to a fully qualified pathname
CString sFullPath = GetPathName(sRelativePath);
if (!sFullPath.IsEmpty())
{
CProjectInfo info;
info.m_sProject = sProject;
info.m_sPathName = sFullPath;
m_mapProjects[sProject] = info;
}
}
return TRUE;
}
return FALSE;
}
CString CWorkspaceFileBuffer::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 + -