]>
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 | ||
20 | #include "win32.h" | |
21 | #include <shlobj.h> | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | #include <ctype.h> | |
25 | ||
26 | #include "dialog.h" | |
27 | #include "resource.h" | |
28 | #include "state.h" | |
29 | #include "msg.h" | |
30 | #include "mount.h" | |
31 | ||
32 | static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 }; | |
33 | ||
34 | static void | |
35 | check_if_enable_next (HWND h) | |
36 | { | |
37 | EnableWindow (GetDlgItem (h, IDOK), root_text && root_dir); | |
38 | } | |
39 | ||
40 | static void | |
41 | load_dialog (HWND h) | |
42 | { | |
43 | rbset (h, rb, root_text); | |
44 | eset (h, IDC_ROOT_DIR, root_dir); | |
45 | check_if_enable_next (h); | |
46 | } | |
47 | ||
48 | static void | |
49 | save_dialog (HWND h) | |
50 | { | |
51 | root_text = rbget (h, rb); | |
52 | root_dir = eget (h, IDC_ROOT_DIR, root_dir); | |
53 | } | |
54 | ||
55 | static void | |
56 | read_mount_table () | |
57 | { | |
58 | int istext; | |
59 | root_dir = find_root_mount (&istext); | |
60 | if (root_dir) | |
61 | { | |
62 | if (istext) | |
63 | root_text = IDC_ROOT_TEXT; | |
64 | else | |
65 | root_text = IDC_ROOT_BINARY; | |
66 | } | |
67 | } | |
68 | ||
69 | static int CALLBACK | |
70 | browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data) | |
71 | { | |
72 | switch (msg) | |
73 | { | |
74 | case BFFM_INITIALIZED: | |
75 | SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM)root_dir); | |
76 | break; | |
77 | } | |
78 | return 0; | |
79 | } | |
80 | ||
81 | static void | |
82 | browse (HWND h) | |
83 | { | |
84 | BROWSEINFO bi; | |
85 | CHAR name[MAX_PATH]; | |
86 | LPITEMIDLIST pidl; | |
87 | memset (&bi, 0, sizeof (bi)); | |
88 | bi.hwndOwner = h; | |
89 | bi.pszDisplayName = name; | |
90 | bi.lpszTitle = "Select an installation root directory"; | |
91 | bi.ulFlags = BIF_RETURNONLYFSDIRS; | |
92 | bi.lpfn = browse_cb; | |
93 | pidl = SHBrowseForFolder (&bi); | |
94 | if (pidl) | |
95 | { | |
96 | if (SHGetPathFromIDList (pidl, name)) | |
97 | eset (h, IDC_ROOT_DIR, name); | |
98 | } | |
99 | } | |
100 | ||
101 | #define isslash(c) ((c) == '\\' || (c) == '/') | |
102 | ||
103 | static int | |
104 | directory_is_absolute () | |
105 | { | |
106 | if (isalpha (root_dir[0]) | |
107 | && root_dir[1] == ':' | |
108 | && (root_dir[2] == '\\' || root_dir[2] == '/')) | |
109 | return 1; | |
110 | return 0; | |
111 | } | |
112 | ||
113 | static int | |
114 | directory_is_rootdir () | |
115 | { | |
116 | char *c; | |
117 | for (c = root_dir; *c; c++) | |
118 | if (isslash(c[0]) && c[1] && !isslash(c[1])) | |
119 | return 0; | |
120 | return 1; | |
121 | } | |
122 | ||
123 | static int | |
124 | directory_has_spaces () | |
125 | { | |
126 | if (strchr (root_dir, ' ')) | |
127 | return 1; | |
128 | return 0; | |
129 | } | |
130 | ||
131 | static BOOL | |
132 | dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) | |
133 | { | |
134 | switch (id) | |
135 | { | |
136 | ||
137 | case IDC_ROOT_DIR: | |
138 | case IDC_ROOT_TEXT: | |
139 | case IDC_ROOT_BINARY: | |
140 | save_dialog (h); | |
141 | check_if_enable_next (h); | |
142 | break; | |
143 | ||
144 | case IDC_ROOT_BROWSE: | |
145 | browse (h); | |
146 | break; | |
147 | ||
148 | case IDOK: | |
149 | save_dialog(h); | |
150 | ||
151 | if (! directory_is_absolute ()) | |
152 | { | |
153 | note (IDS_ROOT_ABSOLUTE); | |
154 | break; | |
155 | } | |
156 | ||
157 | if (directory_is_rootdir ()) | |
158 | if (IDNO == yesno (IDS_ROOT_SLASH)) | |
159 | break; | |
160 | ||
161 | if (directory_has_spaces ()) | |
162 | if (IDNO == yesno (IDS_ROOT_SPACE)) | |
163 | break; | |
164 | ||
165 | switch (source) | |
166 | { | |
167 | case IDC_SOURCE_NETINST: | |
168 | NEXT(IDD_NET); | |
169 | break; | |
170 | case IDC_SOURCE_CWD: | |
171 | NEXT(IDD_S_FROM_CWD); | |
172 | break; | |
173 | default: | |
174 | msg("source is default? %d\n", source); | |
175 | NEXT(0); | |
176 | } | |
177 | break; | |
178 | ||
179 | case IDC_BACK: | |
180 | save_dialog(h); | |
181 | NEXT(IDD_SOURCE); | |
182 | break; | |
183 | ||
184 | case IDCANCEL: | |
185 | NEXT(0); | |
186 | break; | |
187 | } | |
188 | } | |
189 | ||
190 | static BOOL CALLBACK | |
191 | dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) | |
192 | { | |
193 | switch (message) | |
194 | { | |
195 | case WM_INITDIALOG: | |
196 | load_dialog(h); | |
197 | return FALSE; | |
198 | case WM_COMMAND: | |
199 | return HANDLE_WM_COMMAND(h, wParam, lParam, dialog_cmd); | |
200 | } | |
201 | return FALSE; | |
202 | } | |
203 | ||
204 | void | |
205 | do_root (HINSTANCE h) | |
206 | { | |
207 | int rv = 0; | |
208 | if (!root_dir) | |
209 | read_mount_table(); | |
210 | rv = DialogBox (h, MAKEINTRESOURCE (IDD_ROOT), 0, dialog_proc); | |
211 | if (rv == -1) | |
212 | fatal (IDS_DIALOG_FAILED); | |
213 | } | |
214 |