Skip to content

Commit

Permalink
Ver 0.10.1-RC1: Fix bugs
Browse files Browse the repository at this point in the history
bugs which cause the button didn't disable it self as expected.
  • Loading branch information
Shiroiame-Kusu committed Dec 23, 2023
1 parent 97d7939 commit 8ea29f2
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 32 deletions.
38 changes: 19 additions & 19 deletions Serein/Universal/Core/Server/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
using System.Diagnostics;
using System.IO;
using System.Text;
using RegExp = System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Documents;
using System.Windows.Controls;
using RegExp = System.Text.RegularExpressions;

namespace Serein.Core.Server
{
Expand Down Expand Up @@ -97,8 +95,8 @@ internal static class ServerManager
public static string? JEStartMaxRam { get; set; }
public static string? JavaVersion { get; set; }
public static int? JavaVersionNumber { get; set; }
public static bool AbleToUse_incubator_vector { get; set;}
public static string? Use_incubator_vector {get; set;}
public static bool AbleToUse_incubator_vector { get; set; }
public static string? Use_incubator_vector { get; set; }
public static bool? StartResult;

/// <summary>
Expand Down Expand Up @@ -169,28 +167,29 @@ public static bool Start(bool quiet)
Logger.Output(LogType.Server_Clear);
#endif
Logger.Output(LogType.Server_Notice, "启动中");

string ServerType = Global.Settings.Server.Path.Substring(Global.Settings.Server.Path.Length - 3);
if(string.IsNullOrEmpty(Global.Settings.Server.MaxRAM))
{
if (string.IsNullOrEmpty(Global.Settings.Server.MaxRAM))
{
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
float AvailableRAM = ramCounter.NextValue();
double AutoSetRAM = Math.Round(AvailableRAM * 0.8, 0);
Global.Settings.Server.MaxRAM = AutoSetRAM.ToString();
JEStartMaxRam = Global.Settings.Server.MaxRAM;
Logger.MsgBox("未设置最大内存\n已自动为您设置启动内存为 " + JEStartMaxRam + "M", "Serein", 0, 48);

}
else
{
JEStartMaxRam = Global.Settings.Server.MaxRAM;
}
string? JavaPathSettings = Global.Settings.Server.JavaPath;
if (string.IsNullOrEmpty(JavaPathSettings) == true){
if (string.IsNullOrEmpty(JavaPathSettings) == true)
{
CurrentJavaPath = "java";
}
else
{
{
CurrentJavaPath = Global.Settings.Server.JavaPath;
}
try
Expand All @@ -205,13 +204,13 @@ public static bool Start(bool quiet)
Process? pr = Process.Start(defaultJava);
JavaVersion = pr?.StandardError?.ReadLine()?.Split(' ')[2].Replace("\"", "");
JavaVersionNumber = int.Parse(JavaVersion?.Substring(0, 2));

Check warning on line 206 in Serein/Universal/Core/Server/ServerManager.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.

Check warning on line 206 in Serein/Universal/Core/Server/ServerManager.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.

}
catch (Exception ex)
{
Console.WriteLine("Exception is " + ex.Message);
}
if(JavaVersionNumber == 16 || JavaVersionNumber == 17 || JavaVersionNumber == 18 || JavaVersionNumber == 19)
if (JavaVersionNumber == 16 || JavaVersionNumber == 17 || JavaVersionNumber == 18 || JavaVersionNumber == 19)
{
AbleToUse_incubator_vector = true;
Use_incubator_vector = " --add-modules=jdk.incubator.vector";
Expand Down Expand Up @@ -251,7 +250,7 @@ public static bool Start(bool quiet)
{
JEOptimizationArguments = Use_incubator_vector;
}

ProcessStartInfo ServerStartInfo = new ProcessStartInfo(Global.Settings.Server.Path)
{

Expand Down Expand Up @@ -280,10 +279,10 @@ public static bool Start(bool quiet)
StandardOutputEncoding = _encodings[Global.Settings.Server.OutputEncoding],
WorkingDirectory = Path.GetDirectoryName(Global.Settings.Server.Path)
};

StartInfo = ServerStartInfo;
}

_serverProcess = Process.Start(StartInfo);
_serverProcess!.EnableRaisingEvents = true;
_serverProcess.Exited += (_, _) => CloseAll();
Expand All @@ -306,7 +305,8 @@ public static bool Start(bool quiet)
Difficulty = string.Empty;
_tempLine = string.Empty;
CommandHistory.Clear();
StartFileName = Path.GetFileName(Global.Settings.Server.Path);
//StartFileName = Path.GetFileName(Global.Settings.Server.Path);
StartFileName = ServerType == "jar" ? Path.GetFullPath(Global.Settings.Server.Path) : Path.GetFileName(Global.Settings.Server.Path);
_prevProcessCpuTime = TimeSpan.Zero;
#endregion

Expand All @@ -322,8 +322,8 @@ public static bool Start(bool quiet)
return false;
}
public static void MainProcess()
{
{

}
/// <summary>
/// 关闭服务器
Expand Down
5 changes: 2 additions & 3 deletions Serein/Universal/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ internal static class Global
/// <summary>
/// 版本号
/// </summary>
public const string VERSION = "v0.10.0-RC1";
public const string VERSION = "v0.10.1-RC1";
//public static readonly string VERSION = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion.ToString();

/// <summary>
/// 分支
/// </summary>
public const string BRANCH = "ReleaseCandidate";


//public static readonly Object[]? Shiroiame_Kusu = { };
/// <summary>
/// 类型
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Serein/Universal/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("0.10.0.1")]
[assembly: AssemblyFileVersion("0.10.0-RC1")]
[assembly: AssemblyVersion("0.10.1.1")]
[assembly: AssemblyFileVersion("0.10.1-RC1")]
6 changes: 3 additions & 3 deletions Serein/WPF/Windows/Pages/Function/Frp/Login.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Margin="20,0,20,10" Header="用户名" FontSize="12">
<TextBox Grid.Row="0" Margin="5" MinHeight="40" VerticalAlignment="Center" ToolTip="用户名" />
<TextBox Grid.Row="0" Margin="5" MinHeight="40" VerticalAlignment="Center" ToolTip="用户名" Name="Username"/>
</GroupBox>

<GroupBox Grid.Row="1" Margin="20,10" Header="密码" FontSize="12">
<TextBox Grid.Row="1" Margin="5" MinHeight="40" VerticalAlignment="Center" ToolTip="密码"/>
<TextBox Grid.Row="1" Margin="5" MinHeight="40" VerticalAlignment="Center" ToolTip="密码" Name="Password"/>
</GroupBox>

<ui:Button Grid.Row="2" Content="登录" Height="40" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<ui:Button Grid.Row="2" Content="登录" Height="40" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center" Name="_Login" Click="Login_Click"/>
</Grid>
<Grid Grid.Row="4">
<Grid.ColumnDefinitions>
Expand Down
33 changes: 32 additions & 1 deletion Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;
using Newtonsoft.Json.Linq;
using Serein.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -23,6 +27,7 @@ namespace Serein.Windows.Pages.Function.Frp
/// </summary>
public partial class Login : UiPage
{
private string token { get; set; }
public Login()

Check warning on line 31 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Non-nullable property 'token' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 31 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Non-nullable property 'token' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
InitializeComponent();
Expand All @@ -47,5 +52,31 @@ private void ForgetPassword_Navigate(object sender, RequestNavigateEventArgs e)
});
e.Handled = true;
}

