Пример #1
0
        private void SelectAllImagesOfRank()
        {
            int selectedRank;

            try
            {
                selectedRank = int.Parse(Interaction.InputBox("Enter a rank to select: ", "Select Images of Rank"));
            }
            catch // no response
            {
                return;
            }

            if (WallpaperData.ContainsRank(selectedRank))
            {
                string[] imagesToSelect = WallpaperData.GetImagesOfRank(selectedRank);
                RebuildImageSelector_CheckRandomizer(imagesToSelect);
            }
            else
            {
                MessageBox.Show("Invalid Rank");
                SelectAllImagesOfRank();
                return; //? keep this here for just in case code is added below this segment in the future
            }
        }
Пример #2
0
 public void Unmute()
 {
     if (player != null && activeVideoImagePath != null)
     {
         player.Volume = WallpaperData.GetImageData(activeVideoImagePath).VideoSettings.Volume;
     }
 }
Пример #3
0
        // Filters a subset of images based on the active radio button (Not needed if your input is not already filtered in some way, there are functions for that)
        private string[] FilterImages(string[] imagesToFilter)
        {
            List <string> imagesToSelect = new List <string>();

            if (radioButtonAll.Checked) // All
            {
                foreach (string imagePath in imagesToFilter)
                {
                    imagesToSelect.Add(imagePath);
                }
            }
            else if (radioButtonUnranked.Checked) // Unranked
            {
                foreach (string imagePath in imagesToFilter)
                {
                    if (WallpaperData.GetImageRank(imagePath) == 0)
                    {
                        imagesToSelect.Add(imagePath);
                    }
                }
            }
            else if (radioButtonRanked.Checked) // Ranked
            {
                foreach (string imagePath in imagesToFilter)
                {
                    if (WallpaperData.GetImageRank(imagePath) != 0)
                    {
                        imagesToSelect.Add(imagePath);
                    }
                }
            }

            return(imagesToSelect.ToArray());
        }
Пример #4
0
        // Remove Tag From Images
        private void RemoveTagFromImages(string[] targetImages, Button tagButton)
        {
            if (MessageBox.Show("Remove tag from all selected images?", "Choose an option", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                if (targetImages.Length > 0)
                {
                    string unincludedImages = "The following images you attempted to remove a tag from are not included:";
                    foreach (string image in targetImages)
                    {
                        if (WallpaperData.ContainsImage(image))
                        {
                            WallpaperData.GetImageData(image).RemoveTag(activeTag);
                        }
                        else
                        {
                            unincludedImages += "\n" + image;
                        }
                    }

                    if (unincludedImages.Contains("\n"))
                    {
                        MessageBox.Show(unincludedImages);
                    }
                }
                else
                {
                    MessageBox.Show("There are no images selected to remove this tag from");
                }
            }
        }
Пример #5
0
        public IMaybe <WallpaperData> GetById(Guid id)
        {
            using (var stream = _fs.OpenDownloadStream(id))
            {
                if (stream != null)
                {
                    var data = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);

                    var dto = new WallpaperData
                    {
                        Id   = id,
                        Data = data,
                    };

                    if (stream.FileInfo.Metadata.IsBsonDocument &&
                        stream.FileInfo.Metadata.TryGetValue(WALLPAPER_ID_FIELD_NAME, out var wallpaperId) &&
                        wallpaperId.IsGuid)
                    {
                        dto.WallpaperId = wallpaperId.AsGuid;
                    }

                    return(new Maybe <WallpaperData>(dto));
                }
            }

            return(new Maybe <WallpaperData>(null));
        }
Пример #6
0
        private void buttonModifyMaxRank_Click(object sender, EventArgs e)
        {
            int newRankMax;

            try
            {
                newRankMax = int.Parse(Interaction.InputBox("Enter a new max rank", "Modify Max Rank", WallpaperData.GetMaxRank().ToString()));
            }
            catch // no response
            {
                return;
            }

            if (newRankMax > 0 && newRankMax != WallpaperData.GetMaxRank()) // cannot be equal to or less than 0 and this will not change anything if the same rank is chosen
            {
                if (newRankMax <= WallpaperData.LargestMaxRank)
                {
                    WallpaperData.SetMaxRank(newRankMax);
                }
                else
                {
                    MessageBox.Show("Cannot be larger than 1000");
                }
            }
            else
            {
                MessageBox.Show("Invalid Input");
            }
        }
