예제 #1
0
파일: icon.c 프로젝트: jsoref/rufus
/*
 * Create an autorun.inf, if none exists
 * We use this to set the icon as well as labels that are longer than 11/32 chars or,
 * in the case of FAT, contain non-English characters
 */
BOOL SetAutorun(const char* path)
{
	FILE* fd;
	char filename[64];
	wchar_t wlabel[128], wRufusVersion[32];

	safe_sprintf(filename, sizeof(filename), "%s\\autorun.inf", path);
	fd = fopen(filename, "r");	// If there's an existing autorun, don't overwrite
	if (fd != NULL) {
		uprintf("%s already exists - keeping it\n", filename);
		fclose(fd);
		return FALSE;
	}
	// No "/autorun.inf" => create a new one in UTF-16 LE mode
	fd = fopen(filename, "w, ccs=UTF-16LE");
	if (fd == NULL) {
		uprintf("Unable to create %s\n", filename);
		return FALSE;
	}

	GetWindowTextW(hLabel, wlabel, ARRAYSIZE(wlabel));
	GetWindowTextW(hMainDialog, wRufusVersion, ARRAYSIZE(wRufusVersion));
	fwprintf(fd, L"; Created by %s\n; " LTEXT(RUFUS_URL) L"\n", wRufusVersion);
	fwprintf(fd, L"[autorun]\nicon  = autorun.ico\nlabel = %s\n", wlabel);
	fclose(fd);
	uprintf("Created: %s\n", filename);

	// .inf -> .ico
	filename[strlen(filename)-1] = 'o';
	filename[strlen(filename)-2] = 'c';
	return SaveIcon(filename);
}
예제 #2
0
	const char*	FerryRegionSymbolImpl::GetIcon()
	{
		char icon_path[AUGE_PATH_MAX];
		memset(icon_path, 0, AUGE_PATH_MAX);
		auge_make_symbol_icon_path(m_icon_name.c_str(), icon_path, AUGE_PATH_MAX);

		if(g_access(icon_path,4))
		{
			DrawIcon();
			SaveIcon(icon_path);
		}
		return m_icon_name.c_str();
	}
예제 #3
0
bool ExtractExeDllIcon(LPCTSTR strExeFile,LPCTSTR strSaveDir,bool bExtractLarge = false ,UINT iIndexICon = 0)
{
	HICON hIconArry[1]={0};
	UINT iSuccessCount = 0;
	if (bExtractLarge)
		iSuccessCount = ExtractIconEx(strExeFile,iIndexICon,hIconArry,NULL,1);
	else
		iSuccessCount = ExtractIconEx(strExeFile,iIndexICon,NULL,hIconArry,1);

	if (iSuccessCount!=1)
	{
		ZTools::WriteZToolsFormatLog("从文件【%s】中获取索引为【%d】的图标失败!",strExeFile,iIndexICon);
		return false;
	}

	string strName  = GetFileNameNoExt(strExeFile);

	string strPngFile  = string(strSaveDir) + "\\" + strName + ".png";
	string strIconFile = string(strSaveDir) + "\\" + strName + ".ico";

	BOOL bok1  = SavePngFile(hIconArry[0],strPngFile.c_str());
	if (!bok1)
	{
		ZTools::WriteZToolsFormatLog("保存png文件【%s】失败!",strPngFile.c_str());
	}
	BOOL bok2  =  SaveIcon(hIconArry[0],strIconFile.c_str(),32);
	if (!bok2)
	{
		ZTools::WriteZToolsFormatLog("保存icon文件【%s】失败!",strIconFile.c_str());
	}

	DestroyIcon(hIconArry[0]);
	if (bok1 && bok2)
		return true;

	return false;
}
예제 #4
0
bool GetTypeIconToFile(const char * pszExt,const char * pszOutDir,bool bLargeIcon = true)
{
	static HRESULT hr = S_FALSE;
	if (hr!=S_OK)
	{
		hr =  CoInitialize(NULL); //如果不初始化COM,那么调用该函数就无法得到.htm/.mht/.xml文件的图标。
	}


	if (pszExt==NULL && pszOutDir==NULL)
		return false;

	if (strlen(pszExt) < 2  || pszExt[0] !='.')
		return false;

	char szExt[30] ={0};
	strcpy_s(szExt,pszExt+1);

	string strDir = string(pszOutDir) + "\\" + szExt  + "\\";
	if (!MakeSureDirectoryPathExists(strDir.c_str()))
		return false;

	string strIconFile = strDir + szExt + ".ico";
	string strPngFile = strDir + szExt  + ".png";

	if(PathFileExists(strIconFile.c_str()))
		remove(strIconFile.c_str());

	if(PathFileExists(strPngFile.c_str()))
		remove(strPngFile.c_str());

	string sDummyFileName = string("foo.") + szExt;

	SHFILEINFO shfi;
	memset(&shfi,0,sizeof(shfi));

	UINT uFlags = SHGFI_ICON|SHGFI_USEFILEATTRIBUTES;
	if (bLargeIcon)
		uFlags|=SHGFI_LARGEICON; 
	else
		uFlags|=SHGFI_SMALLICON; 

	SHGetFileInfo(sDummyFileName.c_str(),FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(shfi),uFlags);

	BOOL bok1  = SavePngFile(shfi.hIcon,strPngFile.c_str());
	if (!bok1)
	{
		ZTools::WriteZToolsFormatLog("保存png文件【%s】失败!",strPngFile.c_str());
	}
	BOOL bok2  =  SaveIcon(shfi.hIcon,strIconFile.c_str(),32);
	if (!bok2)
	{
		ZTools::WriteZToolsFormatLog("保存icon文件【%s】失败!",strIconFile.c_str());
	}

	DestroyIcon(shfi.hIcon);
	if (bok1 && bok2)
		return true;

	return false;
}