예제 #1
0
        ///<inheritdoc/>
        public async Task <bool> TrySetWallpaperImageAsync(string imageFilePath)
        {
            if (String.IsNullOrEmpty(imageFilePath))
            {
                throw new ArgumentNullException(nameof(imageFilePath));
            }

            bool success = false;
            //remove old wallpapers
            await FileService.CleanUpFolderAsync(ApplicationData.Current.LocalFolder, FileTypeFilter, 0);

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                StorageFile wallpaper;
                if (!imageFilePath.Contains(ApplicationData.Current.LocalFolder.Path))
                {
                    StorageFile originalStorageFile = await StorageFile.GetFileFromPathAsync(imageFilePath);

                    wallpaper = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                        new FileInfo(imageFilePath).Name, CreationCollisionOption.GenerateUniqueName);

                    await originalStorageFile.CopyAndReplaceAsync(wallpaper);
                }
                else
                {
                    wallpaper = await StorageFile.GetFileFromPathAsync(imageFilePath);
                }
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                success = await profileSettings.TrySetWallpaperImageAsync(wallpaper);
            }
            return(success);
        }
예제 #2
0
        /// <summary>
        /// Returns the current contents of the cache folder
        /// </summary>
        /// <returns></returns>
        private async Task <bool> SetBackgroundImage(UpdateTypes type, StorageFile file)
        {
            bool wasSuccess = false;

            if (type == UpdateTypes.Band)
            {
                wasSuccess = await m_baconMan.BackgroundMan.BandMan.UpdateBandWallpaper(file);

                // The band can fail quite a lot, if so don't count this as a fail.
                wasSuccess = true;
            }
            // Make sure we can do it
            else if (UserProfilePersonalizationSettings.IsSupported())
            {
                // Try to set the image
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                if (type == UpdateTypes.LockScreen)
                {
                    wasSuccess = await profileSettings.TrySetLockScreenImageAsync(file);
                }
                else
                {
                    wasSuccess = await profileSettings.TrySetWallpaperImageAsync(file);
                }
            }
            return(wasSuccess);
        }
예제 #3
0
        public Picture(string fileName, DateTime dateCreated, string filePath)
        {
            FileName    = fileName;
            DateCreated = dateCreated;
            FilePath    = filePath;
            ImageSource = new BitmapImage();

            this.SetAsBackgroundCommand = new RelayCommand(async() =>
            {
                if (UserProfilePersonalizationSettings.IsSupported())
                {
                    var file = await SaveImage("backgroundimage.jpg");
                    UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                    Debug.Write(await profileSettings.TrySetWallpaperImageAsync(file));
                }
            });

            this.SetAsLockscreenCommand = new RelayCommand(async() =>
            {
                if (UserProfilePersonalizationSettings.IsSupported())
                {
                    var file = await SaveImage("lockscreenimage.jpg");
                    UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                    Debug.Write(await profileSettings.TrySetLockScreenImageAsync(file));
                }
            });
        }
예제 #4
0
        private async void btnSetWallpaper_Click(object sender, RoutedEventArgs e)
        {
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current;
                StorageFile cacheFile = await CacheManager.GetCachedFileAsync(parameter.FileName);

                StorageFile file = await cacheFile.CopyAsync(ApplicationData.Current.LocalFolder, "WallpaperImage", NameCollisionOption.ReplaceExisting);

                if (!await settings.TrySetWallpaperImageAsync(file))
                {
                    var messageDialog = new MessageDialog("更换壁纸失败");
                    await messageDialog.ShowAsync();
                }
                else
                {
                    await ShowTip("已更换壁纸");
                }
            }
            else
            {
                var messageDialog = new MessageDialog("您的设备不支持更换壁纸");
                await messageDialog.ShowAsync();
            }
        }
예제 #5
0
        public async void SetAsDesktopBackgroundItem_Click(object sender, RoutedEventArgs e)
        {
            var         item = (CurrentInstance.ContentPage as BaseLayout).SelectedItem;
            StorageFile file = await StorageFile.GetFileFromPathAsync(item.FilePath);

            UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
            await profileSettings.TrySetWallpaperImageAsync(file);
        }
        private async void SetWallpaperAsync()
        {
            var file = await GetOrCreateAppDataImageFileAsync("Wallpaper.png");

            var success = await _personalizationSettings.TrySetWallpaperImageAsync(file);

            await ShowResultDialogAsync(success);
        }
