diff --git a/PhotoSift/AppSettings.cs b/PhotoSift/AppSettings.cs index acd1f38..e23aa9d 100644 --- a/PhotoSift/AppSettings.cs +++ b/PhotoSift/AppSettings.cs @@ -394,6 +394,8 @@ public Color CustomMenuColorHightlight public FeatureSwitch FileMIMEChecker { get; set; } [Category("File Type"), DisplayName("Allowed MIME"), DescriptionAttribute("File MIME types allowed to be added to the pool. Work only while the Check MIME option be turn on. Semicolon separated. Spaces on edge are ignored. Default: 'image/;video/;audio/'.")] public string allowsMIME { get; set; } + [Category("File Type"), DisplayName("Expand folder shortcuts"), DescriptionAttribute("When adding files, the program will only parse one folder shortcut (if it is the first) to avoid flooding. If enabled, it attempts to recursively resolve all folder shortcuts.")] + public bool expandFolderLnks { get; set; } // Misc settings [Category("Misc"), DisplayName("Copy action"), DescriptionAttribute("Sets the action type when you press Ctrl+C or click the \"Copy to clipboard\" menu in this software.")] @@ -518,7 +520,8 @@ public AppSettings() defaultSettings.Add("allowsVidExts", Util.Def_allowsVideoExts); defaultSettings.Add("FileMIMEChecker", FeatureSwitch.Disabled); defaultSettings.Add("allowsMIME", "image/);video/);audio/"); - + defaultSettings.Add("expandFolderLnks", false); + // Misc defaultSettings.Add("SaveRelativePaths", true); defaultSettings.Add("CopyActionType", CopytoClipboardOptions.Bitmap); diff --git a/PhotoSift/PhotoSift.csproj b/PhotoSift/PhotoSift.csproj index ca09614..6f482d5 100644 --- a/PhotoSift/PhotoSift.csproj +++ b/PhotoSift/PhotoSift.csproj @@ -229,6 +229,15 @@ aximp False + + {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} + 1 + 0 + 0 + tlbimp + False + False + {50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1 diff --git a/PhotoSift/frmMain.cs b/PhotoSift/frmMain.cs index 44883d8..2beee45 100644 --- a/PhotoSift/frmMain.cs +++ b/PhotoSift/frmMain.cs @@ -294,37 +294,57 @@ private void frmMain_DragDrop( object sender, DragEventArgs e ) } // Add file to the image pool - private void _addFile(string file, ref List newPics, List allowsExts) + private void _addFile(string filePath, ref List newPics, List allowsExts) { - if (pics.Exists(i => i == file)) return; + if (pics.Exists(i => i == filePath)) return; + string ext = Path.GetExtension(filePath); + if (ext.ToLower() == ".lnk") + { + string targetPath = GetLnkFileTarget(filePath); + if (System.IO.Directory.Exists(targetPath)) + { + // refuse to expand multiple lnks at once + if (settings.expandFolderLnks || newPics.Count < 1) + { + var files = System.IO.Directory.EnumerateFiles(targetPath, "*", System.IO.SearchOption.AllDirectories).ToArray(); + foreach (var file in files) + { + _addFiles_AddingByMIME(file, ref newPics, allowsExts); + } + } + } + else + { + filePath = targetPath; + if (pics.Exists(i => i == filePath)) return; + _addFiles_AddingByMIME(filePath, ref newPics, allowsExts); + } + return; + } + _addFiles_AddingByMIME(filePath, ref newPics, allowsExts); + } + private void _addFiles_AddingByMIME(string filePath, ref List newPics, List allowsExts) { + string ext = Path.GetExtension(filePath); if (settings.FileMIMEChecker == FeatureSwitch.Enabled && allowsMIME.Length > 0) { - string mime = GetFileMIME(file); + string mime = MimeTypes.MimeTypeMap.GetMimeType(ext); int match = allowsMIME.Where(rule => mime.Contains(rule)).ToArray().Length; if (match > 0) - newPics.Add(file); + newPics.Add(filePath); } - else if (allowsExts.Contains(Path.GetExtension(file), StringComparer.OrdinalIgnoreCase)) - newPics.Add(file); + else if (allowsExts.Contains(ext, StringComparer.OrdinalIgnoreCase)) + newPics.Add(filePath); } - private int AddFiles( string[] items ) + private List _addFiles_validate(string[] items) { - if( items.Length == 0 ) return 0; - - HaltAutoAdvance(); - lblHeader.Text = "Loading..."; - updateTitleStr("Loading..."); - Util.CenterControl( lblHeader, picLogo.Image.Height / 2 + 20 ); - this.Refresh(); - // validate files to add List newPics = new List(); List allowsExts = settings.allowsPicExts.Union(settings.allowsVidExts).ToList(); - foreach ( string item in items ) + foreach (string item in items) { - if( System.IO.Directory.Exists( item ) ) // is Directory + if (System.IO.Directory.Exists(item)) // is Directory { try { @@ -336,16 +356,33 @@ private int AddFiles( string[] items ) catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // lising dir error, e.g. "C:\". - return -1; + return null; } } - else if( System.IO.File.Exists( item ) ) // is File + else if (System.IO.File.Exists(item)) // is File { _addFile(item, ref newPics, allowsExts); } - } - if( newPics.Count == 0 ) + return newPics; + } + private int AddFiles( string[] items ) + { + if( items.Length == 0 ) return 0; + + HaltAutoAdvance(); + lblHeader.Text = "Loading..."; + updateTitleStr("Loading..."); + Util.CenterControl( lblHeader, picLogo.Image.Height / 2 + 20 ); + this.Refresh(); + + var newPics = _addFiles_validate(items); + + if (newPics == null) + { + return 0; + } + else if ( newPics.Count == 0 ) { ShowPicByOffset( 0 ); return 0; @@ -1598,11 +1635,18 @@ private void timerMetaInfoUpdate_Tick(object sender, EventArgs e) updateInfoLabel(str); } - public static string GetFileMIME(string filePath) - { - var ext = Path.GetExtension(filePath); - return MimeTypes.MimeTypeMap.GetMimeType(ext); + public static string GetLnkFileTarget(string filePath) + { + try + { + IWshRuntimeLibrary.IWshShell wsh = new IWshRuntimeLibrary.WshShellClass(); + IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(filePath); + return link.TargetPath; + } + catch (Exception) + { + return ""; + } } } - }