Skip to content

Commit

Permalink
[+] 정규표현식 검색 기능 정식 추가
Browse files Browse the repository at this point in the history
  ㄴ 메인 창 수동 검색 글자 옆에 정규 표현식 검색 체크박스 추가.
  ㄴ 정규표현식 검색 시 단어 전체가 아닌 단어 인덱스에서 검색이 수행되던 문제 수정
  ㄴ 정규표현식 검색 체크박스를 클릭 시, 검색 버튼을 클릭해도 검색 창이 초기화되지 않음. 이는 힘들게 적은 정규표현식을 날려버리지 않도록 하려는 조치임.

[/] 데이터베이스 검사 도중 발생하던 몇몇 오류 및 실수 수정
  ㄴ (SQLite 데이터베이스 한정) Vacuum 쿼리 수행 도중 StoredProcedure 관련 오류가 발생하던 현상 수정
  ㄴ (SQLite 데이터베이스 한정) 잘못된 단어 삭제 과정에서 트랜색션 속에 트랜잭션이 겹쳐서 발생하는 예외 수정
  ㄴ 잘못된 한방 단어 노드 검출 과정에서 이상한 행과 열을 검색하여 문제가 있는 노드들은 그대로 놔두고 멀쩡한 한방 단어 노드들을 날려버리던 문제 수정
  ㄴ 단어 테이블에서 수정된 오류 갯수가 총 수정된 오류 갯수에 집계되지 않던 문제 수정

[*] Win32InputSimulator를 NativeInputSimulator로 나누는 작업 완료
  -> 이제 컴파일 가능. 더 이상 컴파일 오류 발생하지 않음.
  • Loading branch information
hsheric0210 committed Dec 3, 2023
1 parent 2379d46 commit ad11461
Show file tree
Hide file tree
Showing 21 changed files with 192 additions and 203 deletions.
1 change: 1 addition & 0 deletions AutoKkutuGui/DatabaseManagement.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using AutoKkutuLib.Database.Jobs.Node;
using AutoKkutuLib.Database.Jobs.Word;
using AutoKkutuLib.Database.Jobs;
using AutoKkutuLib.Database.Jobs.DbCheck;

namespace AutoKkutuGui;

Expand Down
10 changes: 9 additions & 1 deletion AutoKkutuGui/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
</Style>
<Style x:Key="BaseCheckboxStyle" TargetType="CheckBox">
<Setter Property="Margin" Value="5,5,5,5" />
<Setter Property="Padding" Value="10,0,10,0" />
<Setter Property="Foreground" Value="#FFFFFF" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
</Style>
<Style x:Key="BaseSearchBox" TargetType="TextBox">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Background" Value="#333337" />
Expand Down Expand Up @@ -141,7 +148,8 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="10,10,0,0" VerticalAlignment="Bottom" Content="수동 검색" FontFamily="/AutoKkutu;component/Resources/Font/#NanumBarunGothic" FontSize="20" Foreground="#FFFFFFFF" />
<Label Grid.Row="0" Grid.Column="0" Margin="10,10,0,0" VerticalAlignment="Bottom" Content="수동 검색" FontFamily="/AutoKkutu;component/Resources/Font/#NanumBarunGothic" FontSize="20" Foreground="#FFFFFFFF" />
<CheckBox Name="RegexpSearch" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Content="정규표현식" Style="{StaticResource BaseCheckboxStyle}" />
<Button Name="SubmitSearch" Grid.Row="1" Grid.Column="1" MinHeight="25" Margin="2,5,15,5" Click="SubmitSearch_Click" Content="검색" FontSize="14" Style="{StaticResource BaseButtonStyle}" />
<TextBox x:Name="SearchField" Grid.Row="1" Grid.Column="0" Margin="15,0,2,0" KeyDown="SearchField_KeyDown" Style="{StaticResource BaseSearchBox}" />
<TextBlock Grid.Row="1" Grid.Column="0" Margin="15,0,15,0" Text="검색할 키워드를 입력해주세요">
Expand Down
6 changes: 4 additions & 2 deletions AutoKkutuGui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,13 @@ private void SubmitSearch_Click(object? sender, RoutedEventArgs e)
missionChar = mainInstance.AutoKkutu.Game.Session.WordCondition.MissionChar;

