Skip to content

Commit bd572fe

Browse files
Added Community Scripts support.
1 parent 22138c6 commit bd572fe

File tree

4 files changed

+229
-2
lines changed

4 files changed

+229
-2
lines changed

VDD Control/VDD Control/CommunityScriptsForm.Designer.cs

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Diagnostics;
6+
using System.Drawing;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using System.Windows.Forms;
12+
13+
namespace VDD_Control
14+
{
15+
public partial class CommunityScriptsForm : Form
16+
{
17+
private const string SCRIPTS_FOLDER = "Community Scripts";
18+
private ListBox scriptListBox;
19+
private Label noScriptsLabel;
20+
21+
public CommunityScriptsForm()
22+
{
23+
InitializeComponents();
24+
LoadScripts();
25+
}
26+
27+
private void InitializeComponents()
28+
{
29+
// Configure form
30+
this.Text = "Community Scripts";
31+
this.Size = new Size(500, 400);
32+
this.FormBorderStyle = FormBorderStyle.FixedDialog;
33+
this.MaximizeBox = false;
34+
this.MinimizeBox = false;
35+
this.StartPosition = FormStartPosition.CenterParent;
36+
this.BackColor = Color.FromArgb(32, 34, 37);
37+
this.ForeColor = Color.White;
38+
39+
// Create script list box
40+
scriptListBox = new ListBox
41+
{
42+
Dock = DockStyle.Fill,
43+
BackColor = Color.FromArgb(45, 47, 49),
44+
ForeColor = Color.White,
45+
BorderStyle = BorderStyle.FixedSingle
46+
};
47+
scriptListBox.DoubleClick += ScriptListBox_DoubleClick;
48+
49+
// Create no scripts label
50+
noScriptsLabel = new Label
51+
{
52+
Text = "No scripts found in the Community Scripts folder.",
53+
TextAlign = ContentAlignment.MiddleCenter,
54+
Dock = DockStyle.Fill,
55+
ForeColor = Color.White,
56+
BackColor = Color.FromArgb(45, 47, 49),
57+
Visible = false
58+
};
59+
60+
// Add controls to form
61+
this.Controls.Add(scriptListBox);
62+
this.Controls.Add(noScriptsLabel);
63+
}
64+
65+
private void LoadScripts()
66+
{
67+
// Make sure the scripts directory exists
68+
string scriptsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SCRIPTS_FOLDER);
69+
70+
// Create the directory if it doesn't exist
71+
if (!Directory.Exists(scriptsDirectory))
72+
{
73+
Directory.CreateDirectory(scriptsDirectory);
74+
}
75+
76+
// Find script files
77+
string[] scriptFiles = Directory.GetFiles(scriptsDirectory, "*.*")
78+
.Where(file =>
79+
file.EndsWith(".cmd", StringComparison.OrdinalIgnoreCase) ||
80+
file.EndsWith(".bat", StringComparison.OrdinalIgnoreCase) ||
81+
file.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase) ||
82+
file.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
83+
.ToArray();
84+
85+
// Clear the list
86+
scriptListBox.Items.Clear();
87+
88+
// If no scripts found, show the label
89+
if (scriptFiles.Length == 0)
90+
{
91+
scriptListBox.Visible = false;
92+
noScriptsLabel.Visible = true;
93+
return;
94+
}
95+
96+
// Otherwise, hide the label and populate the list
97+
scriptListBox.Visible = true;
98+
noScriptsLabel.Visible = false;
99+
100+
// Add scripts to list
101+
foreach (string scriptFile in scriptFiles)
102+
{
103+
scriptListBox.Items.Add(Path.GetFileName(scriptFile));
104+
}
105+
}
106+
107+
private void ScriptListBox_DoubleClick(object sender, EventArgs e)
108+
{
109+
if (scriptListBox.SelectedItem == null)
110+
return;
111+
112+
string selectedScript = scriptListBox.SelectedItem.ToString();
113+
string scriptPath = Path.Combine(
114+
AppDomain.CurrentDomain.BaseDirectory,
115+
SCRIPTS_FOLDER,
116+
selectedScript);
117+
118+
// Execute the script based on its extension
119+
try
120+
{
121+
if (selectedScript.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase))
122+
{
123+
// PowerShell script
124+
Process process = new Process
125+
{
126+
StartInfo = new ProcessStartInfo
127+
{
128+
FileName = "powershell.exe",
129+
Arguments = $"-ExecutionPolicy Bypass -File \"{scriptPath}\"",
130+
UseShellExecute = false,
131+
CreateNoWindow = false
132+
}
133+
};
134+
process.Start();
135+
}
136+
else if (selectedScript.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
137+
{
138+
// Executable
139+
Process.Start(scriptPath);
140+
}
141+
else
142+
{
143+
// Batch or CMD file
144+
Process process = new Process
145+
{
146+
StartInfo = new ProcessStartInfo
147+
{
148+
FileName = "cmd.exe",
149+
Arguments = $"/c \"{scriptPath}\"",
150+
UseShellExecute = false,
151+
CreateNoWindow = false
152+
}
153+
};
154+
process.Start();
155+
}
156+
}
157+
catch (Exception ex)
158+
{
159+
MessageBox.Show($"Error executing script: {ex.Message}", "Error",
160+
MessageBoxButtons.OK, MessageBoxIcon.Error);
161+
}
162+
}
163+
164+
// Method to refresh the script list (can be called externally)
165+
public void RefreshScripts()
166+
{
167+
LoadScripts();
168+
}
169+
}
170+
}

VDD Control/VDD Control/MainWindow.Designer.cs

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VDD Control/VDD Control/MainWindow.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public partial class mainWindow : Form
1818

1919
// Make IXCLI nullable to fix null safety warnings
2020
private XMLController? IXCLI;
21+
22+
// Reference to the community scripts form
23+
private CommunityScriptsForm? communityScriptsForm;
2124

2225
private bool SDR10_STATE = false;
2326
private bool CUSTOMEDID_STATE = false;
@@ -4135,5 +4138,34 @@ private void devModeLoggingToolStripMenuItem1_Click(object sender, EventArgs e)
41354138
{
41364139
devModeLoggingToolStripMenuItem_Click_1(sender, e);
41374140
}
4141+
4142+
// Community Scripts event handlers
4143+
private void communityScriptsToolStripMenuItem_Click(object sender, EventArgs e)
4144+
{
4145+
ShowCommunityScriptsWindow();
4146+
}
4147+
4148+
private void scriptsToolStripMenuItem_Click(object sender, EventArgs e)
4149+
{
4150+
ShowCommunityScriptsWindow();
4151+
}
4152+
4153+
// Method to show the Community Scripts window
4154+
private void ShowCommunityScriptsWindow()
4155+
{
4156+
// Create the form if it doesn't exist or was disposed
4157+
if (communityScriptsForm == null || communityScriptsForm.IsDisposed)
4158+
{
4159+
communityScriptsForm = new CommunityScriptsForm();
4160+
}
4161+
else
4162+
{
4163+
// If form exists, refresh the scripts
4164+
communityScriptsForm.RefreshScripts();
4165+
}
4166+
4167+
// Show the form
4168+
communityScriptsForm.ShowDialog(this);
4169+
}
41384170
}
41394171
}

0 commit comments

Comments
 (0)