Skip to content

Commit baabc31

Browse files
authored
Program Arguments Support and File Chooser
File Chooser only when multiple .jar-Files!
1 parent 09d99ab commit baabc31

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

entry.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ public static byte[] translate(byte[] bytes, int shift) {
2020
return bytes;
2121
}
2222

23+
[STAThread]
2324
public static void Main(string[] args) {
2425
bool gui = true, shell = false;
26+
string parsethrough = string.Empty;
2527
if(args.Length > 0) {
26-
foreach (string arg in args)
28+
foreach (string arg in args) {
2729
if (arg.Equals("nogui")) gui = false;
2830
else if (arg.Equals("shell")) shell = true;
31+
parsethrough += ' ' + arg;
32+
}
2933
}
3034
string cwd = Environment.CurrentDirectory;
3135
string exe = Process.GetCurrentProcess().MainModule.FileName;
@@ -58,19 +62,32 @@ public static void Main(string[] args) {
5862
stream.Close();
5963
}
6064
ProcessStartInfo info = new ProcessStartInfo();
61-
if(exe.EndsWith(".shell.exe")) {
62-
info.Arguments = "/c title Effyiex Java Packager & java -jar \"" + jar + "\" & pause";
65+
if (exe.EndsWith(".shell.exe")) {
66+
info.Arguments = "/c title Effyiex Java Packager & java -jar \"" + jar + "\"" + parsethrough + " & pause";
6367
info.FileName = "cmd.exe";
64-
} else info.FileName = jar;
68+
} else {
69+
info.Arguments = parsethrough.Substring(1);
70+
info.FileName = jar;
71+
}
6572
info.WorkingDirectory = cwd;
6673
Process.Start(info).WaitForExit();
6774
File.Delete(jar);
6875
} else {
76+
short jcount = 0;
6977
foreach (string f in Directory.GetFiles(cwd))
7078
if (f.EndsWith(".jar")) {
7179
jar = f;
72-
break;
80+
jcount++;
7381
}
82+
if (jcount > 1 && gui) {
83+
OpenFileDialog dialog = new OpenFileDialog();
84+
dialog.Title = "There are multiple Jars to choose from.";
85+
dialog.InitialDirectory = cwd;
86+
dialog.Filter = "Java Package (*.jar) | *.jar";
87+
dialog.Multiselect = false;
88+
if (dialog.ShowDialog() == DialogResult.OK) jar = dialog.FileName;
89+
else Environment.Exit(0);
90+
}
7491
if (!File.Exists(jar)) {
7592
string msg = "There has to be placed a jar-file in the same folder as the packager!";
7693
MessageBox.Show(msg, "ERROR: jar not found", MessageBoxButtons.OK, MessageBoxIcon.Error);

0 commit comments

Comments
 (0)