]> cygwin.com Git - cygwin-apps/setup.git/blob - localdir.cc
* net.cc (do_net): Default to direct download.
[cygwin-apps/setup.git] / localdir.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 Andrej Borsenkow <Andrej.Borsenkow@mow.siemens.ru>
13 * based on work and suggestions of DJ Delorie
14 *
15 */
16
17 /* The purpose of this file is to ask the user where they want the
18 root of the installation to be, and to ask whether the user prefers
19 text or binary mounts. */
20
21 static char *cvsid = "\n%%% $Id$\n";
22
23 #include "win32.h"
24 #include <shlobj.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <ctype.h>
28
29 #include "dialog.h"
30 #include "resource.h"
31 #include "state.h"
32 #include "msg.h"
33 #include "mount.h"
34 #include "concat.h"
35 #include "log.h"
36
37 static void
38 check_if_enable_next (HWND h)
39 {
40 EnableWindow (GetDlgItem (h, IDOK), local_dir != 0);
41 }
42
43 static void
44 load_dialog (HWND h)
45 {
46 eset (h, IDC_LOCAL_DIR, local_dir);
47 check_if_enable_next (h);
48 }
49
50 static void
51 save_dialog (HWND h)
52 {
53 local_dir = eget (h, IDC_LOCAL_DIR, local_dir);
54 }
55
56
57 static int CALLBACK
58 browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
59 {
60 switch (msg)
61 {
62 case BFFM_INITIALIZED:
63 if (local_dir)
64 SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM)local_dir);
65 break;
66 }
67 return 0;
68 }
69
70 static void
71 browse (HWND h)
72 {
73 BROWSEINFO bi;
74 CHAR name[MAX_PATH];
75 LPITEMIDLIST pidl;
76 memset (&bi, 0, sizeof (bi));
77 bi.hwndOwner = h;
78 bi.pszDisplayName = name;
79 bi.lpszTitle = "Select download directory";
80 bi.ulFlags = BIF_RETURNONLYFSDIRS;
81 bi.lpfn = browse_cb;
82 pidl = SHBrowseForFolder (&bi);
83 if (pidl)
84 {
85 if (SHGetPathFromIDList (pidl, name))
86 eset (h, IDC_LOCAL_DIR, name);
87 }
88 }
89
90
91 static BOOL
92 dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
93 {
94 switch (id)
95 {
96
97 case IDC_LOCAL_DIR:
98 save_dialog (h);
99 check_if_enable_next (h);
100 break;
101
102 case IDC_LOCAL_DIR_BROWSE:
103 browse (h);
104 break;
105
106 case IDOK:
107 save_dialog (h);
108 if (SetCurrentDirectoryA (local_dir))
109 {
110 switch (source)
111 {
112 case IDC_SOURCE_DOWNLOAD:
113 NEXT (IDD_NET);
114 break;
115 case IDC_SOURCE_NETINST:
116 case IDC_SOURCE_CWD:
117 NEXT (IDD_ROOT);
118 break;
119 default:
120 NEXT (0);
121 break;
122 }
123 }
124 else
125 note (IDS_ERR_CHDIR, local_dir);
126
127 break;
128
129 case IDC_BACK:
130 save_dialog (h);
131 NEXT (IDD_SOURCE);
132 break;
133
134 case IDCANCEL:
135 NEXT (0);
136 break;
137 }
138 }
139
140 static BOOL CALLBACK
141 dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
142 {
143 switch (message)
144 {
145 case WM_INITDIALOG:
146 load_dialog (h);
147 return FALSE;
148 case WM_COMMAND:
149 return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd);
150 }
151 return FALSE;
152 }
153
154 extern char cwd[_MAX_PATH];
155
156 void
157 do_local_dir (HINSTANCE h)
158 {
159 int rv = 0;
160 rv = DialogBox (h, MAKEINTRESOURCE (IDD_LOCAL_DIR), 0, dialog_proc);
161 if (rv == -1)
162 fatal (IDS_DIALOG_FAILED);
163
164 log (0, "Selected local directory: %s", local_dir);
165 }
166
This page took 0.045272 seconds and 5 git commands to generate.