]> cygwin.com Git - cygwin-apps/setup.git/blame - root.cc
2001-11-01 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
8507f105
DD
20static char *cvsid = "\n%%% $Id$\n";
21
23c9e63c
DD
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"
bf1d5889 33#include "concat.h"
89b1a15b 34#include "log.h"
23c9e63c
DD
35
36static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 };
24e259bb 37static int su[] = { IDC_ROOT_SYSTEM, IDC_ROOT_USER, 0 };
23c9e63c
DD
38
39static void
40check_if_enable_next (HWND h)
41{
85b43844 42 EnableWindow (GetDlgItem (h, IDOK), root_text && get_root_dir () && root_scope);
23c9e63c
DD
43}
44
45static void
46load_dialog (HWND h)
47{
48 rbset (h, rb, root_text);
24e259bb 49 rbset (h, su, root_scope);
85b43844 50 eset (h, IDC_ROOT_DIR, get_root_dir ());
23c9e63c
DD
51 check_if_enable_next (h);
52}
53
54static void
55save_dialog (HWND h)
56{
57 root_text = rbget (h, rb);
24e259bb 58 root_scope = rbget (h, su);
85b43844 59 set_root_dir (eget (h, IDC_ROOT_DIR, (char *) get_root_dir ()));
23c9e63c
DD
60}
61
23c9e63c
DD
62static int CALLBACK
63browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
64{
65 switch (msg)
66 {
67 case BFFM_INITIALIZED:
85b43844
CF
68 if (get_root_dir ())
69 SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) get_root_dir ());
23c9e63c
DD
70 break;
71 }
72 return 0;
73}
74
75static void
76browse (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
97static int
98directory_is_absolute ()
99{
85b43844
CF
100 const char *r = get_root_dir ();
101 if (isalpha (r[0]) && r[1] == ':' && (r[2] == '\\' || r[2] == '/'))
23c9e63c
DD
102 return 1;
103 return 0;
104}
105
106static int
107directory_is_rootdir ()
108{
85b43844
CF
109 const char *c;
110 for (c = get_root_dir (); *c; c++)
1fd6d0a2 111 if (isslash (c[0]) && c[1] && !isslash (c[1]))
23c9e63c
DD
112 return 0;
113 return 1;
114}
115
116static int
117directory_has_spaces ()
118{
85b43844 119 if (strchr (get_root_dir (), ' '))
23c9e63c
DD
120 return 1;
121 return 0;
122}
123
124static BOOL
125dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
126{
127 switch (id)
128 {
129
130 case IDC_ROOT_DIR:
131 case IDC_ROOT_TEXT:
132 case IDC_ROOT_BINARY:
24e259bb
DD
133 case IDC_ROOT_SYSTEM:
134 case IDC_ROOT_USER:
23c9e63c
DD
135 save_dialog (h);
136 check_if_enable_next (h);
137 break;
138
139 case IDC_ROOT_BROWSE:
140 browse (h);
141 break;
142
143 case IDOK:
1fd6d0a2 144 save_dialog (h);
23c9e63c
DD
145
146 if (! directory_is_absolute ())
147 {
148 note (IDS_ROOT_ABSOLUTE);
149 break;
150 }
151
152 if (directory_is_rootdir ())
153 if (IDNO == yesno (IDS_ROOT_SLASH))
154 break;
155
156 if (directory_has_spaces ())
157 if (IDNO == yesno (IDS_ROOT_SPACE))
158 break;
159
160 switch (source)
161 {
162 case IDC_SOURCE_NETINST:
1fd6d0a2 163 NEXT (IDD_NET);
23c9e63c
DD
164 break;
165 case IDC_SOURCE_CWD:
1fd6d0a2 166 NEXT (IDD_S_FROM_CWD);
23c9e63c
DD
167 break;
168 default:
1fd6d0a2
DD
169 msg ("source is default? %d\n", source);
170 NEXT (0);
23c9e63c
DD
171 }
172 break;
173
174 case IDC_BACK:
1fd6d0a2 175 save_dialog (h);
c92e1307 176 NEXT (IDD_LOCAL_DIR);
23c9e63c
DD
177 break;
178
179 case IDCANCEL:
1fd6d0a2 180 NEXT (0);
23c9e63c
DD
181 break;
182 }
183}
184
185static BOOL CALLBACK
186dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
187{
188 switch (message)
189 {
190 case WM_INITDIALOG:
1fd6d0a2 191 load_dialog (h);
23c9e63c
DD
192 return FALSE;
193 case WM_COMMAND:
1fd6d0a2 194 return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd);
23c9e63c
DD
195 }
196 return FALSE;
197}
198
199void
200do_root (HINSTANCE h)
201{
202 int rv = 0;
85b43844 203 if (!get_root_dir ())
a351e48c 204 read_mounts ();
23c9e63c
DD
205 rv = DialogBox (h, MAKEINTRESOURCE (IDD_ROOT), 0, dialog_proc);
206 if (rv == -1)
207 fatal (IDS_DIALOG_FAILED);
89b1a15b 208
85b43844 209 log (0, "root: %s %s %s", get_root_dir (),
89b1a15b
DD
210 (root_text == IDC_ROOT_TEXT) ? "text" : "binary",
211 (root_scope == IDC_ROOT_USER) ? "user" : "system");
23c9e63c
DD
212}
213
This page took 0.049763 seconds and 5 git commands to generate.