diff --git a/launcher/CmderLauncher.vcxproj b/launcher/CmderLauncher.vcxproj index 879bb5a..08deaeb 100644 --- a/launcher/CmderLauncher.vcxproj +++ b/launcher/CmderLauncher.vcxproj @@ -1,4 +1,4 @@ - + @@ -61,6 +61,9 @@ Windows true + + src/app.manifest %(AdditionalManifestFiles) + _USING_V110_SDK71_;%(PreprocessorDefinitions) @@ -84,6 +87,9 @@ true true + + src/app.manifest %(AdditionalManifestFiles) + copy $(TargetPath) $(SolutionDir)..\$(TargetFileName) diff --git a/launcher/src/Resource.rc b/launcher/src/Resource.rc index 9d4ec33..fa9a64f 100644 Binary files a/launcher/src/Resource.rc and b/launcher/src/Resource.rc differ diff --git a/launcher/src/app.manifest b/launcher/src/app.manifest new file mode 100644 index 0000000..bf133f7 --- /dev/null +++ b/launcher/src/app.manifest @@ -0,0 +1,54 @@ + + + + + + Cmder Console Emulator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true/pm + + + + diff --git a/launcher/src/version.rc2.sample b/launcher/src/version.rc2.sample new file mode 100644 index 0000000..003621d --- /dev/null +++ b/launcher/src/version.rc2.sample @@ -0,0 +1,27 @@ + +/** + * WARNING: do NOT modify this file! the content of this file should be + * automatically genereted before AppVeyor builds using the + * respective .ps1 Powershell scripts. + * + */ + +///////////////////////////////////////////////////////////////////////////// +// Define the version numbers and build information manually here: + +#define CMDER_MAJOR_VERSION {Cmder-Major-Version} +#define CMDER_MINOR_VERSION {Cmder-Minor-Version} +#define CMDER_REVISION_VERSION {Cmder-Revision-Version} +#define CMDER_BUILD_VERSION {Cmder-Build-Version} +#define CMDER_VERSION_STR {Cmder-Version-Str} + +#define CMDER_PRODUCT_NAME_STR "Cmder" +#define CMDER_FILE_DESCRIPTION_STR "Cmder: Lovely Console Emulator." +#define CMDER_INTERNAL_NAME_STR "Cmder" +#define CMDER_ORIGINAL_FILENAME_STR "Cmder.exe" +#define CMDER_COMPANY_NAME_STR "Samuel Vasko" +#define CMDER_COPYRIGHT_YEAR_STR "2016" + +#define CMDER_DEBUGFLAG 0x0L // set to 0x1L to enable debug mode +#define CMDER_BUILDFLAGS 0x0L +///////////////////////////////////////////////////////////////////////////// diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 62eb4e5..7a78a85 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -58,12 +58,15 @@ $ScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition $cmder_root = $ScriptRoot.replace("\scripts","") # Dot source util functions into this scope -. ".\utils.ps1" +. "$PSScriptRoot\utils.ps1" $ErrorActionPreference = "Stop" Push-Location -Path $saveTo $sources = Get-Content $sourcesPath | Out-String | Convertfrom-Json +# Get the version string +$version = Get-VersionStr + # Check for requirements Ensure-Exists $sourcesPath Ensure-Executable "7z" @@ -116,10 +119,17 @@ Pop-Location if($Compile) { Push-Location -Path $launcher - msbuild CmderLauncher.vcxproj /p:configuration=Release + Create-RC $version ($launcher + '\src\version.rc2'); + msbuild CmderLauncher.vcxproj /t:Clean,Build /p:configuration=Release if ($LastExitCode -ne 0) { throw "msbuild failed to build the executable." } + else { + Write-Verbose "successfully built Cmder v$version!" + if ( $Env:APPVEYOR -eq 'True' ) { + Add-AppveyorMessage -Message "Building Cmder v$version was successful." -Category Information + } + } Pop-Location } else { Write-Warning "You are not building a launcher, Use -Compile" diff --git a/scripts/pack.ps1 b/scripts/pack.ps1 index 1b76a67..8382d5f 100644 --- a/scripts/pack.ps1 +++ b/scripts/pack.ps1 @@ -48,7 +48,7 @@ $targets = @{ Delete-Existing "..\Version*" Delete-Existing "..\build\*" -$version = Invoke-Expression "git describe --abbrev=0 --tags" +$version = Get-VersionStr (New-Item -ItemType file "$cmderRoot\Version $version") | Out-Null foreach ($t in $targets.GetEnumerator()) { diff --git a/scripts/utils.ps1 b/scripts/utils.ps1 index e3a47fc..08d40d0 100644 --- a/scripts/utils.ps1 +++ b/scripts/utils.ps1 @@ -62,6 +62,85 @@ function Digest-Hash($path) { return Invoke-Expression "md5sum $path" } +function Get-VersionStr() { + + # Clear existing variable + if ($string) { Clear-Variable -name string } + + # Determine if git is available + if (Get-Command "git.exe" -ErrorAction SilentlyContinue) + { + + # Determine if the current diesctory is a git repository + $GitPresent = Invoke-Expression "git rev-parse --is-inside-work-tree" -erroraction SilentlyContinue + + if ( $GitPresent -eq 'true' ) + { + $string = Invoke-Expression "git describe --abbrev=0 --tags" + } + + } + + # Fallback used when Git is not available + if ( -not($string) ) + { + $string = Parse-Changelog ($PSScriptRoot + '\..\' + 'CHANGELOG.md') + } + + # Add build number, if AppVeyor is present + if ( $Env:APPVEYOR -eq 'True' ) + { + $string = $string + '.' + $Env:APPVEYOR_BUILD_NUMBER + } + + # Remove starting 'v' characters + $string = $string -replace '^v+','' # normalize version string + + return $string + +} + +function Parse-Changelog($file) { + + # Define the regular expression to match the version string from changelog + [regex]$regex = '^## \[(?[\w\-\.]+)\]\([^\n()]+\)\s+\([^\n()]+\)$'; + + # Find the first match of the version string which means the latest version + $version = Select-String -Path $file -Pattern $regex | Select-Object -First 1 | % { $_.Matches.Groups[1].Value } + + return $version +} + +function Create-RC($string, $path) { + + $version = $string + '.0.0.0.0' # padding for version string + + if ( !(Test-Path "$path.sample") ) { + throw "Invalid path provided for resources file." + } + + $resource = Get-Content -Path "$path.sample" + $pattern = @( "Cmder-Major-Version", "Cmder-Minor-Version", "Cmder-Revision-Version", "Cmder-Build-Version" ) + $index = 0 + + # Replace all non-numeric characters to dots and split to array + $version = $version -replace '[^0-9]+','.' -split '\.' + + foreach ($fragment in $version) { + if ( !$fragment ) { break } + elseif ($index -le $pattern.length) { + $resource = $resource.Replace( "{" + $pattern[$index++] + "}", $fragment ) + } + } + + # Add the version string + $resource = $resource.Replace( "{Cmder-Version-Str}", '"' + $string + '"' ) + + # Write the results + Set-Content -Path $path -Value $resource + +} + function Register-Cmder() { [CmdletBinding()] Param