SHARE
TWEET

Untitled

a guest Oct 21st, 2019 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class SettingsObj
  2. {
  3.    [String] $location
  4.    $settings
  5.    
  6.    SettingsObj ([String]$location)
  7.    {
  8.       $this.location = $location
  9.       $this.updateSettings();
  10.    }
  11.    
  12.    updateSettings() {
  13.       #If there are already settings in the specified location, load them
  14.       if([System.IO.File]::Exists($this.location)){
  15.          $this.settings = Import-Clixml $this.location
  16.       } else {
  17.          #Otherwise, create a new, empty, settings object
  18.          $this.settings = New-Object 'System.Collections.Generic.Dictionary[String,String]'
  19.       }
  20.    }
  21.    
  22.    [String] getSetting([String]$setting) {
  23.       $this.updateSettings();
  24.       return $this.settings[$setting]
  25.    }
  26.    
  27.    [bool] hasSetting([String]$setting) {
  28.       $this.updateSettings();
  29.       return $this.settings.ContainsKey($setting)
  30.    }
  31.    
  32.    setSetting([String]$setting, [String]$newVal) {
  33.       $this.updateSettings();
  34.       if($this.settings.ContainsKey($setting)){
  35.          this.settings[$setting] = $newVal;
  36.       } else {
  37.          $this.settings.Add($setting, $newVal)
  38.       }
  39.       #Whenever settings are added/changed, export them so they are on-disk
  40.       Export-Clixml -InputObject $this.settings -Path $this.location
  41.    }
  42.    
  43.    removeSetting([String]$setting) {
  44.       $this.updateSettings();
  45.       if($this.settings.ContainsKey($setting)){
  46.          $this.settings.Remove($setting)
  47.          #Whenever settings are removed, export them so they are on-disk
  48.          Export-Clixml -InputObject $this.settings -Path $this.location
  49.       }
  50.    }
  51.    
  52.    printSettings() {
  53.       Write-Host $($this.settings | Out-String)
  54.    }
  55. }
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