]>
Commit | Line | Data |
---|---|---|
23c9e63c DD |
1 | /* |
2 | * Copyright (c) 2000, Red Hat, Inc. | |
3 | * | |
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. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by DJ Delorie <dj@cygnus.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | /* The purpose of this file is to ask the user where they want the | |
17 | root of the installation to be, and to ask whether the user prefers | |
18 | text or binary mounts. */ | |
19 | ||
8507f105 DD |
20 | static char *cvsid = "\n%%% $Id$\n"; |
21 | ||
23c9e63c DD |
22 | #include "win32.h" |
23 | #include <shlobj.h> | |
24 | #include <stdio.h> | |
25 | #include <stdlib.h> | |
26 | #include <ctype.h> | |
27 | ||
28 | #include "dialog.h" | |
29 | #include "resource.h" | |
30 | #include "state.h" | |
31 | #include "msg.h" | |
32 | #include "mount.h" | |
bf1d5889 | 33 | #include "concat.h" |
89b1a15b | 34 | #include "log.h" |
23c9e63c DD |
35 | |
36 | static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 }; | |
24e259bb | 37 | static int su[] = { IDC_ROOT_SYSTEM, IDC_ROOT_USER, 0 }; |
23c9e63c DD |
38 | |
39 | static void | |
40 | check_if_enable_next (HWND h) | |
41 | { | |
24e259bb | 42 | EnableWindow (GetDlgItem (h, IDOK), root_text && root_dir && root_scope); |
23c9e63c DD |
43 | } |
44 | ||
45 | static void | |
46 | load_dialog (HWND h) | |
47 | { | |
48 | rbset (h, rb, root_text); | |
24e259bb | 49 | rbset (h, su, root_scope); |
23c9e63c DD |
50 | eset (h, IDC_ROOT_DIR, root_dir); |
51 | check_if_enable_next (h); | |
52 | } | |
53 | ||
54 | static void | |
55 | save_dialog (HWND h) | |
56 | { | |
57 | root_text = rbget (h, rb); | |
24e259bb | 58 | root_scope = rbget (h, su); |
23c9e63c DD |
59 | root_dir = eget (h, IDC_ROOT_DIR, root_dir); |
60 | } | |
61 | ||
62 | static void | |
63 | read_mount_table () | |
64 | { | |
65 | int istext; | |
24e259bb DD |
66 | int issystem; |
67 | root_dir = find_root_mount (&istext, &issystem); | |
23c9e63c DD |
68 | if (root_dir) |
69 | { | |
70 | if (istext) | |
71 | root_text = IDC_ROOT_TEXT; | |
72 | else | |
73 | root_text = IDC_ROOT_BINARY; | |
24e259bb DD |
74 | if (issystem) |
75 | root_scope = IDC_ROOT_SYSTEM; | |
76 | else | |
77 | root_scope = IDC_ROOT_USER; | |
23c9e63c | 78 | } |
bf1d5889 DD |
79 | else |
80 | { | |
81 | char windir[_MAX_PATH]; | |
82 | GetWindowsDirectory (windir, sizeof (windir)); | |
83 | windir[2] = 0; | |
84 | root_dir = concat (windir, "\\cygwin", 0); | |
85 | root_text = IDC_ROOT_BINARY; | |
86 | root_scope = IDC_ROOT_USER; | |
87 | } | |
23c9e63c DD |
88 | } |
89 | ||
90 | static int CALLBACK | |
91 | browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data) | |
92 | { | |
93 | switch (msg) | |
94 | { | |
95 | case BFFM_INITIALIZED: | |
bf1d5889 DD |
96 | if (root_dir) |
97 | SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM)root_dir); | |
23c9e63c DD |
98 | break; |
99 | } | |
100 | return 0; | |
101 | } | |
102 | ||
103 | static void | |
104 | browse (HWND h) | |
105 | { | |
106 | BROWSEINFO bi; | |
107 | CHAR name[MAX_PATH]; | |
108 | LPITEMIDLIST pidl; | |
109 | memset (&bi, 0, sizeof (bi)); | |
110 | bi.hwndOwner = h; | |
111 | bi.pszDisplayName = name; | |
112 | bi.lpszTitle = "Select an installation root directory"; | |
113 | bi.ulFlags = BIF_RETURNONLYFSDIRS; | |
114 | bi.lpfn = browse_cb; | |
115 | pidl = SHBrowseForFolder (&bi); | |
116 | if (pidl) | |
117 | { | |
118 | if (SHGetPathFromIDList (pidl, name)) | |
119 | eset (h, IDC_ROOT_DIR, name); | |
120 | } | |
121 | } | |
122 | ||
123 | #define isslash(c) ((c) == '\\' || (c) == '/') | |
124 | ||
125 | static int | |
126 | directory_is_absolute () | |
127 | { | |
128 | if (isalpha (root_dir[0]) | |
129 | && root_dir[1] == ':' | |
130 | && (root_dir[2] == '\\' || root_dir[2] == '/')) | |
131 | return 1; | |
132 | return 0; | |
133 | } | |
134 | ||
135 | static int | |
136 | directory_is_rootdir () | |
137 | { | |
138 | char *c; | |
139 | for (c = root_dir; *c; c++) | |
1fd6d0a2 | 140 | if (isslash (c[0]) && c[1] && !isslash (c[1])) |
23c9e63c DD |
141 | return 0; |
142 | return 1; | |
143 | } | |
144 | ||
145 | static int | |
146 | directory_has_spaces () | |
147 | { | |
148 | if (strchr (root_dir, ' ')) | |
149 | return 1; | |
150 | return 0; | |
151 | } | |
152 | ||
153 | static BOOL | |
154 | dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) | |
155 | { | |
156 | switch (id) | |
157 | { | |
158 | ||
159 | case IDC_ROOT_DIR: | |
160 | case IDC_ROOT_TEXT: | |
161 | case IDC_ROOT_BINARY: | |
24e259bb DD |
162 | case IDC_ROOT_SYSTEM: |
163 | case IDC_ROOT_USER: | |
23c9e63c DD |
164 | save_dialog (h); |
165 | check_if_enable_next (h); | |
166 | break; | |
167 | ||
168 | case IDC_ROOT_BROWSE: | |
169 | browse (h); | |
170 | break; | |
171 | ||
172 | case IDOK: | |
1fd6d0a2 | 173 | save_dialog (h); |
23c9e63c DD |
174 | |
175 | if (! directory_is_absolute ()) | |
176 | { | |
177 | note (IDS_ROOT_ABSOLUTE); | |
178 | break; | |
179 | } | |
180 | ||
181 | if (directory_is_rootdir ()) | |
182 | if (IDNO == yesno (IDS_ROOT_SLASH)) | |
183 | break; | |
184 | ||
185 | if (directory_has_spaces ()) | |
186 | if (IDNO == yesno (IDS_ROOT_SPACE)) | |
187 | break; | |
188 | ||
189 | switch (source) | |
190 | { | |
191 | case IDC_SOURCE_NETINST: | |
1fd6d0a2 | 192 | NEXT (IDD_NET); |
23c9e63c DD |
193 | break; |
194 | case IDC_SOURCE_CWD: | |
1fd6d0a2 | 195 | NEXT (IDD_S_FROM_CWD); |
23c9e63c DD |
196 | break; |
197 | default: | |
1fd6d0a2 DD |
198 | msg ("source is default? %d\n", source); |
199 | NEXT (0); | |
23c9e63c DD |
200 | } |
201 | break; | |
202 | ||
203 | case IDC_BACK: | |
1fd6d0a2 DD |
204 | save_dialog (h); |
205 | NEXT (IDD_SOURCE); | |
23c9e63c DD |
206 | break; |
207 | ||
208 | case IDCANCEL: | |
1fd6d0a2 | 209 | NEXT (0); |
23c9e63c DD |
210 | break; |
211 | } | |
212 | } | |
213 | ||
214 | static BOOL CALLBACK | |
215 | dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) | |
216 | { | |
217 | switch (message) | |
218 | { | |
219 | case WM_INITDIALOG: | |
1fd6d0a2 | 220 | load_dialog (h); |
23c9e63c DD |
221 | return FALSE; |
222 | case WM_COMMAND: | |
1fd6d0a2 | 223 | return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd); |
23c9e63c DD |
224 | } |
225 | return FALSE; | |
226 | } | |
227 | ||
228 | void | |
229 | do_root (HINSTANCE h) | |
230 | { | |
231 | int rv = 0; | |
232 | if (!root_dir) | |
1fd6d0a2 | 233 | read_mount_table (); |
23c9e63c DD |
234 | rv = DialogBox (h, MAKEINTRESOURCE (IDD_ROOT), 0, dialog_proc); |
235 | if (rv == -1) | |
236 | fatal (IDS_DIALOG_FAILED); | |
89b1a15b DD |
237 | |
238 | log (0, "root: %s %s %s", root_dir, | |
239 | (root_text == IDC_ROOT_TEXT) ? "text" : "binary", | |
240 | (root_scope == IDC_ROOT_USER) ? "user" : "system"); | |
23c9e63c DD |
241 | } |
242 |