Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region ### CSS ###
- $htmlhead="<html>
- <style>
- BODY{font-family: Calibri; font-size: 10pt;text-align:center;}
- H1{font-size: 16px; color: #780000;text-align:left;}
- h2{font-size: 14px; color: #780000;text-align:left;}
- H3{font-size: 10px; color: #780000;text-align:left;}
- TABLE{border: 1px solid black; border-collapse: collapse; font-size: 10pt;width:90%; margin-left:5%; margin-right:5%;}
- tr:nth-child(odd) {background: #EEE}
- tr:nth-child(even) {background: #FFF}
- TH{border: 1px solid black; background: #dddddd; padding: 2px; color: #000000;}
- TD{border: 1px solid black; padding: 1px; }
- Td.column{border: 1px solid black; background: #dddddd; padding: 2px; color: #000000; font-weight:bold;}
- td.pass{background: #7FFF00;}
- td.warn{background: #FFE600;}
- td.fail{background: #FF0000; color: #ffffff;}
- </style>
- "
- $htmltail = "</html>"
- #endregion
- Function Get-FileName($initialDirectory)
- {
- [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
- Out-Null
- $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
- $OpenFileDialog.initialDirectory = $initialDirectory
- $OpenFileDialog.filter = "All files (*.*)| *.*"
- $OpenFileDialog.ShowDialog() | Out-Null
- $OpenFileDialog.filename
- } #end function Get-FileName
- function replace-filestring(
- [parameter(Mandatory=$TRUE,Position=0)]
- [String] $Pattern,
- [parameter(Mandatory=$TRUE,Position=1)]
- [String] [AllowEmptyString()] $Replacement,
- [parameter(Mandatory=$TRUE,ParameterSetName="Path",
- Position=2,ValueFromPipeline=$TRUE)]
- [String[]] $Path,
- [parameter(Mandatory=$TRUE,ParameterSetName="LiteralPath",
- Position=2)]
- [String[]] $LiteralPath,
- [Switch] $CaseSensitive,
- [Switch] $Multiline,
- [Switch] $UnixText,
- [Switch] $Overwrite,
- [Switch] $Force,
- [String] $Encoding="ASCII"
- ){
- begin {
- # Throw an error if $Encoding is not valid.
- $encodings = @("ASCII","BigEndianUnicode","Unicode","UTF32","UTF7",
- "UTF8")
- if ($encodings -notcontains $Encoding) {
- throw "Encoding must be one of the following: $encodings"
- }
- # Extended test-path: Check the parameter set name to see if we
- # should use -literalpath or not.
- function test-pathEx($path) {
- switch ($PSCmdlet.ParameterSetName) {
- "Path" {
- test-path $path
- }
- "LiteralPath" {
- test-path -literalpath $path
- }
- }
- }
- # Extended get-childitem: Check the parameter set name to see if we
- # should use -literalpath or not.
- function get-childitemEx($path) {
- switch ($PSCmdlet.ParameterSetName) {
- "Path" {
- get-childitem $path -force
- }
- "LiteralPath" {
- get-childitem -literalpath $path -force
- }
- }
- }
- # Outputs the full name of a temporary file in the specified path.
- function get-tempname($path) {
- do {
- $tempname = join-path $path ([IO.Path]::GetRandomFilename())
- }
- while (test-path $tempname)
- $tempname
- }
- # Use '\r$' instead of '$' unless -UnixText specified because
- # '$' alone matches '\n', not '\r\n'. Ignore '\$' (literal '$').
- if (-not $UnixText) {
- $Pattern = $Pattern -replace '(?<!\\)\$', '\r$'
- }
- # Build an array of Regex options and create the Regex object.
- $opts = @()
- if (-not $CaseSensitive) { $opts += "IgnoreCase" }
- if ($MultiLine) { $opts += "Multiline" }
- if ($opts.Length -eq 0) { $opts += "None" }
- $regex = new-object Text.RegularExpressions.Regex $Pattern, $opts
- }
- process {
- # The list of items to iterate depends on the parameter set name.
- switch ($PSCmdlet.ParameterSetName) {
- "Path" { $list = $Path }
- "LiteralPath" { $list = $LiteralPath }
- }
- # Iterate the items in the list of paths. If an item does not exist,
- # continue to the next item in the list.
- foreach ($item in $list) {
- if (-not (test-pathEx $item)) {
- write-error "Unable to find '$item'."
- continue
- }
- # Iterate each item in the path. If an item is not a file,
- # skip all remaining items.
- foreach ($file in get-childitemEx $item) {
- if ($file -isnot [IO.FileInfo]) {
- write-error "'$file' is not in the file system."
- break
- }
- # Get a temporary file name in the file's directory and create
- # it as a empty file. If set-content fails, continue to the next
- # file. Better to fail before than after reading the file for
- # performance reasons.
- if ($Overwrite) {
- $tempname = get-tempname $file.DirectoryName
- set-content $tempname $NULL -confirm:$FALSE
- if (-not $?) { continue }
- write-verbose "Created file '$tempname'."
- }
- # Read all the text from the file into a single string. We have
- # to do it this way to be able to search across line breaks.
- try {
- write-verbose "Reading '$file'."
- $text = [IO.File]::ReadAllText($file.FullName)
- write-verbose "Finished reading '$file'."
- }
- catch [Management.Automation.MethodInvocationException] {
- write-error $ERROR[0]
- continue
- }
- # If -Overwrite not specified, output the result of the Replace
- # method and continue to the next file.
- if (-not $Overwrite) {
- $regex.Replace($text, $Replacement)
- continue
- }
- # Do nothing further if we're in 'what if' mode.
- if ($WHATIFPREFERENCE) { continue }
- try {
- write-verbose "Writing '$tempname'."
- [IO.File]::WriteAllText("$tempname", $regex.Replace($text,
- $Replacement), [Text.Encoding]::$Encoding)
- write-verbose "Finished writing '$tempname'."
- write-verbose "Copying '$tempname' to '$file'."
- copy-item $tempname $file -force:$Force -erroraction Continue
- if ($?) {
- write-verbose "Finished copying '$tempname' to '$file'."
- }
- remove-item $tempname
- if ($?) {
- write-verbose "Removed file '$tempname'."
- }
- }
- catch [Management.Automation.MethodInvocationException] {
- write-error $ERROR[0]
- }
- } # foreach $file
- } # foreach $item
- } # process
- end { }
- }
- function tidy-input($file){
- }
- function lookup-mods([int]$modval){
- $modhash = @{1 = "Miniaturized" ; 2 = "Composite" ; 4 = "Shielded" ; 8 = "Extended" ; 16 = "Scoped" ; 32 = "Dynamic" ; 64 = "Amorphous" ; 128 = "Radioactive" ; 256 = "Sleek" ; 512 = "Resonating" ; 1024 = "Docktastic" ; 2048 = "Intelligent" ; 4096 = "Amped" ; 8192 = "Rewired" ; 16384 = "Workhorse" ; 32768 = "Evil" ; 65536 = "Superconducting" ; 131072 = "Transcendental" ; 262144 = "Overclocked" ; 524288 = "Forceful" ; 1048576 = "Gyroscopic" ; 2097152 = "Buffered" ; 4194304 = "Super Intelligent" ; 8388608 = "Angelic" ; 16777216 = "Reinforced" ; 33554432 = "New3" ; 67108864 = "New4" ; 134217728 = "New5" ; 268435456 = "New6"}
- $mods = $modhash.Keys | where { $_ -band $modval } | foreach { $modhash.Get_Item($_) }
- return $mods
- }
- #Generated Form Function
- function GenerateForm {
- ########################################################################
- # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
- # Generated On: 14/03/2015 17:35
- # Generated By: Topbuzzz
- ########################################################################
- #region Import the Assemblies
- [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
- [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
- #endregion
- #region Generated Form Objects
- $form1 = New-Object System.Windows.Forms.Form
- $checkBox2 = New-Object System.Windows.Forms.CheckBox
- $checkBox1 = New-Object System.Windows.Forms.CheckBox
- $groupBox1 = New-Object System.Windows.Forms.GroupBox
- $button2 = New-Object System.Windows.Forms.Button
- $button3 = New-Object System.Windows.Forms.Button
- $label1 = New-Object System.Windows.Forms.Label
- $button1 = New-Object System.Windows.Forms.Button
- $textBox1 = New-Object System.Windows.Forms.TextBox
- $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
- #endregion Generated Form Objects
- #----------------------------------------------
- #Generated Event Script Blocks
- #----------------------------------------------
- #Provide Custom Code for events specified in PrimalForms.
- $button3_OnClick=
- {
- $button3.enabled = $false
- $inventory = @()
- $path = $textbox1.text
- [xml]$charinv = Get-Content $path
- $hulls = $charinv.inventory.ship.hull
- #$hulls > c.txt
- #$charinv.inventory.ship | ft
- foreach( $ship in $charinv.inventory.ship)
- {
- [string]$id = $ship.hull.id
- $name = $ship.hull.'#text'.toupper()
- write-host $name $ID -BackgroundColor yellow -ForegroundColor black
- $items = $ship.item
- #$items | select nm, id, m >> item.txt
- foreach ($item in $items){
- $temp = "" | select ship, shipid, item, Quantity, mod, NB, equipped, itemid | Sort-Object ship,item
- $temp.ship = $name
- $temp.shipid = $id
- $temp.item = $item.nm
- $temp.itemid = $item.id
- [int]$moddec = $item.m
- $temp.Quantity = $item.quant
- $mods = lookup-mods $moddec
- $mods = $mods -join ","
- $temp.mod = $mods
- if($item.eqp -eq 1){
- $temp.equipped = "Y"
- }
- ELSE{
- $temp.equipped = "N"
- }
- if($item.own -ne $null){
- $temp.NB = "Y"
- }
- ELSE{
- $temp.NB = "N"
- }
- #write-host $item.nm $item.m
- if($checkBox1.checked){
- if($item.m -ne $null){
- if($checkbox2.checked){
- if($temp.NB -eq "N" ){
- $inventory += $temp
- }
- }
- ELSE{
- $inventory += $temp
- }
- }
- }
- Else{
- if($checkbox2.checked){
- if($temp.NB -eq "N" ){
- $inventory += $temp
- }
- }
- ELSE{
- $inventory += $temp
- }
- }
- }
- }
- $body = $inventory | sort-object ship,item | ConvertTo-Html -Fragment
- $completedreport = $htmlhead + $body + $htmltail
- $filepath = $env:TMP + "\inventory.htm"
- write-host $filepath
- $completedreport | out-File $filepath
- invoke-item -Path $filepath
- $button3.enabled = $true
- }
- $button1_OnClick=
- {
- $path = Get-FileName -initialDirectory "%temp%"
- $textBox1.text = $path
- Get-Item -path $path | Replace-FileString -Pattern '<DOCKEDSHIP>' -Replacement '' -Overwrite
- Get-Item -path $path | Replace-FileString -Pattern '</DOCKEDSHIP>' -Replacement '' -Overwrite
- #Get-Item -path $path | Replace-FileString -Pattern '"/>' -Replacement '"</ITEM>' -Overwrite
- }
- $button2_OnClick=
- {
- $button2.enabled = $false
- $inventory = @()
- $path = $textbox1.text
- [xml]$charinv = Get-Content $path
- $hulls = $charinv.inventory.ship.hull
- #$hulls > c.txt
- #$charinv.inventory.ship | ft
- foreach( $ship in $charinv.inventory.ship)
- {
- [string]$id = $ship.hull.id
- $name = $ship.hull.'#text'.toupper()
- write-host $name $ID -BackgroundColor yellow -ForegroundColor black
- $items = $ship.item
- #$items | select nm, id, m >> item.txt
- foreach ($item in $items){
- $temp = "" | select Ship, Shipid, Num, Item, Modifications, EQ, NB, Mods | Sort-Object ship,item
- # ,Min,Com,Shi,Ext,Sco,Dyn,Amo,Rad,Slk,Res,Dck,Int,Amp,Rew,Wrk,Evl,Sup,Trn,Ovc,Frc,Gyr,Buf,SIn,Ang,Rei
- $temp.ship = $name
- $temp.shipid = $id
- $temp.item = $item.nm
- #$temp.itemid = $item.id
- [int]$moddec = $item.m
- $temp.Num = $item.quant
- $mods = lookup-mods $moddec
- $temp.mods = $mods.count
- $mods = $mods -join ","
- $temp.modifications = $mods
- if($item.eqp -eq 1){
- $temp.eq = "Y"
- }
- ELSE{
- $temp.eq = "N"
- }
- if($item.own -ne $null){
- $temp.NB = "Y"
- }
- ELSE{
- $temp.NB = "N"
- }
- #write-host $item.nm $item.m
- if($checkBox1.checked){
- if($item.m -ne $null){
- if($checkbox2.checked){
- if($temp.NB -eq "N" ){
- $inventory += $temp
- }
- }
- ELSE{
- $inventory += $temp
- }
- }
- }
- Else{
- if($checkbox2.checked){
- if($temp.NB -eq "N" ){
- $inventory += $temp
- }
- }
- ELSE{
- $inventory += $temp
- }
- }
- }
- }
- $inventory | sort-object Ship,Item | ogv
- $button2.enabled = $true
- }
- $OnLoadForm_StateCorrection=
- {#Correct the initial state of the form to prevent the .Net maximized form issue
- $form1.WindowState = $InitialFormWindowState
- }
- #----------------------------------------------
- #region Generated Form Code
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 147
- $System_Drawing_Size.Width = 599
- $form1.ClientSize = $System_Drawing_Size
- $form1.DataBindings.DefaultDataSourceUpdateMode = 0
- $form1.Name = "form1"
- $form1.Text = "StarSonata - Mod Collector Pro"
- $checkBox2.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 33
- $System_Drawing_Point.Y = 108
- $checkBox2.Location = $System_Drawing_Point
- $checkBox2.Name = "checkBox2"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 24
- $System_Drawing_Size.Width = 198
- $checkBox2.Size = $System_Drawing_Size
- $checkBox2.TabIndex = 9
- $checkBox2.Text = "Remove Neurobound"
- $checkBox2.UseVisualStyleBackColor = $True
- $form1.Controls.Add($checkBox2)
- $checkBox1.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 33
- $System_Drawing_Point.Y = 79
- $checkBox1.Location = $System_Drawing_Point
- $checkBox1.Name = "checkBox1"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 24
- $System_Drawing_Size.Width = 198
- $checkBox1.Size = $System_Drawing_Size
- $checkBox1.TabIndex = 8
- $checkBox1.Text = "Only Modded Items"
- $checkBox1.UseVisualStyleBackColor = $True
- $form1.Controls.Add($checkBox1)
- $groupBox1.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 375
- $System_Drawing_Point.Y = 67
- $groupBox1.Location = $System_Drawing_Point
- $groupBox1.Name = "groupBox1"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 65
- $System_Drawing_Size.Width = 200
- $groupBox1.Size = $System_Drawing_Size
- $groupBox1.TabIndex = 7
- $groupBox1.TabStop = $False
- $groupBox1.Text = "Output"
- $form1.Controls.Add($groupBox1)
- $button2.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 6
- $System_Drawing_Point.Y = 31
- $button2.Location = $System_Drawing_Point
- $button2.Name = "button2"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 23
- $System_Drawing_Size.Width = 75
- $button2.Size = $System_Drawing_Size
- $button2.TabIndex = 5
- $button2.Text = "Grid"
- $button2.UseVisualStyleBackColor = $True
- $button2.add_Click($button2_OnClick)
- $groupBox1.Controls.Add($button2)
- $button3.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 119
- $System_Drawing_Point.Y = 31
- $button3.Location = $System_Drawing_Point
- $button3.Name = "button3"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 23
- $System_Drawing_Size.Width = 75
- $button3.Size = $System_Drawing_Size
- $button3.TabIndex = 6
- $button3.Text = "Html"
- $button3.UseVisualStyleBackColor = $True
- $button3.add_Click($button3_OnClick)
- $groupBox1.Controls.Add($button3)
- $label1.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 33
- $System_Drawing_Point.Y = 9
- $label1.Location = $System_Drawing_Point
- $label1.Name = "label1"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 23
- $System_Drawing_Size.Width = 109
- $label1.Size = $System_Drawing_Size
- $label1.TabIndex = 2
- $label1.Text = "XML Location:"
- $form1.Controls.Add($label1)
- $button1.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 500
- $System_Drawing_Point.Y = 37
- $button1.Location = $System_Drawing_Point
- $button1.Name = "button1"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 23
- $System_Drawing_Size.Width = 75
- $button1.Size = $System_Drawing_Size
- $button1.TabIndex = 1
- $button1.Text = "Browse"
- $button1.UseVisualStyleBackColor = $True
- $button1.add_Click($button1_OnClick)
- $form1.Controls.Add($button1)
- $textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 33
- $System_Drawing_Point.Y = 37
- $textBox1.Location = $System_Drawing_Point
- $textBox1.Name = "textBox1"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 23
- $System_Drawing_Size.Width = 461
- $textBox1.Size = $System_Drawing_Size
- $textBox1.TabIndex = 0
- $form1.Controls.Add($textBox1)
- #endregion Generated Form Code
- #Save the initial state of the form
- $InitialFormWindowState = $form1.WindowState
- #Init the OnLoad event to correct the initial state of the form
- $form1.add_Load($OnLoadForm_StateCorrection)
- #Show the Form
- $form1.ShowDialog()| Out-Null
- } #End Function
- #Call the Function
- GenerateForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement