Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeManarin committed Jun 2, 2021
2 parents cc5f472 + 59fb3e1 commit a55178d
Show file tree
Hide file tree
Showing 36 changed files with 626 additions and 341 deletions.
12 changes: 12 additions & 0 deletions ScreenToGif/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Threading;
using Microsoft.Win32;
using ScreenToGif.Controls;
using ScreenToGif.Model;
using ScreenToGif.Settings;
Expand Down Expand Up @@ -62,6 +63,9 @@ private void App_Startup(object sender, StartupEventArgs e)
LocalizationHelper.SelectCulture(UserSettings.All.LanguageCode);
ThemeHelper.SelectTheme(UserSettings.All.MainTheme);

//Listen to changes in theme.
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;

#region Download mode

if (Argument.IsInDownloadMode)
Expand Down Expand Up @@ -327,8 +331,16 @@ private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEven
}
}

private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
if (e.Category == UserPreferenceCategory.General)
ThemeHelper.SelectTheme(UserSettings.All.MainTheme);
}

private void App_Exit(object sender, ExitEventArgs e)
{
SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged;

try
{
MutexList.RemoveAll();
Expand Down
35 changes: 22 additions & 13 deletions ScreenToGif/Cloud/Imgur/Imgur.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
Expand Down Expand Up @@ -34,7 +34,7 @@ public async Task<History> UploadFileAsync(UploadPreset preset, string path, Can

if (imgurPreset.UploadToAlbum)
{
var album = string.IsNullOrWhiteSpace(imgurPreset.SelectedAlbum) || imgurPreset.SelectedAlbum == "♥♦♣♠" ?
var album = string.IsNullOrWhiteSpace(imgurPreset.SelectedAlbum) || imgurPreset.SelectedAlbum == "♥♦♣♠" ?
await AskForAlbum(imgurPreset) : imgurPreset.SelectedAlbum;

if (!string.IsNullOrEmpty(album))
Expand All @@ -45,19 +45,19 @@ public async Task<History> UploadFileAsync(UploadPreset preset, string path, Can
{
headers.Add("Authorization", "Client-ID " + Secret.ImgurId);
}

if (cancellationToken.IsCancellationRequested)
return null;

return await Upload(imgurPreset, path, args, headers);
}


public static string GetAuthorizationAdress()
{
var args = new Dictionary<string, string>
{
{"client_id", Secret.ImgurId},
{"client_id", Secret.ImgurId},
{"response_type", "pin"}
};

Expand Down Expand Up @@ -165,24 +165,33 @@ private async Task<History> Upload(ImgurPreset preset, string path, Dictionary<s

//Error when sending video.
//{"data":{"errorCode":null,"ticket":"7234557b"},"success":true,"status":200}
//{"data":{"error":"No image data was sent to the upload api","request":"\/3\/image","method":"POST"},"success":false,"status":400}

if (response == null || (!response.Success && response.Status != 200))
{
LogWriter.Log("It was not possible to upload to Imgur", result);

return new ImgurHistory
{
PresetName = preset.Title,
DateInUtc = DateTime.UtcNow,
Result = 400,
Message = response?.Status.ToString() ?? result
Message = response?.Status + " - " + (response?.Data?.Error ?? result)
};
}

if (string.IsNullOrEmpty(response.Data?.Link))
return new ImgurHistory
{
PresetName = preset.Title,
DateInUtc = DateTime.UtcNow,
Result = 400,
Message = "Upload failed. The link was not provided."
};
{
LogWriter.Log("It was not possible to upload to Imgur", result);

return new ImgurHistory
{
PresetName = preset.Title,
DateInUtc = DateTime.UtcNow,
Result = 400,
Message = "Upload failed. The link was not provided."
};
}

var history = new ImgurHistory
{
Expand Down
5 changes: 4 additions & 1 deletion ScreenToGif/Cloud/Imgur/ImgurImage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.Serialization;
using System.Runtime.Serialization;

namespace ScreenToGif.Cloud.Imgur
{
Expand Down Expand Up @@ -73,5 +73,8 @@ public class ImgurImageData

[DataMember(Name = "comment_preview")]
public string CommentPreview { get; set; }

[DataMember(Name = "error")]
public string Error { get; set; }
}
}
2 changes: 1 addition & 1 deletion ScreenToGif/Controls/BaseScreenRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class BaseScreenRecorder : BaseRecorder
/// <summary>
/// Indicates when the user is mouse-clicking.
/// </summary>
internal bool RecordClicked = false;
internal MouseButtonType RecordClicked = MouseButtonType.None;

/// <summary>
/// Deals with all screen capture methods.
Expand Down
15 changes: 11 additions & 4 deletions ScreenToGif/Model/ApplicationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,8 @@ internal bool InstallUpdate(bool wasPromptedManually = false)

//TODO: Check if Windows is not turning off.

var runAfterwards = false;

//Prompt if:
//Not configured to download the update automatically OR
//Configured to download but set to prompt anyway OR
Expand All @@ -1042,6 +1044,8 @@ internal bool InstallUpdate(bool wasPromptedManually = false)

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

runAfterwards = download.RunAfterwards;
}

//Only try to install if the update was downloaded.
Expand All @@ -1055,27 +1059,30 @@ internal bool InstallUpdate(bool wasPromptedManually = false)
return true;
}

//Detect installed components.
var files = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory).ToList();
var isInstaller = files.Any(x => x.ToLowerInvariant().EndsWith("screentogif.visualelementsmanifest.xml"));
var hasSharpDx = files.Any(x => x.ToLowerInvariant().EndsWith("sharpdx.dll"));
var hasGifski = files.Any(x => x.ToLowerInvariant().EndsWith("gifski.dll"));
var hasMenuShortcut = File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "ScreenToGif.lnk"));
var hasDesktopShortcut = File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop", "ScreenToGif.lnk"));
var hasDesktopShortcut = File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "ScreenToGif.lnk")) ||
File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory), "ScreenToGif.lnk"));
var hasMenuShortcut = File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "ScreenToGif.lnk")) ||
File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "ScreenToGif.lnk"));

