Esempio n. 1
0
        private static void CheckAndThrowExceptionOnError()
        {
            switch (EverythingApiDllImport.Everything_GetLastError())
            {
            case StateCode.CreateThreadError:
                throw new CreateThreadException();

            case StateCode.CreateWindowError:
                throw new CreateWindowException();

            case StateCode.InvalidCallError:
                throw new InvalidCallException();

            case StateCode.InvalidIndexError:
                throw new InvalidIndexException();

            case StateCode.IPCError:
                throw new IPCErrorException();

            case StateCode.MemoryError:
                throw new MemoryErrorException();

            case StateCode.RegisterClassExError:
                throw new RegisterClassExException();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Resets this instance.
 /// </summary>
 public void Reset()
 {
     lock (_syncObject)
     {
         EverythingApiDllImport.Everything_Reset();
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Searches the specified key word and reset the everything API afterwards
        /// </summary>
        /// <param name="keyWord">The key word.</param>
        /// <param name="token">when cancelled the current search will stop and exit (and would not reset)</param>
        /// <param name="offset">The offset.</param>
        /// <param name="maxCount">The max count.</param>
        /// <returns></returns>
        public List <SearchResult> Search(string keyWord, CancellationToken token, int offset = 0, int maxCount = 100)
        {
            if (string.IsNullOrEmpty(keyWord))
            {
                throw new ArgumentNullException(nameof(keyWord));
            }

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }

            if (maxCount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxCount));
            }

            lock (_syncObject)
            {
                if (keyWord.StartsWith("@"))
                {
                    EverythingApiDllImport.Everything_SetRegex(true);
                    keyWord = keyWord.Substring(1);
                }

                EverythingApiDllImport.Everything_SetSearchW(keyWord);
                EverythingApiDllImport.Everything_SetOffset(offset);
                EverythingApiDllImport.Everything_SetMax(maxCount);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }


                if (!EverythingApiDllImport.Everything_QueryW(true))
                {
                    CheckAndThrowExceptionOnError();
                    return(null);
                }

                var results = new List <SearchResult>();
                for (int idx = 0; idx < EverythingApiDllImport.Everything_GetNumResults(); ++idx)
                {
                    if (token.IsCancellationRequested)
                    {
                        return(null);
                    }

                    EverythingApiDllImport.Everything_GetResultFullPathNameW(idx, _buffer, BufferSize);

                    var result = new SearchResult {
                        FullPath = _buffer.ToString()
                    };
                    if (EverythingApiDllImport.Everything_IsFolderResult(idx))
                    {
                        result.Type = ResultType.Folder;
                    }
                    else if (EverythingApiDllImport.Everything_IsFileResult(idx))
                    {
                        result.Type = ResultType.File;
                    }

                    results.Add(result);
                }

                Reset();

                return(results);
            }
        }