SDA Component

Properties   Methods   Events   Config Settings   Errors  

The SDA component can be used to create a self-decrypting archive which will run natively on Windows platforms.

Syntax

nsoftware.IPWorksOpenPGP.Sda

Remarks

The component uses the Deflate algorithm specified in RFC 1951 for compression, and then creates a self-decrypting executable archive. This exe will bring up a dialog that will allow the user to select the target directory in which to decompress the files. There is also an optional splash screen that may be displayed before decompression. The text for this splash screen may be set with the BannerText property. You can also set the text that appears on the title bar of each dialog box using the CaptionText property.

Example (Creating a Self-Decrypting Archive)

component.ArchiveFile = "c:\test.exe" component.RecurseSubdirectories = true component.SourceDirectory = "c:\foo\" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA() component.ArchiveFile = "c:\test.exe" component.SourceFile = "c:\foo\bar.dat" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA()

Note: When creating a self-decrypting archive which exceeds 4 GB or more of uncompressed data or which contains more than 64K files, the component will create a 64-bit archive.

The self-decrypting archive that is created by the SDA component is a Windows application. However, there are command line options available if you wish to batch multiple files. The options are:

Option NameDescription
targetpathPath to decompress the archive to. This overrides the ExtractToPath. "." indicates the current directory (if no ExtractToPath was specified and no targetpath is given, the archive is decompressed to the current directory).
overwriteIf set to true, the archive will automatically overwrite existing files (thus suppressing the message box asking you to overwrite or not)
displaymessageIf set to false, it will suppress the display of the "Extraction Complete" message after the archive has finished (this may also be accomplished by setting the CompleteMessage config setting to "").
openfileIf set to false, this option will override opening the file indicated by FileToExecute. (Alternatively, set FileToExecute to "").
passwordThe password used to decrypt the archive. If the archive is not encrypted this option is ignored. However if the archive is encrypted and no password is supplied, decompression will fail.

For example, the following suppresses all questions and message boxes, and decompress to the current directory, use the following options: SDAExtractor /targetpath="." /overwrite=1 /displaymessage=0 /openfile=0 /password=pass

Note that if you run the self-decrypting archive with any command line options, the pop up message box containing the BannerText will be suppressed.

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

ArchiveFileThe name of the self-decrypting archive to create.
BannerTextOptional banner text to show before the self-extraction starts.
CaptionTextOptional caption (title) text for the self-extractor dialogs.
CompressionLevelThe compression level to use.
ExtractToPathOptional target directory for the self-extractor.
FileToExecuteOptional file to execute (open) after the archive is extracted.
PasswordAn optional password for the self-decrypting archive.
RecurseSubdirectoriesWhether or not to recurse into subdirectories during archive creation.
SourceDirectoryDirectory to be compressed into a self-decrypting archive.
SourceFileFile to be compressed into a self-decrypting archive.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

ConfigSets or retrieves a configuration setting.
CreateSDACompresses the files and creates a self-decrypting archive.
ResetResets the component.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

ErrorInformation about non-fatal errors.
ProgressFired as progress is made.
StatusShows the progress of the operation.

Config Settings


The following is a list of config settings for the component with short descriptions. Click on the links for further details.

CompleteMessageMessage to notify user that extraction has finished normally.
ExtractorStubPath to optional self-extractor executable stub.
FileToExecuteParamsList of parameters to pass to FileToExecute.
InstallationModeThis setting will install to ExtractToPath, run FileToExecute, and then remove the extracted files.
LogLevelSpecifies the level of detail that is logged.
RequireAdminPrivsSpecifies whether the created executable requires Administrator privileges.
SilentExtractionSpecifies whether the archive should hide all UI interaction while extracting.
BuildInfoInformation about the product's build.
GUIAvailableTells the component whether or not a message loop is available for processing events.
LicenseInfoInformation about the current license.
MaskSensitiveWhether sensitive data is masked in log messages.
UseInternalSecurityAPITells the component whether or not to use the system security libraries or an internal implementation.

ArchiveFile Property (SDA Component)

The name of the self-decrypting archive to create.

Syntax

public string ArchiveFile { get; set; }
Public Property ArchiveFile As String

Default Value

""

Remarks

