Skip to content

Commit

Permalink
Add windows installer
Browse files Browse the repository at this point in the history
  • Loading branch information
McGiverGim committed Jan 20, 2018
1 parent 83f522a commit ee0ed30
Show file tree
Hide file tree
Showing 6 changed files with 822 additions and 12 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

Binary file added assets/windows/cf_installer_icon.ico
Binary file not shown.
Binary file added assets/windows/cf_uninstaller_icon.ico
Binary file not shown.
118 changes: 118 additions & 0 deletions assets/windows/installer.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
!include "MUI2.nsh"
!include "FileFunc.nsh"
!include "LogicLib.nsh"

# Receives variables from the command line
# ${VERSION} - Version to generate (x.y.z)
# ${PLATFORM} - Platform to generate (win32 or win64)
# ${DEST_FOLDER} - Destination folder for the installer files

# Some definitions
!define SOURCE_FILES "..\..\apps\cleanflight-blackbox-explorer\${PLATFORM}\*"
!define APP_NAME "Cleanflight Blackbox Explorer"
!define COMPANY_NAME "Cleanflight Team"
!define GROUP_NAME "Cleanflight"
!define FOLDER_NAME "Cleanflight-Blackbox-Explorer"
!define FILE_NAME_INSTALLER "cleanflight-blackbox-explorer-installer_${VERSION}_${PLATFORM}.exe"
!define FILE_NAME_UNINSTALLER "uninstall-cleanflight-blackbox-explorer.exe"
!define FILE_NAME_EXECUTABLE "cleanflight-blackbox-explorer.exe"
!define LICENSE "..\..\LICENSE"
!define MUI_ICON ".\cf_installer_icon.ico"
!define MUI_UNICON ".\cf_uninstaller_icon.ico"

Name "${APP_NAME}"
BrandingText "${COMPANY_NAME}"

# set the icon

# define the resulting installer's name:
OutFile "..\..\${DEST_FOLDER}\${FILE_NAME_INSTALLER}"

# set the default installation directory
!if ${PLATFORM} == 'win64'
InstallDir "$PROGRAMFILES64\${GROUP_NAME}\${FOLDER_NAME}\"
!else
InstallDir "$PROGRAMFILES\${GROUP_NAME}\${FOLDER_NAME}\"
!endif

# app dialogs
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE ${LICENSE}
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

!define MUI_FINISHPAGE_RUN "$INSTDIR\${FILE_NAME_EXECUTABLE}"

!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"

# default install dir, readed from registry from latest installation
InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" "InstallLocation"

# default section start
Section

# remove the older version
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"InstallLocation"

${If} $R0 != ""
# delete the installed files of the older version
RMDir /r $R0
${EndIf}

# define the path to which the installer should install
SetOutPath $INSTDIR

# specify the files to go in the output path
File /r ${SOURCE_FILES}

# create the uninstaller
WriteUninstaller "$INSTDIR\${FILE_NAME_UNINSTALLER}"

# create shortcuts in the start menu and on the desktop
CreateDirectory "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}"
CreateShortCut "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}\${APP_NAME}.lnk" "$INSTDIR\${FILE_NAME_EXECUTABLE}"
CreateShortCut "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}\Uninstall ${APP_NAME}.lnk" "$INSTDIR\${FILE_NAME_UNINSTALLER}"
CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\${FILE_NAME_EXECUTABLE}"

# include in add/remove programs
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"Publisher" "${COMPANY_NAME}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"DisplayName" "${APP_NAME}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"DisplayIcon" "$\"$INSTDIR\${FILE_NAME_EXECUTABLE}$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"UninstallString" "$\"$INSTDIR\${FILE_NAME_UNINSTALLER}$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"InstallLocation" "$INSTDIR"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"DisplayVersion" "${VERSION}"

# estimate the size
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" \
"EstimatedSize" "$0"


SectionEnd

# create a section to define what the uninstaller does
Section "Uninstall"

# delete the installed files
RMDir /r $INSTDIR

# delete the shortcuts
Delete "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}\${APP_NAME}.lnk"
Delete "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}\Uninstall ${APP_NAME}.lnk"
RMDir "$SMPROGRAMS\${GROUP_NAME}\${FOLDER_NAME}"
RMDir "$SMPROGRAMS\${GROUP_NAME}"
Delete "$DESKTOP\${APP_NAME}.lnk"

# remove from add/remove programs
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}"

SectionEnd
41 changes: 29 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var path = require('path');
var archiver = require('archiver');
var del = require('del');
var NwBuilder = require('nw-builder');
var makensis = require('makensis');

var gulp = require('gulp');
var concat = require('gulp-concat');
Expand Down Expand Up @@ -320,18 +321,34 @@ gulp.task('post-build', function(done) {
done();
});

// Create distribution package for windows platform
function release_win32() {
var src = path.join(appsDir, pkg.name, 'win32');
var output = fs.createWriteStream(path.join(releaseDir, get_release_filename('win32', 'zip')));
var archive = archiver('zip', {
zlib: { level: 9 }
//Create installer package for windows platforms
function release_win(arch) {

// Create the output directory, with write permissions
fs.mkdir(releaseDir, '0775', function(err) {
if (err) {
if (err.code !== 'EEXIST') {
throw err;
}
}
});
archive.on('warning', function (err) { throw err; });
archive.on('error', function (err) { throw err; });
archive.pipe(output);
archive.directory(src, 'Betaflight Blackbox Explorer');
return archive.finalize();

// Parameters passed to the installer script
const options = {
verbose: 2,
define: {
'VERSION': pkg.version,
'PLATFORM': arch,
'DEST_FOLDER': releaseDir
}
}
var output = makensis.compileSync('./assets/windows/installer.nsi', options);

if (output.status === 0) {
console.log('Installer finished for platform: ' + arch);
} else {
console.error('Installer for platform ' + arch + ' finished with error ' + output.status + ': ' + output.stderr);
}
}

// Create distribution package for linux platform
Expand Down Expand Up @@ -415,7 +432,7 @@ gulp.task('release', ['apps', 'clean-release'], function () {
}

if (platforms.indexOf('win32') !== -1) {
release_win32();
release_win('win32');
}
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"gulp-install": "^1.1.0",
"inflection": "1.12.0",
"jquery-ui-npm": "1.12.0",
"makensis": "^0.9.0",
"nw-builder": "^3.4.1",
"os": "^0.1.1",
"platform-dependent-modules": "0.0.14",
Expand Down

0 comments on commit ee0ed30

Please sign in to comment.