Expose no-startmenu option to post-install and pre-remove scripts
[cygwin-setup.git] / source.cc
blob63da024191df21161d4e197e024e70d038f9e89a
1 /*
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
10 * http://www.gnu.org/
12 * Written by DJ Delorie <dj@cygnus.com>
16 /* The purpose of this file is to manage the dialog box that lets the
17 user choose the source of the install - from the net, from the
18 current directory, or to just download files. */
20 #include "source.h"
22 #include "LogSingleton.h"
24 #include "win32.h"
25 #include <stdio.h>
26 #include "dialog.h"
27 #include "resource.h"
28 #include "state.h"
29 #include "msg.h"
30 #include "package_db.h"
32 #include "SourceSetting.h"
34 #include "getopt++/BoolOption.h"
36 static BoolOption DownloadOption (false, 'D', "download", IDS_HELPTEXT_DOWNLOAD);
37 static BoolOption LocalOption (false, 'L', "local-install", IDS_HELPTEXT_LOCAL_INSTALL);
39 static int rb[] =
40 { IDC_SOURCE_NETINST, IDC_SOURCE_DOWNLOAD, IDC_SOURCE_LOCALDIR, 0 };
42 static void
43 load_dialog (HWND h)
45 rbset (h, rb, source);
48 static void
49 save_dialog (HWND h)
51 source = rbget (h, rb);
52 /* We mustn't construct any packagedb objects until after the root
53 directory has been selected, but setting the static data member
54 that records the mode we're running in is fine here (and conversely,
55 would be A Bad Thing if we did it again after the first time we
56 construct a packagedb object; see package_db.h for details). */
57 packagedb::task =
58 source == IDC_SOURCE_DOWNLOAD ? PackageDB_Download : PackageDB_Install;
61 static BOOL
62 dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
64 switch (id)
67 case IDC_SOURCE_DOWNLOAD:
68 case IDC_SOURCE_NETINST:
69 case IDC_SOURCE_LOCALDIR:
70 save_dialog (h);
71 break;
73 default:
74 break;
76 return 0;
79 bool
80 SourcePage::Create ()
82 return PropertyPage::Create (NULL, dialog_cmd, IDD_SOURCE);
85 void
86 SourcePage::OnActivate ()
88 if (DownloadOption && LocalOption)
89 source = IDC_SOURCE_NETINST;
90 else if (DownloadOption)
91 source = IDC_SOURCE_DOWNLOAD;
92 else if (LocalOption)
93 source = IDC_SOURCE_LOCALDIR;
94 else if ((unattended_mode != attended) || (!source))
95 // default to IDC_SOURCE_NETINST if unattended, or source not already set
96 // (i.e. first run)
97 source = IDC_SOURCE_NETINST;
99 load_dialog (GetHWND ());
100 // Check to see if any radio buttons are selected. If not, select a default.
101 if (SendMessage (GetDlgItem (IDC_SOURCE_DOWNLOAD), BM_GETCHECK, 0, 0)
102 != BST_CHECKED
103 && SendMessage (GetDlgItem (IDC_SOURCE_LOCALDIR), BM_GETCHECK, 0, 0)
104 != BST_CHECKED)
105 SendMessage (GetDlgItem (IDC_SOURCE_NETINST), BM_SETCHECK,
106 BST_CHECKED, 0);
109 long
110 SourcePage::OnNext ()
112 HWND h = GetHWND ();
114 save_dialog (h);
115 return 0;
118 long
119 SourcePage::OnBack ()
121 save_dialog (GetHWND ());
122 return 0;
125 void
126 SourcePage::OnDeactivate ()
128 Log (LOG_PLAIN) << "source: "
129 << ((source == IDC_SOURCE_DOWNLOAD) ? "download" :
130 (source == IDC_SOURCE_NETINST) ? "network install" : "from local dir")
131 << endLog;
134 long
135 SourcePage::OnUnattended ()
137 return OnNext();