forked from SolarLiner/kOS-IDE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadScript.cs
119 lines (99 loc) · 3.69 KB
/
LoadScript.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
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;
namespace kOS_IDE
{
public partial class LoadScript : Form
{
string _ksp;
string _fName;
public string FileName
{
get { return _fName; }
}
public LoadScript()
{
InitializeComponent();
_fName = null;
FolderBrowserDialog fd = new FolderBrowserDialog();
fd.Description = "Locate your KSP directory";
if (fd.ShowDialog() != DialogResult.OK) return;
_ksp = fd.SelectedPath;
AppOptions.KSPfolder = fd.SelectedPath;
}
public LoadScript(string KSPdir)
{
InitializeComponent();
_fName = null;
if (String.IsNullOrWhiteSpace(KSPdir))
{
FolderBrowserDialog fd = new FolderBrowserDialog();
fd.Description = "Locate your KSP directory";
if (fd.ShowDialog() != DialogResult.OK) return;
_ksp = fd.SelectedPath;
AppOptions.KSPfolder = fd.SelectedPath;
}
else _ksp = KSPdir;
}
private void OK_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
private void Cancel_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.Close();
}
private void LoadScript_Load(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(_ksp))
{
MessageBox.Show("Cannot get the KSP Directory.", "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = System.Windows.Forms.DialogResult.Abort;
this.Close();
}
string ArchivePath = Path.Combine(_ksp, @"Plugins\PluginData\Archive");
if (!Directory.Exists(ArchivePath))
{
MessageBox.Show("KSP does not include a functionnal archive for kOS. Aborting.", "Archive Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = System.Windows.Forms.DialogResult.Abort;
this.Close();
}
ShowKSPdir.Text = "Kerbal Space Program directory: " + _ksp;
foreach (string filepath in Directory.GetFiles(ArchivePath))
{
if (Path.GetExtension(filepath) != ".txt") continue;
string name = Path.GetFileNameWithoutExtension(filepath);
long size = new FileInfo(filepath).Length;
ListViewItem added = listView1.Items.Add(name);
added.Tag = filepath;
if (size < 1024) // 2^10 = 1024 b
{
added.SubItems.Add(size + " b");
}
else
{
added.SubItems.Add(Math.Round(size / 1024.0, 3) + " kb");
}
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedIndices.Count == 0) OK.Enabled = false;
else { OK.Enabled = true; _fName = (string)listView1.SelectedItems[0].Tag; }
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
if (listView1.SelectedIndices.Count == 0) return;
_fName = (string)listView1.SelectedItems[0].Tag;
OK_Click(null, e);
}
}
}