]> cygwin.com Git - cygwin-apps/setup.git/blob - root.cc
* filemanip.c (parse_filename): Revert previous change.
[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 "concat.h"
37 #include "log.h"
38 #include "root.h"
39
40 static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 };
41 static int su[] = { IDC_ROOT_SYSTEM, IDC_ROOT_USER, 0 };
42
43 static void
44 check_if_enable_next (HWND h)
45 {
46 EnableWindow (GetDlgItem (h, IDOK), root_text && get_root_dir ()
47 && root_scope);
48 }
49
50 static void
51 load_dialog (HWND h)
52 {
53 rbset (h, rb, root_text);
54 rbset (h, su, root_scope);
55 eset (h, IDC_ROOT_DIR, get_root_dir ());
56 check_if_enable_next (h);
57 }
58
59 static void
60 save_dialog (HWND h)
61 {
62 root_text = rbget (h, rb);
63 root_scope = rbget (h, su);
64 set_root_dir (eget (h, IDC_ROOT_DIR, (char *) get_root_dir ()));
65 }
66
67 static int CALLBACK
68 browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
69 {
70 switch (msg)
71 {
72 case BFFM_INITIALIZED:
73 if (get_root_dir ())
74 SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) get_root_dir ());
75 break;
76 }
77 return 0;
78 }
79
80 static void
81 browse (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
102 static int
103 directory_is_absolute ()
104 {
105 const char *r = get_root_dir ();
106 if (isalpha (r[0]) && r[1] == ':' && (r[2] == '\\' || r[2] == '/'))
107 return 1;
108 return 0;
109 }
110
111 static int
112 directory_is_rootdir ()
113 {
114 const char *c;
115 for (c = get_root_dir (); *c; c++)
116 if (isslash (c[0]) && c[1] && !isslash (c[1]))
117 return 0;
118 return 1;
119 }
120
121 static int
122 directory_has_spaces ()
123 {
124 if (strchr (get_root_dir (), ' '))
125 return 1;
126 return 0;
127 }
128
129 static BOOL
130 dialog_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:
138 case IDC_ROOT_SYSTEM:
139 case IDC_ROOT_USER:
140 save_dialog (h);
141 check_if_enable_next (h);
142 break;
143
144 case IDC_ROOT_BROWSE:
145 browse (h);
146 break;
147 }
148 return 0;
149 }
150
151 bool
152 RootPage::Create ()
153 {
154 return PropertyPage::Create (NULL, dialog_cmd, IDD_ROOT);
155 }
156
157 void
158 RootPage::OnInit ()
159 {
160 if (!get_root_dir ())
161 read_mounts ();
162 load_dialog (GetHWND ());
163 }
164
165 long
166 RootPage::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);
183
184 log (0, "root: %s %s %s", get_root_dir (),
185 (root_text == IDC_ROOT_TEXT) ? "text" : "binary",
186 (root_scope == IDC_ROOT_USER) ? "user" : "system");
187
188 return 0;
189 }
190
191 long
192 RootPage::OnBack ()
193 {
194 HWND h = GetHWND ();
195
196 save_dialog (h);
197 NEXT (IDD_SOURCE);
198 return 0;
199 }
This page took 0.04891 seconds and 6 git commands to generate.