-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
158 lines (132 loc) · 5.96 KB
/
Program.cs
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
using Microsoft.Win32;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using LoLChatViewer.UI.Animations;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using LoLChatViewer.UI.Panels;
using System.Diagnostics;
namespace LoLChatViewer
{
public class ChatViewerWindow
{
private Dispatcher Dispatcher = System.Windows.Application.Current.Dispatcher;
private TitleElements TitleElements = new();
private LogViewerElements LogViewerElements = new();
// Ubicaciones de las carpetas que se usan, leagueFolderPath vendira siendo la carpeta League of Legends
// leagueLogFolderPath es la ubicacion de la carpeta 'Logs' dentro de 'League of Legends'
// y entireLeaguePath son esas dos de antes pero combinadas.
private String lolFolderPath = Properties.Settings.Default.MainLeaguePath, r3dlogFolderPath = @"\Logs\GameLogs", entireLoLPath = "";
// Grid principal en el que se muestra todo el programa.
private Grid mainGrid = new()
{
VerticalAlignment = VerticalAlignment.Stretch,
HorizontalAlignment = HorizontalAlignment.Stretch,
Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(69, 41, 64)),
IsHitTestVisible = true,
Opacity = 0
};
// Grid delgado posicionado arriba que solo muestra texto.
private Grid topGrid = new()
{
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Stretch,
Height = 100,
Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)),
IsHitTestVisible = true,
};
// Grid que contiene a fileGrid y logGrid, usado mas que nada para seprar un poco todo.
private Grid bottomGrid = new Grid()
{
VerticalAlignment = VerticalAlignment.Stretch,
HorizontalAlignment = HorizontalAlignment.Stretch,
Margin = new Thickness(0, 40, 0, 0),
};
// Easing usado en las animaciones.
private QuadraticEase quadratic = new()
{
EasingMode = EasingMode.EaseOut
};
// Inicio
public Grid Start()
{
if (lolFolderPath == "") // Si esto esta vacio significa que es la primera vez que se inicia el prrograma.
{
if (Directory.Exists(@"C:\Riot Games\League of Legends")) // Si existe y tiene archivos adentro, entonces guardala como default y setearla para usarla en el momento.
{
if (Directory.GetFiles(@"C:\Riot Games\League of Legends").Length > 0)
{
lolFolderPath = @"C:\Riot Games\League of Legends";
Properties.Settings.Default.MainLeaguePath = lolFolderPath;
}
}
else
{
MessageBox.Show("La carpeta 'League of Legends' parece estar en otro lado, selecciona la ubicacion correcta", "Caracoles", MessageBoxButton.OK, MessageBoxImage.Asterisk);
PathCheck();
}
}
// Crear path completo.
entireLoLPath = lolFolderPath + r3dlogFolderPath;
TitleElements.ShowIn(topGrid, "(v1.1) Hallo :D");
LogViewerElements.ShowIn(Dispatcher, LogViewerElements, bottomGrid, entireLoLPath);
// Añadir todo el Grid principal
mainGrid.Children.Add(topGrid);
mainGrid.Children.Add(bottomGrid);
// Setear eventos.
mainGrid.PreviewKeyDown += SelectFileManually;
Animate.Opacity(mainGrid, 1, quadratic, 1300, 0, 0);
Animate.Position(bottomGrid, new TranslateTransform(0, 0), quadratic, 600, 0, new TranslateTransform(0, 50));
Animate.Position(topGrid, new TranslateTransform(0, 0), quadratic, 600, 0, new TranslateTransform(0, -50));
return mainGrid;
}
// Mostrar select file dialog y checkear que la ubicacion es valida.
private void PathCheck()
{
OpenFolderDialog ofd = new()
{
Title = "Seleccione la carpeta 'League of Legends'",
};
bool? DIALOG_RESULT = ofd.ShowDialog(); // Si el usuario presiona 'OK' este boolean da true como resultado.
if (DIALOG_RESULT == true && !string.IsNullOrWhiteSpace(ofd.FolderName))
{
lolFolderPath = ofd.FolderName;
entireLoLPath = lolFolderPath + r3dlogFolderPath;
// Guardar ajustes
Properties.Settings.Default.MainLeaguePath = lolFolderPath;
Properties.Settings.Default.Save();
if (!Directory.Exists(entireLoLPath))
{
MessageBox.Show("Ubicacion invalida", "Frijoles", MessageBoxButton.OK, MessageBoxImage.Error);
PathCheck();
}
}
else
{
Environment.Exit(0);
}
}
// Funcion especial que hace que puedas abrir un archivo especifico presionando la tecla 'L'
private void SelectFileManually(object sender, KeyEventArgs e)
{
if (e.Key == Key.L)
{
OpenFileDialog ofd = new()
{
Title = "Seleccione un archivo 'r3dlog'",
Filter = "Archivos de texto (*.txt*)|*.txt|Todos los archivos (*.*)|*.*"
};
bool? result = ofd.ShowDialog();
if (result == true)
{
MessageList.ShowMessages(Dispatcher , LogViewerElements.logGrid, ofd.FileName);
LogViewerElements.pathLabel.Content = ofd.FileName;
LogViewerElements.FileList.DeselectFile();
}
}
}
}
}