]> cygwin.com Git - cygwin-apps/setup.git/blob - localdir.cc
2002-02-19 Robert Collins <rbtcollins@hotmail.com>
[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 * locally downloaded package files to be cached
19 */
20
21 #if 0
22 static const char *cvsid =
23 "\n%%% $Id$\n";
24 #endif
25
26 #include "win32.h"
27 #include <shlobj.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <ctype.h>
31
32 #include "dialog.h"
33 #include "resource.h"
34 #include "state.h"
35 #include "msg.h"
36 #include "mount.h"
37 #include "log.h"
38 #include "io_stream.h"
39
40 #include "localdir.h"
41
42 #include "threebar.h"
43 extern ThreeBarProgressPage Progress;
44
45 void
46 save_local_dir ()
47 {
48 io_stream::mkpath_p (PATH_TO_DIR, local_dir);
49
50 io_stream *f;
51 if (get_root_dir ().size())
52 {
53 f = io_stream::open ("cygfile:///etc/setup/last-cache", "wb");
54 io_stream::remove ("file://last-cache");
55 }
56 else
57 f = io_stream::open ("file://last-cache", "wb");
58 if (f)
59 {
60 f->write (local_dir.cstr_oneuse(), local_dir.size());
61 delete f;
62 }
63 }
64
65 static void
66 check_if_enable_next (HWND h)
67 {
68 EnableWindow (GetDlgItem (h, IDOK), local_dir.size() != 0);
69 }
70
71 static void
72 load_dialog (HWND h)
73 {
74 eset (h, IDC_LOCAL_DIR, local_dir);
75 check_if_enable_next (h);
76 }
77
78 static void
79 save_dialog (HWND h)
80 {
81 local_dir = egetString (h, IDC_LOCAL_DIR);
82 }
83
84
85 static int CALLBACK
86 browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
87 {
88 switch (msg)
89 {
90 case BFFM_INITIALIZED:
91 if (local_dir.size())
92 SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) local_dir.cstr_oneuse());
93 break;
94 }
95 return 0;
96 }
97
98 static void
99 browse (HWND h)
100 {
101 BROWSEINFO bi;
102 CHAR name[MAX_PATH];
103 LPITEMIDLIST pidl;
104 memset (&bi, 0, sizeof (bi));
105 bi.hwndOwner = h;
106 bi.pszDisplayName = name;
107 bi.lpszTitle = "Select download directory";
108 bi.ulFlags = BIF_RETURNONLYFSDIRS;
109 bi.lpfn = browse_cb;
110 pidl = SHBrowseForFolder (&bi);
111 if (pidl)
112 {
113 if (SHGetPathFromIDList (pidl, name))
114 eset (h, IDC_LOCAL_DIR, name);
115 }
116 }
117
118 static BOOL
119 dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
120 {
121 switch (id)
122 {
123
124 case IDC_LOCAL_DIR:
125 save_dialog (h);
126 check_if_enable_next (h);
127 break;
128
129 case IDC_LOCAL_DIR_BROWSE:
130 browse (h);
131 break;
132 }
133 return 0;
134 }
135
136 bool
137 LocalDirPage::Create ()
138 {
139 return PropertyPage::Create (NULL, dialog_cmd, IDD_LOCAL_DIR);
140 }
141
142 void
143 LocalDirPage::OnInit ()
144 {
145 static int inited = 0;
146 if (!inited)
147 {
148 io_stream *f =
149 io_stream::open ("cygfile:///etc/setup/last-cache", "rt");
150 if (!f)
151 f = io_stream::open ("file://last-cache", "rt");
152 if (f)
153 {
154 char localdir[1000];
155 char *fg_ret = f->gets (localdir, 1000);
156 delete f;
157 if (fg_ret)
158 local_dir = String (localdir);
159 }
160 inited = 1;
161 }
162 }
163
164 void
165 LocalDirPage::OnActivate ()
166 {
167 load_dialog (GetHWND ());
168 }
169
170 long
171 LocalDirPage::OnNext ()
172 {
173 HWND h = GetHWND ();
174
175 save_dialog (h);
176 save_local_dir ();
177 log (LOG_PLAIN, String ("Selected local directory: ") + local_dir);
178 if (SetCurrentDirectoryA (local_dir.cstr_oneuse()))
179 {
180 if (source == IDC_SOURCE_CWD)
181 {
182 do_fromcwd (GetInstance (), GetHWND ());
183 if (next_dialog == IDD_S_LOAD_INI)
184 {
185 Progress.SetActivateTask (WM_APP_START_SETUP_INI_DOWNLOAD);
186 return IDD_INSTATUS;
187 }
188 return next_dialog;
189 }
190 }
191 else
192 note (h, IDS_ERR_CHDIR, local_dir.cstr_oneuse());
193
194 return 0;
195 }
196
197 long
198 LocalDirPage::OnBack ()
199 {
200 save_dialog (GetHWND ());
201 if (source == IDC_SOURCE_DOWNLOAD)
202 {
203 // Downloading only, skip the unix root page
204 return IDD_SOURCE;
205 }
206 return 0;
207 }
This page took 0.042627 seconds and 5 git commands to generate.