public MainViewModel()
{
_timer = new Timer(1000);
_timer.Elapsed += TimerOnElapsed;
#region Commands
ScreenShotCommand = new DelegateCommand(CaptureScreenShot, () => _canScreenShot);
RecordCommand = new DelegateCommand(() =>
{
if (ReadyToRecord)
StartRecording();
else StopRecording();
}, () => _canRecord);
RefreshCommand = new DelegateCommand(() =>
{
VideoViewModel.RefreshVideoSources();
VideoViewModel.RefreshCodecs();
AudioViewModel.RefreshAudioSources();
Status = $"{VideoViewModel.AvailableCodecs.Count} Encoder(s) and {AudioViewModel.AvailableAudioSources.Count - 1} AudioDevice(s) found";
});
OpenOutputFolderCommand = new DelegateCommand(() => Process.Start("explorer.exe", OutPath));
PauseCommand = new DelegateCommand(() =>
{
if (IsPaused)
{
_recorder.Start();
_timer.Start();
IsPaused = false;
Status = "Recording...";
}
else
{
_recorder.Pause();
_timer.Stop();
IsPaused = true;
Status = "Paused";
}
}, () => !ReadyToRecord && _recorder != null);
SelectOutputFolderCommand = new DelegateCommand(() =>
{
var dlg = new FolderBrowserDialog
{
SelectedPath = OutPath,
Description = "Select Output Folder"
};
if (dlg.ShowDialog() != DialogResult.OK)
return;
OutPath = dlg.SelectedPath;
Settings.Default.OutputPath = dlg.SelectedPath;
Settings.Default.Save();
});
#endregion
//Populate Available Codecs, Audio and Video Sources ComboBoxes
RefreshCommand.Execute(null);
AudioViewModel.PropertyChanged += (Sender, Args) =>
{
if (Args.PropertyName == nameof(AudioViewModel.SelectedAudioSource))
CheckFunctionalityAvailability();
};
VideoViewModel.PropertyChanged += (Sender, Args) =>
{
if (Args.PropertyName == nameof(VideoViewModel.SelectedVideoSource))
CheckFunctionalityAvailability();
};
_cursor = new MouseCursor(OthersViewModel.Cursor);
OthersViewModel.PropertyChanged += (Sender, Args) =>
{
switch (Args.PropertyName)
{
case nameof(OthersViewModel.RegionSelectorVisible):
VideoViewModel.RefreshVideoSources();
break;
case nameof(OthersViewModel.Cursor):
_cursor.Include = OthersViewModel.Cursor;
break;
}
};
// If Output Dircetory is not set. Set it to Documents\Captura\
if (string.IsNullOrWhiteSpace(OutPath))
OutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Captura\\");
// Create the Output Directory if it does not exist
if (!Directory.Exists(OutPath))
Directory.CreateDirectory(OutPath);
Settings.Default.OutputPath = OutPath;
Settings.Default.Save();
}