]> cygwin.com Git - cygwin-apps/setup.git/blob - root.cc
2002-07-02 Robert Collins <rbtcollins@hotmail.com>
[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 static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 };
40 static int su[] = { IDC_ROOT_SYSTEM, IDC_ROOT_USER, 0 };
41
42 static void
43 check_if_enable_next (HWND h)
44 {
45 EnableWindow (GetDlgItem (h, IDOK), root_text && get_root_dir ().size()
46 && root_scope);
47 }
48
49 static void
50 load_dialog (HWND h)
51 {
52 rbset (h, rb, root_text);
53 rbset (h, su, root_scope);
54 eset (h, IDC_ROOT_DIR, get_root_dir ());
55 check_if_enable_next (h);
56 }
57
58 static void
59 save_dialog (HWND h)
60 {
61 root_text = rbget (h, rb);
62 root_scope = rbget (h, su);
63 set_root_dir (egetString (h, IDC_ROOT_DIR));
64 }
65
66 static int CALLBACK
67 browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
68 {
69 switch (msg)
70 {
71 case BFFM_INITIALIZED:
72 if (get_root_dir ().size())
73 SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) get_root_dir ().cstr_oneuse());
74 break;
75 }
76 return 0;
77 }
78
79 static void
80 browse (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
101 static int
102 directory_is_absolute ()
103 {
104
105 const char *r = get_root_dir ().cstr();
106 if (isalpha (r[0]) && r[1] == ':' && (r[2] == '\\' || r[2] == '/'))
107 {
108 delete [] r;
109 return 1;
110 }
111 delete[]r;
112 return 0;
113 }
114
115 static int
116 directory_is_rootdir ()
117 {
118 char *t=get_root_dir ().cstr();
119 const char *c;
120 for (c = t; *c; c++)
121 if (isslash (c[0]) && c[1] && !isslash (c[1]))
122 {delete[]t;
123 return 0;}
124 delete[]t;
125 return 1;
126 }
127
128 static int
129 directory_has_spaces ()
130 {
131 if (get_root_dir ().find(' '))
132 return 1;
133 return 0;
134 }
135
136 static BOOL
137 dialog_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:
145 case IDC_ROOT_SYSTEM:
146 case IDC_ROOT_USER:
147 save_dialog (h);
148 check_if_enable_next (h);
149 break;
150
151 case IDC_ROOT_BROWSE:
152 browse (h);
153 break;
154 }
155 return 0;
156 }
157
158 bool
159 RootPage::Create ()
160 {
161 return PropertyPage::Create (NULL, dialog_cmd, IDD_ROOT);
162 }
163
164 void
165 RootPage::OnInit ()
166 {
167 if (!get_root_dir ().size())
168 read_mounts ();
169 load_dialog (GetHWND ());
170 }
171
172 long
173 RootPage::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);
190
191 log (LOG_PLAIN, String ("root: ") + get_root_dir () +
192 (root_text == IDC_ROOT_TEXT ? " text" : " binary") +
193 (root_scope == IDC_ROOT_USER ? " user" : " system"));
194
195 return 0;
196 }
197
198 long
199 RootPage::OnBack ()
200 {
201 HWND h = GetHWND ();
202
203 save_dialog (h);
204 NEXT (IDD_SOURCE);
205 return 0;
206 }
This page took 0.040277 seconds and 5 git commands to generate.