Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Delphi, .NET, Asm (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   регенератор проектов visual studio. (https://forum.antichat.xyz/showthread.php?t=121587)

sn0w 21.05.2009 00:01

регенератор проектов visual studio.
 
ну тулза считай для того чтоб переименовать проект. тупо и просто =)

// reprojectDlg.cpp : implementation file
//

#include "stdafx.h"
#include "reproject.h"
#include "reprojectDlg.h"
#include ".\reprojectdlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CreprojectDlg dialog



CreprojectDlg::CreprojectDlg(CWnd* pParent /*=NULL*/)
: CDialog(CreprojectDlg::IDD, pParent)
, m_PathName(_T(""))
, m_NewName(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CreprojectDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_PathName);
DDV_MaxChars(pDX, m_PathName, 256);
DDX_Text(pDX, IDC_EDIT2, m_NewName);
DDV_MaxChars(pDX, m_NewName, 256);
}

BEGIN_MESSAGE_MAP(CreprojectDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
END_MESSAGE_MAP()


// CreprojectDlg message handlers

BOOL CreprojectDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CreprojectDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CreprojectDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}

void CreprojectDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
OPENFILENAME ofn;
char s_file[MAX_PATH];

ZeroMemory(&ofn, sizeof(ofn));
ZeroMemory(s_file, sizeof(s_file));

ofn.lStructSize = sizeof(ofn);
ofn.lpstrFilter = "MSVC projectfile (*.vcproj)\0*.vcproj\0\0";
ofn.nMaxFile = sizeof(s_file);
ofn.lpstrFile = s_file;
ofn.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;

if(!GetOpenFileName(&ofn)){
return;
}

m_PathName = s_file;
SetCurrentDirectory(s_file);
UpdateData(0);

}











void run_replace(char *tofile, char *mem, DWORD memsize, char *tofind, char *replacestr)
{
HANDLE hOutput;
DWORD io;

hOutput = CreateFile(tofile,GENERIC_WRITE,FILE_SHARE_WRITE,0 ,CREATE_ALWAYS,0,0);

if(hOutput == INVALID_HANDLE_VALUE) return;


//write header


char *my_tag = "//\n"
"// Generated with Reproject v 1.0\n"
"// Copyright (c) 2009 by sn0w. All Rights Reserved.\n"
"// 2funny@inbox.ru\n"
"//\n\n";


char *ext = tofile;
ext += strlen(tofile);
while(*ext!='.')
ext--;
ext++;

if(!strcmp(ext, "cpp") || !strcmp(ext, "rc") || !strcmp(ext, "h") || !strcmp(ext, "c") || !strcmp(ext, "hpp"))
WriteFile(hOutput, my_tag, strlen(my_tag), &io, 0);


for(DWORD i=0; i< memsize; i++){


if(memicmp(&mem[i], tofind, strlen(tofind))==0){

WriteFile(hOutput, replacestr, strlen(replacestr), &io, 0);
i+=strlen(tofind)-1;
continue;

}

WriteFile(hOutput, &mem[i], 1, &io, 0);
}

CloseHandle(hOutput);

}



void EditCopyFile(char *s_source, char *s_target, char *tofind, char *replacestr)
{
HANDLE hFile, hMapping;
DWORD dwSize;
BYTE *fileData;


hFile = CreateFile(s_source, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if(hFile == INVALID_HANDLE_VALUE) return;

dwSize = GetFileSize(hFile, NULL);

hMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
CloseHandle(hFile);

if(hMapping == NULL) return;

fileData = (BYTE *)MapViewOfFile(hMapping, FILE_MAP_ALL_ACCESS, 0, 0, 0);

if(fileData == NULL) {
CloseHandle(hMapping);
return;
}

run_replace(s_target, (char*)fileData, dwSize, tofind, replacestr);

UnmapViewOfFile(fileData);
CloseHandle(hMapping);

}


void CreprojectDlg::OnBnClickedButton2()
{

UpdateData();

if(m_PathName.IsEmpty()){
MessageBox("No project specified!");
return;
}

if(m_NewName.IsEmpty()){
MessageBox("New name is not specified!");
return;
}
//MessageBox(m_NewName.GetBuffer(0));
//MessageBox(m_PathName.GetBuffer(0));


//reproject: [newname].rc [newname].sln [newname].vcproj

char s_path[256], *p, newname[256], oldname[256];

strcpy(s_path, m_PathName.GetBuffer(0));
p = s_path + strlen(s_path);


// "c:\\myproject\\reproject.vcproj" --> "reproject"
while(*--p!='\\') if(*p=='.') *p=0;
p++;


// process vcproj
strcpy(newname, m_NewName.GetBuffer(0));
strcat(newname, ".vcproj");
strcpy(oldname, p);
strcat(oldname, ".vcproj");
EditCopyFile(oldname, newname, p, m_NewName.GetBuffer(0));

// process cpp
strcpy(newname, m_NewName.GetBuffer(0));
strcat(newname, ".cpp");
strcpy(oldname, p);
strcat(oldname, ".cpp");
EditCopyFile(oldname, newname, p, m_NewName.GetBuffer(0));


// process rc
strcpy(newname, m_NewName.GetBuffer(0));
strcat(newname, ".rc");
strcpy(oldname, p);
strcat(oldname, ".rc");
EditCopyFile(oldname, newname, p, m_NewName.GetBuffer(0));

// process sln
strcpy(newname, m_NewName.GetBuffer(0));
strcat(newname, ".sln");
strcpy(oldname, p);
strcat(oldname, ".sln");
EditCopyFile(oldname, newname, p, m_NewName.GetBuffer(0));

// process h
strcpy(newname, m_NewName.GetBuffer(0));
strcat(newname, ".h");
strcpy(oldname, p);
strcat(oldname, ".h");
EditCopyFile(oldname, newname, p, m_NewName.GetBuffer(0));


// process c
strcpy(newname, m_NewName.GetBuffer(0));
strcat(newname, ".c");
strcpy(oldname, p);
strcat(oldname, ".c");
EditCopyFile(oldname, newname, p, m_NewName.GetBuffer(0));

// process hpp
strcpy(newname, m_NewName.GetBuffer(0));
strcat(newname, ".hpp");
strcpy(oldname, p);
strcat(oldname, ".hpp");
EditCopyFile(oldname, newname, p, m_NewName.GetBuffer(0));

// process suo
strcpy(newname, m_NewName.GetBuffer(0));
strcat(newname, ".suo");
strcpy(oldname, p);
strcat(oldname, ".suo");
CopyFile(oldname, newname, 0);


MessageBox("Reprojection complete!");

}

сорцы тут - http://www.sendspace.com/file/5i86yr

razb 21.05.2009 11:50

Ну ты хоть по человечески пост оформи, а то даже смотреть противно.

Gar|k 23.05.2009 02:53

sn0w, походу разгребает винт и все че он кодил сюда выкладывает...
вопрос, кому нужен авто переименовщик???

причем написаный абы как часть на MFC, часть на WinAPI, часть на Си.... гргргргр

scrat 23.05.2009 10:30

Цитата:

Сообщение от Gar|k
sn0w, походу разгребает винт и все че он кодил сюда выкладывает...
вопрос, кому нужен авто переименовщик???

причем написаный абы как часть на MFC, часть на WinAPI, часть на Си.... гргргргр

мне недавно нужен был.


Время: 20:30