<?php


namespace CMSMSExt\wip;


use CMSMSExt\core\Error;
use CMSMSExt\Exceptions\FileSystemException;
use CMSMSExt\FS;

class Manifest
{
  protected $_lines = [];
  protected $_builder;
  protected $_do_md5 = FALSE;
  protected $_fv = '';
  protected $_tv = '';
  protected $_out = 'out';
  protected $_temp_root_dir = '';
  
  protected function _initialize()
  {
    $this->_reset();
  }
  
  protected function _reset()
  {
    FS::dir_recursive_delete($this->_temp_root_dir);
  
    $fn = utils::join_path($this->_temp_root_dir, $this->_fv);
  
    if( !FS::mkdir_r($fn) )
    {
      throw new FileSystemException(Error::CREATE_DIR_ERROR, $fn);
    }
  
    $fn = utils::join_path($this->_temp_root_dir, $this->_ft);
  
    if( !FS::mkdir_r($fn) )
    {
      throw new FileSystemException(Error::CREATE_DIR_ERROR, $fn);
    }
  
    $fn = utils::join_path($this->_temp_root_dir, $this->_out);
  
    if( !FS::mkdir_r($fn) )
    {
      throw new FileSystemException(Error::CREATE_DIR_ERROR, $fn);
    }
  }
  
  protected function _reset_out()
  {
    $fn = utils::join_path($this->_temp_root_dir, $this->_out);
    FS::dir_recursive_delete($fn);
  }
  
  
  public function __construct(string $module_name = '', string $from_version = '', string $to_version = '')
  {
    $this->_fv = $from_version;
    $this->_tv = $to_version;
    
    $this->_temp_root_dir = utils::join_path(
      \xt_utils::get_xt()->GetExtendedConfig()['root_path'],
      'tmp',
      '_manifest_tmp_',
      $module_name
    );
  }
  
  public function Save(string $fn = '')
  {
    $this->_reset_out();
  }
}

?>