]>
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" | |
bf1d5889 | 36 | #include "concat.h" |
89b1a15b | 37 | #include "log.h" |
ab57ceaa | 38 | #include "root.h" |
23c9e63c DD |
39 | |
40 | static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 }; | |
24e259bb | 41 | static int su[] = { IDC_ROOT_SYSTEM, IDC_ROOT_USER, 0 }; |
23c9e63c DD |
42 | |
43 | static void | |
44 | check_if_enable_next (HWND h) | |
45 | { | |
b24c88b3 RC |
46 | EnableWindow (GetDlgItem (h, IDOK), root_text && get_root_dir () |
47 | && root_scope); | |
23c9e63c DD |
48 | } |
49 | ||
50 | static void | |
51 | load_dialog (HWND h) | |
52 | { | |
53 | rbset (h, rb, root_text); | |
24e259bb | 54 | rbset (h, su, root_scope); |
85b43844 | 55 | eset (h, IDC_ROOT_DIR, get_root_dir ()); |
23c9e63c DD |
56 | check_if_enable_next (h); |
57 | } | |
58 | ||
59 | static void | |
60 | save_dialog (HWND h) | |
61 | { | |
62 | root_text = rbget (h, rb); | |
24e259bb | 63 | root_scope = rbget (h, su); |
85b43844 | 64 | set_root_dir (eget (h, IDC_ROOT_DIR, (char *) get_root_dir ())); |
23c9e63c DD |
65 | } |
66 | ||
23c9e63c DD |
67 | static int CALLBACK |
68 | browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data) | |
69 | { | |
70 | switch (msg) | |
71 | { | |
72 | case BFFM_INITIALIZED: | |
85b43844 CF |
73 | if (get_root_dir ()) |
74 | SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) get_root_dir ()); | |
23c9e63c DD |
75 | break; |
76 | } | |
77 | return 0; | |
78 | } | |
79 | ||
80 | static void | |
81 | browse (HWND h) | |
82 | { | |
83 | BROWSEINFO bi; | |
84 | CHAR name[MAX_PATH]; | |
85 | LPITEMIDLIST pidl; | |
86 | memset (&bi, 0, sizeof (bi)); | |
87 | bi.hwndOwner = h; | |
88 | bi.pszDisplayName = name; | |
89 | bi.lpszTitle = "Select an installation root directory"; | |
90 | bi.ulFlags = BIF_RETURNONLYFSDIRS; | |
91 | bi.lpfn = browse_cb; | |
92 | pidl = SHBrowseForFolder (&bi); | |
93 | if (pidl) | |
94 | { | |
95 | if (SHGetPathFromIDList (pidl, name)) | |
96 | eset (h, IDC_ROOT_DIR, name); | |
97 | } | |
98 | } | |
99 | ||
100 | #define isslash(c) ((c) == '\\' || (c) == '/') | |
101 | ||
102 | static int | |
103 | directory_is_absolute () | |
104 | { | |
85b43844 CF |
105 | const char *r = get_root_dir (); |
106 | if (isalpha (r[0]) && r[1] == ':' && (r[2] == '\\' || r[2] == '/')) | |
23c9e63c DD |
107 | return 1; |
108 | return 0; | |
109 | } | |
110 | ||
111 | static int | |
112 | directory_is_rootdir () | |
113 | { | |
85b43844 CF |
114 | const char *c; |
115 | for (c = get_root_dir (); *c; c++) | |
1fd6d0a2 | 116 | if (isslash (c[0]) && c[1] && !isslash (c[1])) |
23c9e63c DD |
117 | return 0; |
118 | return 1; | |
119 | } | |
120 | ||
121 | static int | |
122 | directory_has_spaces () | |
123 | { | |
85b43844 | 124 | if (strchr (get_root_dir (), ' ')) |
23c9e63c DD |
125 | return 1; |
126 | return 0; | |
127 | } | |
128 | ||
129 | static BOOL | |
130 | dialog_cmd (HWND h, int id, HWND hwndctl, UINT code) | |
131 | { | |
132 | switch (id) | |
133 | { | |
134 | ||
135 | case IDC_ROOT_DIR: | |
136 | case IDC_ROOT_TEXT: | |
137 | case IDC_ROOT_BINARY: | |
24e259bb DD |
138 | case IDC_ROOT_SYSTEM: |
139 | case IDC_ROOT_USER: | |
23c9e63c DD |
140 | save_dialog (h); |
141 | check_if_enable_next (h); | |
142 | break; | |
143 | ||
144 | case IDC_ROOT_BROWSE: | |
145 | browse (h); | |
146 | break; | |
23c9e63c | 147 | } |
b24c88b3 | 148 | return 0; |
23c9e63c DD |
149 | } |
150 | ||
ab57ceaa RC |
151 | bool |
152 | RootPage::Create () | |
23c9e63c | 153 | { |
ab57ceaa | 154 | return PropertyPage::Create (NULL, dialog_cmd, IDD_ROOT); |
23c9e63c DD |
155 | } |
156 | ||
157 | void | |
ab57ceaa | 158 | RootPage::OnInit () |
23c9e63c | 159 | { |
85b43844 | 160 | if (!get_root_dir ()) |
a351e48c | 161 | read_mounts (); |
ab57ceaa RC |
162 | load_dialog (GetHWND ()); |
163 | } | |
164 | ||
165 | long | |
166 | RootPage::OnNext () | |
167 | { | |
168 | HWND h = GetHWND (); | |
169 | ||
170 | save_dialog (h); | |
171 | ||
172 | if (!directory_is_absolute ()) | |
173 | { | |
174 | note (h, IDS_ROOT_ABSOLUTE); | |
175 | return -1; | |
176 | } | |
177 | else if (directory_is_rootdir () && (IDNO == yesno (h, IDS_ROOT_SLASH))) | |
178 | return -1; | |
179 | else if (directory_has_spaces () && (IDNO == yesno (h, IDS_ROOT_SPACE))) | |
180 | return -1; | |
181 | ||
182 | NEXT (IDD_LOCAL_DIR); | |
89b1a15b | 183 | |
85b43844 | 184 | log (0, "root: %s %s %s", get_root_dir (), |
89b1a15b DD |
185 | (root_text == IDC_ROOT_TEXT) ? "text" : "binary", |
186 | (root_scope == IDC_ROOT_USER) ? "user" : "system"); | |
ab57ceaa RC |
187 | |
188 | return 0; | |
189 | } | |
190 | ||
191 | long | |
192 | RootPage::OnBack () | |
193 | { | |
194 | HWND h = GetHWND (); | |
195 | ||
196 | save_dialog (h); | |
197 | NEXT (IDD_SOURCE); | |
198 | return 0; | |
23c9e63c | 199 | } |