A small tool for cleaning vs engineering

Source: Internet
Author: User
Tags svn

VS Project After compiling will produce a large number of temporary files, this small program is clean vs project residue files, can quickly clean up the VS project, if there are subfolders recursively clean, the program use multithreading high efficiency.

* * * filename:main.cpp * AUTHOR:LOUGD * created:2014-12-26 10:25 * version:1.0.0.1 * * Desc:clea 
R vs Project * Version: * History: * * #include <Windows.h> #include <stdio.h> #include <set> #include <list> #include <string> #include <Shlwapi.h> #pragma comment (lib, "Shlwapi.lib") using name

Space Std;
size_t g_busy_count = 0;
Set<string> g_exts;
Set<string> G_dirs;
List<string> g_dir_list;
HANDLE g_dir_lock = Createmutexa (null, FALSE, NULL);
HANDLE g_work = Createeventa (null, FALSE, FALSE, NULL);

HANDLE g_exit = Createeventa (null, TRUE, FALSE, NULL);

VOID WINAPI Lock () {WaitForSingleObject (G_dir_lock, INFINITE);}

VOID WINAPI UnLock () {ReleaseMutex (g_dir_lock);}
	VOID WINAPI Deletedirwithfile (const char *dir) {list<string> files;
	List<string> dirs;
	WIN32_FIND_DATAA data;
	Char tmp[512] = {0x00};
	Char path[512] = {0x00};
	int mark = Lstrlena (dir);
	Lstrcata (tmp, dir); LsTrcata (Path, dir);

	Pathappenda (Path, "*");
	HANDLE h = Findfirstfilea (path, &data); if (!h | |
	Invalid_handle_value = = h) {return; Do {if (0 = Lstrcmpa (".", Data.cfilename) | | 0 = LSTRCMPA ("...", data.cfilename) | | 0 = = Lstrlena (data.cfilename) ) {if (!
			Findnextfilea (H, &data)) {break;
		} continue;
		} pathappenda (TMP, data.cfilename);
		if (Pathisdirectorya (TMP)) {dirs.push_back (TMP);
		else {files.push_back (TMP);
	} Tmp[mark] = 0x00;

	while (Findnextfilea (h, &data));
	if (H && invalid_handle_value!= h) {findclose (h);
	} List<string>::iterator itm;
	for (itm = Dirs.begin (); itm!= dirs.end (); itm++) {Deletedirwithfile (Itm->c_str ());
	for (itm = Files.begin (); itm!= files.end (); itm++) {DeleteFileA (Itm->c_str ());
} Removedirectorya (dir);
	} VOID WINAPI Recursioncleardir (const char *dir) {list<string> files;
	List<string> dirs;
	WIN32_FIND_DATAA data; Char TMP[512] = {0x00};
	Char path[512] = {0x00};
	int mark = Lstrlena (dir);
	Lstrcata (tmp, dir);
	Lstrcata (Path, dir);

	Pathappenda (Path, "*");
	HANDLE h = Findfirstfilea (path, &data); if (!h | |
	Invalid_handle_value = = h) {return; Do {if (0 = Lstrcmpa (".", Data.cfilename) | | 0 = LSTRCMPA ("...", data.cfilename) | | 0 = = Lstrlena (data.cfilename) ) {if (!
			Findnextfilea (H, &data)) {break;
		} continue;
		} pathappenda (TMP, data.cfilename);
			if (Pathisdirectorya (TMP)) {if (G_dirs.end ()!= g_dirs.find (data.cfilename)) {dirs.push_back (TMP);
			Lock ();
			G_dir_list.push_back (String (TMP));
			UnLock ();
		SetEvent (g_work);
			else {if (G_exts.end ()!= g_exts.find (Pathfindextensiona (tmp)) {files.push_back (TMP);
	}} Tmp[mark] = 0x00;

	while (Findnextfilea (h, &data));
	List<string>::iterator ITM;
	for (itm = Dirs.begin (); itm!= dirs.end (); itm++) {Deletedirwithfile (Itm->c_str ()); for (itm = Files.begin (); ITM!= files.end ();
	itm++) {DeleteFileA (Itm->c_str ());
	} if (H && invalid_handle_value!= h) {findclose (h);
	} DWORD winapi ProcessThread (lpvoid param) {HANDLE arry[] = {g_work, g_exit};
		while (TRUE) {DWORD ret = waitformultipleobjects (sizeof (Arry)/sizeof (HANDLE), Arry, FALSE, INFINITE);
			if (wait_object_0 = = ret) {string path;
			Lock ();
			g_busy_count++;
			
			UnLock ();
				while (TRUE) {Lock ();
				int count = G_dir_list.size ();
					if (count <= 0) {UnLock ();
				Break
				Path = G_dir_list.front ();
				G_dir_list.pop_front ();
				UnLock ();
			Recursioncleardir (Path.c_str ());
			Lock ();
			g_busy_count--;
			if (0 = = G_busy_count && 0 = g_dir_list.size ()) {setevent (g_exit);
		} UnLock ();
		} if ((Wait_object_0 + 1) = ret) {break;
} return 0;
	} VOID WINAPI Getfiletype () {G_exts.insert (". NCB");
	G_exts.insert (". suo");
	G_exts.insert (". Exp"); G_exts.Insert (". pdb");
	G_exts.insert (". Ilk");
	G_exts.insert (". User");
	G_exts.insert (". APs");
	G_exts.insert (". obj");
	G_exts.insert (". IDB");
	G_exts.insert (". Dep");
	G_exts.insert (". SBR");
	G_exts.insert (". tmp");
	G_exts.insert (". TLH");
	G_exts.insert (". Tli");
	G_exts.insert (". TLog");
	G_exts.insert (". Log");
	G_exts.insert (". htm");
	G_exts.insert (". CLW");
	G_exts.insert (". DSP");
	G_exts.insert (". opt");
	G_exts.insert (". sdf");
	G_exts.insert (". Filters");
	G_exts.insert (". PLG");
	G_exts.insert (". positions");

	G_exts.insert (". Svn-base");
	G_dirs.insert (". SVN");
G_dirs.insert ("Debug");
	int main (int argc, char *argv[]) {if (ARGC < 2) {printf ("param error\n");
		} if (0 = = Lstrcmpia (argv[1], "/C")) {string path = argv[2];
		System_info system = {0};
		GetSystemInfo (&system);
		int cpu = system.dwnumberofprocessors;
		G_dir_list.push_back (Path.c_str ());
		SetEvent (g_work);
		
		Getfiletype ();
		int itm;
		HANDLE *ws = new HANDLE[CPU + 2]; for (itm = 0; itm < (CPU + 2) ;
		itm++) {Ws[itm] = CreateThread (null, 0, processthread, 0, 0, NULL);
		} waitformultipleobjects (CPU + 2, WS, TRUE, INFINITE);
	delete []ws;
return 0; }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.