Пример #1
0
void CppCheckPlugin::OnCheckFileExplorerItem(wxCommandEvent& e)
{
    if ( m_cppcheckProcess ) {
        wxLogMessage(_("CppCheckPlugin: CppCheck is currently busy please wait for it to complete the current check"));
        return;
    }

    TreeItemInfo item = m_mgr->GetSelectedTreeItemInfo(TreeFileExplorer);
    for(size_t i=0; i<item.m_paths.GetCount(); ++i) {
        if ( wxDir::Exists(item.m_paths.Item(i)) ) {
            // directory
            GetFileListFromDir( item.m_paths.Item(i) );
        } else {
            // filename
            m_filelist.Add( item.m_paths.Item(i) );
        }
    }
    DoStartTest();
}
Пример #2
0
void GetFileListFromDir(const char* pszDir, std::vector<std::string>& setFilelist)
{
	_finddata_t filestruct;
	int p = 0;
	int fn = 0;
	char szSearch[255];
	if (strlen(pszDir) == 0)
	{
		strcpy(szSearch , "*.*");
	}
	else
	{
		strcpy(szSearch , pszDir);
		strcat(szSearch , "/*.*");
	}

	int hnd = _findfirst(szSearch , &filestruct);
	if(hnd == -1) 
	{
		return;
	}
	do
	{
		char szFullName[MAX_PATH] = "";
		if (strlen(pszDir) > 0)
		{
			sprintf(szFullName , "%s/%s" , pszDir , filestruct.name);		
		}
		else
		{
			strcpy(szFullName , filestruct.name);
		}
		if (!(filestruct.attrib & _A_HIDDEN)) // ignore hidden
		{
			if (!(filestruct.attrib & _A_SUBDIR)) 
			{
				// Process the file name
				char szFileCopy[512];
				strcpy(szFileCopy, szFullName);
				strlwr(szFileCopy);
				unsigned long uFileNameLength = strlen(szFileCopy);
				for(size_t i = 0; i < uFileNameLength; ++i)
				{
					if(szFileCopy[i] == '/')
					{
						szFileCopy[i] = '\\';
					}
				}
				if (szFileCopy[uFileNameLength-1]!='e'||
					szFileCopy[uFileNameLength-2]!='x'||
					szFileCopy[uFileNameLength-3]!='e'||
					szFileCopy[uFileNameLength-4]!='.')
				{
					setFilelist.push_back(szFileCopy);
				}
			}
			else // Directory
			{
				if (strcmp(filestruct.name , "..") != 0 && strcmp(filestruct.name, ".") != 0)
				{
					GetFileListFromDir(szFullName,setFilelist);
				}
			}
		}
	}while(!_findnext(hnd , &filestruct)); 
}
Пример #3
0
int _tmain(int argc, _TCHAR* argv[])
{
	//
	//char   szModuleFile[MAX_PATH]   ;    
	//GetModuleFileNameA(NULL, szModuleFile, MAX_PATH);  

	// get file list from dir
	std::vector<std::string> setFilelist;
	GetFileListFromDir("",setFilelist);

	std::cout<<"File count: "<<setFilelist.size()<<std::endl;
	// get the save filename
	char szPakFilename[128];
	GetCurrentDirectoryA(128, szPakFilename);
	if (strlen(szPakFilename) != 0)
	{
		strcat(szPakFilename , ".pak");
	}
	std::cout<<"The pak filename: "<<szPakFilename<<std::endl;

	// open or create pak
	FILE* f=fopen(szPakFilename, "wb");
	if(!f)
	{
		return false;
	}

	// Head
	char szFileHeader[32]="DawnPack.TqDigital";
	fwrite(szFileHeader, sizeof(char), 32, f);

	// Version
	unsigned long uVersion = 1000;
	fwrite(&uVersion, sizeof(unsigned long), 1, f);

	// count
	unsigned long uFileCount = setFilelist.size();
	fwrite(&uFileCount, sizeof(unsigned long), 1, f);

	// get offset
	unsigned long uFileListOffset = ftell(f);
	const unsigned long uFileDataStart = ftell(f)+setFilelist.size()*FILE_INFO_SIZE;
	unsigned long uFileDataOffset = uFileDataStart;

	// vector
	int nCount = 0;
	for (std::vector<std::string>::iterator it=setFilelist.begin();it!=setFilelist.end();it++)
	{
		nCount++;
		std::cout<<"packing "<<nCount<<"/"<<uFileCount<<": "<<it->c_str()<<std::endl;
		// check the filelist is ok
		if (uFileListOffset+FILE_INFO_SIZE>uFileDataStart)
		{
			std::cout<<"error: Out of file list range. Address: "<<uFileListOffset<<std::endl;
			break;
		}
		//
		unsigned long uFileSize = 0;
		// push back the file data to "*.pak"
		{
			FILE* fFile = fopen(it->c_str(),"rb");
			if (!fFile)
			{
				std::cout<<"warning: This file can be read."<<std::endl;
				continue;
			}
			{
				fseek(fFile, 0, SEEK_END);
				uFileSize = ftell(fFile);
				fseek(fFile, 0, SEEK_SET);
			}
			if (uFileSize>0)
			{
				char* buffer = new char[uFileSize];
				fread(buffer,uFileSize,1,fFile);
				// write data to pak
				fseek(f,uFileDataOffset,SEEK_SET);
				fwrite(buffer,uFileSize,1,f);
				delete buffer;
			}
			fclose(fFile);
		}
		// write file info to FileList
		fseek(f, uFileListOffset, SEEK_SET);
		unsigned long id = GeneratePakFileID(it->c_str());
		{
			fwrite(&id,sizeof(unsigned long),1,f);
			fwrite(&uFileSize,sizeof(unsigned long),1,f);
			fwrite(&uFileDataOffset, sizeof(unsigned long), 1, f);
		}
		// offset
		uFileListOffset+=FILE_INFO_SIZE;
		uFileDataOffset+=uFileSize;
	}
	fclose(f);
	std::cout<<"Completed."<<std::endl;

	system("pause");   

	//getch();
	return 0;
}