Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MathewSachin committed Mar 25, 2019
1 parent fc720fa commit 0eec186
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 110 deletions.
4 changes: 2 additions & 2 deletions src/Captura.FFmpeg/Audio/FFmpegAudioWriter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Captura.Audio;
using System;
using System.Diagnostics;
using System.IO;
using Captura.FFmpeg;

namespace Captura.Models
{
Expand Down Expand Up @@ -47,7 +47,7 @@ public void Write(byte[] Data, int Offset, int Count)
{
if (_ffmpegProcess.HasExited)
{
throw new Exception("An Error Occurred with FFmpeg");
throw new FFmpegException(_ffmpegProcess.ExitCode);
}

_ffmpegIn.Write(Data, Offset, Count);
Expand Down
38 changes: 38 additions & 0 deletions src/Captura.FFmpeg/FFmpegTrimmer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Threading.Tasks;
using Captura.Models;

namespace Captura.FFmpeg
{
public class FFmpegTrimmer
{
public async Task Run(string SourceFile,
TimeSpan From,
TimeSpan To,
string DestFile,
bool HasAudio)
{
var argsBuilder = new FFmpegArgsBuilder();

var inputArgs = argsBuilder.AddInputFile(SourceFile)
.AddArg($"-ss {From}")
.AddArg($"-to {To}");

if (HasAudio)
inputArgs.SetAudioCodec("copy");

argsBuilder.AddOutputFile(DestFile);

var args = argsBuilder.GetArgs();

var process = FFmpegService.StartFFmpeg(args, DestFile);

await Task.Factory.StartNew(process.WaitForExit);

if (process.ExitCode != 0)
{
throw new FFmpegException(process.ExitCode);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Captura.FFmpeg/Video/FFmpegVideoWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void WriteAudio(byte[] Buffer, int Length)
{
if (_ffmpegProcess.HasExited)
{
throw new Exception("An Error Occurred with FFmpeg");
throw new FFmpegException( _ffmpegProcess.ExitCode);
}

if (_firstAudio)
Expand Down
17 changes: 3 additions & 14 deletions src/Captura/ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Diagnostics;
using System.Windows.Input;
using Reactive.Bindings;

namespace Captura
{
Expand All @@ -23,20 +24,8 @@ public AboutViewModel(Settings Settings, ILocalizationProvider Loc) : base(Setti
{
AppVersion = "v" + Version.ToString(3);

HyperlinkCommand = new DelegateCommand(Link =>
{
if (Link is string s)
{
try
{
Process.Start(s);
}
catch
{
// Suppress Errors
}
}
});
HyperlinkCommand = new ReactiveCommand<string>()
.WithSubscribe(M => Process.Start(M));
}
}
}
15 changes: 8 additions & 7 deletions src/Captura/ViewModels/ExceptionViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.ObjectModel;
using System.Reactive.Linq;
using System.Windows.Input;
using Reactive.Bindings;
using Reactive.Bindings.Extensions;
using Screna;

namespace Captura
Expand All @@ -9,13 +12,11 @@ public class ExceptionViewModel : NotifyPropertyChanged
{
public ExceptionViewModel()
{
CopyToClipboardCommand = new DelegateCommand(() =>
{
if (Exceptions.Count > 0)
{
Exceptions[0].ToString().WriteToClipboard();
}
});
CopyToClipboardCommand = Exceptions
.ObserveProperty(M => M.Count)
.Select(M => M > 0)
.ToReactiveCommand()
.WithSubscribe(() => Exceptions[0].ToString().WriteToClipboard());
}

string _message = "An unhandled exception occurred. Here are the details.";
Expand Down
43 changes: 22 additions & 21 deletions src/Captura/ViewModels/RegionSelectorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Drawing;
using System.Windows.Input;
using Reactive.Bindings;

// ReSharper disable MemberCanBePrivate.Global

Expand All @@ -21,25 +22,31 @@ public class RegionSelectorViewModel : NotifyPropertyChanged

public RegionSelectorViewModel()
{
MoveLeftCommand = new DelegateCommand(() => Left -= KeyMoveDelta);
MoveRightCommand = new DelegateCommand(() => Left += KeyMoveDelta);
MoveUpCommand = new DelegateCommand(() => Top -= KeyMoveDelta);
MoveDownCommand = new DelegateCommand(() => Top += KeyMoveDelta);

IncreaseWidthCommand = new DelegateCommand(() => Width += KeyMoveDelta);
DecreaseWidthCommand = new DelegateCommand(() => Width -= KeyMoveDelta);
IncreaseHeightCommand = new DelegateCommand(() => Height += KeyMoveDelta);
DecreaseHeightCommand = new DelegateCommand(() => Height -= KeyMoveDelta);
MoveLeftCommand = new ReactiveCommand()
.WithSubscribe(() => Left -= KeyMoveDelta);
MoveRightCommand = new ReactiveCommand()
.WithSubscribe(() => Left += KeyMoveDelta);
MoveUpCommand = new ReactiveCommand()
.WithSubscribe(() => Top -= KeyMoveDelta);
MoveDownCommand = new ReactiveCommand()
.WithSubscribe(() => Top += KeyMoveDelta);

IncreaseWidthCommand = new ReactiveCommand()
.WithSubscribe(() => Width += KeyMoveDelta);
DecreaseWidthCommand = new ReactiveCommand()
.WithSubscribe(() => Width -= KeyMoveDelta);
IncreaseHeightCommand = new ReactiveCommand()
.WithSubscribe(() => Height += KeyMoveDelta);
DecreaseHeightCommand = new ReactiveCommand()
.WithSubscribe(() => Height -= KeyMoveDelta);
}

public int Left
{
get => _left;
set
{
_left = value;

OnPropertyChanged();
Set(ref _left, value);
RaisePropertyChanged(nameof(LeftDip));
}
}
Expand All @@ -55,9 +62,7 @@ public int Top
get => _top;
set
{
_top = value;

OnPropertyChanged();
Set(ref _top, value);
RaisePropertyChanged(nameof(TopDip));
}
}
Expand All @@ -73,9 +78,7 @@ public int Width
get => _width;
set
{
_width = Math.Max(value, MinWidth);

OnPropertyChanged();
Set(ref _width, Math.Max(value, MinWidth));
RaisePropertyChanged(nameof(WidthDip));
}
}
Expand All @@ -91,9 +94,7 @@ public int Height
get => _height;
set
{
_height = Math.Max(value, MinHeight);

OnPropertyChanged();
Set(ref _height, Math.Max(value, MinHeight));
RaisePropertyChanged(nameof(HeightDip));
}
}
Expand Down
Loading

0 comments on commit 0eec186

Please sign in to comment.