VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "mFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Public fTemporaryPath As String
Attribute fTemporaryPath.VB_VarDescription = "Path used for placing in temporary files."

Public Function iAbout(Box As Boolean) As String
Attribute iAbout.VB_Description = "Returns internal information about the component, can display a MSGBOX."
iAbout = "ICI style I/O PO file access module" + vbCrLf + _
"Made by Jure Sah of MesonAI" + vbCrLf + _
"Last modified on 12:32 3.5.2002" + vbCrLf + _
"DO NOT MODIFY WITHOUT MY PREMITION!!!" + vbCrLf + _
"jure.sah@guest.arnes.si" + vbCrLf + _
vbCrLf + _
"FREEWARE!" + vbCrLf + _
vbCrLf + _
"ICI xc project, originals for ICI Console interface"
If Box Then MsgBox iAbout, vbInformation, "DS DLL"
End Function

Public Function iVB_Code(Box As Boolean) As String
Attribute iVB_Code.VB_Description = "Returns the internal VB code to get the Temp path. Can display a MSGBOX."
iVB_Code = "File.fTemporaryPath = Environ$(" + Chr$(34) + "ICI" + Chr$(34) + ")" + vbCrLf + _
"If File.fTemporaryPath = " + Chr$(34) + Chr$(34) + " Then File.fTemporaryPath = Environ$(" + Chr$(34) + "TEMP" + Chr$(34) + ") " + vbCrLf + _
"If File.fTemporaryPath = " + Chr$(34) + Chr$(34) + " Then File.fTemporaryPath = Environ$(" + Chr$(34) + "TMP" + Chr$(34) + ") " + vbCrLf + _
"If File.fTemporaryPath = " + Chr$(34) + Chr$(34) + " Then File.fTemporaryPath = App.Path"
If Box Then MsgBox iVB_Code, vbInformation, "DS DLL"
End Function

Public Sub xDeleteEntry(xFile As String)
Attribute xDeleteEntry.VB_Description = "Removes the top entry from the PO file."
'    On Error Resume Next
Randomize Timer
Dim Copy_now As Boolean, Already_got_an_entry As Boolean, xSwapFile As String

Copy_now = False
Already_got_an_entry = False
''Name a temporary file and make sure it doesn't already exist
xSwapFile = xSwpFile(xFile)

FN1 = FreeFile
Open xFile For Input As #FN1
FN2 = FreeFile
Open xSwapFile For Output As #FN2
Do
    Line Input #FN1, a$
    If Left$(a$, 3) = "---" Then
        If Already_got_an_entry Then Copy_now = True
        Already_got_an_entry = True
    End If
    ''When past the first entry, copy to swap file
    If Copy_now Then Print #FN2, a$
Loop Until EOF(FN1)
Close #FN1, #FN2
''Swap swap file with original
Kill xFile
Name xSwapFile As xFile
End Sub

Public Function xReadEntry(xFile As String) As String
Attribute xReadEntry.VB_Description = "Reads the top entry in the PO file."
'    On Error Resume Next
Dim OK_to_quit  As Boolean, Already_got_an_entry As Boolean

OK_to_quit = False
Already_got_an_entry = False

''Don't read if the file is empty
If FileLen(xFile) = 0 Then xReadEntry = "": Exit Function

''Read an entry
FN = FreeFile
Open xFile For Input As #FN
Do
    Line Input #FN, a$
    If Left$(a$, 3) = "---" Then
        If Already_got_an_entry Then OK_to_quit = True
        Already_got_an_entry = True
        Else
        xReadEntry = xReadEntry + a$ + vbCrLf
    End If
Loop Until EOF(FN) Or OK_to_quit
Close #FN
End Function

Public Sub xWriteEntry(xFile As String, xEntryText As String)
Attribute xWriteEntry.VB_Description = "Appends an entry to the PO file."
'    On Error Resume Next
FN = FreeFile
Open xFile For Append As #FN
Print #FN, "--- Entry by CFP Default on " + Date$ + " " + Time$
Print #FN, xEntryText
Close #FN
'Debug.Print "("; FN; ")", "("; xFile; ")", "("; xEntryText; ")"
End Sub

Public Function xTrim(xS As String) As String
'    On Error Resume Next
''Strip leading and trailing CR and linefeed
If Left$(xS, 2) = vbCrLf Then xS = Mid$(xS, 3)
If Right$(xS, 2) = vbCrLf Then xS = Mid$(xS, 1, Len(xS) - 2)
''Strip leading and trailing spaces
xTrim = Trim$(xS)
End Function

Public Sub xLog(xFile As String, xEntryText As String)
'    On Error Resume Next
yFN = FreeFile
Open xFile + ".Log" For Append As #yFN
Print #yFN, Date$; " "; Time$; "| "; xEntryText
Close #yFN
End Sub

Private Function xSwpFile(xName As String) As String
'    On Error Resume Next
inst = 0
2 inst = inst + 1
xSwpFile = File.fTemporaryPath + "\CFP." + Dir$(xName) + "." + Hex$(inst) + ".TMP"
'Debug.Print "["; xName; "]", "["; xSwpFile; "]"
If Not (Dir$(xSwpFile) = "") Then GoTo 2
End Function



