Skip to content

Commit

Permalink
Added a settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
flare561 committed Jan 25, 2017
1 parent 536f473 commit 6ff2f41
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 85 deletions.
11 changes: 11 additions & 0 deletions Rippy/AlbumData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ public string Medium
set { _medium = value; OnPropertyChanged("Medium"); }
}

public List<string> Trackers
{
get { return Rippy.Properties.Settings.Default.Trackers.Split(',').ToList(); }
}

public string TrackersString
{
get { return Rippy.Properties.Settings.Default.Trackers; }
set { Rippy.Properties.Settings.Default.Trackers = value; OnPropertyChanged("Trackers"); OnPropertyChanged("TrackersString"); }
}

public string Tracker
{
get { return _tracker; }
Expand Down
10 changes: 2 additions & 8 deletions Rippy/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@
<setting name="TorrentDirectory" serializeAs="String">
<value>.\Torrents\</value>
</setting>
<setting name="Trackers" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>https://example.com/stuff/announce</string>
<string>https://example2.com/stuff2/announce</string>
</ArrayOfString>
</value>
<setting name="Trackers" serializeAs="String">
<value>https://example1.com/stuff/announce,https://example2.com/stuff2/announce</value>
</setting>
</Rippy.Properties.Settings>
</userSettings>
Expand Down
96 changes: 89 additions & 7 deletions Rippy/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
</Style>
</Window.Resources>
<Grid Margin="0,0,0,0">
<Button Panel.ZIndex="3" x:Name="settingsBtn" Content="Settings ⚙️" Style="{StaticResource LinkButton}" HorizontalAlignment="Left" Margin="440,6,0,0" VerticalAlignment="Top" Width="64" Click="settingsBtn_Click" IsEnabled="False" Visibility="Hidden"/>
<Button Panel.ZIndex="3" x:Name="settingsBtn" Content="Settings ⚙️" Style="{StaticResource LinkButton}" HorizontalAlignment="Left" Margin="440,6,0,0" VerticalAlignment="Top" Width="64" Click="settingsBtn_Click" />
<StackPanel Panel.ZIndex="2" Name="pnlLeftMenu" Orientation="Horizontal" HorizontalAlignment="Left" Margin="-524,0,0,0" IsEnabled="False">
<Border BorderBrush="#444444" BorderThickness="1" Width="524" Background="#444444" >
<Border BorderBrush="#444444" BorderThickness="1" Width="524" Background="#777777" >
<Grid>
<TextBox Name="dbPowerAmpTbx" Margin="10,37,0,0" HorizontalAlignment="Left" Width="303" Height="23" VerticalAlignment="Top" Text="{Binding Source={x:Static properties:Settings.Default},Path=DBPowerampLocation,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<Label Content="dBPoweramp coreconverter.exe Location" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<TextBox Name="dbPowerAmpTbx" Margin="10,36,0,0" HorizontalAlignment="Left" Width="303" Height="23" VerticalAlignment="Top" Text="{Binding Source={x:Static properties:Settings.Default},Path=DBPowerampLocation,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<TextBox.ToolTip>
dBpoweramp coreconverter.exe Location
</TextBox.ToolTip>
Expand All @@ -65,8 +66,10 @@
</Style>
</TextBox.Style>
</TextBox>
<Button x:Name="dbBrowseBtn" Content="Browse" HorizontalAlignment="Left" Margin="318,37,0,0" VerticalAlignment="Top" Width="70" Height="23"/>
<TextBox Name="mp3TagTbx" Margin="10,65,0,0" HorizontalAlignment="Left" Width="303" Height="23" VerticalAlignment="Top" Text="{Binding Source={x:Static properties:Settings.Default},Path=MP3TagLocation,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<Button x:Name="dbBrowseBtn" Content="Browse" HorizontalAlignment="Left" Margin="318,36,0,0" VerticalAlignment="Top" Width="70" Height="23" Click="dbBrowseBtn_Click"/>

<Label Content="Mp3tag.exe Location" HorizontalAlignment="Left" Margin="10,64,0,0" VerticalAlignment="Top"/>
<TextBox Name="mp3TagTbx" Margin="10,90,0,0" HorizontalAlignment="Left" Width="303" Height="23" VerticalAlignment="Top" Text="{Binding Source={x:Static properties:Settings.Default},Path=MP3TagLocation,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
<TextBox.ToolTip>
Mp3tag.exe Location
</TextBox.ToolTip>
Expand All @@ -93,7 +96,86 @@
</Style>
</TextBox.Style>
</TextBox>
<Button x:Name="mp3TagBrowseBtn" Content="Browse" HorizontalAlignment="Left" Margin="318,65,0,0" VerticalAlignment="Top" Width="70" Height="23"/>
<Button x:Name="mp3TagBrowseBtn" Content="Browse" HorizontalAlignment="Left" Margin="318,90,0,0" VerticalAlignment="Top" Width="70" Height="23" Click="mp3TagBrowseBtn_Click"/>
<Label Content="Output Directory" HorizontalAlignment="Left" Margin="10,118,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="outputTbx" Margin="10,144,0,0" HorizontalAlignment="Left" Width="184" Height="23" VerticalAlignment="Top" Text="{Binding OutputDirectory, Mode=TwoWay, Source={x:Static properties:Settings.Default}, UpdateSourceTrigger=PropertyChanged}">
<TextBox.ToolTip>Output Directory</TextBox.ToolTip>
<TextBox.Style>
<Style xmlns:sys="clr-namespace:System;assembly=mscorlib" TargetType="{x:Type TextBox}">
<Style.Resources>
<VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None" >
<VisualBrush.Visual>
<Label Content="Output Directory" Foreground="Gray" Background="White" Width="303" Height="23"/>
</VisualBrush.Visual>
</VisualBrush>
</Style.Resources>
<Style.Triggers>
<Trigger Property="Text" Value="{x:Static sys:String.Empty}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter Property="Background" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<Label Content="Torrent Directory" HorizontalAlignment="Left" Margin="204,118,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="torrentTbx" Margin="204,144,0,0" HorizontalAlignment="Left" Width="184" Height="23" VerticalAlignment="Top" Text="{Binding TorrentDirectory, Mode=TwoWay, Source={x:Static properties:Settings.Default}, UpdateSourceTrigger=PropertyChanged}">
<TextBox.ToolTip>Torrent Directory</TextBox.ToolTip>
<TextBox.Style>
<Style xmlns:sys="clr-namespace:System;assembly=mscorlib" TargetType="{x:Type TextBox}">
<Style.Resources>
<VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None" >
<VisualBrush.Visual>
<Label Content="Torrent Directory" Foreground="Gray" Background="White" Width="303" Height="23"/>
</VisualBrush.Visual>
</VisualBrush>
</Style.Resources>
<Style.Triggers>
<Trigger Property="Text" Value="{x:Static sys:String.Empty}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter Property="Background" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<Label Content="Trackers" HorizontalAlignment="Left" Margin="10,172,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="trackersTbx" Margin="10,203,0,0" HorizontalAlignment="Left" Width="378" Height="22" VerticalAlignment="Top" Text="{Binding TrackersString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextChanged="trackersTbx_TextChanged">
<TextBox.ToolTip>Trackers (Separate multiple trackers with a comma)</TextBox.ToolTip>
<TextBox.Style>
<Style xmlns:sys="clr-namespace:System;assembly=mscorlib" TargetType="{x:Type TextBox}">
<Style.Resources>
<VisualBrush x:Key="CueBannerBrush" AlignmentX="Left" AlignmentY="Center" Stretch="None" >
<VisualBrush.Visual>
<Label Content="Trackers" Foreground="Gray" Background="White" Width="378" Height="23"/>
</VisualBrush.Visual>
</VisualBrush>
</Style.Resources>
<Style.Triggers>
<Trigger Property="Text" Value="{x:Static sys:String.Empty}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
<Trigger Property="Text" Value="{x:Null}">
<Setter Property="Background" Value="{StaticResource CueBannerBrush}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter Property="Background" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<Button x:Name="saveBtn" Content="Save" HorizontalAlignment="Left" Margin="313,230,0,0" VerticalAlignment="Top" Width="75" Click="saveBtn_Click"/>
</Grid>
</Border>
</StackPanel>
Expand Down Expand Up @@ -296,7 +378,7 @@
</TextBox.Style>
</TextBox>
<Label Content="Tracker" HorizontalAlignment="Left" Margin="10,206,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.558,2.439"/>
<ComboBox x:Name="trackersCobx" HorizontalAlignment="Left" Margin="10,237,0,0" VerticalAlignment="Top" Width="494" ItemsSource="{Binding Path=SettingsObj.Trackers, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" SelectedItem="{Binding Path=Tracker, UpdateSourceTrigger=PropertyChanged}"/>
<ComboBox x:Name="trackersCobx" HorizontalAlignment="Left" Margin="10,237,0,0" VerticalAlignment="Top" Width="494" ItemsSource="{Binding Path=Trackers, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding Path=Tracker, UpdateSourceTrigger=PropertyChanged}"/>
<CheckBox x:Name="mp3320Cbx" Content="MP3 320" HorizontalAlignment="Left" Margin="256,264,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=MP3320, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"/>
<CheckBox x:Name="mp3V0Cbx" Content="MP3 V0" HorizontalAlignment="Left" Margin="327,264,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=MP3V0, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"/>
<CheckBox x:Name="mp3V2Cbx" Content="MP3 V2" HorizontalAlignment="Left" Margin="392,264,0,0" VerticalAlignment="Top" IsChecked="{Binding Path=MP3V2, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"/>
Expand Down
50 changes: 37 additions & 13 deletions Rippy/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ public partial class MainWindow : Window
public bool MP3V0 { get; set; } = true;
public bool MP3V2 { get; set; } = false;
public bool FLAC { get; set; } = false;
public Settings SettingsObj { get; set; }

public MainWindow()
{
InitializeComponent();
_albumData = new AlbumData();
DataContext = _albumData;
SettingsObj = Settings.Load();
_albumData.Tracker = SettingsObj.Trackers[0];
_albumData.Tracker = _albumData.Trackers[0];
_createProgressDialog.DoWork += _createProgressDialog_DoWork;
_createProgressDialog.RunWorkerCompleted += _createProgressDialog_RunWorkerCompleted;
}
Expand All @@ -64,12 +62,12 @@ public MainWindow()
/// <param name="name"></param>
private void CreateFolder(string name)
{
if (!Directory.Exists(SettingsObj.OutputDirectory))
Directory.CreateDirectory(SettingsObj.OutputDirectory);
if (!Directory.Exists(SettingsObj.TorrentDirectory))
Directory.CreateDirectory(SettingsObj.TorrentDirectory);
if (!Directory.Exists(Rippy.Properties.Settings.Default.OutputDirectory))
Directory.CreateDirectory(Rippy.Properties.Settings.Default.OutputDirectory);
if (!Directory.Exists(Rippy.Properties.Settings.Default.TorrentDirectory))
Directory.CreateDirectory(Rippy.Properties.Settings.Default.TorrentDirectory);

Directory.CreateDirectory(Path.Combine(SettingsObj.OutputDirectory, name));
Directory.CreateDirectory(Path.Combine(Rippy.Properties.Settings.Default.OutputDirectory, name));
}

/// <summary>
Expand Down Expand Up @@ -113,7 +111,7 @@ private bool TranscodeFiles(string directory, string dbargs, int totalFiles)
{
var convProc = new Process
{
StartInfo = new ProcessStartInfo(SettingsObj.DBPowerampLocation, $"-infile=\"{infile.FullName}\" -outfile=\"{outfile.FullName}\" -convert_to\"mp3 (Lame)\" {dbargs}")
StartInfo = new ProcessStartInfo(Rippy.Properties.Settings.Default.DBPowerampLocation, $"-infile=\"{infile.FullName}\" -outfile=\"{outfile.FullName}\" -convert_to\"mp3 (Lame)\" {dbargs}")
{
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
Expand All @@ -139,14 +137,14 @@ private void CreateTorrent(string directory, string name)
tc.Private = true;
tc.Announces.Add(new List<string>() { _albumData.Tracker });
tc.Source = "PTH";
tc.Create(new TorrentFileSource(directory), Path.Combine(SettingsObj.TorrentDirectory, $"{name}.torrent"));
tc.Create(new TorrentFileSource(directory), Path.Combine(Rippy.Properties.Settings.Default.TorrentDirectory, $"{name}.torrent"));
}


private bool ProcessDirectory(string name, string dbargs, int totalFiles)
{
CreateFolder(name);
var directory = Path.Combine(SettingsObj.OutputDirectory, name);
var directory = Path.Combine(Rippy.Properties.Settings.Default.OutputDirectory, name);
CopyFiles(directory);
if (!TranscodeFiles(directory, dbargs, totalFiles))
return false;
Expand Down Expand Up @@ -194,7 +192,7 @@ private void browseBtn_Click(object sender, RoutedEventArgs e)
private async void metadataBtn_Click(object sender, RoutedEventArgs e)
{
mainWindow.IsEnabled = false;
await HelperMethods.RunProcessAsync(SettingsObj.MP3TagLocation, $"\"{_albumData.FlacFolder}\"");
await HelperMethods.RunProcessAsync(Rippy.Properties.Settings.Default.MP3TagLocation, $"\"{_albumData.FlacFolder}\"");
mainWindow.IsEnabled = true;
UpdateMetadata();
}
Expand Down Expand Up @@ -252,6 +250,32 @@ private void settingsBtn_Click(object sender, RoutedEventArgs e)
MainWindowGrid.IsEnabled = false;
}
}


private void dbBrowseBtn_Click(object sender, RoutedEventArgs e)
{
var dialog = new Ookii.Dialogs.Wpf.VistaOpenFileDialog();
dialog.FileName = _albumData.FlacFolder;
var result = dialog.ShowDialog();
Rippy.Properties.Settings.Default.DBPowerampLocation = dialog.FileName;
}

private void mp3TagBrowseBtn_Click(object sender, RoutedEventArgs e)
{

var dialog = new Ookii.Dialogs.Wpf.VistaOpenFileDialog();
dialog.FileName = _albumData.FlacFolder;
var result = dialog.ShowDialog();
Rippy.Properties.Settings.Default.MP3TagLocation = dialog.FileName;
}

private void saveBtn_Click(object sender, RoutedEventArgs e)
{
Rippy.Properties.Settings.Default.Save();
}

private void trackersTbx_TextChanged(object sender, TextChangedEventArgs e)
{
trackersCobx?.GetBindingExpression(ComboBox.ItemsSourceProperty)?.UpdateSource();
}
}
}
10 changes: 3 additions & 7 deletions Rippy/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6ff2f41

Please sign in to comment.