Interface DelphiResources


public interface DelphiResources
Delphi resource and module manager
  • Method Details

    • getModuleDirectory

      Path getModuleDirectory()
      Gets the module directory.

      The returned path is the modules directory inside the Delphi plugin's data folder.

      Returns:
      Module directory
    • createDirectoryModule

      DirectoryModule createDirectoryModule(@NotNull @NotNull Path path)
      Create a directory module with the specified path as the directory.
      Parameters:
      path - Directory path
      Returns:
      Created module.
      Throws:
      NullPointerException - If path is null
    • createZipModule

      Result<ZipModule, DelphiException> createZipModule(@NotNull @NotNull Path zipPath)
      Create a zip module from the specified zipPath.

      This method will attempt to immediately open and read the zip file into memory, and will return an erroneous result if it fails to do so for any reason.

      Error messages
      Format Description
      "No Such File" zipPath file doesn't exist
      "Access Denied: %reason%" Read access was denied to the zip file
      "IO Error: %message%" Threw an IOException
      Parameters:
      zipPath - Zip file path
      Returns:
      A successful result if the zip archive was opened, otherwise an erroneous result.
      Throws:
      NullPointerException - If zipPath is null
    • registerModule

      boolean registerModule(@NotNull @NotNull String moduleName, @NotNull @NotNull ResourceModule module)
      Registers a module.

      This method will return false if another module has already been registered with the specified moduleName.

      Parameters:
      moduleName - Name of the module.
      module - Module.
      Returns:
      true, if the module was registered, false, if the specified name is already in use.
      Throws:
      NullPointerException - If either moduleName or module is null.
      IllegalArgumentException - If the module name doesn't pass the ResourcePath.validateQuery(String) check.
    • unregisterModule

      @Contract("null -> false") boolean unregisterModule(@Nullable @Nullable String moduleName)
      Unregisters a module

      When a module is unregistered, all pages open to the specified module are closed as well.

      This method only unregisters modules that were registered with the registerModule(String, ResourceModule) method. Any modules inside the getModuleDirectory() cannot be unregistered.

      Parameters:
      moduleName - Module name
      Returns:
      true if a module with the moduleName was found and was removed, false otherwise.
    • findModule

      Result<ResourceModule, DelphiException> findModule(String moduleName)
      Attempts to locate a module.

      This will first attempt to find a module registered with registerModule(String, ResourceModule). No registered module is found, it will attempt to find a directory or a zip archive with the specified name.

      This method assumes the input has no file extension.

      Result errors
      Error code Description
      ERR_EMPTY_MODULE_NAME The module name was empty or null
      ERR_MODULE_DIRECTORY_NOT_FOUND Couldn't find any registered modules matching the name, and the module directory doesn't exist
      ERR_MODULE_ZIP_ACCESS_DENIED Attempted to open a .zip module file, but access was denied
      ERR_IO_ERROR An IO error occurred while trying to read a .zip module file
      ERR_MODULE_UNKNOWN No registered module, directory or .zip module was found that matched the specified moduleName
      Parameters:
      moduleName - Name of the module
      Returns:
      Found module, or an erroneous result if no module was found.
    • getModuleNames

      List<String> getModuleNames()
      Gets an array list of all module names. This list inclues all registered modules as well as all directory and zip archive modules installed in getModuleDirectory()
      Returns:
      Module name list.