Click here to Skip to main content
Click here to Skip to main content

Project Rename - Rename an Existing Visual Studio Project

By , 9 Jun 2009
 
ProjectRename

ProjRename-11.jpg

Introduction

This is an MFC application that renames Visual C++ Projects.
This application will replace all occurences of "Current Project Name" to "New Project Name" in all files and rename all file names that have "Current Project Name" in it.

This application supports:

  1. VC6 ~ VC9 Projects
  2. Changing the Project GUID
  3. Allows cancel during renaming
  4. UTF-8 files that may be created when the project name was non-english language
  5. Shows elapsed time and failed file list

    ProjRename-12.jpg

This application was developed for Windows XP and uses Windows XP visual style.
The borders of controls like CEdit may not be displayed clearly on Windows Vista.

Usage

  1. Browse the Visual C++ project to rename (*.dsp *.sln)
  2. Enter new project name
  3. Select "Project GUID change" if you want to change the project GUID
    (You can change GUID if you don't like the generated GUID)
  4. Click "Rename" to begin processing

Using the Code

This program is a dialog based application.
It has two views, one is "SelectView" the other is "ProgressView".

BEGIN_MESSAGE_MAP(CProjectRenameDlg, CDialog)
   ON_WM_SYSCOMMAND()
   ON_WM_PAINT()
   ON_WM_QUERYDRAGICON()
   ON_WM_DESTROY()
   ON_MESSAGE(WMU_SELECT_VIEW_CLOSE, OnSelectViewClose)
   ON_MESSAGE(WMU_PROGRESS_VIEW_CLOSE, OnProgressViewClose)
   ON_MESSAGE(WMU_RENAME_FINISHED, OnRenameDone)
   ON_MESSAGE(WMU_RENAME_CANCELED, OnCancelRename)
END_MESSAGE_MAP()

When the user clicked "Rename" to begin renaming, WM_SELECT_VIEW_CLOSE message is sent from "SelectView" and the thread to process is created.

LRESULT CProjectRenameDlg::OnSelectViewClose(WPARAM wParam, LPARAM lParam)
{
   m_pRenameThread = (CRenameThread*)AfxBeginThread
	(RUNTIME_CLASS(CRenameThread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
   m_pRenameThread->m_bCancel = FALSE;
   m_pRenameThread->m_pOwner = this;
   m_pRenameThread->m_renameOptions = ((CSelectView*)m_pSelectView)->GetRenameOptions();
   m_pRenameThread->ResumeThread();
}

When renaming has been finished, the thread sends WM_RENANE_FINISHED message to notify that renaming has been completed. 

BOOL CRenameThread::InitInstance()
{
    ASSERT(!m_renameOptions.strCurrentPath.IsEmpty());

    // Make list of files to rename
    m_astrFileList.RemoveAll();
    PrepareRename(m_renameOptions.strCurrentPath);

    m_renameStatus.nTotalFiles = m_astrFileList.GetSize();
    m_renameStatus.nCheckedFiles = 0;
    m_renameStatus.nRenamedFiles = 0;
    m_renameStatus.astrErrorList.RemoveAll();
    ProcessRename(m_renameOptions.strCurrentPath);
    return FALSE;
}

int CRenameThread::ExitInstance()
{
    m_pOwner->PostMessage(WMU_RENAME_FINISHED);
    return CWinThread::ExitInstance();
}

History

  • 8 Jun 2009: Version 0.10 Released
  • 9 Jun 2009: Version 0.11 Fixed bug with writing to UFT-8 files

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Flying Light
Korea (Republic Of) Korea (Republic Of)
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalerror when project including a XML filemembermaplewang24 Oct '10 - 21:16 
occurs in RenameThread.cpp
CString strWorkingFile = strFile;
strWorkingFile.MakeLower();//error here when the file is UpgradeLog.XML
strFind.MakeLower();
the upgrade.xml is an autogenerate file when converting a dsw or low version of VS sln files to VS2008.
GeneralRe: error when project including a XML filememberFlying Light27 Oct '10 - 13:38 
It's because the MakeLower() generates an error if invalid ascii charactor is in the string.
You can catch an exception to solve the error.
 
    try
    {
        strFind.MakeLower();
        strWorkingFile.MakeLower();
        nIndex = strWorkingFile.Find(strFind);
    }
    catch (...)
    {
        // if the file has invalid characters in it
        m_renameStatus.astrErrorList.Add(GetFilePathExcludingStartPath(strFilePath) + _T(" (Unable to check - It has invalid characters)"));
        ASSERT(FALSE);
        return FALSE;
    }
 
    if (nIndex == -1)
        return FALSE;
 
New executable is available.
 
Download Static Executable
GeneralRe: error when project including a XML filemembermaplewang22 Nov '10 - 21:23 
error still exist in StringTraits::StringLowercase( pszBuffer, nLength+1 );
the xml mail file is autogenerate by VS2008 when upgrade form lower version VS project, my fail file name is UpgradeLog.XML
GeneralGot error when running ProjRen.exememberehaerim15 Jun '09 - 10:11 
The executables downloaded failed to run.
 
Also tried to download the source and compile but unfortunately don't have VC2008 but VC2005.
 
I've tried to hack the .sln and .vcproj file by modifying the VC version related numbers, but still got the following complaints from the VC2005 compiler:
 
1>------ Rebuild All started: Project: ProjectRenameDlg, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'ProjectRenameDlg', configuration 'Debug|Win32'
1>Compiling...
1>StdAfx.cpp
1>Compiling...
1>SelectView.cpp
1>RenameThread.cpp
1>ProjectRenameDlg.cpp
1>ProjectRename.cpp
1>ProgressView.cpp
1>GroupBox.cpp
1>Generating Code...
1>Compiling resources...
1>.\ProjectRenameDlg.rc(69) : error RC2176 : old DIB in res\ProjectRenameDlg.ico; pass it through SDKPAINT
1>Build log was saved at "file://c:\Download\ProjectRename\Debug\BuildLog.htm"
1>ProjectRenameDlg - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
 
Would you be able to convert the source to VC2005 version?
 
You can send me the converted project files to ehaerim@gmail.com.
 
Thanks a lot.
GeneralRe: Got error when running ProjRen.exemembermerano15 Jun '09 - 13:54 
After changing Version="9.00" to Version="8.00"
and adding the res folder everything was working.
 
I found the following about your Problem:
 
Install the Vista SDK if you're going to build.
The icon is Vista-compatible, but VC2k5 doesn't
have a new enough resource compiler.
 
Best regards
Rainer
GeneralRe: Got error when running ProjRen.exememberehaerim15 Jun '09 - 14:19 
I got error when running the ProjRen.exe extracted from the zip file.
 
Does the executable included in the zip also require Vista SDK to run?
 
HR
AnswerPlease download static executablememberFlying Light15 Jun '09 - 18:48 
ProjRen.exe was built with dynamic libraries option, you may not be able to run it if you don't have VS2008.
Please download the executable built with static libraries for you.
 
Download Static Executable
 
modified on Tuesday, June 16, 2009 1:31 AM

AnswerRe: Got error when running ProjRen.exemembermerano16 Jun '09 - 3:47 
The included ProjRen.exe requires mfc90.dll (and msvcr90.dll ...)
 
If you run Windows XP and VS2005 it is not availible.
 
After recompiling it uses the Version that is installed.
 
Cant say at the moment what Package includes MFC updates but
certainly it is in VS2008 (which i dont use ..)
General#include "res\ProjectRenameDlg.rc2" // non-Microsoft Visual C++ edited resources missingmembertransoft10 Jun '09 - 2:12 
Can not compile. missing following
 
#include "res\ProjectRenameDlg.rc2" // non-Microsoft Visual C++ edited resources
AnswerPlease download missing filesmemberFlying Light10 Jun '09 - 3:00 
Thank you for your message.
You can download missing files if you click the link.
 
Misssing Files
 
modified on Wednesday, June 10, 2009 9:08 AM

GeneralWorks finememberSpolm9 Jun '09 - 22:40 
It compiles and works fine and is very useful for me.
Thank you very much, you got my 5! Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 9 Jun 2009
Article Copyright 2009 by Flying Light
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid