Skip to content

Commit

Permalink
내가 원하는 프로그램의 개발 방향과 동떨어진 커밋들을 되돌립니다.
Browse files Browse the repository at this point in the history
Revert "Prevent entering of record setting, capture region selection and open recording folder during capturing"

This reverts commit 40bd1ba.

Revert "Set window display affinity only after rendering of main window"

Revert "Selecting of capture target will not start capturing, last selected target will be saved including position and size"

This reverts commit d10c107.

Revert "Change tooltip for selecting capture target"

This reverts commit 29eacee.

Revert "Fix selecting capture target where primary monitor is beneath secondary one. Maybe fixes issue #30"

This reverts commit 2d1f2a4.

Revert "Optional time controlled capture"

This reverts commit 374c2e5.

Revert "Implement end of time controlled capture"

This reverts commit 4223fbe.

Revert "Optional resizing of capture target window during selection"

Revert "Implement program exit for time controlled capture"

This reverts commit 5e91779.

Revert "Fix resize window during target selection"

This reverts commit a13e76b.

Revert "possible minimize to system tray"

Revert "Refactor loading of configuration"

This reverts commit 6dd139f.

Revert "added button for target selection in record settings"

This reverts commit 37b92ce.

Revert "prevent closing of program for manual abort of time controlled capture"

This reverts commit f6f2f68.
  • Loading branch information
akon47 committed Jun 23, 2022
1 parent 4ffc4a0 commit a6c969f
Show file tree
Hide file tree
Showing 22 changed files with 336 additions and 1,048 deletions.
50 changes: 0 additions & 50 deletions ScreenRecorder/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Diagnostics;

