1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 Functions for getting paths for data files
23 """
24
25 import os
26 import sys
27 import platform
28 import preferences
29 try:
30 import _winreg
31 except ImportError:
32 pass
33
35 """
36 @rtype: str
37 @return: the directory for the program's read-only data
38 Mac OS-X support is non-existant
39 """
40 if platform.system() == "Windows":
41 try:
42 key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Arctographer")
43 except WindowsError:
44 path = "."
45 else:
46 path = _winreg.QueryValueEx(key, "Path")[0]
47 return path
48 elif platform.system() == "Linux":
49 possibilities = [
50 "/usr/share/arctographer",
51 "/usr/share/games/arctographer",
52 "/usr/local/share/arctographer",
53 "/usr/local/share/games/arctographer",
54 os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir)
55 ]
56 for p in possibilities:
57 if os.path.exists(p):
58 return p
59 else:
60 raise Exception("Unsupported operating system")
61
63 """
64 Mac OS-X support is non-existant
65 @rtype: str
66 @return: the directory for storting user configuration files
67 """
68 if platform.system() == "Windows":
69 path = os.path.join(os.path.expanduser("~"), "AppData", "Local", "Artographer-0.3")
70 return path
71 elif platform.system() == "Linux":
72 path = os.path.join(os.path.expanduser("~"), ".config", "arctographer")
73 return path
74 else:
75 raise Exception("Unsupported operating system")
76
77
79 """
80 Gets the path that icons are stored in
81 """
82 return os.path.join(programDataPath(), "icons", iconName)
83
85 """
86 Gets the path for a tileset
87 """
88 if preferences.files["use_prefixes"]:
89 return os.path.join(preferences.files["data_prefix"],
90 preferences.files["tileset_prefix"],
91 os.path.basename(fileName))
92 else:
93 return fileName
94
96 """
97 Gets a path for a parallax background
98 """
99 if preferences.files["use_prefixes"]:
100 return os.path.join(preferences.files["data_prefix"],
101 preferences.files["parallax_prefix"],
102 os.path.basename(fileName))
103 else:
104 return fileName
105
106
109 self.__fileName = fileName
110
112 return (("Could not find the file \"%s\". Please check your file "
113 +"preferences and make sure that the file exists.")
114 % self.__fileName)
115