Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F108997976
D33425.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D33425.diff
View Options
Index: usr.sbin/bsdinstall/distfetch/Makefile
===================================================================
--- usr.sbin/bsdinstall/distfetch/Makefile
+++ usr.sbin/bsdinstall/distfetch/Makefile
@@ -2,7 +2,8 @@
BINDIR= ${LIBEXECDIR}/bsdinstall
PROG= distfetch
-LIBADD= fetch dialog m
+CFLAGS+= -I${SRCTOP}/contrib/bsddialog/lib
+LIBADD= fetch bsddialog m
MAN=
Index: usr.sbin/bsdinstall/distfetch/distfetch.c
===================================================================
--- usr.sbin/bsdinstall/distfetch/distfetch.c
+++ usr.sbin/bsdinstall/distfetch/distfetch.c
@@ -32,15 +32,21 @@
#include <sys/param.h>
#include <ctype.h>
+#include <bsddialog.h>
#include <err.h>
-#include <dialog.h>
#include <errno.h>
+#include <stdio.h>
#include <fetch.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#define FAILED 1
+#define DONE 5
+#define INPROGRESS 7
+#define PENDING 10
+
static int fetch_files(int nfiles, char **urls);
int
@@ -52,6 +58,7 @@
int ndists = 0;
int nfetched;
char error[PATH_MAX + 512];
+ struct bsddialog_conf conf;
if (getenv("DISTRIBUTIONS") == NULL)
errx(EXIT_FAILURE, "DISTRIBUTIONS variable is not set");
@@ -68,9 +75,12 @@
errx(EXIT_FAILURE, "Out of memory!");
}
- init_dialog(stdin, stdout);
- dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer");
- dlg_put_backtitle();
+ bsddialog_initconf(&conf);
+ if (bsddialog_init() == BSDDIALOG_ERROR) {
+ free(diststring);
+ errx(EXIT_FAILURE, "Cannot init libbsddialog");
+ }
+ bsddialog_backtitle(&conf, __DECONST(char *, "FreeBSD Installer"));
for (i = 0; i < ndists; i++) {
urls[i] = malloc(PATH_MAX);
@@ -82,14 +92,15 @@
snprintf(error, sizeof(error),
"Could not change to directory %s: %s\n",
getenv("BSDINSTALL_DISTDIR"), strerror(errno));
- dialog_msgbox("Error", error, 0, 0, TRUE);
- end_dialog();
+ conf.title = __DECONST(char *, "Error");
+ bsddialog_msgbox(&conf, error, 0, 0);
+ bsddialog_end();
return (EXIT_FAILURE);
}
nfetched = fetch_files(ndists, urls);
- end_dialog();
+ bsddialog_end();
free(diststring);
for (i = 0; i < ndists; i++)
@@ -104,7 +115,8 @@
{
FILE *fetch_out;
FILE *file_out;
- const char **items;
+ char **minilabel;
+ int *miniperc, perc;
int i;
int last_progress;
int nsuccess = 0; /* Number of files successfully downloaded */
@@ -113,26 +125,29 @@
off_t current_bytes;
off_t fsize;
off_t total_bytes;
- char status[8];
struct url_stat ustat;
char errormsg[PATH_MAX + 512];
uint8_t block[4096];
+ struct bsddialog_conf conf;
- /* Make the transfer list for dialog */
- items = calloc(sizeof(char *), nfiles * 2);
- if (items == NULL)
- errx(EXIT_FAILURE, "Out of memory!");
+ /* Make the transfer list for mixedgauge */
+ minilabel = calloc(sizeof(char *), nfiles);
+ miniperc = calloc(sizeof(int), nfiles);
+ if (minilabel == NULL || miniperc == NULL)
+ errx(EXIT_FAILURE, "Mixedgauge minibars out of memory!");
for (i = 0; i < nfiles; i++) {
- items[i*2] = strrchr(urls[i], '/');
- if (items[i*2] != NULL)
- items[i*2]++;
+ minilabel[i] = strrchr(urls[i], '/');
+ if (minilabel[i] != NULL)
+ minilabel[i]++;
else
- items[i*2] = urls[i];
- items[i*2 + 1] = "Pending";
+ minilabel[i] = urls[i];
+ miniperc[i] = PENDING;
}
- dialog_msgbox("", "Connecting to server.\nPlease wait...", 0, 0, FALSE);
+ bsddialog_initconf(&conf);
+ bsddialog_infobox(&conf,
+ __DECONST(char *, "Connecting to server.\nPlease wait..."), 0, 0);
/* Try to stat all the files */
total_bytes = 0;
@@ -153,22 +168,22 @@
snprintf(errormsg, sizeof(errormsg),
"Error while fetching %s: %s\n", urls[i],
fetchLastErrString);
- items[i*2 + 1] = "Failed";
- dialog_msgbox("Fetch Error", errormsg, 0, 0,
- TRUE);
+ miniperc[2] = FAILED;
+ conf.title = __DECONST(char *, "Fetch Error");
+ bsddialog_msgbox(&conf, errormsg, 0, 0);
continue;
}
- items[i*2 + 1] = "In Progress";
+ miniperc[i] = INPROGRESS;
fsize = 0;
- file_out = fopen(items[i*2], "w+");
+ file_out = fopen(minilabel[i], "w+");
if (file_out == NULL) {
snprintf(errormsg, sizeof(errormsg),
"Error while fetching %s: %s\n",
urls[i], strerror(errno));
- items[i*2 + 1] = "Failed";
- dialog_msgbox("Fetch Error", errormsg, 0, 0,
- TRUE);
+ miniperc[i] = FAILED;
+ conf.title = __DECONST(char *, "Fetch Error");
+ bsddialog_msgbox(&conf, errormsg, 0, 0);
fclose(fetch_out);
continue;
}
@@ -187,16 +202,18 @@
}
if (ustat.size > 0) {
- snprintf(status, sizeof(status), "-%jd",
- (fsize*100)/ustat.size);
- items[i*2 + 1] = status;
+ perc = -((fsize*100)/ustat.size);
+ /* 0% is not "Succedded", use "In Progress" */
+ miniperc[i] = perc == 0 ? INPROGRESS : perc;
}
- if (progress > last_progress)
- dialog_mixedgauge("Fetching Distribution",
- "Fetching distribution files...", 0, 0,
- progress, nfiles,
- __DECONST(char **, items));
+ if (progress > last_progress) {
+ conf.title =
+ __DECONST(char *, "Fetching Distribution");
+ bsddialog_mixedgauge(&conf, __DECONST(char *,
+ "Fetching distribution files..."), 0, 0,
+ progress, nfiles, minilabel, miniperc);
+ }
}
if (ustat.size > 0 && fsize < ustat.size) {
@@ -208,11 +225,11 @@
snprintf(errormsg, sizeof(errormsg),
"Error while fetching %s: %s\n",
urls[i], fetchLastErrString);
- items[i*2 + 1] = "Failed";
- dialog_msgbox("Fetch Error", errormsg, 0, 0,
- TRUE);
+ miniperc[i] = FAILED;
+ conf.title = __DECONST(char *, "Fetch Error");
+ bsddialog_msgbox(&conf, errormsg, 0, 0);
} else {
- items[i*2 + 1] = "Done";
+ miniperc[i] = DONE;
nsuccess++;
}
@@ -220,6 +237,7 @@
fclose(file_out);
}
- free(items);
+ free(minilabel);
+ free(miniperc);
return (nsuccess);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 31, 11:17 AM (14 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16361707
Default Alt Text
D33425.diff (5 KB)
Attached To
Mode
D33425: Convert (bsdinstall) distfetch for libbsddialog
Attached
Detach File
Event Timeline
Log In to Comment