Other Functions

The following functions are available globally.

  • Copies source to target. Tries to use the most optimal implementation.

    Declaration

    Swift

    public func copyFile(
            source: VirtualFile,
            target: TargetFile,
            overwrite: Bool,
            progress: @escaping (Int) -> Bool = { _ in true }
    ) throws
  • Copies source to target using generic file streams.

    - Parameter overwrite: `true` if the target file may be overwritten.
    If false, an exception will occur if the target file already exists.
    
    - Parameter mode: the file mode of the newly created file. Should contain either `S_IFLNK` or `S_IFREG` flag.
    
    - Parameter bufferSize: the intermediate buffer size in bytes.
    
    - Parameter progress: the progress callback.
        The passed `Int` is a number of the bytes copied.
        Return `false` if you want to stop copying, `true` otherwise.
    

    Declaration

    Swift

    public func copyFileUsingStreams(
            source: VirtualFile,
            target: TargetFile,
            overwrite: Bool,
            mode: mode_t,
            bufferSize: Int = DEFAULT_BUFFER_SIZE,
            progress: (Int) -> Bool = { _ in true }
    ) throws
  • Copy input stream to output.

    - Parameter bufferSize: the intermediate buffer size in bytes.
    
    - Parameter progress: the progress callback.
        The passed `Int` is a number of the bytes copied.
        Return `false` if you want to stop copying, `true` otherwise.
    

    Declaration

    Swift

    public func copyStreams(
            input: FileInputStream,
            output: FileOutputStream,
            bufferSize: Int = DEFAULT_BUFFER_SIZE,
            progress: (Int) -> Bool = { _ in true }
    ) throws
  • Show an exception alert dialog.

    Declaration

    Swift

    public func showExceptionAlert(_ error: Error)
  • Show an exception alert dialog with a additional message text.

    Declaration

    Swift

    public func showExceptionAlert(_ error: Error, _ message: String)
  • Show a single button alert dialog.

    Declaration

    Swift

    public func showAlert(
        _ level: NSAlert.Style,
        _ message: String,
        description: String? = nil,
        buttonText: String = "Close"
    )
  • Show a Yes/No two button alert dialog.

    Declaration

    Swift

    public func showOkCancelDialog(
        _ level: NSAlert.Style,
        _ message: String,
        description: String? = nil
    ) -> Bool
  • Show a Yes/No two button alert dialog.

    Declaration

    Swift

    public func showYesNoDialog(
        _ level: NSAlert.Style,
        _ message: String,
        description: String? = nil,
        first: String = "Yes",
        second: String = "No"
    ) -> Bool
  • Cache the files asynchronously with the progress window.

    Note that onComplete is not called if the caching was cancelled by user.

    Declaration

    Swift

    public func cacheFiles(
            _ files: [VirtualFile],
            _ context: WeakActionContext,
            onComplete: @escaping (Result<[(originalFile: VirtualFile, localFile: LocalFile)]>) -> ()
    )

    Parameters

    files

    the files to cache. Some of them may be local, they won’t be cached.

    context

    an action context.

    onComplete

    handler to call when the caching is complete (or there was an error).