Custom folder icons with desktop.ini & instant ref

2019-07-29 22:24发布

问题:

I am tasked with creating a book-keeping program that tracks some statistics of when files and folders are read. Similar to Google Drive and TortoiseSVN, the folder and file icons should reflect certain changes. For instance, a USB with files that haven't been viewed on a certain computer have an 'x', whereas viewed files get a 'o'.

I can track file usage with this Windows API, and icons (as well as some other nice options) can be changed by the desktop.ini files [1,2,3,4].

While manually messing around with desktop.ini files, I've successfully changed icons, descriptions, and other fun stuff. The problem is that the new changes don't update until Windows parses the desktop.ini file again. This tends to happen inconsistently between a few seconds to several minutes. F5 refreshes do not force a reparse, but will update the image if a reparse has occurred.

How do I force Windows to reparse desktop.ini files both manually and (more importantly) in a C++ program?

Is there an alternative C++ Windows API that can change folder icons immidiately?

回答1:

If you edit desktop.ini, it Explorer won't refresh automatically. Use SHGetSetFolderCustomSettings to write to it:

SHFOLDERCUSTOMSETTINGS fcs = {0};
fcs.dwSize = sizeof(SHFOLDERCUSTOMSETTINGS);
fcs.dwMask = FCSM_ICONFILE;
fcs.pszIconFile = iconPath;
fcs.cchIconFile = 0;
fcs.iIconIndex = iconIndex;
SHGetSetFolderCustomSettings(&fcs, folderPath, FCS_FORCEWRITE);


回答2:

If you wish to have different folder icons to indicate different states distinctively (similar to SVN) then you need icon overlays. Changing folder icons is not the suitable solution. The changes in folder icons will reflect instantaneously If you need further details, Please let me know.