Browse Source

QVCopier: Use native api lookup filesystem

HOME 8 months ago
parent
commit
d48a642afa

+ 4 - 0
QVCopier/QVCopier.csproj

@@ -76,6 +76,10 @@
       <SubType>Component</SubType>
     </Compile>
     <Compile Include="Utility\ExplorerAccessor.cs" />
+    <Compile Include="Utility\FindFile\FindFileApi.cs" />
+    <Compile Include="Utility\FindFile\WIN32_FIND_DATA.cs" />
+    <Compile Include="Utility\FindFile\FINDEX_INFO_LEVELS.cs" />
+    <Compile Include="Utility\FindFile\FINDEX_SEARCH_OPS.cs" />
     <Compile Include="Utility\Logger.cs" />
     <Compile Include="Utility\RunningChecksum.cs" />
     <Compile Include="Utility\TextFormatter.cs" />

+ 14 - 1
QVCopier/QvcMainForm.MainLV.cs

@@ -7,13 +7,26 @@ namespace QVCopier
 {
     public partial class QvcMainForm : Form
     {
+        //TODO: create workItem
+        //TODO: list and filters
+
         private void MainListView_DragEnter(object sender, DragEventArgs e)
         {
-
+            e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop)
+                ? DragDropEffects.Copy
+                : DragDropEffects.None;
         }
 
         private void MainListView_DragDrop(object sender, DragEventArgs e)
         {
+            var items = (string[])e.Data.GetData(DataFormats.FileDrop);
+            //TODO: looking up filesystem
+
+            foreach (var item in items)
+            {
+                
+            }
+
 
         }
     }

+ 0 - 1
QVCopier/QvcMainForm.cs

@@ -78,7 +78,6 @@ namespace QVCopier
                 }
             });
             cm.Show(ChooseDestButton, new Point(0, ChooseDestButton.Height));
-
         }
     }
 }

+ 8 - 0
QVCopier/Utility/FindFile/FINDEX_INFO_LEVELS.cs

@@ -0,0 +1,8 @@
+namespace QVCopier.Utility.FindFile
+{
+    public enum FINDEX_INFO_LEVELS
+    {
+        FindExInfoStandard = 0,
+        FindExInfoBasic = 1
+    }
+}

+ 9 - 0
QVCopier/Utility/FindFile/FINDEX_SEARCH_OPS.cs

@@ -0,0 +1,9 @@
+namespace QVCopier.Utility.FindFile
+{
+    public enum FINDEX_SEARCH_OPS
+    {
+        FindExSearchNameMatch = 0,
+        FindExSearchLimitToDirectories = 1,
+        FindExSearchLimitToDevices = 2
+    }
+}

+ 84 - 0
QVCopier/Utility/FindFile/FindFileApi.cs

@@ -0,0 +1,84 @@
+using System;
+using System.ComponentModel;
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace QVCopier.Utility.FindFile
+{
+    internal static class FindFileApi
+    {
+        [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
+        private static extern IntPtr FindFirstFileEx(
+            string lpFileName,
+            FINDEX_INFO_LEVELS fInfoLevelId,
+            out WIN32_FIND_DATA lpFindFileData,
+            FINDEX_SEARCH_OPS fSearchOp,
+            IntPtr lpSearchFilter,
+            int dwAdditionalFlags);
+
+        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
+        private static extern bool FindNextFile(IntPtr hFindFile, out WIN32_FIND_DATA lpFindFileData);
+
+        [DllImport("kernel32.dll")]
+        private static extern bool FindClose(IntPtr hFindFile);
+
+        // dwAdditionalFlags:
+        private const int FIND_FIRST_EX_CASE_SENSITIVE = 1;
+
+        private const int FIND_FIRST_EX_LARGE_FETCH = 2;
+
+        public static void Find(string fileNameOrPath)
+        {
+            FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoStandard;
+            int additionalFlags = 0;
+            if (Environment.OSVersion.Version.Major >= 6)
+            {
+                findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoBasic;
+                additionalFlags = FIND_FIRST_EX_LARGE_FETCH;
+            }
+
+            var hFile = FindFirstFileEx(
+                fileNameOrPath,
+                findInfoLevel,
+                out var findData,
+                FINDEX_SEARCH_OPS.FindExSearchNameMatch,
+                IntPtr.Zero,
+                additionalFlags);
+
+            int error = Marshal.GetLastWin32Error();
+
+            if (error == 2)
+            {
+                hFile = FindFirstFileEx(
+                    Path.Combine(fileNameOrPath, "*.*"),
+                    findInfoLevel,
+                    out findData,
+                    FINDEX_SEARCH_OPS.FindExSearchNameMatch,
+                    IntPtr.Zero,
+                    additionalFlags);
+            }
+
+            if (hFile.ToInt32() != -1)
+            {
+                do
+                {
+                    if ((findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
+                    {
+                        Console.WriteLine("File {0}", findData.cFileName);
+                    }
+                    else
+                    {
+                        Console.WriteLine("Dir {0}", findData.cFileName);
+                    }
+                }
+                while (FindNextFile(hFile, out findData));
+
+                FindClose(hFile);
+            }
+            else
+            {
+                var ex = new Win32Exception();
+            }
+        }
+    }
+}

+ 29 - 0
QVCopier/Utility/FindFile/WIN32_FIND_DATA.cs

@@ -0,0 +1,29 @@
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace QVCopier.Utility.FindFile
+{
+    // The CharSet must match the CharSet of the corresponding PInvoke signature
+    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
+    internal struct WIN32_FIND_DATA
+    {
+        public FileAttributes dwFileAttributes;
+        public System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime;
+        public System.Runtime.InteropServices.ComTypes.FILETIME ftLastAccessTime;
+        public System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime;
+        public uint nFileSizeHigh;
+        public uint nFileSizeLow;
+        public uint dwReserved0;
+        public uint dwReserved1;
+
+        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
+        public string cFileName;
+
+        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
+        public string cAlternateFileName;
+
+        public uint dwFileType;
+        public uint dwCreatorType;
+        public uint wFinderFlags;
+    }
+}