]>
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 | ||
b24c88b3 RC |
20 | #if 0 |
21 | static const char *cvsid = | |
22 | "\n%%% $Id$\n"; | |
23 | #endif | |
8507f105 | 24 | |
23c9e63c DD |
25 | #include "win32.h" |
26 | #include <shlobj.h> | |
27 | #include <stdio.h> | |
28 | #include <stdlib.h> | |
29 | #include <ctype.h> | |
30 | ||
31 | #include "dialog.h" | |
32 | #include "resource.h" | |
33 | #include "state.h" | |
34 | #include "msg.h" | |
35 | #include "mount.h" | |
89b1a15b | 36 | #include "log.h" |
ab57ceaa | 37 | #include "root.h" |
23c9e63c | 38 | |
f2ff9838 RC |
39 | #include "getopt++/StringOption.h" |
40 | ||
6625e635 RC |
41 | using namespace std; |
42 | ||
f2ff9838 RC |
43 | StringOption RootOption ("", 'R', "root", "Root installation directory"); |
44 | ||
23c9e63c | 45 | static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 }; |
24e259bb | 46 | static int su[] = { IDC_ROOT_SYSTEM, IDC_ROOT_USER, 0 }; |
23c9e63c DD |
47 | |
48 | static void | |
49 | check_if_enable_next (HWND h) | |
50 | { | |
3c054baf | 51 | EnableWindow (GetDlgItem (h, IDOK), root_text && get_root_dir ().size() |
b24c88b3 | 52 | && root_scope); |
23c9e63c DD |
53 | } |
54 | ||
55 | static void | |
56 | load_dialog (HWND h) | |
57 | { | |
58 | rbset (h, rb, root_text); | |
24e259bb | 59 | rbset (h, su, root_scope); |
85b43844 | 60 | eset (h, IDC_ROOT_DIR, get_root_dir ()); |
23c9e63c DD |
61 | check_if_enable_next (h); |
62 | } | |
63 | ||
64 | static void | |
65 | save_dialog (HWND h) | |
66 | { | |
67 | root_text = rbget (h, rb); | |
24e259bb | 68 | root_scope = rbget (h, su); |
3c054baf | 69 | set_root_dir (egetString (h, IDC_ROOT_DIR)); |
23c9e63c DD |
70 | } |
71 | ||
23c9e63c DD |
72 | static int CALLBACK |
73 | browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data) | |
74 | { | |
75 | switch (msg) | |
76 | { | |
77 | case BFFM_INITIALIZED: | |
3c054baf RC |
78 | if (get_root_dir ().size()) |
79 | SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) get_root_dir ().cstr_oneuse()); | |
23c9e63c DD |
80 | break; |
81 | } | |
82 | return 0; | |
83 | } | |
84 | ||
85 | static void | |
86 | browse (HWND h) | |
87 | { | |
88 | BROWSEINFO bi; | |
89 | CHAR name[MAX_PATH]; | |
90 | LPITEMIDLIST pidl; | |
91 | memset (&bi, 0, sizeof (bi)); | |
92 | bi.hwndOwner = h; | |
93 | bi.pszDisplayName = name; | |
94 | bi.lpszTitle = "Select an installation root directory"; | |
95 | bi.ulFlags = BIF_RETURNONLYFSDIRS; | |
96 | bi.lpfn = browse_cb; | |
97 | pidl = SHBrowseForFolder (&bi); | |
98 | if (pidl) | |
99 | { | |
100 | if (SHGetPathFromIDList (pidl, name)) | |
101 | eset (h, IDC_ROOT_DIR, name); | |
102 | } | |
103 | } | |
104 | ||
105 | #define isslash(c) ((c) == '\\' || (c) == '/') | |
106 | ||
107 | static int | |
108 | directory_is_absolute () | |
109 | { | |
3c054baf RC |
110 | |
111 | const char *r = get_root_dir ().cstr(); | |
85b43844 | 112 | if (isalpha (r[0]) && r[1] == ':' && (r[2] == '\\' || r[2] == '/')) |
3c054baf RC |
113 | { |
114 | delete [] r; | |
115 | return 1; | |
116 | } | |
117 | delete[]r; | |
23c9e63c DD |
118 | return 0; |
119 | } | |
120 | ||
121 | static int | |
122 | directory_is_rootdir () | |
123 | { | |
3c054baf | 124 | char *t=get_root_dir ().cstr(); |
85b43844 | 125 | const char *c; |
3c054baf | 126 | for (c = t; *c; c++) |
1fd6d0a2 | 127 | if (isslash (c[0]) && c[1] && !isslash (c[1])) |
3c054baf RC |
128 | {delete[]t; |
129 | return 0;} | |
130 | delete[]t; | |
23c9e63c DD |
131 | return 1; |
132 | } | |
133 | ||
134 | static int | |
135 | directory_has_spaces () | |
136 | { | |
3c054baf | 137 | if (get_root_dir ().find(' ')) |
23c9e63c DD |
138 | return 1; |
139 | return 0; | |
140 | } | |
141 | ||
142 | static BOOL | |
143 | dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) | |
144 | { | |
145 | switch (id) | |
146 | { | |
147 | ||
148 | case IDC_ROOT_DIR: | |
149 | case IDC_ROOT_TEXT: | |
150 | case IDC_ROOT_BINARY: | |
24e259bb DD |
151 | case IDC_ROOT_SYSTEM: |
152 | case IDC_ROOT_USER: | |
23c9e63c DD |
153 | save_dialog (h); |
154 | check_if_enable_next (h); | |
155 | break; | |
156 | ||
157 | case IDC_ROOT_BROWSE: | |
158 | browse (h); | |
159 | break; | |
23c9e63c | 160 | } |
b24c88b3 | 161 | return 0; |
23c9e63c DD |
162 | } |
163 | ||
ab57ceaa RC |
164 | bool |
165 | RootPage::Create () | |
23c9e63c | 166 | { |
ab57ceaa | 167 | return PropertyPage::Create (NULL, dialog_cmd, IDD_ROOT); |
23c9e63c DD |
168 | } |
169 | ||
170 | void | |
ab57ceaa | 171 | RootPage::OnInit () |
23c9e63c | 172 | { |
f2ff9838 RC |
173 | if (((string)RootOption).size()) |
174 | set_root_dir((string)RootOption); | |
3c054baf | 175 | if (!get_root_dir ().size()) |
a351e48c | 176 | read_mounts (); |
ab57ceaa RC |
177 | load_dialog (GetHWND ()); |
178 | } | |
179 | ||
180 | long | |
181 | RootPage::OnNext () | |
182 | { | |
183 | HWND h = GetHWND (); | |
184 | ||
185 | save_dialog (h); | |
186 | ||
187 | if (!directory_is_absolute ()) | |
188 | { | |
189 | note (h, IDS_ROOT_ABSOLUTE); | |
190 | return -1; | |
191 | } | |
192 | else if (directory_is_rootdir () && (IDNO == yesno (h, IDS_ROOT_SLASH))) | |
193 | return -1; | |
194 | else if (directory_has_spaces () && (IDNO == yesno (h, IDS_ROOT_SPACE))) | |
195 | return -1; | |
196 | ||
197 | NEXT (IDD_LOCAL_DIR); | |
89b1a15b | 198 | |
1ac649ed | 199 | log (LOG_PLAIN, String ("root: ") + get_root_dir () + |
3c054baf RC |
200 | (root_text == IDC_ROOT_TEXT ? " text" : " binary") + |
201 | (root_scope == IDC_ROOT_USER ? " user" : " system")); | |
ab57ceaa RC |
202 | |
203 | return 0; | |
204 | } | |
205 | ||
206 | long | |
207 | RootPage::OnBack () | |
208 | { | |
209 | HWND h = GetHWND (); | |
210 | ||
211 | save_dialog (h); | |
212 | NEXT (IDD_SOURCE); | |
213 | return 0; | |
23c9e63c | 214 | } |
f2ff9838 RC |
215 | |
216 | long | |
217 | RootPage::OnUnattended () | |
218 | { | |
219 | return OnNext(); | |
220 | } |