Example #1
0
 /// <summary>
 /// Asks the user parameters on how to organize the comics.
 /// </summary>
 void Configure()
 {
     Console.Write("Do you want to use groups? (y/n): ");
     _DoGroups = Console.ReadLine().Trim().Equals("y");
     while (true)
     {
         Console.Write("What's the min number of comics for making a group/artist? (Recommended is 2): ");
         string input = Console.ReadLine().Trim();
         if (int.TryParse(input, out int minNumber))
         {
             _MinNumberOfComics = minNumber;
             break;
         }
         ConsoleUtilities.ErrorMessage("Please write a valid number!");
     }
     while (true)
     {
         Console.Write("Input the path (if you're on mac you need to escape it before!): ");
         string input = Console.ReadLine().Trim();
         if (Directory.Exists(input))
         {
             _MainPath = input;
             break;
         }
         ConsoleUtilities.ErrorMessage("Please write a valid path to a directory!");
     }
 }
Example #2
0
        /// <summary>
        /// Starts and shows the process to organize all comics.
        /// </summary>
        /// <returns></returns>
        async Task OrganizeAsync()
        {
            _StartTime = DateTime.Now;
            PopulateDictionary();
            CleanDictionary();

            await MoveComics();

            _EndTime = DateTime.Now;
            ConsoleUtilities.Division();
            ConsoleUtilities.SuccessMessage("TASK FINISHED!");
            ConsoleUtilities.WarningMessage("{0} organizing {1} directories", (_EndTime - _StartTime).ToString(), "" + _TotalDirectories);

            ConsoleUtilities.WarningMessage("Success Rate: {0}%", SuccessProbability.ToString("P2"));
            ConsoleUtilities.WarningMessage("TOTAL ERROR COUNT: {0}", _Errors.Count + "");

            foreach (var errorMessage in _Errors)
            {
                ConsoleUtilities.ErrorMessage(errorMessage);
            }
        }
Example #3
0
        /// <summary>
        /// Populates the <c>_ComicsNewPaths</c> dictionary with all the comics that need to be moved.
        /// It does so in a way that all comics that need to be moved appear just once in the entire dictionary,
        /// this way we can move all comics asynchronously.
        /// </summary>
        void PopulateDictionary()
        {
            ConsoleUtilities.InfoMessage("Scanning directories...");
            try
            {
                Environment.CurrentDirectory = Path.GetPathRoot(Environment.SystemDirectory);
                if (_DoGroups)
                {
                    GetPreviousToDictionary();
                }

                foreach (var subDirectoryPath in Directory.EnumerateDirectories(_MainPath))
                {
                    string subDirectoryName = Path.GetFileName(subDirectoryPath);

                    //If it isn't a directory with files already organized, organize it
                    if (_AlreadyOrganizedRegex.IsMatch(subDirectoryName))
                    {
                        continue;
                    }

                    for (int i = 0; i < _Regices.Count(); i++)
                    {
                        Regex regex = _Regices[i];
                        if (!regex.IsMatch(subDirectoryName))
                        {
                            continue;
                        }

                        int[] idsGroup = regex.GetGroupNumbers();
                        (string groupName, string artistName, string comicName) =
                            GetComicInfo(idsGroup, regex.Match(subDirectoryName).Groups);

                        (string groupPath, string artistPath) = CreatePaths(groupName, artistName);

                        string artistFinalPath = Path.Combine(artistPath, comicName);
                        string groupFinalPath  = Path.Combine(groupPath, comicName);

                        InitializeKeyIfNotExists(artistPath);
                        _ComicsNewPaths[artistPath].Add(new ComicInfo(subDirectoryPath, artistFinalPath, artistName));

                        if (!_DoGroups || Directory.Exists(artistPath))
                        {
                            break;
                        }


                        InitializeKeyIfNotExists(groupPath);
                        _ComicsNewPaths[groupPath].Add(new ComicInfo(subDirectoryPath, groupFinalPath, artistName));

                        if (_ComicsNewPaths[artistPath].Count < _MinNumberOfComics)
                        {
                            break;
                        }

                        //Removes all references to previous comics that belonged to the same artist and group,
                        //which makes it safe to move all comics asynchonously
                        if (_ComicsNewPaths.TryGetValue(groupPath, out List <ComicInfo> listOfPaths))
                        {
                            listOfPaths.RemoveAll(info => info.ArtistName.Equals(artistName));
                        }

                        break;
                    }
                }
                ConsoleUtilities.InfoMessage("Finished!");
            }
            catch (Exception e)
            {
                ConsoleUtilities.ErrorMessage("An error ocurred...");
                Console.Error.WriteLine(e.Message);
            }
        }