Skip to content

Commit

Permalink
update:代码清理和版本号更改
Browse files Browse the repository at this point in the history
  • Loading branch information
zkhssb committed Apr 3, 2023
1 parent d0c0064 commit 9f409dc
Show file tree
Hide file tree
Showing 29 changed files with 68 additions and 235 deletions.
17 changes: 9 additions & 8 deletions NectarRCON/App.xaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<Application
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
<Application
x:Class="NectarRCON.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:NectarRCON" xmlns:sys="clr-namespace:System;assembly=netstandard"
Startup="OnStartup"
Exit="OnExit">
xmlns:local="clr-namespace:NectarRCON"
xmlns:sys="clr-namespace:System;assembly=netstandard"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Exit="OnExit"
Startup="OnStartup">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemesDictionary Theme="Dark"/>
<ui:ThemesDictionary Theme="Dark" />
<ui:ControlsDictionary />
<ResourceDictionary Source="pack://application:,,,/NectarRCON;component/Resources/Languages/zh_cn.xaml"/>
<ResourceDictionary Source="pack://application:,,,/NectarRCON;component/Resources/Languages/zh_cn.xaml" />
<ResourceDictionary>
<sys:String x:Key="app.version">1.0.0</sys:String>
<sys:String x:Key="app.version">1.0.0-beta1</sys:String>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Expand Down
5 changes: 1 addition & 4 deletions NectarRCON/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NectarRCON.Interfaces;
using NectarRCON.Services;
using NectarRCON.ViewModels;
using NectarRCON.Views.Pages;
using NectarRCON.Windows;
using System.IO;
using System.Reflection;
using System.Windows;
using Wpf.Ui.Mvvm.Contracts;
using Wpf.Ui.Mvvm.Services;
Expand Down
5 changes: 0 additions & 5 deletions NectarRCON/Interfaces/ILogService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using NectarRCON.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NectarRCON.Interfaces;
public interface ILogService
Expand Down
3 changes: 1 addition & 2 deletions NectarRCON/Interfaces/IRconConnectService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using NectarRCON.Models;
using System;
using System.Threading.Tasks;

namespace NectarRCON.Interfaces;
public delegate void MessageEvent(ServerInformation information,string message);
public delegate void MessageEvent(ServerInformation information, string message);
public delegate void EventEvent(ServerInformation information);
public delegate void ClosedEvent(ServerInformation information);
public interface IRconConnectService
Expand Down
5 changes: 0 additions & 5 deletions NectarRCON/Interfaces/IServerPasswordService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using NectarRCON.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NectarRCON.Interfaces;
public interface IServerPasswordService
Expand Down
4 changes: 1 addition & 3 deletions NectarRCON/NectarRCON.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>1.0.0-beta1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -35,9 +36,6 @@
<Page Update="Resources\Languages\en_us.xaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page>
<Page Update="Resources\Languages\zh_cn.xaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page>
</ItemGroup>

</Project>
Binary file removed NectarRCON/Resources/Languages/zh_cn.zip
Binary file not shown.
11 changes: 4 additions & 7 deletions NectarRCON/Services/ApplicationHostService.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting;
using NectarRCON.Helper;
using NectarRCON.Interfaces;
using NectarRCON.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Wpf.Ui.Mvvm.Contracts;

namespace NectarRCON.Services;
public class ApplicationHostService: IHostedService
public class ApplicationHostService : IHostedService
{
private readonly IServiceProvider _serviceProvider;
private readonly INavigationService _navigationService;
Expand Down Expand Up @@ -54,7 +51,7 @@ private void LoadConfig()
default:
break;
}
if(_configService.GetConfig().LanguageName == string.Empty)
if (_configService.GetConfig().LanguageName == string.Empty)
{
_languageService.SelectLanguage();
_configService.GetConfig().LanguageName = _languageService.GetKey("file.language");
Expand All @@ -74,7 +71,7 @@ private async Task HandleActivationAsync()
_navigationWindow = (_serviceProvider.GetService(typeof(INavigationWindow)) as INavigationWindow)!;
_navigationWindow!.ShowWindow();
}

LoadConfig();

await Task.CompletedTask;
Expand Down
9 changes: 5 additions & 4 deletions NectarRCON/Services/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public ConfigService(ILanguageService languageService)
_config = JsonSerializer.Deserialize<Config>(File.ReadAllText("./config.json"))
?? new Config();
}
catch(Exception ex)
catch (Exception ex)
{
var resutl = MessageBox.Show(_languageService.GetKey(ex.GetType() == typeof(JsonException)? "text.config.json_error" : "text.config.error")
var resutl = MessageBox.Show(_languageService.GetKey(ex.GetType() == typeof(JsonException) ? "text.config.json_error" : "text.config.error")
.Replace("%s", ex.Message), _languageService.GetKey("text.error"), MessageBoxButton.YesNo, MessageBoxImage.Error);
if(resutl == MessageBoxResult.Yes)
if (resutl == MessageBoxResult.Yes)
{
_config = new();
Save();
Expand All @@ -42,7 +42,8 @@ public void Save()
try
{
File.WriteAllText("./config.json", JsonSerializer.Serialize(_config));
}catch(Exception ex)
}
catch (Exception ex)
{
MessageBox.Show(_languageService.GetKey("text.config.save_error")
.Replace("%s", ex.Message), _languageService.GetKey("text.error"), MessageBoxButton.OK, MessageBoxImage.Error);
Expand Down
21 changes: 9 additions & 12 deletions NectarRCON/Services/LanguageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Markup;
using System.Xaml;

namespace NectarRCON.Services;
public class LanguageService : ILanguageService
{
private readonly Dictionary<string, string> _defaultLanguages = new ();
private readonly Dictionary<string, string> _defaultLanguages = new();
private Dictionary<string, ResourceDictionary> _languages = new();
private ResourceDictionary _selectedLanguage = new ResourceDictionary()
{
Expand All @@ -33,7 +30,7 @@ public Dictionary<string, ResourceDictionary> Languages
{
get => _languages;
}
public Dictionary<string, ResourceDictionary> GetLanguages()
public Dictionary<string, ResourceDictionary> GetLanguages()
=> Languages;
public ResourceDictionary GetSelectedLanguage()
{
Expand All @@ -44,11 +41,11 @@ public void Refresh()
_languages.Clear();
// 从本地目录获取xaml
string[] files = new string[0];
if(Directory.Exists("./languages/"))
if (Directory.Exists("./languages/"))
files = Directory.GetFiles("./languages/");
foreach(string file in files)
foreach (string file in files)
{
if(Path.GetExtension(file).ToLower() == ".xaml" || Path.GetExtension(file).ToLower() == ".xml")
if (Path.GetExtension(file).ToLower() == ".xaml" || Path.GetExtension(file).ToLower() == ".xml")
{
ResourceDictionary resourceDictionary = new ResourceDictionary();
using (FileStream fs = File.OpenRead(file))
Expand All @@ -61,11 +58,11 @@ public void Refresh()
// 从内部文件加载
_defaultLanguages.Add("zh_cn", "pack://application:,,,/NectarRCON;component/Resources/Languages/zh_cn.xaml");
_defaultLanguages.Add("en_us", "pack://application:,,,/NectarRCON;component/Resources/Languages/en_us.xaml");
foreach(KeyValuePair<string, string> language in _defaultLanguages)
foreach (KeyValuePair<string, string> language in _defaultLanguages)
{
if(_languages.ContainsKey(language.Key))
if (_languages.ContainsKey(language.Key))
_languages.Remove(language.Key);
Languages.Add(language.Key , new ResourceDictionary()
Languages.Add(language.Key, new ResourceDictionary()
{
Source = new Uri(language.Value, UriKind.RelativeOrAbsolute)
});
Expand All @@ -92,7 +89,7 @@ public void SelectLanguage(string languageName, bool name = false)
return l.Key.ToLower() == languageName.ToLower();
}
}).FirstOrDefault();
if(null == language.Value)
if (null == language.Value)
{
_selectedLanguage = new ResourceDictionary()
{
Expand Down
5 changes: 1 addition & 4 deletions NectarRCON/Services/LogService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using NectarRCON.Interfaces;
using NectarRCON.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;

namespace NectarRCON.Services;
public class LogService : ILogService
Expand All @@ -24,7 +21,7 @@ public void Clear()
}
public string GetText()
{
using(MemoryStream ms = new MemoryStream())
using (MemoryStream ms = new MemoryStream())
{
_logFileStream?.CopyTo(ms);
return Encoding.UTF8.GetString(ms.ToArray());
Expand Down
10 changes: 4 additions & 6 deletions NectarRCON/Services/RconConnectService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using NectarRCON.Interfaces;
using CoreRCON;
using NectarRCON.Interfaces;
using NectarRCON.Models;
using CoreRCON;
using System.Threading.Tasks;
using System.Net;
using System;
using System.Net;
using System.Threading.Tasks;
using System.Windows;
using Wpf.Ui.Mvvm.Contracts;
using Wpf.Ui.Controls.Interfaces;

namespace NectarRCON.Services;
public class RconConnectService : IRconConnectService
Expand Down
12 changes: 7 additions & 5 deletions NectarRCON/Services/ServerInformationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ServerInformationService : IServerInformationService
{
private readonly ILanguageService _languageService;
private List<ServerInformation> _servers = new();
public List<ServerInformation> Servers
public List<ServerInformation> Servers
=> _servers;
public ServerInformationService(ILanguageService languageService)
{
Expand All @@ -26,16 +26,17 @@ public ServerInformationService(ILanguageService languageService)
_servers = JsonSerializer.Deserialize<List<ServerInformation>>(jsonString)
?? new List<ServerInformation>();
}
catch(JsonException ex)
catch (JsonException ex)
{
MessageBoxResult result = MessageBox.Show(_languageService.GetKey("text.server_information.error.json_error")
.Replace("%s", ex.Message)
.Replace("\\n","\n"), _languageService.GetKey("text.error"), MessageBoxButton.OKCancel, MessageBoxImage.Error);
.Replace("\\n", "\n"), _languageService.GetKey("text.error"), MessageBoxButton.OKCancel, MessageBoxImage.Error);
if (result == MessageBoxResult.OK)
File.WriteAllText("./servers.json", "[]");
else
Process.GetCurrentProcess().Kill();
}catch(Exception ex)
}
catch (Exception ex)
{
MessageBox.Show(_languageService.GetKey("text.server_information.error.text")
.Replace("%s", ex.Message)
Expand Down Expand Up @@ -68,7 +69,8 @@ public void Save()
try
{
File.WriteAllText("./servers.json", JsonSerializer.Serialize(_servers));
}catch(Exception ex)
}
catch (Exception ex)
{
MessageBox.Show(_languageService.GetKey("text.server_information.error.save")
.Replace("%s", ex.Message)
Expand Down
8 changes: 1 addition & 7 deletions NectarRCON/ViewModels/AboutPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NectarRCON.ViewModels
namespace NectarRCON.ViewModels
{
class AboutPageViewModel
{
Expand Down
4 changes: 2 additions & 2 deletions NectarRCON/ViewModels/AddServerWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Windows;

namespace NectarRCON.ViewModels;
public partial class AddServerWindowViewModel:ObservableObject
public partial class AddServerWindowViewModel : ObservableObject
{
private readonly IServerInformationService _serverInformationService;
private readonly ILanguageService _languageService;
Expand All @@ -29,7 +29,7 @@ public void SetWindow(AddServerWindow window)
[RelayCommand]
public void Ok()
{
if(string.IsNullOrWhiteSpace(_serverName) || string.IsNullOrWhiteSpace(_serverAddress))
if (string.IsNullOrWhiteSpace(_serverName) || string.IsNullOrWhiteSpace(_serverAddress))
{
MessageBox.Show(_languageService.GetKey("ui.add_server_window.null_text"), _languageService.GetKey("text.error"), MessageBoxButton.OK, MessageBoxImage.Error);
return;
Expand Down
9 changes: 3 additions & 6 deletions NectarRCON/ViewModels/EditPasswordWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
using CommunityToolkit.Mvvm.Input;
using NectarRCON.Interfaces;
using NectarRCON.Models;
using NectarRCON.Services;
using NectarRCON.Windows;
using System.Windows;
using Wpf.Ui.Controls;

namespace NectarRCON.ViewModels;
public partial class EditPasswordWindowViewModel:ObservableObject
public partial class EditPasswordWindowViewModel : ObservableObject
{
private readonly IServerPasswordService _serverPasswordService;
private readonly ServerInformation _serverInformation;
Expand All @@ -23,7 +20,7 @@ public EditPasswordWindowViewModel()
_serverPasswordService = App.GetService<IServerPasswordService>();
_serverInformation = _serverPasswordService.GetSelect()!;
var password = _serverPasswordService.Get(_serverInformation);
if(password != null)
if (password != null)
{
Password = password.Password;
IsEmpty = string.IsNullOrEmpty(Password);
Expand All @@ -36,7 +33,7 @@ public EditPasswordWindowViewModel()
}
public void SetWindow(EditPasswordWindow window)
{
_window= window;
_window = window;
}
[RelayCommand]
public void TextChange()
Expand Down
5 changes: 0 additions & 5 deletions NectarRCON/ViewModels/EditServerWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
using CommunityToolkit.Mvvm.Input;
using NectarRCON.Interfaces;
using NectarRCON.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Wpf.Ui.Controls;
using MessageBox = System.Windows.MessageBox;
Expand Down
8 changes: 0 additions & 8 deletions NectarRCON/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using NectarRCON.Interfaces;
using NectarRCON.Models;
using NectarRCON.Services;
using NectarRCON.Views.Pages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Wpf.Ui.Controls;
using Wpf.Ui.Mvvm.Contracts;
using MessageBox = System.Windows.MessageBox;
using TextBox = Wpf.Ui.Controls.TextBox;
Expand Down
Loading

0 comments on commit 9f409dc

Please sign in to comment.