Skip to content

Commit 34a2de5

Browse files
committed
Added flag for file auto open
1 parent 48493cc commit 34a2de5

File tree

3 files changed

+50
-16
lines changed

3 files changed

+50
-16
lines changed

PDFUnisci/Menu.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public static void Create() {
2121
Console.WriteLine("\t\t-s\t\t\tSplit all the files in dedicated folders");
2222
Console.WriteLine("\t\t-flat\t\t\tAll the comments will be flattened");
2323
Console.WriteLine("\t\t-singlePageSplit\tOnly the selected page will be splitted");
24-
Console.WriteLine("\t\t-np\t\t\tCreate ad open a new empty page in a temp folder\n");
24+
Console.WriteLine("\t\t-np\t\t\tCreate new empty page in a temp folder");
25+
Console.WriteLine("\t\t-o\t\t\tAuto open the created file");
26+
Console.WriteLine("\n");
2527

2628
Console.WriteLine("More information: https://github.com/Clouz/PDFUnisci\n");
2729

PDFUnisci/Program.cs

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ namespace PDFUnisci
1010
{
1111
class Program
1212
{
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+
1332
static void Main(string[] args)
1433
{
1534
List<string> argsL = args.ToList();
@@ -19,6 +38,7 @@ static void Main(string[] args)
1938
string Cover = null;
2039
bool flat = false;
2140
bool splitAll = false;
41+
bool autoOpenFile = false;
2242
int singlePageSplit = 0;
2343
string createNewPageFormat = null;
2444

@@ -65,11 +85,14 @@ static void Main(string[] args)
6585
createNewPageFormat = "A4";
6686
}
6787

68-
LogHelper.Log($"Created a new Empty Page with size: {createNewPageFormat}", LogType.Normal);
6988
Config.ExitConfirmation = 0;
7089

7190
break;
7291

92+
case "-o":
93+
autoOpenFile = true;
94+
break;
95+
7396
case "-b":
7497
PDFInterface.Bookmarks = 1;
7598
break;
@@ -107,8 +130,9 @@ static void Main(string[] args)
107130

108131
string OutFileName = $"{Path.GetDirectoryName(Files.FirstOrDefault())}{Path.DirectorySeparatorChar}{Path.GetFileNameWithoutExtension(Files.FirstOrDefault())}";
109132
string OutFileNameImg = $"{Path.GetDirectoryName(Images.FirstOrDefault())}{Path.DirectorySeparatorChar}{Path.GetFileNameWithoutExtension(Images.FirstOrDefault())}";
133+
string OutFileNameFinal = "";
110134

111-
if(Files.Count() == 2)
135+
if (Files.Count() == 2)
112136
{
113137
Cover = Files.FirstOrDefault(x => Path.GetFileNameWithoutExtension(x).ToLower().Contains("cover"));
114138

@@ -122,7 +146,8 @@ static void Main(string[] args)
122146
}
123147
else if (Images.Count > 0)
124148
{
125-
PDFInterface.ImgToPDF(Images, $"{OutFileNameImg}_ImgMerged.pdf");
149+
OutFileNameFinal = $"{OutFileNameImg}_ImgMerged.pdf";
150+
PDFInterface.ImgToPDF(Images, OutFileNameFinal);
126151
}
127152
else if(flat)
128153
{
@@ -138,16 +163,13 @@ static void Main(string[] args)
138163
else if (createNewPageFormat != null)
139164
{
140165
//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";
142167

143-
PDFInterface.CreateEmptyPage(fileName, pageSize: createNewPageFormat);
168+
PDFInterface.CreateEmptyPage(OutFileNameFinal, pageSize: createNewPageFormat);
144169

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);
147172

148-
fileopener.StartInfo.FileName = "explorer";
149-
fileopener.StartInfo.Arguments = "\"" + fileName + "\"";
150-
fileopener.Start();
151173
}
152174
else
153175
{
@@ -156,8 +178,11 @@ static void Main(string[] args)
156178
case 0:
157179
break;
158180
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+
}
161186
break;
162187
default:
163188

@@ -171,12 +196,19 @@ static void Main(string[] args)
171196
}
172197
else
173198
{
174-
PDFInterface.MergePDF(Files, $"{OutFileName}_merged.pdf");
199+
OutFileNameFinal = $"{OutFileName}_merged.pdf";
200+
PDFInterface.MergePDF(Files, OutFileNameFinal);
175201
}
176202
break;
177203
}
178204
}
179205

206+
if (autoOpenFile)
207+
{
208+
LogHelper.Log($"File auto open enabled", LogType.Successful);
209+
OpenFile(OutFileNameFinal);
210+
}
211+
180212
if (Config.ExitConfirmation == 1)
181213
{
182214
Console.Write("\nPress enter to close...");

PDFUnisci/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
3232
// usando l'asterisco '*' come illustrato di seguito:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.14.1.0")]
35-
[assembly: AssemblyFileVersion("1.14.1.0")]
34+
[assembly: AssemblyVersion("1.14.2.0")]
35+
[assembly: AssemblyFileVersion("1.14.2.0")]

0 commit comments

Comments
 (0)