Skip to content

Commit 038e462

Browse files
committed
少量bug修复
1 parent 1d0a9d8 commit 038e462

3 files changed

Lines changed: 154 additions & 46 deletions

File tree

LibVideo/LibVideo2.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<MapFileExtensions>true</MapFileExtensions>
2929
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
3030
<WebPage>publish.htm</WebPage>
31-
<ApplicationRevision>22</ApplicationRevision>
31+
<ApplicationRevision>26</ApplicationRevision>
3232
<ApplicationVersion>1.1.0.%2a</ApplicationVersion>
3333
<UseApplicationTrust>false</UseApplicationTrust>
3434
<PublishWizardCompleted>true</PublishWizardCompleted>

LibVideo/MainWindow.xaml

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,58 @@
66
xmlns:local="clr-namespace:LibVideo"
77
mc:Ignorable="d"
88
Title="我家视频" Height="527.371" Width="800"
9-
WindowState="Normal" ResizeMode="NoResize"
10-
11-
>
12-
<Grid>
9+
WindowState="Normal" ResizeMode="NoResize" >
10+
1311

1412

13+
<Grid>
1514
<TextBox x:Name="dirTxt" HorizontalAlignment="Left" Height="113" Margin="630,10,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="147" TextChanged="dirTextBox_TextChanged"/>
1615
<Button Content="添加视频目录" HorizontalAlignment="Left" Height="27" Margin="669,128,0,0" VerticalAlignment="Top" Width="80" Click="dirButton_Click"/>
17-
<Label Content="" HorizontalAlignment="Center" Height="33" Margin="81.667,60,62.666,406.333" VerticalAlignment="Center" Width="153" FontSize="18" Grid.Column="2" Grid.ColumnSpan="2"/>
18-
<DataGrid x:Name="outputGrid" HorizontalAlignment="Left" Height="456" Margin="10,43,0,0" VerticalAlignment="Top" Width="615"
19-
AutoGenerateColumns="False" SelectionMode="Single" SelectionUnit="Cell" IsReadOnly="true">
20-
<DataGrid.Columns>
21-
<DataGridTextColumn Header="编号" Binding="{Binding Id}" />
22-
<DataGridTextColumn Header="视频" Binding="{Binding FullName}" />
23-
</DataGrid.Columns>
24-
25-
<DataGrid.Resources>
26-
<Style TargetType="DataGridRow">
27-
<EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/>
28-
</Style>
29-
</DataGrid.Resources>
30-
31-
32-
<DataGrid.ContextMenu>
33-
<ContextMenu>
34-
<!--<MenuItem Header="复制" Command="Copy" />-->
35-
<MenuItem Header="播放" Click="PlayOrOpenItem" />
36-
<MenuItem Header="打开文件夹" Click="OpenContainingFolder" />
37-
</ContextMenu>
38-
</DataGrid.ContextMenu>
39-
</DataGrid>
16+
17+
18+
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
19+
<DataGrid x:Name="outputGrid" Height="402" Margin="10,43,0,0" Width="611"
20+
AutoGenerateColumns="False" SelectionMode="Single" SelectionUnit="Cell" IsReadOnly="true" HorizontalAlignment="Left">
21+
<DataGrid.Columns>
22+
<DataGridTextColumn Header="编号" Binding="{Binding Id}" />
23+
<DataGridTextColumn Header="视频" Binding="{Binding FullName}">
24+
<DataGridTextColumn.ElementStyle>
25+
<Style TargetType="TextBlock">
26+
<Setter Property="ToolTip" Value="{Binding FullName}" />
27+
</Style>
28+
</DataGridTextColumn.ElementStyle>
29+
</DataGridTextColumn>
30+
</DataGrid.Columns>
31+
32+
<DataGrid.Resources>
33+
<Style TargetType="DataGridRow">
34+
<EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/>
35+
</Style>
36+
</DataGrid.Resources>
37+
38+
<DataGrid.ContextMenu>
39+
<ContextMenu>
40+
<MenuItem Header="播放" Click="PlayOrOpenItem" />
41+
<MenuItem Header="打开文件夹" Click="OpenContainingFolder" />
42+
</ContextMenu>
43+
</DataGrid.ContextMenu>
44+
</DataGrid>
45+
46+
</ScrollViewer>
4047

