Repository navigation
Expand file tree
/
Copy pathGUI_Diff.cpp
More file actions
240 lines (227 loc) · 7.09 KB
/
Copy pathGUI_Diff.cpp
File metadata and controls
240 lines (227 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include "GUI_Diff.h"
GUI_Diff::GUI_Diff() {
CtrlLayout(*this, "GUI Diff v1.0 by Marlon Palacios © 2025");
Sizeable().Zoomable();
validacionOpciones();
metodoOpcionEstricto();
metodoOpcionSilencioso();
metodoOpcionCreditos();
metodoOpcionEstadistica();
metodoOpcionInsensible();
metodoOpcionOrdenado();
cargarArchivo1();
cargarArchivo2();
metodoOpcionDinamico();
metodoBotonComparar();
}
void GUI_Diff::validacionOpciones() {
if (dataArchivo2.GetData() == "" || dataArchivo1.GetData() == "") {//habilitar/desabilitar all
botonComparar.Enable(false);
opcionEstricto.Enable(false);
opcionEstadistica.Enable(false);
opcionOrdenado.Enable(false);
opcionInsensible.Enable(false);
opcionSilencioso.Enable(false);
opcionCreditos.Enable(false);
}
else {
botonComparar.Enable(true);
opcionEstricto.Enable(true);
opcionEstadistica.Enable(true);
opcionOrdenado.Enable(true);
opcionInsensible.Enable(true);
opcionSilencioso.Enable(true);
opcionCreditos.Enable(true);
}
}
void GUI_Diff::cargarArchivo1() {
dataArchivo1 << [=] {//cargar archivo 1
FileSel selectorDeArchivo;
selectorDeArchivo.Type("Text file(s)", "*.txt");
selectorDeArchivo.ActiveDir(GetCurrentDirectory());//para conseguir la ubicacion actual
if (selectorDeArchivo.ExecuteOpen())
dataArchivo1.SetData(selectorDeArchivo.Get());
else
Exclamation("No se seleciono nada");
validacionOpciones();
};
}
void GUI_Diff::cargarArchivo2() {
dataArchivo2 << [=] {//cargar archivo 2
FileSel selectorDeArchivo;
selectorDeArchivo.Type("Text file(s)", "*.txt");
selectorDeArchivo.ActiveDir(GetCurrentDirectory());
if (selectorDeArchivo.ExecuteOpen()) {
dataArchivo2.SetData(selectorDeArchivo.Get());
}
else
Exclamation("No se seleciono nada");
validacionOpciones();
};
}
void GUI_Diff::metodoBotonComparar() {
//comparar
botonComparar << [=] {
comparacionTextos();
};
}
void GUI_Diff::metodoOpcionEstricto() {
//estricto
opcionEstricto << [=] {
opcionOrdenado.Set(false);
if (opcionDinamico)
comparacionTextos();
};
}
void GUI_Diff::metodoOpcionOrdenado() {
//ordenado
opcionOrdenado << [=] {
opcionEstricto.Set(false);
if (opcionDinamico)
comparacionTextos();
};
}
void GUI_Diff::metodoOpcionInsensible() {
//insensible
opcionInsensible << [=] {
if (opcionDinamico)
comparacionTextos();
};
}
void GUI_Diff::metodoOpcionSilencioso() {
//silencioso
opcionSilencioso << [=] {
opcionEstadistica.Set(false);
opcionCreditos.Set(false);
if (opcionDinamico)
comparacionTextos();
};
}
void GUI_Diff::metodoOpcionEstadistica() {
//estadistica
opcionEstadistica << [=] {
opcionSilencioso.Set(false);
if (opcionDinamico)
comparacionTextos();
};
}
void GUI_Diff::metodoOpcionCreditos() {
//creditos
opcionCreditos << [=] {
opcionSilencioso.Set(false);
if (opcionDinamico)
comparacionTextos();
};
}
void GUI_Diff::metodoOpcionDinamico() {
opcionDinamico << [=] {//dinamico
if (opcionDinamico.Get())
botonComparar.Enable(false);
else if (dataArchivo2.GetData() != "" && dataArchivo1.GetData() != "")
botonComparar.Enable(true);
};
}
void GUI_Diff::AMinusculas(Vector<String>& vector) {
for (int indice = 0; indice < vector.size(); indice++) {
vector[indice] = ToLower(vector[indice]);
}
}
void GUI_Diff::OrdenarTexto(Vector<String>& vector) {
int size = vector.size();
for (int indice1 = 0; indice1 < size - 1; indice1++) {
for (int indice2 = 0; indice2 < size - indice1 - 1; indice2++) {
if (vector[indice2] > vector[indice2 + 1]) {
String temporal = vector[indice2];
vector[indice2] = vector[indice2 + 1];
vector[indice2 + 1] = temporal;
}
}
}
}
void GUI_Diff::comparacionTextos() {
String salidaQTF = "";
String path1 = dataArchivo1.GetData();
String path2 = dataArchivo2.GetData();
if (!FileExists(path1) || !FileExists(path2)) {//validaciones de los archivos
if (!FileExists(path1))
Exclamation("No encuentro el archivo 1 ('" + path1 + "')");
if (!FileExists(path2))
Exclamation("No encuentro el archivo 2 ('" + path2 + "')");
miRichTextView.Background(Red());
miRichTextView.SetQTF("");
return;
}
String nombreArchivo1 = strrchr(path1, '\\');
String nombreArchivo2 = strrchr(path2, '\\');
String contenido1 = LoadFile(path1);
String contenido2 = LoadFile(path2);
Vector<String> lineas1 = Split(contenido1, "\n");
Vector<String> lineas2 = Split(contenido2, "\n");
for (int indice = 0; indice < lineas1.size(); indice++)
lineas1[indice] = TrimBoth(lineas1[indice]);//para borrar /n y /r
for (int indice = 0; indice < lineas2.size(); indice++)
lineas2[indice] = TrimBoth(lineas2[indice]);
int size1 = 0, size2 = 0;//para obtener size
for (int indice = 0; indice < lineas1.size(); indice++)
size1 += lineas1[indice].GetCount();
for (int indice = 0; indice < lineas2.size(); indice++)
size2 += lineas2[indice].GetCount();
// Ordenado
if (opcionOrdenado.Get()) {
OrdenarTexto(lineas1);
OrdenarTexto(lineas2);
}
// Insensible
if (opcionInsensible.Get()) {
if (!opcionSilencioso.Get()) {
salidaQTF += "[7@8*_C CONVERSIÓN:]&";
salidaQTF += "[2@8 -|" + nombreArchivo1 + ": 'mayúsculas -> minúsculas']&";
salidaQTF += "[2@8 -|" + nombreArchivo2 + ": 'mayúsculas -> minúsculas']&";
}
AMinusculas(lineas1);
AMinusculas(lineas2);
}
String stringTemporal = "";
int lineasMaximas = max(lineas1.GetCount(), lineas2.GetCount());
bool sonIguales = true;
for (int indice = 0; indice < lineasMaximas; indice++) {
String linea1 = (indice < lineas1.GetCount()) ? lineas1[indice] : "EOF";//validacion con operador ternario
String linea2 = (indice < lineas2.GetCount()) ? lineas2[indice] : "EOF";
if (linea1 != linea2) {
sonIguales = false;
stringTemporal += "[2@3 -|" + nombreArchivo1 + ": '" + linea1 + "' != " + nombreArchivo2 + ": '" + linea2 + "']&";
}
else if (!opcionSilencioso.Get()) {
stringTemporal += "[2@4 -|" + nombreArchivo1 + ": '" + linea1 + "' == " + nombreArchivo2 + ": '" + linea2 + "']&";
}
}
//comparacion
if (!opcionSilencioso.Get() || !sonIguales) {
salidaQTF += "[7@8*_C COMPARACIÓN:]&";
salidaQTF += stringTemporal;
}
// Conclusión
if (!opcionSilencioso.Get() || !sonIguales)
salidaQTF += "&[7@8*_C CONCLUSIÓN:]&";
if (sonIguales) {
if (!opcionSilencioso.Get() || !sonIguales)
salidaQTF += "[2@4 -|'" + nombreArchivo1 + "' y '" + nombreArchivo2 + "' tienen el MISMO contenido!]&";
miRichTextView.Background(ColorFromText("#006400"));//color verde
}
else {
if (!opcionSilencioso.Get() || !sonIguales)
salidaQTF += "[2@3 -|'" + nombreArchivo1 + "' y '" + nombreArchivo2 + "' tienen DIFERENTE contenido!]&";
miRichTextView.Background(Red());
}
// Estadísticas
if (opcionEstadistica.Get()) {
salidaQTF += "&[7@8*_C ESTADÍSTICAS:]&";
salidaQTF += "[2@0 -|'" << nombreArchivo1 << "' contiene " << lineas1.GetCount() << " líneas y " << size1 << " caracteres.]&";
salidaQTF += "[2@0 -|'" << nombreArchivo2 << "' contiene " << lineas2.GetCount() << " líneas y " << size2 << " caracteres.]&";
}
// Créditos
if (opcionCreditos.Get() && !opcionSilencioso.Get()) {
salidaQTF += "[1@1> GUI Diff v1.0 by Marlon Palacios (c) 2025]";
}
miRichTextView.SetQTF(salidaQTF);
}