Skip to content

Instantly share code, notes, and snippets.

@judge2020
Last active January 20, 2017 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save judge2020/80b18fee49f979cdb5f8b5a52f0d5d08 to your computer and use it in GitHub Desktop.
Save judge2020/80b18fee49f979cdb5f8b5a52f0d5d08 to your computer and use it in GitHub Desktop.
unblock file
public class FileUnblocker {
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteFile(string name );
public bool Unblock(string fileName) {
return DeleteFile(fileName+ ":Zone.Identifier");
}
}
; HDT code
foreach(var file in PluginDir) {
FileUnblocker.Unblock(file.FullPath);
}
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DeleteFile(string name);
public static void UnblockPath(string path)
{
string[] files = System.IO.Directory.GetFiles(path);
string[] dirs = System.IO.Directory.GetDirectories(path);
foreach (string file in files)
{
UnblockFile(file);
}
foreach (string dir in dirs)
{
UnblockPath(dir);
}
}
public static bool UnblockFile(string fileName)
{
return DeleteFile(fileName + ":Zone.Identifier");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment