⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workspacefilebuffer.cpp

📁 ResOrg 图形化管理Vc项目的资源ID的工具的源代码。 ResOrg - Manage and Renumber Resource Symbol IDs Introduction The
💻 CPP
字号:
/************************************************************************
 *
 *                 Resource ID Organiser Core Library
 *
 * (c) Copyright 2000-2004 by Anna-Jayne Metcalfe (resorg@annasplace.me.uk)
 *                         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 later
 *                Microsoft Visual C++ .NET 2003
 *                                                                       
 *  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/WorkspaceFileBuffer.cpp $
 *   $Revision: 12 $
 *       $Date: 26/10/04 10:04 $
 *     $Author: Anna $
 *
 *    $History: WorkspaceFileBuffer.cpp $
 * 
 * *****************  Version 12  *****************
 * User: Anna         Date: 26/10/04   Time: 10:04
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Added CWorkspaceFileBuffer::GetSolutionName() and
 * GetResourceFilePathNames()
 * 
 * *****************  Version 11  *****************
 * User: Anna         Date: 15/04/03   Time: 20:32
 * 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:20
 * 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: 7/06/02    Time: 17:04
 * Updated in $/Projects/AddIns/ResOrg/ResOrgCore
 * Renamed the ResOrgUtils module to ResOrgCore. Updated file banners
 * accordingly
 * 
 * *****************  Version 7  *****************
 * User: Andy         Date: 1/24/02    Time: 10:15p
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * Added support for VC7 workspaces and project files
 * 
 * *****************  Version 6  *****************
 * User: Andy         Date: 15/08/01   Time: 21:59
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * Removed unnecessary #include of ReservedSymbolsDlg.h
 * 
 * *****************  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: $
 *
 ************************************************************************/


#include "StdAfx.h"
#include <math.h>
#include "ResOrgCore_Priv.h"

#include "ResourceSymbol.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)
{
	m_eFormat = Workspace_VC6;
}


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();
}


/******************************************************************************
 *	Read from an archive
 *
 ******************************************************************************/

BOOL CWorkspaceFileBuffer::Read(CArchive& ar)
{
	CNGSplitPath splitpath(m_sFileName);
	CString sExt = splitpath.GetExtension();

	if (0 == sExt.CompareNoCase( _T(".dsw") ) )
	{
		m_eFormat = Workspace_VC6;
	}
	else
	{
		m_eFormat = Workspace_VC7;
	}
	return CWorkspaceFileBuffer_BASE::Read(ar);
}

/////////////////////////////////////////////////////////////////////////////
// Operations

CString	CWorkspaceFileBuffer::GetSolutionName(void) const
{
	CNGSplitPath split(m_sFileName);

	return split.GetFileName();
}


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_sProject);
	}

	return rarrayProjects.GetSize();
}


int CWorkspaceFileBuffer::GetProjectCount(void) const
{
	return m_mapProjects.GetCount();
}


int CWorkspaceFileBuffer::GetResourceFilePathNames(const CString& sProject,
												   CStringArray& rarrayPathNames) const
{
	rarrayPathNames.RemoveAll();

	CProjectInfo info;
	if (m_mapProjects.Lookup(sProject, info) )
	{
		CString sPathName = info.m_sPathName;

		CProjectFileBuffer prj;
		if (!sPathName.IsEmpty())
		{
			// Parse the Project file to get the Resource 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();
				}
			}
			prj.GetFiles(rarrayPathNames, _T(".rc"));
		}
	}
	return rarrayPathNames.GetSize();
}


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 Project file to get the Resource 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

/******************************************************************************
 *	Parse the given line
 *
 *
 ******************************************************************************/

BOOL CWorkspaceFileBuffer::Parse(const CString& sLine)
{
	if (!sLine.IsEmpty())
	{
		switch (m_eFormat)
		{
			case Workspace_VC6:
			{
				// 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;
			}

			case Workspace_VC7:
			{
				//Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ResOrgAddIn", "ResOrgAddIn\ResOrgAddIn.vcproj", "{C1385D10-8039-4095-80DF-0D1F9B3EAAC5}"
				if (sLine.Find( _T("Project(") ) == 0)
				{
					CString sProject = ::Between(sLine, _T("="), _T(",") );

					CString sRemnant = ::After(sLine, sProject);

					sProject.TrimLeft( _T(" \"") );
					sProject.TrimRight( _T(" \"") );

					sRemnant.TrimLeft( _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 + -