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