Update Everything library, Fix #41

This commit is contained in:
Lin Yu-Chieh (Victor) 2022-12-17 22:53:28 +08:00
parent ef6154bce0
commit b777e48893
4 changed files with 18 additions and 19 deletions

View File

@ -18,13 +18,13 @@ namespace Community.PowerToys.Run.Plugin.Everything
private readonly string[] _appExtensions = { ".exe", ".bat", ".appref-ms", ".lnk" };
private bool _swapCopy;
private string[] _options;
private int[] _options;
internal void UpdateCopy(bool swapCopy)
{
_swapCopy = swapCopy;
}
public ContextMenuLoader(PluginInitContext context, string[] options)
public ContextMenuLoader(PluginInitContext context, int[] options)
{
_context = context;
_options = options;
@ -36,11 +36,11 @@ namespace Community.PowerToys.Run.Plugin.Everything
if (selectedResult.ContextData is SearchResult record)
{
bool isFile = record.File, runAs = CanFileBeRunAsAdmin(record.Path);
foreach (string o in _options)
foreach (int o in _options)
{
switch (o)
{
case "0":
case 0:
// Open folder
if (isFile)
{
@ -67,7 +67,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
}
break;
case "1":
case 1:
// Run as Adsmin
if (runAs)
{
@ -96,7 +96,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
}
break;
case "2":
case 2:
// Run as User
if (runAs)
{
@ -125,7 +125,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
}
break;
case "3":
case 3:
// Copy File/Folder
contextMenus.Add(new ContextMenuResult
{
@ -154,7 +154,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
},
});
break;
case "4":
case 4:
// Copy Path
contextMenus.Add(new ContextMenuResult
{
@ -183,7 +183,7 @@ namespace Community.PowerToys.Run.Plugin.Everything
},
});
break;
case "5":
case 5:
// Open in Shell
contextMenus.Add(new ContextMenuResult
{

Binary file not shown.

View File

@ -1,7 +1,9 @@
namespace Community.PowerToys.Run.Plugin.Everything
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
internal class Settings
{
@ -16,18 +18,18 @@
// Settings from settings.toml
internal uint Max { get; } = 20;
internal int Sort { get; } = 14;
internal string[] Options { get; }
internal int[] Options { get; } = new int[] { 0, 1, 2, 3, 4, 5 };
internal Dictionary<string, string> Filters { get; } = new Dictionary<string, string>();
internal Settings()
{
string[] strArr;
try { strArr = File.ReadAllLines("modules\\launcher\\Plugins\\Everything\\settings.toml"); }
try { strArr = File.ReadAllLines(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "settings.toml")); }
catch { return; }
var culture = new System.Globalization.CultureInfo("en-US");
foreach (string str in strArr)
{
if (str.Length == 0 || str[0] == '#') continue;
string[] kv = str.Split('=', System.StringSplitOptions.RemoveEmptyEntries | System.StringSplitOptions.TrimEntries);
string[] kv = str.Split('=', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (kv.Length != 2) continue;
switch (kv[0])
{
@ -40,7 +42,7 @@
catch { }
break;
case "options":
Options = kv[1].Split(';', System.StringSplitOptions.RemoveEmptyEntries | System.StringSplitOptions.TrimEntries);
Options = Array.ConvertAll(kv[1].Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries), int.Parse);
break;
default:
if (kv[0].Contains(':'))
@ -48,8 +50,6 @@
break;
}
}
Options ??= new string[] { "0", "1", "2", "3", "4", "5" };
}
}
}

View File

@ -7,14 +7,13 @@
internal class Update
{
private const string URL = "https://img.shields.io/github/v/release/lin-ycv/everythingpowertoys";
internal Update(Version v)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(URL);
Version latest = Version.Parse(doc.GetElementsByTagName("title")[0].InnerXml.Split(':', StringSplitOptions.TrimEntries)[1].Remove(0, 1));
doc.Load("https://img.shields.io/github/v/release/lin-ycv/everythingpowertoys");
Version latest = Version.Parse(doc.GetElementsByTagName("title")[0].InnerXml.Split(':', StringSplitOptions.TrimEntries)[1].AsSpan(1));
if (latest > v)
{
MessageBoxResult mbox = MessageBox.Show($"New version available for EverythingPowerToys.\n\nInstalled:\t {v}\nLatest:\t {latest}", "Download Update?", MessageBoxButton.OKCancel);
@ -29,7 +28,7 @@
}
}
}
catch (Exception e) { MessageBox.Show(e.ToString()); }
catch { }
}
}
}