Lines 1-173
Link Here
|
1 |
--- setup/src/c/setup.cpp.orig 2008-04-24 16:16:49.000000000 +0400 |
|
|
2 |
+++ setup/src/c/setup.cpp 2008-05-08 16:55:40.000000000 +0400 |
3 |
@@ -25,6 +25,7 @@ |
4 |
#include <stdio.h> |
5 |
#include <unistd.h> |
6 |
#include <pwd.h> |
7 |
+#include <sys/stat.h> |
8 |
#include <sys/types.h> |
9 |
|
10 |
#endif |
11 |
@@ -33,6 +34,57 @@ |
12 |
using std::string; |
13 |
using std::vector; |
14 |
char origpath[65536]; |
15 |
+ |
16 |
+static void changeToProgramDirectory(char *argv0) { |
17 |
+ int ret = -1; /* Should it use argv[0] directly? */ |
18 |
+ char *program = argv0; |
19 |
+#ifndef _WIN32 |
20 |
+ char buf[65536]; |
21 |
+ { |
22 |
+ char linkname[128]; /* /proc/<pid>/exe */ |
23 |
+ linkname[0]='\0'; |
24 |
+ pid_t pid; |
25 |
+ |
26 |
+ /* Get our PID and build the name of the link in /proc */ |
27 |
+ pid = getpid(); |
28 |
+ |
29 |
+ sprintf(linkname, "/proc/%d/exe", pid); |
30 |
+ ret = readlink(linkname, buf, 65535); |
31 |
+ if (ret <= 0) { |
32 |
+ sprintf(linkname, "/proc/%d/file", pid); |
33 |
+ ret = readlink(linkname, buf, 65535); |
34 |
+ } |
35 |
+ if (ret <= 0) { |
36 |
+ ret = readlink(program, buf, 65535); |
37 |
+ } |
38 |
+ if (ret > 0) { |
39 |
+ buf[ret]='\0'; |
40 |
+ /* Ensure proper NUL termination */ |
41 |
+ program = buf; |
42 |
+ } |
43 |
+ } |
44 |
+#endif |
45 |
+ |
46 |
+ char *parentdir; |
47 |
+ int pathlen=strlen(program); |
48 |
+ parentdir=new char[pathlen+1]; |
49 |
+ char *c; |
50 |
+ strncpy ( parentdir, program, pathlen+1 ); |
51 |
+ c = (char*) parentdir; |
52 |
+ while (*c != '\0') /* go to end */ |
53 |
+ c++; |
54 |
+ |
55 |
+ while ((*c != '/')&&(*c != '\\')&&c>parentdir) /* back up to parent */ |
56 |
+ c--; |
57 |
+ |
58 |
+ *c = '\0'; /* cut off last part (binary name) */ |
59 |
+ if (strlen (parentdir)>0) { |
60 |
+ chdir (parentdir);/* chdir to the binary app's parent */ |
61 |
+ } |
62 |
+ delete []parentdir; |
63 |
+} |
64 |
+ |
65 |
+ |
66 |
#if defined(_WINDOWS)&&defined(_WIN32) |
67 |
typedef char FileNameCharType [65536]; |
68 |
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd) { |
69 |
@@ -44,20 +96,21 @@ |
70 |
#else |
71 |
int main(int argc, char *argv[]) { |
72 |
#endif |
73 |
-#if 1 |
74 |
-//def _WIN32 |
75 |
+ |
76 |
+ if (argc>1) { |
77 |
+ if (strcmp(argv[1], "--target")==0 && argc>2) { |
78 |
+ chdir(argv[2]); |
79 |
+ } else { |
80 |
+ fprintf(stderr,"Usage: vssetup [--target DATADIR]\n"); |
81 |
+ return 1; |
82 |
+ } |
83 |
+ } |
84 |
getcwd (origpath,65535); |
85 |
origpath[65535]=0; |
86 |
- int i; |
87 |
- for (i=strlen(argv[0]);argv[0][i]!='\\'&&argv[0][i]!='/'&&i>=0;i--) { |
88 |
- } |
89 |
- argv[0][i+1]='\0'; |
90 |
- if (i>=0) { |
91 |
- chdir(argv[0]); |
92 |
- } |
93 |
-#endif |
94 |
|
95 |
- { |
96 |
+ changeToProgramDirectory(argv[0]); |
97 |
+ |
98 |
+ { |
99 |
vector<string> data_paths; |
100 |
#ifdef DATA_DIR |
101 |
data_paths.push_back( DATA_DIR); |
102 |
@@ -69,6 +122,7 @@ |
103 |
data_paths.push_back( string(origpath)+"/data4.x"); |
104 |
data_paths.push_back( string(origpath)+"/data"); |
105 |
data_paths.push_back( string(origpath)+"/../data"); |
106 |
+ data_paths.push_back( string(origpath)+"/../Resources"); |
107 |
getcwd (origpath,65535); |
108 |
origpath[65535]=0; |
109 |
data_paths.push_back( "."); |
110 |
@@ -79,6 +133,8 @@ |
111 |
data_paths.push_back( "../../data"); |
112 |
data_paths.push_back( "../Resources"); |
113 |
data_paths.push_back( "../Resources/data"); |
114 |
+ data_paths.push_back( "../Resources/data4.x"); |
115 |
+/* |
116 |
data_paths.push_back( "/usr/share/local/vegastrike/data"); |
117 |
data_paths.push_back( "/usr/local/share/vegastrike/data"); |
118 |
data_paths.push_back( "/usr/local/vegastrike/data"); |
119 |
@@ -86,7 +142,6 @@ |
120 |
data_paths.push_back( "/usr/local/games/vegastrike/data"); |
121 |
data_paths.push_back( "/usr/games/vegastrike/data"); |
122 |
data_paths.push_back( "/opt/share/vegastrike/data"); |
123 |
- data_paths.push_back( "../Resources/data4.x"); |
124 |
data_paths.push_back( "/usr/share/local/vegastrike/data4.x"); |
125 |
data_paths.push_back( "/usr/local/share/vegastrike/data4.x"); |
126 |
data_paths.push_back( "/usr/local/vegastrike/data4.x"); |
127 |
@@ -94,7 +149,7 @@ |
128 |
data_paths.push_back( "/usr/local/games/vegastrike/data4.x"); |
129 |
data_paths.push_back( "/usr/games/vegastrike/data4.x"); |
130 |
data_paths.push_back( "/opt/share/vegastrike/data4.x"); |
131 |
- |
132 |
+*/ |
133 |
// Win32 data should be "." |
134 |
char tmppath[16384]; |
135 |
for( vector<string>::iterator vsit=data_paths.begin(); vsit!=data_paths.end(); vsit++) |
136 |
@@ -118,8 +173,8 @@ |
137 |
#ifndef _WIN32 |
138 |
struct passwd *pwent; |
139 |
pwent = getpwuid (getuid()); |
140 |
- string HOMESUBDIR=".vegastrike"; |
141 |
|
142 |
+ string HOMESUBDIR; |
143 |
FILE *version=fopen("Version.txt","r"); |
144 |
if (!version) |
145 |
version=fopen("../Version.txt","r"); |
146 |
@@ -135,13 +190,23 @@ |
147 |
if (hsd.length()) { |
148 |
HOMESUBDIR=hsd; |
149 |
//fprintf (STD_OUT,"Using %s as the home directory\n",hsd.c_str()); |
150 |
- } |
151 |
+ } |
152 |
+ } |
153 |
+ if (HOMESUBDIR.empty()) { |
154 |
+ fprintf(stderr,"Error: Failed to find Version.txt anywhere.\n"); |
155 |
+ return 1; |
156 |
} |
157 |
chdir (pwent->pw_dir); |
158 |
- chdir (HOMESUBDIR.c_str()); |
159 |
+ |
160 |
+ mkdir(HOMESUBDIR.c_str() |
161 |
+#ifndef _WIN32 |
162 |
+ , 0755 |
163 |
#endif |
164 |
-#ifdef GTK |
165 |
-#endif //GTK |
166 |
+ ); |
167 |
+ |
168 |
+#endif |
169 |
+ chdir (HOMESUBDIR.c_str()); |
170 |
+ |
171 |
Start(&argc,&argv); |
172 |
#if defined(_WINDOWS)&&defined(_WIN32) |
173 |
delete []argv0; |