File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,14 +23,16 @@ public enum BackgroundType
2323 Extra = 3
2424 }
2525
26+
27+
2628 /// <summary>
2729 /// Get wallpaper image source berdasarkan tipe
2830 /// </summary>
2931 private static BitmapImage ? GetBackgroundImage ( BackgroundType type )
3032 {
3133 try
3234 {
33- string wallpaperPath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "Resources" , "Wallpapers" ) ;
35+ string wallpaperPath = Paths . ResolveWallpapersDir ( ) ;
3436
3537 string imagePath = type switch
3638 {
@@ -102,7 +104,7 @@ public static bool ValidateBackgroundFiles()
102104
103105 foreach ( BackgroundType type in Enum . GetValues ( typeof ( BackgroundType ) ) )
104106 {
105- string wallpaperPath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "Resources" , "Wallpapers" ) ;
107+ string wallpaperPath = Paths . ResolveWallpapersDir ( ) ;
106108 string imagePath = type switch
107109 {
108110 BackgroundType . Default => Path . Combine ( wallpaperPath , "wallpapers.jpg" ) ,
Original file line number Diff line number Diff line change @@ -30,12 +30,9 @@ public enum WallpaperType
3030 Quality = 2
3131 }
3232
33- /// <summary>
34- /// Get wallpaper path berdasarkan tipe
35- /// </summary>
3633 private static string GetWallpaperPath ( WallpaperType type )
3734 {
38- string wallpaperPath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "Resources" , "Wallpapers" ) ;
35+ string wallpaperPath = Paths . ResolveWallpapersDir ( ) ;
3936
4037 return type switch
4138 {
Original file line number Diff line number Diff line change @@ -39,6 +39,29 @@ static class Paths
3939
4040 public static bool Initialized => ! String . IsNullOrEmpty ( Base ) ;
4141
42+ /// <summary>
43+ /// Resolve the Wallpapers folder path, trying multiple base directories
44+ /// to handle different execution contexts (build, installed, published).
45+ /// </summary>
46+ public static string ResolveWallpapersDir ( )
47+ {
48+ string [ ] candidates = new [ ]
49+ {
50+ AppDomain . CurrentDomain . BaseDirectory ,
51+ Path . GetDirectoryName ( typeof ( Paths ) . Assembly . Location ) ?? "" ,
52+ Path . GetDirectoryName ( Environment . ProcessPath ?? "" ) ?? ""
53+ } ;
54+
55+ foreach ( string dir in candidates )
56+ {
57+ if ( string . IsNullOrEmpty ( dir ) ) continue ;
58+ string path = Path . Combine ( dir , "Resources" , "Wallpapers" ) ;
59+ if ( Directory . Exists ( path ) ) return path ;
60+ }
61+
62+ return Path . Combine ( candidates [ 0 ] , "Resources" , "Wallpapers" ) ;
63+ }
64+
4265 public static void Initialize ( string baseDirectory )
4366 {
4467 Base = baseDirectory ;
You can’t perform that action at this time.
0 commit comments