forked from yanchunlei/SC-Chinese
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExternalContentScreen.cs
168 lines (165 loc) · 5.88 KB
/
ExternalContentScreen.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
using Engine;
using Game;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace ZHCN
{
public class ExternalContentScreen : Game.ExternalContentScreen
{
public override void Update()
{
if (m_listDirty)
{
m_listDirty = false;
UpdateList();
}
ExternalContentEntry externalContentEntry = null;
if (m_directoryList.SelectedIndex.HasValue)
externalContentEntry = m_directoryList.Items[m_directoryList.SelectedIndex.Value] as ExternalContentEntry;
if (externalContentEntry != null)
{
m_actionButton.IsVisible = true;
if (externalContentEntry.Type == ExternalContentType.Directory)
{
m_actionButton.Text = "进入";
m_actionButton.IsEnabled = true;
m_copyLinkButton.IsEnabled = false;
}
else
{
m_actionButton.Text = "下载";
if (ExternalContentManager.IsEntryTypeDownloadSupported(ExternalContentManager.ExtensionToType(Storage.GetExtension(externalContentEntry.Path).ToLower())))
{
m_actionButton.IsEnabled = true;
m_copyLinkButton.IsEnabled = true;
}
else
{
m_actionButton.IsEnabled = false;
m_copyLinkButton.IsEnabled = false;
}
}
}
else
{
m_actionButton.IsVisible = false;
m_copyLinkButton.IsVisible = false;
}
m_directoryLabel.Text = m_externalContentProvider.IsLoggedIn ? ("内容 " + m_path) : "未登陆";
m_providerNameLabel.Text = m_externalContentProvider.DisplayName;
m_upDirectoryButton.IsEnabled = m_externalContentProvider.IsLoggedIn && m_path != "/";
m_loginLogoutButton.Text = m_externalContentProvider.IsLoggedIn ? "注销" : "登陆";
m_loginLogoutButton.IsVisible = m_externalContentProvider.RequiresLogin;
m_copyLinkButton.IsVisible = m_externalContentProvider.SupportsLinks;
m_copyLinkButton.IsEnabled = externalContentEntry != null && ExternalContentManager.IsEntryTypeDownloadSupported(externalContentEntry.Type);
if (m_changeProviderButton.IsClicked)
{
DialogsManager.ShowDialog(null, new SelectExternalContentProviderDialog("选择内容源", true, delegate (IExternalContentProvider provider)
{
m_externalContentProvider = provider;
m_listDirty = true;
SetPath(null);
}));
}
if (m_upDirectoryButton.IsClicked)
{
string directoryName = Storage.GetDirectoryName(m_path);
SetPath(directoryName);
}
if (m_actionButton.IsClicked && externalContentEntry != null)
if (externalContentEntry.Type == ExternalContentType.Directory)
SetPath(externalContentEntry.Path);
else
DownloadEntry(externalContentEntry);
if (m_copyLinkButton.IsClicked && externalContentEntry != null && ExternalContentManager.IsEntryTypeDownloadSupported(externalContentEntry.Type))
{
var busyDialog = new CancellableBusyDialog("创建链接", false);
DialogsManager.ShowDialog(null, busyDialog);
m_externalContentProvider.Link(externalContentEntry.Path, busyDialog.Progress, delegate (string link)
{
DialogsManager.HideDialog(busyDialog);
DialogsManager.ShowDialog(null, new ExternalContentLinkDialog(link));
}, delegate (Exception error)
{
DialogsManager.HideDialog(busyDialog);
DialogsManager.ShowDialog(null, new MessageDialog("Error", error.Message, "OK", null, null));
});
}
if (m_loginLogoutButton.IsClicked)
if (m_externalContentProvider.IsLoggedIn)
{
m_externalContentProvider.Logout();
SetPath(null);
m_listDirty = true;
}
else
{
ExternalContentManager.ShowLoginUiIfNeeded(m_externalContentProvider, false, delegate
{
SetPath(null);
m_listDirty = true;
});
}
if (Input.Back || Input.Cancel || Children.Find<ButtonWidget>("TopBar.Back", true).IsClicked)
ScreensManager.SwitchScreen("Content");
}
public new void UpdateList()
{
m_directoryList.ClearItems();
if (m_externalContentProvider != null && m_externalContentProvider.IsLoggedIn)
{
var busyDialog = new CancellableBusyDialog("检索目录", false);
DialogsManager.ShowDialog(null, busyDialog);
m_externalContentProvider.List(m_path, busyDialog.Progress, delegate (ExternalContentEntry entry)
{
DialogsManager.HideDialog(busyDialog);
var list = new List<ExternalContentEntry>((from e in entry.ChildEntries
where EntryFilter(e)
select e).Take(1000));
m_directoryList.ClearItems();
list.Sort(delegate (ExternalContentEntry e1, ExternalContentEntry e2)
{
if (e1.Type == ExternalContentType.Directory && e2.Type != ExternalContentType.Directory)
return -1;
if (e1.Type != ExternalContentType.Directory && e2.Type == ExternalContentType.Directory)
return 1;
return string.Compare(e1.Path, e2.Path);
});
foreach (ExternalContentEntry item in list)
{
m_directoryList.AddItem(item);
}
}, delegate (Exception error)
{
DialogsManager.HideDialog(busyDialog);
DialogsManager.ShowDialog(null, new MessageDialog("Error", error.Message, "OK", null, null));
});
}
}
public new void DownloadEntry(ExternalContentEntry entry)
{
var busyDialog = new CancellableBusyDialog("下载中", false);
DialogsManager.ShowDialog(null, busyDialog);
m_externalContentProvider.Download(entry.Path, busyDialog.Progress, delegate (Stream stream)
{
busyDialog.LargeMessage = "导入中";
ExternalContentManager.ImportExternalContent(stream, entry.Type, Storage.GetFileName(entry.Path), delegate
{
stream.Dispose();
DialogsManager.HideDialog(busyDialog);
}, delegate (Exception error)
{
stream.Dispose();
DialogsManager.HideDialog(busyDialog);
DialogsManager.ShowDialog(null, new MessageDialog("Error", error.Message, "OK", null, null));
});
}, delegate (Exception error)
{
DialogsManager.HideDialog(busyDialog);
DialogsManager.ShowDialog(null, new MessageDialog("Error", error.Message, "OK", null, null));
});
}
}
}