Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
dev: Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
luojunyuan committed Feb 25, 2022
1 parent 4e291ac commit 69bc4e4
Show file tree
Hide file tree
Showing 52 changed files with 570 additions and 169 deletions.
10 changes: 0 additions & 10 deletions ErogeHelper.Model/DataServices/Interface/IWindowDataService.cs

This file was deleted.

10 changes: 0 additions & 10 deletions ErogeHelper.Model/DataServices/WindowDataService.cs

This file was deleted.

2 changes: 1 addition & 1 deletion ErogeHelper.Model/ErogeHelper.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="System.Speech" Version="6.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
<PackageReference Include="Vanara.PInvoke.NetListMgr" Version="3.3.15" />
<PackageReference Include="Vanara.PInvoke.User32" Version="3.3.15" />
<PackageReference Include="HMBSbige.UpdateChecker" Version="6.0.1" />
<PackageReference Include="Vanara.PInvoke.WinINet" Version="3.3.15" />
<PackageReference Include="WanaKana-net" Version="1.0.0" />
</ItemGroup>

Expand Down
10 changes: 6 additions & 4 deletions ErogeHelper.Model/Repositories/GameInfoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
using Dapper.Contrib.Extensions;
using ErogeHelper.Model.DataModel.Tables;
using ErogeHelper.Model.Repositories.Interface;
using ErogeHelper.Model.Services.Interface;
using Microsoft.Data.Sqlite;

namespace ErogeHelper.Model.Repositories;

