public async Task CleanDuplicates(CommandContext ctx, [RemainingText(), Description("Ruta completa a la carpeta")] string rutacompleta)
 {
     string[] files = Directory.GetFiles(rutacompleta);
     foreach (string f in files)
     {
         ER_Anime e = new ER_Anime(f);
         Utilities.RemoveDuplicates(e);
     }
     ctx.Message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":white_check_mark:"));
 }
Beispiel #2
0
        /// <summary>
        /// From this ER_Anime, checks another versions of it and removes all the previous versions
        /// </summary>
        /// <returns>The final</returns>
        public static ER_Anime RemoveDuplicates(ER_Anime anime)
        {
            ER_Anime Proposal = anime;

            //We create the possible versions of the anime
            ER_Anime Standard = (ER_Anime)anime.Clone();

            Standard.IsV0 = false; Standard.IsV2 = false; Standard.HasMulti = false;
            ER_Anime V0 = (ER_Anime)Standard.Clone();

            V0.IsV0 = true;
            ER_Anime V2 = (ER_Anime)Standard.Clone();

            V2.IsV2 = true;
            ER_Anime Multi = (ER_Anime)Standard.Clone();

            Multi.HasMulti = true;

            //We check if a better version of the release exists and assign it to proposal (So Multi is better than V2 etc...)
            ER_Anime[] releases = { V0, Standard, V2, Multi };
            foreach (ER_Anime item in releases)
            {
                if (item.Exists())
                {
                    Proposal = (ER_Anime)item.Clone();
                }
            }
            //We delete every unwanted file
            foreach (ER_Anime item in releases)
            {
                if ((Proposal.FileName != item.FileName) && item.Exists())
                {
                    File.Delete(item.FullPath);
                }
            }

            //We keep some properties from the original property
            Standard.HasMulti  = Proposal.HasMulti;
            Standard.IsFinale  = Proposal.IsFinale;
            Standard.PreEncode = Proposal.PreEncode;

            //We rename the file so we get rid of any unwanted tag.
            if (Proposal.Exists())
            {
                File.Move(Proposal.FullPath, Standard.FullPath);
            }
            return(Proposal);
        }