@@ -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 + "\n Please 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 + "\n Please 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 ( )
0 commit comments