]> cygwin.com Git - cygwin-apps/setup.git/blame - localdir.cc
2002-05-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"
9f4a0c62 37#include "LogFile.h"
c92e1307 38#include "log.h"
b24c88b3 39#include "io_stream.h"
45c2d7d3 40
ab57ceaa
RC
41#include "localdir.h"
42
43#include "threebar.h"
44extern ThreeBarProgressPage Progress;
9f4a0c62 45extern LogFile theLog;
45c2d7d3
RC
46void
47save_local_dir ()
48{
2fa7c5a4 49 io_stream::mkpath_p (PATH_TO_DIR, String ("file://") + local_dir);
45c2d7d3 50
2db33f10 51 io_stream *f;
3c054baf 52 if (get_root_dir ().size())
2db33f10
RC
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");
b24c88b3
RC
59 if (f)
60 {
3c054baf 61 f->write (local_dir.cstr_oneuse(), local_dir.size());
b24c88b3
RC
62 delete f;
63 }
9f4a0c62
RC
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 }
45c2d7d3
RC
76}
77
c92e1307
DD
78static void
79check_if_enable_next (HWND h)
80{
3c054baf 81 EnableWindow (GetDlgItem (h, IDOK), local_dir.size() != 0);
c92e1307
DD
82}
83
84static void
85load_dialog (HWND h)
86{
87 eset (h, IDC_LOCAL_DIR, local_dir);
88 check_if_enable_next (h);
89}
90
91static void
92save_dialog (HWND h)
93{
3c054baf 94 local_dir = egetString (h, IDC_LOCAL_DIR);
c92e1307
DD
95}
96
97
98static int CALLBACK
99browse_cb (HWND h, UINT msg, LPARAM lp, LPARAM data)
100{
101 switch (msg)
102 {
103 case BFFM_INITIALIZED:
3c054baf
RC
104 if (local_dir.size())
105 SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM) local_dir.cstr_oneuse());
c92e1307
DD
106 break;
107 }
108 return 0;
109}
110
111static void
112browse (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
c92e1307
DD
131static BOOL
132dialog_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;
c92e1307 145 }
b24c88b3 146 return 0;
c92e1307
DD
147}
148
ab57ceaa
RC
149bool
150LocalDirPage::Create ()
c92e1307 151{
ab57ceaa 152 return PropertyPage::Create (NULL, dialog_cmd, IDD_LOCAL_DIR);
c92e1307
DD
153}
154
c92e1307 155void
ab57ceaa 156LocalDirPage::OnInit ()
c92e1307 157{
45c2d7d3
RC
158 static int inited = 0;
159 if (!inited)
160 {
b24c88b3
RC
161 io_stream *f =
162 io_stream::open ("cygfile:///etc/setup/last-cache", "rt");
2db33f10
RC
163 if (!f)
164 f = io_stream::open ("file://last-cache", "rt");
45c2d7d3
RC
165 if (f)
166 {
167 char localdir[1000];
b24c88b3
RC
168 char *fg_ret = f->gets (localdir, 1000);
169 delete f;
45c2d7d3 170 if (fg_ret)
3c054baf 171 local_dir = String (localdir);
45c2d7d3
RC
172 }
173 inited = 1;
174 }
ab57ceaa 175}
45c2d7d3 176
ab57ceaa
RC
177void
178LocalDirPage::OnActivate ()
179{
180 load_dialog (GetHWND ());
181}
182
183long
184LocalDirPage::OnNext ()
185{
186 HWND h = GetHWND ();
c92e1307 187
ab57ceaa
RC
188 save_dialog (h);
189 save_local_dir ();
1ac649ed 190 log (LOG_PLAIN, String ("Selected local directory: ") + local_dir);
3c054baf 191 if (SetCurrentDirectoryA (local_dir.cstr_oneuse()))
ab57ceaa
RC
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
3c054baf 205 note (h, IDS_ERR_CHDIR, local_dir.cstr_oneuse());
ab57ceaa
RC
206
207 return 0;
208}
209
210long
211LocalDirPage::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;
c92e1307 220}
This page took 0.052218 seconds and 5 git commands to generate.