2 * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.commons.file;
10 * FIXME: Quite ugly and unreliable. Better solution is needed.
12 public class CommonPathResolver {
14 private static final String[] desktopNames = new String[]{"Tafelblad", "المكتب",
15 "Masa Üstü", "Сталец", "Десктоп", "ডেস্কটপ", "Desktop",
16 "Escriptori", "Prostředí pracovní plochy", "Penbwrdd",
17 "Skrivebord", "Επιφάνεια εργασίας", "Escritorio", "Töölaud",
18 "Mahaigaina", "Työpöytä", "Bureau", "Deasc", "ડૅસ્કટોપ",
19 "डेस्कटॉप", "Radna površina", "Munkaasztal", "デスクトップ", "დესკტოპი",
20 "데스크탑", "Darbastalis", "Дэлгэц", "Skrivebord", "Teseke", "ਵਿਹੜਾ",
21 "Pulpit", "Ambiente de Trabalho", "Área de Trabalho",
22 "Рабочий стол", "Pracovná plocha", "Hapësira e Punës",
23 "Радна површ", "Radna površ", "Skrivbord", "கணிமேசை", "Мизи корӣ",
24 "พื้นโต๊ะ", "Masaüstü", "Стільниця", "桌面", "Isiga-nyezi"};
26 private static File desktopFile;
29 * This method tries to guess user desktop directory. Implementation is
30 * pretty lousy. Need to improve it some day.
32 * @return file that points to user desktop directory.
33 * @throws RuntimeException if user desktop directory is not found.
35 public static File getDesktopDirectory() {
37 if (desktopFile != null)
40 final String userHomePath = System.getProperty("user.home");
42 for (final String desktopName : desktopNames) {
44 final String desktopPath = userHomePath + "/" + desktopName;
46 final File possibleDesktopFile = new File(desktopPath);
47 if (possibleDesktopFile.exists()) {
48 desktopFile = possibleDesktopFile;
53 throw new RuntimeException("Cannot autodetect user desktop directory.");
56 public static File getHomeDirectory() {
57 return new File(System.getProperty("user.home"));