Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/packages/jQuery.1.8.2/Tools/common.ps1 @ 11359

Last change on this file since 11359 was 9604, checked in by pfleck, 12 years ago

#2063:
Set up basic webpage layout based on WebApplication branch.
Added Asp.Net MVC packages and some helper packages.
Implemented login.

File size: 3.9 KB
Line 
1function Get-Checksum($file) {
2    $cryptoProvider = New-Object "System.Security.Cryptography.MD5CryptoServiceProvider"
3 
4    $fileInfo = Get-Item $file
5  trap { ;
6  continue } $stream = $fileInfo.OpenRead()
7    if ($? -eq $false) {
8    # Couldn't open file for reading
9        return $null
10  }
11   
12    $bytes = $cryptoProvider.ComputeHash($stream)
13    $checksum = ''
14  foreach ($byte in $bytes) {
15    $checksum += $byte.ToString('x2')
16  }
17   
18  $stream.Close() | Out-Null
19   
20    return $checksum
21}
22
23function AddOrUpdate-Reference($scriptsFolderProjectItem, $fileNamePattern, $newFileName) {
24    try {
25        $referencesFileProjectItem = $scriptsFolderProjectItem.ProjectItems.Item("_references.js")
26    }
27    catch {
28        # _references.js file not found
29        return
30    }
31
32    if ($referencesFileProjectItem -eq $null) {
33        # _references.js file not found
34        return
35    }
36
37    $referencesFilePath = $referencesFileProjectItem.FileNames(1)
38    $referencesTempFilePath = Join-Path $env:TEMP "_references.tmp.js"
39
40    if ((Select-String $referencesFilePath -pattern $fileNamePattern).Length -eq 0) {
41        # File has no existing matching reference line
42        # Add the full reference line to the beginning of the file
43        "/// <reference path=""$newFileName"" />" | Add-Content $referencesTempFilePath -Encoding UTF8
44         Get-Content $referencesFilePath | Add-Content $referencesTempFilePath
45    }
46    else {
47        # Loop through file and replace old file name with new file name
48        Get-Content $referencesFilePath | ForEach-Object { $_ -replace $fileNamePattern, $newFileName } > $referencesTempFilePath
49    }
50
51    # Copy over the new _references.js file
52    Copy-Item $referencesTempFilePath $referencesFilePath -Force
53    Remove-Item $referencesTempFilePath -Force
54}
55
56function Remove-Reference($scriptsFolderProjectItem, $fileNamePattern) {
57    try {
58        $referencesFileProjectItem = $scriptsFolderProjectItem.ProjectItems.Item("_references.js")
59    }
60    catch {
61        # _references.js file not found
62        return
63    }
64
65    if ($referencesFileProjectItem -eq $null) {
66        return
67    }
68
69    $referencesFilePath = $referencesFileProjectItem.FileNames(1)
70    $referencesTempFilePath = Join-Path $env:TEMP "_references.tmp.js"
71
72    if ((Select-String $referencesFilePath -pattern $fileNamePattern).Length -eq 1) {
73        # Delete the line referencing the file
74        Get-Content $referencesFilePath | ForEach-Object { if (-not ($_ -match $fileNamePattern)) { $_ } } > $referencesTempFilePath
75
76        # Copy over the new _references.js file
77        Copy-Item $referencesTempFilePath $referencesFilePath -Force
78        Remove-Item $referencesTempFilePath -Force
79    }
80}
81
82function Delete-ProjectItem($item) {
83    $itemDeleted = $false
84    for ($1=1; $i -le 5; $i++) {
85        try {
86            $item.Delete()
87            $itemDeleted = $true
88            break
89        }
90        catch {
91            # Try again in 200ms
92            [System.Threading.Thread]::Sleep(200)
93        }
94    }
95    if ($itemDeleted -eq $false) {
96        throw "Unable to delete project item after five attempts."
97    }
98}
99
100# Extract the version number from the jquery file in the package's content\scripts folder
101$packageScriptsFolder = Join-Path $installPath Content\Scripts
102$jqueryFileName = Join-Path $packageScriptsFolder "jquery-*.js" | Get-ChildItem -Exclude "*.min.js","*-vsdoc.js" | Split-Path -Leaf
103$jqueryFileNameRegEx = "jquery-((?:\d+\.)?(?:\d+\.)?(?:\d+\.)?(?:\d+)).js"
104$jqueryFileName -match $jqueryFileNameRegEx
105$ver = $matches[1]
106
107$intelliSenseFileName = "jquery-$ver.intellisense.js"
108
109# Get the project item for the scripts folder
110try {
111    $scriptsFolderProjectItem = $project.ProjectItems.Item("Scripts")
112    $projectScriptsFolderPath = $scriptsFolderProjectItem.FileNames(1)
113}
114catch {
115    # No Scripts folder
116    Write-Host "No scripts folder found"
117}
Note: See TracBrowser for help on using the repository browser.