Пример #7
0
        public void buttonTag_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Unlink tag?", "Choose an option", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Button  tagButton    = sender as Button;
                string  tagName      = TaggingTools.GetButtonTagName(tagButton);
                string  categoryName = TaggingTools.GetButtonCategoryName(tagButton);
                TagData linkedTag    = WallpaperData.TaggingInfo.GetTag(categoryName, tagName);

                foreach (Tuple <string, string> tagInfo in linkedTag.ChildTags)
                {
                    if (activeTag.ParentTags.Contains(tagInfo))
                    {
                        MessageBox.Show("You cannot unlink " + linkedTag.Name + " while it's child tag " + tagInfo.Item2 + " is also linked");
                        return;
                    }
                }

                if (MessageBox.Show("Would you like to also remove the tag " + tagName + " from images tagged with " + activeTag.Name + "?", "Choose an option", MessageBoxButtons.YesNo)
                    == DialogResult.Yes)
                {
                    foreach (string image in activeTag.GetLinkedImages())
                    {
                        WallpaperData.GetImageData(image).RemoveTag(linkedTag);
                    }
                }

                activeTag.UnlinkTag(linkedTag);
                tagButton.Dispose();
            }
        }
Пример #8
0
        // Add Tag To Images
        private void AddTagToImages(string[] targetImages)
        {
            if (targetImages.Length > 0)
            {
                string unincludedImages = "The following images you attempted to tag are not included:";
                foreach (string image in targetImages)
                {
                    if (WallpaperData.ContainsImage(image))
                    {
                        WallpaperData.GetImageData(image).AddTag(WallpaperData.TaggingInfo.GetTagParentCategory(activeTag), activeTag.Name);
                    }
                    else
                    {
                        unincludedImages += "\n" + image;
                    }
                }

                if (unincludedImages.Contains("\n"))
                {
                    MessageBox.Show(unincludedImages);
                }
            }
            else
            {
                MessageBox.Show("There are no images to tag");
            }
        }
Пример #9
0
        public static string[] RenameImages(string[] images, DirectoryInfo moveDirectory, bool allowTagBaseNaming)
        {
            ///-----Filtering & Initial Processing-----

            // Convert string array to WallpaperData.ImageData array and remove images that conflict with the user's filter
            List <WallpaperData.ImageData> imagesData = new List <WallpaperData.ImageData>();

            ImageType[] filter = GetFilter();
            foreach (string image in images)
            {
                bool filterBreached = false;
                foreach (ImageType imageType in filter) // allows for the filtering of an image type, i.e. Static, GIF, & Video
                {
                    if (WallpaperData.GetAllImagesOfType(imageType).Contains(image))
                    {
                        filterBreached = true;
                        break;
                    }
                }

                if (filterBreached)
                {
                    continue;
                }

                imagesData.Add(WallpaperData.GetImageData(image));
            }

            WallpaperData.ImageData[] imagesToRename = imagesData.ToArray();

            //? This checks if all images were filtered out
            if (imagesToRename.Length == 0)
            {
                MessageBox.Show("None of the given images were able to be renamed");
                return(null);
            }

            //-----Begin Renaming Process-----

            //! Don't forget to save the theme after renaming! (Take note of the return statements)
            //! Don't forget to save the theme after renaming! (Take note of the return statements)
            //! Don't forget to save the theme after renaming! (Take note of the return statements)

            if (allowTagBaseNaming)
            {
                return(TagBasedNaming(imagesToRename, moveDirectory));
            }
            else
            {
                // regardless of if an image is tagged are not, all images in this code block will be directly MOVED (this only applies to moved images)
                // read the TODOs below for some related comments, although there should still be yet another renaming segment below for directly renamed images
            }

            // TODO for all images that won't be renamed based on tags, you should gather a collection of all tag-based renamed images so that they won't be processed a second time
            // TODO See if you can use hashSet's union()/unionWith()/intersectWith() system for this
            // TODO Considering that the filter doesn't highlight the possibility of moving naming-disabled images, the user should be warned of this option with a prompt

            return(null);
        }
Пример #10
0
 private void checkBoxWeightedFrequency_CheckedChanged(object sender, EventArgs e)
 {
     WallpaperData.UpdateImageTypeWeights();
     ThemeOptions.WeightedFrequency = checkBoxWeightedFrequency.Checked; //? this needs to be modified before the below is called
     //? the image type doesn't matter here, only calling this so that the exact frequencies can be updated | ToString() must remain to use the proper method
     FrequencyCalculator.UpdateFrequency(textBoxRelativeStatic, ImageType.Static, FrequencyType.Relative, ref ThemeOptions);
     ResetFrequencyText();
 }
Пример #11
0
        private static bool RandomizeWallpapers()
        {
            Random rand = new Random();

            // Gather potential wallpapers

            string[] potentialWallpapers = new string[DisplayData.Displays.Length];
            for (int i = 0; i < DisplayData.Displays.Length; i++)
            {
                ImageType imageTypeToSearchFor = ImageType.None;

                double staticChance = OptionsData.GetExactFrequency(ImageType.Static);
                double gifChance    = OptionsData.GetExactFrequency(ImageType.GIF);
                double videoChance  = OptionsData.GetExactFrequency(ImageType.Video);

                ImageType[] imageTypeIndexes     = { ImageType.Static, ImageType.GIF, ImageType.Video };
                double[]    imageTypePercentages = { staticChance, gifChance, videoChance };

                imageTypeToSearchFor = rand.NextInWeightedArray(imageTypeIndexes, imageTypePercentages);

                if (WallpaperData.IsAllImagesOfTypeUnranked(imageTypeToSearchFor))
                {
                    MessageBox.Show("Attempted to set a wallpaper to an image type with no valid/ranked images. Wallpaper Change Cancelled [IMAGE TYPE: " + imageTypeToSearchFor + "]" +
                                    "\n\nEither change relative frequency chance of the above image type to 0% (Under Frequency in the options menu)" +
                                    "or activate some wallpapers of the above image type (Unranked images with a rank of 0 are inactive");
                    return(false);
                }

                int randomRank = GetRandomRank(ref rand, imageTypeToSearchFor);

                // Find random image path
                if (randomRank != -1)
                {
                    Debug.WriteLine("Setting Wallpaper: " + i);
                    potentialWallpapers[i] = WallpaperData.GetRandomImageOfRank(randomRank, ref rand, imageTypeToSearchFor);

                    if (!WallpaperData.GetImageData(potentialWallpapers[i]).Active)
                    {
                        //! This shouldn't happen, if this does you have a bug to fix
                        MessageBox.Show("ERROR: Attempted to set display " + i + " to an inactive wallpaper | A new wallpaper has been chosen");
                        i--; // find another wallpaper, the selected wallpaper is inactive
                    }
                }
                else
                {
                    Debug.WriteLine("-1 rank selected | Fix Code | This will occur if all ranks are 0");
                }
            }

            ModifyWallpaperOrder(ref potentialWallpapers);
            UpcomingWallpapers.Enqueue(potentialWallpapers);

            return(true);
        }
Пример #12
0
 // Add Tag To Image
 private void AddTagToImage(string targetImage)
 {
     if (WallpaperData.ContainsImage(targetImage))
     {
         WallpaperData.GetImageData(targetImage).AddTag(WallpaperData.TaggingInfo.GetTagParentCategory(activeTag), activeTag.Name);
     }
     else
     {
         MessageBox.Show("The image you attempted to tag is not included");
     }
 }
Пример #13
0
        private void buttonSelectImagesInFolder_Click(object sender, EventArgs e)
        {
            using (CommonOpenFileDialog dialog = new CommonOpenFileDialog())
            {
                dialog.IsFolderPicker = true;

                if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    RebuildImageSelector_CheckRandomizer(FilterImages(WallpaperData.GetImagesOfFolder(dialog.FileName)));
                }
            }
        }
Пример #14
0
        // Picks ranks based on their default percentiles (Where the highest rank is the most likely to appear and it goes down from there)
        private static int GetRandomRank(ref Random rand, ImageType imageType)
        {
            Debug.WriteLine("Searching for: " + imageType);
            // the percentiles for weighted ranks change everytime an image's rank is altered or if the image type is not none
            if ((WallpaperData.potentialWeightedRankUpdate && OptionsData.ThemeOptions.WeightedRanks) || WallpaperData.potentialRegularRankUpdate || imageType != ImageType.None)
            {
                WallpaperData.UpdateRankPercentiles(imageType); //? this method sets the above booleans to false
            }

            Dictionary <int, double> modifiedRankPercentiles = WallpaperData.GetRankPercentiles(imageType);

            return(rand.NextInWeightedArray(modifiedRankPercentiles.Keys.ToArray(), modifiedRankPercentiles.Values.ToArray()));
        }