4148
<TextBox x:Name="keywords" HorizontalAlignment="Left" Height="28" Margin="190,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="251" TextChanged="keywords_TextChanged" />
4249
<Image Grid.Column="2" HorizontalAlignment="Left" Height="26" Margin="62.667,297,0,0" VerticalAlignment="Top" Width="113"/>
4350
<Label Content="搜索:" HorizontalAlignment="Left" Height="37" Margin="143,10,0,0" VerticalAlignment="Top" Width="63"/>
4451

45-
52+
<!-- 状态栏 -->
53+
<StatusBar VerticalAlignment="Bottom">
54+
<StatusBarItem>
55+
<TextBlock x:Name="totalItemsText"/>
56+
</StatusBarItem>
57+
<StatusBarItem>
58+
<TextBlock x:Name="itemsAddedLast24HoursText"/>
59+
</StatusBarItem>
60+
</StatusBar>
4661
</Grid>
4762

4863
</Window>

LibVideo/MainWindow.xaml.cs

Lines changed: 110 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* 2. 显示splash screen
44
* 3. 优化UI,添加前后图标,显示之前和之后搜索的结果
55
* 4. 列出最近和频繁搜索的关键字
6-
* 5. 定时更新显示
6+
* 5. (已完成)定时更新显示
7+
* 6. 为什么水平滚动条不显示? *
78
*/
89

910
using System;
@@ -39,14 +40,15 @@ public partial class MainWindow : Window
3940
private DirectoryList dirList = new DirectoryList();
4041
private ObservableCollection<AVItems> resultList = new ObservableCollection<AVItems>();
4142
private string potplayerPath = GetPotPlayerPath();
43+
private int initialItemCount = 0; // 在首次加载数据后设置这个值
4244

4345
public MainWindow()
4446
{
4547
InitializeComponent();
4648
this.Loaded += MainWindow_Loaded;
4749
outputGrid.ItemsSource = resultList; // 只设置一次
48-
// 设置定时器
49-
DispatcherTimer timer = new DispatcherTimer();
50+
51+
DispatcherTimer timer = new DispatcherTimer(); // 设置定时器
5052
timer.Interval = TimeSpan.FromSeconds(60); // 每60秒检查一次
5153
timer.Tick += Timer_Tick;
5254
timer.Start();
@@ -76,13 +78,27 @@ private async Task CheckAndUpdateFilesAsync()
7678
{
7779
resultList.Add(item);
7880
}
81+
82+
UpdateStatusBar(); // 更新状态栏信息
7983
});
84+
85+
8086
}
8187
}
8288

83-
8489

90+
private void UpdateStatusBar()
91+
{
92+
// 更新总项数
93+
totalItemsText.Text = $"媒体文件或文件夹共计: {resultList.Count} 个";
8594

95+
// 计算从首次加载后新增的项数
96+
if (initialItemCount > 0)
97+
{
98+
int newItemsCount = resultList.Count - initialItemCount;
99+
itemsAddedLast24HoursText.Text = $"首次加载后新增了: {newItemsCount} 个";
100+
}
101+
}
86102

87103

88104

@@ -174,6 +190,15 @@ private async Task LoadFilesAsync()
174190
}
175191
}
176192
});
193+
194+
// 首次加载后设置初始项数
195+
if (initialItemCount == 0) // 保证只在首次加载时设置
196+
{
197+
initialItemCount = resultList.Count;
198+
}
199+
200+
// 更新状态栏
201+
UpdateStatusBar();
177202
}
178203

179204

@@ -270,38 +295,103 @@ private static string GetPotPlayerPath()
270295
return null;
271296
}
272297