예제 #7
0
파일: LookImg.xaml.cs 프로젝트: kyoeye/MT2
        //public StorageFile Storagefile { get => sf; set=>sf = value; }

        private async void StartBackground_Click(object sender, RoutedEventArgs e)
        {
            sf = await sfd.CreateFileAsync(imgid + ".jpg", CreationCollisionOption.ReplaceExisting);
            await ImgTransfromAsync();

            //sf = await StorageFile.GetFileFromPathAsync(imgLocalpath);
            UserProfilePersonalizationSettings startsetting = UserProfilePersonalizationSettings.Current;
            bool b = await startsetting.TrySetWallpaperImageAsync(sf);
        }
예제 #8
0
        public async Task <bool> setWallpaper(StorageFile imageFile)
        {
            bool success = false;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                success = await profileSettings.TrySetWallpaperImageAsync(imageFile);
            }
            return(success);
        }
예제 #9
0
        private async Task <bool> SetWallpaper(StorageFile wallpaperImage)
        {
            bool successful = false;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                successful = await profileSettings.TrySetWallpaperImageAsync(wallpaperImage);
            }
            return(successful);
        }
예제 #10
0
        private static async Task SetDesktopBackgroundAsync(StorageFile file)
        {
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                StorageFile localFile = await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name,
                                                             NameCollisionOption.ReplaceExisting);

                UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current;
                await settings.TrySetWallpaperImageAsync(localFile);
            }
        }
예제 #11
0
        // Change wallpaper
        // Pass in a relative path to a file inside the assets folder
        async Task <bool> SetWallpaperAsync(string assetsFileName)
        {
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                var         uri  = new Uri("ms-appx:///Assets/" + assetsFileName);
                StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);

                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                return(await profileSettings.TrySetWallpaperImageAsync(file));
            }
            return(false);
        }
예제 #12
0
        public async void SetWallappaer(string url)
        {
            StorageFile file = await HomeController.DownloadImagefromServer(url, "wall");

            bool success = false;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                success = await profileSettings.TrySetWallpaperImageAsync(file);
            }
        }
예제 #13
0
 public static async Task <bool> ChangeWallPaper(StorageFile imageFile)
 {
     if (UserProfilePersonalizationSettings.IsSupported())
     {
         UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current;
         return(await settings.TrySetWallpaperImageAsync(imageFile));
     }
     else
     {
         return(false);
     }
 }
예제 #14
0
        private async Task <bool> SetWallpaperAsyncInternal(string localAppDataFileName)
        {
            bool success = false;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                var file = await ApplicationData.Current.LocalFolder.GetFileAsync(localAppDataFileName);

                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                success = await profileSettings.TrySetWallpaperImageAsync(file);
            }
            return(success);
        }
예제 #15
0
        /// <summary>
        /// 改变桌面壁纸。
        /// </summary>
        /// <param name="localAppDataFileName"></param>
        /// <returns>是否操作成功。</returns>
        public async Task <bool> SetWallpaperAsync(string localAppDataFileName)
        {
            bool success = false;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                var         uri  = new Uri("ms-appdata:///local/" + localAppDataFileName);
                StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);

                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                success = await profileSettings.TrySetWallpaperImageAsync(file);
            }
            return(success);
        }
예제 #16
0
        private IAsyncOperation <bool> SetWallpaperAsync(StorageFile wallpaperImage)
        {
            bool successful = false;

            return(Task.Run <bool>(async() =>
            {
                if (UserProfilePersonalizationSettings.IsSupported())
                {
                    UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                    successful = await profileSettings.TrySetWallpaperImageAsync(wallpaperImage);
                }
                return successful;
            }).AsAsyncOperation());
        }
예제 #17
0
파일: model.cs 프로젝트: xhowar/lindexi_gd
        //设置壁纸
        //复制壁纸到localFolder
        public async void writeasset桌面(StorageFile file)
        {
            //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/桌面.jpg"));

            StorageFile tmp = await file.CopyAsync(ApplicationData.Current.LocalFolder, "桌面.jpg", NameCollisionOption.ReplaceExisting);

            bool success = false;

            //检查是否支持
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                success = await profileSettings.TrySetWallpaperImageAsync(tmp);
            }
        }
