VSoft/Source/VSoft_Dll/Prams/API.cs
紫林公司 6f72e8e105 ### 2024-12-10更新
------
#### VSoft    V2.0.2412.1001
- *.[新增]拖放文件到主界面,支持直接插入到拖放的位置。
- *.[新增]新增支持设置运行次数的功能,可以快速进行多开。
- *.[新增]支持保存大小和选中的栏目和分类位置。
- *.[改进]切换栏目会记录列表滚动条位置和选中的分类。
- *.[改进]编辑添加的内置功能,将不允许修改路径。
- *.[改进]读取快捷方式时,支持自动获取图标信息。
- *.[改进]新增软件完成后,不再刷新列表,而是直接添加到列表末尾。
- *.[改进]新增软件或拖放软件后,界面直接定位到添加的列表位置。
- *.[改进]点击显示主界面时,如果存在模式窗体,则将模式窗体显示在前面。
- *.[改进]当百度翻译出错时自动重试翻译。
- *.[修复]栏目和分类进行拖放操作时,拖放出控件会残留拖放标志的BUG。
2024-12-10 16:56:35 +08:00

95 lines
3.5 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\\");
}
}
string IconLocation = shortcut.IconLocation;
var iPos = IconLocation.LastIndexOf(",");
var IconIndex = 0;
if (iPos >= 0)
{
if(IconLocation.Substring(iPos+1).IsInt())
{
IconIndex = IconLocation.Substring(iPos + 1).ToInt();
IconLocation=IconLocation.Substring(0, iPos);
}
}
if (IconLocation.Length == 0) { IconLocation = TargetPath; }
return new ShortcutDescription()
{
TargetPath = TargetPath,
Arguments = shortcut.Arguments,
WorkDir = shortcut.WorkingDirectory,
IconLocation= IconLocation,
IconIndex= IconIndex,
Description = shortcut.Description
};
}
}
}