From 996601e9cc2874b7aa6e38772bbb7ac23eed6413 Mon Sep 17 00:00:00 2001 From: EverythingWindows Date: Fri, 18 Nov 2022 16:58:37 +0700 Subject: [PATCH] Moving majority functions of apps from TerminalExternalApp into its own separate module and fixing bug on ability to set hostname and username to blank --- ShiftOS-TheRevival/API/TerminalAPI.vb | 9 +- .../MainForms/Console.Designer.vb | 2 +- ShiftOS-TheRevival/MainForms/Console.vb | 4 + ShiftOS-TheRevival/ShiftOS-TheRevival.vbproj | 2 + .../External/BasicCalculator/App_BC.vb | 86 +++++++++++ .../External/GuessTheNumber/App_Guess.vb | 40 ++++++ .../External/TerminalExternalApps.vb | 136 +----------------- .../External/Textpad/App_TextPad.vb | 18 +++ .../Internal/Com_Hostname.vb | 9 +- .../Internal/Com_Username.vb | 9 +- 10 files changed, 177 insertions(+), 138 deletions(-) create mode 100644 ShiftOS-TheRevival/TerminalApplications/External/BasicCalculator/App_BC.vb create mode 100644 ShiftOS-TheRevival/TerminalApplications/External/GuessTheNumber/App_Guess.vb diff --git a/ShiftOS-TheRevival/API/TerminalAPI.vb b/ShiftOS-TheRevival/API/TerminalAPI.vb index 912f782..6003d9e 100644 --- a/ShiftOS-TheRevival/API/TerminalAPI.vb +++ b/ShiftOS-TheRevival/API/TerminalAPI.vb @@ -167,7 +167,8 @@ Case "bc" If Strings.AvailableFeature(9) = "1" Then Console.ChangeInterpreter = True - AppHost("bc", False) + 'AppHost("bc", False) + BC_Start() AdvancedCommand = False NormalCommand() End If @@ -205,7 +206,8 @@ End If Case "guess" Console.ChangeInterpreter = True - AppHost("guess", False) + 'AppHost("guess", False) + GTN_Start() AdvancedCommand = False NormalCommand() 'Undeveloped() @@ -363,7 +365,8 @@ If Strings.AvailableFeature(17) = 1 Then Console.ChangeInterpreter = True command = RawCommand.Replace("textpad ", "") - AppHost("textpad", True) + TextPad_Start() + 'AppHost("textpad", True) AdvancedCommand = False NormalCommand() End If diff --git a/ShiftOS-TheRevival/MainForms/Console.Designer.vb b/ShiftOS-TheRevival/MainForms/Console.Designer.vb index 3d73ced..78dbfbf 100644 --- a/ShiftOS-TheRevival/MainForms/Console.Designer.vb +++ b/ShiftOS-TheRevival/MainForms/Console.Designer.vb @@ -103,5 +103,5 @@ Partial Class Console Friend WithEvents InfoBar As TextBox Friend WithEvents InfoBarTimer As Timer Friend WithEvents ToolBar As TextBox - Friend WithEvents ShortcutHandler As System.ComponentModel.BackgroundWorker + Public WithEvents ShortcutHandler As System.ComponentModel.BackgroundWorker End Class diff --git a/ShiftOS-TheRevival/MainForms/Console.vb b/ShiftOS-TheRevival/MainForms/Console.vb index 41d17fb..c9f4ae9 100644 --- a/ShiftOS-TheRevival/MainForms/Console.vb +++ b/ShiftOS-TheRevival/MainForms/Console.vb @@ -6,6 +6,7 @@ Public Class Console Public BadCommand As Boolean 'Detect if it's a bad command or not Public DisplayStory As Integer 'Keep record for displaying the DevX's or other's monologue Public StoryToTell As String 'Which chapter that you're going to be in + Public ShouldChange As Boolean = False 'Indicates if the interpreter should changed to a specific program Public ChangeInterpreter As Boolean = False 'Default interpreter is Terminal, if it's changed to True, there'll be other program used by Console Public CurrentInterpreter As String 'Shows what program is using Console Public CurrentDirectory As String 'Current Directory for ShiftOS Explorer @@ -16,6 +17,9 @@ Public Class Console Public ShOSKey As String 'DOSKEY tracking string for ShiftOS Private Sub Console_Load(sender As Object, e As EventArgs) Handles MyBase.Load + With ShortcutHandler + .WorkerSupportsCancellation = True + End With Console_Full() Cursor.Hide() InitializeTerminal() diff --git a/ShiftOS-TheRevival/ShiftOS-TheRevival.vbproj b/ShiftOS-TheRevival/ShiftOS-TheRevival.vbproj index 8a84f82..ecedef6 100644 --- a/ShiftOS-TheRevival/ShiftOS-TheRevival.vbproj +++ b/ShiftOS-TheRevival/ShiftOS-TheRevival.vbproj @@ -160,6 +160,8 @@ + + diff --git a/ShiftOS-TheRevival/TerminalApplications/External/BasicCalculator/App_BC.vb b/ShiftOS-TheRevival/TerminalApplications/External/BasicCalculator/App_BC.vb new file mode 100644 index 0000000..06525cb --- /dev/null +++ b/ShiftOS-TheRevival/TerminalApplications/External/BasicCalculator/App_BC.vb @@ -0,0 +1,86 @@ +Module App_BC + 'Basic Calculator's RAM + Public BC_ReadNumbers As Integer + Public BC_Numbers1 As String + Public BC_Numbers2 As String + Public BC_ThriceMoreValue As Integer + Public BC_ThriceMoreCount As Integer + Public BC_CurrentNumber As String + Public BC_Result As Integer + Public BC_Operation2 As String + + Public Sub BC_Start() + Console.DefaultPrompt = "> " + ResetLine("bc (Basic Calcultator)") + NewLine("Copyright, Free Software Foundation.") + NewLine("ShiftOS port by DevX.") + NewLine("This is free software with ABSOLUTELY NO WARRANTY.") + NewLine(Nothing) + Console.CurrentInterpreter = "bc" + Console.ShouldChange = True + End Sub + + Public Sub BC_Calculate() + BC_ReadNumbers = 0 + BC_ThriceMoreValue = 1 + BC_Numbers1 = Nothing + BC_Numbers2 = Nothing + BC_Operation2 = Nothing + BC_CurrentNumber = Nothing + BC_Result = Nothing + Dim GetText As String + Try + Do + GetText = command.Chars(BC_ReadNumbers) + Select Case GetText + Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" + BC_CurrentNumber = BC_CurrentNumber & GetText + Case "+", "-", "*", "/", "^" + Dim BC_Numbers3 As Integer + Select Case BC_ThriceMoreValue + Case 1 + BC_Numbers1 = BC_CurrentNumber + BC_CurrentNumber = Nothing + BC_Operation2 = GetText + BC_ThriceMoreValue = BC_ThriceMoreValue + 1 + Case >= 2 + BC_Numbers2 = BC_CurrentNumber + BC_Counting(BC_Numbers1, BC_Numbers2, BC_Operation2) + BC_Numbers3 = BC_Result + BC_Numbers1 = BC_Numbers3 + BC_Numbers2 = Nothing + BC_CurrentNumber = Nothing + BC_ThriceMoreValue = BC_ThriceMoreValue + 1 + End Select + BC_Operation2 = GetText + Case "." + NewLine("Decimals aren't supported yet!") + Case Else + 'BC_Counting(BC_Numbers1, BC_Numbers2, BC_Operation2) + End Select + BC_ReadNumbers = BC_ReadNumbers + 1 + Loop + Catch ex As Exception + BC_Numbers2 = BC_CurrentNumber + BC_CurrentNumber = Nothing + End Try + BC_Counting(BC_Numbers1, BC_Numbers2, BC_Operation2) + BC_ThriceMoreValue = Nothing + NewLine(BC_Result) + End Sub + + Public Sub BC_Counting(FirstNum As Integer, SecondNum As Integer, Operation As String) + Select Case Operation + Case "+" + BC_Result = FirstNum + SecondNum + Case "-" + BC_Result = FirstNum - SecondNum + Case "*" + BC_Result = FirstNum * SecondNum + Case "/" + BC_Result = FirstNum / SecondNum + Case "^" + BC_Result = FirstNum ^ SecondNum + End Select + End Sub +End Module diff --git a/ShiftOS-TheRevival/TerminalApplications/External/GuessTheNumber/App_Guess.vb b/ShiftOS-TheRevival/TerminalApplications/External/GuessTheNumber/App_Guess.vb new file mode 100644 index 0000000..32910ed --- /dev/null +++ b/ShiftOS-TheRevival/TerminalApplications/External/GuessTheNumber/App_Guess.vb @@ -0,0 +1,40 @@ +Module App_Guess + 'This is for GTN's RAM + Public TheNumber As Integer = 0 + Public FreezeText As String + + Public Sub GTN_Start() + Console.DefaultPrompt = "Your answer: " + NewLine("Guess the Number") + NewLine("Guess the correct number between 1 and 50 and you'll get anything between 1 to 10 Codepoints") + NewLine("Type 'exit' to terminate this game") + Console.CurrentInterpreter = "guess" + GTN_GenerateNumber() + Console.ShouldChange = True + End Sub + + Public Sub GTN_GenerateNumber() + Dim RandNum As New Random + TheNumber = RandNum.Next(1, 51) + End Sub + + Public Sub GTN_CheckNumber() + Dim TheirNumber As Integer = Convert.ToInt32(command) + If TheirNumber > 0 And TheirNumber < 51 Then + If TheirNumber = TheNumber Then + Dim GetCP As New Random + Dim GotCP As Integer = GetCP.Next(1, 11) + ChangeCP(True, GotCP) + NewLine("You are correct!, you got " & GotCP & " Codepoint(s)") + NewLine("Guess the new number between 1 and 50.") + GTN_GenerateNumber() + Else + If TheirNumber < TheNumber Then + NewLine("Higher!") + ElseIf TheirNumber > TheNumber Then + NewLine("Lower!") + End If + End If + End If + End Sub +End Module diff --git a/ShiftOS-TheRevival/TerminalApplications/External/TerminalExternalApps.vb b/ShiftOS-TheRevival/TerminalApplications/External/TerminalExternalApps.vb index 4777fd1..24384e3 100644 --- a/ShiftOS-TheRevival/TerminalApplications/External/TerminalExternalApps.vb +++ b/ShiftOS-TheRevival/TerminalApplications/External/TerminalExternalApps.vb @@ -1,43 +1,10 @@ Imports System.IO Module TerminalExternalApps - Public ShouldChange As Boolean = False Public KeyInput As Keys - 'This is for GTN's RAM - Public TheNumber As Integer = 0 - Public FreezeText As String - 'Basic Calculator's RAM - Public BC_ReadNumbers As Integer - Public BC_Numbers1 As String - Public BC_Numbers2 As String - Public BC_ThriceMoreValue As Integer - Public BC_ThriceMoreCount As Integer - Public BC_CurrentNumber As String - Public BC_Result As Integer - Public BC_Operation2 As String - 'TextPad's RAM - Public TextPad_FileName As String - Public TextPad_TempText As New Timer Public Sub AppHost(App As Object, UseToolBar As Boolean) Select Case App - Case "bc" - Console.DefaultPrompt = "> " - ResetLine("bc (Basic Calcultator)") - NewLine("Copyright, Free Software Foundation.") - NewLine("ShiftOS port by DevX.") - NewLine("This is free software with ABSOLUTELY NO WARRANTY.") - NewLine(Nothing) - Console.CurrentInterpreter = "bc" - ShouldChange = True - Case "guess" 'Guess the Number - Console.DefaultPrompt = "Your answer: " - NewLine("Guess the Number") - NewLine("Guess the correct number between 1 and 50 and you'll get anything between 1 to 10 Codepoints") - NewLine("Type 'exit' to terminate this game") - Console.CurrentInterpreter = "guess" - GTN_GenerateNumber() - ShouldChange = True 'Revisit Later 'Case "pause" 'Pause function ' Terminal.TextBox1.ReadOnly = True @@ -51,25 +18,15 @@ Module TerminalExternalApps ShiftoriumFX_DisplayPackages() NewLine(Nothing) NewLine("Type any package you want to investigate") - ShouldChange = True - Case "textpad" - Console.DefaultPrompt = Nothing - Console.TextBox1.Text = Nothing - Console.ToolBarUse = True - Terminal_CheckFeature() - Console.CurrentInterpreter = "textpad" - TextPad_CheckExist(command) - Console.ToolBar.Text = "TextPad - " & command & Environment.NewLine & "Ctrl-Q Exit | Ctrl-N New | Ctrl-O Open | Ctrl-S Save | F12 Save As" - Console.ReleaseCursor = True - TextRebind() + Console.ShouldChange = True End Select If Console.ReleaseCursor = True Then 'Strings.OnceInfo(5) = Terminal.TrackPos 'Terminal.TrackPos = Nothing End If - If ShouldChange = True Then + If Console.ShouldChange = True Then Console.ChangeInterpreter = True - ShouldChange = False + Console.ShouldChange = False End If End Sub @@ -150,96 +107,11 @@ Module TerminalExternalApps Case "exit" TerminateApp(Nothing) Case Else - BC_ReadNumbers = 0 - BC_ThriceMoreValue = 1 - BC_Numbers1 = Nothing - BC_Numbers2 = Nothing - BC_Operation2 = Nothing - BC_CurrentNumber = Nothing - BC_Result = Nothing - Dim GetText As String - Try - Do - GetText = command.Chars(BC_ReadNumbers) - Select Case GetText - Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" - BC_CurrentNumber = BC_CurrentNumber & GetText - Case "+", "-", "*", "/", "^" - Dim BC_Numbers3 As Integer - Select Case BC_ThriceMoreValue - Case 1 - BC_Numbers1 = BC_CurrentNumber - BC_CurrentNumber = Nothing - BC_Operation2 = GetText - BC_ThriceMoreValue = BC_ThriceMoreValue + 1 - Case >= 2 - BC_Numbers2 = BC_CurrentNumber - BC_Counting(BC_Numbers1, BC_Numbers2, BC_Operation2) - BC_Numbers3 = BC_Result - BC_Numbers1 = BC_Numbers3 - BC_Numbers2 = Nothing - BC_CurrentNumber = Nothing - BC_ThriceMoreValue = BC_ThriceMoreValue + 1 - End Select - BC_Operation2 = GetText - Case "." - NewLine("Decimals aren't supported yet!") - Case Else - 'BC_Counting(BC_Numbers1, BC_Numbers2, BC_Operation2) - End Select - BC_ReadNumbers = BC_ReadNumbers + 1 - Loop - Catch ex As Exception - BC_Numbers2 = BC_CurrentNumber - BC_CurrentNumber = Nothing - End Try - BC_Counting(BC_Numbers1, BC_Numbers2, BC_Operation2) - BC_ThriceMoreValue = Nothing - NewLine(BC_Result) + BC_Calculate() End Select End Select End Sub - Public Sub BC_Counting(FirstNum As Integer, SecondNum As Integer, Operation As String) - Select Case Operation - Case "+" - BC_Result = FirstNum + SecondNum - Case "-" - BC_Result = FirstNum - SecondNum - Case "*" - BC_Result = FirstNum * SecondNum - Case "/" - BC_Result = FirstNum / SecondNum - Case "^" - BC_Result = FirstNum ^ SecondNum - End Select - End Sub - - Public Sub GTN_GenerateNumber() - Dim RandNum As New Random - TheNumber = RandNum.Next(1, 51) - End Sub - - Public Sub GTN_CheckNumber() - Dim TheirNumber As Integer = Convert.ToInt32(command) - If TheirNumber > 0 And TheirNumber < 51 Then - If TheirNumber = TheNumber Then - Dim GetCP As New Random - Dim GotCP As Integer = GetCP.Next(1, 11) - ChangeCP(True, GotCP) - NewLine("You are correct!, you got " & GotCP & " Codepoint(s)") - NewLine("Guess the new number between 1 and 50.") - GTN_GenerateNumber() - Else - If TheirNumber < TheNumber Then - NewLine("Higher!") - ElseIf TheirNumber > TheNumber Then - NewLine("Lower!") - End If - End If - End If - End Sub - Public Sub ShOSKey_InputCommand(lastcommand As String) Console.ShOSKey = lastcommand End Sub diff --git a/ShiftOS-TheRevival/TerminalApplications/External/Textpad/App_TextPad.vb b/ShiftOS-TheRevival/TerminalApplications/External/Textpad/App_TextPad.vb index 80e9599..efe68f4 100644 --- a/ShiftOS-TheRevival/TerminalApplications/External/Textpad/App_TextPad.vb +++ b/ShiftOS-TheRevival/TerminalApplications/External/Textpad/App_TextPad.vb @@ -1,6 +1,24 @@ Imports System.IO +Imports System.ComponentModel Module App_TextPad + 'Public WithEvents TextPad_Shortcut As BackgroundWorker + + 'TextPad's RAM + Public TextPad_FileName As String + + Public Sub TextPad_Start() + Console.DefaultPrompt = Nothing + Console.TextBox1.Text = Nothing + Console.ToolBarUse = True + Terminal_CheckFeature() + Console.CurrentInterpreter = "textpad" + TextPad_CheckExist(command) + Console.ToolBar.Text = "TextPad - " & command & Environment.NewLine & "Ctrl-Q Exit | Ctrl-N New | Ctrl-O Open | Ctrl-S Save | F12 Save As" + Console.ReleaseCursor = True + TextRebind() + End Sub + Public Sub TextPad_CheckExist(TxtFileName As String) If File.Exists(Console.CurrentDirectory & "\" & TxtFileName) = True Then Console.TextBox1.Text = My.Computer.FileSystem.ReadAllText(Console.CurrentDirectory & "\" & TxtFileName) diff --git a/ShiftOS-TheRevival/TerminalApplications/Internal/Com_Hostname.vb b/ShiftOS-TheRevival/TerminalApplications/Internal/Com_Hostname.vb index 8903069..a436643 100644 --- a/ShiftOS-TheRevival/TerminalApplications/Internal/Com_Hostname.vb +++ b/ShiftOS-TheRevival/TerminalApplications/Internal/Com_Hostname.vb @@ -1,6 +1,13 @@ Module Com_Hostname + Public NewHostname As String + Public Sub Hostname() - Strings.ComputerInfo(0) = command.Substring(command.LastIndexOf(" ") + 1, command.Length - (command.LastIndexOf(" ") + 1)) + NewHostname = command.Substring(command.LastIndexOf(" ") + 1, command.Length - (command.LastIndexOf(" ") + 1)) + If NewHostname = "" Then + NewLine("A hostname should not be blank!") + Else + Strings.ComputerInfo(0) = NewHostname + End If Terminal_AssignPrompt() End Sub End Module diff --git a/ShiftOS-TheRevival/TerminalApplications/Internal/Com_Username.vb b/ShiftOS-TheRevival/TerminalApplications/Internal/Com_Username.vb index 0f8b4e7..f3b2423 100644 --- a/ShiftOS-TheRevival/TerminalApplications/Internal/Com_Username.vb +++ b/ShiftOS-TheRevival/TerminalApplications/Internal/Com_Username.vb @@ -1,6 +1,13 @@ Module Com_Username + Public NewUsername As String + Public Sub Username() - Strings.ComputerInfo(1) = command.Substring(command.LastIndexOf(" ") + 1, command.Length - (command.LastIndexOf(" ") + 1)) + NewUsername = command.Substring(command.LastIndexOf(" ") + 1, command.Length - (command.LastIndexOf(" ") + 1)) + If NewUsername = "" Then + NewLine("A username should not be blank") + Else + Strings.ComputerInfo(1) = NewUsername + End If Terminal_AssignPrompt() End Sub End Module