Windows CE如何根据文件名获取其对应文件图标icon

本文解析了Windows CE 5.0系统中文件图标管理机制。详细介绍了如何根据文件名获取图标,包括EXE文件、关联到其他EXE文件的文件类型及系统shell中的图标。通过对系统源码分析,揭示了图标获取的具体流程。

Windows CE如何根据文件名获取其对应文件图标icon

1、背景介绍

如果把一文件copyWindows CE5.0系统的U盘(或者桌面等目录)中,那么这个文件就会有其对应的图标显示,如下图。那么Windows CE5.0文件系统是如何管理文件和其对应图标的呢?

2、文件图标简介

WCE5.0系统中,你能看到的图标都有其对应的图标资源,问题就在于这些图标在哪里,而WCE系统又是如何管理的呢?说到底,文件图标资源存在于两种形式——exe文件和dll文件中。

EXE文件图标

每个exe文件都有其对应的文件图标,可以通过函数ExtractIconEx来获取exe文件中图标。

dll文件中的图标

许多dll中都包含有图标资源,可以通过ExtractIconExLoadImage来获取dll中的图标(要知道图标ID)。

3Windows CE源码分析

有关这部分源码在:$:/WINCE500/PUBLIC/SHELL/OAK/HPC/CESHELL/API/iconcache.cpp文件中,其实就涉及到一个函数:

CIconCache::CacheInfo * CIconCache::CacheItem(LPCWSTR pszFilePath)

       理解了这个函数,也就理解了本课题。首先输入参数仅仅是一个文件的完整路径,也就是说WCE只要根据一文件名就可以得到其对应文件类型图标。如图3-1紧接着ASSERT(!PathIsDirectory(pszFilePath))确保输入参数不是路径。PathIsGUID判断文件名是不是GUID,不是GUID就是系统文件了(// It's a file system file)。

 

图

 

3-1 CacheItem函数

       PathIsExe函数判断文件是否为exe文件,是就用ExtractIconEx获取其图标。不是exe文件继续往下走,用PathFindExtension获取文件后缀名。根据后缀名到注册表去查找文件类型——// TYPE: Figure out the type information,再根据后缀去查找图标——// ICON: Get the requested icons

这里注册表会包含后缀名的一些信息。举个例子,比如*.bmp文件,先查找注册表[HKEY_CLASSES_ROOT/.bmp],于是你可以看到如图3-2所示的画面,其中Default项的值为bmpimage,那么在注册表[HKEY_CLASSES_ROOT/bmpimage/DefaultIcon]会看到如下信息,说明bmp文件图标就是imageviewer.exe的图标。再看看dll文件的信息[HKEY_CLASSES_ROOT/dllfile/DefaultIcon],如图3-4,说明*.dll文件的图标是ceshell.dllID4608的图标。

 

图

 

3-2

图

 

3-3

图

 

3-4

4、总结

       WCE文件系统根据文件名,通过注册表管理其对应的文件图标。总结有三种情况:

*.exe文件

Exe文件最简单,直接通过ExtractIconEx获取文件图标。

简介exe文件,如*.bmp

*.bmp文件虽然不是exe文件,但在注册表中会将*.bmp文件关联到imageviewer.exe,再通过ExtractIconEx获取imageviewer.exe图标作为*.bmp文件图标。

WCE系统SHELL中的图标

*.dll文件,在注册表中关联的并不是exe文件,那么这样情况,是由ceshell.dll中的图标来作为*.dll的文件图标。

 

 

下面的代码没有把“免费用于非商业用途”的IDE的下载链接也获取,我需要也获取(需要将更新整合整套代码):import requests import json def get_jetbrains_versions(): """获取社区版产品列表(包含全名和图标URL)""" products_url = "https://data.services.jetbrains.com/products" headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'} # 产品代码到图标标识的映射 icon_identifier_map = { 'IIC': 'idea', # IntelliJ IDEA Community 'PCP': 'pycharm', # PyCharm Community 'RM': 'ruby', # RubyMine Community 'AI': 'androidstudio', # Android Studio(虽然不是Community命名,但免费) # 添加其他社区版产品的映射... } try: response = requests.get(products_url, headers=headers) products = response.json() community_products = [] for p in products: name = p.get('name', '').lower() code = p['code'] # 过滤条件:包括社区版、CE版和Android Studio if 'community' in name or 'ce' in name or name == 'android studio': # 获取产品图标标识,如果映射中存在则使用,否则使用产品代码的小写 identifier = icon_identifier_map.get(code, code.lower()) # 构建图标URL icon_url = f"https://resources.jetbrains.com/storage/products/{identifier}/img/{identifier}_logo.svg" community_products.append({ 'code': code, 'name': p['name'], 'icon': icon_url }) return community_products except Exception as e: print(f"获取产品列表失败: {str(e)}") return [] def get_download_links(product_info): """获取产品下载链接(包含图标URL)""" product_code = product_info['code'] product_name = product_info['name'] product_icon = product_info['icon'] # 获取产品图标 api_url = f"https://data.services.jetbrains.com/products/releases?code={product_code}&type=release" headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'} try: response = requests.get(api_url, headers=headers) data = response.json() product_data = data.get(product_code, []) results = [] for release in product_data: version = release.get('version', 'unknown') downloads = release.get('downloads', {}) for platform, download_info in downloads.items(): if download_info.get('name', '') in ['zip', 'tar.gz']: continue if 'link' in download_info: results.append({ 'product': product_name, 'code': product_code, 'icon': product_icon, # 添加产品图标URL 'version': version, 'platform': platform, 'size': download_info.get('size', ''), 'checksum': download_info.get('checksumLink', ''), 'download_link': download_info['link'], 'release_date': release.get('date', '') }) return results except Exception as e: print(f"获取{product_name}下载链接失败: {str(e)}") return [] if __name__ == "__main__": print("开始爬取JetBrains社区版下载链接及图标...") community_products = get_jetbrains_versions() print(f"找到 {len(community_products)} 个社区版产品") all_downloads = [] for product_info in community_products: print(f"正在处理 {product_info['name']} ({product_info['code']})...") downloads = get_download_links(product_info) print(f" 找到 {len(downloads)} 个下载项") all_downloads.extend(downloads) # 保存包含图标URL的JSON with open('jetbrains_downloads_with_icons.json', 'w', encoding='utf-8') as f: json.dump(all_downloads, f, indent=2, ensure_ascii=False) print(f"爬取完成! 共获取 {len(all_downloads)} 个下载链接") print("结果已保存到 jetbrains_downloads_with_icons.json")
最新发布
09-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值