internal static ArrayList TestDirectoryAccessGetFileList
            (string directoryStr, int totalFiles,
            int currentFile, out DirectoryInfo directory)
        {
            if (TestDirectoryAccess
                    (directoryStr, out directory))
            {
                return(null);
            }


            Application.DoEvents();



            var filesInDirectory
                = ImportingEngineHelpers
                  .GetDirectoryFileList
                      (directoryStr, totalFiles,
                      currentFile, directory);



            Application.DoEvents();

            return(filesInDirectory);
        }
        internal static bool TestDirectoryAccess
            (string directoryStr,
            out DirectoryInfo directory)
        {
            Application.DoEvents();

            directory = ImportingEngineHelpers
                        .TestDirectoryAccess(directoryStr);

            return(directory == null);
        }
예제 #3
0
        internal static bool ScanConstructedArrayAndImportMediaFiles
            (IMLSection section,
            ref ArrayList extensionsToIgnore,
            string[] filmLocations,
            string[] videoExtensions,
            string[] audioExtensions,
            IEnumerable <string> combinedSceneTags,
            ICollection <FileInfo> filesToImport,
            string pluginPath,
            IEnumerable <string> videoExtensionsCommon)


        {
            if (!Settings.UpdateMediaSectionOnEachImportedItem)
            {
                ImportingEngineHelpers
                .BeginUpdatingSections
                    (section);
            }



            if (!ImportFilesInArray
                    (section, ref extensionsToIgnore,
                    filmLocations, videoExtensions,
                    audioExtensions, combinedSceneTags,
                    filesToImport, pluginPath,
                    videoExtensionsCommon)
                )
            {
                return(false);
            }



            if (!Settings.UpdateMediaSectionOnEachImportedItem)
            {
                ImportingEngineHelpers.EndUpdatingSections
                    (section);
            }



            return(true);
        }
        internal static bool ImportMediaFile
            (FileInfo file,
            IMLSection section,
            ref ArrayList extensionsToIgnore,
            ref string[] filmLocations,
            string[] videoExtensions,
            string[] audioExtensions,
            int totalFiles,
            ref int currentFile,
            IEnumerable <string> combinedSceneTags,
            string pluginPath,
            IEnumerable <string> videoExtensionsCommon)
        {
            try
            {
                Application.DoEvents();

                #region Init

                currentFile++;

                if (file == null)
                {
                    return(true);
                }

                #region Set Progress status
                MainImportingEngine.CurrentProgress = ImportingEngineHelpers.ComputeProgress(currentFile, totalFiles);
                MainImportingEngine.GeneralStatus   = "Performing media importing...";
                MainImportingEngine.SpecialStatus   = String.Format("Checking file {0}...", file.Name);
                #endregion


                if (!File.Exists(file.FullName))
                {
                    return(true);
                }



                #region file variables

                string parentName = string.Empty;
                string fileName;
                string fileExtension;
                bool   isVideo;
                bool   isAudio;


                if (SingleMediaFileImporterHelpers
                    .RemoveExtensionFromFilename
                        (file, out fileName, out fileExtension))
                {
                    return(true);
                }



                #region Retrieve Parent Directory
                DirectoryInfo parent = file.Directory;

                if (parent != null && !String.IsNullOrEmpty(parent.Name))
                {
                    parentName = parent.Name;
                }
                #endregion

                #endregion

                #endregion

                Application.DoEvents();



                if (SingleMediaFileImporterHelpers.ImportAdditionalMediaTypes
                        (file, section,
                        parent, parentName))
                {
                    return(true);
                }

                Application.DoEvents();

                if (MediaTypeDetector.FileTypeBelongsToIgnoredExtensions(file, extensionsToIgnore))
                {
                    return(true);
                }

                Application.DoEvents();


                if (ExistingMediaItemSeachEngine.SkipAlreadyImportedFiles
                        (file, filmLocations, section))
                {
                    return(true);
                }


                Application.DoEvents();


                MediaTypeDetector.FileTypeIsMediaExtension(videoExtensions,
                                                           audioExtensions, fileExtension, out isVideo, out isAudio,
                                                           fileName, videoExtensionsCommon);


                Application.DoEvents();


                if (!MediaSectionPopulator
                    .AnalyzeFileAndAddToMediaSection
                        (file, section, extensionsToIgnore,
                        videoExtensions, combinedSceneTags,
                        fileExtension, isAudio, isVideo,
                        parent, parentName, fileName))
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                if (file != null)
                {
                    Debugger.LogMessageToFile("An error occured while attempting to import a media file " +
                                              // + file.Name +
                                              "." + Environment.NewLine + "The error was: " + e);
                }
            }


            return(true);
        }
        internal static int ExamineDirectoryConstructFilesArray
            (string strDir, out FileInfo[] allfiles,
            int dirsTotal, ref int i)
        {
            var directoriesArray = new ArrayList();
            var filesList        = new ArrayList();


            string[] allDirs
                = Directory.GetDirectories
                      (strDir);


            #region ...for each directory in Root...
            foreach (string strDirName in allDirs)
            {
                try
                {
                    MainImportingEngine.CurrentProgress
                        = ImportingEngineHelpers
                          .ComputeProgress(i, dirsTotal);


                    MainImportingEngine.ThisProgress
                    .Progress(MainImportingEngine
                              .CurrentProgress, "[files found: "
                              + filesList.Count + " ]" +
                              " Examining directory "
                              + strDirName + "...");



                    var dirI = new DirectoryInfo
                                   (strDirName);



                    try
                    {
                        filesList.AddRange
                            (dirI.GetFiles
                                ("*.*", SearchOption.AllDirectories));

                        directoriesArray.AddRange
                            (dirI.GetDirectories
                                ("*.*", SearchOption
                                .AllDirectories));
                    }
                    catch
                    {
                        continue;
                    }


                    i++;

                    ExamineDirectoryConstructFilesArray
                        (strDirName, out allfiles,
                        dirsTotal, ref i);
                }
                catch (Exception e)
                {
                    Debugger.LogMessageToFile
                        ("An unexpected error occured" +
                        " in the media directories examination process." +
                        " The error was: " + e);
                }
            }

            #endregion


            allfiles = (FileInfo[])
                       filesList.ToArray
                           (typeof(FileInfo));


            return(allfiles.Length);
        }
