nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | # |
2 | # Textify - Copy text files and make them useful for Windows users. |
||
3 | # |
||
4 | # Copyright 2013 Gerald Combs <gerald@wireshark.org> |
||
5 | # |
||
6 | # Wireshark - Network traffic analyzer |
||
7 | # By Gerald Combs <gerald@wireshark.org> |
||
8 | # Copyright 1998 Gerald Combs |
||
9 | # |
||
10 | # This program is free software; you can redistribute it and/or |
||
11 | # modify it under the terms of the GNU General Public License |
||
12 | # as published by the Free Software Foundation; either version 2 |
||
13 | # of the License, or (at your option) any later version. |
||
14 | # |
||
15 | # This program is distributed in the hope that it will be useful, |
||
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
18 | # GNU General Public License for more details. |
||
19 | # |
||
20 | # You should have received a copy of the GNU General Public License |
||
21 | # along with this program; if not, write to the Free Software |
||
22 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
23 | |||
24 | #requires -version 2 |
||
25 | |||
26 | <# |
||
27 | .SYNOPSIS |
||
28 | Text file conversion script for packaging on Windows. |
||
29 | |||
30 | .DESCRIPTION |
||
31 | This script copies a text file from a source to a destination, |
||
32 | converting line endings and adding a ".txt" filename extension |
||
33 | if needed. If the destination is a directory the source file |
||
34 | name is used. Newer files will not be overwritten. |
||
35 | |||
36 | The destination file should be double-clickable and usable |
||
37 | when Notepad is the default editor. |
||
38 | |||
39 | .PARAMETER Destination |
||
40 | Specifies the destination directory for the text files. |
||
41 | |||
42 | .PARAMETER SourceFiles |
||
43 | The names of the files to copy and convert. |
||
44 | |||
45 | .INPUTS |
||
46 | -Destination Destination directory. |
||
47 | -SourceFiles List of files. |
||
48 | |||
49 | .OUTPUTS |
||
50 | Copies of input files, UTF8 encoded with Windows line endings and no BOM in the |
||
51 | destination directory. |
||
52 | |||
53 | .EXAMPLE |
||
54 | C:\PS> .\tools\textify.ps1 -Destination wireshark-release-staging COPYING |
||
55 | #> |
||
56 | |||
57 | Param( |
||
58 | [Parameter(Mandatory=$true, Position=0)] |
||
59 | [ValidateScript({Test-Path $_ -PathType 'Container'})] |
||
60 | [String] |
||
61 | $Destination, |
||
62 | |||
63 | [Parameter(Mandatory=$true, Position=1, ValueFromRemainingArguments=$true)] |
||
64 | [ValidateScript({Test-Path $_ -PathType 'Leaf'})] |
||
65 | [String[]] |
||
66 | $SourceFiles |
||
67 | ) |
||
68 | |||
69 | $no_bom_encoding = New-Object System.Text.UTF8Encoding($False) |
||
70 | |||
71 | foreach ($src_file in Get-ChildItem $SourceFiles) { |
||
72 | if ($Destination) { |
||
73 | $base = Split-Path -Leaf $src_file |
||
74 | $dst_file = Join-Path $Destination $base |
||
75 | } else { |
||
76 | $dst_file = $src_file.FullName |
||
77 | } |
||
78 | |||
79 | if (-not $dst_file.EndsWith(".txt")) { |
||
80 | $dst_file += ".txt" |
||
81 | } |
||
82 | |||
83 | $src_modtime = (Get-Item $src_file).LastWriteTime |
||
84 | |||
85 | if (-not (Test-Path $dst_file) -or ((Get-Item $dst_file).LastWriteTime -lt $src_modtime)) { |
||
86 | $contents = Get-Content $src_file |
||
87 | [System.IO.File]::WriteAllLines($dst_file, $contents, $no_bom_encoding) |
||
88 | Write-Host "Textified $src_file to $dst_file" |
||
89 | } else { |
||
90 | Write-Host "Skipping $src_file" |
||
91 | } |
||
92 | } |