private async void Login_Click(object sender, RoutedEventArgs e)
{
Username.IsEnabled = false;
Password.IsEnabled = false;
using var client = new HttpClient();
var result = await client.GetAsync("https://api.locyanfrp.cn/User/DoLogin?username=" + Username.Text + "&password=" + Password.Text);

JObject? ParsedResult = JObject.Parse(result.Content.ReadAsStringAsync().ToString());

Check warning on line 63 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 'json' in 'JObject JObject.Parse(string json)'.
if(result.StatusCode.ToString() == "200")
{
if(ParsedResult["status"].ToString() == "0")

Check warning on line 66 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.
{
token = ParsedResult["token"].ToString();

Check warning on line 68 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.
}
else
{
Logger.MsgBox("Serein", ParsedResult["message"].ToString(), 0, 48);

Check warning on line 72 in Serein/WPF/Windows/Pages/Function/Frp/Login.xaml.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.
}
}
else
{
Logger.MsgBox("Serein", "请检查您的网络连接", 0, 48);
}

}
}
}
16 changes: 12 additions & 4 deletions Serein/WPF/Windows/Pages/Server/Download.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ private async void ServerDownload(object sender, RoutedEventArgs e)
ServerPath = AppDomain.CurrentDomain.BaseDirectory + "Serein-Server";
}
DownloadButton.IsEnabled = false;
Refresh.IsEnabled = false;
ServerDownloadName.IsEnabled = false;
ServerDownloadVersion.IsEnabled = false;
var ServerName = ServerDownloadName.SelectedItem.ToString();
var ServerVersion = ServerDownloadVersion.SelectedItem.ToString();
CurrentServerPath = ServerPath + "\\" + ServerName + "\\" + ServerVersion;
Expand Down Expand Up @@ -111,15 +114,19 @@ private async void ServerDownload(object sender, RoutedEventArgs e)
Logger.MsgBox("下载失败", "Serein", 0, 48);
}

if (AutoSetupPath.IsChecked == true)
if ((bool)AutoSetupPath.IsChecked)
{
Global.Settings.Server.Path = CurrentServerPath + "\\server.jar";
}
try
{
if (isDownloadFinished)
{
Refresh.IsEnabled = true;
DownloadButton.IsEnabled = true;

ServerDownloadVersion.IsEnabled = true;
ServerDownloadName.IsEnabled = true;
}
}catch
{
Expand Down Expand Up @@ -329,12 +336,13 @@ public bool DownloadFile(string URL, string filename)
DownloadProgressText.Dispatcher.Invoke(() =>
{
DownloadProgressText.Text = Math.Round((double)totalDownloadedByte / b / a, 2) + DownloadUnit + Math.Round((double)totalDownloadedByte / totalBytes * 100, 2).ToString() + "%";
});
if(totalDownloadedByte == totalBytes)
});
if (totalDownloadedByte == totalBytes)
{
break;
}
Thread.Sleep(1000);

Thread.Sleep(500);
}

Task.FromResult(0);
Expand Down

0 comments on commit 8ea29f2

Please sign in to comment.