2 # -*- coding: utf-8 -*-
4 #Copyright 2011 Gimick bbtgaf@googlemail.com
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
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 Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
19 Attempt to detect which poker sites are installed by the user, their
20 heroname and the path to the HH files.
22 This is intended for new fpdb users to get them up and running quickly.
24 We assume that the majority of these users will install the poker client
25 into default locations so we will only check those places.
27 We just look for a hero HH folder, and don't really care if the
28 application is installed
30 Situations not handled are:
31 Multiple screennames using the computer
32 TODO Unexpected dirs in HH dir (e.g. "archive" may become a heroname!)
33 Non-standard installation locations
34 TODO Mac installations
37 See TestDetectInstalledSites.py
40 replace hardcoded site list with something more subtle
47 Config
=Configuration
.Config()
49 if Config
.os_family
in ['Win7', 'XP']:
51 PROGRAM_FILES
= winpaths
.get_program_files()
52 LOCAL_APPDATA
= winpaths
.get_local_appdata()
54 class DetectInstalledSites():
56 def __init__(self
, sitename
= "All"):
60 self
.sitestatusdict
= {}
61 self
.sitename
= sitename
66 #since each site has to be hand-coded in this module, there
67 #is little advantage in querying the sites table at the moment.
68 #plus we can run from the command line as no dependencies
70 self
.supportedSites
= [ "Full Tilt Poker",
87 self
.supportedPlatforms
= ["Linux", "XP", "Win7"]
90 for siteiter
in self
.supportedSites
:
91 self
.sitestatusdict
[siteiter
]=self
.detect(siteiter
)
93 self
.sitestatusdict
[sitename
]=self
.detect(sitename
)
94 self
.heroname
= self
.sitestatusdict
[sitename
]['heroname']
95 self
.hhpath
= self
.sitestatusdict
[sitename
]['hhpath']
96 self
.detected
= self
.sitestatusdict
[sitename
]['detected']
100 def detect(self
, siteToDetect
):
105 if siteToDetect
== "Full Tilt Poker":
106 self
.detectFullTilt()
107 elif siteToDetect
== "PartyPoker":
108 self
.detectPartyPoker()
109 elif siteToDetect
== "PokerStars":
110 self
.detectPokerStars()
111 elif siteToDetect
== "Carbon":
112 self
.detectCarbonMergeNetwork()
114 if (self
.pathfound
and self
.herofound
):
115 self
.pathfound
= unicode(self
.pathfound
)
116 self
.herofound
= unicode(self
.herofound
)
117 return {"detected":True, "hhpath":self
.pathfound
, "heroname":self
.herofound
}
119 return {"detected":False, "hhpath":"", "heroname":""}
121 def detectFullTilt(self
):
123 if Config
.os_family
== "Linux":
124 hhp
=os
.path
.expanduser("~/.wine/drive_c/Program Files/Full Tilt Poker/HandHistory/")
125 elif Config
.os_family
== "XP":
126 hhp
=os
.path
.expanduser(PROGRAM_FILES
+"\\Full Tilt Poker\\HandHistory\\")
127 elif Config
.os_family
== "Win7":
128 hhp
=os
.path
.expanduser(PROGRAM_FILES
+"\\Full Tilt Poker\\HandHistory\\")
132 if os
.path
.exists(hhp
):
138 self
.herofound
= os
.listdir(self
.pathfound
)[0]
139 self
.pathfound
= self
.pathfound
+ self
.herofound
145 def detectPokerStars(self
):
147 if Config
.os_family
== "Linux":
148 hhp
=os
.path
.expanduser("~/.wine/drive_c/Program Files/PokerStars/HandHistory/")
149 elif Config
.os_family
== "XP":
150 hhp
=os
.path
.expanduser(PROGRAM_FILES
+"\\PokerStars\\HandHistory\\")
151 elif Config
.os_family
== "Win7":
152 hhp
=os
.path
.expanduser(LOCAL_APPDATA
+"\\PokerStars\\HandHistory\\")
156 if os
.path
.exists(hhp
):
162 self
.herofound
= os
.listdir(self
.pathfound
)[0]
163 self
.pathfound
= self
.pathfound
+ self
.herofound
169 def detectPartyPoker(self
):
171 if Config
.os_family
== "Linux":
172 hhp
=os
.path
.expanduser("~/.wine/drive_c/Program Files/PartyGaming/PartyPoker/HandHistory/")
173 elif Config
.os_family
== "XP":
174 hhp
=os
.path
.expanduser(PROGRAM_FILES
+"\\PartyGaming\\PartyPoker\\HandHistory\\")
175 elif Config
.os_family
== "Win7":
176 hhp
=os
.path
.expanduser("c:\\Programs\\PartyGaming\\PartyPoker\\HandHistory\\")
180 if os
.path
.exists(hhp
):
185 dirs
= os
.listdir(self
.pathfound
)
186 if "XMLHandHistory" in dirs
:
187 dirs
.remove("XMLHandHistory")
190 self
.herofound
= dirs
[0]
191 self
.pathfound
= self
.pathfound
+ self
.herofound
197 def detectCarbonMergeNetwork(self
):
199 # Carbon is the principal room on the Merge network but there are many other skins.
200 # FPDB slightly confusingly uses the "Carbon" identifier for sites on the merge network
202 # Normally, we understand that a player can only be valid at one
203 # room on the Merge network so we will exit once successful
205 # Many thanks to Ilithios for the PlayersOnly information
207 merge_skin_names
= ["CarbonPoker", "PlayersOnly"]
209 for skin
in merge_skin_names
:
210 if Config
.os_family
== "Linux":
211 hhp
=os
.path
.expanduser("~/.wine/drive_c/Program Files/"+skin
+"/history/")
212 elif Config
.os_family
== "XP":
213 hhp
=os
.path
.expanduser(PROGRAM_FILES
+"\\"+skin
+"\\history\\")
214 elif Config
.os_family
== "Win7":
215 hhp
=os
.path
.expanduser(PROGRAM_FILES
+"\\"+skin
+"\\history\\")
219 if os
.path
.exists(hhp
):
222 self
.herofound
= os
.listdir(self
.pathfound
)[0]
223 self
.pathfound
= self
.pathfound
+ self
.herofound