This property specifies the name of the archive to be written when CreateSDA is called. Any pre-existing archive file will be overwritten.

The filename may be specified with or without a path. Paths may be relative or absolute, and should be specified in the format native to the host operating system. The filename should be specified with the appropriate ".exe" extension. An extension will not automatically be appended by the component.

If the file cannot be written a trappable error will be generated.

Example (Creating a Self-Decrypting Archive)

component.ArchiveFile = "c:\test.exe" component.RecurseSubdirectories = true component.SourceDirectory = "c:\foo\" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA() component.ArchiveFile = "c:\test.exe" component.SourceFile = "c:\foo\bar.dat" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA()

Note: When creating a self-decrypting archive which exceeds 4 GB or more of uncompressed data or which contains more than 64K files, the component will create a 64-bit archive.

BannerText Property (SDA Component)

Optional banner text to show before the self-extraction starts.

Syntax

public string BannerText { get; set; }
Public Property BannerText As String

Default Value

""

Remarks

If this property is set, a dialog box will pop up displaying the contents of this property as soon as the SDA executable is run. If this property is set to an empty string (default) no banner dialog will be displayed.

Example (Creating a Self-Decrypting Archive)

component.ArchiveFile = "c:\test.exe" component.RecurseSubdirectories = true component.SourceDirectory = "c:\foo\" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA() component.ArchiveFile = "c:\test.exe" component.SourceFile = "c:\foo\bar.dat" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA()

CaptionText Property (SDA Component)

Optional caption (title) text for the self-extractor dialogs.

Syntax

public string CaptionText { get; set; }
Public Property CaptionText As String

Default Value

""

Remarks

This property contains the text which will appear on the title bar of the dialog boxes that appear when running the SDA executable file. If this property is not set, "IPWorks PG Self Extractor - www.nsoftware.com" will appear in the title bar.

Example (Creating a Self-Decrypting Archive)

component.ArchiveFile = "c:\test.exe" component.RecurseSubdirectories = true component.SourceDirectory = "c:\foo\" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA() component.ArchiveFile = "c:\test.exe" component.SourceFile = "c:\foo\bar.dat" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA()

CompressionLevel Property (SDA Component)

The compression level to use.

Syntax

public int CompressionLevel { get; set; }
Public Property CompressionLevel As Integer

Default Value

4

Remarks

This property specifies the level of compression to be used, between 0 and 6. Higher values will cause the component to compress better; lower values will cause the component to compress faster. A value of 0 will store the file without compression.

ExtractToPath Property (SDA Component)

Optional target directory for the self-extractor.

Syntax

public string ExtractToPath { get; set; }
Public Property ExtractToPath As String

Default Value

""

Remarks

If set to empty string (default), the self-extractor will attempt to extract files into a subdirectory of the directory it is being executed from.

The name of the subdirectory is derived from the name of the self-decrypting archive by removing its extension.

FileToExecute Property (SDA Component)

Optional file to execute (open) after the archive is extracted.

Syntax

public string FileToExecute { get; set; }
Public Property FileToExecute As String

Default Value

"."

Remarks

This property specifies an executable file which will be run after the archive has completed decompressing. This must be a relative path to a file located within ExtractToPath. If this property is set to ".", the folder to which the archive has been decompressed will open in Windows Explorer. If this property is set to "" (empty string), the extractor will close and take no action.

Password Property (SDA Component)

An optional password for the self-decrypting archive.

Syntax

public string Password { get; set; }
Public Property Password As String

Default Value

""

Remarks

This property specifies a case-sensitive password used to encrypt or decrypt the archive. If set to an empty string (default), no encryption is used.

The maximum supported length of the password is 128 characters.

Example (compressing an SDA archive):

component.ArchiveFile = "c:\test.exe" component.RecurseSubdirectories = true component.SourceDirectory = "c:\foo" component.Password = "nsoftware" component.CreateSDA()

RecurseSubdirectories Property (SDA Component)

Whether or not to recurse into subdirectories during archive creation.

Syntax

public bool RecurseSubdirectories { get; set; }
Public Property RecurseSubdirectories As Boolean

Default Value

True

Remarks

If this property is set to true, when calling CreateSDA the component will recurse into all the subdirectories under SourceDirectory and include them in the self extracting archive. If this property is false, only the files in SourceDirectory will be included in the archive.

