Main page Computer games Game development Author related Webpage related
Computer Graphics Art Computer Graphics Software Development Unofficial URL Advanced Graphics Page
-Main page
-Computer Graphics Art
-Computer games
-Computer Graphics
-Game development
-Software Development
-All languages
-Software law
-Theory
-ASP
-CFM
-C/C++
-Misc
-Compilers
-Microsoft Foundation Classes
-Microsoft Visual Studio
-Delphi
-Java
-Javascript
-Lisp
-Lua
-.NET
-PERL
-PHP
-Pythoon
-SQL
-Visual Basic
-VBScript
-Other languages
-Web Development
-Development Tools
-Author related
-Unofficial URL Advanced Graphics Page
-Webpage related
 

Adjust file classes 
Microsoft Visual Studio
This program changes the name of the .cpp and .h files containing a class, changing .dsp
Author M.L. Viñas Livschitz  Last update 2000-08-07  English
 

<< Developing the program Downloads >>

Performing changes

Well the next phase is the change, it will be done by changing the .dsp project:

        
// Now the data is acquired, let's do the changes
{       
 // Change includes in dsp file
 // Open the file
 CString StringFile = _ReadStringFile(m_Project);
 for(POSITION Pos = SourceDeps.GetStartPosition(); Pos!=NULL;)
 {
  // Get the data
  CString TheHeader,ClassName,CorrectHeader;
  SourceDeps.GetNextAssoc(Pos,TheHeader,ClassName);
  ClassToCorrectHeader.Lookup(ClassName,CorrectHeader);
 
  {
   // Header
   CString Pattern1 = "SOURCE="+TheHeader;
   CString Pattern2 = "/"+TheHeader;
   CString Pattern3 = "\\"+TheHeader;
   CString Pattern1Change = "SOURCE="+CorrectHeader;
   CString Pattern2Change = "/"+CorrectHeader;
   CString Pattern3Change = "\\"+CorrectHeader;
 
   StringFile.Replace(Pattern1,Pattern1Change);
   StringFile.Replace(Pattern2,Pattern2Change);
   StringFile.Replace(Pattern3,Pattern3Change);
  }
 
  {
   // Sources
   TheHeader = TheHeader.Left(TheHeader.GetLength()-1)+"cpp";
 
   CorrectHeader = 
    CorrectHeader.Left(CorrectHeader.GetLength()-1)+"cpp";
 
   CString Pattern1 = "SOURCE="+TheHeader;
   CString Pattern2 = "/"+TheHeader;
   CString Pattern3 = "\\"+TheHeader;
   CString Pattern1Change = "SOURCE="+CorrectHeader;
   CString Pattern2Change = "/"+CorrectHeader;
   CString Pattern3Change = "\\"+CorrectHeader;
 
   StringFile.Replace(Pattern1,Pattern1Change);
   StringFile.Replace(Pattern2,Pattern2Change);
   StringFile.Replace(Pattern3,Pattern3Change);
  }
 }
 
 // Save the file
 _WriteStringFile(m_Project,StringFile);
}

After change the project we must change the include references in source and header files.

{       
 // Perform changes in header and source files
 CStringList FilesToPerformReplace;
 FilesToPerformReplace.AddTail(&SourceFiles);
 FilesToPerformReplace.AddTail(&HeaderFiles);
 
 while(!FilesToPerformReplace.IsEmpty())
 {      
  // For each file
  CString TheFile = FilesToPerformReplace.RemoveHead();
 
  // Open the file
  CString StringFile = _ReadStringFile(TheFile);
 
  // Perform replaces
  for(POSITION Pos = SourceDeps.GetStartPosition(); Pos!=NULL;)
  {
   // Get the data
   CString TheHeader,ClassName,CorrectHeader;
   SourceDeps.GetNextAssoc(Pos,TheHeader,ClassName);
   ClassToCorrectHeader.Lookup(ClassName,CorrectHeader);
 
   CString Pattern1 = "\""+TheHeader+"\"";
   CString Pattern2 = "<"+TheHeader+">";
   CString Pattern3 = "\\"+TheHeader+">";
   CString Pattern1Change = "\""+CorrectHeader+"\"";
   CString Pattern2Change = "<"+CorrectHeader+">";
   CString Pattern3Change = "\\"+CorrectHeader+">";
 
   StringFile.Replace(Pattern1,Pattern1Change);
   StringFile.Replace(Pattern2,Pattern2Change);
   StringFile.Replace(Pattern3,Pattern3Change);
  }
 
  // Save the file
  _WriteStringFile(TheFile,StringFile);
 }
 
 // allfiles where replaced
}

