]> cygwin.com Git - cygwin-apps/setup.git/blame - root.cc
* res.rc (IDD_OTHER_URL): reorder to give default focus to entry
[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
20#include "win32.h"
21#include <shlobj.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <ctype.h>
25
26#include "dialog.h"
27#include "resource.h"
28#include "state.h"
29#include "msg.h"
30#include "mount.h"
bf1d5889 31#include "concat.h"
23c9e63c
DD
32
33static int rb[] = { IDC_ROOT_TEXT, IDC_ROOT_BINARY, 0 };
24e259bb 34static int su[] = { IDC_ROOT_SYSTEM, IDC_ROOT_USER, 0 };
23c9e63c
DD
35
36static void
37check_if_enable_next (HWND h)
38{
24e259bb 39 EnableWindow (GetDlgItem (h, IDOK), root_text && root_dir && root_scope);
23c9e63c
DD
40}
41
42static void
43load_dialog (HWND h)
44{
45 rbset (h, rb, root_text);
24e259bb 46 rbset (h, su, root_scope);
23c9e63c
DD
47 eset (h, IDC_ROOT_DIR, root_dir);
48 check_if_enable_next (h);
49}
50
51static void
52save_dialog (HWND h)
53{
54 root_text = rbget (h, rb);
24e259bb 55 root_scope = rbget (h, su);
23c9e63c
DD
56 root_dir = eget (h, IDC_ROOT_DIR, root_dir);
57}
58
59static void
60read_mount_table ()
61{
62 int istext;
24e259bb
DD
63 int issystem;
64 root_dir = find_root_mount (&istext, &issystem);
23c9e63c
DD
65 if (root_dir)
66 {
67 if (istext)
68 root_text = IDC_ROOT_TEXT;
69 else
70 root_text = IDC_ROOT_BINARY;
24e259bb
DD
71 if (issystem)
72 root_scope = IDC_ROOT_SYSTEM;
73 else
74 root_scope = IDC_ROOT_USER;
23c9e63c 75 }
bf1d5889
DD
76 else
77 {
78 char windir[_MAX_PATH];
79 GetWindowsDirectory (windir, sizeof (windir));
80 windir[2] = 0;
81 root_dir = concat (windir, "\\cygwin", 0);
82 root_text = IDC_ROOT_BINARY;
83 root_scope = IDC_ROOT_USER;
84 }
23c9e63c
DD
85}
86
87static int CALLBACK
88browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
89{
90 switch (msg)
91 {
92 case BFFM_INITIALIZED:
bf1d5889
DD
93 if (root_dir)
94 SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM)root_dir);
23c9e63c
DD
95 break;
96 }
97 return 0;
98}
99
100static void
101browse (HWND h)
102{
103 BROWSEINFO bi;
104 CHAR name[MAX_PATH];
105 LPITEMIDLIST pidl;
106 memset (&bi, 0, sizeof (bi));
107 bi.hwndOwner = h;
108 bi.pszDisplayName = name;
109 bi.lpszTitle = "Select an installation root directory";
110 bi.ulFlags = BIF_RETURNONLYFSDIRS;
111 bi.lpfn = browse_cb;
112 pidl = SHBrowseForFolder (&bi);
113 if (pidl)
114 {
115 if (SHGetPathFromIDList (pidl, name))
116 eset (h, IDC_ROOT_DIR, name);
117 }
118}
119
120#define isslash(c) ((c) == '\\' || (c) == '/')
121
122static int
123directory_is_absolute ()
124{
125 if (isalpha (root_dir[0])
126 && root_dir[1] == ':'
127 && (root_dir[2] == '\\' || root_dir[2] == '/'))
128 return 1;
129 return 0;
130}
131
132static int
133directory_is_rootdir ()
134{
135 char *c;
136 for (c = root_dir; *c; c++)
137 if (isslash(c[0]) && c[1] && !isslash(c[1]))
138 return 0;
139 return 1;
140}
141
142static int
143directory_has_spaces ()
144{
145 if (strchr (root_dir, ' '))
146 return 1;
147 return 0;
148}
149
150static BOOL
151dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
152{
153 switch (id)
154 {
155
156 case IDC_ROOT_DIR:
157 case IDC_ROOT_TEXT:
158 case IDC_ROOT_BINARY:
24e259bb
DD
159 case IDC_ROOT_SYSTEM:
160 case IDC_ROOT_USER:
23c9e63c
DD
161 save_dialog (h);
162 check_if_enable_next (h);
163 break;
164
165 case IDC_ROOT_BROWSE:
166 browse (h);
167 break;
168
169 case IDOK:
170 save_dialog(h);
171
172 if (! directory_is_absolute ())
173 {
174 note (IDS_ROOT_ABSOLUTE);
175 break;
176 }
177
178 if (directory_is_rootdir ())
179 if (IDNO == yesno (IDS_ROOT_SLASH))
180 break;
181
182 if (directory_has_spaces ())
183 if (IDNO == yesno (IDS_ROOT_SPACE))
184 break;
185
186 switch (source)
187 {
188 case IDC_SOURCE_NETINST:
189 NEXT(IDD_NET);
190 break;
191 case IDC_SOURCE_CWD:
192 NEXT(IDD_S_FROM_CWD);
193 break;
194 default:
195 msg("source is default? %d\n", source);
196 NEXT(0);
197 }
198 break;
199
200 case IDC_BACK:
201 save_dialog(h);
202 NEXT(IDD_SOURCE);
203 break;
204
205 case IDCANCEL:
206 NEXT(0);
207 break;
208 }
209}
210
211static BOOL CALLBACK
212dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
213{
214 switch (message)
215 {
216 case WM_INITDIALOG:
217 load_dialog(h);
218 return FALSE;
219 case WM_COMMAND:
220 return HANDLE_WM_COMMAND(h, wParam, lParam, dialog_cmd);
221 }
222 return FALSE;
223}
224
225void
226do_root (HINSTANCE h)
227{
228 int rv = 0;
229 if (!root_dir)
230 read_mount_table();
231 rv = DialogBox (h, MAKEINTRESOURCE (IDD_ROOT), 0, dialog_proc);
232 if (rv == -1)
233 fatal (IDS_DIALOG_FAILED);
234}
235
This page took 0.044903 seconds and 5 git commands to generate.