-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoadLoaderForm.cs
189 lines (169 loc) · 6.9 KB
/
RoadLoaderForm.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
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
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AutomationLib;
using InputManager;
namespace EliteRoadLoader
{
public partial class RoadLoaderForm : Form
{
List<string> systems = new List<string>();
int systemIndex = -1;
//Hotkeys
private GlobalHotkey hk_F4;
private GlobalHotkey hk_F5;
private GlobalHotkey hk_F6;
public RoadLoaderForm()
{
InitializeComponent();
}
private void LoadNext(object sender, EventArgs e)
{
if (systemIndex + 1 < systems.Count)
{
systemIndex++;
string currentSystem = systems[systemIndex];
lblDebug.Text = "[Next] Loaded \"" + currentSystem + "\".";
Clipboard.SetText(currentSystem);
Console.Beep(2000, 20);
}
else
Console.Beep(50, 100);
}
private void LoadPrev(object sender, EventArgs e)
{
if (systemIndex > 0)
{
systemIndex--;
string currentSystem = systems[systemIndex];
lblDebug.Text = "[Prev] Loaded \"" + currentSystem + "\".";
Clipboard.SetText(currentSystem);
Console.Beep(5000, 20);
}
else
Console.Beep(50, 100);
}
private void WriteNext(object sender, EventArgs e)
{
if (systemIndex + 1 < systems.Count)
{
systemIndex++;
string currentSystem = systems[systemIndex];
lblDebug.Text = "[Next] Pasted \"" + currentSystem + "\".";
// Copy and paste ; NOTE: SendKeys.Send(currentSystem); is unreliable!
Clipboard.SetText(currentSystem);
Keyboard.ShortcutKeys(new Keys[] { Keys.LControlKey, Keys.V }, 200);
// Wait for system to show up (has no effect when it loads too slow, or there are multiple suggestions)
Timing.RandomizedSleep(1250, 0.04);
// Press ENTER
Keyboard.KeyPress(Keys.Enter, 200);
// Notify the user that it's done.
Console.Beep(2000, 20);
}
else
Console.Beep(50, 100);
}
private void RoadLoaderForm_Load(object sender, EventArgs e)
{
//Register Hotkeys (http://bloggablea.wordpress.com/2007/05/01/global-hotkeys-with-net/)
hk_F4 = new GlobalHotkey(Keys.F4, false, false, false, false);
hk_F4.Pressed += WriteNext;
hk_F4.Register(this);
hk_F5 = new GlobalHotkey(Keys.F5, false, false, false, false);
hk_F5.Pressed += LoadNext;
hk_F5.Register(this);
hk_F6 = new GlobalHotkey(Keys.F6, false, false, false, false);
hk_F6.Pressed += LoadPrev;
hk_F6.Register(this);
}
private void load(List<string> filePaths)
{
foreach (string filePath in filePaths)
{
Console.Beep(200, 100);
if (filePath.EndsWith(".csv"))
{
string csvText = File.ReadAllText(filePath);
string[] lines = csvText.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < lines.Length; i++)
{
if (i != 0 && lines[i][0] == '"')
{
int index = lines[i].IndexOf("\",", 1);
if (index > 0)
{
string systemName = lines[i].Substring(1, index - 1);
if (systems.Count == 0 || systems.Last() != systemName) // Skip sequential duplicates
systems.Add(systemName);
}
}
}
}
else
{
string text = File.ReadAllText(filePath);
string[] lines = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
systems.AddRange(lines);
}
}
txtLoaded.Text = string.Join("\r\n", systems);
lblDebug.Text = "Loaded " + systems.Count + " system name" + (systems.Count == 1 ? "" : "s") + " from " + filePaths.Count + " file" + (filePaths.Count == 1 ? "" : "s") + ".";
}
private void btnOpen_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = System.Reflection.Assembly.GetExecutingAssembly().Location;
openFileDialog.Filter = "Comma-separated values (*.csv)|*.csv|Text documents (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog.FilterIndex = 3;
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
systemIndex = -1;
systems.Clear();
load(openFileDialog.FileNames.ToList());
}
}
}
private void btnPaste_Click(object sender, EventArgs e)
{
PasteBox box = new PasteBox("Enter one system name per line.", "Paste");
if (box.ShowDialog() == DialogResult.OK)
{
Console.Beep(200, 100);
systemIndex = -1;
systems.Clear();
string[] lines = box.Result.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
systems.AddRange(lines);
txtLoaded.Text = string.Join("\r\n", systems);
lblDebug.Text = "Loaded " + systems.Count + " system name" + (systems.Count == 1 ? "" : "s") + " via text input.";
}
}
private void RoadLoaderForm_DragDrop(object sender, DragEventArgs e)
{
systemIndex = -1;
systems.Clear();
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
load(files.Where(x => x.EndsWith(".csv") || x.EndsWith(".txt")).ToList());
}
private void RoadLoaderForm_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
//Enable Ctrl+A for textboxes
private void SelectAll_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.A)
{
((TextBox)sender).SelectAll();
}
}
}
}