2019-09-08 20:16:47 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Wox.Plugin.Program.Views.Models;
|
|
|
|
|
|
|
|
|
|
namespace Wox.Plugin.Program.Views.Commands
|
|
|
|
|
{
|
|
|
|
|
internal static class ProgramSettingDisplay
|
|
|
|
|
{
|
|
|
|
|
internal static List<ProgramSource> LoadProgramSources(this List<Settings.ProgramSource> programSources)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<ProgramSource>();
|
|
|
|
|
|
2019-09-11 06:01:38 +08:00
|
|
|
|
programSources.ForEach(x => list
|
|
|
|
|
.Add(
|
|
|
|
|
new ProgramSource {
|
|
|
|
|
Enabled = x.Enabled,
|
|
|
|
|
Location = x.Location,
|
|
|
|
|
Name = x.Name,
|
|
|
|
|
UniqueIdentifier = x.UniqueIdentifier
|
|
|
|
|
}
|
|
|
|
|
));
|
2019-09-08 20:16:47 +08:00
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 05:57:03 +08:00
|
|
|
|
internal static void LoadAllApplications(this List<ProgramSource> list)
|
2019-09-08 20:16:47 +08:00
|
|
|
|
{
|
2019-09-10 05:57:03 +08:00
|
|
|
|
Main._win32s
|
|
|
|
|
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
2019-09-08 20:16:47 +08:00
|
|
|
|
.ToList()
|
2019-09-10 05:57:03 +08:00
|
|
|
|
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList
|
|
|
|
|
.Add(
|
|
|
|
|
new ProgramSource {
|
|
|
|
|
Name = t1.Name,
|
|
|
|
|
Location = t1.ParentDirectory,
|
|
|
|
|
UniqueIdentifier = t1.UniqueIdentifier,
|
|
|
|
|
Enabled = t1.Enabled
|
2019-09-11 06:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
));
|
2019-09-08 20:16:47 +08:00
|
|
|
|
|
|
|
|
|
Main._uwps
|
2019-09-10 05:57:03 +08:00
|
|
|
|
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
2019-09-08 20:16:47 +08:00
|
|
|
|
.ToList()
|
2019-09-10 05:57:03 +08:00
|
|
|
|
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList
|
|
|
|
|
.Add(
|
|
|
|
|
new ProgramSource {
|
|
|
|
|
Name = t1.DisplayName,
|
|
|
|
|
Location = t1.Package.Location,
|
|
|
|
|
UniqueIdentifier = t1.UniqueIdentifier,
|
|
|
|
|
Enabled = t1.Enabled
|
|
|
|
|
})
|
|
|
|
|
);
|
2019-09-08 20:16:47 +08:00
|
|
|
|
}
|
2019-09-08 20:18:55 +08:00
|
|
|
|
|
2019-10-15 05:05:21 +08:00
|
|
|
|
internal static void SetProgramSourcesStatus(this List<ProgramSource> list, List<ProgramSource> selectedProgramSourcesToDisable, bool status)
|
2019-09-08 20:18:55 +08:00
|
|
|
|
{
|
|
|
|
|
ProgramSetting.ProgramSettingDisplayList
|
2019-10-15 05:05:21 +08:00
|
|
|
|
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
2019-09-08 20:18:55 +08:00
|
|
|
|
.ToList()
|
2019-10-15 05:05:21 +08:00
|
|
|
|
.ForEach(t1 => t1.Enabled = status);
|
2019-09-08 20:18:55 +08:00
|
|
|
|
|
|
|
|
|
Main._win32s
|
2019-10-15 05:05:21 +08:00
|
|
|
|
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
2019-09-08 20:18:55 +08:00
|
|
|
|
.ToList()
|
2019-10-15 05:05:21 +08:00
|
|
|
|
.ForEach(t1 => t1.Enabled = status);
|
2019-09-08 20:18:55 +08:00
|
|
|
|
|
|
|
|
|
Main._uwps
|
2019-10-15 05:05:21 +08:00
|
|
|
|
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
2019-09-08 20:18:55 +08:00
|
|
|
|
.ToList()
|
2019-10-15 05:05:21 +08:00
|
|
|
|
.ForEach(t1 => t1.Enabled = status);
|
2019-09-10 05:57:03 +08:00
|
|
|
|
}
|
2019-09-08 20:18:55 +08:00
|
|
|
|
|
2019-09-10 05:57:03 +08:00
|
|
|
|
internal static void StoreDisabledInSettings(this List<ProgramSource> list)
|
|
|
|
|
{
|
2019-09-08 20:18:55 +08:00
|
|
|
|
Main._settings.ProgramSources
|
2019-09-10 05:57:03 +08:00
|
|
|
|
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
|
2019-09-08 20:18:55 +08:00
|
|
|
|
.ToList()
|
|
|
|
|
.ForEach(t1 => t1.Enabled = false);
|
2019-09-10 05:57:03 +08:00
|
|
|
|
|
|
|
|
|
ProgramSetting.ProgramSettingDisplayList
|
|
|
|
|
.Where(t1 => !t1.Enabled
|
2019-10-15 05:05:21 +08:00
|
|
|
|
&& !Main._settings.DisabledProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
2019-09-10 05:57:03 +08:00
|
|
|
|
.ToList()
|
2019-10-15 05:05:21 +08:00
|
|
|
|
.ForEach(x => Main._settings.DisabledProgramSources
|
2019-09-10 05:57:03 +08:00
|
|
|
|
.Add(
|
2019-10-15 05:05:21 +08:00
|
|
|
|
new Settings.DisabledProgramSource
|
2019-09-10 05:57:03 +08:00
|
|
|
|
{
|
|
|
|
|
Name = x.Name,
|
|
|
|
|
Location = x.Location,
|
|
|
|
|
UniqueIdentifier = x.UniqueIdentifier,
|
|
|
|
|
Enabled = false
|
|
|
|
|
}
|
|
|
|
|
));
|
2019-09-08 20:18:55 +08:00
|
|
|
|
}
|
2019-10-15 05:05:21 +08:00
|
|
|
|
|
|
|
|
|
internal static void RemoveDisabledFromSettings(this List<ProgramSource> list)
|
|
|
|
|
{
|
|
|
|
|
Main._settings.ProgramSources
|
|
|
|
|
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
|
|
|
|
|
.ToList()
|
|
|
|
|
.ForEach(t1 => t1.Enabled = true);
|
|
|
|
|
|
|
|
|
|
Main._settings.DisabledProgramSources
|
|
|
|
|
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
|
|
|
|
|
.ToList()
|
|
|
|
|
.ForEach(x => Main._settings.DisabledProgramSources.Remove(x));
|
|
|
|
|
}
|
2019-09-08 20:16:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|