getExternalDriveHardwareCode static method

String getExternalDriveHardwareCode(
  1. LicenseHardwareCodeType hardwareCodeType,
  2. String? externalDrivePath
)

Retrieves the hardware code of the external drive you run the library on. This function works on Windows only.

param hardwareCodeType The requested hardware code type. Must be windowsUsb. param externalDrivePath On Windows to activate a license on a USB device, it must contain the path to the requested USB drive (e.g 'G:'). return The device hardware code. throws DocumentException An error has occurred during Document Library execution.

Implementation

static String getExternalDriveHardwareCode(LicenseHardwareCodeType hardwareCodeType, String? externalDrivePath) {
  Pointer<Char> pCode = calloc.allocate(256);
  Pointer<Int> pCodeSize = calloc.allocate(1);
  pCodeSize[0] = 256;
  Pointer<Char>? pExternalDrivePath = externalDrivePath?.toNativeUtf8().cast<Char>();
  try {
    var err = documentSDK.id3DocumentLicense_GetExternalDriveHardwareCode(hardwareCodeType.value, pCode, pCodeSize, pExternalDrivePath ?? nullptr);
    if (err == DocumentError.insufficientBuffer.value) {
      calloc.free(pCode);
      pCode = calloc.allocate(pCodeSize.value);
      err = documentSDK.id3DocumentLicense_GetExternalDriveHardwareCode(hardwareCodeType.value, pCode, pCodeSize, pExternalDrivePath ?? nullptr);
      if (err != DocumentError.success.value) {
        throw DocumentException(err);
      }
    }
    final vCode = utf8.decode(Uint8List.fromList(pCode.cast<Uint8>().asTypedList(pCodeSize.value)));
    return vCode;
  } finally {
    calloc.free(pCode);
    calloc.free(pCodeSize);
    if (pExternalDrivePath != null) {
      calloc.free(pExternalDrivePath);
    }
  }
}