Beispiel #1
0
        private static void mainThreadProcess()
        {
            int repeats = 0;

            PickRandomFile.scanDirectories();
            while (stopFlag == false && repeats != PickRandomFile.threadRepeatCount)
            {
                PickRandomFile.pickRandom();
                Thread.Sleep(PickRandomFile.threadWaitDuration);
                repeats++;

                if (PickRandomFile.showStats)
                {
                    String text = "";
                    //if its a repeat-until pick, show the number remaining.
                    if (PickRandomFile.threadRepeatCount != -1)
                    {
                        text += "R" + repeats.ToString() + "\\" + PickRandomFile.threadRepeatCount.ToString() + " ";
                    }
                    //if its a shuffle, show the folder stats
                    if (PickRandomFile.shuffle)
                    {
                        text += "F" + PickRandomFile.allFiles.Count.ToString();
                    }
                    mainWindow.setStatText(text);
                }
            }
            mainWindow.CloseMe();
        }
Beispiel #2
0
 private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (listView1.SelectedItems.Count == 1)
     {
         PickRandomFile.openFile((FileShortInfo)listView1.SelectedItems[0].Tag);
     }
 }
Beispiel #3
0
 private void btn_Open_Only_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem li in listView1.SelectedItems)
     {
         PickRandomFile.openFile((FileShortInfo)li.Tag);
     }
 }
Beispiel #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog f = new FolderBrowserDialog();

            f.ShowDialog();
            if (!String.IsNullOrEmpty(f.SelectedPath))
            {
                PickRandomFile.addPath(f.SelectedPath);
            }
        }
 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);
                }
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            try
            {
                //Load all the commands in args[] into a list so that we can add to them later if we get passed a filename,
                foreach (String s1 in args)
                {
                    commands.Add(s1);
                }
                string s       = "";
                string lastext = "";

                if (args.Length > 0)
                {
                    while (commands.Count > 0)
                    {
                        s = commands[0];
                        s.Trim();
                        commands.RemoveAt(0);
                        switch (ParseMode)
                        {
                        //deafault mode
                        case parseModes.Default:
                            switch (s)
                            {
                            case "-x":
                                ParseMode = parseModes.exclude;
                                break;

                            case "-nr":
                                PickRandomFile.recurse = false;
                                break;

                            case "-1":
                                PickRandomFile.firstfileonly = true;
                                break;

                            case "-shuffle":
                                PickRandomFile.shuffle = true;
                                break;

                            case "-stat":
                                PickRandomFile.showStats = true;
                                break;

                            case "-i":
                                PickRandomFile.ignoreMissingFolders = true;
                                break;

                            case "-f":
                                ParseMode = parseModes.filetype;
                                PickRandomFile.usingFileTypes = true;
                                break;

                            case "-?":
                                Help helpwindow = new Help(

                                    "Usage: \n" +
                                    "<dir>" + "\t\t" + "Include directory" + "\n" +
                                    "-c" + "\t\t" + "Choose file after search" + "\n" +
                                    "-x <dir>" + "\t\t" + "Exclude directory" + "\n" +
                                    "-nr" + "\t\t" + "Disable recursing directories" + "\n" +
                                    "-f <list>" + "\t\t" + "Comma separated list of filetypes (e.g. .avi,.mpg,.mpeg)" + "\n" +
                                    "-r" + "\t\t" + "Repeat pick files " + "\n" +
                                    "-rc <cnt>" + "\t\t" + "How many times to repeat the pick operation (infinite if not specified)" + "\n" +
                                    "-rd <dur>" + "\t\t" + "Duration between pick attempts (seconds)" + "\n" +
                                    "-stat" + "\t\t" + "Show stats (for certain modes) in the window" + "\n" +
                                    "-cachestats" + "\t\t" + "Show cache / pick stats" + "\n" +
                                    "-1" + "\t\t" + "Pick first file in directory" + "\n" +
                                    "-o <ext> <app>" + "\t" + "Override app to open a filetype with" + "\n" +
                                    "-l <filename>" + "\t" + "Load a set of commands from a file" + "\n" +
                                    "-h" + "\t" + "Runs any spawned applications in the background" + "\n" +
                                    "-i" + "\t" + "Silently ignore any missing directories" + "\n" +
                                    "-shuffle" + "\t" + "Picks one at a time until all files have been picked once" + "\n" +
                                    "-cache <min> <max>" + "\t" + "Cache file access for min < x < max hours" + "\n" +
                                    "-cachefolder <directory>" + "\t" + "Folder where cache data should be written" + "\n" +
                                    "--" + "\t" + "Null argument, use in scripts as a placeholder" + "\n" +
                                    "\n" +
                                    "Example File:" + "\n" +
                                    "-f" + "\n" +
                                    ".avi,.mpg,.mpeg,.mkv,.mp4,.rm" + "\n" +
                                    @"E:\eps\30 rock" + "\n" +
                                    @"E:\eps\drawn together" + "\n" +
                                    @"E:\eps\Harvey Birdman" + "\n"
                                    );
                                Application.Run(helpwindow);
                                PickMode = pickModes.noPick;
                                break;

                            case "-h":
                                PickRandomFile.hideSpawnedWindows = true;
                                break;

                            case "-c":
                                PickRandomFile.showChooser = true;
                                break;

                            case "-r":
                                PickMode = pickModes.threaded;
                                break;

                            case "-rc":
                                ParseMode = parseModes.repeatCnt;
                                break;

                            case "-rd":
                                ParseMode = parseModes.repeatDur;
                                break;

                            case "-o":
                                ParseMode = parseModes.overrideext;
                                break;

                            case "-l":
                                ParseMode = parseModes.loadfile;
                                break;


                            case "-cachestats":
                                PickRandomFile.showCacheStats = true;
                                break;

                            case "-cache":
                                PickRandomFile.useCache = true;
                                ParseMode = parseModes.cache_min;
                                break;

                            case "-cachefolder":
                                ParseMode = parseModes.cachefolder;
                                break;

                            case "--":
                                //Nothing needed here
                                break;

                            default:
                                PickRandomFile.addPath(s);
                                break;
                            }
                            break;

                        //exclude directory mode
                        case parseModes.exclude:
                            ParseMode = parseModes.Default;
                            PickRandomFile.excludePath(s);
                            break;

                        case parseModes.cachefolder:
                            ParseMode = parseModes.Default;
                            PickRandomFile.cachefolder = s;
                            break;

                        case parseModes.filetype:
                            ParseMode = parseModes.Default;
                            PickRandomFile.usingFileTypes = true;
                            PickRandomFile.fileFilter     = s;
                            string[] split = s.Split(',');
                            foreach (string filetype in split)
                            {
                                PickRandomFile.addFileType(filetype);
                            }
                            break;

                        case parseModes.repeatDur:
                            ParseMode = parseModes.Default;
                            int duration;
                            if (Int32.TryParse(s, out duration))
                            {
                                PickRandomFile.threadWaitDuration = duration * 1000;
                            }
                            break;

                        case parseModes.repeatCnt:
                            ParseMode = parseModes.Default;
                            int count;
                            if (Int32.TryParse(s, out count))
                            {
                                PickRandomFile.threadRepeatCount = count;
                            }
                            break;

                        case parseModes.overrideext:
                            ParseMode = parseModes.overrideapp;
                            lastext   = s;
                            break;

                        case parseModes.overrideapp:
                            ParseMode = parseModes.Default;
                            PickRandomFile.addOverride(lastext, s);
                            break;

                        case parseModes.loadfile:
                            //load a file one row at a time into args[]
                            ParseMode = parseModes.Default;
                            StreamReader f = new StreamReader(s);
                            string       line;
                            while ((line = f.ReadLine()) != null)
                            {
                                commands.Add(line);
                            }
                            break;

                        case parseModes.cache_min:
                            ParseMode = parseModes.cache_max;
                            PickRandomFile.cacheHoursMin = Convert.ToInt32(s);
                            break;

                        case parseModes.cache_max:
                            ParseMode = parseModes.Default;
                            PickRandomFile.cacheHoursMax = Convert.ToInt32(s);
                            break;
                        }
                    }
                    #region pickModes
                    switch (PickMode)
                    {
                    case pickModes.single:
                        PickRandomFile.scanDirectories();
                        if (PickRandomFile.showChooser)
                        {
                            PickRandomFile.pickChoice();
                        }
                        else
                        {
                            PickRandomFile.pickRandom();
                        }
                        break;

                    case pickModes.threaded:
                        Application.Run(new Monitor());

                        break;
                    }
                    #endregion
                }
                //else
                //{


                //    Application.EnableVisualStyles();
                //    Application.SetCompatibleTextRenderingDefault(false);
                //    Application.Run(new Monitor());
                //}
            }

            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace + "\n\n" + e.InnerException + "\n\n" + e.Source + "\n\n" + e.Data, e.Message);
            }
        }