namespace ScreenRecorder
{
Expand All @@ -12,28 +11,6 @@ namespace ScreenRecorder
public partial class App : Application
{
public volatile static Mutex Mutex = null;
public System.Windows.Forms.NotifyIcon NotifyIcon { get; private set; }

public App()
{
NotifyIcon = new System.Windows.Forms.NotifyIcon();
NotifyIcon.Visible = false;
NotifyIcon.Click += OnNotifyIconClick;
NotifyIcon.Text = AppConstants.AppName;
var iconUri = new Uri("/icon.ico", UriKind.Relative);
using (var iconStream = Application.GetResourceStream(iconUri).Stream)
{
NotifyIcon.Icon = new System.Drawing.Icon(iconStream);
}
}

void OnNotifyIconClick(object sender, EventArgs e)
{
// restore program from system tray to desktop
MainWindow.Visibility = Visibility.Visible;
MainWindow.WindowState = WindowState.Normal;
NotifyIcon.Visible = false;
}

protected override void OnStartup(StartupEventArgs e)
{
Expand All @@ -53,7 +30,6 @@ protected override void OnStartup(StartupEventArgs e)

VideoClockEvent.Start();
AppManager.Instance.Initialize();
AppManager.Instance.PropertyChanged += Instance_PropertyChanged;
AppConfig.Instance.WhenChanged(() =>
{
VideoClockEvent.Framerate = AppConfig.Instance.AdvancedSettings ?
Expand All @@ -77,38 +53,12 @@ protected override void OnStartup(StartupEventArgs e)
}
}

private void Instance_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName.Equals("IsStarted")
|| e.PropertyName.Equals("IsStartedWithEncode")
|| e.PropertyName.Equals("IsPaused")
|| e.PropertyName.Equals("IsStopped")
)
{
Debug.WriteLine($"{e.PropertyName}: isStart: {AppManager.Instance.ScreenEncoder.IsStarted}, isEncode:{AppManager.Instance.ScreenEncoder.IsStartedWithEncode}");
NotifyIcon.Text = AppConstants.AppName;
if (AppManager.Instance.ScreenEncoder.IsStarted && !AppManager.Instance.ScreenEncoder.IsStartedWithEncode)
NotifyIcon.Text += " waiting for start ...";
else if (AppManager.Instance.ScreenEncoder.IsStarted && AppManager.Instance.ScreenEncoder.IsStartedWithEncode)
NotifyIcon.Text += " recording ...";
else if (AppManager.Instance.ScreenEncoder.IsPaused)
NotifyIcon.Text += " paused ...";
else if (AppManager.Instance.ScreenEncoder.IsStopped)
NotifyIcon.Text += " stopped ...";
}
}

protected override void OnExit(ExitEventArgs e)
{
AppCommands.Instance.Dispose();
AppConfig.Instance.Dispose();
AppManager.Instance.Dispose();
VideoClockEvent.Stop();

// maybe not neccessary
NotifyIcon.Click -= OnNotifyIconClick;
NotifyIcon.Visible = false;
NotifyIcon.Dispose();

base.OnExit(e);
}
Expand Down
181 changes: 49 additions & 132 deletions ScreenRecorder/AppCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Diagnostics;
using System.Windows.Input;
using ScreenRecorder.Command;
using ScreenRecorder.Config;
using ScreenRecorder.Encoder;
using ScreenRecorder.DirectX;

namespace ScreenRecorder
{
Expand Down Expand Up @@ -183,89 +181,15 @@ public void Dispose()
private DelegateCommand startScreenRecordCommand;
private DelegateCommand pauseScreenRecordCommand;
private DelegateCommand stopScreenRecordCommand;
private DelegateCommand selectRegionCommand;
private DelegateCommand openFolderInWindowExplorerCommand;
private DelegateCommand openRecordDirecotryCommand;
private DelegateCommand selectRecordDirectory;

private DelegateCommand openShortcutSettingsCommand;

private DelegateCommand windowCloseCommand;
private DelegateCommand windowMinimizeCommand;
#endregion

private Rect? SelectDisplayAndRect (object o)
{
var region = new Rect(0, 0, double.MaxValue, double.MaxValue);
var regionSelectorWindow = new Region.RegionSelectorWindow()
{
RegionSelectionMode = AppConfig.Instance.RegionSelectionMode
};
try
{
if (!regionSelectorWindow.ShowDialog().Value)
return null;

var result = regionSelectorWindow.RegionSelectionResult;
if (result != null)
{
string displayDeviceName = result.DeviceName;
var monitorInfo = MonitorInfo.GetMonitorInfo(displayDeviceName);
Debug.Assert(monitorInfo != null);
region = result.Region;

if (AppConfig.Instance.ForceSourceSize && result.Hwnd != IntPtr.Zero)
{
int cx = AppConfig.Instance.ForcedSourceWidth;
int cy = AppConfig.Instance.ForcedSourceHeight;
// sichern gerader Zahlen ?
cx &= ~0x01;
cy &= ~0x01;

region.Width = cx;
region.Height = cy;

// rect size check with coordinates relative to according screen
Rect monitorBounds = monitorInfo.Bounds;
monitorBounds.Offset(-monitorInfo.Left, -monitorInfo.Top);
double offsetX = (region.Right > monitorBounds.Right) ? monitorBounds.Right - region.Right : 0;
double offsetY = (region.Bottom > monitorBounds.Bottom) ? monitorBounds.Bottom - region.Bottom : 0;
region.Offset(offsetX, offsetY);
// change window size on display with absolute coordinates
region.Offset(monitorInfo.Left, monitorInfo.Top);
Region.WindowRegion.SizeWindow(result.Hwnd, (int)(region.Left), (int)(region.Top), cx, cy, true);
// get absolute coordinates after resizing
region = Region.WindowRegion.GetWindowRectangle(result.Hwnd);
// shift absolute coordinates relative to screen with 0,0 as left,top
region.Offset(-monitorInfo.Left, -monitorInfo.Top);
}
else
{
// Ensure even numbers ?
region.Width = ((int)region.Width) & (~0x01);
region.Height = ((int)region.Height) & (~0x01);
}

if (region.Width < 100 || region.Height < 100)
{
MessageBox.Show(ScreenRecorder.Properties.Resources.RegionSizeError,
AppConstants.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
return null;
}

AppConfig.Instance.ScreenCaptureRect = region;
AppConfig.Instance.ScreenCaptureMonitor = displayDeviceName;
AppManager.Instance.ScreenCaptureMonitorDescription = monitorInfo.Description;
}
}
finally
{
AppConfig.Instance.RegionSelectionMode = regionSelectorWindow.RegionSelectionMode;
}

return region;
}

#region Record Commands
public DelegateCommand StartScreenRecordCommand => startScreenRecordCommand ??
(startScreenRecordCommand = new DelegateCommand(o =>
Expand Down Expand Up @@ -293,6 +217,8 @@ public void Dispose()
if (exts != null && exts.Length > 0)
ext += exts[0];
DateTime now = DateTime.Now;
string filePath = string.Format("{0}\\{1}-{2}{3}",
AppConfig.Instance.RecordDirectory,
AppConstants.AppName,
Expand All @@ -305,39 +231,63 @@ public void Dispose()
AppConfig.Instance.SelectedRecordVideoCodec : MediaEncoder.VideoCodec.H264;
var audioCodec = AppConfig.Instance.AdvancedSettings ?
AppConfig.Instance.SelectedRecordAudioCodec : MediaEncoder.AudioCodec.Aac;
var displayDeviceName = o is string target ? target : AppConfig.Instance.ScreenCaptureMonitor;
var region = new Rect(0, 0, double.MaxValue, double.MaxValue);
if (!AppConfig.Instance.ScreenCaptureRect.HasValue || AppConfig.Instance.ScreenCaptureRect.Value.IsEmpty)
switch(displayDeviceName)
{
// select ScreenCaptureRect and ScreenCaptureMonitor, update ScreenCaptureMonitorDescription
if (!SelectDisplayAndRect(o).HasValue)
{
MessageBox.Show("Unknown capture rect", AppConstants.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
case CaptureTarget.PrimaryCaptureTargetDeviceName:
#region Select PrimayDisplay
displayDeviceName = System.Windows.Forms.Screen.PrimaryScreen.DeviceName;
#endregion
break;
case CaptureTarget.ByUserChoiceTargetDeviceName:
#region Select Region
var regionSelectorWindow = new Region.RegionSelectorWindow()
{
RegionSelectionMode = AppConfig.Instance.RegionSelectionMode
};
try
{
if (!regionSelectorWindow.ShowDialog().Value)
{
return;
}
var result = regionSelectorWindow.RegionSelectionResult;
if (result != null)
{
displayDeviceName = result.DeviceName;
region = result.Region;
region.Width = ((int)region.Width) & (~0x01);
region.Height = ((int)region.Height) & (~0x01);
if(region.Width < 100 || region.Height < 100)
{
MessageBox.Show(ScreenRecorder.Properties.Resources.RegionSizeError,
AppConstants.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
}
}
finally
{
AppConfig.Instance.RegionSelectionMode = regionSelectorWindow.RegionSelectionMode;
}
break;
#endregion
}
MonitorInfo monitorInfo = MonitorInfo.GetMonitorInfo(AppConfig.Instance.ScreenCaptureMonitor);
if (monitorInfo == null)
throw new ArgumentException($"{AppConfig.Instance.ScreenCaptureMonitor} does not exist");
// securety check (coordinates relative to selected monitor with 0,0 as left,top)
Rect monitorRegion = new Rect(0, 0, monitorInfo.Width, monitorInfo.Height);
AppConfig.Instance.ScreenCaptureRect = Rect.Intersect(AppConfig.Instance.ScreenCaptureRect.Value, monitorRegion);
// Start Record
try
{
DateTime? captureStart = AppConfig.Instance.CaptureTimeControlled ? AppConfig.Instance.CaptureStartTime : (DateTime?)null;
DateTime? captureEnd = AppConfig.Instance.CaptureTimeControlled ? AppConfig.Instance.CaptureEndTime : (DateTime?)null;
AppManager.Instance.ScreenEncoder.Start(encodeFormat.Format, filePath,
videoCodec, AppConfig.Instance.SelectedRecordVideoBitrate,
audioCodec, AppConfig.Instance.SelectedRecordAudioBitrate,
monitorInfo.DeviceName, AppConfig.Instance.ScreenCaptureRect.Value,
displayDeviceName, region,
AppConfig.Instance.ScreenCaptureCursorVisible,
AppConfig.Instance.RecordMicrophone,
captureStart, captureEnd
);
AppConfig.Instance.RecordMicrophone);
}
catch
{
Expand All @@ -358,13 +308,7 @@ public void Dispose()
public DelegateCommand PauseScreenRecordCommand => pauseScreenRecordCommand ??
(pauseScreenRecordCommand = new DelegateCommand(o =>
{
if (AppManager.Instance.ScreenEncoder.Status == Encoder.EncoderStatus.Wait)
{
// prevent closing of program for manual stop of time controlled capture
AppManager.Instance.ScreenEncoder.StopByAutomatic = false;
AppManager.Instance.ScreenEncoder.Stop();
}
else if (AppManager.Instance.ScreenEncoder.Status == Encoder.EncoderStatus.Start)
if (AppManager.Instance.ScreenEncoder.Status == Encoder.EncoderStatus.Start)
{
AppManager.Instance.ScreenEncoder.Pause();
}
Expand All @@ -375,22 +319,10 @@ public void Dispose()
{
if (AppManager.Instance.ScreenEncoder.Status != Encoder.EncoderStatus.Stop)
{
// prevent closing of program for manual stop of time controlled capture
AppManager.Instance.ScreenEncoder.StopByAutomatic = false;
AppManager.Instance.ScreenEncoder.Stop();
}
}));

public DelegateCommand SelectRegionCommand => selectRegionCommand ??
(selectRegionCommand = new DelegateCommand(o =>
{
if (AppManager.Instance.ScreenEncoder.Status != Encoder.EncoderStatus.Stop)
return;
AppManager.Instance.RecordSettingChecked = false;
SelectDisplayAndRect(o);
}));

public DelegateCommand SelectRecordDirectory => selectRecordDirectory ??
(selectRecordDirectory = new DelegateCommand(o =>
{
Expand Down Expand Up @@ -466,7 +398,6 @@ public void Dispose()
#endregion

#region Window Commands

public DelegateCommand WindowCloseCommand => windowCloseCommand ??
(windowCloseCommand = new DelegateCommand(o =>
{
Expand All @@ -478,20 +409,6 @@ public void Dispose()
{
return o is Window;
}));

public DelegateCommand WindowMinimizeCommand => windowMinimizeCommand ??
(windowMinimizeCommand = new DelegateCommand(o =>
{
var mainWnd = Application.Current.MainWindow;
if (Application.Current is App myApp)
{
myApp.NotifyIcon.Visible = true;
mainWnd.Hide();
}
else
SystemCommands.MinimizeWindow(mainWnd);
}));

#endregion
}
}
Loading

0 comments on commit a6c969f

Please sign in to comment.