VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "API_DistrManifest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' ======== Products distribution manifest ========
' Shared module version: 20220814
' Tested in:
' Depends on: API_JSON
' Required reference: Scripting, ex_Version
Option Explicit

Private Const MANIFEST_JSON_IDENT = 4

Public data_ As Scripting.Dictionary
Private parser_ As New API_JSON
Private file_ As String

Private Sub Class_Initialize()
  Call parser_.SetupMultiline(MANIFEST_JSON_IDENT)
End Sub

Public Function LoadFrom(sFile$)
  file_ = sFile
  Set data_ = parser_.LoadFromFile(file_)
  If data_ Is Nothing Then _
    Set data_ = New Scripting.Dictionary
End Function

Public Function LoadServer()
  Call LoadFrom(CP_TOOLS_SERVER & "\" & FILE_DISTRIBUTION_MANIFEST)
End Function

Public Function LoadLocal()
  Call LoadFrom(CP_TOOLS_LOCAL & "\" & FILE_DISTRIBUTION_MANIFEST)
End Function

Public Function IsLoaded() As Boolean
  IsLoaded = False
  
  If data_ Is Nothing Then _
    Exit Function
  If data_.Count = 0 Then _
    Exit Function
    
  IsLoaded = True
End Function

Public Function Reload()
  Call LoadFrom(file_)
End Function

Public Function SetVersion(sProduct$, sVersion$)
  data_(sProduct) = sVersion
End Function

Public Function GetVersion(sProduct$) As String
  If Not data_.Exists(sProduct) Then _
    Exit Function
  GetVersion = data_(sProduct)
End Function

Public Function Save() As Boolean
  Save = SaveTo(file_)
End Function

Public Function SaveTo(sFile$) As Boolean
  SaveTo = parser_.SaveToFile(sFile, data_)
End Function
