private HashSet <FileEntry> GetFilesInSelectedFolderCached()
        {
            try
            {
                string folder = GetSelectedNodeFullRealPath();
                if (folder == null || !Directory.Exists(folder))
                {
                    KryptonMessageBox.Show("Can't reach the folder. Not a valid folder selected.", "Invalid folder...", MessageBoxButtons.OK, MessageBoxIcon.Warning, showCtrlCopy: true);
                    cachedFolder            = "";
                    fileEntriesFolderCached = new HashSet <FileEntry>();
                    return(fileEntriesFolderCached);
                }

                if (cachedFolder != folder) //Need updated cache
                {
                    IEnumerable <FileData> fileDatas         = ImageAndMovieFileExtentionsUtility.GetFilesByEnumerableFast(folder, false);
                    HashSet <FileEntry>    fileEntriesFolder = new HashSet <FileEntry>();
                    foreach (FileData fileData in fileDatas)
                    {
                        if (ImageAndMovieFileExtentionsUtility.IsMediaFormat(fileData))
                        {
                            fileEntriesFolder.Add(new FileEntry(fileData.Path, fileData.LastWriteTime));
                        }
                    }
                    fileEntriesFolderCached = fileEntriesFolder;
                    cachedFolder            = folder;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "");
            }

            return(fileEntriesFolderCached);
        }
        private Image LoadMediaCoverArtPosterWithCache(string fullFilePath) //, bool dontReadFilesInCloud, bool isFileInCloud)
        {
            Image image = PosterCacheRead(fullFilePath);

            if (image != null)
            {
                return(image);               //Found in cache
            }
            try
            {
                if (File.Exists(fullFilePath)) //Files can always be moved, deleted or become change outside application (Also may occure when this Rename files)
                {
                    if (ImageAndMovieFileExtentionsUtility.IsVideoFormat(fullFilePath))
                    {
                        var ffMpeg = new NReco.VideoConverter.FFMpegConverter();

                        using (Stream memoryStream = new MemoryStream())
                        {
                            ffMpeg.GetVideoThumbnail(fullFilePath, memoryStream);

                            if (memoryStream.Length > 0)
                            {
                                image = Image.FromStream(memoryStream);
                            }
                            else
                            {
                                image = null;
                            }
                        }
                    }
                    else if (ImageAndMovieFileExtentionsUtility.IsImageFormat(fullFilePath))
                    {
                        bool wasFileLocked = false;
                        image = ImageAndMovieFileExtentionsUtility.LoadImage(fullFilePath, out wasFileLocked);
                        if (image == null && wasFileLocked && File.Exists(fullFilePath))
                        {
                            image = ImageAndMovieFileExtentionsUtility.LoadImage(fullFilePath, out wasFileLocked);
                        }
                        //if (image == null) image = Utility.LoadImageWithoutLock(fullFilePath);
                    }
                }
            } catch (Exception ex)
            {
                Logger.Warn(ex, "LoadMediaCoverArtPoster was not able to create poster of the file " + fullFilePath);
            }
            if (image != null)
            {
                PosterCacheAdd(fullFilePath, image);
            }
            return(image);
        }
        private Image LoadMediaCoverArtThumbnail(string fullFilePath, Size maxSize, FileStatus fileStatus)
        {
            Image image = null;

            try
            {
                if (ImageAndMovieFileExtentionsUtility.IsVideoFormat(fullFilePath))
                {
                    #region Load Video Thumbnail Poster
                    WindowsProperty.WindowsPropertyReader windowsPropertyReader = new WindowsProperty.WindowsPropertyReader();
                    image = windowsPropertyReader.GetThumbnail(fullFilePath);

                    //DO NOT READ FROM FILE - WHEN NOT ALLOWED TO READ CLOUD FILES
                    if (image == null && !fileStatus.IsInCloudOrVirtualOrOffline)
                    {
                        image = LoadMediaCoverArtPosterWithCache(fullFilePath);
                    }
                    #endregion
                }
                else if (ImageAndMovieFileExtentionsUtility.IsImageFormat(fullFilePath))
                {
                    #region Load Picture Thumbnail Poster
                    WindowsProperty.WindowsPropertyReader windowsPropertyReader = new WindowsProperty.WindowsPropertyReader();
                    image = windowsPropertyReader.GetThumbnail(fullFilePath);

                    //DO NOT READ FROM FILE - WHEN NOT ALLOWED TO READ CLOUD FILES
                    if (image == null && !fileStatus.IsInCloudOrVirtualOrOffline)
                    {
                        image = ImageAndMovieFileExtentionsUtility.ThumbnailFromFile(fullFilePath); //Fast version - onlt load thumbnail from file
                        if (image == null)
                        {
                            image = LoadMediaCoverArtPosterWithCache(fullFilePath);                 //Slow loading, load full image
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "LoadMediaCoverArtThumbnail");
            }

            if (image != null)
            {
                image = Utility.ConvertImageToThumbnail(image, maxSize, Color.White, false);
            }
            return(image);
        }
        private IEnumerable <FileData> GetFilesInSelectedFolder(string folder, bool recursive = false)
        {
            IEnumerable <FileData> fileDatas = null;

            try
            {
                if (folder == null || !Directory.Exists(folder))
                {
                    KryptonMessageBox.Show("Can't reach the folder. Not a valid folder selected.", "Invalid folder...", MessageBoxButtons.OK, MessageBoxIcon.Warning, showCtrlCopy: true);
                    return(fileDatas);
                }
                fileDatas = ImageAndMovieFileExtentionsUtility.GetFilesByEnumerableFast(folder, recursive);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "");
            }
            return(fileDatas);
        }
        private void CopyFolder_UpdateTreeViewFolderBrowser(TreeViewFolderBrowser folderTreeView, string sourceDirectory, string tagretDirectory, TreeNode targetNode)
        {
            IEnumerable <FileData> allSourceFileDatas = ImageAndMovieFileExtentionsUtility.GetFilesByEnumerableFast(sourceDirectory, true);

            //----- Create directories and sub-directories
            Directory.CreateDirectory(tagretDirectory);
            foreach (string dirPath in Directory.GetDirectories(sourceDirectory, "*", SearchOption.AllDirectories))
            {
                try
                {
                    Directory.CreateDirectory(dirPath.Replace(sourceDirectory, tagretDirectory));
                }
                catch (SystemException ex)
                {
                    Logger.Error(ex, "Error when create directory when copy all files from folder");
                    AddError(
                        dirPath, AddErrorFileSystemRegion, AddErrorFileSystemCreateFolder, dirPath.Replace(sourceDirectory, tagretDirectory), dirPath.Replace(sourceDirectory, tagretDirectory),
                        "Issue: Failed create directory\r\n" +
                        "Directory: " + dirPath + "\r\n" +
                        "Error message: " + ex.Message);
                }
            }
            using (new WaitCursor())
            {
                //Copy all the files & Replaces any files with the same name
                foreach (FileData sourceFileData in allSourceFileDatas)
                {
                    string sourceFilename     = Path.GetFileName(sourceFileData.Path);
                    string targetFullFilename = Path.Combine(tagretDirectory, sourceFilename);
                    try
                    {
                        Logger.Trace("Copy from:" + sourceFileData.Path + " to: " + targetFullFilename);
                        File.Copy(sourceFileData.Path, sourceFileData.Path.Replace(sourceDirectory, tagretDirectory), false);

                        if (targetNode != null)
                        {
                            TreeViewFolderBrowserHandler.RefreshTreeNode(folderTreeView, targetNode);
                        }

                        databaseAndCacheMetadataExiftool.Copy(
                            Path.GetDirectoryName(sourceFileData.Path), Path.GetFileName(sourceFileData.Path),
                            Path.GetDirectoryName(sourceFileData.Path), Path.GetFileName(sourceFileData.Path));
                    }
                    catch (SystemException ex)
                    {
                        DateTime dateTimeLastWriteTime = DateTime.Now;
                        try
                        {
                            dateTimeLastWriteTime = FileHandler.GetLastWriteTime(sourceFileData.Path);
                        }
                        catch { }

                        FileStatus fileStatusSource = FileHandler.GetFileStatus(
                            sourceFileData.Path, checkLockedStatus: true, hasErrorOccured: true, errorMessage: ex.Message);
                        ImageListView_UpdateItemFileStatusInvoke(sourceFileData.Path, fileStatusSource);

                        FileStatus fileStatusTarget = FileHandler.GetFileStatus(
                            targetFullFilename, checkLockedStatus: true);
                        //ImageListView_UpdateItemFileStatusInvoke(targetFullFilename, fileStatusTarget);

                        AddError(
                            Path.GetDirectoryName(sourceFileData.Path), Path.GetFileName(sourceFileData.Path), dateTimeLastWriteTime,
                            AddErrorFileSystemRegion, AddErrorFileSystemCopy, sourceFileData.Path, targetFullFilename,
                            "Issue: Failed copying file.\r\n" +
                            "From File Name:  " + sourceFileData.Path + "\r\n" +
                            "From File Staus: " + fileStatusSource.ToString() + "\r\n" +
                            "To   File Name:  " + targetFullFilename + "\r\n" +
                            "To   File Staus: " + fileStatusTarget.ToString() + "\r\n" +
                            "Error message: " + ex.Message);
                    }
                }
            }

            //------ Update node tree -----
            GlobalData.DoNotTrigger_TreeViewFolder_BeforeAndAfterSelect = true;
            TreeViewFolderBrowserHandler.RefreshTreeNode(folderTreeView, targetNode);
            GlobalData.DoNotTrigger_TreeViewFolder_BeforeAndAfterSelect = false;
        }
Ejemplo n.º 6
0
        public static List <FileEntry> WriteXtraAtom(
            List <Metadata> metadataListToWrite, List <Metadata> metadataListOriginal, List <string> allowedFileNameDateTimeFormats,
            string writeXtraAtomAlbumVariable, bool writeXtraAtomAlbumVideo,
            string writeXtraAtomCategoriesVariable, bool writeXtraAtomCategoriesVideo,
            string writeXtraAtomCommentVariable, bool writeXtraAtomCommentPicture, bool writeXtraAtomCommentVideo,
            string writeXtraAtomKeywordsVariable, bool writeXtraAtomKeywordsPicture, bool writeXtraAtomKeywordsVideo,
            bool writeXtraAtomRatingPicture, bool writeXtraAtomRatingVideo,
            string writeXtraAtomSubjectVariable, bool writeXtraAtomSubjectPicture, bool writeXtraAtomSubjectVideo,
            string writeXtraAtomSubtitleVariable, bool writeXtraAtomSubtitleVideo,
            string writeXtraAtomArtistVariable, bool writeXtraAtomArtistVideo,
            out Dictionary <string, string> writeXtraAtomErrorMessageForFile)

        {
            Logger.Debug("WriteXtraAtom - started");
            writeXtraAtomErrorMessageForFile = new Dictionary <string, string>(); //Clear out values
            List <FileEntry> filesUpdatedByXtraAtom = new List <FileEntry>();

            if (metadataListToWrite.Count <= 0)
            {
                return(filesUpdatedByXtraAtom);
            }
            if (metadataListToWrite.Count != metadataListOriginal.Count)
            {
                return(filesUpdatedByXtraAtom);
            }
            int writeCount = metadataListToWrite.Count;

            for (int updatedRecord = 0; updatedRecord < writeCount; updatedRecord++)
            {
                Metadata metadataToWrite  = metadataListToWrite[updatedRecord];
                Metadata metadataOriginal = metadataListOriginal[updatedRecord];

                Logger.Debug("WriteXtraAtom - " + metadataToWrite.FileFullPath);
                if (metadataToWrite == metadataOriginal)
                {
                    continue;                                      //No changes found in data, No data to write
                }
                #region Is Video or Image format?
                bool isVideoFormat = false;
                bool isImageFormat = false;

                if (ImageAndMovieFileExtentionsUtility.IsImageFormat(metadataToWrite.FileFullPath))
                {
                    isVideoFormat = false;
                    isImageFormat = true;
                }
                else if (ImageAndMovieFileExtentionsUtility.IsVideoFormat(metadataToWrite.FileFullPath))
                {
                    isVideoFormat = true;
                    isImageFormat = false;
                }
                #endregion

                #region Replace Variable
                string writeXtraAtomAlbumReult       = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomAlbumVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomCategoriesResult = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomCategoriesVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomCommentResult    = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomCommentVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomKeywordsResult   = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomKeywordsVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomSubjectResult    = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomSubjectVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomSubtitleResult   = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomSubtitleVariable, allowedFileNameDateTimeFormats);
                string writeXtraAtomArtistResult     = metadataToWrite.ReplaceVariablesWrittenByUser(writeXtraAtomArtistVariable, allowedFileNameDateTimeFormats);
                #endregion

                #region Write Xtra Atrom using Property Writer
                if (writeXtraAtomKeywordsPicture || writeXtraAtomKeywordsVideo || writeXtraAtomCategoriesVideo || writeXtraAtomAlbumVideo || writeXtraAtomSubtitleVideo ||
                    writeXtraAtomArtistVideo || writeXtraAtomSubjectVideo || writeXtraAtomCommentVideo || writeXtraAtomRatingVideo ||
                    writeXtraAtomSubjectPicture || writeXtraAtomCommentPicture || writeXtraAtomRatingPicture)
                {
                    try
                    {
                        Logger.Debug("WriteXtraAtom - Start write XtraAtom: " + metadataToWrite.FileFullPath);
                        using (WindowsPropertyWriter windowsPropertyWriter = new WindowsPropertyWriter(metadataToWrite.FileFullPath))
                        {
                            if (isVideoFormat)
                            {
                                if (writeXtraAtomCategoriesVideo)
                                {
                                    windowsPropertyWriter.WriteCategories(string.IsNullOrEmpty(writeXtraAtomCategoriesResult) ? null : writeXtraAtomCategoriesResult);
                                }
                                if (writeXtraAtomAlbumVideo)
                                {
                                    windowsPropertyWriter.WriteAlbum(string.IsNullOrEmpty(writeXtraAtomAlbumReult) ? null : writeXtraAtomAlbumReult);
                                }
                                if (writeXtraAtomSubtitleVideo)
                                {
                                    windowsPropertyWriter.WriteSubtitle_Description(string.IsNullOrEmpty(writeXtraAtomSubtitleResult) ? null : writeXtraAtomSubtitleResult);
                                }
                                if (writeXtraAtomArtistVideo)
                                {
                                    windowsPropertyWriter.WriteArtist_Author(string.IsNullOrEmpty(writeXtraAtomArtistResult) ? null : writeXtraAtomArtistResult);
                                }
                                if (writeXtraAtomSubjectVideo)
                                {
                                    windowsPropertyWriter.WriteSubject_Description(string.IsNullOrEmpty(writeXtraAtomSubjectResult) ? null : writeXtraAtomSubjectResult);
                                }
                                if (writeXtraAtomCommentVideo)
                                {
                                    windowsPropertyWriter.WriteComment(string.IsNullOrEmpty(writeXtraAtomCommentResult) ? null : writeXtraAtomCommentResult);
                                }
                                if (writeXtraAtomRatingVideo)
                                {
                                    windowsPropertyWriter.WriteRating((metadataToWrite.PersonalRatingPercent == null ? (int)0 : (int)metadataToWrite.PersonalRatingPercent));
                                }
                                if (writeXtraAtomKeywordsVideo)
                                {
                                    windowsPropertyWriter.WriteKeywords(string.IsNullOrEmpty(writeXtraAtomKeywordsResult) ? null : writeXtraAtomKeywordsResult);
                                }
                            }
                            else if (isImageFormat)
                            {
                                if (writeXtraAtomSubjectPicture)
                                {
                                    windowsPropertyWriter.WriteSubject_Description(string.IsNullOrEmpty(writeXtraAtomSubjectResult) ? null : writeXtraAtomSubjectResult);
                                }
                                if (writeXtraAtomCommentPicture)
                                {
                                    windowsPropertyWriter.WriteComment(string.IsNullOrEmpty(writeXtraAtomCommentResult) ? null : writeXtraAtomCommentResult);
                                }
                                if (writeXtraAtomRatingPicture)
                                {
                                    windowsPropertyWriter.WriteRating((metadataToWrite.PersonalRatingPercent == null ? (int)0 : (int)metadataToWrite.PersonalRatingPercent));
                                }
                                if (writeXtraAtomKeywordsPicture)
                                {
                                    windowsPropertyWriter.WriteKeywords(string.IsNullOrEmpty(writeXtraAtomKeywordsResult) ? null : writeXtraAtomKeywordsResult);
                                }
                            }

                            windowsPropertyWriter.Close();

                            filesUpdatedByXtraAtom.Add(new FileEntry(metadataToWrite.FileFullPath, FileHandler.GetLastWriteTime(metadataToWrite.FileFullPath)));
                        }
                    }
                    catch (Exception ex)
                    {
                        string error = "Failed to write Microsoft's own Xtra Atom Propery on file.: " + metadataToWrite.FileFullPath;
                        Logger.Error(ex, error);
                        writeXtraAtomErrorMessageForFile.Add(metadataToWrite.FileFullPath, error);
                    }
                }
                else
                {
                    Logger.Debug("WriteXtraAtom - nothing to updated: " + metadataToWrite.FileFullPath);
                }
                #endregion
            }
            return(filesUpdatedByXtraAtom);
        }