예제 #1
0
        private async Task ChangeBackgroundAsync()
        {
            if (ImageDataService.UsedList == null)
            {
                ImageDataService.UsedList = new List <Photo>();
            }
            if (UserProfilePersonalizationSettings.IsSupported() && ImageDataService.CuratedWallpaperCollection?.Count > 0)
            {
                try
                {
                    IsBusy        = true;
                    SelectedPhoto = await GetNewPhotoAsync();

                    if (SelectedPhoto != null)
                    {
                        await BackgroundHelper.SetBackgroundAsync(SelectedPhoto);
                    }
                }
                catch (Exception ex)
                {
                    Telemetry.LogException(ex);
                    await DialogHelper.ShowDialogAsync("Something went wrong.");
                }
                finally
                {
                    IsBusy = false;
                }
            }
        }
예제 #2
0
        private static async Task <StorageFile> PrepareImageFileAsync(StorageFile resultFile)
        {
            if (!UserProfilePersonalizationSettings.IsSupported())
            {
                ToastService.SendToast("Your device can't set wallpaper.");
                return(null);
            }
            if (resultFile != null)
            {
                StorageFile file = null;

                //WTF, the file should be copy to LocalFolder to make the setting wallpaer api work.
                var folder  = ApplicationData.Current.LocalFolder;
                var oldFile = await folder.TryGetItemAsync(resultFile.Name) as StorageFile;

                if (oldFile != null)
                {
                    await resultFile.CopyAndReplaceAsync(oldFile);

                    file = oldFile;
                }
                else
                {
                    file = await resultFile.CopyAsync(folder);
                }
                return(file);
            }
            return(null);
        }
예제 #3
0
        private static async Task <StorageFile> PrepareImageFileAsync(StorageFile resultFile)
        {
            if (!UserProfilePersonalizationSettings.IsSupported())
            {
                ToastService.SendToast(ResourcesHelper.GetResString("SettingWallpaperNotSupported"));
                return(null);
            }

            try
            {
                if (resultFile != null)
                {
                    //WTF, the file should be copy to LocalFolder to make the setting wallpaer api work.
                    var         folder = ApplicationData.Current.LocalFolder;
                    StorageFile file;
                    if (await folder.TryGetItemAsync(resultFile.Name) is StorageFile oldFile)
                    {
                        await resultFile.CopyAndReplaceAsync(oldFile);

                        file = oldFile;
                    }
                    else
                    {
                        file = await resultFile.CopyAsync(folder);
                    }
                    return(file);
                }
            }
            catch (FileNotFoundException)
            {
                ShowFailedToast();
            }

            return(null);
        }
        async Task <bool> SetWallpaperAsync(string localAppDataFileName)
        {
            bool success = false;
            var  uri     = new Uri($"ms-appx:///Assets/{localAppDataFileName}");

            //generate new file name to avoid colitions
            var newFileName = $"{Guid.NewGuid().ToString()}{Path.GetExtension(localAppDataFileName)}";

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                var profileSettings = UserProfilePersonalizationSettings.Current;

                var wfile = await StorageFile.GetFileFromApplicationUriAsync(uri);

                //Copy the file to Current.LocalFolder because TrySetLockScreenImageAsync
                //Will fail if the image isn't located there
                using (Stream readStream = await wfile.OpenStreamForReadAsync(),
                       writestream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(newFileName,
                                                                                                       CreationCollisionOption.GenerateUniqueName)
                       )
                { await readStream.CopyToAsync(writestream); }

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

                success = await profileSettings.TrySetLockScreenImageAsync(file);
            }

            Debug.WriteLine(success);
            return(success);
        }
