]>
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 | ||
9d53f045 | 43 | StringOption RootOption ("", 'R', "root", "Root installation directory", false); |
f2ff9838 | 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 | 110 | |
768d880e | 111 | const char *r = get_root_dir ().cstr_oneuse(); |
85b43844 | 112 | if (isalpha (r[0]) && r[1] == ':' && (r[2] == '\\' || r[2] == '/')) |
3c054baf | 113 | { |
3c054baf RC |
114 | return 1; |
115 | } | |
23c9e63c DD |
116 | return 0; |
117 | } | |
118 | ||
119 | static int | |
120 | directory_is_rootdir () | |
121 | { | |
768d880e MB |
122 | |
123 | for (const char *c = get_root_dir().cstr_oneuse(); *c; c++) | |
1fd6d0a2 | 124 | if (isslash (c[0]) && c[1] && !isslash (c[1])) |
768d880e | 125 | return 0; |
23c9e63c DD |
126 | return 1; |
127 | } | |
128 | ||
129 | static int | |
130 | directory_has_spaces () | |
131 | { | |
3c054baf | 132 | if (get_root_dir ().find(' ')) |
23c9e63c DD |
133 | return 1; |
134 | return 0; | |
135 | } | |
136 | ||
137 | static BOOL | |
138 | dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) | |
139 | { | |
140 | switch (id) | |
141 | { | |
142 | ||
143 | case IDC_ROOT_DIR: | |
144 | case IDC_ROOT_TEXT: | |
145 | case IDC_ROOT_BINARY: | |
24e259bb DD |
146 | case IDC_ROOT_SYSTEM: |
147 | case IDC_ROOT_USER: | |
23c9e63c DD |
148 | save_dialog (h); |
149 | check_if_enable_next (h); | |
150 | break; | |
151 | ||
152 | case IDC_ROOT_BROWSE: | |
153 | browse (h); | |
154 | break; | |
23c9e63c | 155 | } |
b24c88b3 | 156 | return 0; |
23c9e63c DD |
157 | } |
158 | ||
ab57ceaa RC |
159 | bool |
160 | RootPage::Create () | |
23c9e63c | 161 | { |
ab57ceaa | 162 | return PropertyPage::Create (NULL, dialog_cmd, IDD_ROOT); |
23c9e63c DD |
163 | } |
164 | ||
165 | void | |
ab57ceaa | 166 | RootPage::OnInit () |
23c9e63c | 167 | { |
f2ff9838 RC |
168 | if (((string)RootOption).size()) |
169 | set_root_dir((string)RootOption); | |
3c054baf | 170 | if (!get_root_dir ().size()) |
a351e48c | 171 | read_mounts (); |
ab57ceaa RC |
172 | load_dialog (GetHWND ()); |
173 | } | |
174 | ||
b28e9f01 MB |
175 | bool |
176 | RootPage::wantsActivation() const | |
177 | { | |
178 | return (source != IDC_SOURCE_DOWNLOAD); | |
179 | } | |
180 | ||
ab57ceaa RC |
181 | long |
182 | RootPage::OnNext () | |
183 | { | |
184 | HWND h = GetHWND (); | |
185 | ||
186 | save_dialog (h); | |
187 | ||
188 | if (!directory_is_absolute ()) | |
189 | { | |
190 | note (h, IDS_ROOT_ABSOLUTE); | |
191 | return -1; | |
192 | } | |
193 | else if (directory_is_rootdir () && (IDNO == yesno (h, IDS_ROOT_SLASH))) | |
194 | return -1; | |
195 | else if (directory_has_spaces () && (IDNO == yesno (h, IDS_ROOT_SPACE))) | |
196 | return -1; | |
197 | ||
1ac649ed | 198 | log (LOG_PLAIN, String ("root: ") + get_root_dir () + |
3c054baf RC |
199 | (root_text == IDC_ROOT_TEXT ? " text" : " binary") + |
200 | (root_scope == IDC_ROOT_USER ? " user" : " system")); | |
ab57ceaa RC |
201 | |
202 | return 0; | |
203 | } | |
204 | ||
205 | long | |
206 | RootPage::OnBack () | |
207 | { | |
208 | HWND h = GetHWND (); | |
209 | ||
210 | save_dialog (h); | |
ab57ceaa | 211 | return 0; |
23c9e63c | 212 | } |
f2ff9838 RC |
213 | |
214 | long | |
215 | RootPage::OnUnattended () | |
216 | { | |
217 | return OnNext(); | |
218 | } |