private void HandleImageRenaming(bool allowTagBasedNaming, DirectoryInfo moveDirectory = null) { List <ImageType> filter = new List <ImageType>(); if (OptionsData.ThemeOptions.ExcludeRenamingStatic) { filter.Add(ImageType.Static); } if (OptionsData.ThemeOptions.ExcludeRenamingGif) { filter.Add(ImageType.GIF); } if (OptionsData.ThemeOptions.ExcludeRenamingVideo) { filter.Add(ImageType.Video); } switch (WallpaperManagerTools.ChooseSelectionType()) { case SelectionType.Active: if (InspectedImage != "") { if (WallpaperData.ContainsImage(InspectedImage)) { int imageIndex = selectedImages.IndexOf(InspectedImage); string[] newName = ImagePathing.RenameImage(InspectedImage, moveDirectory, allowTagBasedNaming); if (newName != null && newName.Length > 0) // this can occur if the given image is not able to be named { selectedImages[imageIndex] = newName[0]; // there will only be one entry in this array, the renamed image } } else { MessageBox.Show("Invalid image"); } } else { MessageBox.Show("There is no image selected"); } break; case SelectionType.All: if (MessageBox.Show("Are you sure you want to rename ALL " + selectedImages.Length + " selected images?", "Choose an option", MessageBoxButtons.YesNo) == DialogResult.Yes) { // Doing this will require a rebuild of the image selector to keep it in tact RebuildImageSelector(ImagePathing.RenameImages(selectedImages, moveDirectory, allowTagBasedNaming), false); } break; } }
//? This allows the image to be disposed when changing pages, otherwise it would just be loaded in the ImageEditorControl public async void LoadImage(ImageEditorControl parentEditorControl, string imagePath) { await Task.Run(() => { using (Image image = WallpaperManagerTools.GetImageFromFile(imagePath)) { if (image != null) // this will happen to unsupported file types { //! the image must be re-drawn to prevent it from being used by wallpaper manager //! which is why it needed to be put onto a bitmap //! don't change to image, if you do make sure to test what happens when an image is used & loaded simultaneously Bitmap imageBitmap = new Bitmap(image.Width, image.Height); using (Graphics g = Graphics.FromImage(imageBitmap)) g.DrawImage(image, 0, 0, image.Width, image.Height); loadedImageInfo.Add(imagePath, imageBitmap); //? Disposes images later (Whenever the page is changed) parentEditorControl.SetBackgroundImage(imageBitmap); } } }).ConfigureAwait(false); // ConfigureAwait(false) prevents a UI deadlock in the instance that the calling function needed to do LoadImage().Result }
private void buttonDeleteImage_Click(object sender, EventArgs e) { //! ADD A WARNING THAT LETS THE USER KNOW THAT THEY'LL BE REMOVING THE ACTUAL FILES (Which should get move to the recycling bin) //! ADD A WARNING THAT LETS THE USER KNOW THAT THEY'LL BE REMOVING THE ACTUAL FILES (Which should get move to the recycling bin) //! ADD A WARNING THAT LETS THE USER KNOW THAT THEY'LL BE REMOVING THE ACTUAL FILES (Which should get move to the recycling bin) if (selectedImages != null) { switch (WallpaperManagerTools.ChooseSelectionType()) { case SelectionType.Active: MessageBox.Show("Selected [This function is currently in development]"); break; case SelectionType.All: MessageBox.Show("All [This function is currently in development]"); break; } } else { MessageBox.Show("There are no images selected to delete"); } }
private static readonly float MIN_VOLUME = 0f; // might make this a really small decimal due to the potential of float errors //private static Guid guid = Guid.NewGuid(); public static async void CheckForMuteConditions() { await Task.Run(() => { int potentialAudioCount = 0; foreach (string wallpaper in WallpaperPathing.ActiveWallpapers) { if (WallpaperManagerTools.IsSupportedVideoType(wallpaper)) { potentialAudioCount++; } } //?if (potentialAudioCount == 0) return; // there's no need to check for muting if no wallpapers that can be muted exist bool muted = false; void ProcessMute() { MuteWallpapers(); muted = true; } if (OptionsData.ThemeOptions.VideoOptions.MuteIfApplicationFocused && !muted) { Process activeWindow = WindowTools.GetActiveWindowProcess(); string windowName = activeWindow.ProcessName; if (windowName != Process.GetCurrentProcess().ProcessName&& windowName != "explorer") //? explorer includes the desktop { WindowPlacementStyle windowStyle = WindowTools.GetWindowStyle(activeWindow); if (windowStyle == WindowPlacementStyle.Normal || windowStyle == WindowPlacementStyle.Maximized) { ProcessMute(); } } } if (OptionsData.ThemeOptions.VideoOptions.MuteIfApplicationMaximized && !muted) // every window needs to be checked for maximization { //xStopwatch test = new Stopwatch(); //xtest.Start(); foreach (Process p in Process.GetProcesses()) //? has the potential to take up a decent CPU load, not noticeable on the thread but still impactful { WindowPlacementStyle windowStyle = WindowTools.GetWindowStyle(p); if (windowStyle == WindowPlacementStyle.Maximized) { ProcessMute(); break; } } //xtest.Stop(); //xDebug.WriteLine("Ms taken to check for maximized app: " + test.ElapsedMilliseconds); } if ((OptionsData.ThemeOptions.VideoOptions.MuteIfAudioPlaying || WallpaperData.WallpaperManagerForm.IsViewingInspector) && !muted) { if (CheckForExternalAudio()) //? CheckForExternalAudio cannot be done on the UI thread | async doesn't fix this { ProcessMute(); } } if (IsWallpapersMuted && !muted) { UnmuteWallpapers(); } }).ConfigureAwait(false); //x while (thread.IsAlive) { /* do nothing | Thread.Join() will just freeze the application */ } << this is only needed if you're returning something }
private static bool CheckForExternalAudio() { WallpaperManagerForm wallpaperManagerForm = WallpaperData.WallpaperManagerForm; using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render)) { using (var sessionEnumerator = sessionManager.GetSessionEnumerator()) { if (wallpaperManagerForm.IsViewingInspector) { // if a video is playing in the inspector, mute the background // Trying to figure out the source would be difficult as all audio links to the app if (WallpaperManagerTools.IsSupportedVideoType(wallpaperManagerForm.InspectedImage)) { return(true); } } List <string> potentialNames = new List <string>(); foreach (string wallpaper in WallpaperPathing.ActiveWallpapers) { if (File.Exists(wallpaper)) { if (WallpaperManagerTools.IsSupportedVideoType(wallpaper)) // only videos should be checked { //xDebug.WriteLine("Active: " + new FileInfo(wallpaper).Name); potentialNames.Add(new FileInfo(wallpaper).Name); } } } if (potentialNames.Count == 0) { return(false); //? there's no audio to play } //? The name of the video playing on the WallpaperForm will definitely be given, so check if //? anything BUT those are playing and if so mute the wallpaper foreach (var session in sessionEnumerator) { // format of session.DisplayName for videos: videoName.extension - extension | We only want videoName.extension, cut off the first space string sessionName = session.DisplayName; string sessionVideoName = !sessionName.Contains(' ') ? sessionName : sessionName.Substring(0, sessionName.IndexOf(' ')); if (session.IconPath.Contains(Path.GetDirectoryName(Application.ExecutablePath))) { Debug.WriteLine("Encountered Audio of Application"); continue; } if (OptionsData.ThemeOptions.VideoOptions.MuteIfAudioPlaying) // this is checked again since in some cases this code was only called due to the inspector { if (!potentialNames.Contains(sessionVideoName)) // checking an audio source that doesn't match up with to the active wallpapers { using (var audioMeterInformation = session.QueryInterface <AudioMeterInformation>()) { if (audioMeterInformation.GetPeakValue() > MIN_VOLUME) // if the volume of this application is greater than MIN_VOLUME, mute all wallpapers { Debug.WriteLine("External Audio Playing: " + session.DisplayName); //xDebug.WriteLine(audioMeterInformation.GetPeakValue()); return(true); } } } } } } } return(false); }