@@ -10,6 +10,25 @@ namespace PDFUnisci
10
10
{
11
11
class Program
12
12
{
13
+ static void OpenFile ( string Filename )
14
+ {
15
+ if ( File . Exists ( Filename ) )
16
+ {
17
+ try
18
+ {
19
+ Process fileopener = new Process ( ) ;
20
+
21
+ fileopener . StartInfo . FileName = "explorer" ;
22
+ fileopener . StartInfo . Arguments = "\" " + Filename + "\" " ;
23
+ fileopener . Start ( ) ;
24
+ }
25
+ catch ( Exception e )
26
+ {
27
+ LogHelper . Log ( e . ToString ( ) , LogType . Error ) ;
28
+ }
29
+ }
30
+ }
31
+
13
32
static void Main ( string [ ] args )
14
33
{
15
34
List < string > argsL = args . ToList ( ) ;
@@ -19,6 +38,7 @@ static void Main(string[] args)
19
38
string Cover = null ;
20
39
bool flat = false ;
21
40
bool splitAll = false ;
41
+ bool autoOpenFile = false ;
22
42
int singlePageSplit = 0 ;
23
43
string createNewPageFormat = null ;
24
44
@@ -65,11 +85,14 @@ static void Main(string[] args)
65
85
createNewPageFormat = "A4" ;
66
86
}
67
87
68
- LogHelper . Log ( $ "Created a new Empty Page with size: { createNewPageFormat } ", LogType . Normal ) ;
69
88
Config . ExitConfirmation = 0 ;
70
89
71
90
break ;
72
91
92
+ case "-o" :
93
+ autoOpenFile = true ;
94
+ break ;
95
+
73
96
case "-b" :
74
97
PDFInterface . Bookmarks = 1 ;
75
98
break ;
@@ -107,8 +130,9 @@ static void Main(string[] args)
107
130
108
131
string OutFileName = $ "{ Path . GetDirectoryName ( Files . FirstOrDefault ( ) ) } { Path . DirectorySeparatorChar } { Path . GetFileNameWithoutExtension ( Files . FirstOrDefault ( ) ) } ";
109
132
string OutFileNameImg = $ "{ Path . GetDirectoryName ( Images . FirstOrDefault ( ) ) } { Path . DirectorySeparatorChar } { Path . GetFileNameWithoutExtension ( Images . FirstOrDefault ( ) ) } ";
133
+ string OutFileNameFinal = "" ;
110
134
111
- if ( Files . Count ( ) == 2 )
135
+ if ( Files . Count ( ) == 2 )
112
136
{
113
137
Cover = Files . FirstOrDefault ( x => Path . GetFileNameWithoutExtension ( x ) . ToLower ( ) . Contains ( "cover" ) ) ;
114
138
@@ -122,7 +146,8 @@ static void Main(string[] args)
122
146
}
123
147
else if ( Images . Count > 0 )
124
148
{
125
- PDFInterface . ImgToPDF ( Images , $ "{ OutFileNameImg } _ImgMerged.pdf") ;
149
+ OutFileNameFinal = $ "{ OutFileNameImg } _ImgMerged.pdf";
150
+ PDFInterface . ImgToPDF ( Images , OutFileNameFinal ) ;
126
151
}
127
152
else if ( flat )
128
153
{
@@ -138,16 +163,13 @@ static void Main(string[] args)
138
163
else if ( createNewPageFormat != null )
139
164
{
140
165
//Create a new file in the temp folder with random filename
141
- string fileName = System . IO . Path . GetTempPath ( ) + Guid . NewGuid ( ) . ToString ( ) + ".pdf" ;
166
+ OutFileNameFinal = System . IO . Path . GetTempPath ( ) + "PDFUnisci_" + Guid . NewGuid ( ) . ToString ( ) + ".pdf" ;
142
167
143
- PDFInterface . CreateEmptyPage ( fileName , pageSize : createNewPageFormat ) ;
168
+ PDFInterface . CreateEmptyPage ( OutFileNameFinal , pageSize : createNewPageFormat ) ;
144
169
145
- //Open the new PDF with the default PDFeditor
146
- Process fileopener = new Process ( ) ;
170
+ LogHelper . Log ( $ "Created a new Empty Page with size: { createNewPageFormat } " , LogType . Successful ) ;
171
+ LogHelper . Log ( $ "File location: { OutFileNameFinal } " , LogType . Normal ) ;
147
172
148
- fileopener . StartInfo . FileName = "explorer" ;
149
- fileopener . StartInfo . Arguments = "\" " + fileName + "\" " ;
150
- fileopener . Start ( ) ;
151
173
}
152
174
else
153
175
{
@@ -156,8 +178,11 @@ static void Main(string[] args)
156
178
case 0 :
157
179
break ;
158
180
case 1 :
159
- if ( Cover == null ) PDFInterface . SplitPDF ( Files . FirstOrDefault ( ) , $ "{ OutFileName } _split", singlePageSplit ) ;
160
- else PDFInterface . ReplaceCoverPDF ( Files . FirstOrDefault ( ) , Cover , $ "{ OutFileName } _merged.pdf") ;
181
+ if ( Cover == null ) PDFInterface . SplitPDF ( Files . FirstOrDefault ( ) , $ "{ OutFileName } _split", singlePageSplit ) ;
182
+ else {
183
+ OutFileNameFinal = $ "{ OutFileName } _merged.pdf";
184
+ PDFInterface . ReplaceCoverPDF ( Files . FirstOrDefault ( ) , Cover , OutFileNameFinal ) ;
185
+ }
161
186
break ;
162
187
default :
163
188
@@ -171,12 +196,19 @@ static void Main(string[] args)
171
196
}
172
197
else
173
198
{
174
- PDFInterface . MergePDF ( Files , $ "{ OutFileName } _merged.pdf") ;
199
+ OutFileNameFinal = $ "{ OutFileName } _merged.pdf";
200
+ PDFInterface . MergePDF ( Files , OutFileNameFinal ) ;
175
201
}
176
202
break ;
177
203
}
178
204
}
179
205
206
+ if ( autoOpenFile )
207
+ {
208
+ LogHelper . Log ( $ "File auto open enabled", LogType . Successful ) ;
209
+ OpenFile ( OutFileNameFinal ) ;
210
+ }
211
+
180
212
if ( Config . ExitConfirmation == 1 )
181
213
{
182
214
Console . Write ( "\n Press enter to close..." ) ;
0 commit comments