GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python-hwpx/scripts/hancom_com_open_verify.ps1 at main · VerifiedIdiot/python-hwpx

Expand file tree

/

hancom_com_open_verify.ps1

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
99 lines (90 loc) · 2.81 KB
/

hancom_com_open_verify.ps1

Copy path

File metadata and controls

99 lines (90 loc) · 2.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
param(
[Parameter(Mandatory = $true)]
[string[]] $Path,
[int] $MaxPages = 20,
[string] $OutJson = ""
)
$ErrorActionPreference = "Stop"
function Resolve-InputPath {
param([string] $InputPath)
$resolved = Resolve-Path -LiteralPath $InputPath
return $resolved.ProviderPath
}
function Copy-ToTrustedTemp {
param([string] $InputPath)
$name = [System.IO.Path]::GetFileName($InputPath)
$dir = Join-Path $env:TEMP ("hwpx-com-open-" + [System.Guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Force -Path $dir | Out-Null
$target = Join-Path $dir $name
Copy-Item -LiteralPath $InputPath -Destination $target -Force
return @{ Directory = $dir; Path = $target }
}
function New-HwpObject {
$hwp = New-Object -ComObject "HWPFrame.HwpObject"
try {
$null = $hwp.RegisterModule("FilePathCheckerModule", "FilePathCheckerModuleExample")
} catch {
Write-Warning ("RegisterModule FilePathCheckerModule failed: " + $_.Exception.Message)
}
return $hwp
}
function Read-HwpText {
param(
[object] $Hwp,
[int] $PageLimit
)
$parts = New-Object System.Collections.Generic.List[string]
for ($page = 1; $page -le $PageLimit; $page++) {
try {
$text = $Hwp.GetPageText($page)
} catch {
break
}
if ($null -eq $text -or [string]::IsNullOrWhiteSpace([string]$text)) {
continue
}
$parts.Add([string]$text)
}
return ($parts -join "`n")
}
$results = New-Object System.Collections.Generic.List[object]
$hwp = $null
try {
$hwp = New-HwpObject
foreach ($item in $Path) {
$inputPath = Resolve-InputPath $item
$trusted = Copy-ToTrustedTemp $inputPath
$opened = $false
$text = ""
$errorMessage = $null
try {
$opened = [bool]$hwp.Open($trusted.Path)
if ($opened) {
$text = Read-HwpText -Hwp $hwp -PageLimit $MaxPages
}
} catch {
$errorMessage = $_.Exception.Message
} finally {
try { $hwp.Clear(1) | Out-Null } catch {}
Remove-Item -LiteralPath $trusted.Directory -Recurse -Force -ErrorAction SilentlyContinue
}
$results.Add([ordered]@{
sourcePath = $inputPath
opened = $opened
textLength = $text.Length
textPreview = if ($text.Length -gt 500) { $text.Substring(0, 500) } else { $text }
error = $errorMessage
})
}
} finally {
if ($null -ne $hwp) {
try { $hwp.Quit() | Out-Null } catch {}
[System.Runtime.InteropServices.Marshal]::FinalReleaseComObject($hwp) | Out-Null
}
}
$json = $results | ConvertTo-Json -Depth 4
if ($OutJson) {
Set-Content -LiteralPath $OutJson -Value $json -Encoding UTF8
} else {
$json
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.