Made a file name duplication prevention

This commit is contained in:
Eric-Turner
2016-05-20 22:03:01 -04:00
parent df6a34420f
commit 0dfc4d854e
+9 -1
View File
@@ -150,7 +150,15 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
Robot robot = new Robot(); Robot robot = new Robot();
Rectangle parabotScreen = new Rectangle((int) getLocation().getX(), (int) getLocation().getY(), getWidth(), getHeight()); Rectangle parabotScreen = new Rectangle((int) getLocation().getX(), (int) getLocation().getY(), getWidth(), getHeight());
BufferedImage image = robot.createScreenCapture(parabotScreen); BufferedImage image = robot.createScreenCapture(parabotScreen);
ImageIO.write(image, "png", new File(Directories.getScreenshotDir().getPath() + "/" + StringUtils.randomString(10) + ".png")); String randString = StringUtils.randomString(10);
for (int x = 0; x < Directories.getScreenshotDir().listFiles().length; x++) {
if (Directories.getScreenshotDir().listFiles()[x].getAbsoluteFile().getName().contains(randString)) {
randString = randString + StringUtils.randomString(4);
}
}
File file = new File(Directories.getScreenshotDir().getPath() + "/" + randString + ".png");
ImageIO.write(image, "png", file);
} catch (IOException | AWTException k) { } catch (IOException | AWTException k) {
k.printStackTrace(); k.printStackTrace();
} }