public class GameInfoRepository : IGameInfoRepository
{
private readonly string _connectString;
private string GameMd5 = string.Empty;
private GameInfoTable? _gameInfo;
private string GameMd5 => _gameDataService.Md5;

public GameInfoRepository(string connectString)
private readonly IGameDataService _gameDataService;

public GameInfoRepository(string connectString, IGameDataService? gameDataService = null)
{
_connectString = connectString;
_gameDataService = gameDataService ?? Shared.DependencyResolver.GetService<IGameDataService>();
}

public void InitGameMd5(string md5) => GameMd5 = md5;

private IDbConnection GetOpenConnection()
{
var connection = new SqliteConnection(_connectString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace ErogeHelper.Model.Repositories.Interface;

public interface IGameInfoRepository
{
public void InitGameMd5(string md5);

public GameInfoTable GameInfo { get; }

public GameInfoTable? TryGetGameInfo();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;
using System.Reactive.Subjects;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Services.Interface;
using ErogeHelper.Shared;
using ErogeHelper.Shared.Contracts;
using Splat;
Expand Down
3 changes: 0 additions & 3 deletions ErogeHelper.Model/Services/GameWindowHooker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Reactive.Concurrency;
using System.Reactive.Subjects;
using System.Runtime.InteropServices;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Services.Interface;
using ErogeHelper.Shared;
using ErogeHelper.Shared.Contracts;
Expand Down Expand Up @@ -67,8 +66,6 @@ public void SetupGameWindowHook(Process process, IGameDataService? gameDataServi

_gameProc.Exited += (_, _) =>
{
// Do cloud save check

mainScheduler.Schedule(() => _gamePositionSubj.OnNext(HiddenPos));
if (ModeDetector.InUnitTestRunner())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
using System.Reactive.Subjects;
using Vanara.PInvoke;

namespace ErogeHelper.Model.DataServices.Interface;
namespace ErogeHelper.Model.Services.Interface;

/// <summary>
/// In memory data store
/// </summary>
public interface IGameDataService : IDisposable
{
void InitGameMd5AndPath(string md5, string gamePath);
Expand Down
1 change: 0 additions & 1 deletion ErogeHelper.Model/Services/Interface/IGameWindowHooker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using System.Reactive.Concurrency;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Shared.Enums;
using ErogeHelper.Shared.Structs;

Expand Down
5 changes: 5 additions & 0 deletions ErogeHelper.Model/Services/Interface/ISavedataSyncService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace ErogeHelper.Model.Services.Interface;

public interface ISavedataSyncService
{
}
3 changes: 1 addition & 2 deletions ErogeHelper.Model/Services/Interface/ITextractorService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Shared.Entities;
using ErogeHelper.Shared.Entities;
using ErogeHelper.Shared.Structs;

namespace ErogeHelper.Model.Services.Interface;
Expand Down
1 change: 0 additions & 1 deletion ErogeHelper.Model/Services/MeCabService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public MeCabService(IEHConfigRepository? ehConfigRepository = null)
_configRepository = ehConfigRepository ?? DependencyResolver.GetService<IEHConfigRepository>();

CanLoadMeCab = Directory.Exists(EHContext.MeCabDicFolder);

if (_configRepository.EnableMeCab)
{
if (CanLoadMeCab)
Expand Down
25 changes: 9 additions & 16 deletions ErogeHelper.Model/Services/SavedataSyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ErogeHelper.Model.Repositories.Interface;
using ErogeHelper.Model.Services.Interface;

namespace ErogeHelper.Model.Services;

internal class SavedataSyncService
public class SavedataSyncService : ISavedataSyncService
{
//private readonly IGameDataService _gameDataService;
//private readonly IEhDbRepository _ehDbRepository;
//private readonly IEhConfigRepository _ehConfigDataService;
//private readonly INetworkListManager _networkListManager;
//private bool IsNetConnected => _networkListManager.IsConnectedToInternet;
Expand All @@ -21,20 +21,13 @@ internal class SavedataSyncService
// _ehConfigDataService.ExternalSharedDrivePath, ConstantValues.EhCloudDbFilename);

//public string[] ExcludeFiles { get; }
private readonly IGameInfoRepository _gameInfoRepository;

//public SavedataSyncService(
// IGameDataService? gameDataService = null,
// IEhDbRepository? ehDbRepository = null,
// IEhConfigRepository? ehConfigDataService = null,
// INetworkListManager? networkListManager = null)
//{
// _gameDataService = gameDataService ?? DependencyInject.GetService<IGameDataService>();
// _ehDbRepository = ehDbRepository ?? DependencyInject.GetService<IEhDbRepository>();
// _ehConfigDataService = ehConfigDataService ?? DependencyInject.GetService<IEhConfigRepository>();
// _networkListManager = networkListManager ?? DependencyInject.GetService<INetworkListManager>();

// ExcludeFiles = GetCurrentGameData()?.ExcludeFiles ?? Array.Empty<string>();
//}
public SavedataSyncService(
IGameInfoRepository? gameInfoRepository = null)
{
_gameInfoRepository = gameInfoRepository ?? Shared.DependencyResolver.GetService<IGameInfoRepository>();
}

//public void InitGameData()
//{
Expand Down
11 changes: 0 additions & 11 deletions ErogeHelper.Model/Services/TTSService.cs

This file was deleted.

1 change: 0 additions & 1 deletion ErogeHelper.Model/Services/TextractorCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Reactive.Subjects;
using System.Text;
using System.Text.RegularExpressions;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Services.Interface;
using ErogeHelper.Shared.Entities;
using ErogeHelper.Shared.Structs;
Expand Down
1 change: 0 additions & 1 deletion ErogeHelper.Model/Services/TextractorHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Diagnostics;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Services.Function;
using ErogeHelper.Model.Services.Interface;
using ErogeHelper.Shared.Contracts;
Expand Down
1 change: 0 additions & 1 deletion ErogeHelper.Model/Services/TouchConversionHooker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Drawing;
using System.Reactive.Linq;
using System.Runtime.InteropServices;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Repositories.Interface;
using ErogeHelper.Model.Services.Interface;
using ErogeHelper.Shared;
Expand Down
7 changes: 3 additions & 4 deletions ErogeHelper.ProcessSelector.WinUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
mc:Ignorable="d">

<StackPanel Margin="20 10">
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="resx:Strings.SelectProcess_Tips" />
<!--<GroupItem Margin="0,20,0,0" Header="{x:Static resx:Strings.SelectProcess_Label}">-->
<TextBlock x:Name="Tips" FontSize="18" TextWrapping="Wrap" />
<TextBlock x:Name="Label" Margin="0 20 0 0" FontSize="22" />

<StackPanel Margin="0 20 0 0" Spacing="10">
<StackPanel Orientation="Horizontal" Spacing="10">
Expand All @@ -35,8 +35,7 @@

<Button x:Name="InjectButton"
Width="240"
Click="InjectButtonOnClick" Content="resx:Strings.SelectProcess_InjectButton"
IsEnabled="False"
Click="InjectButtonOnClick" IsEnabled="False"
Style="{StaticResource AccentButtonStyle}" />
</StackPanel>
</StackPanel>
Expand Down
11 changes: 8 additions & 3 deletions ErogeHelper.ProcessSelector.WinUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace ErogeHelper.ProcessSelector.WinUI;
/// </summary>
public sealed partial class MainWindow : Window
{
private const double DefaultWidth = 400;
private const double DefaultHeight = 250;
private const double DefaultWidth = 415;
private const double DefaultHeight = 295;

private readonly FilterProcessService _filterProcessService;
private readonly ObservableCollection<ProcessDataModel> _processes = new();
Expand All @@ -25,14 +25,19 @@ public MainWindow()
{
InitializeComponent();
InitializeProperties();
//this.SetIsAlwaysOnTop(true);

_filterProcessService = new FilterProcessService();
ProcessComboBox.ItemsSource = _processes;
}

private void InitializeProperties()
{
Title = "Process Selector";
Title = Shared.Languages.Strings.SelectProcess_Title;
Tips.Text = Shared.Languages.Strings.SelectProcess_Tips;
Label.Text = Shared.Languages.Strings.SelectProcess_Label;
InjectButton.Content = Shared.Languages.Strings.SelectProcess_InjectButton;

this.CenterOnScreen(DefaultWidth, DefaultHeight);
HwndExtensions.SetWindowStyle(
this.GetWindowHandle(),
Expand Down
2 changes: 1 addition & 1 deletion ErogeHelper.ProcessSelector/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public MainWindow()

InjectButton.IsEnabled = false;

Task.Run(RefreshProcesses);
Loaded += (_, _) => Task.Run(RefreshProcesses);
}

// UPSTREAM: ToolTip bugged with.Net 6
Expand Down
2 changes: 1 addition & 1 deletion ErogeHelper.Shared/Languages/Strings.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@
<value>提示:没有打开日文文本或者任意一个翻译功能</value>
</data>
<data name="Developing" xml:space="preserve">
<value>开发中。。。</value>
<value>施工中。。。</value>
</data>
<data name="TTSPage.Title" xml:space="preserve">
<value>语音合成</value>
Expand Down
8 changes: 3 additions & 5 deletions ErogeHelper.ViewModel/CloudSave/CloudSaveViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Reactive;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Repositories.Interface;
using ErogeHelper.Shared;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Vanara.PInvoke.NetListMgr;
using System.Reactive.Linq;
using ErogeHelper.Shared.Contracts;
using Vanara.PInvoke;
using ErogeHelper.Model.Services.Interface;

namespace ErogeHelper.ViewModel.CloudSave;

Expand All @@ -21,18 +21,16 @@ public class CloudSaveViewModel : ReactiveObject
public CloudSaveViewModel(
IGameInfoRepository? gameInfoRepository = null,
IEHConfigRepository? ehConfigRepository = null,
INetworkListManager? networkListManager = null,
IGameDataService? gameDataService = null)
{
gameInfoRepository ??= DependencyResolver.GetService<IGameInfoRepository>();
ehConfigRepository ??= DependencyResolver.GetService<IEHConfigRepository>();
networkListManager ??= DependencyResolver.GetService<INetworkListManager>();
gameDataService ??= DependencyResolver.GetService<IGameDataService>();

UNCDatabasePath = ehConfigRepository.ExternalSharedDrivePath;
GameSavedataPath = gameInfoRepository.GameInfo.SaveDataPath;
// TODO: How about folder not exist
ShowNoInternet = networkListManager.IsConnectedToInternet;
ShowNoInternet = WinINet.InternetGetConnectedState(out _);
CanEnable = ShowNoInternet && UNCDatabasePath != string.Empty && GameSavedataPath != string.Empty;
IsSwitchOn = gameInfoRepository.GameInfo.UseCloudSave;

Expand Down
2 changes: 1 addition & 1 deletion ErogeHelper.ViewModel/HookConfig/HCodeViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reactive;
using System.Reactive.Linq;
using System.Text.RegularExpressions;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Repositories.Interface;
using ErogeHelper.Model.Services.Interface;
using ErogeHelper.Shared;
using ErogeHelper.Shared.Contracts;
using ErogeHelper.Shared.Languages;
Expand Down
1 change: 0 additions & 1 deletion ErogeHelper.ViewModel/HookConfig/HookViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Text.Json;
using DynamicData;
using DynamicData.Binding;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Repositories.Interface;
using ErogeHelper.Model.Services.Interface;
using ErogeHelper.Shared;
Expand Down
2 changes: 1 addition & 1 deletion ErogeHelper.ViewModel/HookConfig/ReiPatcherTipViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.Reactive;
using System.Reactive.Linq;
using Config.Net;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Repositories.Interface;
using ErogeHelper.Model.Services.Interface;
using ErogeHelper.Shared;
using ErogeHelper.Shared.Languages;
using ReactiveUI;
Expand Down
2 changes: 1 addition & 1 deletion ErogeHelper.ViewModel/HwndTools.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Runtime.InteropServices;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Services.Interface;
using ErogeHelper.Shared;
using Vanara.PInvoke;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using ErogeHelper.Model.DataServices.Interface;
using ErogeHelper.Model.Repositories.Interface;
using ErogeHelper.Model.Services.Interface;
using ErogeHelper.Shared;
Expand All @@ -20,11 +19,9 @@ public class MenuGameViewModel : ReactiveObject
public MenuGameViewModel(
ITouchConversionHooker? touchConversionHooker = null,
IGameInfoRepository? gameInfoRepository = null,
IWindowDataService? windowDataService = null,
IGameDataService? gameDataService = null)
{
gameDataService ??= DependencyResolver.GetService<IGameDataService>();
windowDataService ??= DependencyResolver.GetService<IWindowDataService>();
gameInfoRepository ??= DependencyResolver.GetService<IGameInfoRepository>();
touchConversionHooker ??= DependencyResolver.GetService<ITouchConversionHooker>();
var disposables = new CompositeDisposable();
Expand Down Expand Up @@ -68,7 +65,7 @@ public MenuGameViewModel(
{
Interactions.MessageBoxConfirm.Handle(Strings.AssistiveTouch_LoseFocusWarn).Subscribe();
}
HwndTools.WindowLostFocus(windowDataService.MainWindowHandle, v);
HwndTools.WindowLostFocus(MainGameViewModel.MainGameWindowHandle, v);
HwndTools.WindowLostFocus(TextViewModel.TextWindowHandle, v);
gameInfoRepository.UpdateLostFocusStatus(v);
});
Expand Down
Loading

0 comments on commit 69bc4e4

Please sign in to comment.