public static string PrepareFilename(Workflow workflow, Image img, EImageFormat imageFormat, NameParser parser)
        {
            string ext = "png";

            switch (imageFormat)
            {
            case EImageFormat.PNG:
                ext = "png";
                break;

            case EImageFormat.JPEG:
                ext = "jpg";
                break;

            case EImageFormat.GIF:
                ext = "gif";
                break;

            case EImageFormat.BMP:
                ext = "bmp";
                break;

            case EImageFormat.TIFF:
                ext = "tif";
                break;
            }

            string pattern = workflow.ConfigFileNaming.EntireScreenPattern;

            switch (parser.Type)
            {
            case NameParserType.ActiveWindow:
                pattern = workflow.ConfigFileNaming.ActiveWindowPattern;
                break;

            default:
                pattern = workflow.ConfigFileNaming.EntireScreenPattern;
                break;
            }
            string fn = parser.Convert(pattern);

            if (Engine.ConfigWorkflow != null)
            {
                Engine.ConfigWorkflow.ConfigFileNaming.AutoIncrement = parser.AutoIncrementNumber; // issue 577; Engine.Workflow.AutoIncrement has to be updated
            }

            string fileName = string.Format("{0}.{1}", fn, ext);

            return(FileSystem.GetUniqueFileName(workflow, fileName));
        }
Exemplo n.º 2
0
        public static bool ManageImageFolders(string path)
        {
            if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
            {
                string[] images = Directory.GetFiles(path);

                List <string> imagesList = new List <string>();

                foreach (string image in images)
                {
                    foreach (string s in Engine.zImageFileTypes)
                    {
                        if (Path.HasExtension(image) && Path.GetExtension(image.ToLower()) == "." + s)
                        {
                            imagesList.Add(image);
                            break;
                        }
                    }
                }

                DebugHelper.WriteLine(string.Format("Found {0} images to move to sub-folders", imagesList.Count));

                if (imagesList.Count > 0)
                {
                    if (MessageBox.Show(string.Format("{0} files found in {1}\nPlease wait until all the files are moved...",
                                                      imagesList.Count, path), Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel)
                    {
                        return(false);
                    }

                    DateTime time;
                    string   newFolderPath;
                    string   movePath;

                    foreach (string image in imagesList)
                    {
                        if (File.Exists(image))
                        {
                            time          = File.GetCreationTime(image);
                            newFolderPath = new NameParser(NameParserType.SaveFolder)
                            {
                                CustomDate = time
                            }.Convert(Engine.ConfigWorkflow.SaveFolderPattern);
                            newFolderPath = Path.Combine(path, newFolderPath);

                            if (!Directory.Exists(newFolderPath))
                            {
                                Directory.CreateDirectory(newFolderPath);
                            }

                            movePath = FileSystem.GetUniqueFileName(Engine.ConfigWorkflow, Path.Combine(newFolderPath, Path.GetFileName(image)));
                            File.Move(image, movePath);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }