private void KeepTogether(ItemList actionlist) { // for each of the items in rcl, do the same copy/move if for other items with the same // base name, but different extensions ItemList extras = new ItemList(); foreach (Item action1 in actionlist) { if (!(action1 is ActionCopyMoveRename)) { continue; } ActionCopyMoveRename action = (ActionCopyMoveRename)(action1); try { DirectoryInfo sfdi = action.From.Directory; string basename = action.From.Name; int l = basename.Length; basename = basename.Substring(0, l - action.From.Extension.Length); string toname = action.To.Name; int l2 = toname.Length; toname = toname.Substring(0, l2 - action.To.Extension.Length); FileInfo[] flist = sfdi.GetFiles(basename + ".*"); foreach (FileInfo fi in flist) { //check to see whether the file is one of the types we do/don't want to include if (!TVSettings.Instance.KeepTogetherFilesWithType(fi.Extension)) { continue; } // do case insensitive replace string n = fi.Name; int p = n.IndexOf(basename, StringComparison.OrdinalIgnoreCase); string newName = n.Substring(0, p) + toname + n.Substring(p + basename.Length); if ((TVSettings.Instance.RenameTxtToSub) && (newName.EndsWith(".txt"))) { newName = newName.Substring(0, newName.Length - 4) + ".sub"; } ActionCopyMoveRename newitem = new ActionCopyMoveRename(action.Operation, fi, FileHelper.FileInFolder(action.To.Directory, newName), action.Episode, null, null); // tidyup on main action, not this // check this item isn't already in our to-do list if (ActionListContains(actionlist, newitem)) { continue; } if (!newitem.SameAs(action)) // don't re-add ourself { extras.Add(newitem); } } } catch (System.IO.PathTooLongException e) { string t = "Path or filename too long. " + action.From.FullName + ", " + e.Message; LOGGER.Warn(e, "Path or filename too long. " + action.From.FullName); if ((!Doc.Args.Unattended) && (!Doc.Args.Hide)) { MessageBox.Show(t, "Path or filename too long", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } foreach (Item action in extras) { // check we don't already have this in our list and, if we don't add it! bool have = AlreadyHaveAction(actionlist, action); if (!have) { actionlist.Insert(0, action); // put before other actions, so tidyup is run last } } }
private static void KeepTogetherForItem(ItemList actionlist, bool fromLibrary, [NotNull] ActionCopyMoveRename action, ItemList extras, bool showErrors, TVDoc d) { try { DirectoryInfo sfdi = action.From.Directory; string basename = action.From.Name; int l = basename.Length; basename = basename.Substring(0, l - action.From.Extension.Length); string toname = action.To.Name; int l2 = toname.Length; toname = toname.Substring(0, l2 - action.To.Extension.Length); try { FileInfo[] flist = sfdi.GetFiles(basename + ".*"); foreach (FileInfo fi in flist) { //check to see whether the file is one of the types we do/don't want to include //If we are copying from outside the library we use the 'Keep Together' Logic if (!fromLibrary && !TVSettings.Instance.KeepTogetherFilesWithType(fi.Extension)) { continue; } //If we are with in the library we use the 'Other Extensions' if (fromLibrary && !TVSettings.Instance.FileHasUsefulExtension(fi, true)) { continue; } string newName = GetFilename(fi.Name, basename, toname); ActionCopyMoveRename newitem = new ActionCopyMoveRename(action.Operation, fi, FileHelper.FileInFolder(action.To.Directory, newName), action.Episode, false, null, d); // tidy up on main action, not this // check this item isn't already in our to-do list if (ActionListContains(actionlist, newitem)) { continue; } if (!newitem.SameAs(action)) // don't re-add ourself { extras.Add(newitem); } } } catch (UnauthorizedAccessException) { LOGGER.Warn("Could not access: " + action.From.FullName); } catch (DirectoryNotFoundException) { LOGGER.Warn("Could not find: " + action.From.FullName); } } catch (PathTooLongException e) { string t = "Path or filename too long. " + action.From.FullName + ", " + e.Message; LOGGER.Warn(e, "Path or filename too long. " + action.From.FullName); if (showErrors && Environment.UserInteractive) { MessageBox.Show(t, "Path or filename too long", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
public void KeepTogether(ItemList Actionlist) { // for each of the items in rcl, do the same copy/move if for other items with the same // base name, but different extensions ItemList extras = new ItemList(); foreach (Item Action1 in Actionlist) { if (!(Action1 is ActionCopyMoveRename)) continue; ActionCopyMoveRename Action = (ActionCopyMoveRename) (Action1); try { DirectoryInfo sfdi = Action.From.Directory; string basename = Action.From.Name; int l = basename.Length; basename = basename.Substring(0, l - Action.From.Extension.Length); string toname = Action.To.Name; int l2 = toname.Length; toname = toname.Substring(0, l2 - Action.To.Extension.Length); FileInfo[] flist = sfdi.GetFiles(basename + ".*"); foreach (FileInfo fi in flist) { // do case insensitive replace string n = fi.Name; int p = n.ToUpper().IndexOf(basename.ToUpper()); string newName = n.Substring(0, p) + toname + n.Substring(p + basename.Length); if ((this.Settings.RenameTxtToSub) && (newName.EndsWith(".txt"))) newName = newName.Substring(0, newName.Length - 4) + ".sub"; ActionCopyMoveRename newitem = new ActionCopyMoveRename(Action.Operation, fi, Helpers.FileInFolder(Action.To.Directory, newName), Action.Episode); // check this item isn't already in our to-do list bool doNotAdd = false; foreach (Item ai2 in Actionlist) { if (!(ai2 is ActionCopyMoveRename)) continue; if (((ActionCopyMoveRename) (ai2)).SameSource(newitem)) { doNotAdd = true; break; } } if (!doNotAdd) { if (!newitem.SameAs(Action)) // don't re-add ourself extras.Add(newitem); } } } catch (System.IO.PathTooLongException e) { string t = "Path or filename too long. " + Action.From.FullName + ", " + e.Message; MessageBox.Show(t, "Path or filename too long", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } foreach (Item action in extras) { // check we don't already have this in our list and, if we don't add it! bool have = false; foreach (Item action2 in Actionlist) { if (action2.SameAs(action)) { have = true; break; } } if (!have) Actionlist.Add(action); } }
public void KeepTogether(ItemList Actionlist) { // for each of the items in rcl, do the same copy/move if for other items with the same // base name, but different extensions ItemList extras = new ItemList(); foreach (Item Action1 in Actionlist) { if (!(Action1 is ActionCopyMoveRename)) { continue; } ActionCopyMoveRename Action = (ActionCopyMoveRename)(Action1); try { DirectoryInfo sfdi = Action.From.Directory; string basename = Action.From.Name; int l = basename.Length; basename = basename.Substring(0, l - Action.From.Extension.Length); string toname = Action.To.Name; int l2 = toname.Length; toname = toname.Substring(0, l2 - Action.To.Extension.Length); FileInfo[] flist = sfdi.GetFiles(basename + ".*"); foreach (FileInfo fi in flist) { // do case insensitive replace string n = fi.Name; int p = n.ToUpper().IndexOf(basename.ToUpper()); string newName = n.Substring(0, p) + toname + n.Substring(p + basename.Length); if ((TVSettings.Instance.RenameTxtToSub) && (newName.EndsWith(".txt"))) { newName = newName.Substring(0, newName.Length - 4) + ".sub"; } ActionCopyMoveRename newitem = new ActionCopyMoveRename(Action.Operation, fi, FileHelper.FileInFolder(Action.To.Directory, newName), Action.Episode, null); // tidyup on main action, not this // check this item isn't already in our to-do list bool doNotAdd = false; foreach (Item ai2 in Actionlist) { if (!(ai2 is ActionCopyMoveRename)) { continue; } if (((ActionCopyMoveRename)(ai2)).SameSource(newitem)) { doNotAdd = true; break; } } if (!doNotAdd) { if (!newitem.SameAs(Action)) // don't re-add ourself { extras.Add(newitem); } } } } catch (System.IO.PathTooLongException e) { string t = "Path or filename too long. " + Action.From.FullName + ", " + e.Message; logger.Warn(e, "Path or filename too long. " + Action.From.FullName); if ((!this.mDoc.Args.Unattended) && (!this.mDoc.Args.Hide)) { MessageBox.Show(t, "Path or filename too long", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } foreach (Item action in extras) { // check we don't already have this in our list and, if we don't add it! bool have = false; foreach (Item action2 in Actionlist) { if (action2.SameAs(action)) { have = true; break; } if ((action is Action) && (action2 is Action)) { Action a1 = (Action)action; Action a2 = (Action)action2; if (a2.produces == a1.produces) { have = true; break; } } } if (!have) { Actionlist.Insert(0, action); // put before other actions, so tidyup is run last } } }