-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackages.cs
102 lines (99 loc) · 3.03 KB
/
Packages.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Decompiled with JetBrains decompiler
// Type: OculusTrayTool.Packages
// Assembly: OculusTrayTool, Version=0.87.8.0, Culture=neutral, PublicKeyToken=null
// MVID: E8946A27-16D6-4BF6-9D7B-70CB25A977E0
// Assembly location: C:\Program Files (x86)\Oculus Tray Tool\OculusTrayTool.exe
using Microsoft.VisualBasic.CompilerServices;
using OculusTrayTool.My;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
#nullable disable
namespace OculusTrayTool
{
[StandardModule]
internal sealed class Packages
{
public static object CheckPackage(string cmd, string app)
{
int num = 0;
try
{
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
using (Pipeline pipeline = runspace.CreatePipeline())
{
pipeline.Commands.AddScript(cmd);
Collection<PSObject> collection = pipeline.Invoke();
num = collection.Count;
if (num != 0 & Operators.CompareString(app, "", false) != 0)
{
try
{
foreach (PSObject psObject in collection)
Log.WriteToLinkLog(app + " is installed in: " + psObject.Members["Source"].Value.ToString());
}
finally
{
IEnumerator<PSObject> enumerator;
enumerator?.Dispose();
}
}
}
runspace.Close();
}
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Exception exception = ex;
Log.WriteToLinkLog("CheckPackage: " + exception.Message);
MyProject.Forms.FrmMain.AddToListboxAndScroll(exception.Message);
ProjectData.ClearProjectError();
}
return (object) num;
}
public static object CheckCode(string cmd)
{
try
{
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
using (Pipeline pipeline = runspace.CreatePipeline())
{
pipeline.Commands.AddScript(cmd);
Collection<PSObject> collection = pipeline.Invoke();
IEnumerator<PSObject> enumerator;
if (collection.Count != 0)
{
try
{
enumerator = collection.GetEnumerator();
if (enumerator.MoveNext())
return (object) enumerator.Current.ToString();
}
finally
{
enumerator?.Dispose();
}
}
}
runspace.Close();
}
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Exception exception = ex;
Log.WriteToLinkLog("CheckPackage: " + exception.Message);
MyProject.Forms.FrmMain.AddToListboxAndScroll(exception.Message);
ProjectData.ClearProjectError();
}
return (object) "0";
}
}
}