VSoft/Source/VSoft_Dll/Prams/API.cs
如果当时 17cafdc685 ### 2021-03-07更新
------
#### VSoft    V1.0.2103.0701
- *.[新增]当拖放的文件是快捷方式时,支持获取备注信息。
- *.[修复]修复内置命令编辑状态时,拖放会导致文件添加到主界面的BUG。
- *.[修复]修复内置命令拖放文件时,在添加界面会保持拖放状态的BUG。
2021-03-08 09:05:27 +08:00

82 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.Win32;
using ryCommon;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace VSoft.Prams
{
public static class API
{
// 关闭64位文件系统的操作转向
[DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int Wow64DisableWow64FsRedirection(ref IntPtr ptr);
// 开启64位文件系统的操作转向
[DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
public static Image GetImg(string url)
{
return GetImg(url, 128);
}
public static Image GetImg(string url,int maxSize)
{
var ext = System.IO.Path.GetExtension(url).ToLower();
var img_ext = ";.jpg;.png;.bmp;.gif;.jpeg;.jfif;.jpe;.tif;.ico;";
if (img_ext.IndexOfEx(";" + ext + ";") >= 0)
{
return RyFiles.LoadPicFromFile(url);
}
else
{
var exe_ext = ";.exe;.dll;";
if (exe_ext.IndexOfEx(";" + ext + ";") >= 0)
{
var img= RyFiles.GetFileIcon(url, 0, out _, maxSize);
if (img == null)
{
var icon = ShellIcon.GetLargeIcon(url);
return icon;
}
return img;
}
//FileIcon ico = new FileIcon(url);
//ico.GetInfo();
//var icon2 = ico.ShellIcon;
var icon2 = ShellIcon.GetLargeIcon(url);
return icon2;
}
}
/// <summary>
/// 读取一个快捷方式的信息
/// </summary>
/// <param name="lnkFilePath"></param>
/// <returns></returns>
public static ShortcutDescription ReadShortcut(string lnkFilePath)
{
var shellType = Type.GetTypeFromProgID("WScript.Shell");
dynamic shell = Activator.CreateInstance(shellType);
var shortcut = shell.CreateShortcut(lnkFilePath);
string TargetPath = shortcut.TargetPath;
if (TargetPath.StartsWith("C:\\Program Files (x86)", StringComparison.OrdinalIgnoreCase))
{
if (!System.IO.File.Exists(TargetPath) && !System.IO.Directory.Exists(TargetPath))
{
TargetPath = TargetPath.Replace("C:\\Program Files (x86)\\", "C:\\Program Files\\");
}
}
return new ShortcutDescription()
{
TargetPath = TargetPath,
Arguments = shortcut.Arguments,
WorkDir = shortcut.WorkingDirectory,
IconLocation= shortcut.IconLocation,
Description = shortcut.Description
};
}
}
}