]> cygwin.com Git - cygwin-apps/setup.git/blob - root.cc
2004-12-25 Max Bowsher <maxb@ukf.net>
[cygwin-apps/setup.git] / root.cc
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
20 #if 0
21 static const char *cvsid =
22 "\n%%% $Id$\n";
23 #endif
24
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"
36 #include "log.h"
37 #include "root.h"
38
39 #include "getopt++/StringOption.h"
40
41 using namespace std;
42
43 StringOption RootOption ("", 'R', "root", "Root installation directory", false);
44
45 static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 };
46 static int su[] = { IDC_ROOT_SYSTEM, IDC_ROOT_USER, 0 };
47
48 static void
49 check_if_enable_next (HWND h)
50 {
51 EnableWindow (GetDlgItem (h, IDOK), root_text && get_root_dir ().size()
52 && root_scope);
53 }
54
55 static void
56 load_dialog (HWND h)
57 {
58 rbset (h, rb, root_text);
59 rbset (h, su, root_scope);
60 eset (h, IDC_ROOT_DIR, get_root_dir ());
61 check_if_enable_next (h);
62 }
63
64 static void
65 save_dialog (HWND h)
66 {
67 root_text = rbget (h, rb);
68 root_scope = rbget (h, su);
69 set_root_dir (egetString (h, IDC_ROOT_DIR));
70 }
71
72 static int CALLBACK
73 browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
74 {
75 switch (msg)
76 {
77 case BFFM_INITIALIZED:
78 if (get_root_dir ().size())
79 SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) get_root_dir ().cstr_oneuse());
80 break;
81 }
82 return 0;
83 }
84
85 static void
86 browse (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
107 static int
108 directory_is_absolute ()
109 {
110
111 const char *r = get_root_dir ().cstr_oneuse();
112 if (isalpha (r[0]) && r[1] == ':' && (r[2] == '\\' || r[2] == '/'))
113 {
114 return 1;
115 }
116 return 0;
117 }
118
119 static int
120 directory_is_rootdir ()
121 {
122
123 for (const char *c = get_root_dir().cstr_oneuse(); *c; c++)
124 if (isslash (c[0]) && c[1] && !isslash (c[1]))
125 return 0;
126 return 1;
127 }
128
129 static int
130 directory_has_spaces ()
131 {
132 if (get_root_dir ().find(' '))
133 return 1;
134 return 0;
135 }
136
137 static BOOL
138 dialog_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:
146 case IDC_ROOT_SYSTEM:
147 case IDC_ROOT_USER:
148 save_dialog (h);
149 check_if_enable_next (h);
150 break;
151
152 case IDC_ROOT_BROWSE:
153 browse (h);
154 break;
155 }
156 return 0;
157 }
158
159 bool
160 RootPage::Create ()
161 {
162 return PropertyPage::Create (NULL, dialog_cmd, IDD_ROOT);
163 }
164
165 void
166 RootPage::OnInit ()
167 {
168 if (((string)RootOption).size())
169 set_root_dir((string)RootOption);
170 if (!get_root_dir ().size())
171 read_mounts ();
172 load_dialog (GetHWND ());
173 }
174
175 bool
176 RootPage::wantsActivation() const
177 {
178 return (source != IDC_SOURCE_DOWNLOAD);
179 }
180
181 long
182 RootPage::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
198 log (LOG_PLAIN, String ("root: ") + get_root_dir () +
199 (root_text == IDC_ROOT_TEXT ? " text" : " binary") +
200 (root_scope == IDC_ROOT_USER ? " user" : " system"));
201
202 return 0;
203 }
204
205 long
206 RootPage::OnBack ()
207 {
208 HWND h = GetHWND ();
209
210 save_dialog (h);
211 return 0;
212 }
213
214 long
215 RootPage::OnUnattended ()
216 {
217 return OnNext();
218 }
This page took 0.043212 seconds and 5 git commands to generate.