daily pastebin goal
64%
SHARE
TWEET

Star sonata Mod collector.PS1

a guest Mar 15th, 2015 229 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #region ### CSS ###
  2.                 $htmlhead="<html>
  3.                                                                 <style>
  4.                                                                 BODY{font-family: Calibri; font-size: 10pt;text-align:center;}
  5.                                                                 H1{font-size: 16px; color: #780000;text-align:left;}
  6.                                                                 h2{font-size: 14px; color: #780000;text-align:left;}
  7.                                                                 H3{font-size: 10px; color: #780000;text-align:left;}
  8.                                                                 TABLE{border: 1px solid black; border-collapse: collapse; font-size: 10pt;width:90%; margin-left:5%; margin-right:5%;}
  9.                                                 tr:nth-child(odd) {background: #EEE}
  10.                                                 tr:nth-child(even) {background: #FFF}  
  11.                                                                 TH{border: 1px solid black; background: #dddddd; padding: 2px; color: #000000;}
  12.                                                                 TD{border: 1px solid black; padding: 1px; }
  13.                                                                 Td.column{border: 1px solid black; background: #dddddd; padding: 2px; color: #000000; font-weight:bold;}
  14.                                                                 td.pass{background: #7FFF00;}
  15.                                                                 td.warn{background: #FFE600;}
  16.                                                                 td.fail{background: #FF0000; color: #ffffff;}
  17.                                                                 </style>
  18.                                                                 "
  19.  
  20.                 $htmltail = "</html>"
  21.  
  22. #endregion
  23.  
  24. Function Get-FileName($initialDirectory)
  25. {  
  26.  [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
  27.  Out-Null
  28.  
  29.  $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
  30.  $OpenFileDialog.initialDirectory = $initialDirectory
  31.  $OpenFileDialog.filter = "All files (*.*)| *.*"
  32.  $OpenFileDialog.ShowDialog() | Out-Null
  33.  $OpenFileDialog.filename
  34. } #end function Get-FileName
  35.  
  36. function replace-filestring(
  37.   [parameter(Mandatory=$TRUE,Position=0)]
  38.     [String] $Pattern,
  39.   [parameter(Mandatory=$TRUE,Position=1)]
  40.     [String] [AllowEmptyString()] $Replacement,
  41.   [parameter(Mandatory=$TRUE,ParameterSetName="Path",
  42.     Position=2,ValueFromPipeline=$TRUE)]
  43.     [String[]] $Path,
  44.   [parameter(Mandatory=$TRUE,ParameterSetName="LiteralPath",
  45.     Position=2)]
  46.     [String[]] $LiteralPath,
  47.     [Switch] $CaseSensitive,
  48.     [Switch] $Multiline,
  49.     [Switch] $UnixText,
  50.     [Switch] $Overwrite,
  51.     [Switch] $Force,
  52.     [String] $Encoding="ASCII"
  53. ){
  54. begin {
  55.   # Throw an error if $Encoding is not valid.
  56.   $encodings = @("ASCII","BigEndianUnicode","Unicode","UTF32","UTF7",
  57.                  "UTF8")
  58.   if ($encodings -notcontains $Encoding) {
  59.     throw "Encoding must be one of the following: $encodings"
  60.   }
  61.  
  62.   # Extended test-path: Check the parameter set name to see if we
  63.   # should use -literalpath or not.
  64.   function test-pathEx($path) {
  65.     switch ($PSCmdlet.ParameterSetName) {
  66.       "Path" {
  67.         test-path $path
  68.       }
  69.       "LiteralPath" {
  70.         test-path -literalpath $path
  71.       }
  72.     }
  73.   }
  74.  
  75.   # Extended get-childitem: Check the parameter set name to see if we
  76.   # should use -literalpath or not.
  77.   function get-childitemEx($path) {
  78.     switch ($PSCmdlet.ParameterSetName) {
  79.       "Path" {
  80.         get-childitem $path -force
  81.       }
  82.       "LiteralPath" {
  83.         get-childitem -literalpath $path -force
  84.       }
  85.     }
  86.   }
  87.  
  88.   # Outputs the full name of a temporary file in the specified path.
  89.   function get-tempname($path) {
  90.     do {
  91.       $tempname = join-path $path ([IO.Path]::GetRandomFilename())
  92.     }
  93.     while (test-path $tempname)
  94.     $tempname
  95.   }
  96.  
  97.   # Use '\r$' instead of '$' unless -UnixText specified because
  98.   # '$' alone matches '\n', not '\r\n'. Ignore '\$' (literal '$').
  99.   if (-not $UnixText) {
  100.     $Pattern = $Pattern -replace '(?<!\\)\$', '\r$'
  101.   }
  102.  
  103.   # Build an array of Regex options and create the Regex object.
  104.   $opts = @()
  105.   if (-not $CaseSensitive) { $opts += "IgnoreCase" }
  106.   if ($MultiLine) { $opts += "Multiline" }
  107.   if ($opts.Length -eq 0) { $opts += "None" }
  108.   $regex = new-object Text.RegularExpressions.Regex $Pattern, $opts
  109. }
  110.  
  111. process {
  112.   # The list of items to iterate depends on the parameter set name.
  113.   switch ($PSCmdlet.ParameterSetName) {
  114.     "Path" { $list = $Path }
  115.     "LiteralPath" { $list = $LiteralPath }
  116.   }
  117.  
  118.   # Iterate the items in the list of paths. If an item does not exist,
  119.   # continue to the next item in the list.
  120.   foreach ($item in $list) {
  121.     if (-not (test-pathEx $item)) {
  122.       write-error "Unable to find '$item'."
  123.       continue
  124.     }
  125.  
  126.     # Iterate each item in the path. If an item is not a file,
  127.     # skip all remaining items.
  128.     foreach ($file in get-childitemEx $item) {
  129.       if ($file -isnot [IO.FileInfo]) {
  130.         write-error "'$file' is not in the file system."
  131.         break
  132.       }
  133.  
  134.       # Get a temporary file name in the file's directory and create
  135.       # it as a empty file. If set-content fails, continue to the next
  136.       # file. Better to fail before than after reading the file for
  137.       # performance reasons.
  138.       if ($Overwrite) {
  139.         $tempname = get-tempname $file.DirectoryName
  140.         set-content $tempname $NULL -confirm:$FALSE
  141.         if (-not $?) { continue }
  142.         write-verbose "Created file '$tempname'."
  143.       }
  144.  
  145.       # Read all the text from the file into a single string. We have
  146.       # to do it this way to be able to search across line breaks.
  147.       try {
  148.         write-verbose "Reading '$file'."
  149.         $text = [IO.File]::ReadAllText($file.FullName)
  150.         write-verbose "Finished reading '$file'."
  151.       }
  152.       catch [Management.Automation.MethodInvocationException] {
  153.         write-error $ERROR[0]
  154.         continue
  155.       }
  156.  
  157.       # If -Overwrite not specified, output the result of the Replace
  158.       # method and continue to the next file.
  159.       if (-not $Overwrite) {
  160.         $regex.Replace($text, $Replacement)
  161.         continue
  162.       }
  163.  
  164.       # Do nothing further if we're in 'what if' mode.
  165.       if ($WHATIFPREFERENCE) { continue }
  166.  
  167.       try {
  168.         write-verbose "Writing '$tempname'."
  169.         [IO.File]::WriteAllText("$tempname", $regex.Replace($text,
  170.           $Replacement), [Text.Encoding]::$Encoding)
  171.         write-verbose "Finished writing '$tempname'."
  172.         write-verbose "Copying '$tempname' to '$file'."
  173.         copy-item $tempname $file -force:$Force -erroraction Continue
  174.         if ($?) {
  175.           write-verbose "Finished copying '$tempname' to '$file'."
  176.         }
  177.         remove-item $tempname
  178.         if ($?) {
  179.           write-verbose "Removed file '$tempname'."
  180.         }
  181.       }
  182.       catch [Management.Automation.MethodInvocationException] {
  183.         write-error $ERROR[0]
  184.       }
  185.     } # foreach $file
  186.   } # foreach $item
  187. } # process
  188.  
  189. end { }
  190.  
  191. }
  192.  
  193. function tidy-input($file){
  194.  
  195. }
  196.  
  197. function lookup-mods([int]$modval){
  198.  
  199. $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"}
  200. $mods = $modhash.Keys | where { $_ -band $modval } | foreach { $modhash.Get_Item($_) }
  201. return $mods
  202. }
  203.  
  204. #Generated Form Function
  205. function GenerateForm {
  206. ########################################################################
  207. # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
  208. # Generated On: 14/03/2015 17:35
  209. # Generated By: Topbuzzz
  210. ########################################################################
  211.  
  212. #region Import the Assemblies
  213. [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
  214. [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
  215. #endregion
  216.  
  217. #region Generated Form Objects
  218. $form1 = New-Object System.Windows.Forms.Form
  219. $checkBox2 = New-Object System.Windows.Forms.CheckBox
  220. $checkBox1 = New-Object System.Windows.Forms.CheckBox
  221. $groupBox1 = New-Object System.Windows.Forms.GroupBox
  222. $button2 = New-Object System.Windows.Forms.Button
  223. $button3 = New-Object System.Windows.Forms.Button
  224. $label1 = New-Object System.Windows.Forms.Label
  225. $button1 = New-Object System.Windows.Forms.Button
  226. $textBox1 = New-Object System.Windows.Forms.TextBox
  227. $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
  228. #endregion Generated Form Objects
  229.  
  230. #----------------------------------------------
  231. #Generated Event Script Blocks
  232. #----------------------------------------------
  233. #Provide Custom Code for events specified in PrimalForms.
  234. $button3_OnClick=
  235. {
  236. $button3.enabled = $false
  237. $inventory = @()
  238. $path = $textbox1.text
  239. [xml]$charinv = Get-Content $path
  240. $hulls = $charinv.inventory.ship.hull
  241. #$hulls > c.txt
  242. #$charinv.inventory.ship | ft
  243. foreach( $ship in $charinv.inventory.ship)
  244. {
  245.      
  246.      [string]$id = $ship.hull.id
  247.      $name = $ship.hull.'#text'.toupper()
  248.  
  249.      write-host $name $ID -BackgroundColor yellow -ForegroundColor black
  250.      $items = $ship.item
  251.  
  252.      #$items | select nm, id, m >> item.txt
  253.  
  254.             foreach ($item in $items){
  255.             $temp = "" | select ship, shipid, item, Quantity, mod, NB, equipped, itemid | Sort-Object ship,item
  256.            
  257.             $temp.ship = $name
  258.             $temp.shipid = $id
  259.             $temp.item = $item.nm
  260.             $temp.itemid = $item.id
  261.             [int]$moddec = $item.m
  262.             $temp.Quantity = $item.quant
  263.             $mods = lookup-mods $moddec
  264.             $mods = $mods -join ","
  265.             $temp.mod = $mods
  266.  
  267.             if($item.eqp -eq 1){
  268.             $temp.equipped = "Y"
  269.             }
  270.             ELSE{
  271.             $temp.equipped = "N"
  272.             }
  273.             if($item.own -ne $null){
  274.             $temp.NB = "Y"
  275.             }
  276.             ELSE{
  277.             $temp.NB = "N"
  278.             }          
  279.  
  280.             #write-host $item.nm $item.m
  281.  
  282.             if($checkBox1.checked){
  283.            
  284.                 if($item.m -ne $null){
  285.  
  286.                     if($checkbox2.checked){
  287.                    
  288.                         if($temp.NB -eq "N" ){
  289.                         $inventory += $temp
  290.                         }
  291.                     }
  292.                     ELSE{
  293.                     $inventory += $temp
  294.                     }
  295.                 }          
  296.             }
  297.             Else{
  298.                     if($checkbox2.checked){
  299.                    
  300.                         if($temp.NB -eq "N" ){
  301.                         $inventory += $temp
  302.                         }
  303.                     }
  304.                     ELSE{
  305.                     $inventory += $temp
  306.                     }
  307.             }
  308.            
  309.             }
  310.  
  311. }
  312.  
  313. $body = $inventory | sort-object ship,item | ConvertTo-Html -Fragment
  314. $completedreport = $htmlhead + $body + $htmltail
  315. $filepath = $env:TMP + "\inventory.htm"
  316. write-host $filepath
  317. $completedreport | out-File $filepath
  318. invoke-item -Path $filepath
  319. $button3.enabled = $true
  320. }
  321.  
  322. $button1_OnClick=
  323. {
  324. $path = Get-FileName -initialDirectory "%temp%"
  325. $textBox1.text = $path
  326. Get-Item -path $path | Replace-FileString  -Pattern '<DOCKEDSHIP>' -Replacement '' -Overwrite
  327. Get-Item -path $path | Replace-FileString  -Pattern '</DOCKEDSHIP>' -Replacement '' -Overwrite
  328. #Get-Item -path $path | Replace-FileString  -Pattern '"/>' -Replacement '"</ITEM>' -Overwrite
  329.  
  330.  
  331.  
  332. }
  333.  
  334. $button2_OnClick=
  335. {
  336. $button2.enabled = $false
  337. $inventory = @()
  338. $path = $textbox1.text
  339. [xml]$charinv = Get-Content $path
  340. $hulls = $charinv.inventory.ship.hull
  341. #$hulls > c.txt
  342. #$charinv.inventory.ship | ft
  343. foreach( $ship in $charinv.inventory.ship)
  344. {
  345.      
  346.      [string]$id = $ship.hull.id
  347.      $name = $ship.hull.'#text'.toupper()
  348.  
  349.      write-host $name $ID -BackgroundColor yellow -ForegroundColor black
  350.      $items = $ship.item
  351.  
  352.      #$items | select nm, id, m >> item.txt
  353.  
  354.             foreach ($item in $items){
  355.             $temp = "" | select Ship, Shipid, Num, Item, Modifications, EQ, NB, Mods | Sort-Object ship,item
  356.             # ,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
  357.  
  358.             $temp.ship = $name
  359.             $temp.shipid = $id
  360.             $temp.item = $item.nm
  361.             #$temp.itemid = $item.id
  362.             [int]$moddec = $item.m
  363.             $temp.Num = $item.quant
  364.             $mods = lookup-mods $moddec
  365.             $temp.mods = $mods.count
  366.             $mods = $mods -join ","
  367.             $temp.modifications = $mods
  368.  
  369.             if($item.eqp -eq 1){
  370.             $temp.eq = "Y"
  371.             }
  372.             ELSE{
  373.             $temp.eq = "N"
  374.             }
  375.             if($item.own -ne $null){
  376.             $temp.NB = "Y"
  377.             }
  378.             ELSE{
  379.             $temp.NB = "N"
  380.             }          
  381.  
  382.  
  383.  
  384.  
  385.             #write-host $item.nm $item.m
  386.  
  387.             if($checkBox1.checked){
  388.            
  389.                 if($item.m -ne $null){
  390.  
  391.                     if($checkbox2.checked){
  392.                    
  393.                         if($temp.NB -eq "N" ){
  394.                         $inventory += $temp
  395.                         }
  396.                     }
  397.                     ELSE{
  398.                     $inventory += $temp
  399.                     }
  400.                 }          
  401.             }
  402.             Else{
  403.                     if($checkbox2.checked){
  404.                    
  405.                         if($temp.NB -eq "N" ){
  406.                         $inventory += $temp
  407.                         }
  408.                     }
  409.                     ELSE{
  410.                     $inventory += $temp
  411.                     }
  412.             }
  413.            
  414.             }
  415.  
  416. }
  417.  
  418. $inventory | sort-object Ship,Item | ogv
  419. $button2.enabled = $true
  420. }
  421.  
  422. $OnLoadForm_StateCorrection=
  423. {#Correct the initial state of the form to prevent the .Net maximized form issue
  424.         $form1.WindowState = $InitialFormWindowState
  425. }
  426.  
  427. #----------------------------------------------
  428. #region Generated Form Code
  429. $System_Drawing_Size = New-Object System.Drawing.Size
  430. $System_Drawing_Size.Height = 147
  431. $System_Drawing_Size.Width = 599
  432. $form1.ClientSize = $System_Drawing_Size
  433. $form1.DataBindings.DefaultDataSourceUpdateMode = 0
  434. $form1.Name = "form1"
  435. $form1.Text = "StarSonata - Mod Collector Pro"
  436.  
  437.  
  438. $checkBox2.DataBindings.DefaultDataSourceUpdateMode = 0
  439.  
  440. $System_Drawing_Point = New-Object System.Drawing.Point
  441. $System_Drawing_Point.X = 33
  442. $System_Drawing_Point.Y = 108
  443. $checkBox2.Location = $System_Drawing_Point
  444. $checkBox2.Name = "checkBox2"
  445. $System_Drawing_Size = New-Object System.Drawing.Size
  446. $System_Drawing_Size.Height = 24
  447. $System_Drawing_Size.Width = 198
  448. $checkBox2.Size = $System_Drawing_Size
  449. $checkBox2.TabIndex = 9
  450. $checkBox2.Text = "Remove Neurobound"
  451. $checkBox2.UseVisualStyleBackColor = $True
  452.  
  453. $form1.Controls.Add($checkBox2)
  454.  
  455.  
  456. $checkBox1.DataBindings.DefaultDataSourceUpdateMode = 0
  457.  
  458. $System_Drawing_Point = New-Object System.Drawing.Point
  459. $System_Drawing_Point.X = 33
  460. $System_Drawing_Point.Y = 79
  461. $checkBox1.Location = $System_Drawing_Point
  462. $checkBox1.Name = "checkBox1"
  463. $System_Drawing_Size = New-Object System.Drawing.Size
  464. $System_Drawing_Size.Height = 24
  465. $System_Drawing_Size.Width = 198
  466. $checkBox1.Size = $System_Drawing_Size
  467. $checkBox1.TabIndex = 8
  468. $checkBox1.Text = "Only Modded Items"
  469. $checkBox1.UseVisualStyleBackColor = $True
  470.  
  471. $form1.Controls.Add($checkBox1)
  472.  
  473.  
  474. $groupBox1.DataBindings.DefaultDataSourceUpdateMode = 0
  475. $System_Drawing_Point = New-Object System.Drawing.Point
  476. $System_Drawing_Point.X = 375
  477. $System_Drawing_Point.Y = 67
  478. $groupBox1.Location = $System_Drawing_Point
  479. $groupBox1.Name = "groupBox1"
  480. $System_Drawing_Size = New-Object System.Drawing.Size
  481. $System_Drawing_Size.Height = 65
  482. $System_Drawing_Size.Width = 200
  483. $groupBox1.Size = $System_Drawing_Size
  484. $groupBox1.TabIndex = 7
  485. $groupBox1.TabStop = $False
  486. $groupBox1.Text = "Output"
  487.  
  488. $form1.Controls.Add($groupBox1)
  489.  
  490. $button2.DataBindings.DefaultDataSourceUpdateMode = 0
  491.  
  492. $System_Drawing_Point = New-Object System.Drawing.Point
  493. $System_Drawing_Point.X = 6
  494. $System_Drawing_Point.Y = 31
  495. $button2.Location = $System_Drawing_Point
  496. $button2.Name = "button2"
  497. $System_Drawing_Size = New-Object System.Drawing.Size
  498. $System_Drawing_Size.Height = 23
  499. $System_Drawing_Size.Width = 75
  500. $button2.Size = $System_Drawing_Size
  501. $button2.TabIndex = 5
  502. $button2.Text = "Grid"
  503. $button2.UseVisualStyleBackColor = $True
  504. $button2.add_Click($button2_OnClick)
  505.  
  506. $groupBox1.Controls.Add($button2)
  507.  
  508.  
  509. $button3.DataBindings.DefaultDataSourceUpdateMode = 0
  510.  
  511. $System_Drawing_Point = New-Object System.Drawing.Point
  512. $System_Drawing_Point.X = 119
  513. $System_Drawing_Point.Y = 31
  514. $button3.Location = $System_Drawing_Point
  515. $button3.Name = "button3"
  516. $System_Drawing_Size = New-Object System.Drawing.Size
  517. $System_Drawing_Size.Height = 23
  518. $System_Drawing_Size.Width = 75
  519. $button3.Size = $System_Drawing_Size
  520. $button3.TabIndex = 6
  521. $button3.Text = "Html"
  522. $button3.UseVisualStyleBackColor = $True
  523. $button3.add_Click($button3_OnClick)
  524.  
  525. $groupBox1.Controls.Add($button3)
  526.  
  527.  
  528. $label1.DataBindings.DefaultDataSourceUpdateMode = 0
  529.  
  530. $System_Drawing_Point = New-Object System.Drawing.Point
  531. $System_Drawing_Point.X = 33
  532. $System_Drawing_Point.Y = 9
  533. $label1.Location = $System_Drawing_Point
  534. $label1.Name = "label1"
  535. $System_Drawing_Size = New-Object System.Drawing.Size
  536. $System_Drawing_Size.Height = 23
  537. $System_Drawing_Size.Width = 109
  538. $label1.Size = $System_Drawing_Size
  539. $label1.TabIndex = 2
  540. $label1.Text = "XML Location:"
  541.  
  542. $form1.Controls.Add($label1)
  543.  
  544.  
  545. $button1.DataBindings.DefaultDataSourceUpdateMode = 0
  546.  
  547. $System_Drawing_Point = New-Object System.Drawing.Point
  548. $System_Drawing_Point.X = 500
  549. $System_Drawing_Point.Y = 37
  550. $button1.Location = $System_Drawing_Point
  551. $button1.Name = "button1"
  552. $System_Drawing_Size = New-Object System.Drawing.Size
  553. $System_Drawing_Size.Height = 23
  554. $System_Drawing_Size.Width = 75
  555. $button1.Size = $System_Drawing_Size
  556. $button1.TabIndex = 1
  557. $button1.Text = "Browse"
  558. $button1.UseVisualStyleBackColor = $True
  559. $button1.add_Click($button1_OnClick)
  560.  
  561. $form1.Controls.Add($button1)
  562.  
  563. $textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
  564. $System_Drawing_Point = New-Object System.Drawing.Point
  565. $System_Drawing_Point.X = 33
  566. $System_Drawing_Point.Y = 37
  567. $textBox1.Location = $System_Drawing_Point
  568. $textBox1.Name = "textBox1"
  569. $System_Drawing_Size = New-Object System.Drawing.Size
  570. $System_Drawing_Size.Height = 23
  571. $System_Drawing_Size.Width = 461
  572. $textBox1.Size = $System_Drawing_Size
  573. $textBox1.TabIndex = 0
  574.  
  575. $form1.Controls.Add($textBox1)
  576.  
  577. #endregion Generated Form Code
  578.  
  579. #Save the initial state of the form
  580. $InitialFormWindowState = $form1.WindowState
  581. #Init the OnLoad event to correct the initial state of the form
  582. $form1.add_Load($OnLoadForm_StateCorrection)
  583. #Show the Form
  584. $form1.ShowDialog()| Out-Null
  585.  
  586. } #End Function
  587.  
  588. #Call the Function
  589. GenerateForm
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top