예제 #18
0
        async Task <bool> SetWallpaperAsync(string iFile)
        {
            bool success = false;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                var         uri  = new Uri(this.BaseUri, "C:\\Users\\Deepak\\Pictures\\" + iFile);
                StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);

                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                success = await profileSettings.TrySetWallpaperImageAsync(file);
            }

            return(success);
        }
        private async Task ChangeBackground()
        {
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                Uri urichangewallpaper;
                if (newItem == null)
                {
                    urichangewallpaper = new Uri(itemaaa.cover_photo.urls.full);
                }
                else
                {
                    urichangewallpaper = new Uri(newItem.urls.full);
                }

                using (Windows.Web.Http.HttpClient client = new Windows.Web.Http.HttpClient())
                {
                    try
                    {
                        Windows.Web.Http.HttpResponseMessage response = await client.GetAsync(urichangewallpaper);

                        if (response != null && response.StatusCode == Windows.Web.Http.HttpStatusCode.Ok)
                        {
                            string filename  = "background.jpg";
                            var    imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

                            using (IRandomAccessStream stream = await imageFile.OpenAsync(FileAccessMode.ReadWrite))
                            {
                                await response.Content.WriteToStreamAsync(stream);
                            }
                            StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename);

                            UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current;
                            if (!await settings.TrySetWallpaperImageAsync(file))
                            {
                                System.Diagnostics.Debug.WriteLine("Failed");
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine("Success");
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
예제 #20
0
        public async void SetAsDesktopBackgroundItem_Click(object sender, RoutedEventArgs e)
        {
            // Get the path of the selected file
            StorageFile sourceFile = await StorageFile.GetFileFromPathAsync(CurrentInstance.ContentPage.SelectedItem.ItemPath);

            // Get the app's local folder to use as the destination folder.
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;

            // Copy the file to the destination folder.
            // Replace the existing file if the file already exists.
            StorageFile file = await sourceFile.CopyAsync(localFolder, "Background.png", NameCollisionOption.ReplaceExisting);

            // Set the desktop background
            UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
            await profileSettings.TrySetWallpaperImageAsync(file);
        }
예제 #21
0
        public async Task UpdateImage(CancellationTokenSource _source)
        {
            var saveFile = await GetLiveEarthPictureForWallPaper(_source);

            if (saveFile == null)
            {
                return;
            }
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                var success = await profileSettings.TrySetWallpaperImageAsync(saveFile);

                //download_status.Text = success ? "success" : "failed";
            }
        }
예제 #22
0
        /// <summary>
        /// Returns the current contents of the cache folder
        /// </summary>
        /// <returns></returns>
        private async Task <bool> SetBackgroundImage(UpdateTypes type, StorageFile file)
        {
            bool wasSuccess = false;

            // Try to set the image
            UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;

            if (type == UpdateTypes.LockScreen)
            {
                wasSuccess = await profileSettings.TrySetLockScreenImageAsync(file);
            }
            else
            {
                wasSuccess = await profileSettings.TrySetWallpaperImageAsync(file);
            }

            return(wasSuccess);
        }
        private async Task LockScreenBackground()
        {
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                string filename = "background.jpg";

                StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename);

                UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current;
                if (!await settings.TrySetWallpaperImageAsync(file))
                {
                    System.Diagnostics.Debug.WriteLine("Failed");
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Success");
                }
            }
        }
예제 #24
0
        private async void btnAplicar_Click(object sender, RoutedEventArgs e)
        {
            ContentDialog setWallpaperDialog = new ContentDialog
            {
                Title             = "Aplicar wallpaper como fondo de pantalla?",
                Content           = $"Desea aplicar la imagen {imagenSeleccionada.Nombre} como fondo de pantalla?",
                CloseButtonText   = "Cancelar",
                PrimaryButtonText = "Aplicar"
            };

            ContentDialogResult result = await setWallpaperDialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;

                await profileSettings.TrySetWallpaperImageAsync(files[imagenSeleccionada.Posicion]);
            }
        }
예제 #25
0
        /// <summary>
        /// Returns the current contents of the cache folder
        /// </summary>
        /// <returns></returns>
        private async Task <bool> SetBackgroundImage(bool isLockScreen, StorageFile file)
        {
            bool wasSuccess = false;

            // Make sure we can do it
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                // Try to set the image
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                if (isLockScreen)
                {
                    wasSuccess = await profileSettings.TrySetLockScreenImageAsync(file);
                }
                else
                {
                    wasSuccess = await profileSettings.TrySetWallpaperImageAsync(file);
                }
            }
            return(wasSuccess);
        }
예제 #26
0
        public static async Task ApplyImagetoWallpaperAsync(StorageFile file)
        {
            ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;

            if ((string)settings.Values["UseWeatherForDesktop"] == "true")
            {
                if (UserProfilePersonalizationSettings.IsSupported())
                {
                    UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                    await profileSettings.TrySetWallpaperImageAsync(file);
                }
            }
            if ((string)settings.Values["UseWeatherForLockscreen"] == "true")
            {
                if (UserProfilePersonalizationSettings.IsSupported())
                {
                    UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                    await profileSettings.TrySetLockScreenImageAsync(file);
                }
            }
        }