예제 #5
0
        internal static async Task ChangeLockScreenBackground(string path)
        {
            if (!UserProfilePersonalizationSettings.IsSupported())
            {
                return;
            }

            var folder = Path.GetDirectoryName(path);
            var file   = Path.GetFileName(path);

            try
            {
                var storageFolder = await StorageFolder.GetFolderFromPathAsync(folder);

                var storageFile = await storageFolder.GetFileAsync(file);

                using var stream = await storageFile.OpenAsync(FileAccessMode.Read);

                await LockScreen.SetImageStreamAsync(stream);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
0
        /// <summary>
        /// THREAD BLOCKING: Kicks off an update of the images, this will block the current thread.
        /// </summary>
        /// <param name="force"></param>
        public bool RunUpdate(bool force = false)
        {
            if ((IsDeskopEnabled || IsLockScreenEnabled) && UserProfilePersonalizationSettings.IsSupported())
            {
                TimeSpan timeSinceLastRun = DateTime.Now - LastImageUpdate;
                if (timeSinceLastRun.TotalMinutes > UpdateFrquency || force)
                {
                    // Make sure we aren't running
                    lock (this)
                    {
                        if (m_isRunning)
                        {
                            return(false);
                        }
                        m_isRunning = true;
                    }

                    // Do the updates
                    bool success = ActuallyDoTheUpdate(force);
                    if (success)
                    {
                        // Set the new update time
                        LastImageUpdate = DateTime.Now;
                    }
                    return(success);
                }
            }
            return(true);
        }
예제 #9
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));
                }
            });
        }
예제 #10
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();
            }
        }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
0
파일: LookImg.xaml.cs 프로젝트: kyoeye/MT2
        private void LockBackground_Click(object sender, RoutedEventArgs e)
        {
            //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync();//需要将下载的目录拿到

            UserProfilePersonalizationSettings locksetting = UserProfilePersonalizationSettings.Current;


            //bool b =  await locksetting.TrySetLockScreenImageAsync(file);
            // LockBackground.Label = b.ToString ();
        }
예제 #14
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);
        }
예제 #15
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);
            }
        }
예제 #16
0
        public static async Task <bool> SetWallpaperAsync(StorageFile localAppDataFileName)
        {
            bool success = false;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                success = await profileSettings.TrySetLockScreenImageAsync(localAppDataFileName);
            }
            return(success);
        }
예제 #17
0
        // Pass in a relative path to a file inside the local appdata folder
        private async Task <bool> SetLockscreenAsync(StorageFile file)
        {
            bool success = false;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                success = await profileSettings.TrySetLockScreenImageAsync(file);
            }
            return(success);
        }
예제 #18
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);
        }
예제 #19
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);
        }
예제 #20
0
 public static async Task <bool> ChangeLockScreenBackground(StorageFile imageFile)
 {
     if (UserProfilePersonalizationSettings.IsSupported())
     {
         UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current;
         return(await settings.TrySetLockScreenImageAsync(imageFile));
     }
     else
     {
         return(false);
     }
 }
예제 #21
0
 public static async Task <bool> ChangeWallPaper(StorageFile imageFile)
 {
     if (UserProfilePersonalizationSettings.IsSupported())
     {
         UserProfilePersonalizationSettings settings = UserProfilePersonalizationSettings.Current;
         return(await settings.TrySetWallpaperImageAsync(imageFile));
     }
     else
     {
         return(false);
     }
 }
예제 #22
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);
            }
        }
예제 #23
0
        public async Task <bool> SetWallpaperAsync(byte[] imageBytes)
        {
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(Constants.WallpaperFileName, CreationCollisionOption.ReplaceExisting);

                await FileIO.WriteBytesAsync(file, imageBytes);

                return(await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(file));
            }
            return(false);
        }
예제 #24
0
        public static async Task <string> SetBackgroundImageAsync(Posts posts, uint postShuffle, CropMethod method, Size screenSize, bool isLockscreen)
        {
            var folderName = isLockscreen ? LOCKSCREEN_FOLDER_NAME : WALLPAPER_FOLDER_NAME;

            Random rnd     = new Random();
            int    pointer = rnd.Next((int)postShuffle);

            var post = await GetPostAtAsync(posts, pointer);

            var previewBuffer = await(new Windows.Web.Http.HttpClient()).GetBufferAsync(new Uri(post.PreviewUrl));
            var jpegBuffer    = await(new Windows.Web.Http.HttpClient()).GetBufferAsync(new Uri(post.JpegUrl));


            var imageFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists);

            var imageFile = await imageFolder.CreateFileAsync($"{post.Id}.jpg", CreationCollisionOption.ReplaceExisting);

            await FileIO.WriteBufferAsync(imageFile, jpegBuffer);

            var jpegFile = await imageFolder.CreateFileAsync($"{post.Id}-original.jpg", CreationCollisionOption.ReplaceExisting);

            await FileIO.WriteBufferAsync(jpegFile, jpegBuffer);



            // Crop the image
            var imageSize = new Size(post.JpegWidth, post.JpegHeight);

            await CropImageFile(imageFile, imageSize, method, screenSize, previewBuffer);

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                if (isLockscreen)
                {
                    var b = await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(imageFile);

                    if (b)
                    {
                        return(post.Id.ToString());
                    }
                }
                else
                {
                    var b = await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(imageFile);

                    if (b)
                    {
                        return(post.Id.ToString());
                    }
                }
            }
            return("");
        }
