This project is read-only.

How to transition easy

Mar 5, 2014 at 3:48 PM
Can you give us some direction how to transition easy to AlphaFS?

I thought it has more sense to user AphpaFS for everything instead of checking path every time so I use
using Alphaleonis.Win32.Filesystem;
using Alphaleonis.Win32.Security;
using Directory = Alphaleonis.Win32.Filesystem.Directory;
using DirectoryInfo = Alphaleonis.Win32.Filesystem.DirectoryInfo;
using DriveInfo = Alphaleonis.Win32.Filesystem.DriveInfo;
using File = Alphaleonis.Win32.Filesystem.File;
using FileSystemInfo = Alphaleonis.Win32.Filesystem.FileSystemInfo;
using Path = Alphaleonis.Win32.Filesystem.Path;
using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo;
using FileAccess = Alphaleonis.Win32.Filesystem.FileAccess;
using FileAttributes = Alphaleonis.Win32.Filesystem.FileAttributes;
using FileMode = Alphaleonis.Win32.Filesystem.FileMode;
The last 3 do not exist when using dll from alphafs-107068
and if I use
AlphaFS-1.5-BinAndDocs, then there is no
using DriveInfo = Alphaleonis.Win32.Filesystem.DriveInfo;
or Directory.EnumerateDirectories(path)

Mar 5, 2014 at 5:00 PM

That is the correct and easier way to use AlphaFS.
Currently only the development build has the DriveInfo() class and the .NET 4 EnumXxx methods.

For FileAccess, FileAttributes and FileMode you should use the System.IO implementations.

Marked as answer by Yomodo on 3/7/2014 at 12:21 AM
Mar 5, 2014 at 9:09 PM
Edited Mar 5, 2014 at 9:10 PM
This is too easy!!! Thank you very much for this amazing project.

I managed to switch everything within 20 minutes and the only thing I am missing is support for FileSystemWatcher and ability to get icon fast.

I see mentioning of SHGetFileInfo but I was not able to find how to call this with AlphaFS
IntPtr hImgSmall = Win32.SHGetFileInfo(fileName, FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo), (uint)(SHGFI.ICON | SHGFI.SMALLICON | SHGFI.USEFILEATTRIBUTES | SHGFI_TYPENAME));           
Icon icon = (Icon)System.Drawing.Icon.FromHandle(shinfo.hIcon).Clone();
Mar 5, 2014 at 10:10 PM
Edited Mar 6, 2014 at 3:46 PM

You might also want to add this: using Alphaleonis.Win32.Network; for some networking functions.
FileSystemWatcher... perhaps somewhere in the near future.

To retrieve icons use method: Shell32.GetFileInformation()

Try this:
using (Icon icon = GetShellStockIcon(fullPath, Shell32.FileInfoAttributes.SmallIcon))

private static Icon GetShellStockIcon(string path, Shell32.FileInfoAttributes size)
  if (string.IsNullOrWhiteSpace(path))
      return null;

  Shell32.FileInfo shInfo = Shell32.GetFileInformation(path, FileAttributes.Normal, size | Shell32.FileInfoAttributes.Icon | Shell32.FileInfoAttributes.AddOverlays, true);

  return (Icon) (shInfo.IconHandle != IntPtr.Zero ? Icon.FromHandle(shInfo.IconHandle).Clone() : null);
Mar 6, 2014 at 4:18 PM
Thanks! I will see if I need something from Network in current project.

I tried your code and got errors on shInfo.IconHandle:
'Alphaleonis.Win32.Filesystem.Shell32.FileInfoAttributes' is inaccessible due to its protection level

'Alphaleonis.Win32.Filesystem.Shell32.FileInfo.IconHandle' is inaccessible due to its protection level  

Inconsistent accessibility: parameter type 'Alphaleonis.Win32.Filesystem.Shell32.FileInfoAttributes' is less accessible than method 'myproject.cIcon.GetShellStockIcon(string, Alphaleonis.Win32.Filesystem.Shell32.FileInfoAttributes)'    
Mar 6, 2014 at 7:02 PM
My bad; should've seen that one coming.

I've just checked-in an update, could you try again?

Mar 6, 2014 at 8:31 PM
Edited Mar 6, 2014 at 8:31 PM
I updated and just replaced FileInfoAttributes from your code to FileAttributes and now it works great! Thanks!

I also added DestroyIcon(shInfo.IconHandle); after .clone() and I think I should add Lock since SHGetFileInfo is not threadsafe.