89f8e3448a8e7148302925054a098b3984d77efb
[chise/xemacs-chise.git.1] / netinstall / 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    root of the installation to be, and to ask whether the user prefers
19    text or binary mounts. */
20
21 #include "win32.h"
22 #include <shlobj.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <ctype.h>
26
27 #include "dialog.h"
28 #include "resource.h"
29 #include "state.h"
30 #include "msg.h"
31 #include "concat.h"
32 #include "log.h"
33
34 static void
35 check_if_enable_next (HWND h)
36 {
37   EnableWindow (GetDlgItem (h, IDOK), local_dir != 0);
38 }
39
40 static void
41 load_dialog (HWND h)
42 {
43   eset (h, IDC_LOCAL_DIR, local_dir);
44   check_if_enable_next (h);
45 }
46
47 static void
48 save_dialog (HWND h)
49 {
50   local_dir = eget (h, IDC_LOCAL_DIR, local_dir);
51 }
52
53
54 static int CALLBACK
55 browse_cb (HWND h, UINT m, LPARAM lp, LPARAM data)
56 {
57   switch (m)
58     {
59     case BFFM_INITIALIZED:
60       if (local_dir)
61         SendMessage (h, BFFM_SETSELECTION, TRUE, (LPARAM)local_dir);
62       break;
63     }
64   return 0;
65 }
66
67 static void
68 browse (HWND h)
69 {
70   BROWSEINFO bi;
71   CHAR name[MAX_PATH];
72   LPITEMIDLIST pidl;
73   memset (&bi, 0, sizeof (bi));
74   bi.hwndOwner = h;
75   bi.pszDisplayName = name;
76   bi.lpszTitle = "Select download directory";
77   bi.ulFlags = BIF_RETURNONLYFSDIRS;
78   bi.lpfn = browse_cb;
79   pidl = SHBrowseForFolder (&bi);
80   if (pidl)
81     {
82       if (SHGetPathFromIDList (pidl, name))
83         eset (h, IDC_LOCAL_DIR, name);
84     }
85 }
86
87
88 static BOOL
89 dialog_cmd (HWND h, int id, HWND hwndctl, UINT code)
90 {
91   switch (id)
92     {
93
94     case IDC_LOCAL_DIR:
95       save_dialog (h);
96       check_if_enable_next (h);
97       break;
98
99     case IDC_LOCAL_DIR_BROWSE:
100       browse (h);
101       break;
102
103     case IDOK:
104       save_dialog (h);
105       if (SetCurrentDirectoryA (local_dir))
106         {
107           switch (source)
108             {
109             case IDC_SOURCE_DOWNLOAD:
110               NEXT (IDD_NET);
111               break;
112             case IDC_SOURCE_NETINST:
113             case IDC_SOURCE_CWD:
114               NEXT (IDD_ROOT);
115               break;
116             default:
117               NEXT (0);
118               break;
119             }
120         }
121       else
122         note (IDS_ERR_CHDIR, local_dir);
123
124       break;
125
126     case IDC_BACK:
127       save_dialog (h);
128       NEXT (IDD_SOURCE);
129       break;
130
131     case IDCANCEL:
132       NEXT (0);
133       break;
134     }
135   return FALSE;
136 }
137
138 static BOOL CALLBACK
139 dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
140 {
141   switch (message)
142     {
143     case WM_INITDIALOG:
144       load_dialog (h);
145       return FALSE;
146     case WM_COMMAND:
147       return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd);
148     }
149   return FALSE;
150 }
151
152 extern char cwd[_MAX_PATH];
153
154 void
155 do_local_dir (HINSTANCE h)
156 {
157   int rv = 0;
158   rv = DialogBox (h, MAKEINTRESOURCE (IDD_LOCAL_DIR), 0, dialog_proc);
159   if (rv == -1)
160     fatal (IDS_DIALOG_FAILED);
161
162   log (0, "Selected local directory: %s", local_dir);
163 }
164