# Maintainer: nezu <nezu@nezu.cc>
pkgname=lcn-pro-patched
_pkgname=lcn-pro
pkgver=6.9.5
pkgrel=1
pkgdesc="PC program for setting up LCN modules - patched"
arch=('x86_64')
url="https://www.lcn.eu/en/service/software-2/"
license=('custom')
options=(!debug !strip)
depends=(wine)
makedepends=(gendesk icoutils 7zip)
provides=('lcn-pro')
conflicts=('lcn-pro')
_url="https://vaclive.party/software/lcn-pro/releases/download/${pkgver}"
source=(
  "LCN-PRO-${pkgver}_Setup.exe::$_url/LCN-PRO-${pkgver}_Setup.exe"
  "LCN-PRO-${pkgver}_Setup.exe.asc::$_url/LCN-PRO-${pkgver}_Setup.exe.asc"
  "LCNPRO-${pkgver}_patched.exe::$_url/LCNPRO_patched.exe"
  "LCNPRO-${pkgver}_patched.exe.asc::$_url/LCNPRO_patched.exe.asc"
  "lcn-pro.sh"
)
sha256sums=('f3312db3848dbe29af0e015279570209e765b79780a7aec30a33c48dc10d9e3a'
  'SKIP'
  '4d0b356444afdb60399b4a7b959d8c8cfb76bade4af84bad037576f78fe41219'
  'SKIP'
  'fe1761f84dee22e2c04f2ec4dfbf9fbfd850076295cf6889ac44d6a340b0b610')
validpgpkeys=('09BE40243217978201A0440E101BA3F4C612AA41') # nezu <nezu@nezu.cc>

prepare() {
  # extract the installer
  7z x -y LCN-PRO-${pkgver}_Setup.exe -olcn-pro

  # extract the icon out of the executable
  wrestool -x -n MAINICON lcn-pro/LCNPRO.exe -o lcn-pro.ico

  # get the highest quality PNG from the icon file
  icotool -x lcn-pro.ico -i 1 -o lcn-pro.png

  # generate a .desktop file
  gendesk -f -n \
    --name "LCN-PRO" \
    --pkgname "$_pkgname" \
    --pkgdesc "$pkgdesc" \
    --exec lcn-pro \
    --icon lcn-pro.png \
    --categories "Utility;Network;HardwareSettings"
}

package() {
  install -d "$pkgdir"/usr/share/"$_pkgname"
  cp -a lcn-pro/{*.dll,Data,locale} "$pkgdir"/usr/share/"$_pkgname"
  find "$pkgdir"/usr/share -type f -exec chmod 644 "{}" \;
  find "$pkgdir"/usr/share -type d -exec chmod 755 "{}" \;
  install -Dm755 LCNPRO-${pkgver}_patched.exe "$pkgdir"/usr/share/"$_pkgname"/LCNPRO.exe

  install -Dm755 lcn-pro.sh "$pkgdir"/usr/bin/lcn-pro

  install -Dm644 lcn-pro.png "$pkgdir"/usr/share/pixmaps/lcn-pro.png
  install -Dm644 lcn-pro.desktop "$pkgdir"/usr/share/applications/lcn-pro.desktop
}