예제 #6
0
        private static bool ImportFilesInArray
            (IMLSection section,
            ref ArrayList extensionsToIgnore,
            string[] filmLocations,
            string[] videoExtensions,
            string[] audioExtensions,
            IEnumerable <string> combinedSceneTags,
            ICollection <FileInfo> filesToImport,
            string pluginPath,
            IEnumerable <string> videoExtensionsCommon)
        {
            if (filesToImport.Count <= 0)
            {
                return(true);
            }

            int currentFile = 0;



            foreach (FileInfo file in filesToImport)
            {
                Application.DoEvents();


                if (SingleMediaFileImporter
                    .ImportMediaFile
                        (file,
                        section,
                        ref extensionsToIgnore,
                        ref filmLocations,
                        videoExtensions,
                        audioExtensions,
                        filesToImport.Count,
                        ref currentFile,
                        combinedSceneTags,
                        pluginPath,
                        videoExtensionsCommon))
                {
                    continue;
                }



                ImportingEngineHelpers
                .EndUpdatingSections
                    (section);



                MainImportingEngine.
                CurrentProgress = 100;



                Helpers.UpdateProgress
                    ("All operations were cancelled." +
                    " Completed jobs were save to library.", "");



                MainImportingEngine
                .ThisProgress = null;



                return(false);
            }


            return(true);
        }
        internal static bool UpdateFilmItem
            (int itemID,
            IMLSection moviesSection,
            string pluginpath,
            ref int currentItem,
            int totalItems,
            IBaseSystem iBaseSystem,
            IEnumerable <string> combinedSceneTags)
        {
            MainImportingEngine
            .CurrentProgress =
                ImportingEngineHelpers
                .ComputeProgress
                    (currentItem, totalItems);



            #region item variables


            Helpers.UpdateProgress("", "Fetching library item...");
            Debugger.LogMessageToFile("Fetching library item...");


            var item = moviesSection
                       .FindItemByID(itemID);

            if (item == null)
            {
                return(true);
            }


            DirectoryInfo parent;


            string moviehash,
                   imdbid,
                   tmdbID,
                   year,
                   itemTitle,
                   sortTitle,
                   location;



            SingleMovieItemUpdaterHelpers.InitializeItemKeys
                (itemID, item, out moviehash, out imdbid,
                out tmdbID, out year, out itemTitle,
                out sortTitle, out location);



            #endregion



            Helpers.UpdateProgress("", "Creating filesystem instance...");

            Debugger.LogMessageToFile(String.Format
                                          ("Creating filesystem instances for media file {0}...",
                                          location));


            try
            {
                var fi = new FileInfo
                             (location);

                parent = fi.Directory;
            }
            catch (Exception e)
            {
                Debugger.LogMessageToFile(String.Format
                                              ("Unable to create filesystem instances" +
                                              " for this media file." +
                                              "An error occured: {0}", e));

                return(true);
            }



            if (IdentifyFilmAndDownloadMetadata
                    (combinedSceneTags,
                    item, parent))
            {
                return(true);
            }


            if (Helpers.UserCancels
                    (MainImportingEngine.SpecialStatus))
            {
                return(false);
            }



            SetFilmItemProcessingFlags
            .SetUpdateFlag(item);


            item.SaveTags();
            currentItem++;
            return(true);
        }