
const $ = require('../common')
const {join} = require('path').posix

module.exports = {
  sign: async function (arch, buildPath) {
    let exeName = `${$.appName()}.exe`;
    let exePath = join(buildPath, exeName);
    // see package function
    // forward-slashes are doubled because of mingw, see http://www.mingw.org/wiki/Posix_path_conversion
    let signParams = '//v //s MY //n "itch corp." //fd sha256 //tr http://timestamp.comodoca.com/?td=sha256 //td sha256'
    let signtoolPath = 'vendor/signtool.exe'
    $(await $.sh(`${signtoolPath} sign ${signParams} ${exePath}`))
  },

  package: async function (arch, buildPath) {
    $.say('Creating installer + nupkg full/delta files')
    $(await $.sh(`mkdir -p ${$.winstallerPath(arch)}`))
    const appName = $.appName();
    const appVersion = $.buildVersion()
    const outDir = join('build', 'v' + appVersion)
    const companyName = 'Itch Corp'
    const iconsPath = join('release', 'images', appName + '-icons')
    const icoPath = join(iconsPath, 'itch.ico')
    const installerGifPath = 'release/images/installer.gif'
    const electronInstaller = require('electron-winstaller')
    const electronInstallerOpts = {
      authors: companyName,
      exe: appName + '.exe',
      description: 'The best way to play itch.io games',
      version: appVersion,
      title: appName,
      // sic. it's really itch.ico, even for kitch
      iconUrl: 'http://raw.githubusercontent.com/itchio/itch/master/release/images/' + appName + '-icons/itch.ico',
      loadingGif: installerGifPath,
      setupIcon: icoPath,
      remoteReleases: 'https://github.com/itchio/' + appName,
      // see sign function
      signWithParams: '/v /s MY /n "itch corp." /fd sha256 /tr http://timestamp.comodoca.com/?td=sha256 /td sha256',
      noMsi: true,
      appDirectory: join(outDir, appName + '-win32-ia32'),
      outputDirectory: process.env.CI_WINDOWS_INSTALLER_PATH || join('build', 'squirrel-ia32')
    }
    await electronInstaller.createWindowsInstaller(electronInstallerOpts)

    $.say('Copying artifacts to packages/')
    $(await $.sh(`cp -vf ${$.winstallerPath(arch)}/${$.appName()}-${$.buildVersion()}*.nupkg ${$.winstallerPath(arch)}/*.exe ${$.winstallerPath(arch)}/RELEASES packages/`))
  }
}

@@ -1876,86 +1876,103 @@
 ry: 
-process.env.CI_WINDOWS_INSTALLER_PATH %7C%7C join('build', 'squirrel-ia32')%0A    %7D%0A
+$.winstallerPath(arch)%0A    %7D%0A    await $.measure('Creating windows installer', async () =%3E %7B%0A  
     
@@ -2040,16 +2040,25 @@
 lerOpts)
+;%0A    %7D);
 %0A%0A    $.

Fix windows installer package path