예제 #27
0
        private async void SetWallpaper()
        {
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                progressImage2.IsActive       = true;
                textBlockWallpaper.Visibility = Visibility.Visible;
                textBlockWallpaper.Text       = "Descargando wallpaper";

                btnAplicar.IsEnabled = false;

                bool descarga = await DownloadImage(nasa.hdurl, $"{nasa.title}.jpg");

                if (descarga)
                {
                    textBlockWallpaper.Text = "Aplicando wallpaper";

                    UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                    bool res = await profileSettings.TrySetWallpaperImageAsync(fileFondo);

                    if (res)
                    {
                        progressImage2.IsActive       = false;
                        textBlockWallpaper.Visibility = Visibility.Collapsed;
                        btnAplicar.IsEnabled          = true;
                    }
                    else
                    {
                        progressImage2.IsActive = false;
                        textBlockWallpaper.Text = "Error al establecer wallpaper";
                        btnAplicar.IsEnabled    = true;
                    }
                }
                else
                {
                    progressImage2.IsActive = false;
                    textBlockWallpaper.Text = "Error en la descarga";
                    btnAplicar.IsEnabled    = true;
                }
            }
        }
예제 #28
0
        public static async Task <bool> setWallpaper(string filename)
        {
            StorageFolder fold = Windows.Storage.ApplicationData.Current.LocalFolder;
            var           file = await fold.GetFileAsync(filename);

            UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
            //bool success = await profileSettings.TrySetLockScreenImageAsync(file);
            bool success = await profileSettings.TrySetWallpaperImageAsync(file);

            var timer = new Windows.UI.Xaml.DispatcherTimer {
                Interval = TimeSpan.FromSeconds(0.5)
            };

            timer.Tick += (sender, args) =>
            {
                MainPage.initTitlebar();
                timer.Stop();
            };

            timer.Start();
            return(success);
        }
예제 #29
0
        public static async void SetAsBackground(WallpaperType type, string filePath, IShellPage associatedInstance)
        {
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                // Get the path of the selected file
                BaseStorageFile sourceFile = await StorageHelpers.ToStorageItem <BaseStorageFile>(filePath, associatedInstance);

                if (sourceFile == null)
                {
                    return;
                }

                // Get the app's local folder to use as the destination folder.
                BaseStorageFolder localFolder = ApplicationData.Current.LocalFolder;

                // the file to the destination folder.
                // Generate unique name if the file already exists.
                // If the file you are trying to set as the wallpaper has the same name as the current wallpaper,
                // the system will ignore the request and no-op the operation
                BaseStorageFile file = await FilesystemTasks.Wrap(() => sourceFile.CopyAsync(localFolder, sourceFile.Name, NameCollisionOption.GenerateUniqueName).AsTask());

                if (file == null)
                {
                    return;
                }

                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                if (type == WallpaperType.Desktop)
                {
                    // Set the desktop background
                    await profileSettings.TrySetWallpaperImageAsync(await file.ToStorageFileAsync());
                }
                else if (type == WallpaperType.LockScreen)
                {
                    // Set the lockscreen background
                    await profileSettings.TrySetLockScreenImageAsync(await file.ToStorageFileAsync());
                }
            }
        }
예제 #30
0
        public async Task <bool> SetAsAsync(string Uri = null, StorageFile image = null, SetAs setAs = SetAs.Wallpaper)
        {
            bool        success = false;
            StorageFile file;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                try
                {
                    file = image ?? await StorageFile.GetFileFromPathAsync(Uri) ?? throw new ArgumentNullException(nameof(image));
                }
                catch (Exception)
                {
                    throw;
                }

                var wallpaperPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Wallpaper");
                if (!Directory.Exists(wallpaperPath))
                {
                    Directory.CreateDirectory(wallpaperPath);
                }

                IStorageFolder wallpaperFolder = await StorageFolder.GetFolderFromPathAsync(wallpaperPath);

                var copiedFile = await file.CopyAsync(wallpaperFolder, file.Name, NameCollisionOption.ReplaceExisting);

                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                if (setAs == SetAs.Wallpaper)
                {
                    success = await profileSettings.TrySetWallpaperImageAsync(copiedFile);
                }
                else
                {
                    success = await profileSettings.TrySetLockScreenImageAsync(copiedFile);
                }
            }
            return(success);
        }