-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
frmMain.cs
144 lines (126 loc) 路 5 KB
/
frmMain.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
锘縰sing Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PasteAsFile
{
public partial class frmMain : Form
{
public string CurrentLocation { get; set; }
public bool IsText { get; set; }
public frmMain()
{
InitializeComponent();
}
public frmMain(string location)
{
InitializeComponent();
this.CurrentLocation = location;
}
private void frmMain_Load(object sender, EventArgs e)
{
txtFilename.Text = DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss");
txtCurrentLocation.Text = CurrentLocation ?? @"C:\";
if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Paste As File\command", "", null) == null)
{
if (MessageBox.Show("Seems that you are running this application for the first time,\nDo you want to Register it with your system Context Menu ?", "Paste As File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Program.RegisterApp();
}
}
if (Clipboard.ContainsText())
{
lblType.Text = "Text File";
comExt.SelectedItem = "txt";
IsText = true;
txtContent.Text = Clipboard.GetText();
return;
}
if (Clipboard.ContainsImage())
{
lblType.Text = "Image";
comExt.SelectedItem = "png";
imgContent.Image = Clipboard.GetImage();
return;
}
lblType.Text = "Unknown File";
btnSave.Enabled = false;
}
private void btnSave_Click(object sender, EventArgs e)
{
string location = txtCurrentLocation.Text;
location = location.EndsWith("\\") ? location : location + "\\";
string filename = txtFilename.Text + "." + comExt.SelectedItem.ToString() ;
if (IsText)
{
File.WriteAllText(location+filename,txtContent.Text,Encoding.UTF8);
this.Text += " : File Saved :)";
}
else
{
switch (comExt.SelectedItem.ToString())
{
case "png":
imgContent.Image.Save(location + filename, ImageFormat.Png);
break;
case "ico":
imgContent.Image.Save(location + filename, ImageFormat.Icon);
break;
case "jpg":
imgContent.Image.Save(location + filename, ImageFormat.Jpeg);
break;
case "bmp":
imgContent.Image.Save(location + filename, ImageFormat.Bmp);
break;
case "gif":
imgContent.Image.Save(location + filename, ImageFormat.Gif);
break;
default:
imgContent.Image.Save(location + filename, ImageFormat.Png);
break;
}
this.Text += " : Image Saved :)";
}
Task.Factory.StartNew(() =>
{
Thread.Sleep(1000);
Environment.Exit(0);
});
}
private void btnBrowseForFolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "Select a folder for saving this file ";
if (fbd.ShowDialog() == DialogResult.OK)
{
txtCurrentLocation.Text = fbd.SelectedPath;
}
}
private void lblWebsite_Click(object sender, EventArgs e)
{
Process.Start("http://eslamx.com");
}
private void lblMe_Click(object sender, EventArgs e)
{
Process.Start("http://twitter.com/EslaMx7");
}
private void lblHelp_Click(object sender, EventArgs e)
{
string msg = "Paste As File helps you paste any text or images in your system clipboard into a file directly instead of creating new file yourself";
msg += "\n--------------------\nTo Register the application to your system Context Menu run the program as Administrator with this argument : /reg";
msg += "\nto Unregister the application use this argument : /unreg\n";
msg += "\n--------------------\nSend Feedback to : EslaMx7@Gmail.Com\n\nThanks :)";
MessageBox.Show(msg,"Paste As File Help",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}