Skip to content

Commit df7b37f

Browse files
committed
process log autoexit
1 parent f4bd102 commit df7b37f

File tree

4 files changed

+88
-98
lines changed

4 files changed

+88
-98
lines changed

DeCraftLauncher/Configs/RuntimeConfig.cs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class RuntimeConfig
1616
public bool isJava9 = true;
1717
public List<Category> jarCategories = new List<Category>();
1818
public List<JarEntry> jarEntries = new List<JarEntry>();
19+
public bool autoExitProcessLog = false;
1920

2021
public void UpdateAutoIsJava9Option()
2122
{
@@ -44,48 +45,50 @@ public static RuntimeConfig LoadFromXML()
4445
{
4546
ret.javaHome = Util.GetInnerOrDefault(rootNode, "JavaPath");
4647
ret.isJava9 = bool.Parse(Util.GetInnerOrDefault(rootNode, "IsJava9", "true", "bool"));
47-
}
48+
ret.autoExitProcessLog = bool.Parse(Util.GetInnerOrDefault(rootNode, "AutoExitProcessLog", "true", "bool"));
4849

49-
XmlNode categoriesNode = rootNode.SelectSingleNode("Categories");
50-
if (categoriesNode != null)
51-
{
52-
foreach (XmlNode catNode in categoriesNode.SelectNodes("Category"))
50+
XmlNode categoriesNode = rootNode.SelectSingleNode("Categories");
51+
if (categoriesNode != null)
5352
{
54-
string catName = Util.GetInnerOrDefault(catNode, "Name", null);
55-
string colorText = Util.GetInnerOrDefault(catNode, "Color", null);
56-
//todo: verify if it's actually a hex value
57-
try
53+
foreach (XmlNode catNode in categoriesNode.SelectNodes("Category"))
5854
{
59-
UInt32 catColor = colorText != null ? UInt32.Parse(colorText, System.Globalization.NumberStyles.HexNumber) : 0;
60-
if (catName != null && colorText != null)
55+
string catName = Util.GetInnerOrDefault(catNode, "Name", null);
56+
string colorText = Util.GetInnerOrDefault(catNode, "Color", null);
57+
//todo: verify if it's actually a hex value
58+
try
59+
{
60+
UInt32 catColor = colorText != null ? UInt32.Parse(colorText, System.Globalization.NumberStyles.HexNumber) : 0;
61+
if (catName != null && colorText != null)
62+
{
63+
Category cat = new Category(catName, colorText);
64+
ret.jarCategories.Add(cat);
65+
}
66+
}
67+
catch (FormatException)
6168
{
62-
Category cat = new Category(catName, colorText);
63-
ret.jarCategories.Add(cat);
6469
}
65-
} catch (FormatException)
66-
{
6770
}
6871
}
69-
}
7072

71-
XmlNode jarsNode = rootNode.SelectSingleNode("Jars");
72-
if (jarsNode != null)
73-
{
74-
foreach (XmlNode jarNode in jarsNode.SelectNodes("JarEntry"))
73+
XmlNode jarsNode = rootNode.SelectSingleNode("Jars");
74+
if (jarsNode != null)
7575
{
76-
string jarFileName = Util.GetInnerOrDefault(jarNode, "JarFileName", null);
77-
string jarFriendlyName = Util.GetInnerOrDefault(jarNode, "FriendlyName", "");
78-
string category = Util.GetInnerOrDefault(jarNode, "Category", null);
79-
IEnumerable<Category> matchingCategories =
80-
(from x in ret.jarCategories
81-
where category != null && x.name == category
82-
select x);
76+
foreach (XmlNode jarNode in jarsNode.SelectNodes("JarEntry"))
77+
{
78+
string jarFileName = Util.GetInnerOrDefault(jarNode, "JarFileName", null);
79+
string jarFriendlyName = Util.GetInnerOrDefault(jarNode, "FriendlyName", "");
80+
string category = Util.GetInnerOrDefault(jarNode, "Category", null);
81+
IEnumerable<Category> matchingCategories =
82+
(from x in ret.jarCategories
83+
where category != null && x.name == category
84+
select x);
8385

84-
JarEntry jarEntry = new JarEntry(jarFileName);
85-
jarEntry.friendlyName = jarFriendlyName;
86-
jarEntry.category = matchingCategories.Any() ? matchingCategories.First() : null;
86+
JarEntry jarEntry = new JarEntry(jarFileName);
87+
jarEntry.friendlyName = jarFriendlyName;
88+
jarEntry.category = matchingCategories.Any() ? matchingCategories.First() : null;
8789

88-
ret.jarEntries.Add(jarEntry);
90+
ret.jarEntries.Add(jarEntry);
91+
}
8992
}
9093
}
9194
}
@@ -104,6 +107,7 @@ public void SaveToXML(MainWindow caller)
104107

