关于
我的项目
相关阅读
热度排行
- [转] 宫崎骏用动漫教给我们的人生哲理,每一句都能说到心里! - (日期:[八月 24, 2013] 点击:[53,609])
- Google 网页爬虫报告无法连接站点解决办法 - (日期:[七月 20, 2014] 点击:[38,665])
- 架设Tiny Tiny RSS(TTRSS)阅读器,找回Google Reader! - (日期:[九月 27, 2013] 点击:[27,807])
- SkyDrive、DropBox和Google Drive三大公有云存储服务对比 - (日期:[六月 25, 2013] 点击:[25,673])
- 升级到至强E5440后,与i5 CPU笔记本性能对比 - (日期:[二月 18, 2014] 点击:[23,841])
- 公钥私钥加密解密数字证书数字签名详解 - (日期:[四月 19, 2014] 点击:[22,976])
- 本站建站技术合集 - (日期:[九月 20, 2013] 点击:[22,557])
- 使用OpenerDNS解决无法访问Google的问题 - (日期:[七月 5, 2014] 点击:[21,857])
- WordPress博客添加“返回顶部”按钮 - (日期:[七月 14, 2013] 点击:[21,278])
- Linux文件系统基础之inode和dentry - (日期:[三月 13, 2015] 点击:[20,221])
- 云存储中的HTTP鉴权算法分析 - (日期:[二月 7, 2014] 点击:[18,655])
- 存储基础知识之——磁盘阵列原理及操作实战 - (日期:[二月 9, 2014] 点击:[17,544])
- 精选37条强大的常用linux shell命令组合 - (日期:[九月 4, 2013] 点击:[17,469])
- DNS原理、架构和配置详解 - (日期:[九月 6, 2013] 点击:[16,876])
- Netty和Jetty的Java NIO 网络框架模型分析 - (日期:[七月 13, 2013] 点击:[16,351])
- CoreOS 初识之安装 - (日期:[十一月 16, 2014] 点击:[16,221])
- Windows与Linux文件系统互访的几种方法 - (日期:[八月 21, 2014] 点击:[15,739])
- Dijkstra算法求解最短路径分析 - (日期:[七月 12, 2014] 点击:[14,942])
- NAS解决方案实现多媒体文件共享播放 - (日期:[十二月 21, 2014] 点击:[13,967])
- 简介 - (日期:[九月 1, 2012] 点击:[13,790])
- 如何编程实现 2 + 2 = 5? - (日期:[六月 2, 2014] 点击:[13,278])
- 搭建了一个iNews程序 - (日期:[十月 15, 2013] 点击:[13,252])
- 2014年9月曝出的Bash ShellShock漏洞简析 - (日期:[九月 26, 2014] 点击:[13,170])
- 彻底解决WordPress博客垃圾评论的问题 - (日期:[八月 5, 2013] 点击:[13,165])
- 如何使用1M的内存排序100万个8位数 - (日期:[三月 27, 2014] 点击:[12,570])
- 全部日志列表 - (日期:[十一月 11, 2012] 点击:[12,427])
- 关于回调函数和this指针探讨 - (日期:[八月 24, 2014] 点击:[12,246])
- 开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南 - (日期:[四月 23, 2022] 点击:[11,864])
- 给定一个long型常量,其值为x,给定long型变量a,要求a & x 的取值集合 - (日期:[九月 8, 2012] 点击:[11,742])
- WordPress建站必备实用插件 - (日期:[八月 7, 2014] 点击:[11,388])
-
近期文章
- Golang PGO技术介绍 四月 13, 2025
- 3FS Usrbio 简介 四月 6, 2025
- NVIDIA 为 CUDA 添加原生 Python 支持:开启 GPU 计算新篇章 四月 5, 2025
- pico.sh服务简介 四月 4, 2025
- cloudflare的妙用 一月 11, 2025
- 介绍一个生产力工具:ntfy 十二月 24, 2024
- 困扰了快1个月的家用宽带网络卡顿问题-Linux病毒实战手记 四月 21, 2024
- HomeServer 2024升级计划 二月 11, 2024
- HomeServer直播、监控方案实践 九月 28, 2023
- 我的2022 一月 7, 2023
近期评论
- 匿名发表在《开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南》
- 1发表在《开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南》
- xxgl发表在《开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南》
- 童燕群发表在《开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南》
- xxgl发表在《开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南》
- 童燕群发表在《开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南》
- xxgl发表在《开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南》
- 童燕群发表在《开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南》
- xxgl发表在《开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南》
- xxgl发表在《开源好用的电子书管理服务Talebook(Calibre网络版)安装使用指南》
分类目录
文章归档
- 2025年四月 (4)
- 2025年一月 (1)
- 2024年十二月 (1)
- 2024年四月 (1)
- 2024年二月 (1)
- 2023年九月 (1)
- 2023年一月 (1)
- 2022年十月 (1)
- 2022年八月 (2)
- 2022年四月 (1)
- 2022年三月 (1)
- 2021年十二月 (2)
- 2021年十月 (2)
- 2021年九月 (1)
- 2021年八月 (1)
- 2021年五月 (1)
- 2021年三月 (2)
- 2021年一月 (2)
- 2020年十二月 (5)
- 2020年十一月 (2)
- 2020年十月 (2)
- 2020年九月 (1)
- 2020年八月 (5)
- 2020年七月 (2)
- 2019年九月 (1)
- 2018年八月 (1)
- 2018年七月 (1)
- 2018年六月 (1)
- 2018年五月 (1)
- 2018年三月 (1)
- 2018年二月 (1)
- 2018年一月 (2)
- 2017年十二月 (3)
- 2017年十月 (4)
- 2017年九月 (1)
- 2017年七月 (1)
- 2017年六月 (1)
- 2016年十二月 (1)
- 2016年十月 (1)
- 2016年九月 (1)
- 2016年七月 (2)
- 2016年六月 (1)
- 2016年二月 (3)
- 2015年十二月 (3)
- 2015年十一月 (2)
- 2015年十月 (1)
- 2015年八月 (2)
- 2015年七月 (4)
- 2015年六月 (1)
- 2015年三月 (2)
- 2015年二月 (1)
- 2015年一月 (4)
- 2014年十二月 (2)
- 2014年十一月 (2)
- 2014年十月 (5)
- 2014年九月 (8)
- 2014年八月 (11)
- 2014年七月 (17)
- 2014年六月 (7)
- 2014年五月 (15)
- 2014年四月 (16)
- 2014年三月 (14)
- 2014年二月 (5)
- 2013年十二月 (5)
- 2013年十一月 (3)
- 2013年十月 (13)
- 2013年九月 (13)
- 2013年八月 (13)
- 2013年七月 (9)
- 2013年六月 (8)
- 2013年五月 (1)
- 2013年三月 (3)
- 2013年一月 (1)
- 2012年十一月 (1)
- 2012年九月 (12)
- 2012年八月 (3)
- 2011年二月 (1)
- 2009年三月 (1)
- 2009年二月 (1)
- 2008年十一月 (1)
- 2008年六月 (1)
- 2008年四月 (1)
- 2008年三月 (1)
扫描目录自动生成VS2005/2008工程文件
对于喜欢使用Visual Studio看代码和写代码的同学而言,没有VS工程,手动建工程通常是一件非常痛苦的事情。之前一直使用一个叫做MPC的工具生成各个版本的VS工程文件,该工具依赖perl语言,而且只能遍历一级目录,不能递归到所有的子目录(也可能工具提供,但是是我没有深入研究工具的配置),而且工具集成到右键菜单,不是经常使用的功能集成到右键菜单不是很好。重新安装了操作系统后,再也不想安装复杂的MPC了,在网上找新的替代工具,找到了如下网址提供的DIY式的工具:链接。
感觉工具中写死工程名字不是很好,稍作了一点修改。使用目录名作为工程名,同时省去了第三个参数。这样只需要将目录拖拽到工具上面就可以在目录内部生成一个与目录名同名的工程文件。该工程文件为VS2005和VS2008兼容的vcxproj格式的文件。对于高版本打开该工具生成的工程时,打开时,会提示升级。以下代码在VS2013编译通过。
根据下面的代码生成一个vcmaketool.exe的工具,然后将需要生成VS工程的目录拖拽到其上即可。
VS2013工程下载:链接。
#include "stdafx.h"
#include <string>
#include <io.h>
#include <windows.h>
FILE *g_pFile = NULL;
const char *g_packsDir = NULL;
int g_packsDirLen = 0;
void Build(const char *packsDir, const char *subdir)
{
WIN32_FIND_DATAA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH]; // directory specification
DWORD dwError;
strcpy_s(DirSpec, packsDir);
int rlen = strlen(DirSpec);
if (DirSpec[rlen - 1] == '\\')
{
DirSpec[rlen - 1] = '0';
}
if (subdir&&subdir[0] != 0)
{
strcat_s(DirSpec, "\\");
strcat_s(DirSpec, subdir);
}
int saveLen = strlen(DirSpec);
strcat_s(DirSpec, "\\*");
hFind = FindFirstFileA(DirSpec, &FindFileData);
DirSpec[saveLen] = '\0';
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
if (FindFileData.cFileName[0] != '.'
&& strstr(FindFileData.cFileName, "objchk") == NULL
&& strstr(FindFileData.cFileName, "objfre") == NULL
)
{
fprintf(g_pFile, " <Filter "
"\nName=\"%s\""
"\nFilter=\"cpp;c;h;cc;cxx;def;odl;idl;hpj;bat;asm;asmx\""
"\n>\n", FindFileData.cFileName
);
Build(DirSpec, FindFileData.cFileName);
fprintf(g_pFile, "%s\n", "\n </Filter>\n");
}
}
else
{
int len = strlen(FindFileData.cFileName);
if (len < 4 || _strcmpi(FindFileData.cFileName + len - 4, ".obj") != 0)
{
fprintf(g_pFile,
"\n<File"
"\nRelativePath=\".%s\\%s\""
"\n></File>\n",
DirSpec + g_packsDirLen, FindFileData.cFileName);
}
}
} while (FindNextFileA(hFind, &FindFileData) != 0);
dwError = GetLastError();
FindClose(hFind);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
if (argc != 2)
{
printf("usage:\nvcmaketool dir"
"\n\nexample:"
"\nvcmaketool c:\\abc\n");
getchar();
return 0;
}
std::string path = argv[1];
int pos = 0;
while (((pos = path.rfind("\\")) == (path.size() - 1)) && !path.empty())
{
path.erase(pos);
pos = path.rfind("\\");
}
if (pos == 0 || path.empty())
{
printf("input path is invalid!\n");
return -1;
}
std::string projname = path.substr(pos + 1, path.size());
std::string projfilename = path + "\\" + projname + ".vcproj";
if (_access(projfilename.c_str(), 0) == 0)
{
printf("the project file(%s) is already exist.\n", projfilename.c_str());
getchar();
return -1;
}
int ret = fopen_s(&g_pFile, projfilename.c_str(), "w");
if (0 != ret)
{
printf("create the project file failed!\n");
getchar();
return -1;
}
const char* proj = projname.c_str();
#define MAX_OUT_LEN (1024 * 1024)
char* szOut = new char[MAX_OUT_LEN];
sprintf_s(szOut, MAX_OUT_LEN - 1,
"<?xml version=\"1.0\" encoding=\"gb2312\"?>"
"\n<VisualStudioProject"
"\n ProjectType=\"Visual C++\""
"\n Version=\"9.00\""
"\n Name=\"%s\""
"\n ProjectGUID=\"{8B8C6959-68F6-4182-8EA9-87C1E30EBE9E}\""
"\n Keyword=\"MakeFileProj\""
"\n TargetFrameworkVersion=\"196613\""
"\n >"
"\n <Platforms>"
"\n <Platform"
"\n Name=\"Win32\""
"\n />"
"\n </Platforms>"
"\n <ToolFiles>"
"\n </ToolFiles>"
"\n <Configurations>"
"\n <Configuration"
"\n Name=\"Debug|Win32\""
"\n OutputDirectory=\"$(ConfigurationName)\""
"\n IntermediateDirectory=\"$(ConfigurationName)\""
"\n ConfigurationType=\"0\""
"\n >"
"\n <Tool"
"\n Name=\"%s\""
"\n BuildCommandLine=\"\""
"\n ReBuildCommandLine=\"\""
"\n CleanCommandLine=\"\""
"\n Output=\"%sd.exe\""
"\n PreprocessorDefinitions=\"WIN32;_DEBUG\""
"\n IncludeSearchPath=\"\""
"\n ForcedIncludes=\"\""
"\n AssemblySearchPath=\"\""
"\n ForcedUsingAssemblies=\"\""
"\n CompileAsManaged=\"\""
"\n />"
"\n </Configuration>"
"\n <Configuration"
"\n Name=\"Release|Win32\""
"\n OutputDirectory=\"$(ConfigurationName)\""
"\n IntermediateDirectory=\"$(ConfigurationName)\""
"\n ConfigurationType=\"0\""
"\n >"
"\n <Tool"
"\n Name=\"%s\""
"\n BuildCommandLine=\"\""
"\n ReBuildCommandLine=\"\""
"\n CleanCommandLine=\"\""
"\n Output=\"%s.exe\""
"\n PreprocessorDefinitions=\"WIN32;NDEBUG\""
"\n IncludeSearchPath=\"\""
"\n ForcedIncludes=\"\""
"\n AssemblySearchPath=\"\""
"\n ForcedUsingAssemblies=\"\""
"\n CompileAsManaged=\"\""
"\n />"
"\n </Configuration>"
"\n </Configurations>"
"\n <References>"
"\n </References>"
"\n <Files>"
"\n ", proj, proj, proj, proj, proj);
fprintf(g_pFile, szOut);
delete [] szOut;
g_packsDir = argv[1];
g_packsDirLen = strlen(g_packsDir);
Build(g_packsDir, "");
fprintf(g_pFile, "%s",
"\n </Files>"
"\n <Globals>"
"\n </Globals>"
"\n</VisualStudioProject>"
);
fclose(g_pFile);
printf("created VS Project successfully!\n");
getchar();
return 0;
}
1条评论
在选取文件类型时,仅仅只是排除了obj类型的文件。感觉最好是限定哪些文件加入到工程,而不是排除obj文件。
if (len < 4 || _strcmpi(FindFileData.cFileName + len – 4, ".obj") != 0)