Skip to content

Commit

Permalink
Program Arguments Support and File Chooser
Browse files Browse the repository at this point in the history
File Chooser only when multiple .jar-Files!
  • Loading branch information
Effyiex authored Dec 15, 2020
1 parent 09d99ab commit baabc31
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ public static byte[] translate(byte[] bytes, int shift) {
return bytes;
}

[STAThread]
public static void Main(string[] args) {
bool gui = true, shell = false;
string parsethrough = string.Empty;
if(args.Length > 0) {
foreach (string arg in args)
foreach (string arg in args) {
if (arg.Equals("nogui")) gui = false;
else if (arg.Equals("shell")) shell = true;
parsethrough += ' ' + arg;
}
}
string cwd = Environment.CurrentDirectory;
string exe = Process.GetCurrentProcess().MainModule.FileName;
Expand Down Expand Up @@ -58,19 +62,32 @@ public static void Main(string[] args) {
stream.Close();
}
ProcessStartInfo info = new ProcessStartInfo();
if(exe.EndsWith(".shell.exe")) {
info.Arguments = "/c title Effyiex Java Packager & java -jar \"" + jar + "\" & pause";
if (exe.EndsWith(".shell.exe")) {
info.Arguments = "/c title Effyiex Java Packager & java -jar \"" + jar + "\"" + parsethrough + " & pause";
info.FileName = "cmd.exe";
} else info.FileName = jar;
} else {
info.Arguments = parsethrough.Substring(1);
info.FileName = jar;
}
info.WorkingDirectory = cwd;
Process.Start(info).WaitForExit();
File.Delete(jar);
} else {
short jcount = 0;
foreach (string f in Directory.GetFiles(cwd))
if (f.EndsWith(".jar")) {
jar = f;
break;
jcount++;
}
if (jcount > 1 && gui) {
OpenFileDialog dialog = new OpenFileDialog();
dialog.Title = "There are multiple Jars to choose from.";
dialog.InitialDirectory = cwd;
dialog.Filter = "Java Package (*.jar) | *.jar";
dialog.Multiselect = false;
if (dialog.ShowDialog() == DialogResult.OK) jar = dialog.FileName;
else Environment.Exit(0);
}
if (!File.Exists(jar)) {
string msg = "There has to be placed a jar-file in the same folder as the packager!";
MessageBox.Show(msg, "ERROR: jar not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
Expand Down

0 comments on commit baabc31

Please sign in to comment.