-
Notifications
You must be signed in to change notification settings - Fork 7
/
file2clip.cs
93 lines (82 loc) · 2.9 KB
/
file2clip.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
/*
this simple tool will copy file passed as argument into windows clipboard
http://stackoverflow.com/questions/17189010/how-to-copy-cut-a-file-not-the-contents-to-the-clipboard-in-windows-on-the-com
*/
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("File2Clip")]
[assembly: AssemblyDescription("copies file to clipboard (as a file)")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("rostok - https://github.com/rostok/")]
[assembly: AssemblyProduct("File2Clip")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
namespace File2Clip
{
public class App
{
private static bool isConsoleSizeZero {
get{ return 0 == (Console.WindowHeight + Console.WindowWidth); }
}
public static bool IsOutputRedirected {
get { return isConsoleSizeZero && !Console.KeyAvailable; }
}
public static bool IsInputRedirected {
get { return isConsoleSizeZero && Console.KeyAvailable; }
}
[STAThread]
static void Main(string[] args)
{
//Console.WriteLine("File2Clip");
List<string> list = new List<string>();
string line;
try{
bool ka = Console.KeyAvailable;
// if this should raise an error we are dealing with redirection
// http://stackoverflow.com/questions/12911833/how-to-catch-all-exceptions-in-c-sharp-using-try-and-catch
// http://stackoverflow.com/questions/3453220/how-to-detect-if-console-in-stdin-has-been-redirected/3453272#3453272
// http://stackoverflow.com/questions/7302544/flushing-system-console-read
}
catch (Exception e)
{
//Console.WriteLine("Console.KeyAvailable PROBLEM");
// stdin
//if (!IsInputRedirected)
{
while(!string.IsNullOrEmpty(line = Console.ReadLine())) list.Add(line);
}
//Console.WriteLine("Console.In.Peek() "+ Console.In.Peek());
}
// args
foreach (string s in args) {
list.Add(s);
}
StringCollection paths = new StringCollection();
foreach (string s in list)
{
string t = s.Trim('"');
paths.Add(
System.IO.Path.IsPathRooted(t) ?
t :
System.IO.Directory.GetCurrentDirectory() +
@"\" + t);
}
if (paths.Count>0)
{
Clipboard.SetFileDropList(paths);
}
else
{
Console.WriteLine("Input is Empty! Provide file paths via STDIN or command line arguments.");
}
}
}
}