SourceDirectory Property (SDA Component)

Directory to be compressed into a self-decrypting archive.

Syntax

public string SourceDirectory { get; set; }
Public Property SourceDirectory As String

Default Value

""

Remarks

This property specifies the name of the directory containing the files to be compressed. This may be a local or absolute path. If the RecurseSubdirectories property is true, all the subdirectories under SourceDirectory will be recursed into, and those files will also be compressed.

Example (Creating a Self-Decrypting Archive)

component.ArchiveFile = "c:\test.exe" component.RecurseSubdirectories = true component.SourceDirectory = "c:\foo\" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA() component.ArchiveFile = "c:\test.exe" component.SourceFile = "c:\foo\bar.dat" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA()

SourceFile Property (SDA Component)

File to be compressed into a self-decrypting archive.

Syntax

public string SourceFile { get; set; }
Public Property SourceFile As String

Default Value

""

Remarks

This property specifies the name of a single file to be compressed. When both SourceFile and SourceDirectory are set, only SourceDirectory is used.

Example (Creating a Self-Decrypting Archive)

component.ArchiveFile = "c:\test.exe" component.RecurseSubdirectories = true component.SourceDirectory = "c:\foo\" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA() component.ArchiveFile = "c:\test.exe" component.SourceFile = "c:\foo\bar.dat" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA()

Config Method (SDA Component)

Sets or retrieves a configuration setting.

Syntax

public string Config(string configurationString);

Async Version
public async Task<string> Config(string configurationString);
public async Task<string> Config(string configurationString, CancellationToken cancellationToken);
Public Function Config(ByVal ConfigurationString As String) As String

Async Version
Public Function Config(ByVal ConfigurationString As String) As Task(Of String)
Public Function Config(ByVal ConfigurationString As String, cancellationToken As CancellationToken) As Task(Of String)

Remarks

Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

CreateSDA Method (SDA Component)

Compresses the files and creates a self-decrypting archive.

Syntax

public void CreateSDA();

Async Version
public async Task CreateSDA();
public async Task CreateSDA(CancellationToken cancellationToken);
Public Sub CreateSDA()

Async Version
Public Sub CreateSDA() As Task
Public Sub CreateSDA(cancellationToken As CancellationToken) As Task

Remarks

Invoking CreateSDA creates the archive specified by ArchiveFile. When the method is called, all files specified by SourceDirectory will be compressed and written to ArchiveFile. If RecurseSubdirectories is true, all the subdirectories under SourceDirectory and the files they contain will also be compressed and written to ArchiveFile.

If ArchiveFile exists when you call CreateSDA it will be overwritten.

As the files in SourceDirectory are being compressed, the Progress event will fire periodically to indicate how many bytes have been processed and the percentage of compression that has been completed.

To include your own custom text on the title bar of all of the self-extractor dialog boxes, set the CaptionText before calling CreateSDA. Setting the optional BannerText property will cause a small dialog to pop up when the self-extractor is run. You can put in a description of the contents, instructions, or any text you like.

Example (Creating a Self-Decrypting Archive)

component.ArchiveFile = "c:\test.exe" component.RecurseSubdirectories = true component.SourceDirectory = "c:\foo\" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA() component.ArchiveFile = "c:\test.exe" component.SourceFile = "c:\foo\bar.dat" component.CaptionText = "Testing SDA" component.BannerText = "Press continue to decompress the archive." component.CreateSDA()

Note: When creating a self-decrypting archive which exceeds 4 GB or more of uncompressed data or which contains more than 64K files, the component will create a 64-bit archive.

The self-decrypting archive that is created by the SDA component is a Windows application. However, there are command line options available if you wish to batch multiple files. The options are:

Option NameDescription
targetpathPath to decompress the archive to. This overrides the ExtractToPath. "." indicates the current directory (if no ExtractToPath was specified and no targetpath is given, the archive is decompressed to the current directory).
overwriteIf set to true, the archive will automatically overwrite existing files (thus suppressing the message box asking you to overwrite or not)
displaymessageIf set to false, it will suppress the display of the "Extraction Complete" message after the archive has finished (this may also be accomplished by setting the CompleteMessage config setting to "").
openfileIf set to false, this option will override opening the file indicated by FileToExecute. (Alternatively, set FileToExecute to "").
passwordThe password used to decrypt the archive. If the archive is not encrypted this option is ignored. However if the archive is encrypted and no password is supplied, decompression will fail.

