@@ -48,6 +48,7 @@ public MainVM()
4848 private IntPtr desktopHandle ;
4949 private Process ffplayProcess ;
5050 private IntPtr ffplayWindowHandle ;
51+ private readonly string _exitWallpaper = "ExitWallpaper" ;
5152
5253 #endregion
5354
@@ -237,23 +238,7 @@ public List<WallpaperItem> WallpaperArray
237238
238239 #endregion
239240
240- #region Wallpaper
241- var wallpaersPath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "Video" ) ;
242- if ( Directory . Exists ( wallpaersPath ) )
243- {
244- var names = new List < WallpaperItem > ( ) ;
245- var files = Directory . GetFiles ( wallpaersPath ) ;
246- foreach ( var filePath in files )
247- {
248- var fileName = Path . GetFileNameWithoutExtension ( filePath ) ;
249- names . Add ( new WallpaperItem { ItemName = fileName , VideoPath = filePath , IsSelected = ConfigHelper . WallpaperPath == filePath ? true : false } ) ;
250- }
251- names . Add ( new WallpaperItem { ItemName = "更多壁纸请加QQ群:929469013" } ) ;
252- WallpaperArray = names ;
253- if ( WallpaperArray . Count > 0 )
254- ShowWallpaper ( ConfigHelper . WallpaperPath ) ;
255- }
256- #endregion
241+ WallpaersFilePlay ( ) ;
257242
258243 if ( Common . ApplicationListCache == null )
259244 {
@@ -430,8 +415,30 @@ private void ScreenCapturer_SnapCompleted(CroppedBitmap bitmap)
430415 {
431416 if ( obj is WallpaperItem wallpaper )
432417 {
433- if ( string . IsNullOrWhiteSpace ( wallpaper . VideoPath ) ) return ;
434- ShowWallpaper ( wallpaper . VideoPath ) ;
418+ if ( wallpaper . VideoPath == _exitWallpaper )
419+ {
420+ if ( ! wallpaper . IsSelected )
421+ {
422+ StopFFplayProcess ( ) ;
423+ wallpaper . ItemName = "壁纸已关闭" ;
424+ wallpaper . IsSelected = false ;
425+ }
426+ else
427+ {
428+ WallpaersFilePlay ( ) ;
429+ wallpaper . ItemName = "壁纸已开启" ;
430+ wallpaper . IsSelected = true ;
431+ }
432+ }
433+ else
434+ {
435+ if ( string . IsNullOrWhiteSpace ( wallpaper . VideoPath ) ) return ;
436+ if ( File . Exists ( wallpaper . VideoPath ) )
437+ {
438+ ShowWallpaper ( wallpaper . VideoPath ) ;
439+ }
440+
441+ }
435442 }
436443
437444 } ) ;
@@ -444,10 +451,16 @@ void ShowWallpaper(string wallpaperPath)
444451 {
445452 if ( string . IsNullOrWhiteSpace ( wallpaperPath ) || ! File . Exists ( wallpaperPath ) ) return ;
446453 StopFFplayProcess ( ) ;
447- WallpaperArray . Where ( x => x . VideoPath != wallpaperPath ) . ToList ( ) . ForEach ( x =>
454+ WallpaperArray . Where ( x => x . VideoPath != wallpaperPath && x . VideoPath != _exitWallpaper ) . ToList ( ) . ForEach ( x =>
448455 {
449456 x . IsSelected = false ;
450457 } ) ;
458+ var wallpaper = WallpaperArray . FirstOrDefault ( x => x . VideoPath == _exitWallpaper ) ;
459+ if ( wallpaper != null )
460+ {
461+ wallpaper . ItemName = "壁纸已开启" ;
462+ wallpaper . IsSelected = true ;
463+ }
451464 StartFFplayProcess ( wallpaperPath ) ;
452465 if ( ffplayWindowHandle != IntPtr . Zero )
453466 {
@@ -509,7 +522,7 @@ private void MouseHook_MouseDown(object sender, MouseEventArgs e)
509522 {
510523 _timer . Stop ( ) ;
511524 mouseHook . Stop ( ) ;
512- if ( colorView != null )
525+ if ( colorView != null )
513526 colorView . Close ( ) ;
514527 }
515528 }
@@ -587,6 +600,29 @@ void StopFFplayProcess()
587600 Log . Error ( $ "Error: StopFFplayProcess { ex . Message } ") ;
588601 }
589602 }
603+ void WallpaersFilePlay ( )
604+ {
605+ WallpaperArray = null ;
606+ #region Wallpaper
607+ var wallpaersPath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "Video" ) ;
608+ if ( Directory . Exists ( wallpaersPath ) )
609+ {
610+ var names = new List < WallpaperItem > ( ) ;
611+ var files = Directory . GetFiles ( wallpaersPath ) ;
612+ foreach ( var filePath in files )
613+ {
614+ var fileName = Path . GetFileNameWithoutExtension ( filePath ) ;
615+ names . Add ( new WallpaperItem { ItemName = fileName , VideoPath = filePath , IsSelected = ConfigHelper . WallpaperPath == filePath ? true : false } ) ;
616+ }
617+ if ( names . Count > 0 )
618+ names . Add ( new WallpaperItem { ItemName = ConfigHelper . OpenWallpaper == true ? "壁纸已开启" : "壁纸已关闭" , VideoPath = _exitWallpaper , IsSelected = ConfigHelper . OpenWallpaper } ) ;
619+ names . Add ( new WallpaperItem { ItemName = "更多壁纸请加QQ群:929469013" } ) ;
620+ WallpaperArray = names ;
621+ if ( WallpaperArray . Count > 0 )
622+ ShowWallpaper ( ConfigHelper . WallpaperPath ) ;
623+ }
624+ #endregion
625+ }
590626 #endregion
591627 }
592628}
0 commit comments