|
3 | 3 | * 2. 显示splash screen |
4 | 4 | * 3. 优化UI,添加前后图标,显示之前和之后搜索的结果 |
5 | 5 | * 4. 列出最近和频繁搜索的关键字 |
6 | | - * 5. 定时更新显示 |
| 6 | + * 5. (已完成)定时更新显示 |
| 7 | + * 6. 为什么水平滚动条不显示? * |
7 | 8 | */ |
8 | 9 |
|
9 | 10 | using System; |
@@ -39,14 +40,15 @@ public partial class MainWindow : Window |
39 | 40 | private DirectoryList dirList = new DirectoryList(); |
40 | 41 | private ObservableCollection<AVItems> resultList = new ObservableCollection<AVItems>(); |
41 | 42 | private string potplayerPath = GetPotPlayerPath(); |
| 43 | + private int initialItemCount = 0; // 在首次加载数据后设置这个值 |
42 | 44 |
|
43 | 45 | public MainWindow() |
44 | 46 | { |
45 | 47 | InitializeComponent(); |
46 | 48 | this.Loaded += MainWindow_Loaded; |
47 | 49 | outputGrid.ItemsSource = resultList; // 只设置一次 |
48 | | - // 设置定时器 |
49 | | - DispatcherTimer timer = new DispatcherTimer(); |
| 50 | + |
| 51 | + DispatcherTimer timer = new DispatcherTimer(); // 设置定时器 |
50 | 52 | timer.Interval = TimeSpan.FromSeconds(60); // 每60秒检查一次 |
51 | 53 | timer.Tick += Timer_Tick; |
52 | 54 | timer.Start(); |
@@ -76,13 +78,27 @@ private async Task CheckAndUpdateFilesAsync() |
76 | 78 | { |
77 | 79 | resultList.Add(item); |
78 | 80 | } |
| 81 | + |
| 82 | + UpdateStatusBar(); // 更新状态栏信息 |
79 | 83 | }); |
| 84 | + |
| 85 | + |
80 | 86 | } |
81 | 87 | } |
82 | 88 |
|
83 | | - |
84 | 89 |
|
| 90 | + private void UpdateStatusBar() |
| 91 | + { |
| 92 | + // 更新总项数 |
| 93 | + totalItemsText.Text = $"媒体文件或文件夹共计: {resultList.Count} 个"; |
85 | 94 |
|
| 95 | + // 计算从首次加载后新增的项数 |
| 96 | + if (initialItemCount > 0) |
| 97 | + { |
| 98 | + int newItemsCount = resultList.Count - initialItemCount; |
| 99 | + itemsAddedLast24HoursText.Text = $"首次加载后新增了: {newItemsCount} 个"; |
| 100 | + } |
| 101 | + } |
86 | 102 |
|
87 | 103 |
|
88 | 104 |
|
@@ -174,6 +190,15 @@ private async Task LoadFilesAsync() |
174 | 190 | } |
175 | 191 | } |
176 | 192 | }); |
| 193 | + |
| 194 | + // 首次加载后设置初始项数 |
| 195 | + if (initialItemCount == 0) // 保证只在首次加载时设置 |
| 196 | + { |
| 197 | + initialItemCount = resultList.Count; |
| 198 | + } |
| 199 | + |
| 200 | + // 更新状态栏 |
| 201 | + UpdateStatusBar(); |
177 | 202 | } |
178 | 203 |
|
179 | 204 |
|
@@ -270,38 +295,103 @@ private static string GetPotPlayerPath() |
270 | 295 | return null; |
271 | 296 | } |
272 | 297 |
|
273 | | - private void PlayOrOpenItem(object sender, RoutedEventArgs e) |
| 298 | + private void OpenMediaOrFile(string filePath) |
274 | 299 | { |
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)) |
279 | 301 | { |
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 | + } |
281 | 317 | } |
282 | 318 | else |
283 | 319 | { |
284 | | - Process.Start(item.Text); |
| 320 | + MessageBox.Show("The file path is empty or invalid.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); |
285 | 321 | } |
| 322 | + } |
286 | 323 |
|
| 324 | + private bool IsIsoFile(string filePath) |
| 325 | + { |
| 326 | + return Path.GetExtension(filePath).Equals(".iso", StringComparison.OrdinalIgnoreCase); |
287 | 327 | } |
288 | 328 |
|
289 | | - private void Row_DoubleClick(object sender, MouseButtonEventArgs e) |
| 329 | + private bool ContainsIsoFile(string directoryPath) |
290 | 330 | { |
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 | + } |
293 | 337 |
|
294 | | - if (potplayerPath != null) |
| 338 | + private void StartProcessForIso(string filePath) |
| 339 | + { |
| 340 | + string isoFilePath = filePath; |
| 341 | + |
| 342 | + if (Directory.Exists(filePath)) |
295 | 343 | { |
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文件 |
297 | 351 | } |
298 | 352 | else |
299 | 353 | { |
300 | | - Process.Start(item.Text); |
| 354 | + MessageBox.Show("No ISO file found in the specified directory.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); |
301 | 355 | } |
| 356 | + } |
302 | 357 |
|
| 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 | + } |
303 | 370 | } |
304 | 371 |
|
| 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 | + |
305 | 395 | private void OpenContainingFolder(object sender, RoutedEventArgs e) |
306 | 396 | { |
307 | 397 | // 获取当前选中的单元格信息 |
@@ -388,6 +478,9 @@ public class AVItems |
388 | 478 | public AVItems() |
389 | 479 | { |
390 | 480 | Id = nextId++; // 构造函数中分配ID,并递增计数器 |
| 481 | + CreationTime = DateTime.Now; // 初始化时设置创建时间 |
391 | 482 | } |
| 483 | + |
| 484 | + public DateTime CreationTime { get; private set; } |
392 | 485 | } |
393 | 486 | } |
0 commit comments