]> cygwin.com Git - cygwin-apps/setup.git/blame - localdir.cc
2002-02-19 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / localdir.cc
CommitLineData
c92e1307
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 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
b24c88b3
RC
18 * locally downloaded package files to be cached
19 */
c92e1307 20
b24c88b3
RC
21#if 0
22static const char *cvsid =
45c2d7d3 23 "\n%%% $Id$\n";
b24c88b3 24#endif
c92e1307
DD
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"
c92e1307 37#include "log.h"
b24c88b3 38#include "io_stream.h"
45c2d7d3 39
ab57ceaa
RC
40#include "localdir.h"
41
42#include "threebar.h"
43extern ThreeBarProgressPage Progress;
44
45c2d7d3
RC
45void
46save_local_dir ()
47{
3c054baf 48 io_stream::mkpath_p (PATH_TO_DIR, local_dir);
45c2d7d3 49
2db33f10 50 io_stream *f;
3c054baf 51 if (get_root_dir ().size())
2db33f10
RC
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");
b24c88b3
RC
58 if (f)
59 {
3c054baf 60 f->write (local_dir.cstr_oneuse(), local_dir.size());
b24c88b3
RC
61 delete f;
62 }
45c2d7d3
RC
63}
64
c92e1307
DD
65static void
66check_if_enable_next (HWND h)
67{
3c054baf 68 EnableWindow (GetDlgItem (h, IDOK), local_dir.size() != 0);
c92e1307
DD
69}
70
71static void
72load_dialog (HWND h)
73{
74 eset (h, IDC_LOCAL_DIR, local_dir);
75 check_if_enable_next (h);
76}
77
78static void
79save_dialog (HWND h)
80{
3c054baf 81 local_dir = egetString (h, IDC_LOCAL_DIR);
c92e1307
DD
82}
83
84
85static int CALLBACK
86browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
87{
88 switch (msg)
89 {
90 case BFFM_INITIALIZED:
3c054baf
RC
91 if (local_dir.size())
92 SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) local_dir.cstr_oneuse());
c92e1307
DD
93 break;
94 }
95 return 0;
96}
97
98static void
99browse (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
c92e1307
DD
118static BOOL
119dialog_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;
c92e1307 132 }
b24c88b3 133 return 0;
c92e1307
DD
134}
135
ab57ceaa
RC
136bool
137LocalDirPage::Create ()
c92e1307 138{
ab57ceaa 139 return PropertyPage::Create (NULL, dialog_cmd, IDD_LOCAL_DIR);
c92e1307
DD
140}
141
c92e1307 142void
ab57ceaa 143LocalDirPage::OnInit ()
c92e1307 144{
45c2d7d3
RC
145 static int inited = 0;
146 if (!inited)
147 {
b24c88b3
RC
148 io_stream *f =
149 io_stream::open ("cygfile:///etc/setup/last-cache", "rt");
2db33f10
RC
150 if (!f)
151 f = io_stream::open ("file://last-cache", "rt");
45c2d7d3
RC
152 if (f)
153 {
154 char localdir[1000];
b24c88b3
RC
155 char *fg_ret = f->gets (localdir, 1000);
156 delete f;
45c2d7d3 157 if (fg_ret)
3c054baf 158 local_dir = String (localdir);
45c2d7d3
RC
159 }
160 inited = 1;
161 }
ab57ceaa 162}
45c2d7d3 163
ab57ceaa
RC
164void
165LocalDirPage::OnActivate ()
166{
167 load_dialog (GetHWND ());
168}
169
170long
171LocalDirPage::OnNext ()
172{
173 HWND h = GetHWND ();
c92e1307 174
ab57ceaa
RC
175 save_dialog (h);
176 save_local_dir ();
1ac649ed 177 log (LOG_PLAIN, String ("Selected local directory: ") + local_dir);
3c054baf 178 if (SetCurrentDirectoryA (local_dir.cstr_oneuse()))
ab57ceaa
RC
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
3c054baf 192 note (h, IDS_ERR_CHDIR, local_dir.cstr_oneuse());
ab57ceaa
RC
193
194 return 0;
195}
196
197long
198LocalDirPage::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;
c92e1307 207}
This page took 0.046923 seconds and 5 git commands to generate.