-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03e8cbe
commit 5cc3645
Showing
4 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
package oger.util.java | ||
|
||
import org.gradle.internal.extensions.stdlib.capitalized | ||
import org.gradle.internal.extensions.stdlib.toDefaultLowerCase | ||
import java.io.File | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
|
||
object GDriveLocator { | ||
var DEBUG = false | ||
|
||
fun locate(): Path? { | ||
|
||
val letterDriveCandidates = File.listRoots() | ||
.map { it.toPath() } | ||
.map { it.resolve("My Drive") } | ||
.toCollection(ArrayList()) | ||
|
||
addIfExists(letterDriveCandidates, "GDRIVE") | ||
|
||
letterDriveCandidates.add(Paths.get("${System.getenv("userprofile")}/Google Drive")) | ||
letterDriveCandidates.add(Paths.get("${System.getenv("userprofile")}/My Drive")) | ||
|
||
if (DEBUG) letterDriveCandidates.forEach { println("checking location $it: ${Files.exists(it)}") } | ||
|
||
return letterDriveCandidates.find { Files.exists(it) } | ||
} | ||
|
||
private fun addIfExists(candidates: MutableList<Path>, value: String) { | ||
System.getenv(value)?.let { | ||
candidates.add(0, Paths.get(it)) | ||
} | ||
System.getProperty(value.toDefaultLowerCase().capitalized())?.let { | ||
candidates.add(0, Paths.get(it)) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters