forked from TranslucentTB/TranslucentTB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
78 lines (69 loc) · 2.25 KB
/
Copy pathProgram.cs
File metadata and controls
78 lines (69 loc) · 2.25 KB
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
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
namespace DesktopInstallerBuilder
{
class Program
{
private static string WalkParent(string path, int count)
{
var dir = new DirectoryInfo(path);
foreach (int _ in Enumerable.Range(0, count))
{
dir = dir.Parent ?? throw new Exception("Tried to get parent of folder structure root.");
}
return dir.FullName;
}
private static string GetInPath(string fileName)
{
if (File.Exists(fileName))
{
return Path.GetFullPath(fileName);
}
foreach (var path in Environment.GetEnvironmentVariable("PATH").Split(';'))
{
var fullPath = Path.Combine(path, fileName);
if (File.Exists(fullPath))
{
return fullPath;
}
}
return null;
}
public static int Main()
{
var p = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = GetInPath("ISCC.exe") ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Inno Setup 5", "ISCC.exe"),
Arguments = Path.Combine(WalkParent(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), 4), "DesktopInstaller", "main.iss"),
UseShellExecute = false,
RedirectStandardOutput = true
}
};
try
{
p.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
p.Start();
p.BeginOutputReadLine();
p.WaitForExit();
return p.ExitCode;
}
catch (Exception ex)
{
var originalColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex);
Console.ForegroundColor = originalColor;
return 1;
}
finally
{
p.Dispose();
}
}
}
}