Skip to content

Commit 59d42ec

Browse files
committed
feat: a new hope
1 parent 31ee16e commit 59d42ec

File tree

14 files changed

+47
-30
lines changed

14 files changed

+47
-30
lines changed

src/DDS.Tools/Commands/Base/ConvertCommandBase.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,32 @@ namespace DDS.Tools.Commands.Base;
1515
/// <inheritdoc/>
1616
internal abstract class ConvertCommandBase<TSettings>(ITodoService todoService) : Command<TSettings> where TSettings : CommandSettings
1717
{
18-
private readonly ITodoService _todoService = todoService;
18+
private const string ResultFileName = "Result.json";
1919

20-
protected int Action(ConvertSettings settings, ImageType imageType)
20+
protected int Action(ConvertSettingsBase settings, ImageType imageType)
2121
{
2222
TodoCollection todos;
2323

2424
if (!Directory.Exists(settings.SourceFolder))
2525
throw new CommandException($"Directory '{settings.SourceFolder}' not found.");
2626

27-
string jsonFilePath = Path.Combine(settings.SourceFolder, "Result.json");
27+
string jsonFilePath = Path.Combine(settings.SourceFolder, ResultFileName);
28+
bool resultFileExists = File.Exists(jsonFilePath);
2829

29-
todos = File.Exists(jsonFilePath)
30-
? _todoService.GetTodosFromJson(settings, imageType, jsonFilePath)
31-
: _todoService.GetTodos(settings, imageType);
30+
todos = resultFileExists
31+
? todoService.GetTodosFromJson(settings, imageType, jsonFilePath)
32+
: todoService.GetTodos(settings, imageType);
3233

3334
if (todos.Count.Equals(0))
3435
{
3536
AnsiConsole.MarkupLine($"[yellow]There is nothing todo![/]");
3637
return 1;
3738
}
3839

39-
_todoService.GetTodosDone(todos, settings, imageType);
40+
if (resultFileExists)
41+
todoService.GetTodosDoneFromJson(todos, settings, imageType);
42+
else
43+
todoService.GetTodosDone(todos, settings, imageType);
4044

4145
return 0;
4246
}

src/DDS.Tools/Enumerators/ConvertModeType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public enum ConvertModeType
99
/// The automatic mode.
1010
/// </summary>
1111
Automatic = 0,
12-
12+
1313
/// <summary>
1414
/// The manual mode.
1515
/// </summary>

src/DDS.Tools/Interfaces/Services/ITodoService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,36 @@ namespace DDS.Tools.Interfaces.Services;
1010
internal interface ITodoService
1111
{
1212
/// <summary>
13-
/// Returns a collection of todos depending on the provided <see cref="ConvertSettings"/>.
13+
/// Returns a collection of todos depending on the provided <see cref="ConvertSettingsBase"/>.
1414
/// </summary>
1515
/// <param name="settings">The settings that need to be considered.</param>
1616
/// <param name="imageType">The image type to work with.</param>
1717
/// <returns>A collection of todos.</returns>
18-
TodoCollection GetTodos(ConvertSettings settings, ImageType imageType);
18+
TodoCollection GetTodos(ConvertSettingsBase settings, ImageType imageType);
1919

2020
/// <summary>
21-
/// Returns a collection of todos depending on the provided <see cref="ConvertSettings"/>
21+
/// Returns a collection of todos depending on the provided <see cref="ConvertSettingsBase"/>
2222
/// and the <paramref name="jsonContent"/>.
2323
/// </summary>
2424
/// <param name="settings">The settings that need to be considered.</param>
2525
/// <param name="imageType">The image type to work with.</param>
2626
/// <param name="jsonContent">The json content to work with.</param>
2727
/// <returns>A collection of todos.</returns>
28-
TodoCollection GetTodosFromJson(ConvertSettings settings, ImageType imageType, string jsonContent);
28+
TodoCollection GetTodosFromJson(ConvertSettingsBase settings, ImageType imageType, string jsonContent);
2929

3030
/// <summary>
3131
/// Get the todos done.
3232
/// </summary>
3333
/// <param name="todos">The collection of todos.</param>
3434
/// <param name="settings">The settings that need to be considered.</param>
3535
/// <param name="imageType">The image type to work with.</param>
36-
void GetTodosDone(TodoCollection todos, ConvertSettings settings, ImageType imageType);
36+
void GetTodosDone(TodoCollection todos, ConvertSettingsBase settings, ImageType imageType);
3737

3838
/// <summary>
3939
/// Get the todos done in a different way.
4040
/// </summary>
4141
/// <param name="todos">The collection of todos.</param>
4242
/// <param name="settings">The settings that need to be considered.</param>
4343
/// <param name="imageType">The image type to work with.</param>
44-
void GetTodosDoneFromJson(TodoCollection todos, ConvertSettings settings, ImageType imageType);
44+
void GetTodosDoneFromJson(TodoCollection todos, ConvertSettingsBase settings, ImageType imageType);
4545
}

src/DDS.Tools/Services/LoggerService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System.Diagnostics.CodeAnalysis;
22

3-
using Microsoft.Extensions.Logging;
43
using DDS.Tools.Interfaces.Services;
54

5+
using Microsoft.Extensions.Logging;
6+
67
namespace DDS.Tools.Services;
78

89
/// <summary>

src/DDS.Tools/Services/TodoService.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal sealed class TodoService(ILoggerService<TodoService> logger, IServicePr
3232

3333
/// <inheritdoc/>
3434
/// <exception cref="ServiceException"></exception>
35-
public TodoCollection GetTodos(ConvertSettings settings, ImageType imageType)
35+
public TodoCollection GetTodos(ConvertSettingsBase settings, ImageType imageType)
3636
{
3737
try
3838
{
@@ -57,7 +57,7 @@ public TodoCollection GetTodos(ConvertSettings settings, ImageType imageType)
5757

5858
/// <inheritdoc/>
5959
/// <exception cref="ServiceException"></exception>
60-
public TodoCollection GetTodosFromJson(ConvertSettings settings, ImageType imageType, string jsonFilePath)
60+
public TodoCollection GetTodosFromJson(ConvertSettingsBase settings, ImageType imageType, string jsonFilePath)
6161
{
6262
try
6363
{
@@ -80,7 +80,7 @@ public TodoCollection GetTodosFromJson(ConvertSettings settings, ImageType image
8080

8181
/// <inheritdoc/>
8282
/// <exception cref="ServiceException"></exception>
83-
public void GetTodosDone(TodoCollection todos, ConvertSettings settings, ImageType imageType)
83+
public void GetTodosDone(TodoCollection todos, ConvertSettingsBase settings, ImageType imageType)
8484
{
8585
try
8686
{
@@ -104,7 +104,7 @@ public void GetTodosDone(TodoCollection todos, ConvertSettings settings, ImageTy
104104
}
105105

106106
/// <inheritdoc/>
107-
public void GetTodosDoneFromJson(TodoCollection todos, ConvertSettings settings, ImageType imageType)
107+
public void GetTodosDoneFromJson(TodoCollection todos, ConvertSettingsBase settings, ImageType imageType)
108108
{
109109
try
110110
{
@@ -118,7 +118,7 @@ public void GetTodosDoneFromJson(TodoCollection todos, ConvertSettings settings,
118118
}
119119
}
120120

121-
private void GetTodo(TodoCollection todos, ConvertSettings settings, ImageType imageType, string file)
121+
private void GetTodo(TodoCollection todos, ConvertSettingsBase settings, ImageType imageType, string file)
122122
{
123123
FileInfo fileInfo = new(file);
124124

@@ -136,7 +136,7 @@ private void GetTodo(TodoCollection todos, ConvertSettings settings, ImageType i
136136
todos.Add(todo);
137137
}
138138

139-
private static void GetTodoFromJson(TodoCollection todos, ConvertSettings settings, ImageType imageType, TodoModel todoFromJson)
139+
private static void GetTodoFromJson(TodoCollection todos, ConvertSettingsBase settings, ImageType imageType, TodoModel todoFromJson)
140140
{
141141
string newFullPathName =
142142
Path.Combine(settings.TargetFolder, todoFromJson.RelativePath, todoFromJson.FileName.Replace(GetTargetFileExtensions(imageType), $"{imageType}"));
@@ -152,7 +152,7 @@ private static void GetTodoFromJson(TodoCollection todos, ConvertSettings settin
152152
todos.Add(todo);
153153
}
154154

155-
private void GetTodoDone(TodoModel todo, ConvertSettings settings, ImageType imageType)
155+
private void GetTodoDone(TodoModel todo, ConvertSettingsBase settings, ImageType imageType)
156156
{
157157
if (settings.ConvertMode.Equals(ConvertModeType.Automatic))
158158
{
@@ -169,7 +169,7 @@ private void GetTodoDone(TodoModel todo, ConvertSettings settings, ImageType ima
169169
_todosDone.Add(todo.FileHash);
170170
}
171171

172-
private void SaveImage(ConvertSettings settings, TodoModel todo, ImageType imageType)
172+
private void SaveImage(ConvertSettingsBase settings, TodoModel todo, ImageType imageType)
173173
{
174174
IImageModel image = _provider.GetRequiredKeyedService<IImageModel>(imageType);
175175
image.Load(todo.FullPathName);
@@ -183,7 +183,7 @@ private void SaveImage(ConvertSettings settings, TodoModel todo, ImageType image
183183
image.Save(newFilePath);
184184
}
185185

186-
private static string PrepareTargetFolder(ConvertSettings settings, IImageModel image, string targetFolder)
186+
private static string PrepareTargetFolder(ConvertSettingsBase settings, IImageModel image, string targetFolder)
187187
{
188188
string newTargetFolder = targetFolder;
189189

@@ -202,7 +202,7 @@ private static string PrepareTargetFolder(ConvertSettings settings, IImageModel
202202
return newTargetFolder;
203203
}
204204

205-
private static string GetTargetFileName(ConvertSettings settings, TodoModel todo)
205+
private static string GetTargetFileName(ConvertSettingsBase settings, TodoModel todo)
206206
{
207207
if (settings.ConvertMode == ConvertModeType.Manual && settings.RetainStructure)
208208
{

src/DDS.Tools/Settings/Base/ConvertSettings.cs renamed to src/DDS.Tools/Settings/Base/ConvertSettingsBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
namespace DDS.Tools.Settings.Base;
88

99
/// <summary>
10-
/// The convert settings class
10+
/// The convert settings base class
1111
/// </summary>
12-
internal abstract class ConvertSettings : CommandSettings
12+
internal abstract class ConvertSettingsBase : CommandSettings
1313
{
1414
/// <summary>
1515
/// The source folder of the images.

src/DDS.Tools/Settings/DdsConvertSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace DDS.Tools.Settings;
1111
/// <summary>
1212
/// The dds convert settings class.
1313
/// </summary>
14-
internal sealed class DdsConvertSettings : ConvertSettings
14+
internal sealed class DdsConvertSettings : ConvertSettingsBase
1515
{
1616
/// <summary>
1717
/// The compression level in which the images should be saved.

src/DDS.Tools/Settings/PngConvertSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace DDS.Tools.Settings;
1111
/// <summary>
1212
/// The png convert settings class.
1313
/// </summary>
14-
internal sealed class PngConvertSettings : ConvertSettings
14+
internal sealed class PngConvertSettings : ConvertSettingsBase
1515
{
1616
/// <summary>
1717
/// The compression level in which the images should be saved.

tests/DDS.ToolsTests/DDS.ToolsTests.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
<None Update="Resources\DDS\32A.dds">
1212
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1313
</None>
14+
<None Update="Resources\DDS\Red\64.DDS">
15+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Resources\DDS\Red\64A.DDS">
18+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
19+
</None>
1420
<None Update="Resources\PNG\32.png">
1521
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1622
</None>
@@ -20,6 +26,12 @@
2026
<None Update="Resources\PNG\outfit101m.png">
2127
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2228
</None>
29+
<None Update="Resources\PNG\Red\64.png">
30+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
31+
</None>
32+
<None Update="Resources\PNG\Red\64A.png">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</None>
2335
</ItemGroup>
2436

2537
</Project>
5.48 KB
Binary file not shown.

0 commit comments

Comments
 (0)