--- prozilla-2.0.4.old/libprozilla/src/download.c +++ prozilla-2.0.4/libprozilla/src/download.c @@ -106,8 +106,14 @@ download->num_connections = num_connections; out_file=kmalloc(PATH_MAX); + +#ifdef NOTDEF snprintf(out_file, PATH_MAX, "%s/%s.prozilla", download->dl_dir, connection->u.file); +#else + snprintf(out_file, PATH_MAX, "%s/%d-%d.prozilla", + download->dl_dir, getuid(), getpid()); +#endif proz_debug("out file %s",out_file); @@ -403,11 +409,36 @@ out_filename=kmalloc(PATH_MAX); orig_filename=kmalloc(PATH_MAX); +#ifdef NOTDEF snprintf(orig_filename, PATH_MAX, "%s/%s", download->dl_dir, download->pconnections[0]->u.file); snprintf(out_filename, PATH_MAX, "%s/%s.prozilla", download->dl_dir, download->pconnections[0]->u.file); - if(rename(out_filename, orig_filename)==-1) +#else + if (libprozrtinfo.output_file) + { + snprintf (orig_filename, PATH_MAX, "%s/%s", + download->dl_dir, + libprozrtinfo.output_file); + } + else + { + char *xp = download->pconnections [0]->u.file; + + if ((xp == NULL) || (*xp == '/') || (*xp == '\0')) + { + xp = "index.html"; + } + + snprintf (orig_filename, PATH_MAX, "%s/%s", + download->dl_dir, xp); + } + + snprintf (out_filename, PATH_MAX, "%s/%d-%d.prozilla", + download->dl_dir, getuid(), getpid()); +#endif + + if(rename(out_filename, orig_filename)==-1) { download_show_message(download, "Error While attempting to rename the file: %s", strerror(errno)); } @@ -1182,8 +1213,28 @@ struct stat st_buf; int ret; +#ifdef NOTDEF snprintf(out_file_name, PATH_MAX, "%s/%s", download->output_dir, download->u.file); +#else + if (libprozrtinfo.output_file) + { + snprintf (out_file_name, PATH_MAX, "%s/%s", + download->output_dir, libprozrtinfo.output_file); + } + else + { + char *xp = download->u.file; + + if ((xp == NULL) || (*xp == '/') || (*xp == '\0')) + { + xp = "index.html"; + } + + snprintf (out_file_name, PATH_MAX, "%s/%s", + download->output_dir, xp); + } +#endif ret = stat(out_file_name, &st_buf); if (ret == -1) --- prozilla-2.0.4.old/libprozilla/src/main.c +++ prozilla-2.0.4/libprozilla/src/main.c @@ -105,6 +105,7 @@ libprozrtinfo.dl_dir = kstrdup("."); libprozrtinfo.output_dir = kstrdup("."); + libprozrtinfo.output_file = NULL; libprozrtinfo.log_dir = kstrdup("."); debug_init(); return 1; @@ -119,6 +120,12 @@ kfree(libprozrtinfo.ftp_proxy); kfree(libprozrtinfo.dl_dir); kfree(libprozrtinfo.output_dir); + + if (libprozrtinfo.output_file) + { + kfree (libprozrtinfo.output_file); + } + kfree(libprozrtinfo.log_dir); } @@ -218,6 +225,13 @@ libprozrtinfo.output_dir = kstrdup(dir); } +void proz_set_output_file(char *file) +{ + assert (file != NULL); + if (libprozrtinfo.output_file) + kfree (libprozrtinfo.output_file); + libprozrtinfo.output_file = kstrdup (file); +} char *proz_get_libprozilla_version() { --- prozilla-2.0.4.old/libprozilla/src/prozilla.h +++ prozilla-2.0.4/libprozilla/src/prozilla.h @@ -201,6 +201,7 @@ char *ftp_default_passwd; char *dl_dir; char *output_dir; + char *output_file; char *log_dir; boolean ftp_use_pasv; proxy_info *ftp_proxy; @@ -472,6 +473,7 @@ void proz_set_download_dir(char *dir); void proz_set_logfile_dir(char *dir); void proz_set_output_dir(char *dir); + void proz_set_output_file(char *file); char *proz_get_libprozilla_version(); /*Functions for loggind debug messages */ --- prozilla-2.0.4.old/src/download_win.cpp +++ prozilla-2.0.4/src/download_win.cpp @@ -695,8 +695,12 @@ int DL_Window::askUserOverwrite(connection_t *connectionb) { int ret = 0; - const char msg[] = "File %s already exists, would you like to (A)bort it or (O)verwrite it?"; +#ifdef NOTDEF + const char msg[] = "File %s already exists, would you like to (A)bort it or (O)verwrite it?"; +#else + const char msg[] = "File already exists, (A)bort or (O)verwrite it? "; +#endif do { if (rt.display_mode == DISP_CURSES) --- prozilla-2.0.4.old/src/main.cpp +++ prozilla-2.0.4/src/main.cpp @@ -75,6 +75,7 @@ {"no-curses", no_argument, NULL, 140}, {"min-size",required_argument,NULL,141}, {"ftpsid", required_argument, NULL,142}, + {"output", required_argument, NULL, 'o'}, {0, 0, 0, 0} }; @@ -133,8 +134,10 @@ " -v,--verbose Increase the amount of information sent to stdout\n" " --no-curses Don't use Curses, plain text to stdout\n" "\n" - "Directories:\n" - " -P, --directory-prefix=DIR save the generated file to DIR/\n" + "Output:\n" + " -P, --directory-prefix=DIR save file in DIR/\n" + " --output=FILENAME save file as FILENAME\n" + " --output=PATHNAME save file as PATHNAME\n" "\n" "FTP Options:\n" " --use-port Force usage of PORT insted of PASV (default)\n" @@ -215,6 +218,7 @@ main (int argc, char **argv) { int c; + char *cp; int ret; proz_init (argc, argv); //init libprozilla set_defaults (); //set some reasonable defaults @@ -275,6 +279,31 @@ rt.use_netrc = FALSE; break; + case 'o': + /* + * Save downloaded file to FILENAME or PATHNAME + */ + cp = strrchr (optarg, '/'); + + if (cp == NULL) + { + proz_set_output_file (optarg); + } + else + { + if ((cp == optarg) || (cp [1] == '\0')) + { +fprintf (stderr, "%s\n", + "Usage: prozilla --output /foo/bar ..."); +exit (1); + } + + proz_set_output_file (cp + 1); + *cp = '\0'; + rt.output_dir = kstrdup (optarg); + } + break; + case 'P': /* * Save the downloaded file to DIR