-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
FileProcessor.cs
53 lines (50 loc) · 1.77 KB
/
FileProcessor.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
namespace PasteEx.Core
{
public class FileProcessor : BaseProcessor
{
public FileProcessor(ClipboardData clipData) : base(clipData)
{
Data = clipData;
}
public override string[] Analyze()
{
if (Data.IAcquisition.GetDataPresent(DataFormats.FileDrop, false))
{
List<string> extensions = new List<string>();
if (Data.IAcquisition.GetData(DataFormats.FileDrop) is string[] filePaths)
{
if (filePaths.Length == 1)
{
if (!String.IsNullOrEmpty(filePaths[0]) && File.Exists(filePaths[0]))
{
Data.Storage.SetData(DataFormats.FileDrop, Data.IAcquisition.GetData(DataFormats.FileDrop));
extensions.Clear();
extensions.Add(Path.GetExtension(filePaths[0]).Remove(0, 1));
}
}
}
return extensions.ToArray();
}
return null;
}
public override bool SaveAs(string path, string extension)
{
// copy file priority
if (Data.Storage.GetDataPresent(DataFormats.FileDrop, false))
{
string[] filePaths = Data.Storage.GetData(DataFormats.FileDrop) as string[];
if (filePaths.Length > 0 && !String.IsNullOrEmpty(filePaths[0]))
{
File.Copy(filePaths[0], path);
}
OnSaveAsFileCompleted();
return true;
}
return false;
}
}
}