105108
rootElement.AppendChild(Util.GenElementChild(newXml, "JavaPath", javaHome));
106109
rootElement.AppendChild(Util.GenElementChild(newXml, "IsJava9", isJava9.ToString()));
110+
rootElement.AppendChild(Util.GenElementChild(newXml, "AutoExitProcessLog", autoExitProcessLog.ToString()));
107111

108112
XmlNode catEntries = Util.GenElementChild(newXml, "Categories");
109113
foreach (Category cat in jarCategories) //meow

DeCraftLauncher/Configs/UI/WindowRuntimeConfig.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
<TextBox x:Name="jre_path" Style="{DynamicResource TextBoxMainStyle}" Margin="103,75,54,0" TextWrapping="NoWrap" VerticalAlignment="Top" Height="20" Background="Transparent" TextChanged="TextBox_TextChanged" KeyDown="jre_path_KeyDown" ToolTip=""/>
1313
<Button Content="Find..." Margin="0,75,16,0" VerticalAlignment="Top" Background="{x:Null}" Foreground="White" BorderBrush="#FF3C3C3C" HorizontalAlignment="Right" Width="38" Click="Button_Click"/>
1414
<Label Content="Runtime configuration" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Foreground="White" FontWeight="Bold" FontSize="22"/>
15-
<Label x:Name="jreconfig_version" Content="&lt;press Enter to test&gt;" Margin="10,148,16,0" VerticalAlignment="Top" Foreground="White" Height="135"/>
16-
<Label Content="(leave empty to use the system-wide java installation)" Margin="10,125,16,0" VerticalAlignment="Top" Background="{x:Null}" Foreground="White" FontStyle="Italic"/>
17-
<Label Content="Use required Java 9+ options" HorizontalAlignment="Left" Margin="10,94,0,0" VerticalAlignment="Top" Background="{x:Null}" Foreground="White"/>
18-
<CheckBox x:Name="checkbox_isjava9" Content="" HorizontalAlignment="Left" Margin="179,94,0,0" VerticalAlignment="Top" Height="26" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsChecked="True" ToolTip="Check this option if you are using Java version 9 or newer."/>
15+
<Label x:Name="jreconfig_version" Content="&lt;press Enter to test&gt;" Margin="10,188,16,0" VerticalAlignment="Top" Foreground="White" Height="135"/>
16+
<Label Content="(leave empty to use the system-wide java installation)" Margin="10,165,16,0" VerticalAlignment="Top" Background="{x:Null}" Foreground="White" FontStyle="Italic"/>
17+
<Label Content="Use required Java 9+ options" HorizontalAlignment="Left" Margin="10,94,0,0" VerticalAlignment="Top" Background="{x:Null}" Foreground="White" Width="179"/>
18+
<CheckBox x:Name="checkbox_isjava9" Content="" HorizontalAlignment="Left" Margin="209,94,0,0" VerticalAlignment="Top" Height="26" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsChecked="True" ToolTip="Check this option if you are using Java version 9 or newer."/>
19+
<Label Content="Close Process Log automatically" HorizontalAlignment="Left" Margin="10,125,0,0" VerticalAlignment="Top" Background="{x:Null}" Foreground="White"/>
20+
<CheckBox x:Name="checkbox_autoexitprocesslog" Content="" HorizontalAlignment="Left" Margin="209,125,0,0" VerticalAlignment="Top" Height="26" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" IsChecked="True" ToolTip="Check this option if you are using Java version 9 or newer."/>
1921

2022
</Grid>
2123
</fw:AcrylicWindow>

DeCraftLauncher/Configs/UI/WindowRuntimeConfig.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public WindowRuntimeConfig(MainWindow parent)
3030
this.parent = parent;
3131
jre_path.Text = MainWindow.mainRTConfig.javaHome;
3232
checkbox_isjava9.IsChecked = MainWindow.mainRTConfig.isJava9;
33+
checkbox_autoexitprocesslog.IsChecked = MainWindow.mainRTConfig.autoExitProcessLog;
3334
}
3435

3536
public void FixJavaHomeString()
@@ -92,6 +93,7 @@ private void AcrylicWindow_Closed(object sender, EventArgs e)
9293
FixJavaHomeString();
9394
MainWindow.mainRTConfig.javaHome = jre_path.Text;
9495
MainWindow.mainRTConfig.isJava9 = checkbox_isjava9.IsChecked == true;
96+
MainWindow.mainRTConfig.autoExitProcessLog = checkbox_autoexitprocesslog.IsChecked == true;
9597
parent.SaveRuntimeConfig();
9698
} catch (Exception ex)
9799
{

DeCraftLauncher/WindowProcessLog.xaml.cs

Lines changed: 45 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.ComponentModel;
67
using System.Diagnostics;
78
using System.Linq;
89
using System.Text;
@@ -31,69 +32,9 @@ public partial class WindowProcessLog : AcrylicWindow
3132
public DispatcherTimer logPrintTimer = new DispatcherTimer();
3233

3334
public Process target;
35+
private volatile bool autoExitTimerStarted = false;
36+
private volatile bool abortAutoExit = false;
3437

35-
public void ThreadLoggerStdOut()
36-
{
37-
Stopwatch timer = new Stopwatch();
38-
string stdout_buffer = "";
39-
while (!target.HasExited)
40-
{
41-
if (!target.StandardOutput.EndOfStream)
42-
{
43-
stdout_buffer += target.StandardOutput.ReadLine() + "\n";
44-
if (!timer.IsRunning)
45-
{
46-
timer.Start();
47-
}
48-
}
49-
if (timer.IsRunning && timer.ElapsedMilliseconds > 64)
50-
{
51-
timer.Stop();
52-
}
53-
if (stdout_buffer != "" && !timer.IsRunning)
54-
{
55-
Dispatcher.Invoke(delegate
56-
{
57-
logtext.Text += stdout_buffer;
58-
logscroller.ScrollToVerticalOffset(logscroller.ExtentHeight);
59-
stdout_buffer = "";
60-
});
61-
62-
}
63-
Thread.Sleep(1);
64-
}
65-
66-
Console.WriteLine("ThreadLogger exit");
67-
}
68-
public void ThreadLoggerStdErr()
69-
{
70-
int dispatcherTimer = 0;
71-
string stderr_buffer = "";
72-
while (!target.HasExited)
73-
{
74-
if (!target.StandardError.EndOfStream)
75-
{
76-
stderr_buffer += target.StandardError.ReadLine() + "\n";
77-
}
78-
if (stderr_buffer != "" && dispatcherTimer <= 0)
79-
{
80-
Dispatcher.Invoke(delegate
81-
{
82-
logtext.Text += stderr_buffer;
83-
logscroller.ScrollToVerticalOffset(logscroller.ExtentHeight);
84-
stderr_buffer = "";
85-
});
86-
dispatcherTimer = 100;
87-
}
88-
Thread.Sleep(1);
89-
if (dispatcherTimer > 0)
90-
{
91-
dispatcherTimer--;
92-
}
93-
}
94-
95-
Console.WriteLine("ThreadLoggerStdErr exit");
96-
}
9738
public WindowProcessLog(Process t)
9839
{
9940
target = t;
@@ -226,7 +167,26 @@ public WindowProcessLog(Process t)
226167
logtext.Text += "\nIf possible, open Runtime settings set the Java path to a non-ARM version of Java.";
227168
logtext.Text += "\nAlternatively, add a version of LWJGL with ARM DLLs.";
228169
}
170+
if (MainWindow.mainRTConfig.autoExitProcessLog)
171+
{
172+
logtext.Text += "\n\nExiting in 5 seconds... [F2] to keep this window open";
173+
}
229174
});
175+
autoExitTimerStarted = true;
176+
if (MainWindow.mainRTConfig.autoExitProcessLog)
177+
{
178+
Thread.Sleep(5000);
179+
if (!abortAutoExit)
180+
{
181+
Dispatcher.Invoke(delegate
182+
{
183+
if (!this.IsFocused)
184+
{
185+
this.Close();
186+
}
187+
});
188+
}
189+
}
230190
};
231191
}
232192

@@ -297,7 +257,6 @@ public string ProcessLogTranslateString(string a, TinyV2Mapper tinyV2Mapper)
297257

298258
protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e)
299259
{
300-
//todo: make this a visible option
301260
if (e.Key == Key.F1)
302261
{
303262
OpenFileDialog tinyV2MapDialog = new OpenFileDialog();
@@ -311,7 +270,30 @@ protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e)
311270
select ProcessLogTranslateString(x, tinyV2Mapper)));
312271
}
313272
}
273+
else if (e.Key == Key.F2)
274+
{
275+
if (autoExitTimerStarted)
276+
{
277+
abortAutoExit = true;
278+
Dispatcher.Invoke(delegate
279+
{
280+
logtext.Text += "\nAuto exit aborted.";
281+
});
282+
}
283+
}
314284
base.OnKeyDown(e);
315285
}
286+
287+
protected override void OnClosing(CancelEventArgs e)
288+
{
289+
if (!target.HasExited)
290+
{
291+
if (System.Windows.MessageBox.Show("This process is still running.\nClosing this window will keep it in the background. Close anyway?", "DECRAFT", MessageBoxButton.YesNo) == MessageBoxResult.No)
292+
{
293+
e.Cancel = true;
294+
}
295+
}
296+
base.OnClosing(e);
297+
}
316298
}
317299
}

0 commit comments

Comments
 (0)