-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.cs
312 lines (272 loc) · 11.6 KB
/
Form1.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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test1C3
{
public partial class SortToFolder : Form
{
//Sort Buttom
[DllImport("FileOrganizerDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern string startApplication(bool perm = false, string[] arr = null, int size = 0);
private static DialogResult ShowInputDialog(ref string input)
{
System.Drawing.Size size = new System.Drawing.Size(200, 70);
Form inputBox = new Form();
inputBox.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
inputBox.ClientSize = size;
inputBox.Text = "Name";
System.Windows.Forms.TextBox textBox = new TextBox();
textBox.Size = new System.Drawing.Size(size.Width - 10, 23);
textBox.Location = new System.Drawing.Point(5, 5);
textBox.Text = input;
inputBox.Controls.Add(textBox);
Button okButton = new Button();
okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
okButton.Name = "okButton";
okButton.Size = new System.Drawing.Size(75, 23);
okButton.Text = "&OK";
okButton.Location = new System.Drawing.Point(size.Width - 80 - 80, 39);
inputBox.Controls.Add(okButton);
Button cancelButton = new Button();
cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
cancelButton.Name = "cancelButton";
cancelButton.Size = new System.Drawing.Size(75, 23);
cancelButton.Text = "&Cancel";
cancelButton.Location = new System.Drawing.Point(size.Width - 80, 39);
inputBox.Controls.Add(cancelButton);
inputBox.AcceptButton = okButton;
inputBox.CancelButton = cancelButton;
DialogResult result = inputBox.ShowDialog();
input = textBox.Text;
return result;
}
//List<string> allInput = new List<string>();
public static class Globals
{
public const Int32 BUFFER_SIZE = 512; // Unmodifiable
public static String FILE_NAME = "Output.txt"; // Modifiable
public static readonly String CODE_PREFIX = "US-"; // Unmodifiable
public static int lastID = 0; // Modifiable
public static string lastStringTB = ""; // Modifiable
}
Dictionary<String, int> allLocations = new Dictionary<string, int>();
public SortToFolder()
{
InitializeComponent();
try
{
this.textBox1.Multiline = true;
string path = Environment.CurrentDirectory + "/" + "sortToFolderFinal.conf";
FileInfo fInfo = new FileInfo(path);
if (!fInfo.Exists)
{
File.CreateText(path);
}
else
{
using (StreamReader sr = new StreamReader(path))
{
if (new FileInfo(path).Length == 0)
{
}
else
{
String line;
line = sr.ReadLine();
//Continue to read until you reach end of file
int count = 0;
while (line != null)
{
//write the lie to console window
allLocations.Add(line, count);
//Read the next line
line = sr.ReadLine();
count++;
}
}
}
}
}
catch(Exception except)
{
try
{
string path = Environment.CurrentDirectory + "/" + "sortToFolderFinal.conf";
using (StreamWriter sw = new StreamWriter(path))
{
File.CreateText(path);
}
System.Windows.Forms.MessageBox.Show(GetExceptionDetails(except));
}
catch (Exception except2)
{
System.Windows.Forms.MessageBox.Show(GetExceptionDetails(except2));
}
}
printToScreen();
}
private void printToScreen()
{
textBox1.AppendText("Locations:----");
textBox1.AppendText(Environment.NewLine);
foreach (KeyValuePair<string, int> entry in allLocations)
{
textBox1.AppendText(entry.Key);
textBox1.AppendText(Environment.NewLine);
}
}
string getLatest()
{
return Globals.lastStringTB;
}
public Dictionary<string, int> AllLocations { get => allLocations; set => allLocations = value; }
private void button1_Click(object sender, EventArgs e)
{
//Set Sort Locations
string path = Environment.CurrentDirectory + "/" + "sortToFolderFinal.conf";
if(!File.Exists(path))
{
}
else
{
textBox1.Text = String.Empty;
try
{
if(textBox1.Multiline == true)
{
//System.Windows.Forms.MessageBox.Show("MultiLined");
}
string[] lines = Globals.lastStringTB.Split( new[] { Environment.NewLine }, StringSplitOptions.None );
Dictionary<string, int> AllLocationsCopy = new Dictionary<string, int>();
//System.Windows.Forms.MessageBox.Show(lines[0]);
for (int count = 0; count < lines.Length; count++)
{
if (lines[count] == "" || lines[count] == Environment.NewLine || lines[count] == "\n" || lines[count] == "Locations:----") {
//System.Windows.Forms.MessageBox.Show("Not added");
}
else
{
if (AllLocationsCopy.ContainsKey(lines[count]))
{
continue;
}
else
{
AllLocationsCopy.Add(lines[count], count);
}
// AllLocationsCopy.Add(lines[count], count);
}
}
AllLocations = AllLocationsCopy;
}
catch (Exception except)
{
// Something unexpected went wrong.
System.Windows.Forms.MessageBox.Show(GetExceptionDetails(except));
}
using (StreamWriter sw = new StreamWriter(path))
{
foreach (KeyValuePair<string, int> entry in allLocations)
{
sw.WriteLine(entry.Key);
}
}
}
textBox1.Text = String.Empty;
}
private void button2_Click(object sender, EventArgs e)
{
//System.Windows.Forms.MessageBox.Show("Fuck");
try
{
textBox1.Text = String.Empty;
textBox1.AppendText("Locations:----");
textBox1.AppendText(Environment.NewLine);
//string[] stringArr = new string[AllLocations.Count()];
// int count = 0;
List<string> allLocsStr = new List<string>();
foreach (KeyValuePair<string, int> entry in allLocations)
{
textBox1.AppendText(entry.Key);
textBox1.AppendText(Environment.NewLine);
//stringArr[count++] = entry.Key;
allLocsStr.Add(entry.Key);
}
/*textBox1.AppendText("Locations:----");
textBox1.AppendText(Environment.NewLine);
for (int x = 0; x < stringArr.Length; x++)
{
textBox1.AppendText(stringArr[x]);
textBox1.AppendText(Environment.NewLine);
}*/
//System.Windows.Forms.MessageBox.Show("You");
//System.Windows.Forms.MessageBox.Show(startApplication(true, stringArr, count));
startApplication(true, allLocsStr.ToArray(), allLocsStr.Count);
}
catch (Exception whatType)
{
//System.Windows.Forms.MessageBox.Show(GetExceptionDetails(whatType));
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "") { }
else
{
Globals.lastStringTB = textBox1.Text;
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
string GetExceptionDetails(Exception exception)
{
PropertyInfo[] properties = exception.GetType()
.GetProperties();
List<string> fields = new List<string>();
foreach (PropertyInfo property in properties)
{
object value = property.GetValue(exception, null);
fields.Add(String.Format(
"{0} = {1}",
property.Name,
value != null ? value.ToString() : String.Empty
));
}
return String.Join("\n", fields.ToArray());
}
private void button4_Click(object sender, EventArgs e)
{
//Quit button
Close();
}
private void button5_Click(object sender, EventArgs e)
{
//Show currently loaded locations
textBox1.Text = String.Empty;
textBox1.AppendText("Locations:----");
textBox1.AppendText(Environment.NewLine);
foreach (KeyValuePair<string, int> entry in allLocations)
{
textBox1.AppendText(entry.Key);
textBox1.AppendText(Environment.NewLine);
}
}
private void button6_Click(object sender, EventArgs e)
{
string message = "Hello there! Welcome to the SortToFolder Readme.\n If you want to add locations to the configuration first load them using \"Show current Locations\" thereafter appending the list by clicking Set Sort Locations";
string message2 = "\n You can quit by exiting normally or hitting the quit button, and sort the locations by clicking the sort data button";
System.Windows.Forms.MessageBox.Show(message + message2);
}
}
}