For example, the following suppresses all questions and message boxes, and decompress to the current directory, use the following options: SDAExtractor /targetpath="." /overwrite=1 /displaymessage=0 /openfile=0 /password=pass

Note that if you run the self-decrypting archive with any command line options, the pop up message box containing the BannerText will be suppressed.

Reset Method (SDA Component)

Resets the component.

Syntax

public void Reset();

Async Version
public async Task Reset();
public async Task Reset(CancellationToken cancellationToken);
Public Sub Reset()

Async Version
Public Sub Reset() As Task
Public Sub Reset(cancellationToken As CancellationToken) As Task

Remarks

Reset resets the state of the component. All properties will be set to their default values, and any files open will be closed.

Error Event (SDA Component)

Information about non-fatal errors.

Syntax

public event OnErrorHandler OnError;

public delegate void OnErrorHandler(object sender, SdaErrorEventArgs e);

public class SdaErrorEventArgs : EventArgs {
  public string Description { get; }
  public int ErrorCode { get; }
  public int Index { get; }
  public string Filename { get; }
  public bool Ignore { get; set; }
}
Public Event OnError As OnErrorHandler

Public Delegate Sub OnErrorHandler(sender As Object, e As SdaErrorEventArgs)

Public Class SdaErrorEventArgs Inherits EventArgs
  Public ReadOnly Property Description As String
  Public ReadOnly Property ErrorCode As Integer
  Public ReadOnly Property Index As Integer
  Public ReadOnly Property Filename As String
  Public Property Ignore As Boolean
End Class

Remarks

The Error event is fired when non-fatal errors occur during compression or decompression. Note that if this event is fired during decompression this may indicate that the archive is corrupt.

By default these errors will cause the component to fail with an exception. The exception may be overridden by setting Ignore to true. This will cause the error to be ignored, the file will be skipped if necessary, and the component will continue operation.

ErrorCode will correspond to one of the following errors:

1Bad or missing CRC-32 checksum.
2Failed to set creation date of a file.
111Can't open file for read (skipping).

Description contains a textual description of the error. Index and Filename contain the array index (where appropriate) and filename of the file being processed at the time of the error.

Progress Event (SDA Component)

Fired as progress is made.

Syntax

public event OnProgressHandler OnProgress;

public delegate void OnProgressHandler(object sender, SdaProgressEventArgs e);

public class SdaProgressEventArgs : EventArgs {
  public string Filename { get; }
  public long BytesProcessed { get; }
  public int PercentProcessed { get; }
}
Public Event OnProgress As OnProgressHandler

Public Delegate Sub OnProgressHandler(sender As Object, e As SdaProgressEventArgs)

Public Class SdaProgressEventArgs Inherits EventArgs
  Public ReadOnly Property Filename As String
  Public ReadOnly Property BytesProcessed As Long
  Public ReadOnly Property PercentProcessed As Integer
End Class

Remarks

The Progress event is automatically fired as compression is performed.

Filename contains the name of the file being written.

BytesProcessed contains the total number of uncompressed bytes processed.

PercentProcessed contains the percent of uncompressed bytes processed, corresponding roughly to the running time of the operation.

Status Event (SDA Component)

Shows the progress of the operation.

Syntax

public event OnStatusHandler OnStatus;

public delegate void OnStatusHandler(object sender, SdaStatusEventArgs e);

public class SdaStatusEventArgs : EventArgs {
  public string Message { get; }
}
Public Event OnStatus As OnStatusHandler

Public Delegate Sub OnStatusHandler(sender As Object, e As SdaStatusEventArgs)

Public Class SdaStatusEventArgs Inherits EventArgs
  Public ReadOnly Property Message As String
End Class

Remarks

The event is fired for informational and logging purposes only. It may be used to track the progress of an operation.

The level of detail is controlled by the LogLevel setting.

Config Settings (SDA Component)

The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

SDA Config Settings

CompleteMessage:   Message to notify user that extraction has finished normally.

