Skip to content

Commit 0bc0835

Browse files
Change command line option names
Change command line option names for TextSubDir and ImageSubDir to TextDefaultDir and ImageDefaultDir. Made this change because this option now supports both sub path and a full (FQN) path.
1 parent cb338e0 commit 0bc0835

2 files changed

Lines changed: 55 additions & 114 deletions

File tree

PasteIntoFile/Program.cs

Lines changed: 50 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,49 @@ static void Main(string[] args)
2020
Application.SetCompatibleTextRenderingDefault(false);
2121
if (args.Length>0)
2222
{
23-
if (string.Equals(args[0], "/reg", StringComparison.CurrentCultureIgnoreCase))
23+
try
2424
{
25-
RegisterApp();
26-
return;
27-
}
28-
else if (string.Equals(args[0], "/unreg", StringComparison.CurrentCultureIgnoreCase))
29-
{
30-
UnRegisterApp();
31-
return;
32-
}
33-
else if (string.Equals(args[0], "/filename", StringComparison.CurrentCultureIgnoreCase))
34-
{
35-
if (args.Length > 1)
25+
if (string.Equals(args[0], "/reg", StringComparison.CurrentCultureIgnoreCase))
3626
{
37-
RegisterFilename(args[1]);
27+
RegisterApp();
28+
return;
3829
}
39-
return;
40-
}
41-
else if (string.Equals(args[0], "/TextSubDir", StringComparison.CurrentCultureIgnoreCase))
42-
{
43-
if (args.Length > 1)
30+
else if (string.Equals(args[0], "/unreg", StringComparison.CurrentCultureIgnoreCase))
4431
{
45-
RegisterTextSubDir(args[1]);
32+
UnRegisterApp();
33+
return;
4634
}
47-
return;
48-
}
49-
else if (string.Equals(args[0], "/ImageSubDir", StringComparison.CurrentCultureIgnoreCase))
35+
else if (string.Equals(args[0], "/filename", StringComparison.CurrentCultureIgnoreCase) && args.Length > 1)
5036
{
51-
if (args.Length > 1)
37+
var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File");
38+
key = key.CreateSubKey("filename");
39+
key.SetValue("", args[1]);
40+
41+
MessageBox.Show("Filename has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information);
42+
return;
43+
}
44+
else if (string.Equals(args[0], "/TextDefaultDir", StringComparison.CurrentCultureIgnoreCase) && args.Length > 1)
5245
{
53-
RegisterImageSubDir(args[1]);
46+
var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File");
47+
key = key.CreateSubKey("TextDefaultDir");
48+
key.SetValue("", args[1]);
49+
50+
MessageBox.Show("TextDefaultDir has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information);
51+
return;
5452
}
55-
return;
53+
else if (string.Equals(args[0], "/ImageDefaultDir", StringComparison.CurrentCultureIgnoreCase) && args.Length > 1)
54+
{
55+
var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File");
56+
key = key.CreateSubKey("ImageDefaultDir");
57+
key.SetValue("", args[1]);
58+
59+
MessageBox.Show("ImageDefaultDir has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information);
60+
return;
61+
}
62+
}
63+
catch (Exception ex)
64+
{
65+
MessageBox.Show(ex.Message + "\nPlease run the application as Administrator !", "Paste As File", MessageBoxButtons.OK, MessageBoxIcon.Error);
5666
}
5767
Application.Run(new frmMain(args[0]));
5868
}
@@ -63,98 +73,29 @@ static void Main(string[] args)
6373

6474
}
6575

66-
public static void ShowMessageToRunAsAdmin(Exception ex)
67-
{
68-
MessageBox.Show(ex.Message + "\nPlease run the application as Administrator !", "Paste As File", MessageBoxButtons.OK, MessageBoxIcon.Error);
69-
}
70-
71-
public static void RegisterFilename(string filename)
72-
{
73-
try
74-
{
75-
var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File");
76-
key = key.CreateSubKey("filename");
77-
key.SetValue("", filename);
78-
79-
MessageBox.Show("Filename has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information);
80-
}
81-
catch (Exception ex)
82-
{
83-
ShowMessageToRunAsAdmin(ex);
84-
}
85-
}
86-
87-
public static void RegisterTextSubDir(string TextSubDir)
88-
{
89-
try
90-
{
91-
var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File");
92-
key = key.CreateSubKey("TextSubDir");
93-
key.SetValue("", TextSubDir);
94-
95-
MessageBox.Show("TextSubDir has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information);
96-
}
97-
catch (Exception ex)
98-
{
99-
ShowMessageToRunAsAdmin(ex);
100-
}
101-
}
102-
103-
public static void RegisterImageSubDir(string ImageSubDir)
104-
{
105-
try
106-
{
107-
var key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File");
108-
key = key.CreateSubKey("ImageSubDir");
109-
key.SetValue("", ImageSubDir);
110-
111-
MessageBox.Show("ImageSubDir has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information);
112-
}
113-
catch (Exception ex)
114-
{
115-
ShowMessageToRunAsAdmin(ex);
116-
}
117-
}
118-
11976
public static void UnRegisterApp()
12077
{
121-
try
122-
{
123-
var key = OpenDirectoryKey().OpenSubKey(@"Background\shell", true);
124-
key.DeleteSubKeyTree("Paste Into File");
125-
126-
key = OpenDirectoryKey().OpenSubKey("shell", true);
127-
key.DeleteSubKeyTree("Paste Into File");
78+
var key = OpenDirectoryKey().OpenSubKey(@"Background\shell", true);
79+
key.DeleteSubKeyTree("Paste Into File");
12880

129-
MessageBox.Show("Application has been Unregistered from your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information);
81+
key = OpenDirectoryKey().OpenSubKey("shell", true);
82+
key.DeleteSubKeyTree("Paste Into File");
13083

131-
}
132-
catch (Exception ex)
133-
{
134-
ShowMessageToRunAsAdmin(ex);
135-
}
84+
MessageBox.Show("Application has been Unregistered from your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information);
13685
}
13786

13887
public static void RegisterApp()
13988
{
140-
try
141-
{
142-
var key = OpenDirectoryKey().CreateSubKey(@"Background\shell").CreateSubKey("Paste Into File");
143-
key.SetValue("Icon", "\"" + Application.ExecutablePath + "\",0");
144-
key = key.CreateSubKey("command");
145-
key.SetValue("" , "\"" + Application.ExecutablePath + "\" \"%V\"");
146-
147-
key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File");
148-
key.SetValue("Icon", "\"" + Application.ExecutablePath + "\",0");
149-
key = key.CreateSubKey("command");
150-
key.SetValue("" , "\"" + Application.ExecutablePath + "\" \"%1\"");
151-
MessageBox.Show("Application has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information);
152-
153-
}
154-
catch (Exception ex)
155-
{
156-
ShowMessageToRunAsAdmin(ex);
157-
}
89+
var key = OpenDirectoryKey().CreateSubKey(@"Background\shell").CreateSubKey("Paste Into File");
90+
key.SetValue("Icon", "\"" + Application.ExecutablePath + "\",0");
91+
key = key.CreateSubKey("command");
92+
key.SetValue("", "\"" + Application.ExecutablePath + "\" \"%V\"");
93+
94+
key = OpenDirectoryKey().CreateSubKey("shell").CreateSubKey("Paste Into File");
95+
key.SetValue("Icon", "\"" + Application.ExecutablePath + "\",0");
96+
key = key.CreateSubKey("command");
97+
key.SetValue("", "\"" + Application.ExecutablePath + "\" \"%1\"");
98+
MessageBox.Show("Application has been registered with your system", "Paste Into File", MessageBoxButtons.OK, MessageBoxIcon.Information);
15899
}
159100

160101
public static void RestartApp()

PasteIntoFile/frmMain.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ private void frmMain_Load(object sender, EventArgs e)
3636
txtCurrentLocation.Text = CurrentLocation ?? @"C:\";
3737
const string DEFAULT_TEXT_SUBFOLDER = "Text";
3838
const string DEFAULT_IMAGE_SUBFOLDER = "Image";
39-
string TextSubDir = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\shell\Paste Into File\TextSubDir", "", null) ?? DEFAULT_TEXT_SUBFOLDER;
40-
string ImageSubDir = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\shell\Paste Into File\ImageSubDir", "", null) ?? DEFAULT_IMAGE_SUBFOLDER;
39+
string TextDefaultDir = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\shell\Paste Into File\TextDefaultDir", "", null) ?? DEFAULT_TEXT_SUBFOLDER;
40+
string ImageDefaultDir = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\shell\Paste Into File\ImageDefaultDir", "", null) ?? DEFAULT_IMAGE_SUBFOLDER;
4141
if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
4242
{
43-
string SubDir = (Clipboard.ContainsText()) ? TextSubDir : ImageSubDir;
43+
string SubDir = (Clipboard.ContainsText()) ? TextDefaultDir : ImageDefaultDir;
4444
txtCurrentLocation.Text = (SubDir.IndexOf(":") > 0) ? SubDir : txtCurrentLocation.Text + @"\" + SubDir;
4545
}
4646

@@ -195,8 +195,8 @@ private void lblHelp_Click(object sender, EventArgs e)
195195
msg += "To create a file automatically without a window prompt, hold shift key while selecting 'Paste Into File'\n";
196196
msg += "To add a default sub folder to 'Current Location', hold ctrl key while selecting 'Paste Into File'. ";
197197
msg += "The default sub folder for a text file is Text, and the default sub folder for an image file is Image.\n\n";
198-
msg += "To change the default Text Sub Folder, use argument:\n/TextSubDir MyDefaultTextFolder\n";
199-
msg += "To change the default Image Sub Folder, use argument:\n/ImageSubDir MyImgDir\n";
198+
msg += "To change the default Text Sub Folder, use argument:\n/TextDefaultDir MyDefaultTextFolder\n";
199+
msg += "To change the default Image Sub Folder, use argument:\n/ImageDefaultDir MyImgDir\n";
200200
msg += "\n--------------------\nSend Feedback to : eslamx7@gmail.com\n\nThanks :)";
201201
MessageBox.Show(msg, "Paste As File Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
202202

0 commit comments

Comments
 (0)