2 * Copyright (c) 2000, Red Hat, Inc.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by Andrej Borsenkow <Andrej.Borsenkow@mow.siemens.ru>
13 * based on work and suggestions of DJ Delorie
17 /* The purpose of this file is to ask the user where they want the
18 * locally downloaded package files to be cached
22 static const char *cvsid
=
28 #include "LogSingleton.h"
42 #include "io_stream.h"
44 #include "UserSettings.h"
46 #include "getopt++/StringOption.h"
49 extern ThreeBarProgressPage Progress
;
50 extern LogFile
* theLog
;
52 static StringOption
LocalDirOption ("", 'l', "local-package-dir", "Local package directory", false);
54 static LocalDirSetting localDir
;
56 static ControlAdjuster::ControlInfo LocaldirControlsInfo
[] = {
57 { IDC_LOCALDIR_GRP
, CP_STRETCH
, CP_TOP
},
58 { IDC_LOCAL_DIR
, CP_STRETCH
, CP_TOP
},
59 { IDC_LOCAL_DIR_BROWSE
, CP_RIGHT
, CP_TOP
},
64 LocalDirSetting::load(){
65 static int inited
= 0;
68 io_stream
*f
= UserSettings::Instance().settingFileForLoad("last-cache");
72 char *fg_ret
= f
->gets (localdir
, 1000);
75 local_dir
= std::string (localdir
);
77 if (((std::string
)LocalDirOption
).size())
78 local_dir
= ((std::string
)LocalDirOption
);
83 LocalDirSetting::save()
85 io_stream
*f
= UserSettings::Instance().settingFileForSave("last-cache");
88 f
->write (local_dir
.c_str(), local_dir
.size());
91 if (source
== IDC_SOURCE_DOWNLOAD
|| !get_root_dir ().size())
94 theLog
->setFile (LOG_BABBLE
, local_dir
+ "/setup.log.full", false);
95 theLog
->setFile (0, local_dir
+ "/setup.log", true);
100 theLog
->setFile (LOG_BABBLE
, cygpath ("/var/log/setup.log.full"), false);
101 theLog
->setFile (0, cygpath ("/var/log/setup.log"), true);
106 check_if_enable_next (HWND h
)
108 EnableWindow (GetDlgItem (h
, IDOK
), local_dir
.size() != 0);
114 eset (h
, IDC_LOCAL_DIR
, local_dir
);
115 check_if_enable_next (h
);
121 local_dir
= egetString (h
, IDC_LOCAL_DIR
);
126 browse_cb (HWND h
, UINT msg
, LPARAM lp
, LPARAM data
)
130 case BFFM_INITIALIZED
:
131 if (local_dir
.size())
132 SendMessage (h
, BFFM_SETSELECTION
, TRUE
, (LPARAM
) local_dir
.c_str());
144 memset (&bi
, 0, sizeof (bi
));
146 bi
.pszDisplayName
= name
;
147 bi
.lpszTitle
= "Select download directory";
148 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
;
150 pidl
= SHBrowseForFolder (&bi
);
153 if (SHGetPathFromIDList (pidl
, name
))
154 eset (h
, IDC_LOCAL_DIR
, name
);
159 dialog_cmd (HWND h
, int id
, HWND hwndctl
, UINT code
)
166 check_if_enable_next (h
);
169 case IDC_LOCAL_DIR_BROWSE
:
176 LocalDirPage::LocalDirPage ()
178 sizeProcessor
.AddControlInfo (LocaldirControlsInfo
);
182 LocalDirPage::Create ()
184 return PropertyPage::Create (NULL
, dialog_cmd
, IDD_LOCAL_DIR
);
188 LocalDirPage::OnActivate ()
190 load_dialog (GetHWND ());
194 LocalDirPage::OnNext ()
200 log (LOG_PLAIN
) << "Selected local directory: " << local_dir
<< endLog
;
202 bool trySetCurDir
= true;
205 trySetCurDir
= false;
206 if (SetCurrentDirectoryA (local_dir
.c_str()))
208 if (source
== IDC_SOURCE_CWD
)
210 if (do_fromcwd (GetInstance (), GetHWND ()))
212 Progress
.SetActivateTask (WM_APP_START_SETUP_INI_DOWNLOAD
);
220 DWORD err
= GetLastError ();
222 LoadString (hinstance
, IDS_ERR_CHDIR
, msgText
, sizeof (msgText
));
225 if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
|
226 FORMAT_MESSAGE_ALLOCATE_BUFFER
, 0, err
, LANG_NEUTRAL
,
227 (LPSTR
)&buf
, 0, 0) != 0)
229 snprintf (msg
, sizeof (msg
), msgText
, local_dir
.c_str(),
233 snprintf (msg
, sizeof (msg
), msgText
, local_dir
.c_str(),
234 "(unknown error)", err
);
235 log (LOG_PLAIN
) << msg
<< endLog
;
236 int ret
= MessageBox (h
, msg
, 0, MB_ICONEXCLAMATION
|
237 MB_ABORTRETRYIGNORE
);
239 if ((ret
== IDABORT
) || (ret
== IDCANCEL
))
242 trySetCurDir
= (ret
== IDRETRY
);
250 LocalDirPage::OnBack ()
252 save_dialog (GetHWND ());