Pre:4.0+B4
[reseter.git] / bas / ConfIO.bas
blob322d16288022d3c9812f417fa8a18c140ea959b4
1 Attribute VB_Name = "ConfIO"
2 Option Explicit
3 ' Este archivo es parte del programa "reseter", el cĂșal es pertenece a SVCommunity.org y a Todosv.com
4 ' Mantenedores principales:
5 ' *Vlad
6 Public Declare Function GetPrivateProfileString _
7 Lib "kernel32" _
8 Alias "GetPrivateProfileStringA" (ByVal lpSectionName As String, _
9 ByVal lpKeyName As Any, _
10 ByVal lpDefault As String, _
11 ByVal lpbuffurnedString As String, _
12 ByVal nBuffSize As Long, _
13 ByVal lpFileName As String) As Long
14 Public Declare Function WritePrivateProfileString _
15 Lib "kernel32" _
16 Alias "WritePrivateProfileStringA" (ByVal lpSectionName As String, _
17 ByVal lpKeyName As Any, _
18 ByVal lpString As Any, _
19 ByVal lpFileName As String) As Long
20 Private Declare Function GetPrivateProfileSectionNames _
21 Lib "kernel32.dll" _
22 Alias "GetPrivateProfileSectionNamesA" (ByVal lpszReturnBuffer As String, _
23 ByVal nSize As Long, _
24 ByVal lpFileName As String) As Long
25 Private Declare Function GetPrivateProfileSection _
26 Lib "kernel32" _
27 Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, _
28 ByVal lpReturnedString As String, _
29 ByVal nSize As Long, _
30 ByVal lpFileName As String) As Long
31 'Las siguientes constantes determinan el nombre de la clave a ocupar para el parametro
32 Private Const IO_codigo As String = "Codigo"
34 Public Sub Obtener_Lista_Externa()
35 'Lista
36 '<EhHeader>
37 On Error GoTo Obtener_Lista_Externa_Err
38 '</EhHeader>
39 Dim Modelos() As String
40 Dim szBuf As String, lLen As Integer
41 126 Registrar "Cargando perfiles de dispositivos soportados..."
42 'Obtenemos los nombres de todas las secciones, vienen separadas por NullChar Chr(0)
43 100 szBuf = String$(32767, vbNullChar) 'Creamos el buffer
44 101 lLen = GetPrivateProfileSectionNames(szBuf, Len(szBuf), rINI_ROUTERS) 'Obtenemos el largo del la lectura
45 102 szBuf = Left$(szBuf, lLen) 'Cortamos lo innecesario
47 103 If szBuf = vbNullString Then
48 Exit Sub
49 End If
51 104 Modelos = Split(szBuf, vbNullChar)
52 105 ReDim Preserve Modelos(UBound(Modelos) - 1) As String
53 Dim i As Long 'Para el contador
54 Dim a As Long 'Total de modelos
55 106 a = UBound(Modelos)
57 107 For i = 0 To a
58 108 frmPrincipal.ComReset.AddItem Modelos(i)
59 Next
61 Registrar ">" & a & " perfiles cargados"
63 '<EhFooter>
64 Exit Sub
65 Obtener_Lista_Externa_Err:
66 Controlar_Error Erl, Err.Description, "Reseter.ConfIO.Obtener_Lista_Externa.Ref 12/2/2008 : 09:38:34"
67 Resume Next
68 '</EhFooter>
69 End Sub
71 Public Sub Memoria_IO(nRouter As String)
72 'De la memoria al archivo
73 '<EhHeader>
74 On Error GoTo Memoria_IO_Err
76 '</EhHeader>
77 100 With frmPrincipal
78 101 Escribir nRouter, IO_codigo, m_Datos.codigo
79 End With
81 '<EhFooter>
82 Exit Sub
83 Memoria_IO_Err:
84 Controlar_Error Erl, Err.Description, "Reseter.ConfIO.Memoria_IO.Ref 12/2/2008 : 09:38:34"
85 Resume Next
86 '</EhFooter>
87 End Sub
89 Public Sub IO_Memoria(nRouter As String)
90 'Del archivo a la memoria
91 '<EhHeader>
92 On Error GoTo IO_Memoria_Err
94 '</EhHeader>
95 100 With frmPrincipal
96 101 m_Datos.codigo = Leer(nRouter, IO_codigo)
97 End With
99 102 Mostrar_Datos
100 '<EhFooter>
101 Exit Sub
102 IO_Memoria_Err:
103 Controlar_Error Erl, Err.Description, "Reseter.ConfIO.IO_Memoria.Ref 12/2/2008 : 09:38:34"
104 Resume Next
105 '</EhFooter>
106 End Sub
108 Private Function Leer(nRouter As String, _
109 nEspecificacion As String, _
110 Optional nValor As String = vbNullString) As String
111 '<EhHeader>
112 On Error GoTo Leer_Err
113 '</EhHeader>
114 Dim Buffer As String * 32767
115 Dim Lgt As Long
116 100 Buffer = String$(32767, vbNullChar)
117 101 Lgt = GetPrivateProfileString(nRouter, nEspecificacion, nValor, Buffer, Len(Buffer), rINI_ROUTERS)
119 102 If Lgt Then Leer = Left$(Buffer, Lgt) Else Leer = vbNullString
120 '<EhFooter>
121 Exit Function
122 Leer_Err:
123 Controlar_Error Erl, Err.Description, "Reseter.ConfIO.Leer.Ref 12/2/2008 : 09:38:34"
124 Resume Next
125 '</EhFooter>
126 End Function
128 Private Sub Escribir(nRouter As String, _
129 nEspecificacion As String, _
130 ByVal nValor As String)
131 '<EhHeader>
132 On Error GoTo Escribir_Err
133 '</EhHeader>
134 100 WritePrivateProfileString nRouter, nEspecificacion, nValor, rINI_ROUTERS
135 '<EhFooter>
136 Exit Sub
137 Escribir_Err:
138 Controlar_Error Erl, Err.Description, "Reseter.ConfIO.Escribir.Ref 12/2/2008 : 09:38:34"
139 Resume Next
140 '</EhFooter>
141 End Sub
143 Public Function Existe_Seccion(nRouter As String) As Boolean
144 '28/04/07 -> nRouter definido como String en lugar de Variant
145 '<EhHeader>
146 On Error GoTo Existe_Seccion_Err
147 '</EhHeader>
148 Dim Buffer As String
149 100 Buffer = String$(32767, Chr$(0))
150 101 Existe_Seccion = GetPrivateProfileSection(nRouter, Buffer, Len(Buffer), rINI_ROUTERS)
151 '<EhFooter>
152 Exit Function
153 Existe_Seccion_Err:
154 Controlar_Error Erl, Err.Description, "Reseter.ConfIO.Existe_Seccion.Ref 12/2/2008 : 09:38:34"
155 Resume Next
156 '</EhFooter>
157 End Function