// TODO: function is still tooooooo large private void SetSeriesPath() { if (Season == -1 || Showname == "") { Destination = ""; return; } //string basepath = Helper.ReadProperty(Config.LastDirectory); string DestinationPath = Helper.ReadProperty(Config.DestinationDirectory); if (!Directory.Exists(DestinationPath)) { DestinationPath = FilePath.Path; } bool DifferentDestinationPath = FilePath.Path != DestinationPath; //for placing files in directory structure, figure out if selected directory is show name, otherwise create one bool isNetwork = FilePath.Path.StartsWith("" + Path.DirectorySeparatorChar + Path.DirectorySeparatorChar); string[] dirs = this.source.Folders; bool InSeriesDir = false; bool InSeasonDir = false; //any (other) season dir bool InASeasonDir = false; bool UseSeasonSubDirs = Helper.ReadBool(Config.UseSeasonSubDir); //figure out if we are in a season dir string[] seasondirs = Helper.ReadProperties(Config.Extract); string aSeasondir = ""; int showdirlevel = 0; //figure out if we are in an extraction dir, if we are, we need to go upwards one level if (dirs.Length > 0 && Filepath.IsExtractionDirectory(dirs[dirs.Length - 1])) { DestinationPath = Filepath.goUpwards(DestinationPath, 1); List <string> blah = new List <string>(dirs); blah.RemoveAt(dirs.Length - 1); dirs = blah.ToArray(); } //check if we are in a season and/or series directory //loop backwards so first season entry is used if nothing is recognized and folder has to be created for (int i = seasondirs.Length - 1; i >= 0; i--) { aSeasondir = RegexConverter.replaceSeriesname(seasondirs[i], nameOfSeries); bool InSomething = false; if (dirs.Length > 1) { Match m = Regex.Match(dirs[dirs.Length - 1], aSeasondir); int parsedSeason; Int32.TryParse(m.Groups["Season"].Value, out parsedSeason); if (m.Success) { if (parsedSeason == season) { InSeasonDir = true; } InASeasonDir = true; InSomething = true; } } //remove dots to avoid problems with series like "N.C.I.S." or "Dr. House" /*if (dirs.Length > 0 && dirs[dirs.Length - 1].Replace(".","").StartsWith(nameOfSeries.Replace(".",""))){ * InSeriesDir=true; * }*/ if (dirs.Length > 0 && Helper.InitialsMatch(dirs[dirs.Length - 1], nameOfSeries)) { InSeriesDir = true; } /*else if (dirs.Length > 1 && dirs[dirs.Length - 2].Replace(".", "").StartsWith(nameOfSeries.Replace(".", "")))*/ else if (dirs.Length > 1 && Helper.InitialsMatch(dirs[dirs.Length - 2], nameOfSeries)) { InSeriesDir = true; showdirlevel = 1; } if (InSomething) { break; } } getCreateDirectory(); if (createDirectoryStructure != DirectoryStructure.CreateDirectoryStructure || !isSeasonValid()) { Destination = ""; return; } //if files aren't meant to be moved somewhere else if (!DifferentDestinationPath) { //somewhere else, create new series dir if (!InSeriesDir && !InSeasonDir && !InASeasonDir) { DestinationPath = addSeriesDir(DestinationPath); DestinationPath = addSeasonsDirIfDesired(DestinationPath); } //in series dir, create seasons dir else if (InSeriesDir && !InASeasonDir) { DestinationPath = addSeasonsDirIfDesired(DestinationPath); } //wrong season dir, add real seasons dir else if (InSeriesDir && InASeasonDir && !InSeasonDir) { DestinationPath = Filepath.goUpwards(DestinationPath, 1); if (showdirlevel == 0) { DestinationPath = addSeriesDir(DestinationPath); } DestinationPath = addSeasonsDirIfDesired(DestinationPath); } //wrong show dir, go back two levels and add proper dir structure else if (!InSeriesDir && InASeasonDir) { DestinationPath = addSeriesDir(Filepath.goUpwards(DestinationPath, 2)); DestinationPath = addSeasonsDirIfDesired(DestinationPath); } } //if they should be moved else { DestinationPath = addSeriesDir(DestinationPath); DestinationPath = addSeasonsDirIfDesired(DestinationPath); } if (DestinationPath != FilePath.Path) { Destination = DestinationPath; } else { Destination = ""; } }
private void fallbackFolderNames() { if (folders.Length == 0) { return; } for (int i = 1; i < folders.Length - 1; i++) { if (!Regex.Match(folders[folders.Length - i], pathBlacklist, RegexOptions.IgnoreCase).Success) { if (name == null || (Helper.InitialsMatch(folders[folders.Length - 1], name) && !Filepath.IsExtractionDirectory(folders[folders.Length - 1]))) { name = folders[folders.Length - i]; break; } } } //Logger.Instance.LogMessage("SNE: fallbackFolderNames: " + name, LogLevel.DEBUG); }