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