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