mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-19 06:53:26 +08:00
Fix an issue if update failed
This commit is contained in:
parent
284767409a
commit
3f6cb3cd73
@ -11,7 +11,7 @@ using Control = System.Windows.Controls.Control;
|
|||||||
|
|
||||||
namespace Wox.Plugin.CMD
|
namespace Wox.Plugin.CMD
|
||||||
{
|
{
|
||||||
public class CMD : IPlugin, ISettingProvider,IPluginI18n
|
public class CMD : IPlugin, ISettingProvider, IPluginI18n
|
||||||
{
|
{
|
||||||
private PluginInitContext context;
|
private PluginInitContext context;
|
||||||
private bool WinRStroked;
|
private bool WinRStroked;
|
||||||
@ -23,87 +23,18 @@ namespace Wox.Plugin.CMD
|
|||||||
List<Result> pushedResults = new List<Result>();
|
List<Result> pushedResults = new List<Result>();
|
||||||
if (query.RawQuery == ">")
|
if (query.RawQuery == ">")
|
||||||
{
|
{
|
||||||
IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.OrderByDescending(o => o.Value)
|
return GetAllHistoryCmds();
|
||||||
.Select(m => new Result
|
|
||||||
{
|
|
||||||
Title = m.Key,
|
|
||||||
SubTitle = "this command has been executed " + m.Value + " times",
|
|
||||||
IcoPath = "Images/cmd.png",
|
|
||||||
Action = (c) =>
|
|
||||||
{
|
|
||||||
ExecuteCmd(m.Key);
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
ContextMenu = GetContextMenus(m.Key)
|
|
||||||
}).Take(5);
|
|
||||||
|
|
||||||
results.AddRange(history);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1)
|
if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1)
|
||||||
{
|
{
|
||||||
string cmd = query.RawQuery.Substring(1);
|
string cmd = query.RawQuery.Substring(1);
|
||||||
Result result = new Result
|
var queryCmd = GetCurrentCmd(cmd);
|
||||||
{
|
context.API.PushResults(query, context.CurrentPluginMetadata, new List<Result>() { queryCmd });
|
||||||
Title = cmd,
|
pushedResults.Add(queryCmd);
|
||||||
Score = 5000,
|
|
||||||
SubTitle = "execute command through command shell",
|
|
||||||
IcoPath = "Images/cmd.png",
|
|
||||||
Action = (c) =>
|
|
||||||
{
|
|
||||||
ExecuteCmd(cmd);
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
ContextMenu = GetContextMenus(cmd)
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
var history = GetHistoryCmds(cmd, queryCmd);
|
||||||
{
|
context.API.PushResults(query, context.CurrentPluginMetadata, history);
|
||||||
if (File.Exists(cmd) || Directory.Exists(cmd))
|
|
||||||
{
|
|
||||||
result.IcoPath = cmd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception) { }
|
|
||||||
|
|
||||||
context.API.PushResults(query, context.CurrentPluginMetadata, new List<Result>() { result });
|
|
||||||
pushedResults.Add(result);
|
|
||||||
|
|
||||||
IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.Where(o => o.Key.Contains(cmd))
|
|
||||||
.OrderByDescending(o => o.Value)
|
|
||||||
.Select(m =>
|
|
||||||
{
|
|
||||||
if (m.Key == cmd)
|
|
||||||
{
|
|
||||||
result.SubTitle = "this command has been executed " + m.Value + " times";
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var ret = new Result
|
|
||||||
{
|
|
||||||
Title = m.Key,
|
|
||||||
SubTitle = "this command has been executed " + m.Value + " times",
|
|
||||||
IcoPath = "Images/cmd.png",
|
|
||||||
Action = (c) =>
|
|
||||||
{
|
|
||||||
ExecuteCmd(m.Key);
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
ContextMenu = GetContextMenus(m.Key)
|
|
||||||
};
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (File.Exists(m.Key) || Directory.Exists(m.Key))
|
|
||||||
{
|
|
||||||
ret.IcoPath = m.Key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception) { }
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}).Where(o => o != null).Take(4);
|
|
||||||
|
|
||||||
context.API.PushResults(query, context.CurrentPluginMetadata, history.ToList());
|
|
||||||
pushedResults.AddRange(history);
|
pushedResults.AddRange(history);
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -130,8 +61,7 @@ namespace Wox.Plugin.CMD
|
|||||||
results.AddRange(autocomplete.ConvertAll(m => new Result()
|
results.AddRange(autocomplete.ConvertAll(m => new Result()
|
||||||
{
|
{
|
||||||
Title = m,
|
Title = m,
|
||||||
SubTitle = "",
|
IcoPath = "Images/cmd.png",
|
||||||
IcoPath = m,
|
|
||||||
Action = (c) =>
|
Action = (c) =>
|
||||||
{
|
{
|
||||||
ExecuteCmd(m);
|
ExecuteCmd(m);
|
||||||
@ -146,6 +76,72 @@ namespace Wox.Plugin.CMD
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Result> GetHistoryCmds(string cmd, Result result)
|
||||||
|
{
|
||||||
|
IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.Where(o => o.Key.Contains(cmd))
|
||||||
|
.OrderByDescending(o => o.Value)
|
||||||
|
.Select(m =>
|
||||||
|
{
|
||||||
|
if (m.Key == cmd)
|
||||||
|
{
|
||||||
|
result.SubTitle = "this command has been executed " + m.Value + " times";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ret = new Result
|
||||||
|
{
|
||||||
|
Title = m.Key,
|
||||||
|
SubTitle = "this command has been executed " + m.Value + " times",
|
||||||
|
IcoPath = "Images/cmd.png",
|
||||||
|
Action = (c) =>
|
||||||
|
{
|
||||||
|
ExecuteCmd(m.Key);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
ContextMenu = GetContextMenus(m.Key)
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
|
}).Where(o => o != null).Take(4);
|
||||||
|
return history.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result GetCurrentCmd(string cmd)
|
||||||
|
{
|
||||||
|
Result result = new Result
|
||||||
|
{
|
||||||
|
Title = cmd,
|
||||||
|
Score = 5000,
|
||||||
|
SubTitle = "execute command through command shell",
|
||||||
|
IcoPath = "Images/cmd.png",
|
||||||
|
Action = (c) =>
|
||||||
|
{
|
||||||
|
ExecuteCmd(cmd);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
ContextMenu = GetContextMenus(cmd)
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Result> GetAllHistoryCmds()
|
||||||
|
{
|
||||||
|
IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.OrderByDescending(o => o.Value)
|
||||||
|
.Select(m => new Result
|
||||||
|
{
|
||||||
|
Title = m.Key,
|
||||||
|
SubTitle = "this command has been executed " + m.Value + " times",
|
||||||
|
IcoPath = "Images/cmd.png",
|
||||||
|
Action = (c) =>
|
||||||
|
{
|
||||||
|
ExecuteCmd(m.Key);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
ContextMenu = GetContextMenus(m.Key)
|
||||||
|
}).Take(5);
|
||||||
|
return history.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
private List<Result> GetContextMenus(string cmd)
|
private List<Result> GetContextMenus(string cmd)
|
||||||
{
|
{
|
||||||
return new List<Result>()
|
return new List<Result>()
|
||||||
|
@ -6,6 +6,7 @@ using System.Windows.Threading;
|
|||||||
using NAppUpdate.Framework;
|
using NAppUpdate.Framework;
|
||||||
using NAppUpdate.Framework.Common;
|
using NAppUpdate.Framework.Common;
|
||||||
using NAppUpdate.Framework.Sources;
|
using NAppUpdate.Framework.Sources;
|
||||||
|
using Wox.Infrastructure.Logger;
|
||||||
|
|
||||||
namespace Wox.Core.Updater
|
namespace Wox.Core.Updater
|
||||||
{
|
{
|
||||||
@ -40,7 +41,16 @@ namespace Wox.Core.Updater
|
|||||||
if (asyncResult.IsCompleted)
|
if (asyncResult.IsCompleted)
|
||||||
{
|
{
|
||||||
// still need to check for caught exceptions if any and rethrow
|
// still need to check for caught exceptions if any and rethrow
|
||||||
((UpdateProcessAsyncResult)asyncResult).EndInvoke();
|
try
|
||||||
|
{
|
||||||
|
((UpdateProcessAsyncResult) asyncResult).EndInvoke();
|
||||||
|
}
|
||||||
|
catch(System.Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e);
|
||||||
|
updManager.CleanUp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// No updates were found, or an error has occured. We might want to check that...
|
// No updates were found, or an error has occured. We might want to check that...
|
||||||
if (updManager.UpdatesAvailable == 0)
|
if (updManager.UpdatesAvailable == 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user