Download
Source
Imports System.IO
Imports System.Windows.Forms.VisualStyles.VisualStyleEleme nt
Public Class Form1
Dim ScriptPathstring As String
Dim Finaltext As String
Public Sub Scriptpathing()
If ScriptPathExtraFolder.Checked Then
ScriptPathstring = ScriptPath1.Text & ScriptPath2.Text & "" & ScriptPath3.Text
ScriptPath2.Enabled = True
Else
ScriptPathstring = ScriptPath1.Text & ScriptPath3.Text
ScriptPath2.Enabled = False
End If
End Sub
Private Sub ScriptPath1_TextChanged(sender As Object, e As EventArgs) Handles ScriptPath1.TextChanged
Scriptpathing()
End Sub
Private Sub ScriptPath2_TextChanged(sender As Object, e As EventArgs) Handles ScriptPath2.TextChanged
Scriptpathing()
End Sub
Private Sub ScriptPath3_TextChanged(sender As Object, e As EventArgs) Handles ScriptPath3.TextChanged
Scriptpathing()
End Sub
'vbCrLf
Private Sub ScriptPathExtraFolder_CheckedChanged(sender As Object, e As EventArgs) Handles ScriptPathExtraFolder.CheckedChanged
Scriptpathing()
End Sub
Private Sub Diot_Click(sender As Object, e As EventArgs) Handles Diot.Click
Dim Finaltext As String = Staticdata.Text & vbNewLine
Dim Actiontxt As String = Action.Text
Finaltext &= " {" & vbNewLine
If Actiontxt = "Console" Then
Finaltext &= " " & """command"": """ & PowershellCommand.Text & """," & vbNewLine
Actiontxt = Actiontxt.Replace("Console", "Shell")
ElseIf Actiontxt = "PowerShellConsole" Then
PowershellCommand.Text = ""
Finaltext &= " " & """command"": """ & PluginScriptText.Text & """," & vbNewLine
Actiontxt = Actiontxt.Replace("PowerShellConsole", "runPS")
ElseIf Actiontxt = "PowerShellFile" Then
PowershellCommand.Text = ""
Finaltext &= " " & """command"": """ & """," & vbNewLine
Actiontxt = Actiontxt.Replace("PowerShellFile", "runPSFile")
ElseIf Actiontxt = "Plugin" Then
Finaltext &= " " & """command"": """ & PowershellCommand.Text & """," & vbNewLine
Actiontxt = Actiontxt.Replace("Plugin", "runPlugin")
End If
Finaltext &= " " & """question"": """ & Question.Text & """," & vbNewLine
Finaltext &= " " & """response"": """ & Response.Text & """," & vbNewLine
Finaltext &= " " & """action"": """ & Actiontxt & """," & vbNewLine
Finaltext &= " " & """category"": """ & Category.Text & """," & vbNewLine
Finaltext &= " " & """description"": """ & Description.Text & """," & vbNewLine
Finaltext &= " " & """scriptPath"": """ & ScriptPathstring & """," & vbNewLine
Finaltext &= " " & """githubURL"": """ & GithubURL.Text & vbNewLine & " }"
Staticdata.Text = Finaltext & ","
Finaltext &= vbNewLine & "]"
' Den zusammengesetzten Text der TextBox StaticDataFinalText zuweisen
StaticDataFinalText.Text = Finaltext
StaticDataFinalText.Lines = (From s As String In StaticDataFinalText.Lines Where s.Length > 0 Select s).ToArray
ReDim Preserve StaticDataFinalText.Lines(StaticDataFinalText.Line s.Count - 1)
End Sub
Private Function IsNullOrWhiteSpace(s As String) As Boolean
Return String.IsNullOrEmpty(s) OrElse s.Trim().Length = 0
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Abspeichern_Click(sender As Object, e As EventArgs) Handles Abspeichern.Click
' Die JSON-Datei wird weiterhin im Hintergrund am festen Ort gespeichert
SaveTextToFile("C:\Winpilot_07\app\appstaticAIData .json", StaticDataFinalText.Text)
' Wenn die Aktion PowerShellFile ist, fragen wir nach dem Speicherort
If Action.Text = "PowerShellFile" Then
Using sfd As New SaveFileDialog()
' Einstellungen für den Speicher-Dialog
sfd.Filter = "PowerShell Script (*.ps1)|*.ps1|All Files (*.*)|*.*"
sfd.Title = "PowerShell-Skript speichern unter..."
sfd.InitialDirectory = "C:\Winpilot_07\plugins"
' Schlägt den Text aus der Question-Box als Dateinamen vor
sfd.FileName = Question.Text & ".ps1"
' Öffnet den Dialog. Nur wenn der Benutzer auf "Speichern" klickt, wird ausgeführt:
If sfd.ShowDialog() = DialogResult.OK Then
Dim pfads As String = sfd.FileName
Try
' Falls die Datei existiert, wird sie überschrieben (WriteAllText mit False überschreibt sowieso,
' aber wir behalten deine Logik bei)
If My.Computer.FileSystem.FileExists(pfads) Then
My.Computer.FileSystem.DeleteFile(pfads)
End If
My.Computer.FileSystem.WriteAllText(pfads, PluginScriptText.Text, False)
MessageBox.Show("Script erfolgreich gespeichert unter:" & vbCrLf & pfads, "Erfolgreich", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show("Fehler beim Speichern: " & ex.Message, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Using
End If
End Sub
Public Sub SaveTextToFile(filePath As String, textToSave As String)
Try
If File.Exists(filePath) Then
File.Delete(filePath)
End If
Using writer As New StreamWriter(filePath, False) ' False überschreibt die Datei, True fügt hinzu
writer.Write(textToSave)
End Using
MessageBox.Show("Datei erfolgreich gespeichert!")
Catch ex As Exception
MessageBox.Show("Fehler beim Speichern der Datei: " & ex.Message)
End Try
End Sub
Private Sub PowershellCommand_TextChanged(sender As Object, e As EventArgs) Handles PowershellCommand.TextChanged
End Sub
End Class