Skip to content

Commit

Permalink
Ver 0.2.0-A2: Fix Restart Feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiroiame-Kusu committed Jul 12, 2023
1 parent d277d45 commit cc16cf1
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 19 deletions.
27 changes: 18 additions & 9 deletions Serein/Universal/Core/Server/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static bool Start(bool quiet)
Logger.Output(LogType.Server_Notice, "启动中");

string ServerType = Global.Settings.Server.Path.Substring(Global.Settings.Server.Path.Length - 3);
if(Global.Settings.Server.MaxRAM == null || Global.Settings.Server.MaxRAM == "")
if(string.IsNullOrEmpty(Global.Settings.Server.MaxRAM) == true)
{
Logger.MsgBox("最大内存为空", "Serein", 0, 48);
return false;
Expand All @@ -177,10 +177,21 @@ public static bool Start(bool quiet)
{
JEStartMaxRam = Global.Settings.Server.MaxRAM;
}
string? JavaPathSettings = Global.Settings.Server.JavaPath;
if (string.IsNullOrEmpty(JavaPathSettings) == true){
bool status = string.IsNullOrEmpty(JavaPathSettings);
CurrentJavaPath = "java";
}
else
{

string.IsNullOrEmpty(JavaPathSettings);
CurrentJavaPath = Global.Settings.Server.JavaPath;
}
try
{
ProcessStartInfo defaultJava = new ProcessStartInfo();
defaultJava.FileName = "java.exe";
defaultJava.FileName = CurrentJavaPath;
defaultJava.Arguments = " -version";
defaultJava.RedirectStandardError = true;
defaultJava.UseShellExecute = false;
Expand Down Expand Up @@ -231,7 +242,7 @@ public static bool Start(bool quiet)
ProcessStartInfo ServerStartInfo = new ProcessStartInfo(Global.Settings.Server.Path)
{

FileName = "java",
FileName = CurrentJavaPath,
Arguments = " -jar -Xmx" + JEStartMaxRam + "M " + JEOptimizationArguments + Global.Settings.Server.Path + " --nogui",
UseShellExecute = false,
CreateNoWindow = true,
Expand Down Expand Up @@ -579,13 +590,10 @@ private static void CloseAll()
/// <summary>
/// 重启请求
/// </summary>
public static void RestartRequest()
public static void RequestRestart()
{
if (!_restart)
{
_restart = false;
Stop();
}
_restart = true;
Stop();
}

/// <summary>
Expand Down Expand Up @@ -654,6 +662,7 @@ public static void UpdateInfo()
public static string Time => Status && _serverProcess is not null ? (DateTime.Now - _serverProcess.StartTime).ToCustomString() : string.Empty;

public static ProcessStartInfo StartInfo { get; private set; }
public static string? CurrentJavaPath { get; private set; }

/// <summary>
/// Unicode转换
Expand Down
4 changes: 3 additions & 1 deletion Serein/Universal/Settings/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ internal class Server

public int Type = 2;

public string MaxRAM;
public string? MaxRAM;

public string? JavaPath;
}
}
6 changes: 0 additions & 6 deletions Serein/WPF/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@
Icon="Box24"
PageTag="functions"
PageType="{x:Type function_pages:Container}" />
<ui:NavigationItem
x:Name="DebugNavigationItem"
Content="调试输出"
Icon="WindowDevTools24"
PageTag="debug"
PageType="{x:Type debug_page:Debug}" />
</ui:NavigationStore.Items>
<ui:NavigationStore.Footer>
<ui:NavigationItem
Expand Down
1 change: 0 additions & 1 deletion Serein/WPF/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public MainWindow()
{
InitializeComponent();
Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
DebugNavigationItem.Visibility = Global.Settings.Serein.DevelopmentTool.EnableDebug ? Visibility.Visible : Visibility.Hidden;
SettingsNavigationItem.Visibility = Global.Settings.Serein.PagesDisplayed.Settings ? Visibility.Visible : Visibility.Hidden;
if (!Global.Settings.Serein.PagesDisplayed.ServerPanel && !Global.Settings.Serein.PagesDisplayed.ServerPluginManager)
{
Expand Down
3 changes: 2 additions & 1 deletion Serein/WPF/Windows/Pages/Server/Panel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void Stop_Click(object sender, RoutedEventArgs e)
=> ServerManager.Stop();

private void Restart_Click(object sender, RoutedEventArgs e)
=> ServerManager.RestartRequest();
=> ServerManager.RequestRestart();

private void Kill_Click(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -124,6 +124,7 @@ private void UpdateInfos()
Time.Content = ServerManager.Status ? ServerManager.Time : "-";
CPUPerc.Content = ServerManager.Status ? "%" + ServerManager.CPUUsage.ToString("N1") : "-";
Catalog.MainWindow?.UpdateTitle(ServerManager.Status ? ServerManager.StartFileName : null);
JavaVersion.Content = ServerManager.JavaVersion;
});
}
Expand Down
22 changes: 22 additions & 0 deletions Serein/WPF/Windows/Pages/Settings/Server.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@
Content="选择文件"
Icon="OpenFolder24" />
</Grid>
<TextBlock
Name="JavaPathBox_A"
HorizontalAlignment="Left"
Text="Java路径"
ToolTip="Java环境路径" />
<Grid Name="JavaPathBox_B">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<TextBox
Name="JavaSEPath"
IsReadOnly="True"
ToolTip="Java环境路径" />
<ui:Button
x:Name="SelectJava"
Grid.Column="1"
Margin="5,0,0,0"
Click="SelectJava_Click"
Content="选择文件"
Icon="OpenFolder24" />
</Grid>
<TextBlock
HorizontalAlignment="Left"
Text="关服指令(一行一条)"
Expand Down
32 changes: 31 additions & 1 deletion Serein/WPF/Windows/Pages/Settings/Server.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public Server()
Load();
_loaded = true;
Catalog.Settings.Server = this;

}

private void Load()
Expand All @@ -31,6 +32,7 @@ private void Load()
OutputEncoding.SelectedIndex = Global.Settings.Server.OutputEncoding;
OutputStyle.SelectedIndex = Global.Settings.Server.OutputStyle;
Path.Text = Global.Settings.Server.Path;
JavaSEPath.Text = Global.Settings.Server.JavaPath;
Port.Value = Global.Settings.Server.Port;
LineTerminator.Text = Global.Settings.Server.LineTerminator.Replace("\r", "\\r").Replace("\n", "\\n");

Expand All @@ -49,7 +51,20 @@ private void EnableUnicode_Click(object sender, RoutedEventArgs e)
private void EnableLog_Click(object sender, RoutedEventArgs e)
=> Global.Settings.Server.EnableLog = EnableLog.IsChecked ?? false;
private void Type_SelectionChanged(object sender, SelectionChangedEventArgs e)
=> Global.Settings.Server.Type = _loaded ? Type.SelectedIndex : Global.Settings.Server.Type;
{
Global.Settings.Server.Type = _loaded ? Type.SelectedIndex : Global.Settings.Server.Type;
if (Type.SelectedIndex != 2)
{
JavaPathBox_A.Visibility = Visibility.Collapsed;
JavaPathBox_B.Visibility = Visibility.Collapsed;
}
else
{
JavaPathBox_A.Visibility = Visibility.Visible;
JavaPathBox_B.Visibility = Visibility.Visible;
}
}

private void InputEncoding_SelectionChanged(object sender, SelectionChangedEventArgs e)
=> Global.Settings.Server.InputEncoding = _loaded ? InputEncoding.SelectedIndex : Global.Settings.Server.InputEncoding;
private void OutputEncoding_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand All @@ -75,5 +90,20 @@ private void Select_Click(object sender, RoutedEventArgs e)
if (Catalog.Server.Plugins != null) { Catalog.Server.Plugins.Load(); }
}
}

private void SelectJava_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new()
{
InitialDirectory = !string.IsNullOrEmpty(Global.Settings.Server.Path) && File.Exists(Global.Settings.Server.Path) ? Global.Settings.Server.Path : Global.PATH,
Filter = "java.exe | java.exe"
};
if (dialog.ShowDialog() ?? false)
{
JavaSEPath.Text = dialog.FileName;
Global.Settings.Server.JavaPath = dialog.FileName;
if (Catalog.Server.Plugins != null) { Catalog.Server.Plugins.Load(); }
}
}
}
}

0 comments on commit cc16cf1

Please sign in to comment.