mainInstance.AutoKkutu.PathFinder.FindPath(gameMode, new PathDetails(
InitialLaw.ApplyInitialLaw(new WordCondition(SearchField.Text, missionChar: missionChar ?? "")),
InitialLaw.ApplyInitialLaw(new WordCondition(SearchField.Text, missionChar: missionChar ?? "", regexp: RegexpSearch.IsChecked ?? false)),
mainInstance.SetupPathFinderFlags(PathFlags.DoNotAutoEnter | PathFlags.DoNotCheckExpired),
mainInstance.Preference.ReturnModeEnabled,
mainInstance.Preference.MaxDisplayedWordCount), mainInstance.Preference.ActiveWordPreference);
SearchField.Text = "";

if (!(RegexpSearch.IsChecked ?? false)) // 힘들게 적은 정규표현식을 지워버리는 것 만큼 빡치는 일도 없음
SearchField.Text = "";
}
}
}
3 changes: 2 additions & 1 deletion AutoKkutuLib/Database/Jobs/DbCheck/DbCheckJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public void CheckDB(bool UseOnlineDB, BrowserBase? browser)
{
new DeduplicateWordTableJob(Db),
new RefreshNodeListJob(nodeManager),
new WordTableCheck(nodeManager),
new InvalidEndNodeCheck(Db),
new RefreshNodeListJob(nodeManager),
new WordTableCheck(nodeManager),
new RunVacuumJob(Db)
};
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protected override int RunCore()
try
{
removed = Db.Query.Deduplicate().Execute();
LibLogger.Info(CheckName, "Removed {0} duplicate word entries.", removed);
LibLogger.Debug(CheckName, "Removed {0} duplicate word entries.", removed);
}
catch (Exception ex)
{
Expand Down
22 changes: 12 additions & 10 deletions AutoKkutuLib/Database/Jobs/DbCheck/InvalidEndNodeCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ public InvalidEndNodeCheck(DbConnectionBase db) : base(db, "Remove Invalid End N
{
}

private int RemoveInvalidEndNode(string wordListColumnName, NodeTypes nodeType, string additionalCondition = "")
private int RemoveInvalidEndNode(NodeTypes nodeType, string additionalCondition = "", bool reverse = false)
{
// Issue #82
var deljob = new NodeDeletionJob(Db, nodeType);
var invalidList = new List<string>();
foreach (var endnode in Db.Query<string>($"SELECT ({DatabaseConstants.WordIndexColumnName}) FROM {nodeType.ToNodeTableName()} ORDER BY({DatabaseConstants.WordIndexColumnName}) DESC"))
var tableName = nodeType.ToNodeTableName();
foreach (var endnode in Db.Query<string>($"SELECT ({DatabaseConstants.WordIndexColumnName}) FROM {tableName} ORDER BY({DatabaseConstants.WordIndexColumnName}) DESC"))
{
var builder = new StringBuilder($"SELECT COUNT(*) FROM {DatabaseConstants.WordTableName} WHERE {wordListColumnName} = @Node");
var builder = new StringBuilder($"SELECT COUNT(*) FROM {DatabaseConstants.WordTableName} WHERE {DatabaseConstants.WordColumnName} LIKE @Pattern");
if (!string.IsNullOrEmpty(additionalCondition))
builder.Append(" AND ").Append(additionalCondition);
builder.Append(';');

var count = Db.ExecuteScalar<int>(builder.ToString(), new { Node = endnode });
var count = Db.ExecuteScalar<int>(builder.ToString(), new { Pattern = reverse ? ('%' + endnode) : (endnode + '%') });
if (count > 0)
{
LibLogger.Info<DbCheckJob>("End node {0} is invalid because {1} suitable words are found from the database.", endnode, count);
LibLogger.Debug(CheckName, "Table {0} end node index {1} is invalid because {2} suitable word(s) are found from the database.", tableName, endnode, count);
invalidList.Add(endnode);
}
}
Expand All @@ -39,10 +39,12 @@ private int RemoveInvalidEndNode(string wordListColumnName, NodeTypes nodeType,

protected override int RunCore()
{
removedEnd = RemoveInvalidEndNode(DatabaseConstants.WordIndexColumnName, NodeTypes.EndWord);
removedReverseEnd = RemoveInvalidEndNode(DatabaseConstants.ReverseWordIndexColumnName, NodeTypes.ReverseEndWord);
removedKkutuEnd = RemoveInvalidEndNode(DatabaseConstants.KkutuWordIndexColumnName, NodeTypes.KkutuEndWord, $"LENGTH({DatabaseConstants.KkutuWordIndexColumnName}) > 3");
removedKKTEnd = RemoveInvalidEndNode(DatabaseConstants.WordIndexColumnName, NodeTypes.KKTEndWord, $"(LENGTH({DatabaseConstants.WordIndexColumnName}) = 2 OR LENGTH({DatabaseConstants.WordIndexColumnName}) = 3)"); // TODO: Replace with 'flags' column read and bitmask 'KKT3' verification
using var transaction = Db.BeginTransaction();
removedEnd = RemoveInvalidEndNode(NodeTypes.EndWord);
removedReverseEnd = RemoveInvalidEndNode(NodeTypes.ReverseEndWord, reverse: true);
removedKkutuEnd = RemoveInvalidEndNode(NodeTypes.KkutuEndWord, $"LENGTH({DatabaseConstants.KkutuWordIndexColumnName}) > 3");
removedKKTEnd = RemoveInvalidEndNode(NodeTypes.KKTEndWord, $"(LENGTH({DatabaseConstants.WordIndexColumnName}) = 2 OR LENGTH({DatabaseConstants.WordIndexColumnName}) = 3)"); // TODO: Replace with 'flags' column read and bitmask 'KKT3' verification
transaction.Commit();
return removedEnd + removedReverseEnd + removedKkutuEnd + removedKKTEnd;
}

Expand Down
9 changes: 1 addition & 8 deletions AutoKkutuLib/Database/Jobs/DbCheck/RefreshNodeListJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ internal class RefreshNodeListJob : DbCheckSubtaskBase

protected override int RunCore()
{
try
{
nodeManager.LoadNodeLists(Db);
}
catch (Exception ex)
{
LibLogger.Error<DbCheckJob>(ex, "Failed to refresh node lists");
}
nodeManager.LoadNodeLists(Db);
return 0;
}

Expand Down
6 changes: 5 additions & 1 deletion AutoKkutuLib/Database/Jobs/DbCheck/RunVacuumJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ public RunVacuumJob(DbConnectionBase db) : base(db, "Run Vacuum")
{
}

protected override int RunCore() => Db.Query.Vacuum().Execute();
protected override int RunCore()
{
Db.Query.Vacuum().Execute();
return 0;
}

public override void BriefResult() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public bool Verify(WordModel entry)

public int Fix(DbConnectionBase db)
{
var job = new BatchWordDeletionJob(db);
var job = new BatchWordDeletionJob(db, false);
return job.Execute(invalidList).TotalCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public bool Verify(WordModel entry)

public int Fix(DbConnectionBase db)
{
var job = new BatchWordDeletionJob(db);
var job = new BatchWordDeletionJob(db, false);
return job.Execute(inexistentList).TotalCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override int RunCore()
count += innerCount;
}
transaction.Commit();
return 0;
return count;
}

public override void BriefResult()
Expand Down
15 changes: 12 additions & 3 deletions AutoKkutuLib/Database/Jobs/Word/BatchWordAdditionJob.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutoKkutuLib.Browser;
using AutoKkutuLib.Database.Path;
using AutoKkutuLib.Database.Sql.Query;
using System.Data;

namespace AutoKkutuLib.Database.Jobs.Word;
public sealed class BatchWordAdditionJob : BatchWordJob
Expand All @@ -9,13 +10,15 @@ public sealed class BatchWordAdditionJob : BatchWordJob
private readonly BrowserBase? browser;
private readonly WordFlags wordFlags;
private readonly bool verifyOnline;
private readonly bool transactioned;

public BatchWordAdditionJob(NodeManager nodeManager, BrowserBase? browser, WordFlags wordFlags, bool verifyOnline) : base(nodeManager.DbConnection)
public BatchWordAdditionJob(NodeManager nodeManager, BrowserBase? browser, WordFlags wordFlags, bool verifyOnline, bool transactioned = true) : base(nodeManager.DbConnection)
{
this.nodeManager = nodeManager;
this.browser = browser;
this.wordFlags = wordFlags;
this.verifyOnline = verifyOnline;
this.transactioned = transactioned;
}

public override WordCount Execute(IEnumerable<string> wordList)
Expand All @@ -24,9 +27,11 @@ public override WordCount Execute(IEnumerable<string> wordList)
throw new ArgumentNullException(nameof(wordList));

var count = new WordCount();
IDbTransaction? transaction = null;
try
{
using var transaction = DbConnection.BeginTransaction(); // This will increase addition speed, especially on SQLite
if (transactioned)
transaction = DbConnection.BeginTransaction(); // This will increase addition speed, especially on SQLite
var query = DbConnection.Query.AddWord();
foreach (var word in wordList)
{
Expand All @@ -45,12 +50,16 @@ public override WordCount Execute(IEnumerable<string> wordList)
AddSingleWord(query, word, wordFlags, ref count);
}

transaction.Commit();
transaction?.Commit();
}
catch (Exception ex)
{
LibLogger.Error<BatchWordAdditionJob>(ex, "Failed to perform batch word addition.");
}
finally
{
transaction?.Dispose();
}
return count;
}

Expand Down
19 changes: 13 additions & 6 deletions AutoKkutuLib/Database/Jobs/Word/BatchWordDeletionJob.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using AutoKkutuLib.Database.Sql.Query;
using System.Data;

namespace AutoKkutuLib.Database.Jobs.Word;
public sealed class BatchWordDeletionJob : BatchWordJob
{
public BatchWordDeletionJob(DbConnectionBase dbConnection) : base(dbConnection)
{
}
private readonly bool transactioned;

public BatchWordDeletionJob(DbConnectionBase dbConnection, bool transactioned = true) : base(dbConnection) => this.transactioned = transactioned;

public override WordCount Execute(IEnumerable<string> wordList)
{
Expand All @@ -14,21 +15,27 @@ public override WordCount Execute(IEnumerable<string> wordList)

var count = new WordCount();

IDbTransaction? transaction = null;
try
{
var transaction = DbConnection.BeginTransaction();
if (transactioned)
transaction = DbConnection.BeginTransaction();
var query = DbConnection.Query.DeleteWord();
foreach (var word in wordList)
{
if (RemoveSingleWord(query, word))
count.Increment(WordFlags.None, 1);
}

transaction.Commit();
transaction?.Commit();
}
catch (Exception ex)
{
LibLogger.Error<BatchWordDeletionJob>(ex, "Failed to commit word addition queries to the database.");
LibLogger.Error<BatchWordDeletionJob>(ex, "Failed to commit word deletion queries to the database.");
}
finally
{
transaction?.Dispose();
}

return count;
Expand Down
2 changes: 1 addition & 1 deletion AutoKkutuLib/Database/Sql/Query/FindWordQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private FindQuery CreateQuery(PathDetails parameter)
// PostgreSQL: https://www.postgresql.org/docs/current/functions-matching.html
// MySQL: https://dev.mysql.com/doc/refman/8.0/en/regexp.html
// MariaDB: https://mariadb.com/kb/en/regexp/
filter = $" WHERE ({wordIndexColumn} REGEXP @PrimaryWord)";
filter = $" WHERE ({DatabaseConstants.WordColumnName} REGEXP @PrimaryWord)";
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion AutoKkutuLib/Database/Sql/Query/VacuumQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dapper;
using System.Data;

namespace AutoKkutuLib.Database.Sql.Query;
public class VacuumQuery : SqlQuery<int>
Expand All @@ -10,6 +11,6 @@ public VacuumQuery(DbConnectionBase connection) : base(connection)
public override int Execute()
{
LibLogger.Debug<VacuumQuery>("Running vacuum cleaner on database.");
return Connection.Execute("VACUUM;");
return Connection.Execute("VACUUM;", commandType: CommandType.Text);
}
}
2 changes: 1 addition & 1 deletion AutoKkutuLib/Game/DomHandlers/BasicDomHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public virtual async ValueTask RegisterInGameFunctions(ISet<int> alreadyRegister
if (!await Browser.EvaluateJavaScriptBoolAsync(Browser.GetScriptTypeName(CommonNameRegistry.FunctionsRegistered)))
{
var script = mapping.ApplyTo(LibResources.baseDomHandlerJs);
LibLogger.Warn<BasicDomHandler>("baseHandler injection result: {result}", await Browser.EvaluateJavaScriptRawAsync(script));
LibLogger.Debug<BasicDomHandler>("baseHandler injection result: {result}", await Browser.EvaluateJavaScriptRawAsync(script));
}
}
}
Loading

0 comments on commit ad11461

Please sign in to comment.