]> cygwin.com Git - cygwin-apps/setup.git/blame - root.cc
2002-02-19 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"
89b1a15b 36#include "log.h"
ab57ceaa 37#include "root.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{
3c054baf 45 EnableWindow (GetDlgItem (h, IDOK), root_text && get_root_dir ().size()
b24c88b3 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);
3c054baf 63 set_root_dir (egetString (h, IDC_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:
3c054baf
RC
72 if (get_root_dir ().size())
73 SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) get_root_dir ().cstr_oneuse());
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{
3c054baf
RC
104
105 const char *r = get_root_dir ().cstr();
85b43844 106 if (isalpha (r[0]) && r[1] == ':' && (r[2] == '\\' || r[2] == '/'))
3c054baf
RC
107 {
108 delete [] r;
109 return 1;
110 }
111 delete[]r;
23c9e63c
DD
112 return 0;
113}
114
115static int
116directory_is_rootdir ()
117{
3c054baf 118 char *t=get_root_dir ().cstr();
85b43844 119 const char *c;
3c054baf 120 for (c = t; *c; c++)
1fd6d0a2 121 if (isslash (c[0]) && c[1] && !isslash (c[1]))
3c054baf
RC
122 {delete[]t;
123 return 0;}
124 delete[]t;
23c9e63c
DD
125 return 1;
126}
127
128static int
129directory_has_spaces ()
130{
3c054baf 131 if (get_root_dir ().find(' '))
23c9e63c
DD
132 return 1;
133 return 0;
134}
135
136static BOOL
137dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
138{
139 switch (id)
140 {
141
142 case IDC_ROOT_DIR:
143 case IDC_ROOT_TEXT:
144 case IDC_ROOT_BINARY:
24e259bb
DD
145 case IDC_ROOT_SYSTEM:
146 case IDC_ROOT_USER:
23c9e63c
DD
147 save_dialog (h);
148 check_if_enable_next (h);
149 break;
150
151 case IDC_ROOT_BROWSE:
152 browse (h);
153 break;
23c9e63c 154 }
b24c88b3 155 return 0;
23c9e63c
DD
156}
157
ab57ceaa
RC
158bool
159RootPage::Create ()
23c9e63c 160{
ab57ceaa 161 return PropertyPage::Create (NULL, dialog_cmd, IDD_ROOT);
23c9e63c
DD
162}
163
164void
ab57ceaa 165RootPage::OnInit ()
23c9e63c 166{
3c054baf 167 if (!get_root_dir ().size())
a351e48c 168 read_mounts ();
ab57ceaa
RC
169 load_dialog (GetHWND ());
170}
171
172long
173RootPage::OnNext ()
174{
175 HWND h = GetHWND ();
176
177 save_dialog (h);
178
179 if (!directory_is_absolute ())
180 {
181 note (h, IDS_ROOT_ABSOLUTE);
182 return -1;
183 }
184 else if (directory_is_rootdir () && (IDNO == yesno (h, IDS_ROOT_SLASH)))
185 return -1;
186 else if (directory_has_spaces () && (IDNO == yesno (h, IDS_ROOT_SPACE)))
187 return -1;
188
189 NEXT (IDD_LOCAL_DIR);
89b1a15b 190
1ac649ed 191 log (LOG_PLAIN, String ("root: ") + get_root_dir () +
3c054baf
RC
192 (root_text == IDC_ROOT_TEXT ? " text" : " binary") +
193 (root_scope == IDC_ROOT_USER ? " user" : " system"));
ab57ceaa
RC
194
195 return 0;
196}
197
198long
199RootPage::OnBack ()
200{
201 HWND h = GetHWND ();
202
203 save_dialog (h);
204 NEXT (IDD_SOURCE);
205 return 0;
23c9e63c 206}
This page took 0.050028 seconds and 5 git commands to generate.