From dcbbf2ec78b602a8d84c192a109a915d162bb042 Mon Sep 17 00:00:00 2001 From: Marco van Munster Date: Wed, 27 Apr 2016 14:18:51 +0200 Subject: [PATCH 1/4] Symlink data to bin\data --- scripts/ps/build.ps1 | 21 ++++++++++++++++++--- scripts/ps/install.ps1 | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/ps/build.ps1 b/scripts/ps/build.ps1 index 99a188f97a..ab2f2b89e8 100644 --- a/scripts/ps/build.ps1 +++ b/scripts/ps/build.ps1 @@ -28,9 +28,24 @@ $openrct2Path = Join-Path $binPath "openrct2.exe" function Build-Data() { - Write-Host "Copying data to bin..." -ForegroundColor Cyan - New-Item -Force -ItemType Directory $binPath > $null - Copy-Item -Force -Recurse "$rootPath\data" $binPath + if(Test-Path "$binPath\data") + { + $object = Get-Item "$binPath\data" + + if(-not ([bool]($object.Attributes -band [IO.FileAttributes]::ReparsePoint))) + { + Write-Host "Copying data to bin..." -ForegroundColor Cyan + New-Item -Force -ItemType Directory $binPath > $null + Copy-Item -Force -Recurse "$rootPath\data" $binPath + } + else{ + Write-Host "Symlink already in place" -ForegroundColor Cyan + } + } + else { + Write-Host "Symlink data to bin..." -ForegroundColor Cyan + New-Item -force -ItemType SymbolicLink -Name bin\data -Target data + } return 0 } diff --git a/scripts/ps/install.ps1 b/scripts/ps/install.ps1 index 016e181e65..12c6248022 100644 --- a/scripts/ps/install.ps1 +++ b/scripts/ps/install.ps1 @@ -34,6 +34,10 @@ if ($currentLibsVersion -ge $libsVersion) $updateLibs = $false } +#symlink data to bin\data +Write-Host "Symlink data to bin..." -ForegroundColor Cyan +New-Item -force -ItemType SymbolicLink -Name bin\data -Target data + # Check if user needs to download dependencies $libsPathExists = Test-Path $libsPath if ($libsPathExists -and -not $updateLibs -and -not $Force) From 08b3e803bfe00db6ec911eb4d6846d1cd0638ef3 Mon Sep 17 00:00:00 2001 From: marcovmun Date: Thu, 28 Apr 2016 10:31:45 +0200 Subject: [PATCH 2/4] Check if you can create a symlink first --- scripts/ps/install.ps1 | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/scripts/ps/install.ps1 b/scripts/ps/install.ps1 index 12c6248022..d2249d8473 100644 --- a/scripts/ps/install.ps1 +++ b/scripts/ps/install.ps1 @@ -19,6 +19,7 @@ $libsVersion = 7 # Get paths $rootPath = Get-RootPath $libsPath = Join-Path $rootPath "lib" +$binPath = Join-Path $rootPath "bin" $zipPath = Join-Path $libsPath "openrct2-libs-vs2015.zip" $libsVersionPath = Join-Path $libsPath "libversion" @@ -35,8 +36,30 @@ if ($currentLibsVersion -ge $libsVersion) } #symlink data to bin\data -Write-Host "Symlink data to bin..." -ForegroundColor Cyan -New-Item -force -ItemType SymbolicLink -Name bin\data -Target data +try { + Write-Host "Symlink data to bin..." -ForegroundColor Cyan + New-Item -force -ItemType SymbolicLink -Name bin\data -Target data +} +catch [System.Management.Automation.ParameterBindingException] { + Write-Host "Your powershell can not create symlinks" -ForegroundColor Red + Write-Host "Copying data to bin..." -ForegroundColor Cyan + New-Item -Force -ItemType Directory $binPath > $null + Copy-Item -Force -Recurse "$rootPath\data" $binPath +} +catch { + Write-Host "Symlink not possible" -ForegroundColor Red + if($force) { + Write-Host "Copying data to bin..." -ForegroundColor Cyan + New-Item -Force -ItemType Directory $binPath > $null + Copy-Item -Force -Recurse "$rootPath\data" $binPath + } + else + { + Write-Host "You need to run powershell in administration mode to symlink the data folder" -ForegroundColor Red + Write-Host "Or run the script in force mode to copy the data folder" -ForegroundColor Red + throw + } +} # Check if user needs to download dependencies $libsPathExists = Test-Path $libsPath From 8bd9a772e6527fc81bf5ee13add7db00eeae9a71 Mon Sep 17 00:00:00 2001 From: Marco van Munster Date: Mon, 2 May 2016 22:32:33 +0200 Subject: [PATCH 3/4] Fix tabs and formatting --- scripts/ps/build.ps1 | 38 ++++++++++++++++++++------------------ scripts/ps/install.ps1 | 24 ++++++++++++++---------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/scripts/ps/build.ps1 b/scripts/ps/build.ps1 index ab2f2b89e8..975d33e6bc 100644 --- a/scripts/ps/build.ps1 +++ b/scripts/ps/build.ps1 @@ -28,24 +28,26 @@ $openrct2Path = Join-Path $binPath "openrct2.exe" function Build-Data() { - if(Test-Path "$binPath\data") - { - $object = Get-Item "$binPath\data" - - if(-not ([bool]($object.Attributes -band [IO.FileAttributes]::ReparsePoint))) - { - Write-Host "Copying data to bin..." -ForegroundColor Cyan - New-Item -Force -ItemType Directory $binPath > $null - Copy-Item -Force -Recurse "$rootPath\data" $binPath - } - else{ - Write-Host "Symlink already in place" -ForegroundColor Cyan - } - } - else { - Write-Host "Symlink data to bin..." -ForegroundColor Cyan - New-Item -force -ItemType SymbolicLink -Name bin\data -Target data - } + if(Test-Path "$binPath\data") + { + $object = Get-Item "$binPath\data" + + if(-not ([bool]($object.Attributes -band [IO.FileAttributes]::ReparsePoint))) + { + Write-Host "Copying data to bin..." -ForegroundColor Cyan + New-Item -Force -ItemType Directory $binPath > $null + Copy-Item -Force -Recurse "$rootPath\data" $binPath + } + else + { + Write-Host "Symlink already in place" -ForegroundColor Cyan + } + } + else + { + Write-Host "Symlink data to bin..." -ForegroundColor Cyan + New-Item -force -ItemType SymbolicLink -Name bin\data -Target data + } return 0 } diff --git a/scripts/ps/install.ps1 b/scripts/ps/install.ps1 index d2249d8473..f62c9ef9df 100644 --- a/scripts/ps/install.ps1 +++ b/scripts/ps/install.ps1 @@ -19,7 +19,7 @@ $libsVersion = 7 # Get paths $rootPath = Get-RootPath $libsPath = Join-Path $rootPath "lib" -$binPath = Join-Path $rootPath "bin" +$binPath = Join-Path $rootPath "bin" $zipPath = Join-Path $libsPath "openrct2-libs-vs2015.zip" $libsVersionPath = Join-Path $libsPath "libversion" @@ -36,19 +36,23 @@ if ($currentLibsVersion -ge $libsVersion) } #symlink data to bin\data -try { +try +{ Write-Host "Symlink data to bin..." -ForegroundColor Cyan New-Item -force -ItemType SymbolicLink -Name bin\data -Target data } -catch [System.Management.Automation.ParameterBindingException] { - Write-Host "Your powershell can not create symlinks" -ForegroundColor Red - Write-Host "Copying data to bin..." -ForegroundColor Cyan - New-Item -Force -ItemType Directory $binPath > $null - Copy-Item -Force -Recurse "$rootPath\data" $binPath -} -catch { +catch [System.Management.Automation.ParameterBindingException] +{ + Write-Host "Your powershell can not create symlinks" -ForegroundColor Red + Write-Host "Copying data to bin..." -ForegroundColor Cyan + New-Item -Force -ItemType Directory $binPath > $null + Copy-Item -Force -Recurse "$rootPath\data" $binPath +} +catch +{ Write-Host "Symlink not possible" -ForegroundColor Red - if($force) { + if($force) + { Write-Host "Copying data to bin..." -ForegroundColor Cyan New-Item -Force -ItemType Directory $binPath > $null Copy-Item -Force -Recurse "$rootPath\data" $binPath From df781b33845bdc89016881555295ad6736f9cb38 Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 3 May 2016 17:51:32 +0100 Subject: [PATCH 4/4] create symlinks only for data sub-directories --- scripts/ps/build.ps1 | 29 ++++++++--------------- scripts/ps/common.psm1 | 54 ++++++++++++++++++++++++++++++++++++++++++ scripts/ps/install.ps1 | 31 ------------------------ 3 files changed, 64 insertions(+), 50 deletions(-) diff --git a/scripts/ps/build.ps1 b/scripts/ps/build.ps1 index 975d33e6bc..49bf0af45c 100644 --- a/scripts/ps/build.ps1 +++ b/scripts/ps/build.ps1 @@ -28,26 +28,17 @@ $openrct2Path = Join-Path $binPath "openrct2.exe" function Build-Data() { - if(Test-Path "$binPath\data") - { - $object = Get-Item "$binPath\data" + $dataPath = "$rootPath\data" + $binDataPath = "$binPath\data" + + # Create data directory in bin + Write-Host "Create data directory..." -ForegroundColor Cyan + New-Item -Force -ItemType Directory $binDataPath > $null + + # Create symlinks + Symlink-or-Copy "$binDataPath\language" "$dataPath\language" + Symlink-or-Copy "$binDataPath\title" "$dataPath\title" - if(-not ([bool]($object.Attributes -band [IO.FileAttributes]::ReparsePoint))) - { - Write-Host "Copying data to bin..." -ForegroundColor Cyan - New-Item -Force -ItemType Directory $binPath > $null - Copy-Item -Force -Recurse "$rootPath\data" $binPath - } - else - { - Write-Host "Symlink already in place" -ForegroundColor Cyan - } - } - else - { - Write-Host "Symlink data to bin..." -ForegroundColor Cyan - New-Item -force -ItemType SymbolicLink -Name bin\data -Target data - } return 0 } diff --git a/scripts/ps/common.psm1 b/scripts/ps/common.psm1 index f643f6da8a..17868366cf 100644 --- a/scripts/ps/common.psm1 +++ b/scripts/ps/common.psm1 @@ -27,3 +27,57 @@ function Prompt-User($message) $choice = $host.UI.PromptForChoice("", $message, $options, 1) return ($choice -eq 0) } + +function Resolve-PathFromBase($path) +{ + $rootPath = Get-RootPath + if ($path.StartsWith($rootPath)) { + $path = $path.Remove(0, $rootPath.Length + 1) + } + return $path +} + +function Symlink-or-Copy($path, $target) +{ + $pathDirectory = Split-Path $path + $pathName = Split-Path $path -Leaf + + $friendlyPath = Resolve-PathFromBase $path + $friendlyTarget = Resolve-PathFromBase $target + + # If the path is not a symlink, copy files instead + $mustCopy = $false + if (Test-Path $path) + { + if (-not ((Get-Item $path).Attributes -band [IO.FileAttributes]::ReparsePoint)) + { + $mustCopy = $true + } + } + + $symlinkSuccessful = $false + if (-not $mustCopy) + { + try + { + Write-Host "Symlink $friendlyPath to $friendlyTarget..." -ForegroundColor Cyan + New-Item -Force -ItemType SymbolicLink -Path $pathDirectory -Name $pathName -Target $target -ErrorAction Stop + $symlinkSuccessful = $true + } + catch [System.Management.Automation.ParameterBindingException] + { + Write-Host " Your powershell can not create symlinks, try updating it" -ForegroundColor Red + } + catch [System.UnauthorizedAccessException] + { + Write-Host " You need to run powershell in administration mode to create symlinks" -ForegroundColor Red + } + } + + if (-not $symlinkSuccessful) + { + Write-Host "Copying $friendlyTarget to $friendlyPath..." -ForegroundColor Cyan + New-Item -Force -Type Directory $path > $null + Copy-Item -Force -Recurse "$target\*" $path + } +} diff --git a/scripts/ps/install.ps1 b/scripts/ps/install.ps1 index f62c9ef9df..016e181e65 100644 --- a/scripts/ps/install.ps1 +++ b/scripts/ps/install.ps1 @@ -19,7 +19,6 @@ $libsVersion = 7 # Get paths $rootPath = Get-RootPath $libsPath = Join-Path $rootPath "lib" -$binPath = Join-Path $rootPath "bin" $zipPath = Join-Path $libsPath "openrct2-libs-vs2015.zip" $libsVersionPath = Join-Path $libsPath "libversion" @@ -35,36 +34,6 @@ if ($currentLibsVersion -ge $libsVersion) $updateLibs = $false } -#symlink data to bin\data -try -{ - Write-Host "Symlink data to bin..." -ForegroundColor Cyan - New-Item -force -ItemType SymbolicLink -Name bin\data -Target data -} -catch [System.Management.Automation.ParameterBindingException] -{ - Write-Host "Your powershell can not create symlinks" -ForegroundColor Red - Write-Host "Copying data to bin..." -ForegroundColor Cyan - New-Item -Force -ItemType Directory $binPath > $null - Copy-Item -Force -Recurse "$rootPath\data" $binPath -} -catch -{ - Write-Host "Symlink not possible" -ForegroundColor Red - if($force) - { - Write-Host "Copying data to bin..." -ForegroundColor Cyan - New-Item -Force -ItemType Directory $binPath > $null - Copy-Item -Force -Recurse "$rootPath\data" $binPath - } - else - { - Write-Host "You need to run powershell in administration mode to symlink the data folder" -ForegroundColor Red - Write-Host "Or run the script in force mode to copy the data folder" -ForegroundColor Red - throw - } -} - # Check if user needs to download dependencies $libsPathExists = Test-Path $libsPath if ($libsPathExists -and -not $updateLibs -and -not $Force)