Changed license to LGPLv3 or later.
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / file / CommonPathResolver.java
1 /*
2  * Svjatoslav Commons - shared library of common functionality.
3  * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
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.
8  */
9
10 package eu.svjatoslav.commons.file;
11
12 import java.io.File;
13
14 public class CommonPathResolver {
15
16         public static File desktopFile;
17
18         static final String[] desktopNames = new String[] { "Tafelblad", "المكتب",
19                         "Masa Üstü", "Сталец", "Десктоп", "ডেস্কটপ", "Desktop",
20                         "Escriptori", "Prostředí pracovní plochy", "Penbwrdd",
21                         "Skrivebord", "Επιφάνεια εργασίας", "Escritorio", "Töölaud",
22                         "Mahaigaina", "Työpöytä", "Bureau", "Deasc", "ડૅસ્કટોપ",
23                         "डेस्कटॉप", "Radna površina", "Munkaasztal", "デスクトップ", "დესკტოპი",
24                         "데스크탑", "Darbastalis", "Дэлгэц", "Skrivebord", "Teseke", "ਵਿਹੜਾ",
25                         "Pulpit", "Ambiente de Trabalho", "Área de Trabalho",
26                         "Рабочий стол", "Pracovná plocha", "Hapësira e Punës",
27                         "Радна површ", "Radna površ", "Skrivbord", "கணிமேசை", "Мизи корӣ",
28                         "พื้นโต๊ะ", "Masaüstü", "Стільниця", "桌面", "Isiga-nyezi" };
29
30         /**
31          * This method tries to guess user desktop directory. Implementation is
32          * pretty lousy. Need to improve it some day.
33          */
34         public static File getDesktopDirectory() {
35
36                 if (desktopFile != null)
37                         return desktopFile;
38
39                 final String userHomePath = System.getProperty("user.home");
40
41                 for (final String desktopName : desktopNames) {
42
43                         final String desktopPath = userHomePath + "/" + desktopName;
44
45                         final File possibleDesktopFile = new File(desktopPath);
46                         if (possibleDesktopFile.exists()) {
47                                 desktopFile = possibleDesktopFile;
48                                 return desktopFile;
49                         }
50                 }
51
52                 throw new RuntimeException("Cannot autodetect user desktop directory.");
53         }
54
55         public static File getHomeDirectory() {
56                 return new File(System.getProperty("user.home"));
57         }
58
59 }