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