-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLibraryStore.cs
67 lines (59 loc) · 2.51 KB
/
LibraryStore.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
namespace LoveMaker;
internal partial class LibraryStore: Form {
private List<LibraryExplorer.LuaLibrary> libs = [];
public LibraryStore() {
this.InitializeComponent();
}
private void AddLibraryToStore(LibraryExplorer.LuaLibrary lib) {
// Add the library to the store.
var item = new ListViewItem(lib.Name.Trim()) {
Tag = lib,
};
this.Libraries.Invoke(new Action(() => this.Libraries.Items.Add(item)));
}
private async void RefreshAvailableLibraries() {
// Fetch the libraries from the LibraryExplorer.
// Display the libraries in the list.
this.libs = await LibraryExplorer.ScrapeLibrariesAsync().ConfigureAwait(false);
foreach (var lib in libs) {
this.AddLibraryToStore(lib);
}
}
private void Cancel_Click(Object sender, EventArgs e) {
this.Close();
}
private void LibraryStore_Load(Object sender, EventArgs e) {
this.RefreshAvailableLibraries();
Libraries.ListViewItemSorter = new AlphabeticSorter();
}
private class AlphabeticSorter: System.Collections.IComparer {
public int Compare(object x, object y) {
// Compare the text of the ListView items
return String.Compare(((ListViewItem) x).Text, ((ListViewItem) y).Text);
}
}
private void Install_Click(Object sender, EventArgs e) {
}
private void Libraries_SelectedIndexChanged(Object sender, EventArgs e) {
this.Docs.Enabled = Libraries.SelectedItems.Count == 1;
}
private void Docs_Click(object sender, EventArgs e) {
if (Libraries.SelectedItems.Count != 1) { return; }
if (Libraries.SelectedItems[0] is null) { return; }
if (Libraries.SelectedItems[0].Tag is null) { return; }
var lib = (LibraryExplorer.LuaLibrary) Libraries.SelectedItems[0].Tag;
if (Uri.TryCreate(lib.Link, UriKind.Absolute, out var uriResult) &&
(uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps)) {
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo {
FileName = uriResult.ToString(),
UseShellExecute = true
});
} else {
MessageBox.Show("The selected library link is not valid.", "Invalid Link!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Refresh_Click(object sender, EventArgs e) {
this.Libraries.Items.Clear();
this.RefreshAvailableLibraries();
}
}