------ #### VSoft V2.0.2412.1001 - *.[新增]拖放文件到主界面,支持直接插入到拖放的位置。 - *.[新增]新增支持设置运行次数的功能,可以快速进行多开。 - *.[新增]支持保存大小和选中的栏目和分类位置。 - *.[改进]切换栏目会记录列表滚动条位置和选中的分类。 - *.[改进]编辑添加的内置功能,将不允许修改路径。 - *.[改进]读取快捷方式时,支持自动获取图标信息。 - *.[改进]新增软件完成后,不再刷新列表,而是直接添加到列表末尾。 - *.[改进]新增软件或拖放软件后,界面直接定位到添加的列表位置。 - *.[改进]点击显示主界面时,如果存在模式窗体,则将模式窗体显示在前面。 - *.[改进]当百度翻译出错时自动重试翻译。 - *.[修复]栏目和分类进行拖放操作时,拖放出控件会残留拖放标志的BUG。
183 lines
7.2 KiB
C#
183 lines
7.2 KiB
C#
using ryCommon;
|
||
using ryCommonDb;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Runtime.InteropServices;
|
||
using System.Text;
|
||
using System.Windows.Forms;
|
||
|
||
namespace VSoft.Prams
|
||
{
|
||
public static class Run
|
||
{
|
||
[DllImportAttribute("shell32.dll")]
|
||
private static extern int SHEmptyRecycleBin(IntPtr handle, string root, int falgs);
|
||
const int SHERB_NOCONFIRMATION = 0x000001;
|
||
const int SHERB_NOPROGRESSUI = 0x000002;
|
||
const int SHERB_NOSOUND = 0x000004;
|
||
/// <summary>
|
||
/// 打开软件
|
||
/// </summary>
|
||
/// <param name="info"></param>
|
||
/// <param name="RunasAdmin"></param>
|
||
/// <returns></returns>
|
||
public static int Open(SoftInfo info, bool RunasAdmin)
|
||
{
|
||
var path = info.TruePath;
|
||
var parm = info.RunPram;
|
||
var StartPath = info.StartPath;
|
||
var SetJson = info.SetJson;
|
||
if (info.SoftType == 1)
|
||
{
|
||
#region 重新载入数据
|
||
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
||
if (db.ConnDb(info.Path) == 1)
|
||
{
|
||
RyQuickSQL mySQL = new RyQuickSQL("Softs");
|
||
string where = "";
|
||
if(parm.StartsWith("cmdid=",StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
where = "CmdId=@CmdId";
|
||
mySQL.AddField("CmdId", parm.Substring(6));
|
||
}
|
||
else if (parm.StartsWith("id=", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
where = "id=@id";
|
||
mySQL.AddField("id", parm.Substring(3).ToInt());
|
||
}
|
||
if (where.Length > 0)
|
||
{
|
||
DataSet ds = db.ReadData("select * from Softs where " + where, mySQL);
|
||
if (ds.HaveData())
|
||
{
|
||
DataRow row = ds.Tables[0].Rows[0];
|
||
path = RyFiles.GetRealPath(row["Path"].ToString());
|
||
parm = row["RunPram"].ToString();
|
||
SetJson = row["SetJson"].ToString();
|
||
StartPath = row["StartPath"].ToString();
|
||
}
|
||
else
|
||
{
|
||
ds.Dispose();
|
||
db.Free();
|
||
return -1;
|
||
}
|
||
ds.Dispose();
|
||
}
|
||
db.Free();
|
||
}
|
||
#endregion
|
||
}
|
||
if (StartPath.Length == 0)
|
||
{
|
||
if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path))
|
||
{
|
||
StartPath = System.IO.Path.GetDirectoryName(path.TrimEnd('\\'));
|
||
}
|
||
else
|
||
{
|
||
StartPath = null;
|
||
}
|
||
}
|
||
if (path.StartsWith("@", StringComparison.OrdinalIgnoreCase)) //如果路径是@开头,则表示这个是一个命令
|
||
{
|
||
switch(path.Substring(1).ToLower())
|
||
{
|
||
case "emptyrecyclebin"://清空回收站
|
||
switch (Msg.ShowMsg("是否确认要清空回收站?\r\n\r\n该操作不可逆!!!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2))
|
||
{
|
||
case DialogResult.Yes:
|
||
SHEmptyRecycleBin(IntPtr.Zero, "", SHERB_NOCONFIRMATION + SHERB_NOPROGRESSUI + SHERB_NOSOUND);
|
||
return 37;
|
||
}
|
||
break;
|
||
case "trans"://翻译
|
||
Config.Soft_Config.MainForm.Invoke(new Action(() =>
|
||
{
|
||
RyForm.ShowOne(new Tools.FrmTrans());
|
||
}));
|
||
return 37;
|
||
}
|
||
return 0;
|
||
}
|
||
Json json = new Json(SetJson);
|
||
var RunCount = json.GetJsonValue("RunCount", 1);
|
||
var run_result = 37;
|
||
for (int i = 0; i < RunCount; i++)
|
||
{
|
||
if (RunasAdmin)
|
||
{
|
||
if(RunProcessAsAdmin(path, parm, StartPath, json.GetJsonValue("RunMode", 0))==-1)
|
||
{
|
||
run_result = -1;break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (json.GetJsonValue("RunAsAdmin", false))
|
||
{
|
||
if (RunProcessAsAdmin(path, parm, StartPath, json.GetJsonValue("RunMode", 0)) == -1)
|
||
{
|
||
run_result = -1; break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (RyFiles.RunFile(path, parm, StartPath, json.GetJsonValue("RunMode", 0)) < 36)
|
||
{
|
||
run_result = -1; break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return run_result;
|
||
|
||
}
|
||
/// <summary>
|
||
/// 以管理员方式打开
|
||
/// </summary>
|
||
/// <param name="exeName"></param>
|
||
/// <param name="parameters"></param>
|
||
/// <param name="CurrentDirectory"></param>
|
||
/// <returns></returns>
|
||
public static int RunProcessAsAdmin(string exeName, string parameters, string CurrentDirectory,int RunMode)
|
||
{
|
||
try
|
||
{
|
||
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
|
||
startInfo.UseShellExecute = true;
|
||
startInfo.WorkingDirectory = CurrentDirectory;
|
||
startInfo.FileName = exeName;
|
||
startInfo.Verb = "runas";
|
||
switch(RunMode)
|
||
{
|
||
case 0:
|
||
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
|
||
break;
|
||
case 1:
|
||
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
|
||
break;
|
||
case 2:
|
||
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
|
||
break;
|
||
case 3:
|
||
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
|
||
break;
|
||
}
|
||
|
||
//MLHIDE
|
||
startInfo.Arguments = parameters;
|
||
startInfo.ErrorDialog = true;
|
||
var process = System.Diagnostics.Process.Start(startInfo);
|
||
return 37;
|
||
}
|
||
catch
|
||
{
|
||
return -1;
|
||
}
|
||
}
|
||
}
|
||
}
|