Esempio n. 1
0
        public bool CheckAllFoldersExist(List<ShowItem> showlist)
        {
            // show MissingFolderAction for any folders that are missing
            // return false if user cancels

            this.LockShowItems();

            if (showlist == null) // nothing specified?
                showlist = ShowItems; // everything

            foreach (ShowItem si in showlist)
            {
                if (!si.DoMissingCheck && !si.DoRename)
                    continue; // skip

                Dictionary<int, List<string>> flocs = si.AllFolderLocations(this.Settings);

                int[] numbers = new int[si.SeasonEpisodes.Keys.Count];
                si.SeasonEpisodes.Keys.CopyTo(numbers, 0);
                foreach (int snum in numbers)
                {
                    if (si.IgnoreSeasons.Contains(snum))
                        continue; // ignore this season

                    //int snum = kvp->Key;
                    if ((snum == 0) && (si.CountSpecials))
                        continue; // no specials season, they're merged into the seasons themselves

                    List<string> folders = new List<String>();

                    if (flocs.ContainsKey(snum))
                        folders = flocs[snum];

                    if ((folders.Count == 0) && (!si.AutoAddNewSeasons))
                        continue; // no folders defined or found, autoadd off, so onto the next

                    if (folders.Count == 0)
                    {
                        // no folders defined for this season, and autoadd didn't find any, so suggest the autoadd folder name instead
                        folders.Add(si.AutoFolderNameForSeason(snum, this.Settings));
                    }

                    foreach (string folderFE in folders)
                    {
                        String folder = folderFE;

                        // generate new filename info
                        bool goAgain = false;
                        DirectoryInfo di = null;
                        do
                        {
                            goAgain = false;
                            if (!string.IsNullOrEmpty(folder))
                            {
                                try
                                {
                                    di = new DirectoryInfo(folder);
                                }
                                catch
                                {
                                    goAgain = false;
                                    break;
                                }
                            }
                            if ((di == null) || (!di.Exists))
                            {
                                string sn = si.ShowName;
                                string text = snum + " of " + si.MaxSeason();
                                string theFolder = folder;
                                string otherFolder = null;

                                FAResult whatToDo = FAResult.kfaNotSet;

                                if (this.Args.MissingFolder == CommandLineArgs.MissingFolderBehaviour.Create)
                                    whatToDo = FAResult.kfaCreate;
                                else if (this.Args.MissingFolder == CommandLineArgs.MissingFolderBehaviour.Ignore)
                                    whatToDo = FAResult.kfaIgnoreOnce;

                                if (this.Args.Hide && (whatToDo == FAResult.kfaNotSet))
                                    whatToDo = FAResult.kfaIgnoreOnce; // default in /hide mode is to ignore

                                if (whatToDo == FAResult.kfaNotSet)
                                {
                                    // no command line guidance, so ask the user
                                    // 									MissingFolderAction ^mfa = gcnew MissingFolderAction(sn, text, theFolder);
                                    // 									mfa->ShowDialog();
                                    // 									whatToDo = mfa->Result;
                                    // 									otherFolder = mfa->FolderName;

                                    MissingFolderAction mfa = new MissingFolderAction(sn, text, theFolder);
                                    mfa.ShowDialog();
                                    whatToDo = mfa.Result;
                                    otherFolder = mfa.FolderName;
                                }

                                if (whatToDo == FAResult.kfaCancel)
                                {
                                    this.UnlockShowItems();
                                    return false;
                                }
                                else if (whatToDo == FAResult.kfaCreate)
                                {
                                    Directory.CreateDirectory(folder);
                                    goAgain = true;
                                }
                                else if (whatToDo == FAResult.kfaIgnoreAlways)
                                {
                                    si.IgnoreSeasons.Add(snum);
                                    this.SetDirty();
                                    break;
                                }
                                else if (whatToDo == FAResult.kfaIgnoreOnce)
                                    break;
                                else if (whatToDo == FAResult.kfaRetry)
                                    goAgain = true;
                                else if (whatToDo == FAResult.kfaDifferentFolder)
                                {
                                    folder = otherFolder;
                                    di = new DirectoryInfo(folder);
                                    goAgain = !di.Exists;
                                    if (di.Exists && (si.AutoFolderNameForSeason(snum, this.Settings).ToLower() != folder.ToLower()))
                                    {
                                        if (!si.ManualFolderLocations.ContainsKey(snum))
                                            si.ManualFolderLocations[snum] = new List<String>();
                                        si.ManualFolderLocations[snum].Add(folder);
                                        this.SetDirty();
                                    }
                                }
                            }
                        }
                        while (goAgain);
                    } // for each folder
                } // for each snum
            } // for each show
            this.UnlockShowItems();

            return true;
        }
        private void CreateSeasonFolder(ShowItem si, int snum, ICollection <string> ignoredLocations, string proposedFolderName)
        {
            string folder = proposedFolderName;

            // generate new filename info
            // ReSharper disable once RedundantAssignment
            bool          goAgain      = false;
            DirectoryInfo di           = null;
            bool          firstAttempt = true;

            do
            {
                goAgain = false;
                if (!string.IsNullOrEmpty(folder))
                {
                    try
                    {
                        di = new DirectoryInfo(folder);
                    }
                    catch
                    {
                        break;
                    }
                }

                if (ignoredLocations.Contains(folder))
                {
                    break;
                }

                if (di != null && di.Exists)
                {
                    continue;
                }

                string sn          = si.ShowName;
                string text        = snum + " of " + si.MaxSeason();
                string theFolder   = folder;
                string otherFolder = null;

                FaResult whatToDo = GetDefaultAction();

                if (TVSettings.Instance.AutoCreateFolders && firstAttempt)
                {
                    whatToDo     = FaResult.kfaCreate;
                    firstAttempt = false;
                }

                if (whatToDo == FaResult.kfaNotSet)
                {
                    // no command line guidance, so ask the user
                    MissingFolderAction mfa = new MissingFolderAction(sn, text, theFolder);
                    mfa.ShowDialog();
                    whatToDo    = mfa.Result;
                    otherFolder = mfa.FolderName;
                }

                switch (whatToDo)
                {
                case FaResult.kfaRetry:
                    goAgain = true;
                    break;

                case FaResult.kfaDifferentFolder:
                    folder  = otherFolder;
                    goAgain = UpdateDirectory(si, snum, folder);
                    break;

                case FaResult.kfaNotSet:
                    break;

                case FaResult.kfaCancel:
                    throw new TVRenameOperationInterruptedException();

                case FaResult.kfaCreate:
                    TryCreateDirectory(folder, sn, text);
                    goAgain = true;
                    break;

                case FaResult.kfaIgnoreOnce:
                    ignoredLocations.Add(folder);
                    break;

                case FaResult.kfaIgnoreAlways:
                    si.IgnoreSeasons.Add(snum);
                    Doc.SetDirty();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            } while (goAgain);
        }
        private void CreateFolder(MovieConfiguration si, ICollection <string> ignoredLocations, string proposedFolderName, IDialogParent owner)
        {
            string folder = proposedFolderName;

            // generate new filename info
            // ReSharper disable once RedundantAssignment
            bool          goAgain      = false;
            DirectoryInfo di           = null;
            bool          firstAttempt = true;

            do
            {
                goAgain = false;
                if (!string.IsNullOrEmpty(folder))
                {
                    try
                    {
                        di = new DirectoryInfo(folder);
                    }
                    catch (Exception e)
                    {
                        LOGGER.Warn($"Could not create Folder {folder} as {e.Message}.");
                        break;
                    }
                }

                if (ignoredLocations.Contains(folder))
                {
                    break;
                }

                if (di != null && di.Exists)
                {
                    continue;
                }

                string?otherFolder = null;

                FaResult whatToDo = GetDefaultAction();

                if (TVSettings.Instance.AutoCreateFolders && firstAttempt)
                {
                    whatToDo     = FaResult.kfaCreate;
                    firstAttempt = false;
                }

                if (whatToDo == FaResult.kfaNotSet)
                {
                    // no command line guidance, so ask the user
                    MissingFolderAction mfa = new MissingFolderAction(si.ShowName, "", folder);

                    owner.ShowChildDialog(mfa);
                    whatToDo    = mfa.Result;
                    otherFolder = mfa.FolderName;
                    mfa.Dispose();
                }

                switch (whatToDo)
                {
                case FaResult.kfaRetry:
                    goAgain = true;
                    break;

                case FaResult.kfaDifferentFolder:
                    if (otherFolder != null)
                    {
                        folder = otherFolder;
                    }
                    goAgain = UpdateDirectory(si, folder);
                    break;

                case FaResult.kfaNotSet:
                    break;

                case FaResult.kfaCancel:
                    throw new TVRenameOperationInterruptedException();

                case FaResult.kfaCreate:
                    TryCreateDirectory(folder, si.ShowName);
                    goAgain = true;
                    break;

                case FaResult.kfaIgnoreOnce:
                    ignoredLocations.Add(folder);
                    break;

                case FaResult.kfaIgnoreAlways:
                    // si.IgnoreSeasons.Add(snum);  TODO What should we do here? Turn off auto / manual folders?
                    Doc.SetDirty();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            } while (goAgain);
        }