load_vtm.anubis 3.13 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 29/03/2018
 * Time: 22:35
 * © Calexium 
 */


transmit view_table_manager_types.anubis

define String modules_directory = find_and_replace(my_anubis_directory, "\\", "/") + "/modules/".

public define Maybe(VTM)
  load_plugin
  (
    String file_name
  )
  =
  if (LoadAdm(VTM))load_adm(file_name) is 
  {
    file_not_found               then print("File '"+file_name+"' not found.\n\n");failure, 
    read_error                   then print("Error reading file '"+file_name+"'.\n\n");failure, 
    timeout                      then print("Timeout when loading '"+file_name+"'.\n\n");failure, 
    file_damaged                 then print("File '"+file_name+"' is damaged.\n\n");failure, 
    bad_version(expected,found)  then print("Secondary module '"+file_name+"' doesn't have the same\n"+
                                           "  version ("+found+") as primary module ("+expected+").\n\n");failure, 
    wrong_type(expected,found)   then print("Secondary module '"+file_name+"' has type:\n"+
                                           found+" while primary module expected:\n"+
                                           expected+"\n\n");failure, 
    ok(vtm_plugin)              then println("vtm plugin "+vtm_plugin.db_version+" loaded "); success(vtm_plugin)
  }.
   
define Maybe(VTM)
  load_vtm
  (
    List(String)  left,
    DB_Version    vtm_version
  )=
  if left is 
  {
    []                then failure,
    [file_name . t]   then
      if load_plugin(modules_directory+file_name) is
      {
        failure       then load_vtm(t, vtm_version),
        success(_vtm) then
          if compare_db_version(_vtm.db_version, vtm_version) is
          {
            less            then load_vtm(t, vtm_version),
            more            then failure,            
            equal           then success(_vtm),
            equal_but_sign  then success(_vtm)
          }
      }
  }
.

define Maybe(VTM)
  load_latest_vtm
  (
    List(String)  left,
    VTM           _current_vtm
  )=
  if left is 
  {
    []              then 
      since _current_vtm is vtm(_version, _, _, _),
      if _version.version.numeric = 0 & _version.db_hash = "" then
        failure
      else
        success(_current_vtm),
    [file_name . t]  then
      if load_plugin(modules_directory+file_name) is
      {
        failure       then load_latest_vtm(t, _current_vtm),
        success(_vtm) then
          if compare_db_version( _vtm.db_version, _current_vtm.db_version) is
          {
            less            then load_latest_vtm(t, _current_vtm),
            more            then load_latest_vtm(t, _vtm),            
            equal           then load_latest_vtm(t, _current_vtm),
            equal_but_sign  then load_latest_vtm(t, _current_vtm)
          }
      }
  }
.

public define Maybe(VTM)
  load_vtm
  (
    DB_Version  vtm_version
  )
  =
  with files = directory_list(modules_directory, "vtm_v*.adm"),
  load_vtm(files, vtm_version)
.

public define Maybe(VTM)
  load_latest_vtm
  =
  with files = directory_list(modules_directory, "vtm_v*.adm"),
  load_latest_vtm(files, blank_vtm)
.