Skip to content

Commit

Permalink
Reuse awt tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
azvegint committed Jun 27, 2024
1 parent b2fdc5a commit 9f4bea6
Showing 1 changed file with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ final class TokenStorage {
private TokenStorage() {}

private static final String REL_NAME =
".fx/robot/screencast-tokens.properties";
".java/.robot/screencast-tokens.properties";
private static final String REL_NAME_SECONDARY =
".awt/robot/screencast-tokens.properties";

private static final Properties PROPS = new Properties();
private static final Path PROPS_PATH;
Expand Down Expand Up @@ -109,26 +111,33 @@ private static Path setupPath() {
return null;
}

Path path = Path.of(userHome, REL_NAME);
Path secondaryPath = Path.of(userHome, REL_NAME_SECONDARY);

// use secondary path only if it already exists and writable
Path path = Files.isWritable(secondaryPath)
? secondaryPath
: Path.of(userHome, REL_NAME);
Path workdir = path.getParent();

if (!Files.exists(workdir)) {
try {
Files.createDirectories(workdir);
} catch (Exception e) {
if (SCREENCAST_DEBUG) {
System.err.printf("Token storage: cannot create" +
" directory %s %s\n", workdir, e);
if (!Files.isWritable(path)) {
if (!Files.exists(workdir)) {
try {
Files.createDirectories(workdir);
} catch (Exception e) {
if (SCREENCAST_DEBUG) {
System.err.printf("Token storage: cannot create" +
" directory %s %s\n", workdir, e);
}
return null;
}
return null;
}
}

if (!Files.isWritable(workdir)) {
if (SCREENCAST_DEBUG) {
System.err.printf("Token storage: %s is not writable\n", workdir);
if (!Files.isWritable(workdir)) {
if (SCREENCAST_DEBUG) {
System.err.printf("Token storage: %s is not writable\n", workdir);
}
return null;
}
return null;
}

try {
Expand Down

0 comments on commit 9f4bea6

Please sign in to comment.