forked from Violet-CLM/MLLE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectorySetupForm.cs
More file actions
77 lines (72 loc) · 2.79 KB
/
DirectorySetupForm.cs
File metadata and controls
77 lines (72 loc) · 2.79 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using Ini;
namespace MLLE
{
public partial class DirectorySetupForm : Form
{
private IniFile Settings;
private static bool result;
private TextBox[] TextBoxes;
public DirectorySetupForm(IniFile settings)
{
InitializeComponent();
Settings = settings;
TextBoxes = new TextBox[] { DirectoryJJ2, DirectoryTSF, Directory110o, Directory100g, DirectoryBC, DirectoryAGA };
Button[] Buttons = new Button[] { button0, button1, button2, button3, button4, button5 };
for (uint i = 0; i < TextBoxes.Length; ++i)
{
Buttons[i].Tag = TextBoxes[i];
Buttons[i].Click += browseButton_Click;
TextBoxes[i].Text = Settings.IniReadValue("Paths", (string)TextBoxes[i].Tag) ?? "";
}
}
public static bool ShowForm(IniFile settings)
{
DirectorySetupForm DSF = new DirectorySetupForm(settings);
DSF.ShowDialog();
return result;
}
private void BrowseDirectory(TextBox box)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
box.Text = folderBrowserDialog1.SelectedPath;
}
private void browseButton_Click(object sender, EventArgs e) { BrowseDirectory((TextBox)((Button)sender).Tag); }
private void buttonOK_Click(object sender, EventArgs e)
{
bool atLeastOneBoxWasFilled = false;
foreach (TextBox box in TextBoxes)
{
if (box.Text.Length > 0) //otherwise skip over this one, the user doesn't have the game
{
if (Directory.Exists(box.Text))
{
atLeastOneBoxWasFilled = true;
Settings.IniWriteValue("Paths", (string)box.Tag, box.Text);
if ((Settings.IniReadValue("Miscellaneous", "DefaultGame") ?? "") == "") Settings.IniWriteValue("Miscellaneous", "DefaultGame", (string)box.Tag);
}
else
{
MessageBox.Show(box.Text + " is not a valid directory! Please leave this textbox empty if you do not have this game.", "Invalid Directory", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
}
}
result = atLeastOneBoxWasFilled;
Dispose();
}
private void buttonCancel_Click(object sender, EventArgs e)
{
result = false;
Dispose();
}
}
}