//MsiExec does not like relative paths.
var isRelative = !string.IsNullOrWhiteSpace(Global.UpdateAvailable.InstallerPath) && !Path.IsPathRooted(Global.UpdateAvailable.InstallerPath);
var nonRoot = isRelative ? Path.GetFullPath(Global.UpdateAvailable.InstallerPath) : Global.UpdateAvailable.InstallerPath;

//msiexec /i PATH INSTALLDIR="" INSTALLAUTOMATICALLY=yes INSTALLPORTABLE=No ADDLOCAL=Binary
//msiexec /a PATH TARGETDIR="" INSTALLAUTOMATICALLY=yes INSTALLPORTABLE=yes ADDLOCAL=Binary

var startInfo = new ProcessStartInfo
{
FileName = "msiexec",
Arguments = $" {(isInstaller ? "/i" : "/a")} \"{nonRoot}\"" +
$" {(isInstaller ? "INSTALLDIR" : "TARGETDIR")}=\"{AppDomain.CurrentDomain.BaseDirectory}\" INSTALLAUTOMATICALLY=yes INSTALLPORTABLE={(isInstaller ? "no" : "yes")}" +
$" ADDLOCAL=Binary{(isInstaller ? ",Auxiliar" : "")}{(hasSharpDx ? ",SharpDX" : "")}{(hasGifski ? ",Gifski" : "")}" +
$" {(wasPromptedManually ? "RUNAFTER=yes" : "")}" +
$" {(wasPromptedManually && runAfterwards ? "RUNAFTER=yes" : "")}" +
(isInstaller ? $" INSTALLDESKTOPSHORTCUT={(hasDesktopShortcut ? "yes" : "no")} INSTALLSHORTCUT={(hasMenuShortcut ? "yes" : "no")}" : ""),
Verb = UserSettings.All.ForceUpdateAsAdmin ? "runas" : ""
};
Expand Down
46 changes: 33 additions & 13 deletions ScreenToGif/Model/FrameInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.Serialization;
using System.Windows;
Expand Down Expand Up @@ -45,11 +45,11 @@ public FrameInfo(string path, int delay, List<SimpleKeyGesture> keyList) : this(
/// <summary>
/// Initialises a FrameInfo instance.
/// </summary>
/// <param name="clicked">True if the user clicked with the mouse.</param>
/// <param name="button">Type of mouse button clicked with the mouse.</param>
/// <param name="keyList">The list of pressed keys.</param>
public FrameInfo(bool clicked, List<SimpleKeyGesture> keyList)
public FrameInfo(MouseButtonType button, List<SimpleKeyGesture> keyList)
{
WasClicked = clicked;
ButtonClicked = button;
KeyList = keyList != null ? new List<SimpleKeyGesture>(keyList) : new List<SimpleKeyGesture>();
}

Expand All @@ -58,12 +58,12 @@ public FrameInfo(bool clicked, List<SimpleKeyGesture> keyList)
/// </summary>
/// <param name="path">The Bitmap.</param>
/// <param name="delay">The delay.</param>
/// <param name="clicked">True if the user clicked with the mouse.</param>
/// <param name="button">Type of mouse button the user clicked with the mouse.</param>
/// <param name="keyList">The list of pressed keys.</param>
/// <param name="index">The index of the frame.</param>
public FrameInfo(string path, int delay, bool clicked, List<SimpleKeyGesture> keyList = null, int index = 0) : this(path, delay)
public FrameInfo(string path, int delay, MouseButtonType button, List<SimpleKeyGesture> keyList = null, int index = 0) : this(path, delay)
{
WasClicked = clicked;
ButtonClicked = button;
KeyList = keyList != null ? new List<SimpleKeyGesture>(keyList) : new List<SimpleKeyGesture>();
Index = index;
}
Expand All @@ -74,15 +74,15 @@ public FrameInfo(string path, int delay, bool clicked, List<SimpleKeyGesture> ke
/// <param name="path">The Bitmap.</param>
/// <param name="delay">The delay.</param>
/// <param name="cursorX">Cursor X position.</param>
/// <param name="cursorY">Cursor Y positiob</param>
/// <param name="clicked">True if the user clicked with the mouse.</param>
/// <param name="cursorY">Cursor Y position</param>
/// <param name="button">Type of mouse button user clicked with the mouse.</param>
/// <param name="keyList">The list of pressed keys.</param>
/// <param name="index">The index of the frame.</param>
public FrameInfo(string path, int delay, int cursorX, int cursorY, bool clicked, List<SimpleKeyGesture> keyList = null, int index = 0) : this(path, delay)
public FrameInfo(string path, int delay, int cursorX, int cursorY, MouseButtonType button, List<SimpleKeyGesture> keyList = null, int index = 0) : this(path, delay)
{
CursorX = cursorX;
CursorY = cursorY;
WasClicked = clicked;
ButtonClicked = button;
KeyList = keyList != null ? new List<SimpleKeyGesture>(keyList) : new List<SimpleKeyGesture>();
Index = index;
}
Expand Down Expand Up @@ -128,9 +128,15 @@ public FrameInfo(string path, int delay, int cursorX, int cursorY, bool clicked,
public int CursorY { get; set; } = int.MinValue;

/// <summary>
/// True if was clicked.
/// Type of the button that was clicked.
/// </summary>
[DataMember(EmitDefaultValue = false, Name = "Clicked")]
[DataMember(EmitDefaultValue = false, Name = "ButtonClicked")]
public MouseButtonType ButtonClicked { get; set; }

/// <summary>
/// If the button was clicked (legacy projects)
/// </summary>
[DataMember(Name = "Clicked")]
public bool WasClicked { get; set; }

/// <summary>
Expand Down Expand Up @@ -190,6 +196,20 @@ public FrameInfo(string path, int delay, int cursorX, int cursorY, bool clicked,
[IgnoreDataMember]
public Image Image { get; set; }


/// <summary>
/// This works as a migration method for mouse clicks. Before storing the button
/// type only bool was stored to mark the clicks. During opening old project it will
/// be converted to Left mouse button click loosing some info unfortunately.
/// </summary>
/// <param name="context"></param>
[OnDeserialized]
void MigrateData(StreamingContext context)
{
if (ButtonClicked == MouseButtonType.None)
ButtonClicked = WasClicked ? MouseButtonType.Left : MouseButtonType.None;
}

#endregion
}
}
35 changes: 28 additions & 7 deletions ScreenToGif/Model/MouseClicksModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace ScreenToGif.Model
{
public class MouseClicksModel : DefaultTaskModel
{
private Color _foregroundColor;
private Color _leftButtonForegroundColor;
private Color _rightButtonForegroundColor;
private Color _middleButtonForegroundColor;
private double _width;
private double _height;

Expand All @@ -15,10 +17,22 @@ public MouseClicksModel()
TaskType = TaskTypeEnum.MouseClicks;
}

public Color ForegroundColor
public Color LeftButtonForegroundColor
{
get => _foregroundColor;
set => SetProperty(ref _foregroundColor, value);
get => _leftButtonForegroundColor;
set => SetProperty(ref _leftButtonForegroundColor, value);
}

public Color RightButtonForegroundColor
{
get => _rightButtonForegroundColor;
set => SetProperty(ref _rightButtonForegroundColor, value);
}

public Color MiddleButtonForegroundColor
{
get => _middleButtonForegroundColor;
set => SetProperty(ref _middleButtonForegroundColor, value);
}

public double Width
Expand All @@ -35,14 +49,19 @@ public double Height

public override string ToString()
{
return $"{LocalizationHelper.Get("S.Caption.Color")} #{ForegroundColor.A:X2}{ForegroundColor.R:X2}{ForegroundColor.G:X2}{ForegroundColor.B:X2}, {LocalizationHelper.Get("S.FreeDrawing.Width")} {Width}, {LocalizationHelper.Get("S.FreeDrawing.Height")} {Height}";
return $"{LocalizationHelper.Get("S.MouseClicks.Color.Left")} #{LeftButtonForegroundColor.A:X2}{LeftButtonForegroundColor.R:X2}{LeftButtonForegroundColor.G:X2}{LeftButtonForegroundColor.B:X2}, "+
$"{LocalizationHelper.Get("S.MouseClicks.Color.Middle")} #{MiddleButtonForegroundColor.A:X2}{MiddleButtonForegroundColor.R:X2}{MiddleButtonForegroundColor.G:X2}{MiddleButtonForegroundColor.B:X2}, "+
$"{LocalizationHelper.Get("S.MouseClicks.Color.Right")} #{RightButtonForegroundColor.A:X2}{RightButtonForegroundColor.R:X2}{RightButtonForegroundColor.G:X2}{RightButtonForegroundColor.B:X2}, "+
$"{LocalizationHelper.Get("S.FreeDrawing.Width")} {Width}, {LocalizationHelper.Get("S.FreeDrawing.Height")} {Height}";
}

public static MouseClicksModel Default()
{
return new MouseClicksModel
{
ForegroundColor = Color.FromArgb(120, 255, 255, 0),
LeftButtonForegroundColor = Color.FromArgb(120, 255, 255, 0),
RightButtonForegroundColor = Color.FromArgb(120, 255, 0, 0),
MiddleButtonForegroundColor = Color.FromArgb(120, 0, 255,255),
Height = 12,
Width = 12
};
Expand All @@ -52,7 +71,9 @@ public static MouseClicksModel FromSettings()
{
return new MouseClicksModel
{
ForegroundColor = UserSettings.All.MouseClicksColor,
LeftButtonForegroundColor = UserSettings.All.LeftMouseButtonClicksColor,
MiddleButtonForegroundColor = UserSettings.All.MiddleMouseButtonClicksColor,
RightButtonForegroundColor = UserSettings.All.RightMouseButtonClicksColor,
Height = UserSettings.All.MouseClicksHeight,
Width = UserSettings.All.MouseClicksWidth
};
Expand Down
4 changes: 2 additions & 2 deletions ScreenToGif/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.30.0.0")]
[assembly: AssemblyFileVersion("2.30.0.0")]
[assembly: AssemblyVersion("2.31.0.0")]
[assembly: AssemblyFileVersion("2.31.0.0")]
11 changes: 4 additions & 7 deletions ScreenToGif/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ This is the current project of ScreenToGif.

_VS 2019 and .Net 4.8 or newer required._

## What's new? (Version 2.30)
## What's new? (Version 2.31)

• Added presets for exporting Mp4 and Mov for Twitter.
• Improved performance in previewing animations (thanks to @mabakay).
• Added option for theme to follow the system's one (thanks to @pawlos).

### Fixed:

#873 - The multi-frame selection was getting lost after removing all previous/next frames (thanks to @pawlos).
#883 - Cancelling the media insertion by pressing the cancel button was causing a crash (thanks to @pawlos).
#885 - The button to open the file after encoding was not appearing.
#887 - The Caption was not being rendered correctly.
♦ The updater now waits for files being blocked by other processes before continuing.
♦ Imgur upload was not working properly unless sending in authenticated mode and selecting an album.

### Known Bugs:

Expand Down
Loading

0 comments on commit a55178d

Please sign in to comment.