156
|
1 import sys
|
|
2 import os
|
|
3 import errno
|
|
4 from orpg.orpg_wx import *
|
|
5
|
|
6 if WXLOADED:
|
|
7 class tmpApp(wx.App):
|
|
8 def OnInit(self):
|
|
9 return True
|
|
10
|
|
11 #-------------------------------------------------------
|
|
12 # void load_paths( dir_struct_reference )
|
|
13 # moved structure loading from dirpath.py by Snowdog 3-8-05
|
|
14 #-------------------------------------------------------
|
|
15 def load_paths(dir_struct, root_dir):
|
|
16 dir_struct["home"] = root_dir + os.sep
|
|
17 dir_struct["core"] = dir_struct["home"] + "orpg"+ os.sep
|
|
18 dir_struct["data"] = dir_struct["home"] + "data"+ os.sep
|
|
19 dir_struct["d20"] = dir_struct["data"] + "d20" + os.sep
|
|
20 dir_struct["dnd3e"] = dir_struct["data"] + "dnd3e" + os.sep
|
|
21 dir_struct["dnd35"] = dir_struct["data"] + "dnd35" + os.sep
|
|
22 dir_struct["SWd20"] = dir_struct["data"] + "SWd20" + os.sep
|
|
23 dir_struct["icon"] = dir_struct["home"] + "images" + os.sep
|
|
24 dir_struct["template"] = dir_struct["core"] + "templates" + os.sep
|
|
25 dir_struct["plugins"] = dir_struct["home"] + "plugins" + os.sep
|
|
26 dir_struct["nodes"] = dir_struct["template"] + "nodes" + os.sep
|
|
27 dir_struct["rollers"] = dir_struct["core"] + "dieroller" + os.sep + "rollers" + os.sep
|
|
28
|
|
29 _userbase_dir = dir_struct["home"]
|
|
30 _user_dir = dir_struct["home"] + "myfiles" + os.sep
|
|
31
|
|
32 try:
|
|
33 os.makedirs(_user_dir)
|
|
34 os.makedirs(_user_dir + "runlogs" + os.sep);
|
|
35 os.makedirs(_user_dir + "logs" + os.sep);
|
|
36 os.makedirs(_user_dir + "webfiles" + os.sep);
|
|
37 except OSError, e:
|
|
38 if e.errno != errno.EEXIST: raise
|
|
39
|
|
40 dir_struct["user"] = _user_dir
|
|
41 dir_struct["logs"] = dir_struct["user"] + "logs" + os.sep
|
|
42
|
|
43 #-------------------------------------------------------
|
|
44 # int verify_home_path( directory_name )
|
|
45 # added by Snowdog 3-8-05
|
|
46 # updated with bailout code. Snowdog 7-25-05
|
|
47 #-------------------------------------------------------
|
|
48 def verify_home_path( path ):
|
|
49 """checks for key ORPG files in the openrpg tree
|
|
50 and askes for user intervention if their is a problem"""
|
|
51 try:
|
|
52 #verify that the root dir (as supplied) exists
|
|
53 if not verify_file(path): return 0
|
65
|
54
|
156
|
55 #These checks require that 'path' have a separator at the end.
|
|
56 #Check and temporarily add one if needed
|
|
57 if (path[(len(path)-len(os.sep)):] != os.sep):
|
|
58 path = path + os.sep
|
|
59 # These files should always exist at the root orpg dir
|
|
60 check_files = ["orpg","data","images"]
|
|
61 for n in range(len(check_files)):
|
|
62 if not verify_file(path + check_files[n]): return 0
|
|
63 except:
|
|
64 # an error occured while verifying the directory structure
|
|
65 # bail out with error signal
|
|
66 return 0
|
|
67
|
|
68 #all files and directories exist.
|
|
69 return 1
|
|
70
|
|
71 #-------------------------------------------------------
|
|
72 # int verify_file( absolute_path )
|
|
73 # added by Snowdog 3-8-05
|
|
74 #-------------------------------------------------------
|
|
75 def verify_file(abs_path):
|
|
76 """Returns True if file or directory exists"""
|
|
77 try:
|
|
78 os.stat(abs_path)
|
|
79 return 1
|
|
80 except OSError:
|
|
81 #this exception signifies the file or dir doesn't exist
|
|
82 return 0
|
|
83
|
|
84
|
65
|
85 #-------------------------------------------------------
|
156
|
86 # pathname get_user_help()
|
|
87 # added by Snowdog 3-8-05
|
|
88 # bug fix (SF #1242456) and updated with bailout code. Snowdog 7-25-05
|
|
89 #-------------------------------------------------------
|
|
90 ## This can be removed in the future. TaS '09
|
|
91 def get_user_located_root():
|
|
92 """Notify the user of directory problems
|
|
93 and show directory selection dialog """
|
|
94
|
|
95 if WXLOADED:
|
|
96 app = tmpApp(0)
|
|
97 app.MainLoop()
|
65
|
98
|
156
|
99 dir = None
|
|
100 try:
|
|
101 msg = "OpenRPG cannot locate critical files.\nPlease locate the /System/ directory in the following window"
|
|
102 alert= wx.MessageDialog(None,msg,"Warning",wx.OK|wx.ICON_ERROR)
|
|
103 alert.Show()
|
|
104 if alert.ShowModal() == wx.OK:
|
|
105 alert.Destroy()
|
|
106 dlg = wx.DirDialog(None, "Locate the System directory:",style=wx.DD_DEFAULT_STYLE)
|
|
107 if dlg.ShowModal() == wx.ID_OK:
|
|
108 dir = dlg.GetPath()
|
|
109 dlg.Destroy()
|
|
110 app.Destroy()
|
|
111 return dir
|
|
112 except Exception, e:
|
|
113 print e
|
|
114 print "OpenRPG encountered a problem while attempting to load file dialog to locate the OpenRPG root directory."
|
|
115 print "please delete the files ./openrpg/orpg/dirpath/aproot.py and ./openrpg/orpg/dirpath/aproot.pyc and try again."
|
|
116 else:
|
|
117 dir = raw_input("Enter the full path to your openrpg folder: ")
|
|
118 return dir
|
14
|
119
|