Skip to content

Commit

Permalink
Release 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Segilmez06 authored Oct 23, 2023
2 parents 96d560b + 8953acc commit a95f2a6
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 46 deletions.
8 changes: 1 addition & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

## General

- [x] Optimize code and fragment info methods
- [x] Fix workflows (publishing)
- [x] Move settings to embedded resource
- [x] Optimize web requests
- [x] Create console logging utility
- [x] Remove unused libraries

## CLI Args

- [x] Clear web download cache
8 changes: 1 addition & 7 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,4 @@

## General

- [x] Optimize code and fragment info methods
- [ ] Localization
- [ ] ~~Add web link caching with hash checking~~

## CLI Args

- [ ] Open web cache directory in explorer
- [ ] Add comments
39 changes: 17 additions & 22 deletions src/App.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CommandLine;
using Newtonsoft.Json;
using SixLabors.ImageSharp.Processing.Processors.Transforms;

using System.Diagnostics;
using System.Net.Http.Headers;
using System.Reflection;

Expand Down Expand Up @@ -62,41 +61,46 @@ public class Options

[Option('c', "clear", Required = false, Default = false, HelpText = "Clear downloaded cache folder.")]
public bool ClearCache { get; set; }

}

public static class Logger
{
public enum LogLevel
{
Verbose,
Info,
Warn,
Warning,
Error
}

private static readonly Dictionary<LogLevel, int> LevelColors = new()
{
{ LogLevel.Info, 4 }, // Blue
{ LogLevel.Warn, 3 }, // Yellow
{ LogLevel.Error, 1 } // Red
{ LogLevel.Verbose, 7 }, // White
{ LogLevel.Info, 4 }, // Blue
{ LogLevel.Warning, 3 }, // Yellow
{ LogLevel.Error, 1 } // Red
};

private static readonly Dictionary<LogLevel, string> LevelPrefix= new()
{
{ LogLevel.Verbose, Messages.LogCategory_Verbose },
{ LogLevel.Info, Messages.LogCategory_Info },
{ LogLevel.Warn, Messages.LogCategory_Warning },
{ LogLevel.Warning, Messages.LogCategory_Warning },
{ LogLevel.Error, Messages.LogCategory_Error }
};

private static readonly Dictionary<LogLevel, int> LevelExitCodes = new()
{
{ LogLevel.Verbose, 0 },
{ LogLevel.Info, 0 },
{ LogLevel.Warn, 0 },
{ LogLevel.Warning, 0 },
{ LogLevel.Error, 1 }
};

public static void LogMsg(LogLevel Level, string Message)
{
Console.WriteLine($"\u001b[3{LevelColors[Level]}m{LevelPrefix[Level]}:\u001b[37m {Message}\u001b[39m");
Console.WriteLine($"\u001b[3{LevelColors[Level]}m{LevelPrefix[Level]}{((LevelPrefix[Level].Length > 0) ? ": " : "")}\u001b[37m{Message}\u001b[39m");
}

public static void LogExit(LogLevel Level, string Message)
Expand Down Expand Up @@ -129,23 +133,14 @@ public App(string[] Arguments)

private void Run(Options CommandLineOptions)
{
Assembly ExecutingAssembly = Assembly.GetExecutingAssembly();
Stream SettingsStream = ExecutingAssembly.GetManifestResourceStream("TYM.settings.json");
string SettingsContent = new StreamReader(SettingsStream).ReadToEnd();

dynamic Settings = JsonConvert.DeserializeObject<dynamic>(SettingsContent);

if (CommandLineOptions.ListResamplers)
{
Console.WriteLine("\u001b[32mAvailable resampling algorithms:");
Console.Write("\x1b[33m");
typeof(KnownResamplers).GetProperties().ToList().ForEach(x => Console.WriteLine(x.Name));
Console.WriteLine("\x1b[39m");

LogMsg(LogLevel.Info, Messages.Message_AvailableResamplers);
typeof(KnownResamplers).GetProperties().ToList().ForEach(x => LogMsg(LogLevel.Verbose, x.Name));
Environment.Exit(0);
}

string DownloadDirectory = Path.Combine(Path.GetTempPath(), (string)Settings["tempDirectoryName"]);
string DownloadDirectory = Path.Combine(Path.GetTempPath(), Settings.tempDirectoryName);
if (CommandLineOptions.ClearCache)
{
Directory.Delete(DownloadDirectory, true);
Expand All @@ -164,7 +159,7 @@ private void Run(Options CommandLineOptions)
{
HttpClient Client = new();

List<string> SupportedMimeTypes = ((string[])Settings["supportedImageFormats"]).ToList();
List<string> SupportedMimeTypes = Settings.supportedImageFormats.Split(",").Select(x => x = $"image/{x}").ToList();
SupportedMimeTypes.ForEach(x => Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(x)));

Task<HttpResponseMessage> GetTask = Client.GetAsync(WebURI);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
<data name="LogCategory.Info" xml:space="preserve">
<value>INFO</value>
</data>
<data name="LogCategory.Verbose" xml:space="preserve">
<value />
</data>
<data name="LogCategory.Warning" xml:space="preserve">
<value>WARNING</value>
</data>
Expand Down
6 changes: 3 additions & 3 deletions src/Properties/Messages.tr.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Properties/Messages.tr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
<data name="LogCategory.Info" xml:space="preserve">
<value>BILGI</value>
</data>
<data name="LogCategory.Verbose" xml:space="preserve">
<value />
</data>
<data name="LogCategory.Warning" xml:space="preserve">
<value>UYARI</value>
</data>
Expand Down
81 changes: 81 additions & 0 deletions src/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a95f2a6

Please sign in to comment.