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); }
static void TestMethod_UtilsGetCategory() { var testAdd = FilenameUtils.AddCategoryToFilename(PathSep("c:/dir/test/b b.aaa.jpg"), "mk"); TestUtil.IsEq(PathSep("c:/dir/test/b b.aaa__MARKAS__mk.jpg"), testAdd); testAdd = FilenameUtils.AddCategoryToFilename(PathSep("c:/dir/test/b b.aaa.jpg"), ""); TestUtil.IsEq(PathSep("c:/dir/test/b b.aaa__MARKAS__.jpg"), testAdd); Func <string, string> testGetCategory = (input) => { FilenameUtils.GetCategoryFromFilename(input, out string pathWithoutCategory, out string category); return(pathWithoutCategory + "|" + category); };