c# 调用Everything-SDK 实现文件快速搜索

Everything 下载地址:点击访问

Everything-SDK 接口API和注意事项:点击访问

一、下载Everything-SDK 并解压在项目目录中并设置DLL 始终复制输出

image.pngimage.png

二、新建一个 Everything.cs 文件内容如下:

      public class Everything
    {
        /// <summary>
        /// 是否64位
        /// </summary>
        /// <returns></returns>
        public static bool IsSys64bit()
        {
            if (IntPtr.Size == 8)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        internal class Everything32
        {
            private const string LIB_NAME = "dll/Everything32.dll";

            #region 引用定义

            private const int EVERYTHING_OK = 0;
            private const int EVERYTHING_ERROR_MEMORY = 1;
            private const int EVERYTHING_ERROR_IPC = 2;
            private const int EVERYTHING_ERROR_REGISTERCLASSEX = 3;
            private const int EVERYTHING_ERROR_CREATEWINDOW = 4;
            private const int EVERYTHING_ERROR_CREATETHREAD = 5;
            private const int EVERYTHING_ERROR_INVALIDINDEX = 6;
            private const int EVERYTHING_ERROR_INVALIDCALL = 7;

            [DllImport(LIB_NAME)]
            public static extern int Everything_SetSearch(string lpSearchString);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchPath(bool bEnable);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchCase(bool bEnable);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchWholeWord(bool bEnable);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetRegex(bool bEnable);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMax(int dwMax);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetOffset(int dwOffset);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchPath();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchCase();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchWholeWord();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetRegex();

            [DllImport(LIB_NAME)]
            public static extern UInt32 Everything_GetMax();

            [DllImport(LIB_NAME)]
            public static extern UInt32 Everything_GetOffset();

            [DllImport(LIB_NAME)]
            public static extern string Everything_GetSearch();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetLastError();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_Query(bool bWait);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SortResultsByPath();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumFileResults();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumFolderResults();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumResults();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotFileResults();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotFolderResults();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotResults();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsVolumeResult(int nIndex);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsFolderResult(int nIndex);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsFileResult(int nIndex);

            [DllImport(LIB_NAME)]
            public static extern void Everything_GetResultFullPathName(int nIndex, StringBuilder lpString, int nMaxCount);

            [DllImport(LIB_NAME)]
            public static extern void Everything_Reset();

            [DllImport(LIB_NAME)]
            public static extern IntPtr Everything_GetResultFileName(int nIndex);

            [DllImport(LIB_NAME)]
            public static extern IntPtr Everything_GetResultPath(int nIndex);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetResultDateModified(int nIndex, out long lpFileTime);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsAdmin();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsAppData();

            [DllImport(LIB_NAME)]
            public static extern long Everything_GetRevision();

            #endregion 引用定义
        }

        internal class Everything64
        {
            private const string LIB_NAME = "dll/Everything64.dll";

            #region 引用定义

            private const int EVERYTHING_OK = 0;
            private const int EVERYTHING_ERROR_MEMORY = 1;
            private const int EVERYTHING_ERROR_IPC = 2;
            private const int EVERYTHING_ERROR_REGISTERCLASSEX = 3;
            private const int EVERYTHING_ERROR_CREATEWINDOW = 4;
            private const int EVERYTHING_ERROR_CREATETHREAD = 5;
            private const int EVERYTHING_ERROR_INVALIDINDEX = 6;
            private const int EVERYTHING_ERROR_INVALIDCALL = 7;

            [DllImport(LIB_NAME)]
            public static extern int Everything_SetSearch(string lpSearchString);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchPath(bool bEnable);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchCase(bool bEnable);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchWholeWord(bool bEnable);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetRegex(bool bEnable);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMax(int dwMax);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SetOffset(int dwOffset);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchPath();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchCase();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchWholeWord();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetRegex();

            [DllImport(LIB_NAME)]
            public static extern UInt32 Everything_GetMax();

            [DllImport(LIB_NAME)]
            public static extern UInt32 Everything_GetOffset();

            [DllImport(LIB_NAME)]
            public static extern string Everything_GetSearch();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetLastError();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_Query(bool bWait);

            [DllImport(LIB_NAME)]
            public static extern void Everything_SortResultsByPath();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumFileResults();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumFolderResults();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumResults();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotFileResults();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotFolderResults();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotResults();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsVolumeResult(int nIndex);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsFolderResult(int nIndex);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsFileResult(int nIndex);

            [DllImport(LIB_NAME)]
            public static extern void Everything_GetResultFullPathName(int nIndex, StringBuilder lpString, int nMaxCount);

            [DllImport(LIB_NAME)]
            public static extern void Everything_Reset();

            [DllImport(LIB_NAME)]
            public static extern IntPtr Everything_GetResultFileName(int nIndex);

            [DllImport(LIB_NAME)]
            public static extern IntPtr Everything_GetResultPath(int nIndex);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetResultDateModified(int nIndex, out long lpFileTime);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsAdmin();

            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsAppData();

            [DllImport(LIB_NAME)]
            public static extern long Everything_GetRevision();

            #endregion 引用定义
        }

        internal static void Everything_SetSearch(string sKeyWord)
        {
            if (IntPtr.Size == 8)
                Everything64.Everything_SetSearch(sKeyWord);
            else
                Everything32.Everything_SetSearch(sKeyWord);
        }

        internal static bool Everything_Query(bool bWait)
        {
            if (IntPtr.Size == 8)
                return Everything64.Everything_Query(bWait);
            else
                return Everything32.Everything_Query(bWait);
        }

        internal static int Everything_GetNumResults()
        {
            if (IntPtr.Size == 8)
                return Everything64.Everything_GetNumResults();
            else
                return Everything32.Everything_GetNumResults();
        }

        internal static bool Everything_IsFolderResult(int idx)
        {
            if (IntPtr.Size == 8)
                return Everything64.Everything_IsFolderResult(idx);
            else
                return Everything32.Everything_IsFolderResult(idx);
        }

        internal static void Everything_SortResultsByPath()
        {
            if (IntPtr.Size == 8)
                Everything64.Everything_SortResultsByPath();
            else
                Everything32.Everything_SortResultsByPath();
        }

        internal static void Everything_GetResultFullPathName(int i, StringBuilder buf, int bufsize)
        {
            if (IntPtr.Size == 8)
                Everything64.Everything_GetResultFullPathName(i, buf, bufsize);
            else
                Everything32.Everything_GetResultFullPathName(i, buf, bufsize);
        }

        internal static IntPtr Everything_GetResultFileName(int idx)
        {
            if (IntPtr.Size == 8)
                return Everything64.Everything_GetResultFileName(idx);
            else
                return Everything32.Everything_GetResultFileName(idx);
        }

        internal static IntPtr Everything_GetResultPath(int nIndex)
        {
            if (IntPtr.Size == 8)
                return Everything64.Everything_GetResultPath(nIndex);
            else
                return Everything32.Everything_GetResultPath(nIndex);
        }

        internal static bool Everything_GetResultDateModified(int nIndex, out long lpFileTime)
        {
            if (IntPtr.Size == 8)
                return Everything64.Everything_GetResultDateModified(nIndex, out lpFileTime);
            else
                return Everything32.Everything_GetResultDateModified(nIndex, out lpFileTime);
        }

        internal static long Everything_GetRevision()
        {
            if (IntPtr.Size == 8)
                return Everything64.Everything_GetRevision();
            else
                return Everything32.Everything_GetRevision();
        }

        internal static long Everything_GetLastError()
        {
            if (IntPtr.Size == 8)
                return Everything64.Everything_GetLastError();
            else
                return Everything32.Everything_GetLastError();
        }
    }

三、调用

 private static void Main(string[] args)
        {
            try
            {
                string text = "文件";
                Everything.Everything_SetSearch(text);

                Everything.Everything_Query(true);
                int fileNum = Everything.Everything_GetNumResults();
                if (fileNum != 0)
                {
                    const int bufsize = 260;
                    StringBuilder buf = new StringBuilder(bufsize);
                    for (int i = 0; i < fileNum; i++)
                    {
                        long date_modified;
                        long size;
                        Everything.Everything_GetResultFullPathName(i, buf, bufsize);
                        String 后缀名 = System.IO.Path.GetExtension(buf.ToString());
                    }
                }
                else
                {
                    Console.WriteLine("搜索结果为0");
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }

四、效果

image.png




本文作者:admin

本文链接:https://www.javalc.com/post/73.html

版权声明:本篇文章于2021-08-23,由admin发表,转载请注明出处:分享你我。如有疑问,请联系我们

华为光猫HS8145X6 补齐shell EPON与GPON双切换(最简单)

发表评论

取消
扫码支持