Skip to content

Commit

Permalink
[CastIt] Crash fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Nov 3, 2020
1 parent b244487 commit 17b411a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CastIt/Resources/Resource.Designer.cs

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

3 changes: 3 additions & 0 deletions CastIt/Resources/Resource.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,7 @@
<data name="XSeconds" xml:space="preserve">
<value>{0} segundos</value>
</data>
<data name="FileCouldntBeOpened" xml:space="preserve">
<value>El archivo no puedo ser abierto</value>
</data>
</root>
3 changes: 3 additions & 0 deletions CastIt/Resources/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,7 @@
<data name="XSeconds" xml:space="preserve">
<value>{0} seconds</value>
</data>
<data name="FileCouldntBeOpened" xml:space="preserve">
<value>File could not be opened</value>
</data>
</root>
15 changes: 13 additions & 2 deletions CastIt/ViewModels/Items/FileItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ public async Task SetFileInfo(CancellationToken token, bool force = true)
return;
}

FileInfo = await _ffmpegService.GetFileInfo(Path, token);
var fileInfo = await _ffmpegService.GetFileInfo(Path, token);
if (fileInfo != null)
{
FileInfo = fileInfo;
}

var duration = FileInfo?.Format?.Duration ?? -1;
await SetDuration(duration);
Expand All @@ -248,6 +252,9 @@ public async Task SetFileInfo(CancellationToken token, bool force = true)

public async Task SetDuration(double seconds, bool update = true)
{
await RaisePropertyChanged(() => IsLocalFile);
await RaisePropertyChanged(() => IsUrlFile);
await RaisePropertyChanged(() => Exists);
if (!Exists)
{
TotalSeconds = 0;
Expand Down Expand Up @@ -298,13 +305,17 @@ private void OpenFileLocation()
var psi = new ProcessStartInfo("explorer.exe", "/n /e,/select," + @$"""{Path}""");
Process.Start(psi);
}
else
else if (IsUrlFile)
{
Process.Start(new ProcessStartInfo(Path)
{
UseShellExecute = true
});
}
else
{
Messenger.Publish(new SnackbarMessage(this, GetText("FileCouldntBeOpened")));
}
}
}
}
30 changes: 30 additions & 0 deletions CastIt/Views/UserControls/FileItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,35 @@
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Play" />
</MenuItem.Icon>
<MenuItem.Style>
<Style BasedOn="{StaticResource MaterialDesignMenuItem}" TargetType="{x:Type MenuItem}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Exists}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="False" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</MenuItem.Style>
</MenuItem>
<MenuItem Command="{Binding PlayFromTheBeginingCommand}" Header="{Binding [PlayFromTheBegining]}">
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Refresh" />
</MenuItem.Icon>
<MenuItem.Style>
<Style BasedOn="{StaticResource MaterialDesignMenuItem}" TargetType="{x:Type MenuItem}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Exists}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="False" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</MenuItem.Style>
</MenuItem>
<MenuItem Command="{Binding ToggleLoopCommand}" Visibility="{Binding IsBeingPlayed, Converter={StaticResource BooleanToVisibilityConverter}}">
<MenuItem.Style>
Expand Down Expand Up @@ -100,6 +124,12 @@
</Setter.Value>
</Setter>
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Exists}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="False" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</MenuItem.Style>
Expand Down

0 comments on commit 17b411a

Please sign in to comment.