<?php

include_once(dirname(__FILE__).'/../../Base/Model.php');

class MangosConfigurationFile extends Model
{ 
  var $ParameterList;
  
  function __construct($System)
  {
    parent::__construct($System);
    $this->Parameters = array();
  }
  
  function Load($FileName)
  {
    $this->ParameterList = array();
    $Lines = explode("\n", file_get_contents($FileName));
    foreach($Lines as $Line)
    {
      $Line = trim($Line);
      if((strlen(trim($Line)) > 0) and ($Line{0} != '#'))
      {
        $Name = trim(substr($Line, 0, strpos($Line, '=')));
        $Value = trim(substr($Line, strpos($Line, '=') + 1));
        if($Value{0} == '"') $Value = substr($Value, 1, -1);
        $this->ParameterList[$Name] = $Value;
      }
    }
  }
  
  function Save($FileName)
  {
    $Lines = array();
    foreach($this->ParameterList as $Name => $Value)
    {
      if(!is_numeric($Value)) $Value = '"'.$Value.'"';
      $Lines[] = $Name.' = '.$Value;
    }
    file_put_contents($FileName, implode("\n", $Lines));
  } 
}
