This repository has been archived by the owner on Aug 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathBrowse.aspx.cs
304 lines (281 loc) · 11.5 KB
/
Browse.aspx.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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace Mygod.Skylark
{
public partial class Browse : Page
{
protected string RelativePath;
protected DirectoryInfo InfoDirectory;
protected FileInfo InfoFile;
protected CloudTask Task;
protected void Page_PreInit(object sender, EventArgs e)
{
RelativePath = RouteData.GetRelativePath();
var absolutePath = FileHelper.GetFilePath(RelativePath);
Title = ("浏览 " + RelativePath).TrimEnd();
InfoDirectory = new DirectoryInfo(absolutePath);
InfoFile = new FileInfo(absolutePath);
var url = Request.RawUrl.Split('?');
if (InfoDirectory.Exists && !url[0].EndsWith("/", StringComparison.Ordinal))
if (url.Length > 1) Response.Redirect(url[0] + "/?" + url[1], true);
else Response.Redirect(url[0] + '/', true);
if (InfoFile.Exists && url[0].EndsWith("/", StringComparison.Ordinal))
if (url.Length > 1) Response.Redirect(url[0].TrimEnd('/') + "?" + url[1], true);
else Response.Redirect(url[0].TrimEnd('/'), true);
}
protected User CurrentUser;
protected void Page_Init(object sender, EventArgs e)
{
if (!(CurrentUser = Request.GetUser()).Browse)
{
Response.StatusCode = 401;
return;
}
if (InfoDirectory.Exists)
{
Views.SetActiveView(DirectoryView);
if (IsPostBack) return;
var dirs = InfoDirectory.EnumerateDirectories().ToList();
DirectoryList.DataSource = dirs;
DirectoryList.DataBind();
DirectoryCount = dirs.Count.ToString(CultureInfo.InvariantCulture);
var files = InfoDirectory.EnumerateFiles().ToList();
FileList.DataSource = files;
FileList.DataBind();
FileCount = files.Count.ToString(CultureInfo.InvariantCulture);
ArchiveFilePath.Text = string.IsNullOrWhiteSpace(RelativePath) ? "Files.7z" : (RelativePath + ".7z");
}
else if (InfoFile.Exists)
{
string dataPath = FileHelper.GetDataFilePath(RelativePath), state = FileHelper.GetFileValue(dataPath, "state");
Task = GenerateFileTask.Create(RelativePath);
if (Task == null)
if (state == TaskType.NoTask)
{
if (Request.IsAjaxRequest()) Response.Redirect(Request.RawUrl, true); // processing is finished
Views.SetActiveView(FileView);
Mime = FileHelper.GetDefaultMime(dataPath);
RefreshFile();
}
else Views.SetActiveView(GeneralTaskProcessingView);
else if (state == TaskType.UploadTask) Views.SetActiveView(FileUploadingView);
else
{
Viewer.SetTask(Task);
Views.SetActiveView(FileProcessingView);
}
}
else
{
Views.SetActiveView(GoneView);
Response.StatusCode = 404;
}
}
#region Directory
protected string DirectoryCount, FileCount;
private IEnumerable<string> SelectedPaths
{
get
{
return DirectoryList.Items.GetSelectedItemsID()
.Union(FileList.Items.GetSelectedItemsID()).Select(name => FileHelper.Combine(RelativePath, name));
}
}
protected void DirectoryCommand(object source, RepeaterCommandEventArgs e)
{
if (!CurrentUser.OperateFiles)
{
Response.StatusCode = 401;
return;
}
switch (e.CommandName)
{
case "Rename":
FileHelper.Move(FileHelper.Combine(RelativePath,
((HtmlInputHidden)e.Item.FindControl("Hidden")).Value),
FileHelper.Combine(RelativePath, Hidden.Value.UrlDecode()));
Response.Redirect(Request.RawUrl);
break;
}
}
protected void FileCommand(object source, RepeaterCommandEventArgs e)
{
if (!CurrentUser.OperateFiles)
{
Response.StatusCode = 401;
return;
}
switch (e.CommandName)
{
case "Rename":
FileHelper.Move(FileHelper.Combine(RelativePath,
((HtmlInputHidden)e.Item.FindControl("Hidden")).Value),
FileHelper.Combine(RelativePath, Hidden.Value.UrlDecode()));
Response.Redirect(Request.RawUrl);
break;
}
}
protected void NewFolder(object sender, EventArgs e)
{
if (!CurrentUser.OperateFiles)
{
Response.StatusCode = 401;
return;
}
FileHelper.CreateDirectory(FileHelper.Combine(RelativePath, Hidden.Value.UrlDecode()));
Response.Redirect(Request.RawUrl);
}
protected void Move(object sender, EventArgs e)
{
if (!CurrentUser.OperateFiles)
{
Response.StatusCode = 401;
return;
}
foreach (var source in SelectedPaths) FileHelper.Move(source,
FileHelper.Combine(Hidden.Value.UrlDecode(), Path.GetFileName(source)), false);
Response.Redirect(Request.RawUrl);
}
protected void Copy(object sender, EventArgs e)
{
if (!CurrentUser.OperateFiles)
{
Response.StatusCode = 401;
return;
}
foreach (var source in SelectedPaths) FileHelper.Copy(source,
FileHelper.Combine(Hidden.Value.UrlDecode(), Path.GetFileName(source)), false);
Response.Redirect(Request.RawUrl);
}
protected void Delete(object sender, EventArgs e)
{
if (!CurrentUser.OperateFiles)
{
Response.StatusCode = 401;
return;
}
foreach (var path in SelectedPaths) FileHelper.Delete(path);
Response.Redirect(Request.RawUrl);
}
protected void Compress(object sender, EventArgs e)
{
if (!CurrentUser.OperateTasks)
{
Response.StatusCode = 401;
return;
}
new CompressTask(ArchiveFilePath.Text, SelectedPaths, RelativePath,
CompressionLevelList.SelectedValue).Start();
Response.Redirect("/Browse/" + ArchiveFilePath.Text.ToCorrectUrl());
}
protected void BatchMerge(object sender, EventArgs e)
{
if (!CurrentUser.OperateTasks)
{
Response.StatusCode = 401;
return;
}
TaskHelper.StartRunner(string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}", TaskType.BatchMergeVATask,
RelativePath, DeleteSourceBox.Checked, VideoPatternBox.Text,
AudioPatternBox.Text.Replace("\r", string.Empty).Replace('\n', '\t'),
ResultPatternBox.Text.Replace("\r", string.Empty).Replace('\n', '\t')));
Response.Redirect(Request.RawUrl);
}
private static readonly Regex
AppParser = new Regex(@"^http:\/\/((.*?)@)?(.*?)\/Browse\/(.*)$", RegexOptions.Compiled);
protected void CrossAppCopy(object sender, EventArgs e)
{
if (!CurrentUser.OperateTasks)
{
Response.StatusCode = 401;
return;
}
var match = AppParser.Match(Hidden.Value);
if (!match.Success) return;
var task = new CrossAppCopyTask(match.Groups[3].Value, match.Groups[4].Value.UrlDecode(), RelativePath,
match.Groups[2].Success ? match.Groups[2].Value : Request.GetPassword());
task.Start();
Response.Redirect("/Task/Details/" + task.ID);
}
protected void FtpUpload(object sender, EventArgs e)
{
if (!CurrentUser.OperateTasks)
{
Response.StatusCode = 401;
return;
}
Response.Redirect("/Task/Details/" + new FtpUploadTask(RelativePath, SelectedPaths, Hidden.Value));
}
#endregion
#region File
protected string Mime, FFmpegResult;
private void RefreshFile()
{
FFmpegResult = FFmpeg.Analyze(FileHelper.GetFilePath(RelativePath));
foreach (var codec in FFmpeg.Codecs.Where(codec => codec.EncodingSupported))
{
var listItem = new ListItem(codec.ToString(), codec.Name);
switch (codec.Type)
{
case FFmpeg.CodecType.Video:
ConvertVideoCodecBox.Items.Add(listItem);
break;
case FFmpeg.CodecType.Audio:
ConvertAudioCodecBox.Items.Add(listItem);
break;
case FFmpeg.CodecType.Subtitle:
ConvertSubtitleCodecBox.Items.Add(listItem);
break;
}
}
}
protected static string GetMimeType(string mime)
{
var extension = Helper.GetDefaultExtension(mime);
mime = string.Format("<span id=\"current-mime\">{0}</span>", mime);
return extension != null ? string.Format("{0} ({1})", mime, extension) : mime;
}
protected void ModifyMime(object sender, EventArgs e)
{
if (!CurrentUser.OperateFiles)
{
Response.StatusCode = 401;
return;
}
FileHelper.SetDefaultMime(FileHelper.GetDataFilePath(RelativePath), Hidden.Value.UrlDecode());
Response.Redirect(Request.RawUrl);
}
protected void Decompress(object sender, EventArgs e)
{
if (!CurrentUser.OperateTasks)
{
Response.StatusCode = 401;
return;
}
var task = new DecompressTask(RelativePath, Hidden.Value.UrlDecode());
task.Start();
Response.Redirect("/Task/Details/" + task.ID);
}
protected void Convert(object sender, EventArgs e)
{
if (!CurrentUser.OperateTasks)
{
Response.StatusCode = 401;
return;
}
ConvertTask.Create(RelativePath, ConvertPathBox.Text, ConvertSizeBox.Text,
ConvertVideoCodecBox.SelectedValue, ConvertAudioCodecBox.SelectedValue,
ConvertSubtitleCodecBox.SelectedValue, ConvertAudioPathBox.Text,
ConvertStartBox.Text, ConvertEndBox.Text).Start();
Response.Redirect("/Browse/" + ConvertPathBox.Text.ToCorrectUrl());
}
#endregion
}
}