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