-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
280be64
commit 7a871eb
Showing
8 changed files
with
159 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace plugin | ||
{ | ||
public interface IInputPlugin | ||
{ | ||
string Execute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using WUApiLib; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace plugin | ||
{ | ||
[PluginAttribute(PluginName = "Updates")] | ||
public class IUpdates : IInputPlugin | ||
{ | ||
public string Execute() | ||
{ | ||
dynamic package = new JObject(); | ||
package.automaticUpdates = null; | ||
package.numInstalledUpdates = null; | ||
package.installedUpdates = new JArray(); | ||
package.numUpdatesAvailable = null; | ||
package.updatesAvailable = new JArray(); | ||
dynamic update = new JObject(); | ||
|
||
// Checks if automatic updates are enabled | ||
AutomaticUpdates automaticUpdates = new AutomaticUpdates(); | ||
package.automaticUpdates = automaticUpdates.ServiceEnabled; | ||
|
||
|
||
// Checks installed updates | ||
UpdateSession uSession = new UpdateSession(); | ||
|
||
// IUpdateSearcher class | ||
// https://docs.microsoft.com/en-us/windows/desktop/api/wuapi/nn-wuapi-iupdatesearcher | ||
IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher(); | ||
uSearcher.ServerSelection = ServerSelection.ssDefault; | ||
uSearcher.IncludePotentiallySupersededUpdates = true; | ||
uSearcher.Online = false; | ||
try | ||
{ | ||
// Number of installed updates | ||
ISearchResult sResult = uSearcher.Search("IsInstalled=1 And IsHidden=0"); | ||
|
||
package.numInstalledUpdates = sResult.Updates.Count; | ||
|
||
// IUpdate class | ||
// https://docs.microsoft.com/en-us/windows/desktop/api/wuapi/nn-wuapi-iupdate | ||
foreach (IUpdate iupdate in sResult.Updates) | ||
{ | ||
update.id = iupdate.Identity.UpdateID; | ||
update.date = iupdate.LastDeploymentChangeTime; | ||
update.title = iupdate.Title; | ||
update.categories = new JArray(); | ||
// IUpdate class | ||
// https://docs.microsoft.com/en-us/windows/desktop/api/wuapi/nn-wuapi-icategory | ||
foreach (ICategory icategory in iupdate.Categories) | ||
{ | ||
update.categories.Add(icategory.Name); | ||
} | ||
|
||
package.installedUpdates.Add(update); | ||
} | ||
|
||
|
||
// Number of non installed updates | ||
|
||
sResult = uSearcher.Search("IsInstalled=0 And IsHidden=0"); | ||
|
||
package.numUpdatesAvailable = sResult.Updates.Count; | ||
|
||
foreach (IUpdate iupdate in sResult.Updates) | ||
{ | ||
update.id = iupdate.Identity.UpdateID; | ||
update.date = iupdate.LastDeploymentChangeTime; | ||
update.title = iupdate.Title; | ||
|
||
package.updatesAvailable.Add(update); | ||
} | ||
|
||
return package.ToString(); | ||
} | ||
|
||
catch (Exception ex) | ||
{ | ||
Console.WriteLine("Something went wrong: " + ex.Message); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace plugin | ||
{ | ||
public class PluginAttribute : Attribute | ||
{ | ||
public string PluginName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
|
||
namespace plugin | ||
{ | ||
public class PluginDefinition | ||
{ | ||
public Attribute Attribute { get; set; } | ||
public Type ImplementationType { get; set; } | ||
|
||
public PluginDefinition(Attribute Attribute, Type implementationType) | ||
{ | ||
this.Attribute = Attribute; | ||
this.ImplementationType = implementationType; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Newtonsoft.Json" version="12.0.1-beta1" targetFramework="net461" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters