forked from juliand665/Resolution-Control
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathRCUtil.java
More file actions
49 lines (38 loc) · 1.47 KB
/
RCUtil.java
File metadata and controls
49 lines (38 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package io.github.ultimateboomer.resolutioncontrol.util;
import java.io.File;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public final class RCUtil {
private static final String[] UNITS = "KMGTPE".split("");
private static final NumberFormat FORMAT = NumberFormat.getNumberInstance();
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
/**
* Format number with metric conversion (K, M, G etc)
*/
public static String formatMetric(long n) {
if (n < 1000) {
return n + " ";
}
int log10 = (int) Math.log10(n);
int decimalPlace = (int) Math.pow(10, 2 - log10 % 3);
int displayDigits = (int) (n / Math.pow(10, log10 - 2));
float result = (float) displayDigits / decimalPlace;
return String.format("%s %s", FORMAT.format(result), UNITS[log10 / 3 - 1]);
}
public static String getScreenshotFilename(File directory) {
String string = DATE_FORMAT.format(new Date());
int i = 1;
while (true) {
File screenshotDir = new File(directory, "screenshots");
screenshotDir.mkdir();
String fileName = "fb" + string + (i == 1 ? "" : "_" + i) + ".png";
File imagePath = new File(screenshotDir, fileName);
if (!imagePath.exists()) {
return fileName;
}
++i;
}
}
}