示例#1
0
 private void btnFolder_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem li in listView1.SelectedItems)
     {
         FileShortInfo fi = (FileShortInfo)li.Tag;
         System.Diagnostics.Process.Start("Explorer.exe", fi.Directory);
     }
 }
示例#2
0
 private void btngo_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count == 1)
     {
         DialogResult = DialogResult.OK;
         result       = (FileShortInfo)listView1.SelectedItems[0].Tag;
     }
     else
     {
         DialogResult = DialogResult.Abort;
     }
 }
示例#3
0
        private void listView1_MouseHover(object sender, EventArgs e)
        {
            ListViewItem li = listView1.GetItemAt(ListBox.MousePosition.X, ListBox.MousePosition.Y);

            if (li != null)
            {
                FileShortInfo fi = (FileShortInfo)li.Tag;

                toolTip1.SetToolTip(listView1, fi.Directory);
                toolTip1.Show(fi.Directory, this, 10000);
            }
        }
示例#4
0
 private void btngo_Click(object sender, EventArgs e)
 {
     if ( listView1.SelectedItems.Count == 1)
     {
         DialogResult = DialogResult.OK;
         result = (FileShortInfo)listView1.SelectedItems[0].Tag;
     }
     else
     {
         DialogResult = DialogResult.Abort;
     }
 }
        public static void pickRandom()
        {
            //pick a random file from our list
            Random r = new Random(DateTime.Now.Millisecond + DateTime.Now.Second + DateTime.Now.Minute);

            //are we shuffling, and at the end of the shuffled list?
            if (shuffle && allFiles.Count == 0 && pickedFiles.Count > 0)
            {
                allFiles    = pickedFiles;
                pickedFiles = new List <FileShortInfo>();
            }


            if (allFiles.Count > 0)
            {
                FileShortInfo    fi_s        = allFiles[r.Next(allFiles.Count)];
                FileInfo         fi          = new FileInfo(fi_s.FullPath);
                String           overrideApp = isExtensionOverridden(fi.Extension);
                ProcessStartInfo startinfo   = new ProcessStartInfo();

                if (shuffle)
                {
                    pickedFiles.Add(fi_s);
                    allFiles.Remove(fi_s);
                }


                if (overrideApp == "")
                {
                    startinfo = new ProcessStartInfo(fi.FullName);
                }
                else
                {
                    startinfo = new ProcessStartInfo(overrideApp, "\"" + fi.FullName + "\"");
                }
                if (hideSpawnedWindows)
                {
                    startinfo.CreateNoWindow  = true;
                    startinfo.WindowStyle     = ProcessWindowStyle.Hidden;
                    startinfo.UseShellExecute = false;
                }

                try
                {
                    Process.Start(startinfo);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Couldnt start program - " + overrideApp + " - " + fi.FullName + " - " + e.Message + " " + e.StackTrace, "Couldnt start program");
                }
            }
        }
        public static void openFile(FileShortInfo fi)
        {
            String overrideApp = isExtensionOverridden(fi.Extension);

            if (overrideApp == "")
            {
                System.Diagnostics.Process.Start(fi.FileName);
            }
            else
            {
                System.Diagnostics.Process.Start(overrideApp, "\"" + fi.FullPath + "\"");
            }
        }
示例#7
0
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem li in listView1.SelectedItems)
            {
                FileShortInfo fi = (FileShortInfo)li.Tag;
                DialogResult  r  = MessageBox.Show("Are you sure you want to delete this file / these files? \n\r" + fi.FullPath + "\n\r\n\rNote that the file will remain in the list until you search again", "Are you sure?", MessageBoxButtons.YesNo);

                if (r == DialogResult.Yes)
                {
                    FileInfo ffi = new FileInfo(fi.FullPath);
                    if (ffi.Exists)
                    {
                        ffi.Delete();
                    }
                }
            }
        }
 static bool addFileToResults(FileShortInfo f)
 {
     try
     {
         if (usingFileTypes)
         {
             if (PickRandomFile.isExtensionIncluded(f.Extension))
             {
                 return(true);
             }
         }
         else
         {
             return(true);
         }
     }
     catch (Exception e)
     {
         throw new Exception("Error adding file to results", e);
     }
     return(false);
 }
        /// <summary>
        /// Scan directories recursively using the Kernel32 s***e at the bottom.
        /// </summary>
        /// <param name="dirName"></param>
        static void getFilesFromFolder(String dirName)
        {
            IntPtr           INVALID_HANDLE_VALUE = new IntPtr(-1);
            WIN32_FIND_DATAW findData;
            IntPtr           findHandle = INVALID_HANDLE_VALUE;

            List <FileShortInfo> filesForCache = new List <FileShortInfo>();

            try
            {
                findHandle = FindFirstFileW(dirName + @"\*", out findData);
                if (findHandle != INVALID_HANDLE_VALUE)
                {
                    do
                    {
                        //ignore the "up" folders
                        //ignore subfolders (recursion handled above now)
                        if (findData.cFileName == "." ||
                            findData.cFileName == ".." ||
                            PickRandomFile.isDirectoryExcluded(findData.cFileName) ||
                            (findData.dwFileAttributes & FileAttributes.Directory) != 0)
                        {
                            continue;
                        }

                        string fullpath = dirName + (dirName.EndsWith("\\") ? "" : "\\") + findData.cFileName;

                        /*/Directory - recurse
                         * if ((findData.dwFileAttributes & FileAttributes.Directory) != 0 && recurse == true)
                         * {
                         *  dirs_scanned++;
                         *   getFilesFromFolder(fullpath);
                         * }*/

                        DateTime file_start = DateTime.Now;
                        files_scanned++;
                        FileShortInfo f = new FileShortInfo()
                        {
                            CreatedDate  = FTimeToDateTime(findData.ftCreationTime),
                            ModifiedDate = FTimeToDateTime(findData.ftLastWriteTime),
                            FullPath     = fullpath,
                            Extension    = fullpath.Substring(fullpath.LastIndexOf(".")),
                            FileName     = fullpath.Substring(fullpath.LastIndexOf("\\") + 1),
                            Directory    = fullpath.Substring(0, fullpath.LastIndexOf("\\")),
                            Size         = findData.nFileSizeLow
                        };


                        //add file to results
                        if (addFileToResults(f))
                        {
                            allFiles.Add(f);
                            filesForCache.Add(f);
                        }

                        tim_file += DateTime.Now.Subtract(file_start).TotalSeconds;
                    }while (FindNextFile(findHandle, out findData));

                    //now update the cache
                    if (useCache)
                    {
                        cache.addCacheData(dirName, PickRandomFile.fileFilter, filesForCache);
                    }
                }
            }
            catch (Exception e)
            {
                if (!ignoreMissingFolders)
                {
                    MessageBox.Show("Exception when scanning folder" + dirName + "\n" + e.Message + "\n\n" + e.StackTrace + "\n\n" + e.Source);
                }
            }
            finally
            {
                if (findHandle != INVALID_HANDLE_VALUE)
                {
                    FindClose(findHandle);
                }
            }
        }