예제 #25
0
        internal static async Task ChangeLockScreenBackground(string path)
        {
            if (!UserProfilePersonalizationSettings.IsSupported())
            {
                return;
            }

            if (UILogic.ConfigureWindows.GetMainWindow.MainImage.Effect != null || Clipboard.ContainsImage())
            {
                try
                {
                    var SaveImage = ImageDecoder.GetRenderedMagickImage();
                    if (SaveImage == null)
                    {
                        return;
                    }

                    UILogic.Tooltip.ShowTooltipMessage(Application.Current.Resources["Applying"]);

                    await Task.Run(() =>
                    {
                        // Create temp directory
                        var tempPath   = Path.GetTempPath();
                        var randomName = Path.GetRandomFileName() + ".png";

                        // Write temp file to it
                        using var filestream = new FileStream(tempPath + randomName, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.SequentialScan);
                        SaveImage.Write(filestream);
                        SaveImage.Dispose();
                        filestream.Close();

                        // Use it
                        _ = Apply(tempPath + randomName);

                        // Clean up
                        File.Delete(tempPath + randomName);
                        using var timer = new Timer(2000);
                        timer.Elapsed  += (s, x) => Directory.Delete(tempPath);
                    }).ConfigureAwait(true);

                    SaveImage.Dispose(); // Make visual studio happy
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
            else
            {
                await Apply(path).ConfigureAwait(false);
            }
        }
예제 #26
0
        // Pass in a relative path to a file inside the local appdata folder
        public async Task <bool> SetWallpaperAsync()
        {
            bool success = false;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                StorageFile file = await ImageHelper.GetLockscreenImage(GetAppBackgroundName());

                UserProfilePersonalizationSettings profileSettings = UserProfilePersonalizationSettings.Current;
                success = await profileSettings.TrySetLockScreenImageAsync(file);
            }
            return(success);
        }
예제 #27
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);
        }
예제 #28
0
        async public static Task <uint> ChangeWallpaperAsync()
        {
            if (UserProfilePersonalizationSettings.IsSupported())
            {
                //open file
                var local_folder = ApplicationData.Current.LocalFolder;
                var file         = await local_folder.CreateFileAsync("marker.txt", OpenIfExists);

                string value = value = await file.ReadTextAsync();

                uint current_index = 1;
                if (!string.IsNullOrWhiteSpace(value))
                {
                    current_index = uint.Parse(value);
                }

                //read and convert value of file



                //get file for index
                var image_path = $"ms-appdata:///local/club{current_index}.jpg";
                var image_uri  = new Uri(image_path);
                var image_file = await StorageFile.GetFileFromApplicationUriAsync(image_uri);

                bool was_set = false;
                try
                {
                    //display image file
                    was_set = await profile.Current.TrySetWallpaperImageAsync(image_file);
                }
                catch (Exception ex)
                {
                    was_set = false;
                }

                if (was_set)
                {
                    //increment index and store in file
                    current_index++;
                    if (current_index > 7)
                    {
                        current_index = 1;
                    }

                    await file.WriteTextAsync(current_index.ToString());
                }
                return(current_index);
            }
            return(0);
        }
예제 #29
0
        /// <summary>
        /// 改变锁屏壁纸。
        /// </summary>
        /// <param name="localAppDataFileName"></param>
        /// <returns>是否操作成功。</returns>
        public async Task <bool> SetLockScreenAsync(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.TrySetLockScreenImageAsync(file);
            }
            return(success);
        }
예제 #30
0
        public static async Task <bool> SetBingWallpaperLockScreenAsync()
        {
            bool success = false;

            if (UserProfilePersonalizationSettings.IsSupported())
            {
                StorageFile file = await StorageFile.GetFileFromPathAsync(LOCAL_IMAGE_FILE_JPG);

                StorageFile copyLocalFile = await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting);

                success = await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(copyLocalFile);
            }
            return(success);
        }