When the self-decrypting executable created by this component successfully finishes extracting the files contained within itself, it may optionally display a Message Box indicating that it's finished. By default, the message "Extraction Complete." is displayed. You may change this to your own custom message. However, any message longer than 400 characters will be truncated. To disable this message, set the CompleteMessage configuration setting to "" (empty string).

ExtractorStub:   Path to optional self-extractor executable stub.

Normally the component loads a self-extractor stub from an internal resource and uses it to create the self-decrypting executable.

If a path is specified in this setting, the file indicated by that path is used instead.

This setting allows you to specify a custom self-extractor. The compiled self-extractor stub is available on demand. Resources such as icons and text may then be modified.

This may also be used to specify if the resulting executable should be 32 bit or 64 bit by setting this to either "*32bit" or "*64bit".

FileToExecuteParams:   List of parameters to pass to FileToExecute.

This setting allows you to pass command-line parameters to the executable file indicated by FileToExecute. Parameters should be in the form of a space-separated list.

InstallationMode:   This setting will install to ExtractToPath, run FileToExecute, and then remove the extracted files.

Is set to true, this setting makes the self-extractor behave as an installer by installing to a temp directory, running the desired executable, and removing the extracted files upon completion. The default value is false.

LogLevel:   Specifies the level of detail that is logged.

This setting controls the level of detail that is logged through the Status event. Possible values are:

0 (none)No events are logged.
1 (info - default)Informational events are logged.
2 (verbose)Detailed data is logged.
3 (debug)Debug data is logged.
RequireAdminPrivs:   Specifies whether the created executable requires Administrator privileges.

This setting specifies whether the executable created by the component requires Administrator privileges to execute.

This setting is false by default.

SilentExtraction:   Specifies whether the archive should hide all UI interaction while extracting.

This setting specifies whether to hide the progress bar and success window when the archive executable is run. Setting this config to true is equivalent to passing the '/s' command-line parameter to the archive executable.

This setting is false by default.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

GUIAvailable:   Whether or not a message loop is available for processing events.

In a GUI-based application, long-running blocking operations may cause the application to stop responding to input until the operation returns. The component will attempt to discover whether or not the application has a message loop and, if one is discovered, it will process events in that message loop during any such blocking operation.

In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting GUIAvailable to false will ensure that the component does not attempt to process external events.

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a component is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).
  • Last Valid Build: The last valid build number for which the license will work.
MaskSensitive:   Whether sensitive data is masked in log messages.

In certain circumstances it may be beneficial to mask sensitive data, like passwords, in log messages. Set this to true to mask sensitive data. The default is true.

This setting only works on these components: AS3Receiver, AS3Sender, Atom, Client(3DS), FTP, FTPServer, IMAP, OFTPClient, SSHClient, SCP, Server(3DS), Sexec, SFTP, SFTPServer, SSHServer, TCPClient, TCPServer.

UseInternalSecurityAPI:   Whether or not to use the system security libraries or an internal implementation.

When set to false, the component will use the system security libraries by default to perform cryptographic functions where applicable. In this case, calls to unmanaged code will be made. In certain environments, this is not desirable. To use a completely managed security implementation, set this setting to true.

Setting this configuration setting to true tells the component to use the internal implementation instead of using the system security libraries.

On Windows, this setting is set to false by default. On Linux/macOS, this setting is set to true by default.

If using the .NET Standard Library, this setting will be true on all platforms. The .NET Standard library does not support using the system security libraries.

Note: This setting is static. The value set is applicable to all components used in the application.

When this value is set, the product's system dynamic link library (DLL) is no longer required as a reference, as all unmanaged code is stored in that file.

Trappable Errors (SDA Component)

Errors

The following errors may be generated by the component. Note that frequently the error message will contain more specific information than what is listed here.

Note that some non-fatal errors may be trapped and explicitly ignored in the Error event. This will allow the component to continue operation even in case of error.

SDA Errors

105   Password is required to create SDA.
111   Can't open file for read.
112   Can't open file for write.
115   Can't create empty archive.
118   The maximum size of the archive has been exceeded.
119   The archive must be specified.
120   The component is busy.
150   An I/O error has occurred (details follow).
151   Cannot find resource (details follow).
152   Cannot update resource (details follow).