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