1
# Miro - an RSS based video player application
2
# Copyright (C) 2005-2010 Participatory Culture Foundation
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# In addition, as a special exception, the copyright holders give
19
# permission to link the code of portions of this program with the OpenSSL
22
# You must obey the GNU General Public License in all respects for all of
23
# the code used other than OpenSSL. If you modify file(s) with this
24
# exception, you may extend this exception to your version of the file(s),
25
# but you are not obligated to do so. If you do not wish to do so, delete
26
# this exception statement from your version. If you delete this exception
27
# statement from all source files in the program, then also delete it here.
39
from miro import prefs
41
from miro import u3info
42
from miro import fileutil
43
from miro.plat import proxyfind
44
from miro.plat import resources
45
from miro.plat import specialfolders
47
proxy_info = proxyfind.get_proxy_info()
49
def _getSupportDirectory():
51
path = u3info.APP_DATA_PREFIX
53
# We don't get the publisher and long app name from the config so
54
# changing the app name doesn't change the support directory
55
path = os.path.join(specialfolders.appDataDirectory,
56
u'Participatory Culture Foundation',
61
fileutil.makedirs(path)
67
return fileutil.expand_filename(os.path.join(_getSupportDirectory(), "preferences.bin"))
70
save_file = _getConfigFile()
72
# if Miro died while saving the config file, then it's likely there's
73
# a save_file.new floating around and that's the one we want to use.
74
new_save_file = save_file + ".new"
75
if os.path.exists(new_save_file):
76
save_file = new_save_file
78
if os.path.exists(save_file):
80
return cPickle.load(open(save_file))
82
logging.warn("Error loading config: %s", traceback.format_exc())
86
# save to a new file and if that's successful then rename it. this
87
# reduces the chance that the user ends up with a hosed preferences
89
save_file = _getConfigFile()
90
new_file = save_file + ".new"
92
f = open(new_file, 'w')
96
if not os.path.exists(save_file):
97
shutil.move(new_file, save_file)
101
shutil.move(new_file, save_file)
106
if descriptor == prefs.MOVIES_DIRECTORY:
107
return os.path.join(specialfolders.baseMoviesDirectory, app.configfile['shortAppName'])
109
elif descriptor == prefs.NON_VIDEO_DIRECTORY:
110
return specialfolders.nonVideoDirectory
112
elif descriptor == prefs.GETTEXT_PATHNAME:
113
return resources.path("locale")
115
elif descriptor == prefs.SUPPORT_DIRECTORY:
116
return fileutil.expand_filename(_getSupportDirectory())
118
elif descriptor == prefs.ICON_CACHE_DIRECTORY:
119
return os.path.join(_getSupportDirectory(), 'icon-cache')
121
elif descriptor == prefs.DB_PATHNAME:
122
path = get(prefs.SUPPORT_DIRECTORY)
123
return os.path.join(path, 'tvdump')
125
elif descriptor == prefs.BSDDB_PATHNAME:
126
path = get(prefs.SUPPORT_DIRECTORY)
127
return os.path.join(path, 'database')
129
elif descriptor == prefs.SQLITE_PATHNAME:
130
path = get(prefs.SUPPORT_DIRECTORY)
131
return os.path.join(path, 'sqlitedb')
133
elif descriptor == prefs.LOG_PATHNAME:
135
directory = u3info.app_data_path
137
directory = tempfile.gettempdir()
138
return os.path.join(directory,
139
('%s.log' % app.configfile['shortAppName']))
141
elif descriptor == prefs.DOWNLOADER_LOG_PATHNAME:
143
directory = u3info.app_data_path
145
directory = tempfile.gettempdir()
146
return os.path.join(directory,
147
('%s-downloader.log' % app.configfile['shortAppName']))
149
elif descriptor == prefs.RUN_AT_STARTUP:
151
# We use the legacy startup registry key, so legacy versions
152
# of Windows have a chance
153
# http://support.microsoft.com/?kbid=270035
156
folder = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
157
"Software\Microsoft\Windows\CurrentVersion\Run")
158
except WindowsError, e:
159
# 2 indicates that the key doesn't exist yet, so
160
# RUN_AT_STARTUP is clearly False
162
logging.exception("=== windowserror kicked up at open key ===")
165
long_app_name = app.configfile['longAppName']
169
name, val, type_ = _winreg.EnumValue(folder, count)
171
if name == long_app_name:
173
except WindowsError, e:
174
# 22 indicates there are no more items in this folder to
182
elif descriptor == prefs.HTTP_PROXY_ACTIVE:
183
return proxy_info.host is not None
184
elif descriptor == prefs.HTTP_PROXY_HOST:
185
return proxy_info.host
186
elif descriptor == prefs.HTTP_PROXY_PORT:
187
return proxy_info.port
188
elif descriptor == prefs.HTTP_PROXY_IGNORE_HOSTS:
189
return poxy_info.ignore_hosts
190
# Proxy authorization isn't suppored on windows, so the following keps are
193
# HTTP_PROXY_AUTHORIZATION_ACTIVE
194
# HTTP_PROXY_AUTHORIZATION_USERNAME
195
# HTTP_PROXY_AUTHORIZATION_PASSWORD
197
return descriptor.default