273-
private void PlayOrOpenItem(object sender, RoutedEventArgs e)
298+
private void OpenMediaOrFile(string filePath)
274299
{
275-
DataGridCellInfo cell = (DataGridCellInfo)outputGrid.CurrentCell;
276-
TextBlock item = outputGrid.Columns[1].GetCellContent(cell.Item) as TextBlock;
277-
278-
if (potplayerPath != null)
300+
if (!string.IsNullOrEmpty(filePath))
279301
{
280-
Process.Start(potplayerPath, item.Text);
302+
// 检查路径是否指向ISO文件或目录中是否存在ISO文件
303+
if (IsIsoFile(filePath) || ContainsIsoFile(filePath))
304+
{
305+
// 如果是ISO文件或目录中有ISO文件,使用特定的处理逻辑
306+
StartProcessForIso(filePath);
307+
}
308+
else if (File.Exists(filePath) || Directory.Exists(filePath))
309+
{
310+
// 处理其他类型的文件或目录
311+
StartProcess(filePath);
312+
}
313+
else
314+
{
315+
MessageBox.Show("The file path does not exist or is not valid.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
316+
}
281317
}
282318
else
283319
{
284-
Process.Start(item.Text);
320+
MessageBox.Show("The file path is empty or invalid.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
285321
}
322+
}
286323

324+
private bool IsIsoFile(string filePath)
325+
{
326+
return Path.GetExtension(filePath).Equals(".iso", StringComparison.OrdinalIgnoreCase);
287327
}
288328

289-
private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
329+
private bool ContainsIsoFile(string directoryPath)
290330
{
291-
DataGridCellInfo cell = (DataGridCellInfo)outputGrid.CurrentCell;
292-
TextBlock item = outputGrid.Columns[1].GetCellContent(cell.Item) as TextBlock;
331+
if (Directory.Exists(directoryPath))
332+
{
333+
return Directory.GetFiles(directoryPath, "*.iso", SearchOption.TopDirectoryOnly).FirstOrDefault() != null;
334+
}
335+
return false;
336+
}
293337

294-
if (potplayerPath != null)
338+
private void StartProcessForIso(string filePath)
339+
{
340+
string isoFilePath = filePath;
341+
342+
if (Directory.Exists(filePath))
295343
{
296-
Process.Start(potplayerPath, item.Text);
344+
// 如果是目录,尝试找到第一个ISO文件
345+
isoFilePath = Directory.GetFiles(filePath, "*.iso", SearchOption.TopDirectoryOnly).FirstOrDefault();
346+
}
347+
348+
if (!string.IsNullOrEmpty(isoFilePath))
349+
{
350+
Process.Start(isoFilePath); // 使用默认关联应用打开ISO文件
297351
}
298352
else
299353
{
300-
Process.Start(item.Text);
354+
MessageBox.Show("No ISO file found in the specified directory.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
301355
}
356+
}
302357

358+
private void StartProcess(string filePath)
359+
{
360+
if (potplayerPath != null && !IsIsoFile(filePath))
361+
{
362+
// 如果配置了 potplayerPath 并且文件不是.iso,使用 PotPlayer 打开
363+
Process.Start(potplayerPath, filePath);
364+
}
365+
else
366+
{
367+
// 否则使用系统默认程序打开文件
368+
Process.Start(filePath);
369+
}
303370
}
304371

372+
373+
374+
375+
private void PlayOrOpenItem(object sender, RoutedEventArgs e)
376+
{
377+
DataGridCellInfo cell = (DataGridCellInfo)outputGrid.CurrentCell;
378+
if (cell.Item is AVItems avItem)
379+
{
380+
OpenMediaOrFile(avItem.FullName);
381+
}
382+
383+
}
384+
385+
private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
386+
{
387+
DataGridCellInfo cell = (DataGridCellInfo)outputGrid.CurrentCell;
388+
if (cell.Item is AVItems avItem)
389+
{
390+
OpenMediaOrFile(avItem.FullName);
391+
}
392+
}
393+
394+
305395
private void OpenContainingFolder(object sender, RoutedEventArgs e)
306396
{
307397
// 获取当前选中的单元格信息
@@ -388,6 +478,9 @@ public class AVItems
388478
public AVItems()
389479
{
390480
Id = nextId++; // 构造函数中分配ID,并递增计数器
481+
CreationTime = DateTime.Now; // 初始化时设置创建时间
391482
}
483+
484+
public DateTime CreationTime { get; private set; }
392485
}
393486
}

0 commit comments

Comments
 (0)