And rename the files....

{       
 // And now the last phase, renaming the files
 for(POSITION Pos = SourceDeps.GetStartPosition(); 
     Pos!=NULL;)
 {
  // Get the data
  CString TheHeader,ClassName,CorrectHeader;
  SourceDeps.GetNextAssoc(Pos,TheHeader,ClassName);
  ClassToCorrectHeader.Lookup(ClassName,CorrectHeader);
 
  // The headers
  if (TheHeader!=CorrectHeader)
  {
   char *file, *filenew;
   file = _fullpath(NULL,TheHeader,0);
   filenew = _fullpath(NULL,CorrectHeader,0);
   CopyFile(file,filenew,false);
   DeleteFile(file);
   free(file);
   free(filenew);
  }
 
  // The sources
  TheHeader = TheHeader.Left(TheHeader.GetLength()-1)+"cpp";
 
  CorrectHeader 
  = CorrectHeader.Left(CorrectHeader.GetLength()-1)+"cpp";
 
  if (TheHeader!=CorrectHeader)
  {
   char *file, *filenew;
   file = _fullpath(NULL,TheHeader,0);
   filenew = _fullpath(NULL,CorrectHeader,0);
   CopyFile(file,filenew,false);
   DeleteFile(file);
   free(file);
   free(filenew);
  }
 }
}

And that's all. Note that I use a file like a string, it's a serializated file. This is because it increases overall performance using Replace function of CString class made in assembler.

// unique string-file functions
CString CAdjustFileClassesDlg::_ReadStringFile(CString file)
{
 CString StringFile;
 {      
  // We load the file into a string
  char * str;
  CFile file(file,CFile::modeRead | CFile::shareDenyNone);
  StringFile.GetBufferSetLength(file.GetLength()+1);
  str = StringFile.LockBuffer();
  file.ReadHuge(str,file.GetLength());
  str[file.GetLength()]=0;
  file.Close();
  StringFile.UnlockBuffer();
 }
 return StringFile;
}
 
void CAdjustFileClassesDlg::_WriteStringFile(CString _file, 
                                             CString data)
{
 CFile file(_file, 
            CFile::modeCreate 
             | CFile::modeWrite 
             | CFile::shareDenyNone);
 
 file.WriteHuge(data.LockBuffer(),data.GetLength()-1);
 data.UnlockBuffer();
 file.Close();
}

But for reading files, that have a relative path from the .dsp we first need to do this:

// Get the base directory of the project
m_Project.Replace('\\','/');
CString BaseDir;
int pos = m_Project.ReverseFind('/');
 
if (pos==-1)
{
 BaseDir="";
}
else
{
 BaseDir=m_Project.Left(pos+1);
}
 
if(-1==_chdir(BaseDir))
{
 ::AfxMessageBox("Something wrong in the path of "
                 +m_Project+", exiting");
 return;
}

Well, I hope that this code will be interesting and useful for you like it was for me.

<< Developing the program Downloads >>

Any and all trademarks used belong to their respective owners. Please read our Terms, Conditions, and Privacy information.
Optimized for at least 1024x768 resolution (true-color) viewing with Microsoft Internet Explorer 5.0 and later versions.
This site was designed and developed by Manuel Lucas Viñas Livschitz.
Copyright 2000-2002 M.L.Viñas Livschitz.
To subscribe send a mail without subject to ultralight_magazine-subscribe@eListas.net
Para suscribirte manda un mail sin asunto a: ultralight_magazine-alta@eListas.net
To cancel subscription send a mail without subject to ultralight_magazine-unsubscribe@eListas.net
Para cancelar tu suscripción manda un mail sin asunto a: ultralight_magazine-baja@eListas.net

Contact webmaster