Пример #15
0
 // Remove Tag From Image
 private void RemoveTagFromImage(string targetImage, Button tagButton)
 {
     if (MessageBox.Show("Remove tag from active image?", "Choose an option", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         if (WallpaperData.ContainsImage(targetImage))
         {
             WallpaperData.GetImageData(targetImage).RemoveTag(activeTag);
         }
         else
         {
             MessageBox.Show("The image you attempted to remove a tag from is not included");
         }
     }
 }
Пример #16
0
        public bool Insert(WallpaperData data)
        {
            var options = new GridFSUploadOptions
            {
                Metadata = new BsonDocument
                {
                    { WALLPAPER_ID_FIELD_NAME, data.WallpaperId }
                }
            };

            _fs.UploadFromBytes(data.Id, data.Id.ToString(), data.Data, options);

            return(true);
        }
Пример #17
0
 private void buttonSelectImages_Click(object sender, EventArgs e)
 {
     if (radioButtonAll.Checked) // All
     {
         RebuildImageSelector_CheckRandomizer(WallpaperData.GetAllImages());
     }
     else if (radioButtonUnranked.Checked) // Unranked
     {
         RebuildImageSelector_CheckRandomizer(WallpaperData.GetImagesOfRank(0));
     }
     else if (radioButtonRanked.Checked) // Ranked
     {
         RebuildImageSelector_CheckRandomizer(WallpaperData.GetAllRankedImages());
     }
 }
Пример #18
0
        private string[] SelectAllImagesOfType(ImageType imageType)
        {
            switch (imageType)
            {
            case ImageType.Static:
                return(WallpaperData.GetAllImagesOfType(ImageType.Static));

            case ImageType.GIF:
                return(WallpaperData.GetAllImagesOfType(ImageType.GIF));

            case ImageType.Video:
                return(WallpaperData.GetAllImagesOfType(ImageType.Video));

            default:
                return(null);
            }
        }
Пример #19
0
        private void SaveOptionsData(object sender, FormClosedEventArgs e)
        {
            //-----Theme Settings-----
            ThemeOptions.LargerImagesOnLargerDisplays        = checkBoxLargerImagesOnLargerDisplays.Checked;
            ThemeOptions.HigherRankedImagesOnLargerDisplays  = checkBoxHigherRankedImagesOnLargerDisplays.Checked;
            ThemeOptions.EnableDetectionOfInactiveImages     = checkBoxEnableDetectionOfInactiveImages.Checked;
            ThemeOptions.AllowTagBasedRenamingForMovedImages = checkBoxAllowTagNamingMoved.Checked;

            ThemeOptions.ExcludeRenamingStatic = checkBoxExcludeStatic.Checked;
            ThemeOptions.ExcludeRenamingGif    = checkBoxExcludeGif.Checked;
            ThemeOptions.ExcludeRenamingVideo  = checkBoxExcludeVideo.Checked;

            //? This will tell the program to update rank percentiles on the next wallpaper change
            bool updateRankPercentiles = ThemeOptions.WeightedRanks != checkBoxWeightedRanks.Checked || ThemeOptions.WeightedFrequency != checkBoxWeightedFrequency.Checked;

            ThemeOptions.WeightedRanks     = checkBoxWeightedRanks.Checked;
            ThemeOptions.WeightedFrequency = checkBoxWeightedFrequency.Checked;

            //--Video Options--
            ThemeOptions.VideoOptions.MuteIfAudioPlaying         = checkBoxAudioPlaying.Checked;
            ThemeOptions.VideoOptions.MuteIfApplicationMaximized = checkBoxApplicationMaximized.Checked;
            ThemeOptions.VideoOptions.MuteIfApplicationFocused   = checkBoxApplicationFocused.Checked;
            SetMinimumVideoLoops(); // lost focus won't trigger on closing the window
            SetMaximumVideoTime();  // lost focus won't trigger on closing the window

            // note that frequency settings had their opportunity to be changed throughout the form's lifespan

            OptionsData.ThemeOptions = ThemeOptions;

            //! This won't work unless OptionsData.ThemeOptions is updated first | Used to alter weighted rank changes
            if (updateRankPercentiles)
            {
                WallpaperData.UpdateRankPercentiles(ImageType.None);                        //! Now that image types exist this preemptive change may not be worth it
            }
            //-----Global Settings-----
            if (File.Exists(OptionsData.DefaultTheme))
            {
                OptionsData.DefaultTheme                       = labelDefaultThemePath.Text;
                OptionsData.EnableDefaultThemeHotkey           = checkBoxEnableGlobalHotkey.Checked;
                Properties.Settings.Default.DefaultTheme       = labelDefaultThemePath.Text;
                Properties.Settings.Default.DefaultThemeHotkey = checkBoxEnableGlobalHotkey.Checked;
            }

            Properties.Settings.Default.Save();
        }
Пример #20
0
        public RankDistributionChart()
        {
            InitializeComponent();

            int maxRank = WallpaperData.GetMaxRank();

            // Adds each rank's image count to the graph
            SuspendLayout();
            chartRankDistribution.ChartAreas[0].AxisX.Interval = maxRank / 20;
            chartRankDistribution.ChartAreas[0].AxisX.Maximum  = maxRank + 0.5; // this offsets the graph's visuals otherwise only half of the last bar would appear
            for (int i = 1; i <= maxRank; i++)
            {
                chartRankDistribution.Series[0].Points.Add(new DataPoint(i, WallpaperData.GetImagesOfRank(i).Length));
            }

            labelImageCount.Text = "Ranked Images: " + WallpaperData.GetAllRankedImages().Length + " | Unranked Images: " + (WallpaperData.GetAllImageData().Length - WallpaperData.GetAllRankedImages().Length);
            ResumeLayout();
        }
Пример #21
0
        private static bool FinalizeImagePathUpdate(string oldPath, string newPath)
        {
            try
            {
                //? Since File.Move is case insensitive, first we need to check if oldPath and newPath has the same letters when cases are ignored
                if (string.Equals(oldPath, newPath, StringComparison.CurrentCultureIgnoreCase))
                {
                    Debug.WriteLine("Cases ignored");
                    // If oldPath and newPath have the same letters, move the file to a temporary location then move it back to the intended location
                    File.Move(oldPath, TempImageLocation);
                    File.Move(TempImageLocation, newPath);
                }
                else // otherwise, if the cases do not matter, move the file normally
                {
                    File.Move(oldPath, newPath);
                }

                WallpaperData.GetImageData(oldPath).UpdatePath(newPath);
                return(true);
            }
            catch (Exception e)
            {
                // Most likely cause of an error is that the file was being used by another process
                List <Process> processes = FileUtil.WhoIsLocking(oldPath);
                if (processes.Count > 0)
                {
                    string processOutput = oldPath + "\nThe above image is being used by the following process: ";
                    for (int i = 0; i < processes.Count; i++)
                    {
                        processOutput += "\n" + processes[i].ProcessName;
                    }

                    MessageBox.Show(processOutput);
                }
                else
                {
                    MessageBox.Show("Image not changed: \n[" + oldPath + "] " +
                                    "\n\nIntended new path: \n[" + newPath + "] " +
                                    "\n\nError: " + e.Message);
                }
            }

            return(false);
        }
Пример #22
0
        private static void ConflictResolveIdenticalRanks(ref string[] reorderedWallpapers)
        {
            bool conflictFound = false;
            Dictionary <int, List <string> > rankConflicts = new Dictionary <int, List <string> >();

            foreach (string wallpaper in reorderedWallpapers)
            {
                int wallpaperRank = WallpaperData.GetImageRank(wallpaper);
                if (!rankConflicts.ContainsKey(wallpaperRank))
                {
                    rankConflicts.Add(wallpaperRank, new List <string> {
                        wallpaper
                    });
                }
                else // more than one wallpaper contains the same rank, they'll have to have their conflicts resolved below
                {
                    rankConflicts[wallpaperRank].Add(wallpaper);
                    conflictFound = true;
                }
            }

            if (conflictFound) // if this is false then nothing will happen and the original reorderedWallpapers value will persist
            {
                List <string> conflictResolvedOrder = new List <string>();
                foreach (int rank in rankConflicts.Keys)
                {
                    if (rankConflicts[rank].Count > 1) // conflict present, fix it by comparing image sizes and placing the largest image first
                    {
                        string[] conflictResolvedRank = LargestImagesWithCustomFilePath(rankConflicts[rank].ToArray());
                        foreach (string wallpaper in conflictResolvedRank)
                        {
                            conflictResolvedOrder.Add(wallpaper);
                        }
                    }
                    else
                    {
                        conflictResolvedOrder.Add(rankConflicts[rank][0]);
                    }
                }

                reorderedWallpapers = conflictResolvedOrder.ToArray();
            }
        }
Пример #23
0
        private void timerAudioFixer_Tick(object sender, EventArgs e)
        {
            if (IsPlayingVideo && !AudioManager.IsWallpapersMuted)
            {
                // TODO For whatever reason videos randomly use the audio of a previous video, find a more permanent solution to this fix
                // TODO The commented fix did not solve this
                // TODO The occurence is 'rare' enough for me to not know if the below fix has actually done anything yet
                player.Volume = WallpaperData.GetImageData(activeVideoImagePath).VideoSettings.Volume;

                /*
                 * WallpaperData.VideoSettings videoSettings = WallpaperData.GetImageData(activeVideoImagePath).VideoSettings;
                 * if (player.Volume != videoSettings.Volume)
                 * {
                 *  Debug.WriteLine("Error: Had to fix the volume of a wallpaper with the timerAudioFix control");
                 *  player.Volume = videoSettings.Volume;
                 * }
                 */
            }
        }
Пример #24
0
        private static void ModifyWallpaperOrder(ref string[] wallpapersToModify)
        {
            /* TODO
             * // request next 3 wallpapers, determine their preferred setting
             * // set first display with said preferred setting
             * // request next 3 wallpapers
             * // set second display with preferred setting
             * // no request
             * // set first wallpaper to next wallpaper (Using second set of requested wallpapers)
             * // request next 3 wallpapers, this changes the third wallpaper setting
             * // set third display, this will use the *second* preferred setting (Using third set of requested wallpapers)
             * // essentially, there will always be an upcoming set of preferred wallpapers, once that set surpassed, a new set will be made that all displays will have to follow
             */

            if (IsWallpapersValid(wallpapersToModify))
            {
                string[] reorderedWallpapers = new string[0];
                if (OptionsData.ThemeOptions.HigherRankedImagesOnLargerDisplays || OptionsData.ThemeOptions.LargerImagesOnLargerDisplays)
                {
                    int[] largestMonitorIndexOrder = DisplayData.GetLargestDisplayIndexOrder();

                    if (OptionsData.ThemeOptions.HigherRankedImagesOnLargerDisplays)
                    {
                        reorderedWallpapers = (from f in wallpapersToModify orderby WallpaperData.GetImageRank(f) descending select f).ToArray();

                        // both ranking and size are now a factor so first an image's rank will determine their index and then afterwards
                        // any ranking conflicts have their indexes determined by size rather than being random
                        if (OptionsData.ThemeOptions.LargerImagesOnLargerDisplays)
                        {
                            ConflictResolveIdenticalRanks(ref reorderedWallpapers);
                        }
                    }
                    else if (OptionsData.ThemeOptions.LargerImagesOnLargerDisplays)
                    {
                        reorderedWallpapers = LargestImagesWithCustomFilePath(wallpapersToModify);
                    }

                    //? Applies the final modification
                    wallpapersToModify = ApplyModifiedPathOrder(reorderedWallpapers, largestMonitorIndexOrder);
                }
            }
        }
Пример #25
0
        private static string[] TagBasedNaming(WallpaperData.ImageData[] imagesToRename, DirectoryInfo moveDirectory)
        {
            //! NOTE: THIS ONLY HANDLES TAGGED IMAGES | UNTAGGED OR UNNAMABLE IMAGES WILL HAVE TO BE HANDLED IN A SECOND SET
            Dictionary <string, Dictionary <string, HashSet <WallpaperData.ImageData> > > desiredNames = GetDesiredNames(imagesToRename, moveDirectory);

            //! Get extensions and names of images that aren't being touched using FileInfo, not
            //! Images that already exist, regardless of whether or not they are in the process of being renamed, cannot be touched
            //! If you were to rename an entire group of images with the same name, they'd have to be renamed twice to get the proper numbering in place
            //? Note that if a move directory was present, only one directory will be scanned

            // no need to group if there's only 1 image
            // not keeping this as a static option allows for more flexibility in when you want to keep a set of images together or not worry about that at all
            bool groupRenamedImages = imagesToRename.Length > 1 && MessageBox.Show("Group renamed images?", "Choose an option", MessageBoxButtons.YesNo) == DialogResult.Yes;

            Debug.WriteLine("Grouping: " + groupRenamedImages);

            List <string> finalNames = new List <string>();

            foreach (string directory in desiredNames.Keys)
            {
                Debug.WriteLine("\n\n\nDirectory:\n" + directory);
                FileInfo[]       directoryFiles = new DirectoryInfo(directory).GetFiles();
                HashSet <string> filePaths      = new HashSet <string>();
                foreach (FileInfo file in directoryFiles)
                {
                    string fileName = file.FullName;
                    filePaths.Add(fileName.Substring(0, fileName.IndexOf(file.Extension, StringComparison.Ordinal)).ToLower());
                }

                foreach (string name in desiredNames[directory].Keys)
                {
                    int    nameCount     = 1; // image counts don't start at 0
                    bool   canName       = false;
                    string directoryPath = directory + "\\";
                    string countlessName = directoryPath + name;
                    string startingName  = countlessName + nameCount;
                    Debug.WriteLine("\nStarting Name: " + startingName);

                    // This process will repeat until a group-able section is found (or none at all if groupRenamedImages is set to false)
                    while (!canName)
                    {
                        // Finds the next possible starting name
                        // There is no way to skip counting this 1 by 1 without *assuming* that all concurrent values of this name have been filled
                        while (filePaths.Contains(startingName.ToLower()))
                        {
                            nameCount++;
                            startingName = countlessName + nameCount;
                            Debug.WriteLine("Updating Starting Name: " + startingName);
                        }

                        Debug.WriteLine("Checkpoint Starting Name: " + startingName);

                        // Checks for the next fully available space
                        // Ensures that a group of images can be renamed together
                        canName = true;
                        if (groupRenamedImages)
                        {
                            for (int i = 0; i < desiredNames[directory][name].Count; i++)
                            {
                                string testName = countlessName + (nameCount + i);
                                if (filePaths.Contains(testName.ToLower())) //! Note: nameCount should only change if the process fails to update the position
                                {
                                    Debug.WriteLine("Grouping Failed At: " + testName);
                                    nameCount += i + 1; // sets the count to the next possibly valid position
                                    canName    = false;
                                    break;
                                }
                            }
                        }
                    }

                    Debug.WriteLine("Final Starting Name: " + startingName);

                    foreach (WallpaperData.ImageData image in desiredNames[directory][name])
                    {
                        string oldPath = image.Path;
                        string newPathWithoutExtension = countlessName + nameCount;

                        // last call for conflicts | if the images aren't grouped this is expected, if not then there was an unexpected issue
                        while (filePaths.Contains(newPathWithoutExtension.ToLower()))
                        {
                            nameCount++;
                            newPathWithoutExtension = countlessName + nameCount;
                        }

                        string extension = new FileInfo(image.Path).Extension;
                        string newPath   = newPathWithoutExtension + extension;
                        Debug.WriteLine("Setting Name: " + newPath);
                        nameCount++;

                        if (UpdateImagePath(oldPath, newPath, image))
                        {
                            finalNames.Add(newPath);
                        }
                        else
                        {
                            finalNames.Add(oldPath);
                        }
                    }
                }
            }

            WallpaperData.SaveData(WallpaperPathing.ActiveWallpaperTheme); //! Forgetting to save after renaming images could destroy a theme depending on the scale
            return(finalNames.ToArray());
        }
Пример #26
0
 private void buttonLoadDefaultTheme_Click(object sender, EventArgs e)
 {
     WallpaperData.LoadDefaultTheme();
 }
Пример #27
0
 public bool Update(WallpaperData data) => throw new NotSupportedException();
Пример #28
0
        // Recalculate Exact Frequency to account for changes to Relative Frequency
        // (This also displays to the user what the exact chance even is)
        private static void RecalculateExactFrequency(ref ThemeOptions ThemeOptions)
        {
            double chanceTotal = ThemeOptions.RelativeFrequency[ImageType.Static] +
                                 ThemeOptions.RelativeFrequency[ImageType.GIF] +
                                 ThemeOptions.RelativeFrequency[ImageType.Video];


            double staticRelativeChance = ThemeOptions.RelativeFrequency[ImageType.Static] / chanceTotal;
            double gifRelativeChance    = ThemeOptions.RelativeFrequency[ImageType.GIF] / chanceTotal;
            double videoRelativeChance  = ThemeOptions.RelativeFrequency[ImageType.Video] / chanceTotal;

            Debug.WriteLine("chanceTotal: " + chanceTotal);
            Debug.WriteLine("Static: " + staticRelativeChance);
            Debug.WriteLine("GIF: " + gifRelativeChance);
            Debug.WriteLine("Video: " + videoRelativeChance);

            if (!ThemeOptions.WeightedFrequency)
            {
                ThemeOptions.ExactFrequency[ImageType.Static] = staticRelativeChance;
                ThemeOptions.ExactFrequency[ImageType.GIF]    = gifRelativeChance;
                ThemeOptions.ExactFrequency[ImageType.Video]  = videoRelativeChance;
            }
            else
            {
                // Gets the average of both the weighted frequency and the original exact frequency, allowing relative frequency to have an impact on the weight
                double staticWeightedChance = WallpaperData.GetImageOfTypeWeight(ImageType.Static);
                double gifWeightedChance    = WallpaperData.GetImageOfTypeWeight(ImageType.GIF);
                double videoWeightedChance  = WallpaperData.GetImageOfTypeWeight(ImageType.Video);

                if (staticWeightedChance == 1) // prevents a division by 0 error below
                {
                    ThemeOptions.ExactFrequency[ImageType.Static] = 1;
                    ThemeOptions.ExactFrequency[ImageType.GIF]    = ThemeOptions.ExactFrequency[ImageType.Video] = 0;
                    return;
                }
                if (gifWeightedChance == 1) // prevents a division by 0 error below
                {
                    ThemeOptions.ExactFrequency[ImageType.GIF]    = 1;
                    ThemeOptions.ExactFrequency[ImageType.Static] = ThemeOptions.ExactFrequency[ImageType.Video] = 0;
                    return;
                }
                if (videoWeightedChance == 1) // prevents a division by 0 error below
                {
                    ThemeOptions.ExactFrequency[ImageType.Video]  = 1;
                    ThemeOptions.ExactFrequency[ImageType.Static] = ThemeOptions.ExactFrequency[ImageType.GIF] = 0;
                    return;
                }

                /*x
                 * ThemeOptions.ExactFrequency[ImageType.Static] = (staticWeightedChance + staticRelativeChance) / 2;
                 * ThemeOptions.ExactFrequency[ImageType.GIF] = (gifWeightedChance + gifRelativeChance) / 2;
                 * ThemeOptions.ExactFrequency[ImageType.Video] = (videoWeightedChance + videoRelativeChance) / 2;
                 */

                double staticWeightedRelativeChance = staticRelativeChance / (1 - staticWeightedChance);
                double gifWeightedRelativeChance    = gifRelativeChance / (1 - gifWeightedChance);
                double videoWeightedRelativeChance  = videoRelativeChance / (1 - videoWeightedChance);
                double weightedChanceTotal          = staticWeightedRelativeChance + gifWeightedRelativeChance + videoWeightedRelativeChance;

                ThemeOptions.ExactFrequency[ImageType.Static] = staticWeightedRelativeChance / weightedChanceTotal;
                ThemeOptions.ExactFrequency[ImageType.GIF]    = gifWeightedRelativeChance / weightedChanceTotal;
                ThemeOptions.ExactFrequency[ImageType.Video]  = videoWeightedRelativeChance / weightedChanceTotal;
            }
        }
Пример #29
0
        //? Using this will cause old wallpapers to remain visible if you aren't filling the entire screen

        /*
         * // makes the background transparent to prevent flickering (Only stops the 1 frame flicker when closing, not the one that occurs when loading)
         * protected override void OnPaintBackground(PaintEventArgs e)
         * {
         *  var sb = new SolidBrush(Color.FromArgb(0, 0, 0, 0));
         *  e.Graphics.FillRectangle(sb, this.DisplayRectangle);
         * }
         */

        // TODO Create a queue that stores pictureBoxes/axWindowMediaPlayers for each wallpaper. This will be used to allow transitions & prevent flickering from
        // TODO style readjustment when changing wallpapers by *locking* the previous wallpaper in place
        public void SetWallpaper(string imageLocation)
        {
            Loops = 0;
            WallpaperUptime.Stop();

            //! The below conditions were removed but I may consider re-adding this in the future when monitor-specific settings are added, although other methods of handling
            //! not changing a monitor's wallpaper would probably be better than this
            //!if (imageLocation == null) return; //? Under certain conditions a wallpaper won't be selected, this prevents the program from crashing over this

            if (!IsHandleCreated)
            {
                return;
            }

            if (InvokeRequired)
            {
                this.BeginInvoke((MethodInvoker) delegate { SetWallpaperProcess(); });
            }
            else
            {
                SetWallpaperProcess();
            }

            async void SetWallpaperProcess()
            {
                if (!WallpaperManagerTools.IsSupportedVideoType(imageLocation))
                {
                    IsPlayingVideo = false;

                    player.Stop();
                    panelWallpaper.Visible = false;
                    panelWallpaper.Enabled = false;

                    pictureBoxWallpaper.ImageLocation = imageLocation;
                    pictureBoxWallpaper.Enabled       = true;
                    pictureBoxWallpaper.Visible       = true;

                    activeVideoImagePath = null;
                }
                else
                {
                    IsPlayingVideo = true;
                    WallpaperUptime.Restart();

                    pictureBoxWallpaper.Visible = false;
                    pictureBoxWallpaper.Enabled = false;

                    panelWallpaper.Enabled = true;
                    panelWallpaper.Visible = true;

                    activeVideoImagePath = imageLocation;

                    await Task.Run(() =>
                    {
                        player.Reload(imageLocation);

                        WallpaperData.VideoSettings videoSettings = WallpaperData.GetImageData(imageLocation).VideoSettings;
                        player.Volume = AudioManager.IsWallpapersMuted ? 0 : videoSettings.Volume;
                        player.Speed  = videoSettings.PlaybackSpeed;
                    }).ConfigureAwait(false);
                }
            }

            ResetWallpaperStyle(); // this needs to be readjusted with each image
        }