2 # Textify - Copy text files and make them useful for Windows users.
4 # Copyright 2013 Gerald Combs <gerald@wireshark.org>
6 # Wireshark - Network traffic analyzer
7 # By Gerald Combs <gerald@wireshark.org>
8 # Copyright 1998 Gerald Combs
10 # SPDX-License-Identifier: GPL-2.0-or-later
16 Text file conversion script for packaging on Windows.
19 This script copies a text file from a source to a destination,
20 converting line endings and adding a ".txt" filename extension
21 if needed. If the destination is a directory the source file
22 name is used. Newer files will not be overwritten.
24 The destination file should be double-clickable and usable
25 when Notepad is the default editor.
27 .PARAMETER Destination
28 Specifies the destination directory for the text files.
30 .PARAMETER SourceFiles
31 The names of the files to copy and convert.
34 -Destination Destination directory.
35 -SourceFiles List of files.
38 Copies of input files, UTF8 encoded with Windows line endings and no BOM in the
39 destination directory.
42 C:\PS> .\tools\textify.ps1 -Destination wireshark-release-staging COPYING
46 [Parameter(Mandatory=$true, Position=0)]
47 [ValidateScript({Test-Path $_ -PathType 'Container'})]
51 [Parameter(Mandatory=$true, Position=1, ValueFromRemainingArguments=$true)]
52 [ValidateScript({Test-Path $_ -PathType 'Leaf'})]
57 $no_bom_encoding = New-Object System.Text.UTF8Encoding($False)
59 foreach ($src_file in Get-ChildItem $SourceFiles) {
61 $base = Split-Path -Leaf $src_file
62 $dst_file = Join-Path $Destination $base
64 $dst_file = $src_file.FullName
67 if (-not $dst_file.EndsWith(".txt")) {
71 $src_modtime = (Get-Item $src_file).LastWriteTime
73 if (-not (Test-Path $dst_file) -or ((Get-Item $dst_file).LastWriteTime -lt $src_modtime)) {
74 # "Get-Content -Encoding" is undocumented in PS 2.0, but works
75 # here. If it doesn't work elsewhere we can use:
76 # $contents = [System.IO.File]::ReadAllLines($src_file, $no_bom_encoding)
77 $contents = Get-Content -Encoding UTF8 $src_file
78 # We might want to write this out with a BOM in order to improve
79 # the chances of Notepad's UTF-8 heuristics.
80 # https://blogs.msdn.microsoft.com/oldnewthing/20070417-00/?p=27223
81 [System.IO.File]::WriteAllLines($dst_file, $contents, $no_bom_encoding)
82 Write-Host "Textified $src_file to $dst_file"
84 Write-Host "Skipping $src_file"