Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pd233 committed Jan 3, 2024
1 parent c6554af commit a053bcb
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 48 deletions.
29 changes: 22 additions & 7 deletions src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,29 @@

</Button>

<InfoBar
x:Name="Bar">

</InfoBar>



</StackPanel>

<InfoBar
Grid.Row="0"
x:Name="Info"
HorizontalAlignment="Center"
VerticalAlignment="Bottom">

<InfoBar.Resources>

<Storyboard
x:Name="InfoBarPopInStoryboard">
<PopInThemeAnimation TargetName="Info"/>
</Storyboard>

<Storyboard
x:Name="InfoBarPopOutStoryboard">
<PopOutThemeAnimation TargetName="Info"/>
</Storyboard>

</InfoBar.Resources>

</InfoBar>

</Grid>
</Page>
120 changes: 82 additions & 38 deletions src/LipUI/Pages/HomePageModules/BdsPropertiesEditorPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using LipUI.Models;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.Devices.Radios;
using Windows.UI;
using Microsoft.UI.Xaml.Input;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Windows.System;
using Windows.UI;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand Down Expand Up @@ -54,50 +49,100 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
base.OnNavigatedTo(e);
}

private void ShowInfoBar(
string? title,
string? message,
InfoBarSeverity severity,
UIElement? barContent = null,
Action? completed = null)
{
var timer = DispatcherQueue.CreateTimer();
timer.Interval = TimeSpan.FromSeconds(2);
timer.Tick += (sender, e) =>
{
Info.IsOpen = false;
InfoBarPopOutStoryboard.Begin();
timer.Stop();
completed?.Invoke();
};

Info.Title = title;
Info.Message = message;
Info.Severity = severity;
Info.IsClosable = false;
Info.IsOpen = true;
Info.Content = barContent;

InfoBarPopInStoryboard.Begin();
timer.Start();
}

private async void Page_Loaded(object sender, RoutedEventArgs e)
{
if (Server is null)
{
var dialog = new ContentDialog()
{
XamlRoot = XamlRoot,
Content = "i18n.nullServerPath",
CloseButtonText = "OK"
};
await dialog.ShowAsync();
Frame.GoBack();
}
await Task.Delay(500);
ShowInfoBar("i18n.nullServerPath", null, InfoBarSeverity.Error, null, Frame.GoBack);
return;
};

Viewer.Content = new ProgressRing();
DispatcherQueue.TryEnqueue(LoadPropertiesAndCreateUI);
}

private async ValueTask SaveAsync()
{
if (BindingSettings.Count is 0)
return;
try
{
ShowInfoBar("i18n.save", null,
InfoBarSeverity.Informational,
new ProgressBar()
{
IsIndeterminate = true
});

var path = Path.Combine(Server!.WorkingDirectory, "server.properties");
var lines = await File.ReadAllLinesAsync(path);
if (BindingSettings.Count is not 0)
{
var path = Path.Combine(Server!.WorkingDirectory, "server.properties");
var lines = await File.ReadAllLinesAsync(path);

for (int i = 0; i < lines.Length; i++)
{
string? line = lines[i];
if (line.StartsWith('#') || string.IsNullOrWhiteSpace(line))
continue;
for (int i = 0; i < lines.Length; i++)
{
string? line = lines[i];
if (line.StartsWith('#') || string.IsNullOrWhiteSpace(line))
continue;

var key = line[..line.IndexOf('=')];
if (BindingSettings.TryGetValue(key, out var value))
lines[i] = $"{key}={value}";
}
var key = line[..line.IndexOf('=')];
if (BindingSettings.TryGetValue(key, out var value))
lines[i] = $"{key}={value}";
}

await File.WriteAllLinesAsync(path, lines);
await File.WriteAllLinesAsync(path, lines);
}

await Task.Delay(500);
ShowInfoBar("i18n.completed", null, InfoBarSeverity.Success);
}
catch (Exception ex)
{
ShowInfoBar("i18n.error", ex.Message, InfoBarSeverity.Error);
}
}

private async void LoadPropertiesAndCreateUI()
{
var path = Path.Combine(Server!.WorkingDirectory, "server.properties");
var lines = await File.ReadAllLinesAsync(path);
string[] lines;

try
{
lines = await File.ReadAllLinesAsync(path);
}
catch (Exception ex)
{
ShowInfoBar("i18n.failed", ex.Message, InfoBarSeverity.Error, null, Frame.GoBack);
return;
}

string? currentPropertiesLine, nextPropertiesLine = null;
var notes = new List<string>();
Expand Down Expand Up @@ -311,8 +356,7 @@ private async void Page_KeyDown(object sender, KeyRoutedEventArgs e)
return;
}

if (ctrlPressed && e.Key is VirtualKey.S)
await SaveAsync();
if (ctrlPressed && e.Key is VirtualKey.S) await SaveAsync();
}

private void Page_KeyUp(object sender, KeyRoutedEventArgs e)
Expand Down
1 change: 0 additions & 1 deletion src/LipUI/Pages/HomePageModules/ModulesPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using LipUI.Models;
using LipUI.VIews;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using System.Threading.Tasks;

// To learn more about WinUI, the WinUI project structure,
Expand Down
3 changes: 2 additions & 1 deletion src/LipUI/VIews/LipInstallerView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private async ValueTask<byte[]> DownloadLipPortable(InstallerInfo info)
using var client = new HttpClient(
new HttpClientHandler() { ClientCertificateOptions = ClientCertificateOption.Automatic })
{
Timeout = TimeSpan.FromSeconds(2),
DefaultRequestHeaders = { ExpectContinue = false }
};

Expand All @@ -89,7 +90,7 @@ private async ValueTask<byte[]> DownloadLipPortable(InstallerInfo info)
}
catch
{
response = await client.GetAsync($"https://mirror.ghproxy.com/{info.AssetUrl}");
response = await client.GetAsync($"https://github.moeyy.xyz/{info.AssetUrl}");
}

var input = await response.Content.ReadAsStreamAsync();
Expand Down
1 change: 0 additions & 1 deletion src/LipUI/VIews/ModuleIcon.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Net.Security;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand Down

0 comments on commit a053bcb

Please sign in to comment.