void Reload()
        {
            if (_currentfile != null)
            {
                // refresh listbox contents
                string[] lines = File.ReadAllLines(_currentfile, Encoding.UTF8);
                listBox.Items.Clear();
                foreach (var line in lines)
                {
                    listBox.Items.Add(line);
                }

                // get categories string
                var categories = Configs.Current.Get(ConfigKey.CategoriesModeText);
                if (categories == null || categories.Length == 0)
                {
                    categories = "G/good/good|B/bad/bad";
                    Configs.Current.Set(ConfigKey.CategoriesModeText, categories);
                }

                // refresh categories in ui
                _categoryKeyBindings.Clear();
                lblCategories.Text = "";
                var tuples = ModeUtils.CategoriesStringToTuple(categories);
                foreach (var tuple in tuples)
                {
                    lblCategories.Text += tuple.Item1 + "    " +
                                          tuple.Item2 + Utils.NL + Utils.NL;
                    _categoryKeyBindings[tuple.Item1] = tuple.Item3;
                }
            }
        }
        public void AutoAcceptSmallFiles(FormGallery form, int capJpg = 0, int capWebp = 0)
        {
            var list = form.GetFilelist().GetList();

            // first, check for duplicate names
            foreach (var path in list)
            {
                var similar = FindSimilarFilenames.FindSimilarNames(
                    path, GetFileTypes(), list, out bool nameHasSuffix, out string pathWithoutSuffix);
                if (similar.Count != 0)
                {
                    Utils.MessageErr("the file " + path + " has similar name(s) "
                                     + string.Join(Utils.NL, similar));
                    return;
                }
            }

            // then, accept the small files
            if (capJpg == 0)
            {
                var optCapWebp = InputBoxForm.GetInteger("Accept webp files less than this many Kb:", 50);
                if (!optCapWebp.HasValue)
                {
                    return;
                }

                var optCapJpg = InputBoxForm.GetInteger("Accept jpg files less than this many Kb:", 100);
                if (!optCapJpg.HasValue)
                {
                    return;
                }

                capWebp = 1024 * optCapWebp.Value;
                capJpg  = 1024 * optCapJpg.Value;
            }

            int countAccepted      = 0;
            var sizeIsGoodCategory = GetDefaultCategories().Split(new char[] { '/' })[2];

            foreach (var path in list)
            {
                var fileLength = new FileInfo(path).Length;
                if (fileLength > 0 &&
                    ((ModeUtils.IsWebp(path) &&
                      fileLength < capWebp) ||
                     (ModeUtils.IsJpg(path) &&
                      fileLength < capJpg)))
                {
                    countAccepted++;
                    var newPath = FilenameUtils.AddCategoryToFilename(path, sizeIsGoodCategory);
                    form.WrapMoveFile(path, newPath);
                }
            }

            Utils.MessageBox("Accepted for " + countAccepted + " images.", true);
        }
        // bitmapWillLockFile indicates whether holding onto Bitmap will hold lock on a file.
        public static Bitmap GetBitmap(string path, JpegRotationFinder shouldrotate, out bool bitmapWillLockFile)
        {
            Bitmap bitmap = null;

            try
            {
                if (ModeUtils.IsWebp(path))
                {
                    byte[] bytesData = File.ReadAllBytes(path);
                    var    decoder   = new Imazen.WebP.SimpleDecoder();
                    bitmap             = decoder.DecodeFromBytes(bytesData, bytesData.LongLength);
                    bitmapWillLockFile = false;
                }
                else
                {
                    bitmap             = new Bitmap(path);
                    bitmapWillLockFile = true;

                    // some image files have custom resolutions,
                    // I prefer seeing all files at the same resolution.
                    bitmap.SetResolution(96.0f, 96.0f);
                }
            }
            catch (Exception e)
            {
                if (ModeUtils.IsWebp(path) &&
                    e.ToString().ToUpperInvariant().Contains("0x8007007E"))
                {
                    Utils.MessageErr("It appears that the Visual C++ Redistributable " +
                                     "Packages for Visual Studio 2013 are not installed; please run " +
                                     "vcredist_x64.exe so that libwebp.dll can be used.");
                }

                Utils.MessageErr("Could not load the image " + path +
                                 Utils.NL + Utils.NL + Utils.NL + "Details: " +
                                 e.ToString(), true);

                if (bitmap != null)
                {
                    bitmap.Dispose();
                }

                bitmapWillLockFile = true;
                bitmap             = new Bitmap(1, 1, PixelFormat.Format32bppPArgb);
            }

            if (shouldrotate != null && shouldrotate.ShouldRotate(path))
            {
                bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
            }

            return(bitmap);
        }
        public static Tuple <string, string, string>[] ModeToTuples(ModeBase mode)
        {
            var categoriesString = Configs.Current.Get(mode.GetCategories());

            return(ModeUtils.CategoriesStringToTuple(categoriesString));
        }