2 using System.Diagnostics;
3 using System.Diagnostics.Contracts;
6 using System.ComponentModel.Composition;
7 using Pithos.Interfaces;
9 namespace Pithos.ShellExtensions.Overlays
12 public class IconOverlayBase : IShellIconOverlayIdentifier
14 protected static string PithosPrefix = "0Pithos";
16 public string OverlayName { get; private set; }
17 public string IconPath { get; private set; }
19 [Import(typeof (IStatusChecker))]
20 public IStatusChecker StatusChecker;
21 [Import(typeof (IPithosSettings))]
22 public IPithosSettings Settings;
26 public IconOverlayBase(string iconName)
28 Trace.Write("Icon Overlay Instance created");
29 IoC.Current.Compose(this);
32 string overlayName=PithosPrefix + iconName;
33 string iconFile = iconName + "Icon.ico";
36 var iconsFolder = Settings.IconsPath;
37 var fullPath = Path.Combine(iconsFolder, iconFile);
39 OverlayName = overlayName;
46 public int IsMemberOf(string path, uint attributes)
48 if (String.IsNullOrWhiteSpace(path))
49 throw new ArgumentNullException("Empty path");
51 Trace.Write(String.Format("ICON Status check for {0} - {1}",path,GetType().Name));
53 if (!path.StartsWith(Settings.PithosPath,true,null))
54 return WinError.S_FALSE;
56 var status=StatusChecker.GetFileOverlayStatus(path);
57 var isMember = (PithosPrefix + status == OverlayName);
58 Trace.Write(String.Format("Status check for {0} is {1}",path,isMember));
59 return isMember ? WinError.S_OK : WinError.S_FALSE;
62 public int GetOverlayInfo(
63 IntPtr iconFileBuffer,
64 int iconFileBufferSize,
68 Trace.Write("Looking for icons");
70 Trace.WriteLine(string.Format("ICON file {0}", IconPath));
72 int bytesCount = System.Text.Encoding.Unicode.GetByteCount(IconPath);
74 Trace.WriteLine(string.Format(" GetOverlayInfo::{0}",bytesCount));
76 MarshalHelpers.CopyToBuffer(IconPath, iconFileBuffer, iconFileBufferSize);
78 flags = (uint)(ISIOI.ISIOI_ICONFILE);// | ISIOI.ISIOI_ICONINDEX);
83 public int GetPriority(out int priority)
85 Trace.Write("Checking for priority");
91 public static void RegisterOverlay(Type t,string iconName)
96 ShellExtReg.RegisterIconOverlayIdentifier(t.GUID, iconName);
98 NativeMethods.SHChangeNotify(HChangeNotifyEventID.SHCNE_ASSOCCHANGED, HChangeNotifyFlags.SHCNF_IDLIST,
99 IntPtr.Zero, IntPtr.Zero);
100 Trace.Write("Registered icon handler");
104 Trace.WriteLine(ex.Message); // Log the error
105 throw; // Re-throw the exception
110 public static void UnregisterOverlay(Type t,string iconName)
114 ShellExtReg.UnregisterIconOverlayIdentifier(t.GUID, iconName);
115 Trace.Write("UnRegistered icon handler");
119 Trace.WriteLine(ex.Message); // Log the error
120 throw; // Re-throw the exception