Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeManarin committed May 1, 2022
2 parents 84a0a73 + 5bb3d1d commit c91b038
Show file tree
Hide file tree
Showing 65 changed files with 2,686 additions and 568 deletions.
32 changes: 20 additions & 12 deletions Other/Translator/TranslatorWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ namespace Translator;

public partial class TranslatorWindow : Window
{
private static string TempPath => Path.Combine(".", "ScreenToGif", "Resources");

private readonly List<ResourceDictionary> _resourceList = new();
private IEnumerable<string> _cultures;
private ObservableCollection<Translation> _translationList = new();
private string _tempPath;
private string _resourceTemplate;

public TranslatorWindow()
Expand All @@ -42,8 +41,7 @@ public TranslatorWindow()

private async void Window_Loaded(object sender, RoutedEventArgs e)
{
if (!Directory.Exists(TempPath))
Directory.CreateDirectory(TempPath);
PrepareTempPath();

OpenButton.IsEnabled = false;
RefreshButton.IsEnabled = false;
Expand Down Expand Up @@ -220,17 +218,18 @@ private async void Load_Executed(object sender, ExecutedRoutedEventArgs e)
CheckFileExists = true,
Title = "Open a Resource Dictionary",
Filter = "Resource Dictionay (*.xaml)|*.xaml;",
InitialDirectory = Path.GetFullPath(TempPath)
InitialDirectory = Path.GetFullPath(_tempPath)
};

var result = ofd.ShowDialog();

if (!result.HasValue || !result.Value) return;
if (!result.HasValue || !result.Value)
return;

//Will save the file to other folder.
var tempFile = Path.Combine(TempPath, "Temp", Path.GetFileName(ofd.FileName));
var tempFile = Path.Combine(_tempPath, "Temp", Path.GetFileName(ofd.FileName));

Directory.CreateDirectory(Path.Combine(TempPath, "Temp"));
Directory.CreateDirectory(Path.Combine(_tempPath, "Temp"));

//Replaces the special chars.
var text = await Task.Factory.StartNew(() => File.ReadAllText(ofd.FileName, Encoding.UTF8).Replace("&#", "&amp;#").Replace("<!--<!--", "<!--").Replace("-->-->", "-->"));
Expand Down Expand Up @@ -290,7 +289,8 @@ private async void Export_Executed(object sender, ExecutedRoutedEventArgs e)

var result = sfd.ShowDialog();

if (!result.HasValue || !result.Value) return;
if (!result.HasValue || !result.Value)
return;

BaseDataGrid.IsEnabled = false;
StatusBand.Info("Exporting translation...");
Expand Down Expand Up @@ -321,6 +321,14 @@ private void Window_Closing(object sender, CancelEventArgs e)

#region Methods

private void PrepareTempPath()
{
_tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScreenToGif", "Resources");

if (!Directory.Exists(_tempPath))
Directory.CreateDirectory(_tempPath);
}

private async Task DownloadSingleResourceAsync(string culture)
{
try
Expand Down Expand Up @@ -425,7 +433,7 @@ private async Task DownloadFileAsync2(Uri uri, string name)
{
try
{
var file = Path.Combine(Dispatcher.Invoke<string>(() => TempPath), name);
var file = Path.Combine(Dispatcher.Invoke<string>(() => _tempPath), name);

if (File.Exists(file))
File.Delete(file);
Expand Down Expand Up @@ -464,7 +472,7 @@ private async Task DownloadFileAsync(Uri uri, string name)
{
try
{
var file = Path.Combine(Dispatcher.Invoke<string>(() => TempPath), name);
var file = Path.Combine(Dispatcher.Invoke<string>(() => _tempPath), name);

if (File.Exists(file))
File.Delete(file);
Expand Down Expand Up @@ -503,7 +511,7 @@ private async Task LoadFilesAsync()
{
try
{
var files = await Task.Factory.StartNew(() => Directory.EnumerateFiles(TempPath, "*.xaml"));
var files = await Task.Factory.StartNew(() => Directory.EnumerateFiles(_tempPath, "*.xaml"));

foreach (var file in files)
{
Expand Down
1 change: 1 addition & 0 deletions ScreenToGif.Model/Enums/EncoderTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace ScreenToGif.Domain.Enums;
public enum EncoderTypes
{
ScreenToGif, //Gif, Apng
KGySoft, // Gif
System, //Gif, Video
FFmpeg, //Gif, Webp, Apng, Video
Gifski //Gif
Expand Down
4 changes: 2 additions & 2 deletions ScreenToGif.Model/Enums/PanelType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public enum PanelTypes
RemoveDuplicates = 13,

/// <summary>
/// Mouse Clicks Panel.
/// Mouse Events Panel.
/// </summary>
MouseClicks = 14,
MouseEvents = 14,

/// <summary>
/// Smooth Loop Panel.
Expand Down
2 changes: 1 addition & 1 deletion ScreenToGif.Model/Enums/TaskTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace ScreenToGif.Domain.Enums;
public enum TaskTypes
{
NotDeclared = 0,
MouseClicks = 1,
MouseEvents = 1,
KeyStrokes = 2,
Delay = 3,
Progress = 4,
Expand Down
1 change: 1 addition & 0 deletions ScreenToGif.Model/Enums/VideoCodecPresets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace ScreenToGif.Domain.Enums;
[SuppressMessage("ReSharper", "InconsistentNaming")]
public enum VideoCodecPresets
{
Auto = -1,
NotSelected,
None,

Expand Down
11 changes: 10 additions & 1 deletion ScreenToGif.Model/Enums/VideoCodecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,14 @@ public enum VideoCodecs
Vp8,

[Description("libvpx-vp9")]
Vp9
Vp9,

[Description("libaom-av1")]
LibAom,

[Description("libsvtav1")]
SvtAv1,

[Description("librav1e")]
Rav1E,
}
1 change: 1 addition & 0 deletions ScreenToGif.Model/Enums/VideoPixelFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum VideoPixelFormats
Gbrp12Le,
Gray,
Gray10Le,
Gray12Le,
Gray16Be,
MonoB,
Nv12,
Expand Down
2 changes: 1 addition & 1 deletion ScreenToGif.Model/ScreenToGif.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<DebugType>embedded</DebugType>
<UseWPF>True</UseWPF>
<Platforms>AnyCPU;ARM64;x64;x86</Platforms>
<Version>2.36.0</Version>
<Version>2.37.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
2 changes: 1 addition & 1 deletion ScreenToGif.Native/ScreenToGif.Native.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<UseWindowsForms>True</UseWindowsForms>
<DebugType>embedded</DebugType>
<Platforms>AnyCPU;ARM64;x64;x86</Platforms>
<Version>2.36.0</Version>
<Version>2.37.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
4 changes: 2 additions & 2 deletions ScreenToGif.Test/ScreenToGif.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
26 changes: 26 additions & 0 deletions ScreenToGif.Util/Converters/TimeSpanToString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Globalization;
using System.Windows.Data;

namespace ScreenToGif.Util.Converters;

public class TimeSpanToString : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not TimeSpan time)
return Binding.DoNothing;

if (time.Days > 0)
return time.ToString("d\\:hh\\:mm\\:ss", culture);

if (time.Hours > 0)
return time.ToString("h\\:mm\\:ss", culture);

return time.ToString("mm\\:ss", culture);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
}
62 changes: 62 additions & 0 deletions ScreenToGif.Util/Extensions/WriteableBitmapExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#region Usings

#region Used Namespaces

using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

using KGySoft.Drawing.Imaging;

#endregion

#region Used Aliases

using PixelFormat = System.Drawing.Imaging.PixelFormat;
using Size = System.Drawing.Size;

#endregion

#endregion

namespace ScreenToGif.Util.Extensions;

/// <summary>
/// Contains extension methods for the <see cref="WriteableBitmap"/> type.
/// </summary>
public static class WriteableBitmapExtensions
{
#region Methods

/// <summary>
/// Gets a managed read-write accessor for a <see cref="WriteableBitmapData"/> instance.
/// </summary>
/// <param name="bitmap">The bitmap to get the managed accessor.</param>
/// <returns>An <see cref="IReadWriteBitmapData"/> instance that provides managed access to the specified <see cref="bitmap"/>.</returns>
public static IReadWriteBitmapData GetReadWriteBitmapData(this WriteableBitmap bitmap)
{
if (bitmap == null)
throw new ArgumentNullException(nameof(bitmap));
if (bitmap.IsFrozen)
throw new ArgumentException("Bitmap must not be frozen");

var format = bitmap.Format;

// Actually you can support any other formats, including non-natively supported ones by custom PixelFormatInfo and getter/setter delegates
var pixelFormat = format == PixelFormats.Bgra32 ? PixelFormat.Format32bppArgb
: format == PixelFormats.Pbgra32 ? PixelFormat.Format32bppPArgb
: format == PixelFormats.Bgr32 ? PixelFormat.Format32bppRgb
: format == PixelFormats.Bgr24 ? PixelFormat.Format24bppRgb
: throw new NotSupportedException(bitmap.Format.ToString());

bitmap.Lock();
return BitmapDataFactory.CreateBitmapData(bitmap.BackBuffer, new Size(bitmap.PixelWidth, bitmap.PixelHeight), bitmap.BackBufferStride, pixelFormat,
disposeCallback: () =>
{
bitmap.AddDirtyRect(new Int32Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight));
bitmap.Unlock();
});
}

#endregion
}
71 changes: 30 additions & 41 deletions ScreenToGif.Util/LogWritter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@ namespace ScreenToGif.Util;
/// </summary>
public static class LogWriter
{
private static void WriteDetails(TextWriter writer, Exception ex, int level)
{
writer.WriteLine(new string('▬', level) + $" Message - {Environment.NewLine}\t{ex.Message}");
writer.WriteLine(new string('○', level) + $" Type - {Environment.NewLine}\t{ex.GetType()}");
writer.WriteLine(new string('▲', level) + $" Source - {Environment.NewLine}\t{ex.Source}");
writer.WriteLine(new string('▼', level) + $" TargetSite - {Environment.NewLine}\t{ex.TargetSite}");

if (ex is BadImageFormatException bad)
{
writer.WriteLine(new string('☼', level) + $" Filename - {Environment.NewLine}\t{bad.FileName}");
writer.WriteLine(new string('►', level) + $" Fuslog - {Environment.NewLine}\t{bad.FusionLog}");
}
else if (ex is ArgumentException arg)
{
writer.WriteLine(new string('☼', level) + $" ParamName - {Environment.NewLine}\t{arg.ParamName}");
}

if (ex.HelpLink != null)
writer.WriteLine(new string('◘', level) + $" Other - {Environment.NewLine}\t{ex.HelpLink}");

writer.WriteLine(new string('♠', level) + $" StackTrace - {Environment.NewLine}{ex.StackTrace}");

if (ex.InnerException == null || level >= 6)
return;

writer.WriteLine();
WriteDetails(writer, ex.InnerException, level + 1);
}

/// <summary>
/// Writes the exception details to the error log on disk.
/// </summary>
Expand Down Expand Up @@ -58,52 +87,12 @@ public static void Log(Exception ex, string title, object aditional = null, bool
using (var writer = new StreamWriter(fileStream))
{
writer.WriteLine($"► Title - {Environment.NewLine}\t{title}");
writer.WriteLine($"▬ Message - {Environment.NewLine}\t{ex.Message}");
writer.WriteLine($"○ Type - {Environment.NewLine}\t{ex.GetType()}");
writer.WriteLine(FormattableString.Invariant($"♦ [Version] Date/Hour - {Environment.NewLine}\t[{UserSettings.All?.VersionText}] {DateTime.Now}"));
writer.WriteLine($"▲ Source - {Environment.NewLine}\t{ex.Source}");
writer.WriteLine($"▼ TargetSite - {Environment.NewLine}\t{ex.TargetSite}");

if (ex is BadImageFormatException bad)
writer.WriteLine($"► Fuslog - {Environment.NewLine}\t{bad.FusionLog}");

if (aditional != null)
writer.WriteLine($"◄ Aditional - {Environment.NewLine}\t{aditional}");

if (ex.HelpLink != null)
writer.WriteLine($"◘ Other - {Environment.NewLine}\t{ex.HelpLink}");

writer.WriteLine($"♠ StackTrace - {Environment.NewLine}{ex.StackTrace}");

if (ex.InnerException != null)
{
writer.WriteLine();
writer.WriteLine($"▬▬ Message - {Environment.NewLine}\t{ex.InnerException.Message}");
writer.WriteLine($"○○ Type - {Environment.NewLine}\t{ex.InnerException.GetType()}");
writer.WriteLine($"▲▲ Source - {Environment.NewLine}\t{ex.InnerException.Source}");
writer.WriteLine($"▼▼ TargetSite - {Environment.NewLine}\t{ex.InnerException.TargetSite}");
writer.WriteLine($"♠♠ StackTrace - {Environment.NewLine}{ex.InnerException.StackTrace}");

if (ex.InnerException.InnerException != null)
{
writer.WriteLine();
writer.WriteLine($"▬▬▬ Message - {Environment.NewLine}\t{ex.InnerException.InnerException.Message}");
writer.WriteLine($"○○○ Type - {Environment.NewLine}\t{ex.InnerException.InnerException.GetType()}");
writer.WriteLine($"▲▲▲ Source - {Environment.NewLine}\t{ex.InnerException.InnerException.Source}");
writer.WriteLine($"▼▼▼ TargetSite - {Environment.NewLine}\t{ex.InnerException.InnerException.TargetSite}");
writer.WriteLine($"♠♠♠ StackTrace - {Environment.NewLine}\t{ex.InnerException.InnerException.StackTrace}");

if (ex.InnerException.InnerException.InnerException != null)
{
writer.WriteLine();
writer.WriteLine($"▬▬▬▬ Message - {Environment.NewLine}\t{ex.InnerException.InnerException.InnerException.Message}");
writer.WriteLine($"○○○○ Type - {Environment.NewLine}\t{ex.InnerException.InnerException.InnerException.GetType()}");
writer.WriteLine($"▲▲▲▲ Source - {Environment.NewLine}\t{ex.InnerException.InnerException.InnerException.Source}");
writer.WriteLine($"▼▼▼▼ TargetSite - {Environment.NewLine}\t{ex.InnerException.InnerException.InnerException.TargetSite}");
writer.WriteLine($"♠♠♠♠ StackTrace - {Environment.NewLine}\t{ex.InnerException.InnerException.InnerException.StackTrace}");
}
}
}
WriteDetails(writer, ex, 1);

writer.WriteLine();
writer.WriteLine("----------------------------------");
Expand Down
5 changes: 3 additions & 2 deletions ScreenToGif.Util/ScreenToGif.Util.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>True</UseWPF>
<DebugType>embedded</DebugType>
<Platforms>AnyCPU;ARM64;x64;x86</Platforms>
<Version>2.36.0</Version>
<Version>2.37.0</Version>
<!--<UseWindowsForms>True</UseWindowsForms>-->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="KGySoft.Drawing" Version="6.3.2" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
Loading

0 comments on commit c91b038

Please sign in to comment.