Skip to content

Commit

Permalink
Fixed some more issues. Second candidate for the beta release
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyFilter committed Jan 6, 2022
1 parent 0854144 commit 44e46dc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion FunnySounds/FunnySounds.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions FunnySounds/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="Link:" Margin="0,0,5,0"/>
<TextBox x:Name="fileTextBox" Text="Drop file here" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Grid.Column="1" Margin="0,0,5,0" Drop="FileDropped" PreviewDragOver="TextBox_PreviewDragOver" AllowDrop="True" Focusable="False"/>
<TextBox x:Name="fileTextBox" Text="Drop file here" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Grid.Column="1" Margin="0,0,5,0" AllowDrop="True" Focusable="False" Drop="FileDropped" PreviewDragOver="TextBox_PreviewDragOver"/>
<TextBox x:Name="fileSoundNameBox" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Grid.Column="2" Margin="0,0,5,0"/>
<TextBlock IsHitTestVisible="False" Text="Name" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="3,0,0,0" Foreground="DarkGray" Grid.Column="2">
<TextBlock.Style>
Expand All @@ -91,8 +91,8 @@
</Style>
</TextBlock.Style>
</TextBlock>
<Button Content="Copy file" Grid.Column="3" Click="CopyDraggedFilesClicked" Margin="0,0,5,0"/>
<Button Content="Link file" Grid.Column="4" Click="LinkDraggedFilesClicked"/>
<Button Content="Copy file" Grid.Column="3" Click="CopyDraggedFilesClicked" Margin="0,0,5,0" ToolTip="Copies the file into a super secret location in program's local folder (%appdata%\FunnySounds)"/>
<Button Content="Link file" Grid.Column="4" Click="LinkDraggedFilesClicked" ToolTip="Links the sound to already existing audio file on the disk"/>
</Grid>
</StackPanel>
</Grid>
Expand Down
41 changes: 29 additions & 12 deletions FunnySounds/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,18 @@ public void LoadBasicAudio()

foreach (var sound in availableSounds.ToList())
{
var soundControl = new Controls.SoundControl(sound);
soundsPanel.Children.Add(soundControl);
if (File.Exists(sound.path))
{
var soundControl = new Controls.SoundControl(sound);
soundsPanel.Children.Add(soundControl);
}
else
{
userData.sounds.Remove(sound);
MessageBox.Show($"Linked sound '{sound.name}' located at: {sound.path} had to removed, because it was deleted from the disk");
}
}
SaveUserData();
}

private void playAudioTick(object source, ElapsedEventArgs e)
Expand Down Expand Up @@ -219,23 +228,21 @@ public async void RemoveSound(Controls.SoundControl soundControl)

private void FileDropped(object sender, DragEventArgs e)
{
var name = fileSoundNameBox.Text;

if (name == null)
{
MessageBox.Show("Please put in the name/link");
return;
}

if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
//droppedSoundFiles.Clear();
fileTextBox.Text = "";
//fileTextBox.Text = "";
// Note that you can have more than one file.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
var file = files[0];

var sound = new Structs.Sound() { path = file, name = name };
if (!Structs.AUDIO_FILE_EXTENSIONS.Contains(Path.GetExtension(file).ToLower()))
{
MessageBox.Show("Incorrect file extension. Make sure it ends with e.g. '.mp3' or '.wav'");
return;
}

var sound = new Structs.Sound() { path = file };
droppedSoundFile = sound;

fileTextBox.Text = Path.GetFileName(file);
Expand Down Expand Up @@ -275,6 +282,11 @@ private void CopyDraggedFilesClicked(object sender, RoutedEventArgs e)
return;
}
var newSound = droppedSoundFile;
if (fileSoundNameBox.Text == null || fileSoundNameBox.Text.Length <= 0)
{
MessageBox.Show("Please put in the name/link");
return;
}
try
{
File.Copy(droppedSoundFile.path, Path.Combine(Structs.dataDir, Path.GetFileName(droppedSoundFile.path)));
Expand Down Expand Up @@ -345,6 +357,11 @@ private void CopyDraggedFilesClicked(object sender, RoutedEventArgs e)
private void LinkDraggedFilesClicked(object sender, RoutedEventArgs e)
{
if (droppedSoundFile == null) return;
if (fileSoundNameBox.Text == null || fileSoundNameBox.Text.Length <= 0)
{
MessageBox.Show("Please put in the name/link");
return;
}
if (userData.sounds.Any(sound => sound.name == droppedSoundFile.name))
{
MessageBox.Show("Sound with this name already exists");
Expand Down
2 changes: 1 addition & 1 deletion FunnySounds/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Sound
public float volume { get; set; } = 0.5f;
public bool isEnabled { get; set; } = true;

public List<System.Windows.Media.MediaPlayer> mediaPlayers = new();
public List<System.Windows.Media.MediaPlayer> mediaPlayers = new List<System.Windows.Media.MediaPlayer>();
}

[Serializable]
Expand Down

1 comment on commit 44e46dc

@AndyFilter
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.