示例#10
0
        /// <summary>
        /// Scan directories recursively using the Kernel32 s***e at the bottom.
        /// </summary>
        /// <param name="dirName"></param>
        static void getFilesFromFolder(String dirName)
        {
            IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
            WIN32_FIND_DATAW findData;
            IntPtr findHandle = INVALID_HANDLE_VALUE;

            List<FileShortInfo> filesForCache = new List<FileShortInfo>();

            try
            {
                findHandle = FindFirstFileW(dirName + @"\*", out findData);
                if (findHandle != INVALID_HANDLE_VALUE)
                {
                    do
                    {
                        //ignore the "up" folders
                        //ignore subfolders (recursion handled above now)
                        if (findData.cFileName == "."
                            || findData.cFileName == ".."
                            || PickRandomFile.isDirectoryExcluded(findData.cFileName)
                            || (findData.dwFileAttributes & FileAttributes.Directory) != 0)
                            continue;

                        string fullpath = dirName + (dirName.EndsWith("\\") ? "" : "\\") + findData.cFileName;

                        /*/Directory - recurse
                        if ((findData.dwFileAttributes & FileAttributes.Directory) != 0 && recurse == true)
                        {
                            dirs_scanned++;
                             getFilesFromFolder(fullpath);
                        }*/

                        DateTime file_start = DateTime.Now;
                        files_scanned++;
                        FileShortInfo f = new FileShortInfo()
                        {
                            CreatedDate = FTimeToDateTime(findData.ftCreationTime),
                            ModifiedDate = FTimeToDateTime(findData.ftLastWriteTime),
                            FullPath = fullpath,
                            Extension = fullpath.Substring(fullpath.LastIndexOf(".")),
                            FileName = fullpath.Substring(fullpath.LastIndexOf("\\") + 1),
                            Directory = fullpath.Substring(0, fullpath.LastIndexOf("\\")),
                            Size = findData.nFileSizeLow
                        };

                        //add file to results
                        if (addFileToResults(f))
                        {
                            allFiles.Add(f);
                            filesForCache.Add(f);
                        }

                        tim_file += DateTime.Now.Subtract(file_start).TotalSeconds;
                    }
                    while (FindNextFile(findHandle, out findData));

                    //now update the cache
                    if (useCache) {cache.addCacheData(dirName, PickRandomFile.fileFilter, filesForCache);}

                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Exception when scanning folder" + dirName + "\n" + e.Message + "\n\n" + e.StackTrace + "\n\n" + e.Source);
            }
            finally
            {
                if (findHandle != INVALID_HANDLE_VALUE) FindClose(findHandle);
            }
        }
示例#11
0
        static bool addFileToResults(FileShortInfo f)
        {
            try
            {
                if (usingFileTypes)
                {
                    if (PickRandomFile.isExtensionIncluded(f.Extension))
                    {
                        return true;
                    }
                }
                else
                {
                    return true;
                }

            }
            catch (Exception e)
            {
                throw new Exception("Error adding file to results", e);
            }
            return false;
        }
示例#12
0
        public static void openFile(FileShortInfo fi)
        {
            String overrideApp = isExtensionOverridden(fi.Extension);

            if (overrideApp == "")
            {
                System.Diagnostics.Process.Start(fi.FileName);
            }
            else
            {
                System.Diagnostics.Process.Start(overrideApp, "\"" + fi.FullPath + "\"");
            }
        }