Operating System Simulator Plugin
3.5.1
Unreal Engine plugin that simulates an Operating System Environment
|
#include "OperatingSystemTerminal.h"
Public Member Functions | |
UOperatingSystemTerminal () | |
OPERATINGSYSTEMSIMULATOR_API void | ProcessCommand (const FString &TestCommand, FGenericError &OutError) |
bool | ChangeCurrentPath (const FString &TargetPath) |
void | DestroyActiveCommand (const FGenericError &ErrorMessage) |
void | ChangeCurrentUser (const FOperatingSystemUser &NewUser) |
OPERATINGSYSTEMSIMULATOR_API void | PromptRootPassword () |
OPERATINGSYSTEMSIMULATOR_API void | PromptUserContinue () |
OPERATINGSYSTEMSIMULATOR_API bool | CheckRootPassword (const FText &TestPassword, const bool bCaseSensitive=true) const |
void | MessageReceivedFromCommand (const FText &CmdMsg, const EOperatingSystemTerminalMessageType &CmdMsgType) |
OPERATINGSYSTEMSIMULATOR_API void | VerifyUserPrompt (const bool bIsYes) const |
OPERATINGSYSTEMSIMULATOR_API void | ClearHistory () |
OPERATINGSYSTEMSIMULATOR_API bool | HasRepository () const |
OPERATINGSYSTEMSIMULATOR_API bool | GetNextCommandFromHistory (FString &OutCommand) const |
OPERATINGSYSTEMSIMULATOR_API bool | GetPreviousCommandFromHistory (FString &OutCommand) const |
OPERATINGSYSTEMSIMULATOR_API bool | IsTerminalBusy () const |
Checks if the terminal is busy or not. A terminal is considered busy if there is an active command being executed. | |
FORCEINLINE bool | ValidateFlags () const |
Gets the value of the bValidateFlags flag. | |
FORCEINLINE const TSet< FName > & | GetCommandFlagPrefixes () const |
Returns the set of command flag prefixes. | |
FORCEINLINE FString | GetMultiCommandOperatorString () const |
Public Member Functions inherited from UOperatingSystemBaseProgram | |
UOperatingSystemBaseProgram () | |
UOperatingSystemBaseProgram * | StartProgram (FGenericError &OutError) |
bool | IsRunning () const |
bool | CanAddToDesktop () const |
UOperatingSystem * | GetOperatingSystem () const |
UOperatingSystemProgramIconWidget * | CreateIconWidget () |
UOperatingSystemProgramIconWidget * | GetIconWidget () const |
void | OpenFile (UOperatingSystemFile *TargetFile, FGenericError &OutError) |
void | CloseProgram (const bool bIsFullClose, FGenericError &OutError) |
void | BringToFront (FGenericError &OutError) const |
UDraggableWindow * | GetParentWindow () const |
void | IsCompatibleWithOS (const TWeakObjectPtr< const UOperatingSystem > TestOS, FGenericError &OutError) const |
bool | CanSaveSettings () const |
void | SetParentPartition (TWeakObjectPtr< UOperatingSystemPartition > OwningPartition) |
void | OnProgramWindowStateChanged (const EOperatingSystemProgramViewState &NewState) const |
bool | IsWindowMaximized () const |
Checks whether the window of the operating system base program is maximized. | |
virtual OPERATINGSYSTEMSIMULATOR_API FString | GetSaveSlotName () const |
TOptional< FVector2D > | GetWindowPosition () const |
Retrieves the position of the window associated with the operating system program. | |
TWeakObjectPtr< UOperatingSystemPartition > | GetParentPartition () const |
Get the parent partition of the current operating system program. | |
TSoftClassPtr< UOperatingSystemProgramIconWidget > | GetIconWidgetClass () const |
Retrieves the class of the icon widget for the operating system program. | |
TSoftClassPtr< UOperatingSystemProgramWidget > | GetWidgetClass () const |
Retrieves the widget class associated with the operating system base program. This method returns the widget class that should be used to create the program widget for the specific program. | |
TSoftClassPtr< UOperatingSystemProgramSettings > | GetSettingsClass () const |
Get the settings class associated with this program. This method returns the class type of the settings object specific to this program. | |
TSoftClassPtr< UOperatingSystemProgramData > | GetDataClass () const |
Retrieves the data class associated with the program. | |
TSoftClassPtr< UOperatingSystemTaskbarButton > | GetTaskbarButtonClass () const |
Retrieves the taskbar button class associated with the program. | |
TWeakObjectPtr< UOperatingSystemProgramSettings > | GetSettings () const |
Get the settings object for the program. | |
TWeakObjectPtr< UOperatingSystemProgramData > | GetDataObj () const |
Retrieves the data object associated with the operating system program. | |
TWeakObjectPtr< UOperatingSystemTaskbarButton > | GetTaskbarButton () const |
Retrieves the taskbar button associated with the program. | |
UOperatingSystemProgramWidget * | GetProgramWidget () const |
Returns the program widget associated with the operating system program. | |
template<class T > | |
T * | GetSettings () const |
Get the settings object of type T. | |
template<class T > | |
T * | GetDataObj () const |
Returns the data object associated with the program. | |
FORCEINLINE FString | GetProgramName () const |
Returns the program name as a FString. | |
FORCEINLINE FName | GetIdentifier () const |
Returns the identifier of the program. The identifier serves as a unique identification for the program. | |
FORCEINLINE bool | IsSingleInstanceProgram () const |
Returns a boolean value indicating whether the program is a single instance program. A single instance program is a program that allows only one instance to run at a time. | |
FORCEINLINE bool | IsSystemInstalledProgram () const |
Returns a boolean value indicating whether the program is installed on the system. If the program is installed, it will return true; otherwise, it will return false. | |
FORCEINLINE uint32 | GetProcessID () const |
Retrieves the process ID of the current program. This method allows you to obtain the unique process ID of the program. | |
FORCEINLINE float | GetSpaceRequiredInMB () const |
Get the space required by the program in megabytes. This method returns the space required by the program in megabytes. | |
FORCEINLINE bool | ShouldRememberLastWindowPosition () const |
Indicates whether the program should remember the last window position. | |
OPERATINGSYSTEMSIMULATOR_API FORCEINLINE EOperatingSystemProgramCloseMethod | GetCloseMethod () const |
Returns the close method of the operating system program. | |
Protected Member Functions | |
virtual OPERATINGSYSTEMSIMULATOR_API void | OnValidate (FGenericError &OutError) const override |
OnValidate method for validating program-specific logic. | |
virtual OPERATINGSYSTEMSIMULATOR_API void | OnStart (FGenericError &OutError) override |
Called when the program starts. It should be overridden in derived classes to provide the necessary functionality for the specific program. | |
UOperatingSystemTerminalCommand * | GetCommand (const FString &TestCommand, FGenericError &OutError) const |
OPERATINGSYSTEMSIMULATOR_API bool | GetCurrentDirectoryPath (FString &OutPath) const |
void | K2_CommandFinished (const FGenericError &ErrorMessage) |
void | K2_UserChanged () |
void | K2_PromptRootPassword () |
void | K2_PromptUserContinue () |
void | K2_MessageReceivedFromCommand (const FText &CmdMsg, const EOperatingSystemTerminalMessageType &CmdMsgType) |
Protected Member Functions inherited from UOperatingSystemBaseProgram | |
virtual OPERATINGSYSTEMSIMULATOR_API void | OnClose (FGenericError &OutError) |
Called when the program is requested to be closed. It can be overridden by derived classes to perform necessary cleanup operations before the program is closed. The function receives an FGenericError& object as a parameter, which can be used to report any error that occurred during the closing process. | |
virtual OPERATINGSYSTEMSIMULATOR_API void | OnOpenFile (UOperatingSystemFile *TargetFile, FGenericError &OutError) |
Called when a file is opened in the operating system program. It provides the target file that was opened, as well as an output error parameter for reporting any errors that occurred during the file opening process. | |
virtual OPERATINGSYSTEMSIMULATOR_API void | OnThemeChanged (UOperatingSystemSettingModule_Theme *ThemePayload) |
Virtual method called when the theme is changed. | |
void | K2_OnCreate () |
void | K2_OnInstall () |
FGenericError | K2_OnStart () |
void | K2_OnClose () |
void | K2_OnSettingsLoad (UOperatingSystemProgramSettings *LoadedSettings) |
void | K2_OnOpenFile (FGenericError &OutError) |
void | K2_OnValidate (FGenericError &OutError) const |
FString | K2_GetSaveSlotName () const |
Additional Inherited Members | |
Static Public Member Functions inherited from UOperatingSystemBaseProgram | |
static UE_NODISCARD UOperatingSystemBaseProgram * | CreateProgram (TWeakObjectPtr< UOperatingSystem > OwningOS, const TSoftClassPtr< UOperatingSystemBaseProgram > &ProgramClass, FGenericError &OutError, const bool bInstalledWithOS=false) |
static OPERATINGSYSTEMSIMULATOR_API bool | IsStoreItemFree (const FOperatingSystemStoreProgramData &ProgramData) |
Public Attributes inherited from UOperatingSystemBaseProgram | |
FOnOperatingSystemProgramViewStateChanged | OnOperatingSystemProgramViewStateChanged |
The UOperatingSystemTerminal class is a subclass of UOperatingSystemBaseProgram and represents a terminal in the Operating System. It allows users to execute commands and interact with the operating system.
UOperatingSystemTerminal::UOperatingSystemTerminal | ( | ) |
bool UOperatingSystemTerminal::ChangeCurrentPath | ( | const FString & | TargetPath | ) |
Changes the current path to the specified target path.
TargetPath | The target path to change to. |
void UOperatingSystemTerminal::ChangeCurrentUser | ( | const FOperatingSystemUser & | NewUser | ) |
Changes the current user of the Operating System terminal.
This function changes the current user of the operating system terminal to the given user. If the given user is already the current user, the function returns without making any changes.
NewUser | The new user to set as the current user. |
bool UOperatingSystemTerminal::CheckRootPassword | ( | const FText & | TestPassword, |
const bool | bCaseSensitive = true ) const |
This function checks if the provided password matches the password of the root user of the operating system. If the password matches, it will process the command as the root user.
TestPassword | The password to test against the root user's password. |
bCaseSensitive | Whether the password comparison should be case-sensitive. |
void UOperatingSystemTerminal::ClearHistory | ( | ) |
Clears the history of the operating system terminal.
void UOperatingSystemTerminal::DestroyActiveCommand | ( | const FGenericError & | ErrorMessage | ) |
Destroys the active command and processes the next queued command (if any).
This function is called to destroy the active command and process the next command in the queue, if any. If the active command is a blueprint command, it calls the K2_CommandFinished function to notify the blueprint. Then, it marks the active command as garbage and sets it to nullptr. If there is no error message and there is a next command in the queue, it removes the next command from the queue and calls the ProcessCommand function to process it.
ErrorMessage | The error message to pass to the K2_CommandFinished function, if applicable |
|
protected |
Retrieves the command associated with the given test command string.
TestCommand | The test command string to match with a command. |
OutError | [out] The error message if an error occurs. |
|
inline |
Returns the set of command flag prefixes.
This method returns a reference to the set of command flag prefixes used in the operating system terminal. A command flag prefix is a character or string that is placed before a command parameter to indicate that it is a flag.
|
protected |
Retrieves the current directory path and stores it in the provided output parameter.
OutPath | [out] The output parameter to store the current directory path. |
|
inline |
Returns the multi-command operator string.
The GetMultiCommandOperatorString method returns the string representation of the multi-command operator. If the multi-command operator is set to None, the method returns the string " && ". Otherwise, it retrieves the string representation of the multi-command operator, removes any spaces, and formats it using the FString::Printf function with the format specifier "%s". The formatted string is then returned.
bool UOperatingSystemTerminal::GetNextCommandFromHistory | ( | FString & | OutCommand | ) | const |
Retrieves the next command from the history of the operating system terminal.
OutCommand | [out] - The next command retrieved from the terminal history. |
bool UOperatingSystemTerminal::GetPreviousCommandFromHistory | ( | FString & | OutCommand | ) | const |
Retrieves the previous command from the command history.
OutCommand | [out] - The output parameter that will contain the previous command if it exists |
bool UOperatingSystemTerminal::HasRepository | ( | ) | const |
Checks if the operating system terminal has a repository.
It will return true if there is at least one valid repository class, otherwise it will return false.
It first checks if the operating system is Unix. If it is, it retrieves the repository classes from the Unix operating system object. It then iterates through each repository class and checks if it is null. If at least one repository class is not null, the function returns true. If all repository classes are null or the operating system is not Unix, the function returns false.
bool UOperatingSystemTerminal::IsTerminalBusy | ( | ) | const |
Checks if the terminal is busy or not. A terminal is considered busy if there is an active command being executed.
|
protected |
A function that is called when a command finishes execution.
ErrorMessage | The error message generated during the command execution. |
|
protected |
BlueprintImplementableEvent function for receiving messages from the operating system terminal. This function is tied to a blueprint and is called when a message is received from the operating system terminal.
CmdMsg | The received message from the operating system terminal as a FText object |
CmdMsgType | The type of the received message as an EOperatingSystemTerminalMessageType enumeration value |
|
protected |
Event triggered when the root password is prompted.
|
protected |
Event triggered when user wants to continue.
|
protected |
This function is called when the user is changed. It can be implemented in blueprints to handle the event of user change in the operating system terminal.
void UOperatingSystemTerminal::MessageReceivedFromCommand | ( | const FText & | CmdMsg, |
const EOperatingSystemTerminalMessageType & | CmdMsgType ) |
Function to handle received messages from the command. This function is called when a message is received from the command. It can be used to handle and process the message in the operating system terminal.
CmdMsg | The message received from the command. |
CmdMsgType | The type of the message received. |
|
overrideprotectedvirtual |
Called when the program starts. It should be overridden in derived classes to provide the necessary functionality for the specific program.
OutError | A reference to the FGenericError object, used to report any errors that occur during startup. |
Reimplemented from UOperatingSystemBaseProgram.
|
overrideprotectedvirtual |
OnValidate method for validating program-specific logic.
This method is a virtual function that can be overridden by derived classes to perform additional validation specific to the program's requirements. The method takes an FGenericError& parameter, which can be used to report any validation errors encountered during the validation process.
OutError | The error object used to report any validation errors. |
Reimplemented from UOperatingSystemBaseProgram.
void UOperatingSystemTerminal::ProcessCommand | ( | const FString & | TestCommand, |
FGenericError & | OutError ) |
Process the given command in the Operating System terminal If the terminal is busy, it sets the output error indicating that the terminal is busy and cannot run new commands. If the command is empty, it destroys the active command and returns. If the command is not recognized, it sets the output error indicating that the command is not recognized. If the command supports multiple commands and contains a multi-command operator, it splits the command into multiple commands and processes them one by one.
TestCommand | The command to be processed. |
OutError | The output error if any error occurs during the command processing |
void UOperatingSystemTerminal::PromptRootPassword | ( | ) |
Prompts the user for the root password.
void UOperatingSystemTerminal::PromptUserContinue | ( | ) |
Prompts the user to continue the execution in the operating system terminal.
|
inline |
Gets the value of the bValidateFlags flag.
This method returns the value of the bValidateFlags flag. The bValidateFlags flag is used to determine whether the flags are being validated or not.
void UOperatingSystemTerminal::VerifyUserPrompt | ( | const bool | bIsYes | ) | const |
Verifies the user prompt and takes the appropriate action. It checks if the user prompt is "Yes" or "No" and performs the necessary action based on the value of bIsYes parameter.
bIsYes | A boolean indicating if the user prompt is "Yes" or "No". |
|
protected |
Determines if the OperatingSystemTerminal supports multiple commands.
If set to true, the OperatingSystemTerminal supports executing multiple commands at once. If set to false, the OperatingSystemTerminal only supports executing one command at a time.
|
protected |
The flag to indicate whether to validate the operating system terminal.
|
protected |
Soft Object Pointer representing the UOperatingSystemCmdCollection for the operating system terminal.
|
protected |
List of prefixes that must be included when adding flags.
|
protected |
String to use for separating multiple commands. E.g: pwd && ls. NOTE: Does not support space so if you have space, it is automatically removed.