这就是多选文件后,选择试用自己软件执行
编辑
单文件代码
编辑
注册表代码
编辑
如何采用谓词选择模型
- 2023/06/13
必须为谓词设置注册表值,以处理用户可以选择单个项、多个项或从项中进行选择的情况。 对于谓词支持的这三种情况,谓词都需要单独的注册表值。
Instructions
为所有谓词指定 MultiSelectModel 值。 如果未指定 MultiSelectModel 值,则从所选谓词实现的类型推断出来。 对于基于 COM 的方法, (如 DropTarget 和 ExecuteCommand) Player ,对于其他方法,则假定 使用 Document 。
谓词选择模型的可能值如下所示:
- 为仅支持单选的动词指定 Single。
- 为支持任意数量的项的动词指定 Player 。
- 为为每个项目创建顶级窗口的谓词指定 Document 。 这样做会限制激活的项数,并有助于避免在用户打开过多窗口时耗尽系统资源。
编辑
代码
using CyberWin.FairyAlliance.ECO.CompressionTools.CyberWin.fastgo;
using CyberWin.FairyAlliance.ECO.CompressionTools.CyberWin.WinOS;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZstdSharp;
namespace CyberWin.FairyAlliance.ECO.CompressionTools
{
internal static class Program
{
private static Mutex _mutex = new Mutex(true, "{8F6F0AC4-B9A1-45FD-A8CF-72F04E6BDE8F}");
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main作废(string[] args)
{
// 确保只有一个实例运行
if (!_mutex.WaitOne(TimeSpan.Zero, true))
{
return; // 已有实例运行,当前实例退出
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// 设置应用程序图标
Application.ApplicationExit += (s, e) => _mutex.ReleaseMutex();
try
{
// 1. 首次运行注册右键菜单(需管理员权限)
if (args.Contains("/register"))
{
// ContextMenuHelper.RegisterCompressMenu();
// ContextMenuHelper.RegisterDecompressMenu();
//MessageBox.Show("右键菜单注册成功!");
cyberwin_仙盟创梦_初始化本体.仙盟创梦_初始化本体(args);
return;
}
// 2. 处理压缩命令(/compress 后接选中的文件/文件夹路径)
if (args.Length >= 2 && args[0] == "/compress")
{
// 获取所有选中的文件/文件夹路径
//string[] selectedPaths3 = GetSelectedPaths(args[0]);
//东方仙盟_路径函数
MessageBox.Show(args[0]);
// MessageBox.Show(args[1]);
// MessageBox.Show(args[2]);
// 提取所有选中的路径(排除第一个参数 "/compress")
string[] selectedPaths = args.Skip(1).ToArray();
for(int i = 0;i< selectedPaths.Length; i++)
{
MessageBox.Show("I="+selectedPaths[i]);
}
string[] selectedPaths33= Environment.GetCommandLineArgs()
.Skip(1)
.Where(p => !string.IsNullOrEmpty(p) && (File.Exists(p) || Directory.Exists(p)))
.ToArray();
for (int i2 = 0; i2 < selectedPaths33.Length; i2++)
{
MessageBox.Show("I=" + selectedPaths33[i2]);
}
// 去重处理(避免重复路径)
selectedPaths = selectedPaths.Distinct().ToArray();
if (selectedPaths.Length == 0)
{
MessageBox.Show("未选中任何文件或文件夹!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string 文件夹路径1 = 东方仙盟_路径函数.GetParentDirectoryPath(args[1]);
// string 名称1 = 东方仙盟_路径函数.GetNameWithoutExtension(args[1]);
string 名称1 = 东方仙盟_路径函数.GetNameWithoutExtension(selectedPaths[0]);
string 目标压缩 = 文件夹路径1 + "/" + 名称1 + ".zip";
//passwordForm.Password
// progressForm.ShowDialog();
var passwordForm = new CompressPasswordForm();
if (passwordForm.ShowDialog() == DialogResult.OK)
{
// var progressForm = new 东方仙盟_CompressProgressForm( sourcePaths, targetZip,passwordForm.Password)); // 不输入密码则传递空字符串
// progressForm.ShowDialog();
// var progressForm = new 东方仙盟_CompressProgressForm(文路径1, 目标压缩, passwordForm.Password); // 不输入密码则传递空字符串
var progressForm = new 东方仙盟_CompressProgressForm(selectedPaths, 目标压缩, passwordForm.Password); // 不输入密码则传递空字符串
Application.Run(progressForm);
}
return;
}
// 3. 处理解压命令(/decompress 后接压缩文件路径)
if (args.Length == 2 && args[0] == "/decompress")
{
string archivePath = args[1];
// var form = new DecompressForm(archivePath); // 自定义解压窗口(输密码、选目录)
// Application.Run(form);
string 文件夹路径1 = 东方仙盟_路径函数.GetParentDirectoryPath(archivePath);
string 名称1 = 东方仙盟_路径函数.GetNameWithoutExtension(archivePath);
string 目标解压 = 文件夹路径1 + "/" + 名称1 + "_fairydec";
System.IO.Directory.CreateDirectory(目标解压);
var form = new 东方仙盟_DecompressProgressForm(archivePath, 目标解压);
// form.ShowDialog();
// form.Show();
Application.Run(form);
return;
}
// 4. 无参数时启动主窗口
// Application.Run(new MainForm());
Application.Run(new Form1());
}catch(Exception EX)
{
MessageBox.Show(EX.Message);
}
}
private const string MutexId = "{D88A577C-3E5A-4F72-9B9D-5F6D1C5A6E7F}";
private const string PipeName = "FutureWindow_CompressionTool_Pipe";
private static Mutex _instanceMutex;
private static Form1 _mainForm;
[STAThread]
static void Main(string[] args)
{
// 确保单实例运行
bool createdNew;
_instanceMutex = new Mutex(true, MutexId, out createdNew);
if (createdNew)
{
// 第一个实例:启动应用程序并监听参数
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// 创建主窗口并保存引用
_mainForm = new Form1();
// 启动命名管道监听线程,接收其他实例的参数
var listenerThread = new Thread(ListenForParameters);
listenerThread.IsBackground = true;
listenerThread.Start();
// 处理当前实例的参数
ProcessArguments(args);
// 运行应用程序
Application.Run(_mainForm);
// 释放互斥体
_instanceMutex.ReleaseMutex();
}
else
{
// 后续实例:将参数发送给第一个实例并退出
SendParametersToMainInstance(args);
}
}
/// <summary>
/// 监听命名管道,接收其他实例发送的参数
/// </summary>
private static void ListenForParameters()
{
while (true)
{
try
{
using (var pipeServer = new System.IO.Pipes.NamedPipeServerStream(
PipeName,
System.IO.Pipes.PipeDirection.In,
1,
System.IO.Pipes.PipeTransmissionMode.Message,
System.IO.Pipes.PipeOptions.Asynchronous))
{
// 等待客户端连接
pipeServer.WaitForConnection();
// 读取参数
using (var reader = new System.IO.StreamReader(pipeServer))
{
string parameters = reader.ReadToEnd();
if (!string.IsNullOrEmpty(parameters))
{
// 解析参数并在UI线程处理
string[] args = parameters.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
_mainForm.Invoke(new Action<string[]>(ProcessArguments), new object[] { args });
}
}
}
}
catch (Exception ex)
{
// 记录错误但不中断监听
Console.WriteLine(#34;管道监听错误: {ex.Message}");
}
}
}
/// <summary>
/// 将参数发送给主实例
/// </summary>
private static void SendParametersToMainInstance(string[] args)
{
try
{
using (var pipeClient = new System.IO.Pipes.NamedPipeClientStream(
".",
PipeName,
System.IO.Pipes.PipeDirection.Out))
{
// 连接到主实例
pipeClient.Connect(2000);
// 发送参数(用换行符分隔)
using (var writer = new System.IO.StreamWriter(pipeClient))
{
writer.Write(string.Join("\n", args));
writer.Flush();
}
}
}
catch (Exception ex)
{
MessageBox.Show(#34;无法连接到主程序: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 处理接收到的参数
/// </summary>
private static void ProcessArguments(string[] args)
{
if (args == null || args.Length == 0)
return;
// 处理注册命令
if (args[0].Equals("/register", StringComparison.OrdinalIgnoreCase))
{
// ContextMenuManager.RegisterMenus();
// MessageBox.Show("右键菜单注册成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// ContextMenuHelper.RegisterCompressMenu();
// ContextMenuHelper.RegisterDecompressMenu();
//MessageBox.Show("右键菜单注册成功!");
cyberwin_仙盟创梦_初始化本体.仙盟创梦_初始化本体(args);
return;
}
// 解析选中的文件/文件夹路径
// string[] selectedPaths = ParseSelectedPaths(args);
if (args.Length >= 2 && args[0] == "/compress")
{
// 获取所有选中的文件/文件夹路径
//string[] selectedPaths3 = GetSelectedPaths(args[0]);
//东方仙盟_路径函数
MessageBox.Show(args[0]);
// MessageBox.Show(args[1]);
// MessageBox.Show(args[2]);
// 提取所有选中的路径(排除第一个参数 "/compress")
// string[] selectedPaths = args.Skip(1).ToArray();
string[] selectedPaths = ParseSelectedPaths(args);
for (int i = 0; i < selectedPaths.Length; i++)
{
MessageBox.Show("I=" + selectedPaths[i]);
}
/*
string[] selectedPaths33 = Environment.GetCommandLineArgs()
.Skip(1)
.Where(p => !string.IsNullOrEmpty(p) && (File.Exists(p) || Directory.Exists(p)))
.ToArray();
for (int i2 = 0; i2 < selectedPaths33.Length; i2++)
{
MessageBox.Show("I=" + selectedPaths33[i2]);
}
*/
// 去重处理(避免重复路径)
selectedPaths = selectedPaths.Distinct().ToArray();
if (selectedPaths.Length == 0)
{
MessageBox.Show("未选中任何文件或文件夹!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string 文件夹路径1 = 东方仙盟_路径函数.GetParentDirectoryPath(args[1]);
// string 名称1 = 东方仙盟_路径函数.GetNameWithoutExtension(args[1]);
string 名称1 = 东方仙盟_路径函数.GetNameWithoutExtension(selectedPaths[0]);
string 目标压缩 = 文件夹路径1 + "/" + 名称1 + ".zip";
//passwordForm.Password
// progressForm.ShowDialog();
var passwordForm = new CompressPasswordForm();
if (passwordForm.ShowDialog() == DialogResult.OK)
{
// var progressForm = new 东方仙盟_CompressProgressForm( sourcePaths, targetZip,passwordForm.Password)); // 不输入密码则传递空字符串
// progressForm.ShowDialog();
// var progressForm = new 东方仙盟_CompressProgressForm(文路径1, 目标压缩, passwordForm.Password); // 不输入密码则传递空字符串
var progressForm = new 东方仙盟_CompressProgressForm(selectedPaths, 目标压缩, passwordForm.Password); // 不输入密码则传递空字符串
Application.Run(progressForm);
}
return;
}
// 3. 处理解压命令(/decompress 后接压缩文件路径)
if (args.Length == 2 && args[0] == "/decompress")
{
string archivePath = args[1];
// var form = new DecompressForm(archivePath); // 自定义解压窗口(输密码、选目录)
// Application.Run(form);
string 文件夹路径1 = 东方仙盟_路径函数.GetParentDirectoryPath(archivePath);
string 名称1 = 东方仙盟_路径函数.GetNameWithoutExtension(archivePath);
string 目标解压 = 文件夹路径1 + "/" + 名称1 + "_fairydec";
System.IO.Directory.CreateDirectory(目标解压);
var form = new 东方仙盟_DecompressProgressForm(archivePath, 目标解压);
// form.ShowDialog();
// form.Show();
Application.Run(form);
return;
}
}
public static string[] ParseSelectedPaths(string[] args)
{
if (args.Length >= 2 && args[0].Equals("compress", StringComparison.OrdinalIgnoreCase))
{
var paths = new List<string>();
for (int i = 1; i < args.Length; i++)
{
if (string.IsNullOrWhiteSpace(args[i]))
continue;
string path = args[i].Trim('"');
if (File.Exists(path) || Directory.Exists(path))
{
paths.Add(path);
}
}
return paths.Distinct().ToArray();
}
if (args.Length > 0 && !args[0].Equals("compress", StringComparison.OrdinalIgnoreCase))
{
return args.Where(p => File.Exists(p) || Directory.Exists(p))
.Select(p => p.Trim('"'))
.Distinct()
.ToArray();
}
return Array.Empty<string>();
}
}
}
压缩文件夹
编辑
编辑
解压,支持密码
编辑
未来之窗压缩工具:高效、便捷、安全的文件处理利器
未来之窗压缩工具是一款功能强大且设计精巧的文件处理软件,它以无广告、免安装的特性,为用户带来纯净且便捷的使用体验,同时支持密码保护与命令行操作,满足多样化的文件处理需求。
一、功能特性
- 无广告纯净体验:未来之窗压缩工具致力于为用户提供一个无干扰的使用环境,完全不包含任何形式的广告,无论是启动界面、操作过程还是完成任务后,都不会出现弹窗广告或其他广告形式,让用户专注于文件的压缩与解压操作。
- 免安装便捷使用:该工具无需进行繁琐的安装过程,用户下载后可直接运行,节省了系统资源与安装时间。这使得在不同电脑设备上快速使用文件压缩解压功能成为可能,无论是在办公场景下的公用电脑,还是个人的多台设备间切换使用,都能轻松应对。
- 密码保护:在数据安全日益重要的今天,未来之窗压缩工具提供了可靠的密码保护功能。当用户对文件或文件夹进行压缩操作时,软件会弹出密码输入窗口(CompressPasswordForm)。只有在用户输入密码并确认后,才会开始压缩过程。这确保了压缩文件的内容只有知道密码的用户能够解压查看,有效防止文件内容泄露,保护用户隐私与敏感数据。
- 命令行操作支持:软件具备丰富的命令行操作选项,极大地提升了操作效率与灵活性,满足专业用户和自动化任务的需求。 注册右键菜单:通过在命令行输入/register参数(需管理员权限),软件可自动完成右键菜单的注册,方便用户在资源管理器中直接对文件或文件夹进行压缩和解压操作。虽然当前代码中的ContextMenuHelper.RegisterCompressMenu()和ContextMenuHelper.RegisterDecompressMenu()被注释,但整体逻辑保留,未来可通过完善相关方法实现右键菜单的完整功能。 压缩操作:用户在命令行输入/compress后,接着输入要压缩的文件或文件夹路径,即可启动压缩任务。例如,/compress C:\Users\Files\example.txt C:\Users\Folders\exampleFolder,软件会获取这些路径并进行去重处理。然后根据目标路径生成压缩文件,如根据首个路径生成目标压缩文件名为C:\Users\Files\example.zip。之后弹出密码输入窗口,用户输入密码确认后,软件会以东方仙盟_CompressProgressForm展示压缩进度。 解压操作:输入/decompress及压缩文件路径,如/decompress C:\Users\example.zip,软件会自动创建解压目录,例如将example.zip解压到C:\Users\example_fairydec目录下,并通过东方仙盟_DecompressProgressForm展示解压进度。
二、实现原理
- 单实例运行:借助互斥体(Mutex)确保软件在系统中只有一个实例运行。代码中定义了_mutex = new Mutex(true, "{8F6F0AC4 - B9A1 - 45FD - A8CF - 72F04E6BDE8F}"),在Main方法开始处通过_mutex.WaitOne(TimeSpan.Zero, true)判断是否已有实例运行,若已有则当前实例直接退出,避免资源浪费与冲突。
- 参数解析与处理:软件对命令行参数进行详细解析。在Main方法中,根据不同参数执行相应操作,如/register用于注册右键菜单,/compress用于压缩文件或文件夹,/decompress用于解压文件。在处理/compress和/decompress参数时,通过ParseSelectedPaths方法解析路径参数,确保获取正确的文件或文件夹路径,并进行去重处理,以保证操作的准确性与高效性。
- 路径处理与窗口交互:软件通过东方仙盟_路径函数中的GetParentDirectoryPath和GetNameWithoutExtension方法获取文件或文件夹的相关路径信息,用于生成目标压缩文件路径和解压目录路径。在压缩过程中,通过CompressPasswordForm获取用户输入的密码,并将路径信息和密码传递给东方仙盟_CompressProgressForm展示压缩进度;解压时则将压缩文件路径和解压目录路径传递给东方仙盟_DecompressProgressForm展示解压进度。
未来之窗压缩工具凭借其独特的功能特性与高效的实现方式,为用户提供了一个简洁、安全、高效的文件压缩解压解决方案,无论是普通用户还是专业人士,都能从中受益。
阿雪技术观
在科技发展浪潮中,我们不妨积极投身技术共享。不满足于做受益者,更要主动担当贡献者。无论是分享代码、撰写技术博客,还是参与开源项目维护改进,每一个微小举动都可能蕴含推动技术进步的巨大能量。东方仙盟是汇聚力量的天地,我们携手在此探索硅基生命,为科技进步添砖加瓦。
Hey folks, in this wild tech - driven world, why not dive headfirst into the whole tech - sharing scene? Don't just be the one reaping all the benefits; step up and be a contributor too. Whether you're tossing out your code snippets, hammering out some tech blogs, or getting your hands dirty with maintaining and sprucing up open - source projects, every little thing you do might just end up being a massive force that pushes tech forward. And guess what? The Eastern FairyAlliance is this awesome place where we all come together. We're gonna team up and explore the whole silicon - based life thing, and in the process, we'll be fueling the growth of technology.