145 lines
5.0 KiB
C#
145 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using SingsALot.Classes;
|
|
using System.Diagnostics;
|
|
using System.Configuration;
|
|
|
|
namespace SingsALot
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
public string _UserSettingsPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\settings.xml";
|
|
public bool loading = true;
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
this.settings = new UserSettings();
|
|
// if default settings exist
|
|
if (File.Exists(_UserSettingsPath))
|
|
{
|
|
|
|
this.settings = settings.Read(_UserSettingsPath);
|
|
songsLocation.Text = this.settings.songsLocationPath;
|
|
controllerName.Text = this.settings.controllerName;
|
|
}
|
|
loading = false;
|
|
}
|
|
public UserSettings settings { get; private set; }
|
|
|
|
public void SaveUserSettings()
|
|
{
|
|
if (loading) return;
|
|
settings.controllerName = controllerName.Text.Trim();
|
|
settings.songsLocationPath = songsLocation.Text.Trim();
|
|
settings.Save(_UserSettingsPath);
|
|
|
|
string playerConfig = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\KaraokePlayer.exe";
|
|
Configuration config = ConfigurationManager.OpenExeConfiguration(playerConfig);
|
|
config.AppSettings.Settings["KaraokePlayer.ControllerId"].Value = settings.controllerName;
|
|
config.Save(ConfigurationSaveMode.Modified);
|
|
|
|
}
|
|
|
|
private void controllerName_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
CheckVariables();
|
|
SaveUserSettings();
|
|
}
|
|
|
|
private void songsLocation_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
CheckVariables();
|
|
SaveUserSettings();
|
|
}
|
|
|
|
private void CheckVariables()
|
|
{
|
|
if (controllerName.Text.Trim() != string.Empty)
|
|
{
|
|
launchPlayerButton.IsEnabled = true;
|
|
if (songsLocation.Text.Trim() != string.Empty)
|
|
{
|
|
syncLibraryButton.IsEnabled = true;
|
|
updateBillboardButton.IsEnabled = true;
|
|
}
|
|
else
|
|
{
|
|
syncLibraryButton.IsEnabled = false;
|
|
updateBillboardButton.IsEnabled = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
launchPlayerButton.IsEnabled = false;
|
|
syncLibraryButton.IsEnabled = false;
|
|
updateBillboardButton.IsEnabled = false;
|
|
}
|
|
}
|
|
|
|
private void songsLocationButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var d = new Gat.Controls.OpenDialogView();
|
|
var vm = (Gat.Controls.OpenDialogViewModel)d.DataContext;
|
|
bool? result = vm.Show();
|
|
if (result == true)
|
|
{
|
|
// Get selected file path
|
|
songsLocation.Text = vm.SelectedFolder.Path;
|
|
}
|
|
else
|
|
{
|
|
songsLocation.Text = string.Empty;
|
|
}
|
|
}
|
|
|
|
private void launchPlayerButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ProcessStartInfo startInfo = new ProcessStartInfo();
|
|
startInfo.FileName = "KaraokePlayer.exe";
|
|
Process.Start(startInfo);
|
|
}
|
|
|
|
private void syncLibraryButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ProcessStartInfo startInfo = new ProcessStartInfo();
|
|
startInfo.FileName = "SongCrawler.exe";
|
|
startInfo.Arguments = string.Format("{0} {1}", this.settings.controllerName, this.settings.songsLocationPath);
|
|
Process.Start(startInfo);
|
|
|
|
}
|
|
|
|
private void updateBillboardButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ProcessStartInfo startInfo = new ProcessStartInfo();
|
|
startInfo.FileName = "BillboardPlaylistUpdater.exe";
|
|
startInfo.Arguments = this.settings.controllerName;
|
|
Process.Start(startInfo);
|
|
}
|
|
|
|
private void deleteSongsButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ProcessStartInfo startInfo = new ProcessStartInfo();
|
|
startInfo.FileName = "SongCrawler.exe";
|
|
startInfo.Arguments = string.Format("{0} {1} {2}", this.settings.controllerName, this.settings.songsLocationPath, "delete");
|
|
Process.Start(startInfo);
|
|
}
|
|
}
|
|
}
|