]> cygwin.com Git - cygwin-apps/setup.git/blame - root.cc
2004-12-25 Max Bowsher <maxb@ukf.net>
[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"
89b1a15b 36#include "log.h"
ab57ceaa 37#include "root.h"
23c9e63c 38
f2ff9838
RC
39#include "getopt++/StringOption.h"
40
6625e635
RC
41using namespace std;
42
9d53f045 43StringOption RootOption ("", 'R', "root", "Root installation directory", false);
f2ff9838 44
23c9e63c 45static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 };
24e259bb 46static int su[] = { IDC_ROOT_SYSTEM, IDC_ROOT_USER, 0 };
23c9e63c
DD
47
48static void
49check_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
55static void
56load_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
64static void
65save_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
72static int CALLBACK
73browse_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
85static void
86browse (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
107static int
108directory_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
119static int
120directory_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
129static int
130directory_has_spaces ()
131{
3c054baf 132 if (get_root_dir ().find(' '))
23c9e63c
DD
133 return 1;
134 return 0;
135}
136
137static BOOL
138dialog_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
159bool
160RootPage::Create ()
23c9e63c 161{
ab57ceaa 162 return PropertyPage::Create (NULL, dialog_cmd, IDD_ROOT);
23c9e63c
DD
163}
164
165void
ab57ceaa 166RootPage::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
175bool
176RootPage::wantsActivation() const
177{
178 return (source != IDC_SOURCE_DOWNLOAD);
179}
180
ab57ceaa
RC
181long
182RootPage::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
205long
206RootPage::OnBack ()
207{
208 HWND h = GetHWND ();
209
210 save_dialog (h);
ab57ceaa 211 return 0;
23c9e63c 212}
f2ff9838
RC
213
214long
215RootPage::OnUnattended ()
216{
217 return OnNext();
218}
This page took 0.096637 seconds and 5 git commands to generate.