1
1
using Files . Dialogs ;
2
+ using Files . Enums ;
2
3
using Files . Filesystem ;
3
4
using Files . Helpers ;
4
5
using Files . UserControls ;
@@ -65,37 +66,44 @@ public void List_ItemClick(object sender, DoubleTappedRoutedEventArgs e)
65
66
OpenSelectedItems ( false ) ;
66
67
}
67
68
68
- public async void SetAsDesktopBackgroundItem_Click ( object sender , RoutedEventArgs e )
69
+ public void SetAsDesktopBackgroundItem_Click ( object sender , RoutedEventArgs e )
69
70
{
70
- // Get the path of the selected file
71
- StorageFile sourceFile = await ItemViewModel . GetFileFromPathAsync ( CurrentInstance . ContentPage . SelectedItem . ItemPath ) ;
72
-
73
- // Get the app's local folder to use as the destination folder.
74
- StorageFolder localFolder = ApplicationData . Current . LocalFolder ;
75
-
76
- // Copy the file to the destination folder.
77
- // Replace the existing file if the file already exists.
78
- StorageFile file = await sourceFile . CopyAsync ( localFolder , "Background.png" , NameCollisionOption . ReplaceExisting ) ;
71
+ SetAsBackground ( WallpaperType . Desktop ) ;
72
+ }
79
73
80
- // Set the desktop background
81
- UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings . Current ;
82
- await profileSettings . TrySetWallpaperImageAsync ( file ) ;
74
+ public void SetAsLockscreenBackgroundItem_Click ( object sender , RoutedEventArgs e )
75
+ {
76
+ SetAsBackground ( WallpaperType . LockScreen ) ;
83
77
}
84
78
85
- public async void SetAsLockscreenBackgroundItem_Click ( object sender , RoutedEventArgs e )
79
+ public async void SetAsBackground ( WallpaperType type )
86
80
{
87
- // Get the path of the selected file
88
- StorageFile sourceFile = await ItemViewModel . GetFileFromPathAsync ( CurrentInstance . ContentPage . SelectedItem . ItemPath ) ;
81
+ if ( UserProfilePersonalizationSettings . IsSupported ( ) )
82
+ {
83
+ // Get the path of the selected file
84
+ StorageFile sourceFile = await ItemViewModel . GetFileFromPathAsync ( CurrentInstance . ContentPage . SelectedItem . ItemPath ) ;
89
85
90
- // Get the app's local folder to use as the destination folder.
91
- StorageFolder localFolder = ApplicationData . Current . LocalFolder ;
86
+ // Get the app's local folder to use as the destination folder.
87
+ StorageFolder localFolder = ApplicationData . Current . LocalFolder ;
92
88
93
- // Copy the file to the destination folder.
94
- // Replace the existing file if the file already exists.
95
- StorageFile file = await sourceFile . CopyAsync ( localFolder , "Background.png" , NameCollisionOption . ReplaceExisting ) ;
89
+ // Copy the file to the destination folder.
90
+ // Generate unique name if the file already exists.
91
+ // If the file you are trying to set as the wallpaper has the same name as the current wallpaper,
92
+ // the system will ignore the request and no-op the operation
93
+ StorageFile file = await sourceFile . CopyAsync ( localFolder , sourceFile . Name , NameCollisionOption . GenerateUniqueName ) ;
96
94
97
- // Set the lockscreen background
98
- await LockScreen . SetImageFileAsync ( file ) ;
95
+ UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings . Current ;
96
+ if ( type == WallpaperType . Desktop )
97
+ {
98
+ // Set the desktop background
99
+ await profileSettings . TrySetWallpaperImageAsync ( file ) ;
100
+ }
101
+ else if ( type == WallpaperType . LockScreen )
102
+ {
103
+ // Set the lockscreen background
104
+ await profileSettings . TrySetLockScreenImageAsync ( file ) ;
105
+ }
106
+ }
99
107
}
100
108
101
109
public void OpenNewTab ( )
@@ -186,8 +194,13 @@ public static async Task InvokeWin32Components(List<string> applicationPaths, st
186
194
Debug . WriteLine ( "Launching EXE in FullTrustProcess" ) ;
187
195
if ( App . Connection != null )
188
196
{
189
- var value = new ValueSet ( ) ;
190
- value . Add ( "Application" , applicationPaths . FirstOrDefault ( ) ) ;
197
+ var value = new ValueSet
198
+ {
199
+ { "WorkingDirectory" , App . CurrentInstance . FilesystemViewModel . WorkingDirectory } ,
200
+ { "Application" , applicationPaths . FirstOrDefault ( ) } ,
201
+ { "ApplicationList" , JsonConvert . SerializeObject ( applicationPaths ) } ,
202
+ } ;
203
+
191
204
if ( runAsAdmin )
192
205
{
193
206
value . Add ( "Arguments" , "runas" ) ;
@@ -196,7 +209,7 @@ public static async Task InvokeWin32Components(List<string> applicationPaths, st
196
209
{
197
210
value . Add ( "Arguments" , arguments ) ;
198
211
}
199
- value . Add ( "ApplicationList" , JsonConvert . SerializeObject ( applicationPaths ) ) ;
212
+
200
213
await App . Connection . SendMessageAsync ( value ) ;
201
214
}
202
215
}
@@ -894,7 +907,7 @@ public async Task<StorageFolder> MoveDirectoryAsync(StorageFolder SourceFolder,
894
907
}
895
908
896
909
App . JumpList . RemoveFolder ( SourceFolder . Path ) ;
897
-
910
+
898
911
return createdRoot ;
899
912
}
900
913
@@ -1354,7 +1367,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
1354
1367
}
1355
1368
}
1356
1369
} ) ) ;
1357
-
1370
+
1358
1371
await CloneDirectoryAsync ( destFolder_InBuffer , destinationFolder , destFolder_InBuffer . Name , true )
1359
1372
. ContinueWith ( async ( x ) =>
1360
1373
{
0 commit comments